Merge pull request #441 from woogerboy21/servatrice_trustedsources
Servatrice trustedsources
This commit is contained in:
commit
8b0d67ea5c
3 changed files with 631 additions and 613 deletions
|
@ -22,7 +22,7 @@ port=4747
|
||||||
; long delays (lag), you may want to try increasing this value; default is 1.
|
; long delays (lag), you may want to try increasing this value; default is 1.
|
||||||
number_pools=1
|
number_pools=1
|
||||||
|
|
||||||
; When database is enabled, servatrice writes the server status in the "update" database table; this
|
; When database is enabled, servatrice writes the server status in the "update" database table; this
|
||||||
; setting defines every how many milliseconds servatrice will update its status; default is 15000 (15 secs)
|
; setting defines every how many milliseconds servatrice will update its status; default is 15000 (15 secs)
|
||||||
statusupdate=15000
|
statusupdate=15000
|
||||||
|
|
||||||
|
@ -125,6 +125,11 @@ max_game_inactivity_time=120
|
||||||
; Maximum number of users that can connect from the same IP address; useful to avoid bots, default is 4
|
; Maximum number of users that can connect from the same IP address; useful to avoid bots, default is 4
|
||||||
max_users_per_address=4
|
max_users_per_address=4
|
||||||
|
|
||||||
|
; You may want to allow an unlimited number of users from a trusted source. This setting can contain a
|
||||||
|
; comma-separed list of IP addresses which will allow an unlimited number of connections from each of the
|
||||||
|
; IP addresses listed (ignoring the max_users_per_address). Default is "127.0.0.1,::1"; example: "192.73.233.244,81.4.100.74"
|
||||||
|
trusted_sources="127.0.0.1,::1"
|
||||||
|
|
||||||
; Servatrice can avoid users from flooding rooms with large number messages in an interval of time.
|
; Servatrice can avoid users from flooding rooms with large number messages in an interval of time.
|
||||||
; This setting defines the length in seconds of the considered interval; default is 10
|
; This setting defines the length in seconds of the considered interval; default is 10
|
||||||
message_counting_interval=10
|
message_counting_interval=10
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QString>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "servatrice.h"
|
#include "servatrice.h"
|
||||||
#include "servatrice_database_interface.h"
|
#include "servatrice_database_interface.h"
|
||||||
|
@ -45,25 +46,25 @@ Servatrice_GameServer::Servatrice_GameServer(Servatrice *_server, int _numberPoo
|
||||||
server->setThreaded(false);
|
server->setThreaded(false);
|
||||||
Servatrice_DatabaseInterface *newDatabaseInterface = new Servatrice_DatabaseInterface(0, server);
|
Servatrice_DatabaseInterface *newDatabaseInterface = new Servatrice_DatabaseInterface(0, server);
|
||||||
Servatrice_ConnectionPool *newPool = new Servatrice_ConnectionPool(newDatabaseInterface);
|
Servatrice_ConnectionPool *newPool = new Servatrice_ConnectionPool(newDatabaseInterface);
|
||||||
|
|
||||||
server->addDatabaseInterface(thread(), newDatabaseInterface);
|
server->addDatabaseInterface(thread(), newDatabaseInterface);
|
||||||
newDatabaseInterface->initDatabase(_sqlDatabase);
|
newDatabaseInterface->initDatabase(_sqlDatabase);
|
||||||
|
|
||||||
connectionPools.append(newPool);
|
connectionPools.append(newPool);
|
||||||
} else
|
} else
|
||||||
for (int i = 0; i < _numberPools; ++i) {
|
for (int i = 0; i < _numberPools; ++i) {
|
||||||
Servatrice_DatabaseInterface *newDatabaseInterface = new Servatrice_DatabaseInterface(i, server);
|
Servatrice_DatabaseInterface *newDatabaseInterface = new Servatrice_DatabaseInterface(i, server);
|
||||||
Servatrice_ConnectionPool *newPool = new Servatrice_ConnectionPool(newDatabaseInterface);
|
Servatrice_ConnectionPool *newPool = new Servatrice_ConnectionPool(newDatabaseInterface);
|
||||||
|
|
||||||
QThread *newThread = new QThread;
|
QThread *newThread = new QThread;
|
||||||
newThread->setObjectName("pool_" + QString::number(i));
|
newThread->setObjectName("pool_" + QString::number(i));
|
||||||
newPool->moveToThread(newThread);
|
newPool->moveToThread(newThread);
|
||||||
newDatabaseInterface->moveToThread(newThread);
|
newDatabaseInterface->moveToThread(newThread);
|
||||||
server->addDatabaseInterface(newThread, newDatabaseInterface);
|
server->addDatabaseInterface(newThread, newDatabaseInterface);
|
||||||
|
|
||||||
newThread->start();
|
newThread->start();
|
||||||
QMetaObject::invokeMethod(newDatabaseInterface, "initDatabase", Qt::BlockingQueuedConnection, Q_ARG(QSqlDatabase, _sqlDatabase));
|
QMetaObject::invokeMethod(newDatabaseInterface, "initDatabase", Qt::BlockingQueuedConnection, Q_ARG(QSqlDatabase, _sqlDatabase));
|
||||||
|
|
||||||
connectionPools.append(newPool);
|
connectionPools.append(newPool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,12 +99,12 @@ void Servatrice_GameServer::incomingConnection(qintptr socketDescriptor)
|
||||||
}
|
}
|
||||||
qDebug() << "Pool utilisation:" << debugStr;
|
qDebug() << "Pool utilisation:" << debugStr;
|
||||||
Servatrice_ConnectionPool *pool = connectionPools[poolIndex];
|
Servatrice_ConnectionPool *pool = connectionPools[poolIndex];
|
||||||
|
|
||||||
ServerSocketInterface *ssi = new ServerSocketInterface(server, pool->getDatabaseInterface());
|
ServerSocketInterface *ssi = new ServerSocketInterface(server, pool->getDatabaseInterface());
|
||||||
ssi->moveToThread(pool->thread());
|
ssi->moveToThread(pool->thread());
|
||||||
pool->addClient();
|
pool->addClient();
|
||||||
connect(ssi, SIGNAL(destroyed()), pool, SLOT(removeClient()));
|
connect(ssi, SIGNAL(destroyed()), pool, SLOT(removeClient()));
|
||||||
|
|
||||||
QMetaObject::invokeMethod(ssi, "initConnection", Qt::QueuedConnection, Q_ARG(int, socketDescriptor));
|
QMetaObject::invokeMethod(ssi, "initConnection", Qt::QueuedConnection, Q_ARG(int, socketDescriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,11 +112,11 @@ void Servatrice_IslServer::incomingConnection(int socketDescriptor)
|
||||||
{
|
{
|
||||||
QThread *thread = new QThread;
|
QThread *thread = new QThread;
|
||||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||||
|
|
||||||
IslInterface *interface = new IslInterface(socketDescriptor, cert, privateKey, server);
|
IslInterface *interface = new IslInterface(socketDescriptor, cert, privateKey, server);
|
||||||
interface->moveToThread(thread);
|
interface->moveToThread(thread);
|
||||||
connect(interface, SIGNAL(destroyed()), thread, SLOT(quit()));
|
connect(interface, SIGNAL(destroyed()), thread, SLOT(quit()));
|
||||||
|
|
||||||
thread->start();
|
thread->start();
|
||||||
QMetaObject::invokeMethod(interface, "initServer", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(interface, "initServer", Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
@ -137,7 +138,7 @@ bool Servatrice::initServer()
|
||||||
serverName = settingsCache->value("server/name", "My Cockatrice server").toString();
|
serverName = settingsCache->value("server/name", "My Cockatrice server").toString();
|
||||||
serverId = settingsCache->value("server/id", 0).toInt();
|
serverId = settingsCache->value("server/id", 0).toInt();
|
||||||
bool regServerOnly = settingsCache->value("authentication/regonly", 0).toBool();
|
bool regServerOnly = settingsCache->value("authentication/regonly", 0).toBool();
|
||||||
|
|
||||||
const QString authenticationMethodStr = settingsCache->value("authentication/method").toString();
|
const QString authenticationMethodStr = settingsCache->value("authentication/method").toString();
|
||||||
if (authenticationMethodStr == "sql") {
|
if (authenticationMethodStr == "sql") {
|
||||||
qDebug() << "Authenticating method: sql";
|
qDebug() << "Authenticating method: sql";
|
||||||
|
@ -148,22 +149,22 @@ bool Servatrice::initServer()
|
||||||
} else {
|
} else {
|
||||||
if (regServerOnly) {
|
if (regServerOnly) {
|
||||||
qDebug() << "Registration only server enabled but no authentication method defined: Error.";
|
qDebug() << "Registration only server enabled but no authentication method defined: Error.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Authenticating method: none";
|
qDebug() << "Authenticating method: none";
|
||||||
authenticationMethod = AuthenticationNone;
|
authenticationMethod = AuthenticationNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString dbTypeStr = settingsCache->value("database/type").toString();
|
QString dbTypeStr = settingsCache->value("database/type").toString();
|
||||||
if (dbTypeStr == "mysql")
|
if (dbTypeStr == "mysql")
|
||||||
databaseType = DatabaseMySql;
|
databaseType = DatabaseMySql;
|
||||||
else
|
else
|
||||||
databaseType = DatabaseNone;
|
databaseType = DatabaseNone;
|
||||||
|
|
||||||
servatriceDatabaseInterface = new Servatrice_DatabaseInterface(-1, this);
|
servatriceDatabaseInterface = new Servatrice_DatabaseInterface(-1, this);
|
||||||
setDatabaseInterface(servatriceDatabaseInterface);
|
setDatabaseInterface(servatriceDatabaseInterface);
|
||||||
|
|
||||||
if (databaseType != DatabaseNone) {
|
if (databaseType != DatabaseNone) {
|
||||||
settingsCache->beginGroup("database");
|
settingsCache->beginGroup("database");
|
||||||
dbPrefix = settingsCache->value("prefix").toString();
|
dbPrefix = settingsCache->value("prefix").toString();
|
||||||
|
@ -173,13 +174,13 @@ bool Servatrice::initServer()
|
||||||
settingsCache->value("user").toString(),
|
settingsCache->value("user").toString(),
|
||||||
settingsCache->value("password").toString());
|
settingsCache->value("password").toString());
|
||||||
settingsCache->endGroup();
|
settingsCache->endGroup();
|
||||||
|
|
||||||
updateServerList();
|
updateServerList();
|
||||||
|
|
||||||
qDebug() << "Clearing previous sessions...";
|
qDebug() << "Clearing previous sessions...";
|
||||||
servatriceDatabaseInterface->clearSessionTables();
|
servatriceDatabaseInterface->clearSessionTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString roomMethod = settingsCache->value("rooms/method").toString();
|
const QString roomMethod = settingsCache->value("rooms/method").toString();
|
||||||
if (roomMethod == "sql") {
|
if (roomMethod == "sql") {
|
||||||
QSqlQuery query(servatriceDatabaseInterface->getDatabase());
|
QSqlQuery query(servatriceDatabaseInterface->getDatabase());
|
||||||
|
@ -193,7 +194,7 @@ bool Servatrice::initServer()
|
||||||
QStringList gameTypes;
|
QStringList gameTypes;
|
||||||
while (query2.next())
|
while (query2.next())
|
||||||
gameTypes.append(query2.value(0).toString());
|
gameTypes.append(query2.value(0).toString());
|
||||||
|
|
||||||
addRoom(new Server_Room(query.value(0).toInt(),
|
addRoom(new Server_Room(query.value(0).toInt(),
|
||||||
query.value(1).toString(),
|
query.value(1).toString(),
|
||||||
query.value(2).toString(),
|
query.value(2).toString(),
|
||||||
|
@ -207,7 +208,7 @@ bool Servatrice::initServer()
|
||||||
int size = settingsCache->beginReadArray("rooms/roomlist");
|
int size = settingsCache->beginReadArray("rooms/roomlist");
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
settingsCache->setArrayIndex(i);
|
settingsCache->setArrayIndex(i);
|
||||||
|
|
||||||
QStringList gameTypes;
|
QStringList gameTypes;
|
||||||
int size2 = settingsCache->beginReadArray("game_types");
|
int size2 = settingsCache->beginReadArray("game_types");
|
||||||
for (int j = 0; j < size2; ++j) {
|
for (int j = 0; j < size2; ++j) {
|
||||||
|
@ -215,7 +216,7 @@ bool Servatrice::initServer()
|
||||||
gameTypes.append(settingsCache->value("name").toString());
|
gameTypes.append(settingsCache->value("name").toString());
|
||||||
}
|
}
|
||||||
settingsCache->endArray();
|
settingsCache->endArray();
|
||||||
|
|
||||||
Server_Room *newRoom = new Server_Room(
|
Server_Room *newRoom = new Server_Room(
|
||||||
i,
|
i,
|
||||||
settingsCache->value("name").toString(),
|
settingsCache->value("name").toString(),
|
||||||
|
@ -240,17 +241,17 @@ bool Servatrice::initServer()
|
||||||
QStringList("Standard"),
|
QStringList("Standard"),
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
addRoom(newRoom);
|
addRoom(newRoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
settingsCache->endArray();
|
settingsCache->endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLoginMessage();
|
updateLoginMessage();
|
||||||
|
|
||||||
maxGameInactivityTime = settingsCache->value("game/max_game_inactivity_time", 120).toInt();
|
maxGameInactivityTime = settingsCache->value("game/max_game_inactivity_time", 120).toInt();
|
||||||
maxPlayerInactivityTime = settingsCache->value("game/max_player_inactivity_time", 15).toInt();
|
maxPlayerInactivityTime = settingsCache->value("game/max_player_inactivity_time", 15).toInt();
|
||||||
|
|
||||||
maxUsersPerAddress = settingsCache->value("security/max_users_per_address", 4).toInt();
|
maxUsersPerAddress = settingsCache->value("security/max_users_per_address", 4).toInt();
|
||||||
messageCountingInterval = settingsCache->value("security/message_counting_interval", 10).toInt();
|
messageCountingInterval = settingsCache->value("security/message_counting_interval", 10).toInt();
|
||||||
maxMessageCountPerInterval = settingsCache->value("security/max_message_count_per_interval", 10).toInt();
|
maxMessageCountPerInterval = settingsCache->value("security/max_message_count_per_interval", 10).toInt();
|
||||||
|
@ -283,7 +284,7 @@ bool Servatrice::initServer()
|
||||||
QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
|
QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
|
||||||
if (key.isNull())
|
if (key.isNull())
|
||||||
throw QString("Invalid private key.");
|
throw QString("Invalid private key.");
|
||||||
|
|
||||||
QMutableListIterator<ServerProperties> serverIterator(serverList);
|
QMutableListIterator<ServerProperties> serverIterator(serverList);
|
||||||
while (serverIterator.hasNext()) {
|
while (serverIterator.hasNext()) {
|
||||||
const ServerProperties &prop = serverIterator.next();
|
const ServerProperties &prop = serverIterator.next();
|
||||||
|
@ -291,22 +292,22 @@ bool Servatrice::initServer()
|
||||||
serverIterator.remove();
|
serverIterator.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QThread *thread = new QThread;
|
QThread *thread = new QThread;
|
||||||
thread->setObjectName("isl_" + QString::number(prop.id));
|
thread->setObjectName("isl_" + QString::number(prop.id));
|
||||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||||
|
|
||||||
IslInterface *interface = new IslInterface(prop.id, prop.hostname, prop.address.toString(), prop.controlPort, prop.cert, cert, key, this);
|
IslInterface *interface = new IslInterface(prop.id, prop.hostname, prop.address.toString(), prop.controlPort, prop.cert, cert, key, this);
|
||||||
interface->moveToThread(thread);
|
interface->moveToThread(thread);
|
||||||
connect(interface, SIGNAL(destroyed()), thread, SLOT(quit()));
|
connect(interface, SIGNAL(destroyed()), thread, SLOT(quit()));
|
||||||
|
|
||||||
thread->start();
|
thread->start();
|
||||||
QMetaObject::invokeMethod(interface, "initClient", Qt::BlockingQueuedConnection);
|
QMetaObject::invokeMethod(interface, "initClient", Qt::BlockingQueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int networkPort = settingsCache->value("servernetwork/port", 14747).toInt();
|
const int networkPort = settingsCache->value("servernetwork/port", 14747).toInt();
|
||||||
qDebug() << "Starting ISL server on port" << networkPort;
|
qDebug() << "Starting ISL server on port" << networkPort;
|
||||||
|
|
||||||
islServer = new Servatrice_IslServer(this, cert, key, this);
|
islServer = new Servatrice_IslServer(this, cert, key, this);
|
||||||
if (islServer->listen(QHostAddress::Any, networkPort))
|
if (islServer->listen(QHostAddress::Any, networkPort))
|
||||||
qDebug() << "ISL server listening.";
|
qDebug() << "ISL server listening.";
|
||||||
|
@ -316,11 +317,11 @@ bool Servatrice::initServer()
|
||||||
qDebug() << "ERROR --" << error;
|
qDebug() << "ERROR --" << error;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pingClock = new QTimer(this);
|
pingClock = new QTimer(this);
|
||||||
connect(pingClock, SIGNAL(timeout()), this, SIGNAL(pingClockTimeout()));
|
connect(pingClock, SIGNAL(timeout()), this, SIGNAL(pingClockTimeout()));
|
||||||
pingClock->start(1000);
|
pingClock->start(1000);
|
||||||
|
|
||||||
int statusUpdateTime = settingsCache->value("server/statusupdate", 15000).toInt();
|
int statusUpdateTime = settingsCache->value("server/statusupdate", 15000).toInt();
|
||||||
statusUpdateClock = new QTimer(this);
|
statusUpdateClock = new QTimer(this);
|
||||||
connect(statusUpdateClock, SIGNAL(timeout()), this, SLOT(statusUpdate()));
|
connect(statusUpdateClock, SIGNAL(timeout()), this, SLOT(statusUpdate()));
|
||||||
|
@ -328,7 +329,7 @@ bool Servatrice::initServer()
|
||||||
qDebug() << "Starting status update clock, interval " << statusUpdateTime << " ms";
|
qDebug() << "Starting status update clock, interval " << statusUpdateTime << " ms";
|
||||||
statusUpdateClock->start(statusUpdateTime);
|
statusUpdateClock->start(statusUpdateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int numberPools = settingsCache->value("server/number_pools", 1).toInt();
|
const int numberPools = settingsCache->value("server/number_pools", 1).toInt();
|
||||||
gameServer = new Servatrice_GameServer(this, numberPools, servatriceDatabaseInterface->getDatabase(), this);
|
gameServer = new Servatrice_GameServer(this, numberPools, servatriceDatabaseInterface->getDatabase(), this);
|
||||||
gameServer->setMaxPendingConnections(1000);
|
gameServer->setMaxPendingConnections(1000);
|
||||||
|
@ -351,10 +352,10 @@ void Servatrice::addDatabaseInterface(QThread *thread, Servatrice_DatabaseInterf
|
||||||
void Servatrice::updateServerList()
|
void Servatrice::updateServerList()
|
||||||
{
|
{
|
||||||
qDebug() << "Updating server list...";
|
qDebug() << "Updating server list...";
|
||||||
|
|
||||||
serverListMutex.lock();
|
serverListMutex.lock();
|
||||||
serverList.clear();
|
serverList.clear();
|
||||||
|
|
||||||
QSqlQuery query(servatriceDatabaseInterface->getDatabase());
|
QSqlQuery query(servatriceDatabaseInterface->getDatabase());
|
||||||
query.prepare("select id, ssl_cert, hostname, address, game_port, control_port from " + dbPrefix + "_servers order by id asc");
|
query.prepare("select id, ssl_cert, hostname, address, game_port, control_port from " + dbPrefix + "_servers order by id asc");
|
||||||
servatriceDatabaseInterface->execSqlQuery(query);
|
servatriceDatabaseInterface->execSqlQuery(query);
|
||||||
|
@ -363,7 +364,7 @@ void Servatrice::updateServerList()
|
||||||
serverList.append(prop);
|
serverList.append(prop);
|
||||||
qDebug() << QString("#%1 CERT=%2 NAME=%3 IP=%4:%5 CPORT=%6").arg(prop.id).arg(QString(prop.cert.digest().toHex())).arg(prop.hostname).arg(prop.address.toString()).arg(prop.gamePort).arg(prop.controlPort);
|
qDebug() << QString("#%1 CERT=%2 NAME=%3 IP=%4:%5 CPORT=%6").arg(prop.id).arg(QString(prop.cert.digest().toHex())).arg(prop.hostname).arg(prop.address.toString()).arg(prop.gamePort).arg(prop.controlPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
serverListMutex.unlock();
|
serverListMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,7 +373,7 @@ QList<ServerProperties> Servatrice::getServerList() const
|
||||||
serverListMutex.lock();
|
serverListMutex.lock();
|
||||||
QList<ServerProperties> result = serverList;
|
QList<ServerProperties> result = serverList;
|
||||||
serverListMutex.unlock();
|
serverListMutex.unlock();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,8 +382,9 @@ int Servatrice::getUsersWithAddress(const QHostAddress &address) const
|
||||||
int result = 0;
|
int result = 0;
|
||||||
QReadLocker locker(&clientsLock);
|
QReadLocker locker(&clientsLock);
|
||||||
for (int i = 0; i < clients.size(); ++i)
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
if (static_cast<ServerSocketInterface *>(clients[i])->getPeerAddress() == address)
|
if (static_cast<ServerSocketInterface *>(clients[i])->getPeerAddress() == address)
|
||||||
++result;
|
++result;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,18 +402,18 @@ void Servatrice::updateLoginMessage()
|
||||||
{
|
{
|
||||||
if (!servatriceDatabaseInterface->checkSql())
|
if (!servatriceDatabaseInterface->checkSql())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QSqlQuery query(servatriceDatabaseInterface->getDatabase());
|
QSqlQuery query(servatriceDatabaseInterface->getDatabase());
|
||||||
query.prepare("select message from " + dbPrefix + "_servermessages where id_server = :id_server order by timest desc limit 1");
|
query.prepare("select message from " + dbPrefix + "_servermessages where id_server = :id_server order by timest desc limit 1");
|
||||||
query.bindValue(":id_server", serverId);
|
query.bindValue(":id_server", serverId);
|
||||||
if (servatriceDatabaseInterface->execSqlQuery(query))
|
if (servatriceDatabaseInterface->execSqlQuery(query))
|
||||||
if (query.next()) {
|
if (query.next()) {
|
||||||
const QString newLoginMessage = query.value(0).toString();
|
const QString newLoginMessage = query.value(0).toString();
|
||||||
|
|
||||||
loginMessageMutex.lock();
|
loginMessageMutex.lock();
|
||||||
loginMessage = newLoginMessage;
|
loginMessage = newLoginMessage;
|
||||||
loginMessageMutex.unlock();
|
loginMessageMutex.unlock();
|
||||||
|
|
||||||
Event_ServerMessage event;
|
Event_ServerMessage event;
|
||||||
event.set_message(newLoginMessage.toStdString());
|
event.set_message(newLoginMessage.toStdString());
|
||||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||||
|
@ -426,12 +428,12 @@ void Servatrice::statusUpdate()
|
||||||
{
|
{
|
||||||
if (!servatriceDatabaseInterface->checkSql())
|
if (!servatriceDatabaseInterface->checkSql())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int uc = getUsersCount(); // for correct mutex locking order
|
const int uc = getUsersCount(); // for correct mutex locking order
|
||||||
const int gc = getGamesCount();
|
const int gc = getGamesCount();
|
||||||
|
|
||||||
uptime += statusUpdateClock->interval() / 1000;
|
uptime += statusUpdateClock->interval() / 1000;
|
||||||
|
|
||||||
txBytesMutex.lock();
|
txBytesMutex.lock();
|
||||||
quint64 tx = txBytes;
|
quint64 tx = txBytes;
|
||||||
txBytes = 0;
|
txBytes = 0;
|
||||||
|
@ -440,7 +442,7 @@ void Servatrice::statusUpdate()
|
||||||
quint64 rx = rxBytes;
|
quint64 rx = rxBytes;
|
||||||
rxBytes = 0;
|
rxBytes = 0;
|
||||||
rxBytesMutex.unlock();
|
rxBytesMutex.unlock();
|
||||||
|
|
||||||
QSqlQuery query(servatriceDatabaseInterface->getDatabase());
|
QSqlQuery query(servatriceDatabaseInterface->getDatabase());
|
||||||
query.prepare("insert into " + dbPrefix + "_uptime (id_server, timest, uptime, users_count, games_count, tx_bytes, rx_bytes) values(:id, NOW(), :uptime, :users_count, :games_count, :tx, :rx)");
|
query.prepare("insert into " + dbPrefix + "_uptime (id_server, timest, uptime, users_count, games_count, tx_bytes, rx_bytes) values(:id, NOW(), :uptime, :users_count, :games_count, :tx, :rx)");
|
||||||
query.bindValue(":id", serverId);
|
query.bindValue(":id", serverId);
|
||||||
|
@ -481,7 +483,7 @@ void Servatrice::incRxBytes(quint64 num)
|
||||||
void Servatrice::shutdownTimeout()
|
void Servatrice::shutdownTimeout()
|
||||||
{
|
{
|
||||||
--shutdownMinutes;
|
--shutdownMinutes;
|
||||||
|
|
||||||
SessionEvent *se;
|
SessionEvent *se;
|
||||||
if (shutdownMinutes) {
|
if (shutdownMinutes) {
|
||||||
Event_ServerShutdown event;
|
Event_ServerShutdown event;
|
||||||
|
@ -493,13 +495,13 @@ void Servatrice::shutdownTimeout()
|
||||||
event.set_reason(Event_ConnectionClosed::SERVER_SHUTDOWN);
|
event.set_reason(Event_ConnectionClosed::SERVER_SHUTDOWN);
|
||||||
se = Server_ProtocolHandler::prepareSessionEvent(event);
|
se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
clientsLock.lockForRead();
|
clientsLock.lockForRead();
|
||||||
for (int i = 0; i < clients.size(); ++i)
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
clients[i]->sendProtocolItem(*se);
|
clients[i]->sendProtocolItem(*se);
|
||||||
clientsLock.unlock();
|
clientsLock.unlock();
|
||||||
delete se;
|
delete se;
|
||||||
|
|
||||||
if (!shutdownMinutes)
|
if (!shutdownMinutes)
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
@ -507,14 +509,14 @@ void Servatrice::shutdownTimeout()
|
||||||
bool Servatrice::islConnectionExists(int serverId) const
|
bool Servatrice::islConnectionExists(int serverId) const
|
||||||
{
|
{
|
||||||
// Only call with islLock locked at least for reading
|
// Only call with islLock locked at least for reading
|
||||||
|
|
||||||
return islInterfaces.contains(serverId);
|
return islInterfaces.contains(serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Servatrice::addIslInterface(int serverId, IslInterface *interface)
|
void Servatrice::addIslInterface(int serverId, IslInterface *interface)
|
||||||
{
|
{
|
||||||
// Only call with islLock locked for writing
|
// Only call with islLock locked for writing
|
||||||
|
|
||||||
islInterfaces.insert(serverId, interface);
|
islInterfaces.insert(serverId, interface);
|
||||||
connect(interface, SIGNAL(externalUserJoined(ServerInfo_User)), this, SLOT(externalUserJoined(ServerInfo_User)));
|
connect(interface, SIGNAL(externalUserJoined(ServerInfo_User)), this, SLOT(externalUserJoined(ServerInfo_User)));
|
||||||
connect(interface, SIGNAL(externalUserLeft(QString)), this, SLOT(externalUserLeft(QString)));
|
connect(interface, SIGNAL(externalUserLeft(QString)), this, SLOT(externalUserLeft(QString)));
|
||||||
|
@ -531,7 +533,7 @@ void Servatrice::addIslInterface(int serverId, IslInterface *interface)
|
||||||
void Servatrice::removeIslInterface(int serverId)
|
void Servatrice::removeIslInterface(int serverId)
|
||||||
{
|
{
|
||||||
// Only call with islLock locked for writing
|
// Only call with islLock locked for writing
|
||||||
|
|
||||||
// XXX we probably need to delete everything that belonged to it...
|
// XXX we probably need to delete everything that belonged to it...
|
||||||
islInterfaces.remove(serverId);
|
islInterfaces.remove(serverId);
|
||||||
}
|
}
|
||||||
|
@ -539,7 +541,7 @@ void Servatrice::removeIslInterface(int serverId)
|
||||||
void Servatrice::doSendIslMessage(const IslMessage &msg, int serverId)
|
void Servatrice::doSendIslMessage(const IslMessage &msg, int serverId)
|
||||||
{
|
{
|
||||||
QReadLocker locker(&islLock);
|
QReadLocker locker(&islLock);
|
||||||
|
|
||||||
if (serverId == -1) {
|
if (serverId == -1) {
|
||||||
QMapIterator<int, IslInterface *> islIterator(islInterfaces);
|
QMapIterator<int, IslInterface *> islIterator(islInterfaces);
|
||||||
while (islIterator.hasNext())
|
while (islIterator.hasNext())
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue