fixed socket bug and simplified readClient()
This commit is contained in:
parent
b4fd5797f5
commit
03847a9b36
3 changed files with 7 additions and 19 deletions
|
@ -2,13 +2,12 @@
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
Client::Client(QObject *parent)
|
Client::Client(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent), MsgId(0)
|
||||||
{
|
{
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
timer->setInterval(1000);
|
timer->setInterval(1000);
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(checkTimeout()));
|
connect(timer, SIGNAL(timeout()), this, SLOT(checkTimeout()));
|
||||||
|
|
||||||
MsgId = 0;
|
|
||||||
status = StatusDisconnected;
|
status = StatusDisconnected;
|
||||||
socket = new QTcpSocket(this);
|
socket = new QTcpSocket(this);
|
||||||
socket->setTextModeEnabled(true);
|
socket->setTextModeEnabled(true);
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QTextCodec>
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
@ -28,6 +29,8 @@ int main(int argc, char *argv[])
|
||||||
app.setOrganizationName("Cockatrice");
|
app.setOrganizationName("Cockatrice");
|
||||||
app.setApplicationName("Servatrice");
|
app.setApplicationName("Servatrice");
|
||||||
|
|
||||||
|
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
Server server;
|
Server server;
|
||||||
if (!server.openDatabase()) {
|
if (!server.openDatabase()) {
|
||||||
qCritical("Database error");
|
qCritical("Database error");
|
||||||
|
|
|
@ -142,24 +142,10 @@ void ServerSocket::leaveGame()
|
||||||
|
|
||||||
void ServerSocket::readClient()
|
void ServerSocket::readClient()
|
||||||
{
|
{
|
||||||
QTextStream *stream = new QTextStream(this);
|
while (canReadLine()) {
|
||||||
stream->setCodec("UTF-8");
|
QString line = QString(readLine()).trimmed();
|
||||||
QStringList lines;
|
|
||||||
|
|
||||||
// Before parsing, everything has to be buffered so that the stream
|
|
||||||
// can be deleted in order to avoid problems when moving the object
|
|
||||||
// to another thread while this function is still running.
|
|
||||||
for (;;) {
|
|
||||||
QString line = stream->readLine();
|
|
||||||
if (line.isNull())
|
if (line.isNull())
|
||||||
break;
|
break;
|
||||||
lines << line;
|
|
||||||
}
|
|
||||||
delete stream;
|
|
||||||
|
|
||||||
QStringListIterator i(lines);
|
|
||||||
while (i.hasNext()) {
|
|
||||||
QString line = i.next();
|
|
||||||
|
|
||||||
qDebug(QString("<<< %1").arg(line).toLatin1());
|
qDebug(QString("<<< %1").arg(line).toLatin1());
|
||||||
switch (PlayerStatus) {
|
switch (PlayerStatus) {
|
||||||
|
|
Loading…
Reference in a new issue