aboutsummaryrefslogtreecommitdiff
path: root/src/Database/Common/getnumgames.cpp
blob: 14254279083eab54321a5e7d3f982f5134dcac10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "commonactions.h"

QHash<QString, int> getNumGames(const int &serverAge_s)
{
    QSqlQuery q;
    QHash<QString, int> numGames;

    // number of games
    q.prepare("SELECT count(gamename) FROM gameinfo");
    if ( ! q.exec() )
        reportQuery(q);
    if (q.next())
        numGames["numTotal"] = q.value(0).toInt();

    // number of active games
    QString selectString = "SELECT count(gamename) FROM gameinfo "
                           "WHERE num_direct > 0 "
                           "OR    num_total  > 0 ";
    q.prepare(selectString);
    q.bindValue(":timestamp", QDateTime::currentDateTime().addSecs(-serverAge_s ).toSecsSinceEpoch());
    if ( ! q.exec() )
        reportQuery(q);
    if (q.next())
        numGames["numActive"] = q.value(0).toInt();


    // TODO: get more relevant stats

    return numGames;
}