Merge branch 'master' into tooomm-qt5

This commit is contained in:
tooomm 2026-09-12 18:34:48 +02:00 • committed by GitHub
commit 6d7dadf657
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
149 changed files with 2962 additions and 423 deletions

View file

@ -253,3 +253,24 @@ PendingCommand *AbstractClient::prepareAdminCommand(const ::google::protobuf::Me
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont);
}
PendingCommand *AbstractClient::prepareDeveloperCommand(const ::google::protobuf::Message &cmd)
{
CommandContainer cont;
DeveloperCommand *c = cont.add_developer_command();
// A developer command message may also be usable through other command
// families, so select the extension scoped to DeveloperCommand rather than
// guessing by name.
const ::google::protobuf::Descriptor *cmdDescriptor = cmd.GetDescriptor();
const ::google::protobuf::Descriptor *developerDescriptor = DeveloperCommand::descriptor();
const ::google::protobuf::FieldDescriptor *developerExtension = nullptr;
for (int i = 0; i < cmdDescriptor->extension_count(); ++i) {
if (cmdDescriptor->extension(i)->containing_type() == developerDescriptor) {
developerExtension = cmdDescriptor->extension(i);
break;
}
}
Q_ASSERT(developerExtension != nullptr);
c->GetReflection()->MutableMessage(c, developerExtension)->CopyFrom(cmd);
return new PendingCommand(cont);
}

View file

@ -173,6 +173,7 @@ public:
static PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId);
static PendingCommand *prepareModeratorCommand(const ::google::protobuf::Message &cmd);
static PendingCommand *prepareAdminCommand(const ::google::protobuf::Message &cmd);
static PendingCommand *prepareDeveloperCommand(const ::google::protobuf::Message &cmd);
QMap<QString, bool> clientFeatures;
};

View file

@ -66,6 +66,15 @@ Server_AbstractPlayer::Server_AbstractPlayer(Server_Game *_game,
Server_AbstractPlayer::~Server_AbstractPlayer() = default;
int Server_AbstractPlayer::getCardCount() const
{
int result = 0;
for (auto *zone : zones) {
result += zone->getCards().size();
}
return result;
}
void Server_AbstractPlayer::prepareDestroy()
{
delete deck;

View file

@ -43,6 +43,8 @@ public:
Server_AbstractUserInterface *_handler);
~Server_AbstractPlayer() override;
void prepareDestroy() override;
/// Total cards across all of this player's zones. The caller must hold the game's mutex.
int getCardCount() const;
const DeckList *getDeckList() const
{
return deck;

View file

@ -32,6 +32,7 @@
#include "server_spectator.h"
#include <QDebug>
#include <QElapsedTimer>
#include <QRegularExpression>
#include <QTimer>
#include <google/protobuf/descriptor.h>
@ -238,6 +239,17 @@ int Server_Game::getPlayerCount() const
return participants.size() - getSpectatorCount();
}
int Server_Game::getCardsInGame() const
{
QMutexLocker locker(&gameMutex);
int result = 0;
for (auto *player : getPlayers()) {
result += player->getCardCount();
}
return result;
}
int Server_Game::getSpectatorCount() const
{
QMutexLocker locker(&gameMutex);
@ -330,6 +342,9 @@ void Server_Game::doStartGameIfReady(bool forceStartGame)
}
}
// Only actual starts are timed. The early returns above are no-ops.
QElapsedTimer startupTimer;
startupTimer.start();
players = getPlayers(); // players could have been kicked, get new list of players
if (lifecycleStrategy->onGameStarting(this) == Server_GameLifecycleStrategy::StartAction::Handled) {
locker.unlock();
@ -373,6 +388,7 @@ void Server_Game::doStartGameIfReady(bool forceStartGame)
activePlayer = -1;
nextTurn();
room->getServer()->observeGameStartDurationMs(startupTimer.nsecsElapsed() / 1000000);
locker.unlock();

View file

@ -123,6 +123,8 @@ public:
return gameStarted;
}
int getPlayerCount() const;
/// Total cards across all players' zones. Takes gameMutex itself.
int getCardsInGame() const;
int getSpectatorCount() const;
QMap<int, Server_AbstractPlayer *> getPlayers() const;
Server_AbstractPlayer *getPlayer(int id) const;

View file

@ -180,6 +180,11 @@ public:
{
return false;
}
/// Called once per actual game start with how long bringing every player's
/// zones online took, so servers can spot deck sizes that wedge threads.
virtual void observeGameStartDurationMs(qint64 /* elapsedMs */)
{
}
Server_DatabaseInterface *getDatabaseInterface() const;
int getNextLocalGameId()

View file

@ -388,6 +388,33 @@ Response::ResponseCode Server_ProtocolHandler::processAdminCommandContainer(cons
return finalResponseCode;
}
Response::ResponseCode Server_ProtocolHandler::processDeveloperCommandContainer(const CommandContainer &cont,
ResponseContainer &rc)
{
if (!userInfo) {
return Response::RespLoginNeeded;
}
if (!(userInfo->user_level() & ServerInfo_User::IsDeveloper)) {
return Response::RespLoginNeeded;
}
resetIdleTimer();
Response::ResponseCode finalResponseCode = Response::RespOk;
for (int i = cont.developer_command_size() - 1; i >= 0; --i) {
Response::ResponseCode resp = Response::RespInvalidCommand;
const DeveloperCommand &sc = cont.developer_command(i);
const int num = getPbExtension(sc);
logDebugMessage(getSafeDebugString(sc));
resp = processExtendedDeveloperCommand(num, sc, rc);
if (resp != Response::RespOk) {
finalResponseCode = resp;
}
}
return finalResponseCode;
}
void Server_ProtocolHandler::processCommandContainer(const CommandContainer &cont)
{
// Command processing must be disabled after prepareDestroy() has been called.
@ -410,6 +437,8 @@ void Server_ProtocolHandler::processCommandContainer(const CommandContainer &con
finalResponseCode = processModeratorCommandContainer(cont, responseContainer);
} else if (cont.admin_command_size()) {
finalResponseCode = processAdminCommandContainer(cont, responseContainer);
} else if (cont.developer_command_size()) {
finalResponseCode = processDeveloperCommandContainer(cont, responseContainer);
} else {
finalResponseCode = Response::RespInvalidCommand;
}
@ -454,11 +483,12 @@ void Server_ProtocolHandler::pingClockTimeout()
prepareDestroy();
}
// PrivLevel users, Moderators, and Admins are not subject to the server idle timeout policy
// PrivLevel users, Moderators, Admins, and Developers are not subject to the server idle timeout policy
const bool hasPrivLevel = userInfo && QString::fromStdString(userInfo->privlevel()).toLower() != "none";
const bool isModOrAdmin =
userInfo && (userInfo->user_level() & (ServerInfo_User::IsModerator | ServerInfo_User::IsAdmin));
if (!hasPrivLevel && !isModOrAdmin) {
const bool isStaff =
userInfo && (userInfo->user_level() &
(ServerInfo_User::IsModerator | ServerInfo_User::IsAdmin | ServerInfo_User::IsDeveloper));
if (!hasPrivLevel && !isStaff) {
if ((server->getIdleClientTimeout() > 0) && (idleClientWarningSent)) {
if (timeRunning - lastActionReceived > server->getIdleClientTimeout()) {
prepareDestroy();

View file

@ -27,6 +27,7 @@ class CommandContainer;
class SessionCommand;
class ModeratorCommand;
class AdminCommand;
class DeveloperCommand;
class Command_Ping;
class Command_Login;
@ -98,6 +99,12 @@ private:
{
return Response::RespFunctionNotAllowed;
}
Response::ResponseCode processDeveloperCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
virtual Response::ResponseCode
processExtendedDeveloperCommand(int /* cmdType */, const DeveloperCommand & /* cmd */, ResponseContainer & /* rc */)
{
return Response::RespFunctionNotAllowed;
}
void resetIdleTimer();
private slots:
@ -129,7 +136,7 @@ public:
return timeRunning - lastDataReceived;
}
bool addSaidMessageSize(int size);
void processCommandContainer(const CommandContainer &cont);
virtual void processCommandContainer(const CommandContainer &cont);
void sendProtocolItem(const Response &item);
void sendProtocolItem(const SessionEvent &item);