mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 12:03:25 -08:00
[Server] Record uptime through the database interface (#7856)
This commit is contained in:
parent
f1ee6bdc2d
commit
09d0bed997
4 changed files with 49 additions and 13 deletions
|
|
@ -733,6 +733,23 @@ public:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief One row the periodic status update appends to the uptime table. */
|
||||||
|
struct UptimeRecord
|
||||||
|
{
|
||||||
|
int serverId = 0;
|
||||||
|
int uptimeSecs = 0;
|
||||||
|
int usersCount = 0;
|
||||||
|
int modsCount = 0;
|
||||||
|
QString modsList;
|
||||||
|
int gamesCount = 0;
|
||||||
|
quint64 txBytes = 0;
|
||||||
|
quint64 rxBytes = 0;
|
||||||
|
};
|
||||||
|
/** @brief Appends one uptime row; a no-op when persistence is unavailable. */
|
||||||
|
virtual void recordUptime(const UptimeRecord & /* record */)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
virtual void clearSessionTables()
|
virtual void clearSessionTables()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -879,19 +879,16 @@ void Servatrice::statusUpdate()
|
||||||
rxBytes = 0;
|
rxBytes = 0;
|
||||||
rxBytesMutex.unlock();
|
rxBytesMutex.unlock();
|
||||||
|
|
||||||
QSqlQuery *query = servatriceDatabaseInterface->prepareQuery(
|
Server_DatabaseInterface::UptimeRecord uptimeRecord;
|
||||||
"insert into {prefix}_uptime (id_server, timest, uptime, users_count, mods_count, mods_list, games_count, "
|
uptimeRecord.serverId = serverId;
|
||||||
"tx_bytes, rx_bytes) values(:id, NOW(), :uptime, :users_count, :mods_count, :mods_list, :games_count, :tx, "
|
uptimeRecord.uptimeSecs = uptime;
|
||||||
":rx)");
|
uptimeRecord.usersCount = uc;
|
||||||
query->bindValue(":id", serverId);
|
uptimeRecord.modsCount = mc;
|
||||||
query->bindValue(":uptime", uptime);
|
uptimeRecord.modsList = ml;
|
||||||
query->bindValue(":users_count", uc);
|
uptimeRecord.gamesCount = gc;
|
||||||
query->bindValue(":mods_count", mc);
|
uptimeRecord.txBytes = tx;
|
||||||
query->bindValue(":mods_list", ml);
|
uptimeRecord.rxBytes = rx;
|
||||||
query->bindValue(":games_count", gc);
|
servatriceDatabaseInterface->recordUptime(uptimeRecord);
|
||||||
query->bindValue(":tx", tx);
|
|
||||||
query->bindValue(":rx", rx);
|
|
||||||
servatriceDatabaseInterface->execSqlQuery(query);
|
|
||||||
|
|
||||||
if (getRegistrationEnabled() && getEnableInternalSMTPClient()) {
|
if (getRegistrationEnabled() && getEnableInternalSMTPClient()) {
|
||||||
if (getRequireEmailActivationEnabled()) {
|
if (getRequireEmailActivationEnabled()) {
|
||||||
|
|
|
||||||
|
|
@ -3337,6 +3337,27 @@ QList<Server_DatabaseInterface::ServerListEntryRecord> Servatrice_DatabaseInterf
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Servatrice_DatabaseInterface::recordUptime(const UptimeRecord &record)
|
||||||
|
{
|
||||||
|
if (!checkSql()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSqlQuery *query = prepareQuery(
|
||||||
|
"insert into {prefix}_uptime (id_server, timest, uptime, users_count, mods_count, mods_list, games_count, "
|
||||||
|
"tx_bytes, rx_bytes) values(:id, NOW(), :uptime, :users_count, :mods_count, :mods_list, :games_count, :tx, "
|
||||||
|
":rx)");
|
||||||
|
query->bindValue(":id", record.serverId);
|
||||||
|
query->bindValue(":uptime", record.uptimeSecs);
|
||||||
|
query->bindValue(":users_count", record.usersCount);
|
||||||
|
query->bindValue(":mods_count", record.modsCount);
|
||||||
|
query->bindValue(":mods_list", record.modsList);
|
||||||
|
query->bindValue(":games_count", record.gamesCount);
|
||||||
|
query->bindValue(":tx", record.txBytes);
|
||||||
|
query->bindValue(":rx", record.rxBytes);
|
||||||
|
execSqlQuery(query);
|
||||||
|
}
|
||||||
|
|
||||||
bool Servatrice_DatabaseInterface::removeUserAvatar(const QString &userName)
|
bool Servatrice_DatabaseInterface::removeUserAvatar(const QString &userName)
|
||||||
{
|
{
|
||||||
if (!checkSql()) {
|
if (!checkSql()) {
|
||||||
|
|
|
||||||
|
|
@ -280,6 +280,7 @@ public:
|
||||||
UptimeSnapshot getLatestUptimeSnapshot(int serverId) override;
|
UptimeSnapshot getLatestUptimeSnapshot(int serverId) override;
|
||||||
bool getLatestServerMessage(int serverId, QString &message) override;
|
bool getLatestServerMessage(int serverId, QString &message) override;
|
||||||
QList<ServerListEntryRecord> getServerListEntries() override;
|
QList<ServerListEntryRecord> getServerListEntries() override;
|
||||||
|
void recordUptime(const UptimeRecord &record) override;
|
||||||
bool removeUserAvatar(const QString &userName) override;
|
bool removeUserAvatar(const QString &userName) override;
|
||||||
// Outcome of removeUserBanner(), so the caller can tell a missing user apart
|
// Outcome of removeUserBanner(), so the caller can tell a missing user apart
|
||||||
// from a user who simply has no banner card set.
|
// from a user who simply has no banner card set.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue