mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 05:23:56 -07:00
Merge f226a961c4 into 7153f7d4c1
This commit is contained in:
commit
e02875ba54
6 changed files with 31 additions and 8 deletions
|
|
@ -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.
|
; Clients will be notified at the 90% time period of pending disconnection if they do not take action.
|
||||||
idleclienttimeout=3600
|
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]
|
[authentication]
|
||||||
|
|
||||||
; Servatrice can authenticate users connecting. It currently supports 3 different authentication methods:
|
; Servatrice can authenticate users connecting. It currently supports 3 different authentication methods:
|
||||||
|
|
|
||||||
|
|
@ -795,6 +795,11 @@ bool Servatrice::getClientIDRequiredEnabled() const
|
||||||
return settingsCache->value("server/requireclientid", 0).toBool();
|
return settingsCache->value("server/requireclientid", 0).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Servatrice::getGlobalDecksID() const
|
||||||
|
{
|
||||||
|
return settingsCache->value("server/globaldecksid", -1).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
bool Servatrice::getRegOnlyServerEnabled() const
|
bool Servatrice::getRegOnlyServerEnabled() const
|
||||||
{
|
{
|
||||||
return settingsCache->value("authentication/regonly", 0).toBool();
|
return settingsCache->value("authentication/regonly", 0).toBool();
|
||||||
|
|
|
||||||
|
|
@ -253,6 +253,7 @@ public:
|
||||||
int getMinPasswordLength() const;
|
int getMinPasswordLength() const;
|
||||||
int getIdleClientTimeout() const override;
|
int getIdleClientTimeout() const override;
|
||||||
int getServerID() const override;
|
int getServerID() const override;
|
||||||
|
int getGlobalDecksID() const;
|
||||||
int getMaxGameInactivityTime() const override;
|
int getMaxGameInactivityTime() const override;
|
||||||
int getMaxPlayerInactivityTime() const override;
|
int getMaxPlayerInactivityTime() const override;
|
||||||
int getClientKeepAlive() const override;
|
int getClientKeepAlive() const override;
|
||||||
|
|
|
||||||
|
|
@ -921,6 +921,11 @@ DeckList *Servatrice_DatabaseInterface::getDeckFromDatabase(int deckId, int user
|
||||||
{
|
{
|
||||||
checkSql();
|
checkSql();
|
||||||
|
|
||||||
|
if ((server->getGlobalDecksID() != -1) && (deckId > globalDeckOffset)) {
|
||||||
|
deckId = deckId - globalDeckOffset;
|
||||||
|
userId = server->getGlobalDecksID();
|
||||||
|
}
|
||||||
|
|
||||||
QSqlQuery *query =
|
QSqlQuery *query =
|
||||||
prepareQuery("select content from {prefix}_decklist_files where id = :id and id_user = :id_user");
|
prepareQuery("select content from {prefix}_decklist_files where id = :id and id_user = :id_user");
|
||||||
query->bindValue(":id", deckId);
|
query->bindValue(":id", deckId);
|
||||||
|
|
|
||||||
|
|
@ -375,12 +375,14 @@ int AbstractServerSocketInterface::getDeckPathId(const QString &path)
|
||||||
return getDeckPathId(0, path.split("/"));
|
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(
|
QSqlQuery *query = sqlInterface->prepareQuery(
|
||||||
"select id, name from {prefix}_decklist_folders where id_parent = :id_parent and id_user = :id_user");
|
"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_parent", folderId);
|
||||||
query->bindValue(":id_user", userInfo->id());
|
query->bindValue(":id_user", userId);
|
||||||
if (!sqlInterface->execSqlQuery(query))
|
if (!sqlInterface->execSqlQuery(query))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -390,23 +392,23 @@ bool AbstractServerSocketInterface::deckListHelper(int folderId, ServerInfo_Deck
|
||||||
|
|
||||||
for (int key : results.keys()) {
|
for (int key : results.keys()) {
|
||||||
ServerInfo_DeckStorage_TreeItem *newItem = folder->add_items();
|
ServerInfo_DeckStorage_TreeItem *newItem = folder->add_items();
|
||||||
newItem->set_id(key);
|
newItem->set_id(key + offset);
|
||||||
newItem->set_name(results.value(key).toStdString());
|
newItem->set_name(results.value(key).toStdString());
|
||||||
|
|
||||||
if (!deckListHelper(newItem->id(), newItem->mutable_folder()))
|
if (!deckListHelper(key, userId, newItem->mutable_folder()))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
query = sqlInterface->prepareQuery("select id, name, upload_time from {prefix}_decklist_files where id_folder = "
|
query = sqlInterface->prepareQuery("select id, name, upload_time from {prefix}_decklist_files where id_folder = "
|
||||||
":id_folder and id_user = :id_user");
|
":id_folder and id_user = :id_user");
|
||||||
query->bindValue(":id_folder", folderId);
|
query->bindValue(":id_folder", folderId);
|
||||||
query->bindValue(":id_user", userInfo->id());
|
query->bindValue(":id_user", userId);
|
||||||
if (!sqlInterface->execSqlQuery(query))
|
if (!sqlInterface->execSqlQuery(query))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while (query->next()) {
|
while (query->next()) {
|
||||||
ServerInfo_DeckStorage_TreeItem *newItem = folder->add_items();
|
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());
|
newItem->set_name(query->value(1).toString().toStdString());
|
||||||
|
|
||||||
ServerInfo_DeckStorage_File *newFile = newItem->mutable_file();
|
ServerInfo_DeckStorage_File *newFile = newItem->mutable_file();
|
||||||
|
|
@ -430,7 +432,12 @@ Response::ResponseCode AbstractServerSocketInterface::cmdDeckList(const Command_
|
||||||
Response_DeckList *re = new Response_DeckList;
|
Response_DeckList *re = new Response_DeckList;
|
||||||
ServerInfo_DeckStorage_Folder *root = re->mutable_root();
|
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;
|
return Response::RespContextError;
|
||||||
|
|
||||||
rc.setResponseExtension(re);
|
rc.setResponseExtension(re);
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
#include <QWebSocket>
|
#include <QWebSocket>
|
||||||
#include <server_protocolhandler.h>
|
#include <server_protocolhandler.h>
|
||||||
|
|
||||||
|
static const int globalDeckOffset = 10000000;
|
||||||
|
|
||||||
class Servatrice;
|
class Servatrice;
|
||||||
class Servatrice_DatabaseInterface;
|
class Servatrice_DatabaseInterface;
|
||||||
class DeckList;
|
class DeckList;
|
||||||
|
|
@ -84,7 +86,7 @@ private:
|
||||||
Response::ResponseCode cmdRemoveFromList(const Command_RemoveFromList &cmd, ResponseContainer &rc);
|
Response::ResponseCode cmdRemoveFromList(const Command_RemoveFromList &cmd, ResponseContainer &rc);
|
||||||
int getDeckPathId(int basePathId, QStringList path);
|
int getDeckPathId(int basePathId, QStringList path);
|
||||||
int getDeckPathId(const QString &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 cmdDeckList(const Command_DeckList &cmd, ResponseContainer &rc);
|
||||||
Response::ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, ResponseContainer &rc);
|
Response::ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, ResponseContainer &rc);
|
||||||
void deckDelDirHelper(int basePathId);
|
void deckDelDirHelper(int basePathId);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue