This commit is contained in:
Donald Haase 2026-05-14 23:49:26 -07:00 committed by GitHub
commit e02875ba54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 31 additions and 8 deletions

View file

@ -86,6 +86,9 @@ officialwarnings="Flaming,Spamming,Causing Drama,Abusive Language"
; Clients will be notified at the 90% time period of pending disconnection if they do not take action.
idleclienttimeout=3600
; You can define one user whose decks will be available to all users. This is useful for hosting events and distributing preconstructed decks to all users. By default this is unset. This will be matched against the id field in cockatrice_users.
; globaldecksid=1
[authentication]
; Servatrice can authenticate users connecting. It currently supports 3 different authentication methods:

View file

@ -795,6 +795,11 @@ bool Servatrice::getClientIDRequiredEnabled() const
return settingsCache->value("server/requireclientid", 0).toBool();
}
int Servatrice::getGlobalDecksID() const
{
return settingsCache->value("server/globaldecksid", -1).toInt();
}
bool Servatrice::getRegOnlyServerEnabled() const
{
return settingsCache->value("authentication/regonly", 0).toBool();

View file

@ -253,6 +253,7 @@ public:
int getMinPasswordLength() const;
int getIdleClientTimeout() const override;
int getServerID() const override;
int getGlobalDecksID() const;
int getMaxGameInactivityTime() const override;
int getMaxPlayerInactivityTime() const override;
int getClientKeepAlive() const override;

View file

@ -921,6 +921,11 @@ DeckList *Servatrice_DatabaseInterface::getDeckFromDatabase(int deckId, int user
{
checkSql();
if ((server->getGlobalDecksID() != -1) && (deckId > globalDeckOffset)) {
deckId = deckId - globalDeckOffset;
userId = server->getGlobalDecksID();
}
QSqlQuery *query =
prepareQuery("select content from {prefix}_decklist_files where id = :id and id_user = :id_user");
query->bindValue(":id", deckId);

View file

@ -375,12 +375,14 @@ int AbstractServerSocketInterface::getDeckPathId(const QString &path)
return getDeckPathId(0, path.split("/"));
}
bool AbstractServerSocketInterface::deckListHelper(int folderId, ServerInfo_DeckStorage_Folder *folder)
bool AbstractServerSocketInterface::deckListHelper(int folderId, int userId, ServerInfo_DeckStorage_Folder *folder)
{
int offset = (userInfo->id() != userId) ? globalDeckOffset : 0;
QSqlQuery *query = sqlInterface->prepareQuery(
"select id, name from {prefix}_decklist_folders where id_parent = :id_parent and id_user = :id_user");
query->bindValue(":id_parent", folderId);
query->bindValue(":id_user", userInfo->id());
query->bindValue(":id_user", userId);
if (!sqlInterface->execSqlQuery(query))
return false;
@ -390,23 +392,23 @@ bool AbstractServerSocketInterface::deckListHelper(int folderId, ServerInfo_Deck
for (int key : results.keys()) {
ServerInfo_DeckStorage_TreeItem *newItem = folder->add_items();
newItem->set_id(key);
newItem->set_id(key + offset);
newItem->set_name(results.value(key).toStdString());
if (!deckListHelper(newItem->id(), newItem->mutable_folder()))
if (!deckListHelper(key, userId, newItem->mutable_folder()))
return false;
}
query = sqlInterface->prepareQuery("select id, name, upload_time from {prefix}_decklist_files where id_folder = "
":id_folder and id_user = :id_user");
query->bindValue(":id_folder", folderId);
query->bindValue(":id_user", userInfo->id());
query->bindValue(":id_user", userId);
if (!sqlInterface->execSqlQuery(query))
return false;
while (query->next()) {
ServerInfo_DeckStorage_TreeItem *newItem = folder->add_items();
newItem->set_id(query->value(0).toInt());
newItem->set_id(query->value(0).toInt() + offset);
newItem->set_name(query->value(1).toString().toStdString());
ServerInfo_DeckStorage_File *newFile = newItem->mutable_file();
@ -430,7 +432,12 @@ Response::ResponseCode AbstractServerSocketInterface::cmdDeckList(const Command_
Response_DeckList *re = new Response_DeckList;
ServerInfo_DeckStorage_Folder *root = re->mutable_root();
if (!deckListHelper(0, root))
int globalID = servatrice->getGlobalDecksID();
if ((globalID != -1) && ((globalID != userInfo->id())))
if (!deckListHelper(0, globalID, root))
return Response::RespContextError;
if (!deckListHelper(0, userInfo->id(), root))
return Response::RespContextError;
rc.setResponseExtension(re);

View file

@ -26,6 +26,8 @@
#include <QWebSocket>
#include <server_protocolhandler.h>
static const int globalDeckOffset = 10000000;
class Servatrice;
class Servatrice_DatabaseInterface;
class DeckList;
@ -84,7 +86,7 @@ private:
Response::ResponseCode cmdRemoveFromList(const Command_RemoveFromList &cmd, ResponseContainer &rc);
int getDeckPathId(int basePathId, QStringList path);
int getDeckPathId(const QString &path);
bool deckListHelper(int folderId, ServerInfo_DeckStorage_Folder *folder);
bool deckListHelper(int folderId, int userId, ServerInfo_DeckStorage_Folder *folder);
Response::ResponseCode cmdDeckList(const Command_DeckList &cmd, ResponseContainer &rc);
Response::ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, ResponseContainer &rc);
void deckDelDirHelper(int basePathId);