From c8813bb2aa8387473a2812a6fc70f9ee140ece33 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Mon, 11 Jul 2011 23:01:59 +0200 Subject: [PATCH 1/4] extra server logging, server memory leak fixed, m12 --- common/server.cpp | 4 +++- common/server_protocolhandler.cpp | 4 ++-- oracle/sets.xml | 4 ++++ servatrice/src/servatrice.cpp | 24 ++++++++++++++++-------- servatrice/src/server_logger.cpp | 2 +- servatrice/src/serversocketinterface.cpp | 2 +- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/common/server.cpp b/common/server.cpp index 70451018..bf3e19a9 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -57,8 +57,10 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString return authState; if (authState == PasswordRight) { - if (users.contains(name)) + if (users.contains(name)) { + qDebug("Login denied: would overwrite old session"); return WouldOverwriteOldSession; + } } else if (authState == UnknownUser) { // Change user name so that no two users have the same names, // don't interfere with registered user names though. diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index a4167009..437ba7af 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -58,8 +58,8 @@ void Server_ProtocolHandler::prepareDestroy() while (i.hasNext()) delete i.next().value(); QMapIterator j(ignoreList); - while (i.hasNext()) - delete i.next().value(); + while (j.hasNext()) + delete j.next().value(); } void Server_ProtocolHandler::playerRemovedFromGame(Server_Game *game) diff --git a/oracle/sets.xml b/oracle/sets.xml index 8e7dfda7..4418ab6b 100644 --- a/oracle/sets.xml +++ b/oracle/sets.xml @@ -172,6 +172,10 @@ M11 Magic 2011 + + M12 + Magic 2012 + COM Magic: The Gathering-Commander diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index 51ad91cb..5fc24619 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -37,9 +37,8 @@ void Servatrice_TcpServer::incomingConnection(int socketDescriptor) } else { QTcpSocket *socket = new QTcpSocket; socket->setSocketDescriptor(socketDescriptor); - logger->logMessage(QString("incoming connection: %1").arg(socket->peerAddress().toString())); - - new ServerSocketInterface(server, socket); + ServerSocketInterface *ssi = new ServerSocketInterface(server, socket); + logger->logMessage(QString("incoming connection: %1").arg(socket->peerAddress().toString()), ssi); } } @@ -188,18 +187,27 @@ AuthenticationResult Servatrice::checkUserPassword(Server_ProtocolHandler *handl QSqlQuery query; query.prepare("select a.password, time_to_sec(timediff(now(), date_add(b.time_from, interval b.minutes minute))) < 0, b.minutes <=> 0 from " + dbPrefix + "_users a left join " + dbPrefix + "_bans b on b.id_user = a.id and b.time_from = (select max(c.time_from) from " + dbPrefix + "_bans c where c.id_user = a.id) where a.name = :name and a.active = 1"); query.bindValue(":name", user); - if (!execSqlQuery(query)) + if (!execSqlQuery(query)) { + qDebug("Login denied: SQL error"); return PasswordWrong; + } if (query.next()) { - if (query.value(1).toInt() || query.value(2).toInt()) + if (query.value(1).toInt() || query.value(2).toInt()) { + qDebug("Login denied: banned"); return PasswordWrong; - if (query.value(0).toString() == password) + } + if (query.value(0).toString() == password) { + qDebug("Login accepted: password right"); return PasswordRight; - else + } else { + qDebug("Login denied: password wrong"); return PasswordWrong; - } else + } + } else { + qDebug("Login accepted: unknown user"); return UnknownUser; + } } else return UnknownUser; } diff --git a/servatrice/src/server_logger.cpp b/servatrice/src/server_logger.cpp index 7cfaf3ed..ae073a9c 100644 --- a/servatrice/src/server_logger.cpp +++ b/servatrice/src/server_logger.cpp @@ -39,7 +39,7 @@ void ServerLogger::logMessage(QString message, ServerSocketInterface *ssi) bufferMutex.lock(); QString ssiString; if (ssi) - ssiString = QString::number((qulonglong) ssi) + " "; + ssiString = QString::number((qulonglong) ssi, 16) + " "; buffer.append(QDateTime::currentDateTime().toString() + " " + QString::number((qulonglong) QThread::currentThread(), 16) + " " + ssiString + message); bufferMutex.unlock(); diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index 91c7a6b9..1f793fcd 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -60,7 +60,7 @@ ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_s ServerSocketInterface::~ServerSocketInterface() { - logger->logMessage("ServerSocketInterface destructor"); + logger->logMessage("ServerSocketInterface destructor", this); prepareDestroy(); From b38f0e21002ea8219134f94788e2ea6be31d13cb Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Mon, 11 Jul 2011 23:49:54 +0200 Subject: [PATCH 2/4] extra logging; minor server crash fix --- common/server_game.cpp | 2 +- common/server_protocolhandler.cpp | 37 ++++++++++++++++--------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/common/server_game.cpp b/common/server_game.cpp index 5838e3f9..47457869 100644 --- a/common/server_game.cpp +++ b/common/server_game.cpp @@ -56,7 +56,7 @@ Server_Game::~Server_Game() room->removeGame(this); delete creatorInfo; - qDebug("Server_Game destructor"); + qDebug() << "Server_Game destructor: gameId=" << gameId; } void Server_Game::pingClockTimeout() diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 437ba7af..e79bf259 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -207,25 +207,26 @@ void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont) gameListMutex.lock(); GameEventContainer *gQPublic = cont->getGameEventQueuePublic(); if (gQPublic) { - Server_Game *game = games.value(gQPublic->getGameId()).first; - Server_Player *player = games.value(gQPublic->getGameId()).second; - GameEventContainer *gQPrivate = cont->getGameEventQueuePrivate(); - GameEventContainer *gQOmniscient = cont->getGameEventQueueOmniscient(); - if (gQPrivate) { - int privatePlayerId = cont->getPrivatePlayerId(); - Server_Player *privatePlayer; - if (privatePlayerId == -1) - privatePlayer = player; - else - privatePlayer = game->getPlayer(privatePlayerId); - if (gQOmniscient) { - game->sendGameEventContainer(gQPublic, privatePlayer, true); - game->sendGameEventContainerOmniscient(gQOmniscient, privatePlayer); + QPair gamePlayerPair = games.value(gQPublic->getGameId()); + if (gamePlayerPair.first) { + GameEventContainer *gQPrivate = cont->getGameEventQueuePrivate(); + GameEventContainer *gQOmniscient = cont->getGameEventQueueOmniscient(); + if (gQPrivate) { + int privatePlayerId = cont->getPrivatePlayerId(); + Server_Player *privatePlayer; + if (privatePlayerId == -1) + privatePlayer = gamePlayerPair.second; + else + privatePlayer = gamePlayerPair.first->getPlayer(privatePlayerId); + if (gQOmniscient) { + gamePlayerPair.first->sendGameEventContainer(gQPublic, privatePlayer, true); + gamePlayerPair.first->sendGameEventContainerOmniscient(gQOmniscient, privatePlayer); + } else + gamePlayerPair.first->sendGameEventContainer(gQPublic, privatePlayer); + privatePlayer->sendProtocolItem(gQPrivate); } else - game->sendGameEventContainer(gQPublic, privatePlayer); - privatePlayer->sendProtocolItem(gQPrivate); - } else - game->sendGameEventContainer(gQPublic); + gamePlayerPair.first->sendGameEventContainer(gQPublic); + } } gameListMutex.unlock(); From 7d23569952ef52841f784576c7e60eaecae2fdca Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Tue, 12 Jul 2011 00:51:33 +0200 Subject: [PATCH 3/4] locale aware user sorting --- cockatrice/src/userlist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cockatrice/src/userlist.cpp b/cockatrice/src/userlist.cpp index 71101f48..d0eef42e 100644 --- a/cockatrice/src/userlist.cpp +++ b/cockatrice/src/userlist.cpp @@ -92,7 +92,7 @@ bool UserListTWI::operator<(const QTreeWidgetItem &other) const return data(0, Qt::UserRole).toInt() > other.data(0, Qt::UserRole).toInt(); // Sort by name - return data(2, Qt::UserRole).toString().toLower() < other.data(2, Qt::UserRole).toString().toLower(); + return QString::localeAwareCompare(data(2, Qt::UserRole).toString(), other.data(2, Qt::UserRole).toString()) < 0; } UserList::UserList(TabSupervisor *_tabSupervisor, AbstractClient *_client, UserListType _type, QWidget *parent) From c09b0fcba77fa952bc6403a8f3892050cbd307e6 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Mon, 18 Jul 2011 16:29:06 +0200 Subject: [PATCH 4/4] CardDragItem fix --- cockatrice/src/carditem.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cockatrice/src/carditem.cpp b/cockatrice/src/carditem.cpp index afc15e8c..ae4c2950 100644 --- a/cockatrice/src/carditem.cpp +++ b/cockatrice/src/carditem.cpp @@ -394,8 +394,10 @@ CardDragItem *CardItem::createDragItem(int _id, const QPointF &_pos, const QPoin { deleteDragItem(); dragItem = new CardDragItem(this, _id, _pos, faceDown); + dragItem->setVisible(false); scene()->addItem(dragItem); dragItem->updatePosition(_scenePos); + dragItem->setVisible(true); return dragItem; }