server status information table
This commit is contained in:
parent
3573f74313
commit
6b0c644d2f
4 changed files with 33 additions and 5 deletions
|
@ -38,12 +38,12 @@ public:
|
||||||
virtual bool getGameShouldPing() const = 0;
|
virtual bool getGameShouldPing() const = 0;
|
||||||
virtual int getMaxGameInactivityTime() const = 0;
|
virtual int getMaxGameInactivityTime() const = 0;
|
||||||
virtual int getMaxPlayerInactivityTime() const = 0;
|
virtual int getMaxPlayerInactivityTime() const = 0;
|
||||||
private:
|
protected:
|
||||||
QMap<int, Server_Game *> games;
|
QMap<int, Server_Game *> games;
|
||||||
QList<Server_ProtocolHandler *> clients;
|
QList<Server_ProtocolHandler *> clients;
|
||||||
QMap<QString, Server_ProtocolHandler *> users;
|
QMap<QString, Server_ProtocolHandler *> users;
|
||||||
QMap<QString, Server_ChatChannel *> chatChannels;
|
QMap<QString, Server_ChatChannel *> chatChannels;
|
||||||
protected:
|
|
||||||
virtual AuthenticationResult checkUserPassword(const QString &user, const QString &password) = 0;
|
virtual AuthenticationResult checkUserPassword(const QString &user, const QString &password) = 0;
|
||||||
virtual ServerInfo_User *getUserData(const QString &name) = 0;
|
virtual ServerInfo_User *getUserData(const QString &name) = 0;
|
||||||
int nextGameId;
|
int nextGameId;
|
||||||
|
|
|
@ -111,3 +111,11 @@ CREATE TABLE IF NOT EXISTS `users` (
|
||||||
`token` char(32) NOT NULL,
|
`token` char(32) NOT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=915 ;
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=915 ;
|
||||||
|
|
||||||
|
CREATE TABLE `cockatrice_uptime` (
|
||||||
|
`timest` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||||
|
`uptime` int(11) DEFAULT NULL,
|
||||||
|
`users_count` int(11) DEFAULT NULL,
|
||||||
|
`games_count` int(11) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`timest`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
|
@ -27,12 +27,16 @@
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
|
||||||
Servatrice::Servatrice(QObject *parent)
|
Servatrice::Servatrice(QObject *parent)
|
||||||
: Server(parent)
|
: Server(parent), uptime(0)
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
|
||||||
|
statusUpdateClock = new QTimer(this);
|
||||||
|
connect(statusUpdateClock, SIGNAL(timeout()), this, SLOT(statusUpdate()));
|
||||||
|
statusUpdateClock->start(15000);
|
||||||
|
|
||||||
ProtocolItem::initializeHash();
|
ProtocolItem::initializeHash();
|
||||||
settings = new QSettings("servatrice.ini", QSettings::IniFormat, this);
|
settings = new QSettings("servatrice.ini", QSettings::IniFormat, this);
|
||||||
|
|
||||||
|
@ -179,4 +183,18 @@ ServerInfo_User *Servatrice::getUserData(const QString &name)
|
||||||
return new ServerInfo_User(name, ServerInfo_User::IsUser);
|
return new ServerInfo_User(name, ServerInfo_User::IsUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString Servatrice::versionString = "Servatrice 0.20101103";
|
void Servatrice::statusUpdate()
|
||||||
|
{
|
||||||
|
uptime += statusUpdateClock->interval() / 1000;
|
||||||
|
|
||||||
|
checkSql();
|
||||||
|
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare("insert into " + dbPrefix + "_uptime (timest, uptime, users_count, games_count) values(NOW(), :uptime, :users_count, :games_count)");
|
||||||
|
query.bindValue(":uptime", uptime);
|
||||||
|
query.bindValue(":users_count", users.size());
|
||||||
|
query.bindValue(":games_count", games.size());
|
||||||
|
execSqlQuery(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString Servatrice::versionString = "Servatrice 0.20101116";
|
||||||
|
|
|
@ -33,6 +33,7 @@ class Servatrice : public Server
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void newConnection();
|
void newConnection();
|
||||||
|
void statusUpdate();
|
||||||
public:
|
public:
|
||||||
static const QString versionString;
|
static const QString versionString;
|
||||||
Servatrice(QObject *parent = 0);
|
Servatrice(QObject *parent = 0);
|
||||||
|
@ -49,11 +50,12 @@ protected:
|
||||||
AuthenticationResult checkUserPassword(const QString &user, const QString &password);
|
AuthenticationResult checkUserPassword(const QString &user, const QString &password);
|
||||||
ServerInfo_User *getUserData(const QString &name);
|
ServerInfo_User *getUserData(const QString &name);
|
||||||
private:
|
private:
|
||||||
QTimer *pingClock;
|
QTimer *pingClock, *statusUpdateClock;
|
||||||
QTcpServer *tcpServer;
|
QTcpServer *tcpServer;
|
||||||
QString loginMessage;
|
QString loginMessage;
|
||||||
QString dbPrefix;
|
QString dbPrefix;
|
||||||
QSettings *settings;
|
QSettings *settings;
|
||||||
|
int uptime;
|
||||||
int maxGameInactivityTime;
|
int maxGameInactivityTime;
|
||||||
int maxPlayerInactivityTime;
|
int maxPlayerInactivityTime;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue