mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 03:53:26 -08:00
[Server] Serve the login message through the database interface (#7854)
This commit is contained in:
parent
ec3ad812f0
commit
f8f8fffa6b
4 changed files with 35 additions and 18 deletions
|
|
@ -712,6 +712,11 @@ public:
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
/** @brief The newest server message for the login banner; false when the lookup fails or finds no row. */
|
||||||
|
virtual bool getLatestServerMessage(int /* serverId */, QString & /* message */)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void clearSessionTables()
|
virtual void clearSessionTables()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -820,26 +820,20 @@ void Servatrice::updateLoginMessage()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSqlQuery *query = servatriceDatabaseInterface->prepareQuery(
|
QString newLoginMessage;
|
||||||
"select message from {prefix}_servermessages where id_server = :id_server order by timest desc limit 1");
|
if (servatriceDatabaseInterface->getLatestServerMessage(serverId, newLoginMessage)) {
|
||||||
query->bindValue(":id_server", serverId);
|
loginMessageMutex.lock();
|
||||||
if (servatriceDatabaseInterface->execSqlQuery(query)) {
|
loginMessage = newLoginMessage;
|
||||||
if (query->next()) {
|
loginMessageMutex.unlock();
|
||||||
const QString newLoginMessage = query->value(0).toString();
|
|
||||||
|
|
||||||
loginMessageMutex.lock();
|
Event_ServerMessage event;
|
||||||
loginMessage = newLoginMessage;
|
event.set_message(newLoginMessage.toStdString());
|
||||||
loginMessageMutex.unlock();
|
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||||
|
QMapIterator<QString, Server_ProtocolHandler *> usersIterator(users);
|
||||||
Event_ServerMessage event;
|
while (usersIterator.hasNext()) {
|
||||||
event.set_message(newLoginMessage.toStdString());
|
usersIterator.next().value()->sendProtocolItem(*se);
|
||||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
|
||||||
QMapIterator<QString, Server_ProtocolHandler *> usersIterator(users);
|
|
||||||
while (usersIterator.hasNext()) {
|
|
||||||
usersIterator.next().value()->sendProtocolItem(*se);
|
|
||||||
}
|
|
||||||
delete se;
|
|
||||||
}
|
}
|
||||||
|
delete se;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3293,6 +3293,23 @@ Server_DatabaseInterface::UptimeSnapshot Servatrice_DatabaseInterface::getLatest
|
||||||
return snapshot;
|
return snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Servatrice_DatabaseInterface::getLatestServerMessage(int serverId, QString &message)
|
||||||
|
{
|
||||||
|
if (!checkSql()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSqlQuery *query = prepareQuery(
|
||||||
|
"select message from {prefix}_servermessages where id_server = :id_server order by timest desc limit 1");
|
||||||
|
query->bindValue(":id_server", serverId);
|
||||||
|
if (!execSqlQuery(query) || !query->next()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
message = query->value(0).toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Servatrice_DatabaseInterface::removeUserAvatar(const QString &userName)
|
bool Servatrice_DatabaseInterface::removeUserAvatar(const QString &userName)
|
||||||
{
|
{
|
||||||
if (!checkSql()) {
|
if (!checkSql()) {
|
||||||
|
|
|
||||||
|
|
@ -278,6 +278,7 @@ public:
|
||||||
// Uptime snapshot as recorded by Servatrice::statusUpdate() into the
|
// Uptime snapshot as recorded by Servatrice::statusUpdate() into the
|
||||||
// {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 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