mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 03:53:26 -08:00
[Server] Serve the server list through the database interface (#7855)
This commit is contained in:
parent
f8f8fffa6b
commit
f1ee6bdc2d
4 changed files with 47 additions and 7 deletions
|
|
@ -717,6 +717,21 @@ public:
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/** @brief One row of the server list, with the certificate exactly as stored. */
|
||||||
|
struct ServerListEntryRecord
|
||||||
|
{
|
||||||
|
int id = 0;
|
||||||
|
QByteArray sslCert;
|
||||||
|
QString hostname;
|
||||||
|
QString address;
|
||||||
|
int gamePort = 0;
|
||||||
|
int controlPort = 0;
|
||||||
|
};
|
||||||
|
/** @brief Every published server-list row, in id order; empty when the query fails. */
|
||||||
|
virtual QList<ServerListEntryRecord> getServerListEntries()
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
virtual void clearSessionTables()
|
virtual void clearSessionTables()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -743,13 +743,10 @@ void Servatrice::updateServerList()
|
||||||
serverListMutex.lock();
|
serverListMutex.lock();
|
||||||
serverList.clear();
|
serverList.clear();
|
||||||
|
|
||||||
QSqlQuery *query = servatriceDatabaseInterface->prepareQuery(
|
const auto serverListEntries = servatriceDatabaseInterface->getServerListEntries();
|
||||||
"select id, ssl_cert, hostname, address, game_port, control_port from {prefix}_servers order by id asc");
|
for (const auto &entry : serverListEntries) {
|
||||||
servatriceDatabaseInterface->execSqlQuery(query);
|
ServerProperties prop(entry.id, QSslCertificate(entry.sslCert), entry.hostname, QHostAddress(entry.address),
|
||||||
while (query->next()) {
|
entry.gamePort, entry.controlPort);
|
||||||
ServerProperties prop(query->value(0).toInt(), QSslCertificate(query->value(1).toString().toUtf8()),
|
|
||||||
query->value(2).toString(), QHostAddress(query->value(3).toString()),
|
|
||||||
query->value(4).toInt(), query->value(5).toInt());
|
|
||||||
serverList.append(prop);
|
serverList.append(prop);
|
||||||
qDebug() << QString("#%1 CERT=%2 NAME=%3 IP=%4:%5 CPORT=%6")
|
qDebug() << QString("#%1 CERT=%2 NAME=%3 IP=%4:%5 CPORT=%6")
|
||||||
.arg(prop.id)
|
.arg(prop.id)
|
||||||
|
|
|
||||||
|
|
@ -3310,6 +3310,33 @@ bool Servatrice_DatabaseInterface::getLatestServerMessage(int serverId, QString
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Server_DatabaseInterface::ServerListEntryRecord> Servatrice_DatabaseInterface::getServerListEntries()
|
||||||
|
{
|
||||||
|
QList<ServerListEntryRecord> entries;
|
||||||
|
if (!checkSql()) {
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSqlQuery *query = prepareQuery(
|
||||||
|
"select id, ssl_cert, hostname, address, game_port, control_port from {prefix}_servers order by id asc");
|
||||||
|
if (!execSqlQuery(query)) {
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (query->next()) {
|
||||||
|
ServerListEntryRecord entry;
|
||||||
|
entry.id = query->value(0).toInt();
|
||||||
|
entry.sslCert = query->value(1).toString().toUtf8();
|
||||||
|
entry.hostname = query->value(2).toString();
|
||||||
|
entry.address = query->value(3).toString();
|
||||||
|
entry.gamePort = query->value(4).toInt();
|
||||||
|
entry.controlPort = query->value(5).toInt();
|
||||||
|
entries.append(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
bool Servatrice_DatabaseInterface::removeUserAvatar(const QString &userName)
|
bool Servatrice_DatabaseInterface::removeUserAvatar(const QString &userName)
|
||||||
{
|
{
|
||||||
if (!checkSql()) {
|
if (!checkSql()) {
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,7 @@ public:
|
||||||
// {prefix}_uptime table. valid is false when no snapshot exists yet.
|
// {prefix}_uptime table. valid is false when no snapshot exists yet.
|
||||||
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;
|
||||||
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