mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[Server] Consolidate Server_Game construction parameters into a GameConfig struct (#7128)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
d99798111e
commit
7c134efd29
6 changed files with 72 additions and 45 deletions
|
|
@ -10,6 +10,7 @@ set(HEADERS
|
||||||
game/server_card.h
|
game/server_card.h
|
||||||
game/server_cardzone.h
|
game/server_cardzone.h
|
||||||
game/server_counter.h
|
game/server_counter.h
|
||||||
|
game/game_config.h
|
||||||
game/server_game.h
|
game/server_game.h
|
||||||
game/server_player.h
|
game/server_player.h
|
||||||
game/server_spectator.h
|
game/server_spectator.h
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef GAME_CONFIG_H
|
||||||
|
#define GAME_CONFIG_H
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
#include <QString>
|
||||||
|
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
||||||
|
|
||||||
|
struct GameConfig
|
||||||
|
{
|
||||||
|
ServerInfo_User creatorInfo;
|
||||||
|
int gameId = -1;
|
||||||
|
QString description;
|
||||||
|
QString password;
|
||||||
|
int maxPlayers = 2;
|
||||||
|
QList<int> gameTypes;
|
||||||
|
bool onlyBuddies = false;
|
||||||
|
bool onlyRegistered = false;
|
||||||
|
bool spectatorsAllowed = false;
|
||||||
|
bool spectatorsNeedPassword = false;
|
||||||
|
bool spectatorsCanTalk = true;
|
||||||
|
bool spectatorsSeeEverything = true;
|
||||||
|
int startingLifeTotal = 20;
|
||||||
|
bool shareDecklistsOnLoad = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -53,34 +53,19 @@
|
||||||
#include <libcockatrice/protocol/pb/game_replay.pb.h>
|
#include <libcockatrice/protocol/pb/game_replay.pb.h>
|
||||||
#include <libcockatrice/utility/zone_names.h>
|
#include <libcockatrice/utility/zone_names.h>
|
||||||
|
|
||||||
Server_Game::Server_Game(const ServerInfo_User &_creatorInfo,
|
Server_Game::Server_Game(const GameConfig &config, Server_Room *_room)
|
||||||
int _gameId,
|
: QObject(), room(_room), nextPlayerId(0), hostId(0), creatorInfo(new ServerInfo_User(config.creatorInfo)),
|
||||||
const QString &_description,
|
gameStarted(false), gameClosed(false), gameId(config.gameId), description(config.description.simplified()),
|
||||||
const QString &_password,
|
password(config.password), maxPlayers(config.maxPlayers), gameTypes(config.gameTypes), activePlayer(-1),
|
||||||
int _maxPlayers,
|
activePhase(-1), onlyBuddies(config.onlyBuddies), onlyRegistered(config.onlyRegistered),
|
||||||
const QList<int> &_gameTypes,
|
spectatorsAllowed(config.spectatorsAllowed), spectatorsNeedPassword(config.spectatorsNeedPassword),
|
||||||
bool _onlyBuddies,
|
spectatorsCanTalk(config.spectatorsCanTalk), spectatorsSeeEverything(config.spectatorsSeeEverything),
|
||||||
bool _onlyRegistered,
|
startingLifeTotal(config.startingLifeTotal), shareDecklistsOnLoad(config.shareDecklistsOnLoad),
|
||||||
bool _spectatorsAllowed,
|
inactivityCounter(0), startTimeOfThisGame(0), secondsElapsed(0), firstGameStarted(false),
|
||||||
bool _spectatorsNeedPassword,
|
turnOrderReversed(false), startTime(QDateTime::currentDateTime()), pingClock(nullptr), gameMutex()
|
||||||
bool _spectatorsCanTalk,
|
|
||||||
bool _spectatorsSeeEverything,
|
|
||||||
int _startingLifeTotal,
|
|
||||||
bool _shareDecklistsOnLoad,
|
|
||||||
Server_Room *_room)
|
|
||||||
: QObject(), room(_room), nextPlayerId(0), hostId(0), creatorInfo(new ServerInfo_User(_creatorInfo)),
|
|
||||||
gameStarted(false), gameClosed(false), gameId(_gameId), password(_password), maxPlayers(_maxPlayers),
|
|
||||||
gameTypes(_gameTypes), activePlayer(-1), activePhase(-1), onlyBuddies(_onlyBuddies),
|
|
||||||
onlyRegistered(_onlyRegistered), spectatorsAllowed(_spectatorsAllowed),
|
|
||||||
spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk),
|
|
||||||
spectatorsSeeEverything(_spectatorsSeeEverything), startingLifeTotal(_startingLifeTotal),
|
|
||||||
shareDecklistsOnLoad(_shareDecklistsOnLoad), inactivityCounter(0), startTimeOfThisGame(0), secondsElapsed(0),
|
|
||||||
firstGameStarted(false), turnOrderReversed(false), startTime(QDateTime::currentDateTime()), pingClock(nullptr),
|
|
||||||
gameMutex()
|
|
||||||
{
|
{
|
||||||
currentReplay = new GameReplay;
|
currentReplay = new GameReplay;
|
||||||
currentReplay->set_replay_id(room->getServer()->getDatabaseInterface()->getNextReplayId());
|
currentReplay->set_replay_id(room->getServer()->getDatabaseInterface()->getNextReplayId());
|
||||||
description = _description.simplified();
|
|
||||||
|
|
||||||
connect(this, &Server_Game::sigStartGameIfReady, this, &Server_Game::doStartGameIfReady, Qt::QueuedConnection);
|
connect(this, &Server_Game::sigStartGameIfReady, this, &Server_Game::doStartGameIfReady, Qt::QueuedConnection);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#define SERVERGAME_H
|
#define SERVERGAME_H
|
||||||
|
|
||||||
#include "../server_response_containers.h"
|
#include "../server_response_containers.h"
|
||||||
|
#include "game_config.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
@ -92,21 +93,7 @@ private slots:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
mutable QRecursiveMutex gameMutex;
|
mutable QRecursiveMutex gameMutex;
|
||||||
Server_Game(const ServerInfo_User &_creatorInfo,
|
Server_Game(const GameConfig &config, Server_Room *parent);
|
||||||
int _gameId,
|
|
||||||
const QString &_description,
|
|
||||||
const QString &_password,
|
|
||||||
int _maxPlayers,
|
|
||||||
const QList<int> &_gameTypes,
|
|
||||||
bool _onlyBuddies,
|
|
||||||
bool _onlyRegistered,
|
|
||||||
bool _spectatorsAllowed,
|
|
||||||
bool _spectatorsNeedPassword,
|
|
||||||
bool _spectatorsCanTalk,
|
|
||||||
bool _spectatorsSeeEverything,
|
|
||||||
int _startingLifeTotal,
|
|
||||||
bool _shareDecklistsOnLoad,
|
|
||||||
Server_Room *parent);
|
|
||||||
~Server_Game() override;
|
~Server_Game() override;
|
||||||
Server_Room *getRoom() const
|
Server_Room *getRoom() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "server_protocolhandler.h"
|
#include "server_protocolhandler.h"
|
||||||
|
|
||||||
|
#include "game/game_config.h"
|
||||||
#include "game/server_game.h"
|
#include "game/server_game.h"
|
||||||
#include "game/server_player.h"
|
#include "game/server_player.h"
|
||||||
#include "server_database_interface.h"
|
#include "server_database_interface.h"
|
||||||
|
|
@ -920,10 +921,22 @@ Server_ProtocolHandler::cmdCreateGame(const Command_CreateGame &cmd, Server_Room
|
||||||
|
|
||||||
// When server doesn't permit registered users to exist, do not honor only-reg setting
|
// When server doesn't permit registered users to exist, do not honor only-reg setting
|
||||||
bool onlyRegisteredUsers = cmd.only_registered() && (server->permitUnregisteredUsers());
|
bool onlyRegisteredUsers = cmd.only_registered() && (server->permitUnregisteredUsers());
|
||||||
auto *game = new Server_Game(copyUserInfo(false), gameId, description, QString::fromStdString(cmd.password()),
|
GameConfig config{.creatorInfo = copyUserInfo(false),
|
||||||
cmd.max_players(), gameTypes, cmd.only_buddies(), onlyRegisteredUsers,
|
.gameId = gameId,
|
||||||
cmd.spectators_allowed(), cmd.spectators_need_password(), cmd.spectators_can_talk(),
|
.description = description,
|
||||||
cmd.spectators_see_everything(), startingLifeTotal, shareDecklistsOnLoad, room);
|
.password = QString::fromStdString(cmd.password()),
|
||||||
|
.maxPlayers = static_cast<int>(cmd.max_players()),
|
||||||
|
.gameTypes = gameTypes,
|
||||||
|
.onlyBuddies = cmd.only_buddies(),
|
||||||
|
.onlyRegistered = onlyRegisteredUsers,
|
||||||
|
.spectatorsAllowed = cmd.spectators_allowed(),
|
||||||
|
.spectatorsNeedPassword = cmd.spectators_need_password(),
|
||||||
|
.spectatorsCanTalk = cmd.spectators_can_talk(),
|
||||||
|
.spectatorsSeeEverything = cmd.spectators_see_everything(),
|
||||||
|
.startingLifeTotal = startingLifeTotal,
|
||||||
|
.shareDecklistsOnLoad = shareDecklistsOnLoad};
|
||||||
|
|
||||||
|
auto *game = new Server_Game(config, room);
|
||||||
|
|
||||||
game->addPlayer(this, rc, asSpectator, asJudge, false);
|
game->addPlayer(this, rc, asSpectator, asJudge, false);
|
||||||
room->addGame(game);
|
room->addGame(game);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include "game/game_config.h"
|
||||||
#include "game/server_abstract_player.h"
|
#include "game/server_abstract_player.h"
|
||||||
#include "game/server_card.h"
|
#include "game/server_card.h"
|
||||||
#include "game/server_cardzone.h"
|
#include "game/server_cardzone.h"
|
||||||
|
|
@ -22,7 +23,21 @@ TEST(ReverseCardMoveTest, MoveCardFromBottomTest)
|
||||||
// instantiate a fake server instance
|
// instantiate a fake server instance
|
||||||
FakeServer server;
|
FakeServer server;
|
||||||
Server_Room room(0, 0, "", "", "", "", false, "", {}, &server);
|
Server_Room room(0, 0, "", "", "", "", false, "", {}, &server);
|
||||||
Server_Game game(user, 1, "", "", 2, QList<int>(), false, false, false, false, false, false, 20, false, &room);
|
GameConfig config{.creatorInfo = user,
|
||||||
|
.gameId = 1,
|
||||||
|
.description = QString(),
|
||||||
|
.password = QString(),
|
||||||
|
.maxPlayers = 2,
|
||||||
|
.gameTypes = QList<int>(),
|
||||||
|
.onlyBuddies = false,
|
||||||
|
.onlyRegistered = false,
|
||||||
|
.spectatorsAllowed = false,
|
||||||
|
.spectatorsNeedPassword = false,
|
||||||
|
.spectatorsCanTalk = false,
|
||||||
|
.spectatorsSeeEverything = false,
|
||||||
|
.startingLifeTotal = 20,
|
||||||
|
.shareDecklistsOnLoad = false};
|
||||||
|
Server_Game game(config, &room);
|
||||||
Server_AbstractPlayer player(&game, 1, user, false, nullptr);
|
Server_AbstractPlayer player(&game, 1, user, false, nullptr);
|
||||||
Server_CardZone deckZone(&player, ZoneNames::DECK, true, ServerInfo_Zone::PublicZone);
|
Server_CardZone deckZone(&player, ZoneNames::DECK, true, ServerInfo_Zone::PublicZone);
|
||||||
Server_CardZone exileZone(&player, ZoneNames::EXILE, true, ServerInfo_Zone::PublicZone);
|
Server_CardZone exileZone(&player, ZoneNames::EXILE, true, ServerInfo_Zone::PublicZone);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue