Compare commits

...

4 commits

Author SHA1 Message Date
Lukas Brübach
9dd16ec0fc [Server] Add extension points for tournament game commands
Adds the server-side seams the tournament engine will plug into:
- Dispatch ReportMatchResult / AdvanceTournament /
  TournamentSettingsSelect in processGameCommand; base implementations
  return RespContextError so regular games reject them safely
- Server_AbstractPlayer::setDeck lets a backend install a deck into a
  player slot directly
- Server_Room::getUserInterfaceByName resolves a room user by name for
  automated game setup


Took 24 minutes
2026-09-02 10:28:43 +02:00
Lukas Brübach
b8083b6c93 [Protocol] Drop redundant is_tournament from the game-state event
The client already learns a game is a tournament from Event_GameJoined's
ServerInfo_Game.is_tournament, so mirroring it on every Event_GameStateChanged
is dead wire data — nothing on the client reads it. Removed.
2026-09-02 10:27:51 +02:00
Lukas Brübach
b98a267285 [Protocol] Share tournament messages and report draws explicitly
- TournamentPlayer/TournamentPairing/TournamentSettings move into
  serverinfo_tournament.proto, imported by both the tournament event and
  the tournament game commands, so Command_CreateGame reaches them without
  crossing the command/event boundary
- Command_CreateGame carries the full TournamentSettings instead of a
  duplicate games_per_match field, keeping game creation and mid-game
  changes on one wire representation
- draw results are explicit: Command_ReportMatchResult and
  TournamentPairing gain is_draw, so a report stays distinguishable from
  an unset -1 winner
- pairing match-wins are uint32 like the other game counts
2026-09-02 08:43:25 +02:00
Lukas Brübach
3c03d740f3
[Protocol] Add tournament state event and tournament game commands
Adds the protocol layer for the tournament game mode:
- Event_TournamentState (2027) carrying phase, round counters, player
  standings, pairings, and settings (games_per_match)
- Command_ReportMatchResult / Command_AdvanceTournament /
  Command_TournamentSettingsSelect game command extensions (1037-1039)
- is_tournament flag on Command_CreateGame and ServerInfo_Game;
  is_tournament and parent_game_id on Event_GameStateChanged


Took 13 minutes
2026-08-31 13:49:15 +02:00
15 changed files with 174 additions and 0 deletions

View file

@ -41,6 +41,7 @@
#include <libcockatrice/protocol/pb/command_set_sideboard_lock.pb.h>
#include <libcockatrice/protocol/pb/command_set_sideboard_plan.pb.h>
#include <libcockatrice/protocol/pb/command_shuffle.pb.h>
#include <libcockatrice/protocol/pb/command_tournament.pb.h>
#include <libcockatrice/protocol/pb/command_undo_draw.pb.h>
#include <libcockatrice/protocol/pb/context_connection_state_changed.pb.h>
#include <libcockatrice/protocol/pb/event_game_say.pb.h>
@ -536,6 +537,15 @@ Server_AbstractParticipant::processGameCommand(const GameCommand &command, Respo
case GameCommand::SET_PLAYMAT:
return cmdSetPlaymat(command.GetExtension(Command_SetPlaymat::ext), rc, ges);
break;
case GameCommand::REPORT_MATCH_RESULT:
return cmdReportMatchResult(command.GetExtension(Command_ReportMatchResult::ext), rc, ges);
break;
case GameCommand::ADVANCE_TOURNAMENT:
return cmdAdvanceTournament(command.GetExtension(Command_AdvanceTournament::ext), rc, ges);
break;
case GameCommand::TOURNAMENT_SETTINGS_SELECT:
return cmdTournamentSettingsSelect(command.GetExtension(Command_TournamentSettingsSelect::ext), rc, ges);
break;
default:
return Response::RespInvalidCommand;
}
@ -584,3 +594,25 @@ void Server_AbstractParticipant::getInfo(ServerInfo_Player *info,
{
getProperties(*info->mutable_properties(), withUserInfo);
}
Response::ResponseCode Server_AbstractParticipant::cmdReportMatchResult(const Command_ReportMatchResult & /*cmd*/,
ResponseContainer & /*rc*/,
GameEventStorage & /*ges*/)
{
return Response::RespContextError;
}
Response::ResponseCode Server_AbstractParticipant::cmdAdvanceTournament(const Command_AdvanceTournament & /*cmd*/,
ResponseContainer & /*rc*/,
GameEventStorage & /*ges*/)
{
return Response::RespContextError;
}
Response::ResponseCode
Server_AbstractParticipant::cmdTournamentSettingsSelect(const Command_TournamentSettingsSelect & /*cmd*/,
ResponseContainer & /*rc*/,
GameEventStorage & /*ges*/)
{
return Response::RespContextError;
}

View file

@ -53,6 +53,9 @@ class Command_DeckSelect;
class Command_SetSideboardLock;
class Command_ChangeZoneProperties;
class Command_SetPlaymat;
class Command_ReportMatchResult;
class Command_AdvanceTournament;
class Command_TournamentSettingsSelect;
class Server_AbstractParticipant : public Server_ArrowTarget, public ServerInfo_User_Container
{
@ -175,6 +178,13 @@ public:
cmdReverseTurn(const Command_ReverseTurn & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage &ges);
virtual Response::ResponseCode
cmdChangeZoneProperties(const Command_ChangeZoneProperties &cmd, ResponseContainer &rc, GameEventStorage &ges);
virtual Response::ResponseCode
cmdReportMatchResult(const Command_ReportMatchResult &cmd, ResponseContainer &rc, GameEventStorage &ges);
virtual Response::ResponseCode
cmdAdvanceTournament(const Command_AdvanceTournament &cmd, ResponseContainer &rc, GameEventStorage &ges);
virtual Response::ResponseCode cmdTournamentSettingsSelect(const Command_TournamentSettingsSelect &cmd,
ResponseContainer &rc,
GameEventStorage &ges);
Response::ResponseCode processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges);
void sendGameEvent(const GameEventContainer &event);

View file

@ -1663,3 +1663,9 @@ void Server_AbstractPlayer::getPlayerProperties(ServerInfo_PlayerProperties &res
playmatParams->set_zoom(playmat.params.zoom);
}
}
void Server_AbstractPlayer::setDeck(DeckList *_deck)
{
delete deck;
deck = _deck;
}

View file

@ -47,6 +47,7 @@ public:
{
return deck;
}
void setDeck(DeckList *_deck);
bool getReadyStart() const
{
return readyStart;

View file

@ -363,6 +363,18 @@ void Server_Room::broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
}
Server_AbstractUserInterface *Server_Room::getUserInterfaceByName(const QString &name) const
{
usersLock.lockForRead();
auto it = users.constFind(name);
Server_AbstractUserInterface *result = nullptr;
if (it != users.constEnd()) {
result = it.value();
}
usersLock.unlock();
return result;
}
void Server_Room::addGame(Server_Game *game)
{
ServerInfo_Room roomInfo;

View file

@ -135,6 +135,8 @@ public:
void addGame(Server_Game *game);
void removeGame(Server_Game *game);
Server_AbstractUserInterface *getUserInterfaceByName(const QString &name) const;
void sendRoomEvent(RoomEvent *event, bool sendToIsl = true);
RoomEvent *prepareRoomEvent(const ::google::protobuf::Message &roomEvent);
};

View file

@ -60,6 +60,7 @@ set(PROTO_FILES
command_set_sideboard_lock.proto
command_set_sideboard_plan.proto
command_shuffle.proto
command_tournament.proto
command_undo_draw.proto
commands.proto
context_concede.proto
@ -118,6 +119,7 @@ set(PROTO_FILES
event_set_card_counter.proto
event_set_counter.proto
event_shuffle.proto
event_tournament_state.proto
event_user_joined.proto
event_user_left.proto
event_user_message.proto
@ -184,6 +186,7 @@ set(PROTO_FILES
serverinfo_replay_match.proto
serverinfo_report.proto
serverinfo_room.proto
serverinfo_tournament.proto
serverinfo_user.proto
serverinfo_user_alt.proto
serverinfo_user_session.proto

View file

@ -0,0 +1,31 @@
syntax = "proto2";
import "game_commands.proto";
import "serverinfo_tournament.proto";
message Command_ReportMatchResult {
extend GameCommand {
optional Command_ReportMatchResult ext = 1037;
}
optional sint32 game_id = 1 [default = -1];
// The winning player's ID. A drawn match is reported with is_draw set and
// winner_id left unset so a missing report stays distinguishable from a
// reported draw via has_winner_id().
optional sint32 winner_id = 2 [default = -1];
// Whether the match ended in a draw; winner_id is meaningless then.
optional bool is_draw = 3;
}
message Command_AdvanceTournament {
extend GameCommand {
optional Command_AdvanceTournament ext = 1038;
}
}
message Command_TournamentSettingsSelect {
extend GameCommand {
optional Command_TournamentSettingsSelect ext = 1039;
}
optional TournamentSettings settings = 1;
}

View file

@ -24,4 +24,7 @@ message Event_GameStateChanged {
// the amount of seconds since the game started
optional uint32 seconds_elapsed = 5;
// for tournament sub-games: the ID of the parent tournament game (-1 if not a sub-game)
optional sint32 parent_game_id = 10 [default = -1];
}

View file

@ -0,0 +1,22 @@
syntax = "proto2";
import "game_event.proto";
import "serverinfo_tournament.proto";
message Event_TournamentState {
extend GameEvent {
optional Event_TournamentState ext = 2027;
}
enum TournamentPhase {
PHASE_DECK_BUILDING = 0;
PHASE_PLAYING = 1;
PHASE_FINISHED = 2;
}
optional TournamentPhase phase = 1;
optional uint32 current_round = 2;
optional uint32 total_rounds = 3;
repeated TournamentPlayer players = 4;
repeated TournamentPairing pairings = 5;
optional TournamentSettings settings = 6;
}

View file

@ -180,6 +180,15 @@ message GameCommand {
/// Server: Server_Player::cmdSetPlaymat
/// Client: reflected via player properties changed event
SET_PLAYMAT = 1035;
/// Report the result of a tournament match sub-game.
REPORT_MATCH_RESULT = 1037;
/// Advance the tournament to the next round.
ADVANCE_TOURNAMENT = 1038;
/// Select tournament settings.
TOURNAMENT_SETTINGS_SELECT = 1039;
}
extensions 100 to max;

View file

@ -34,6 +34,7 @@ message GameEvent {
CHANGE_ZONE_PROPERTIES = 2020;
REVERSE_TURN = 2021;
GAME_LOG_NOTICE = 2022;
TOURNAMENT_STATE = 2027;
}
optional sint32 player_id = 1 [default = -1];
extensions 100 to max;

View file

@ -1,4 +1,5 @@
syntax = "proto2";
import "serverinfo_tournament.proto";
message RoomCommand {
enum RoomCommandType {
LEAVE_ROOM = 1000;
@ -69,6 +70,12 @@ message Command_CreateGame {
// share decklists with all players when selected
optional bool share_decklists_on_load = 14;
// tournament settings shared by game creation and mid-game changes
optional TournamentSettings tournament_settings = 15;
// whether this is a tournament game
optional bool is_tournament = 16;
}
message Command_JoinGame {

View file

@ -65,4 +65,7 @@ message ServerInfo_Game {
// the current host of the game, which may differ from the creator after a host transfer
optional ServerInfo_User host_info = 53;
// whether this game is a tournament game
optional bool is_tournament = 54;
}

View file

@ -0,0 +1,32 @@
syntax = "proto2";
// Player-entered tournament metadata as shown in the standings and bracket views.
message TournamentPlayer {
optional sint32 player_id = 1;
optional string player_name = 2;
optional uint32 wins = 3;
optional uint32 losses = 4;
optional uint32 draws = 5;
optional bool deck_submitted = 6;
}
// A single match pairing within a tournament round.
message TournamentPairing {
optional sint32 player1_id = 1;
// -1 when the pairing is a bye.
optional sint32 player2_id = 2 [default = -1];
optional sint32 game_id = 3;
// The winning player's ID, or -1 when the match ended in a draw (is_draw).
// An unset field reads back as -1 too; has_winner_id() distinguishes those.
optional sint32 winner_id = 4 [default = -1];
optional uint32 player1_match_wins = 5;
optional uint32 player2_match_wins = 6;
// Whether the match ended in a draw; winner_id is meaningless then.
optional bool is_draw = 7;
}
// Settings governing all matches of a tournament.
message TournamentSettings {
// Number of games per match (e.g. 3 for best of 3).
optional uint32 games_per_match = 1 [default = 1];
}