diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 58d02740..05b3c0d9 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -406,6 +406,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinRoom(Command_JoinRoom *cmd, CommandC if (!r) return RespNameNotFound; + QMutexLocker serverLocker(&server->serverMutex); QMutexLocker roomLocker(&r->roomMutex); r->addClient(this); rooms.insert(r->getId(), r); diff --git a/servatrice/src/main.cpp b/servatrice/src/main.cpp index 6c16c965..247111be 100644 --- a/servatrice/src/main.cpp +++ b/servatrice/src/main.cpp @@ -129,8 +129,8 @@ int main(int argc, char *argv[]) if (testRandom) testRNG(); - Servatrice server(settings); - QObject::connect(&server, SIGNAL(destroyed()), &app, SLOT(quit()), Qt::QueuedConnection); + Servatrice *server = new Servatrice(settings); + QObject::connect(server, SIGNAL(destroyed()), &app, SLOT(quit()), Qt::QueuedConnection); std::cerr << "-------------------------" << std::endl; std::cerr << "Server initialized." << std::endl; @@ -142,6 +142,7 @@ int main(int argc, char *argv[]) delete rng; delete settings; + delete loggerThread; return retval; } diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index e5f7afa6..97995e9f 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -66,7 +66,7 @@ Servatrice::Servatrice(QSettings *_settings, QObject *parent) } bool threaded = settings->value("server/threaded", false).toInt(); - tcpServer = new Servatrice_TcpServer(this, threaded); + tcpServer = new Servatrice_TcpServer(this, threaded, this); int port = settings->value("server/port", 4747).toInt(); qDebug() << "Starting server on port" << port; if (tcpServer->listen(QHostAddress::Any, port)) @@ -364,17 +364,20 @@ void Servatrice::updateLoginMessage() void Servatrice::statusUpdate() { - QMutexLocker locker(&dbMutex); + const int uc = getUsersCount(); // for correct mutex locking order + const int gc = getGamesCount(); + uptime += statusUpdateClock->interval() / 1000; + QMutexLocker locker(&dbMutex); checkSql(); QSqlQuery query; query.prepare("insert into " + dbPrefix + "_uptime (id_server, timest, uptime, users_count, games_count) values(:id, NOW(), :uptime, :users_count, :games_count)"); query.bindValue(":id", serverId); query.bindValue(":uptime", uptime); - query.bindValue(":users_count", getUsersCount()); - query.bindValue(":games_count", getGamesCount()); + query.bindValue(":users_count", uc); + query.bindValue(":games_count", gc); execSqlQuery(query); } diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index 4fe5bb3a..bf23290c 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -69,6 +69,7 @@ ServerSocketInterface::~ServerSocketInterface() delete xmlReader; delete socket; socket = 0; + delete topLevelItem; } void ServerSocketInterface::processProtocolItem(ProtocolItem *item)