mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-01 15:14:53 -05:00
Some checks failed
Build Desktop / Configure (push) Has been cancelled
Build Docker Image / amd64 & arm64 (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Debian, DEB, 13) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Debian, DEB, skip, 11) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Debian, DEB, skip, 12) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Fedora, RPM, 42) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Fedora, RPM, skip, 41) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Ubuntu, DEB, 24.04) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Ubuntu, DEB, skip, 22.04) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (yes, Arch, skip) (push) Has been cancelled
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (1, macos-13, Intel, 13, Release, 14.3.1) (push) Has been cancelled
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (1, macos-14, Apple, 14, Release, 15.4) (push) Has been cancelled
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (1, macos-15, Apple, 15, Release, 16.2) (push) Has been cancelled
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (macos-15, Apple, 15, Debug, 16.2) (push) Has been cancelled
Build Desktop / Windows ${{matrix.target}} (msvc2019_64, 5.15.*, 7) (push) Has been cancelled
Build Desktop / Windows ${{matrix.target}} (msvc2019_64, qtimageformats qtmultimedia qtwebsockets, 6.6.*, 10) (push) Has been cancelled
* move common server files * update includes with move * create participant, move code * fix linker errors * fix regressions * mark function as override to make clang happy * split out spectator to new file * forgot to add to cmakelists * autocompleter picking wrong casing for var name * clean up forwards declarations in player * fix includes in game
96 lines
3.2 KiB
C++
96 lines
3.2 KiB
C++
#include "server_response_containers.h"
|
|
|
|
#include "game/server_game.h"
|
|
|
|
#include <google/protobuf/descriptor.h>
|
|
|
|
GameEventStorageItem::GameEventStorageItem(const ::google::protobuf::Message &_event,
|
|
int _playerId,
|
|
EventRecipients _recipients)
|
|
: event(new GameEvent), recipients(_recipients)
|
|
{
|
|
event->GetReflection()->MutableMessage(event, _event.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(_event);
|
|
event->set_player_id(_playerId);
|
|
}
|
|
|
|
GameEventStorageItem::~GameEventStorageItem()
|
|
{
|
|
delete event;
|
|
}
|
|
|
|
GameEventStorage::GameEventStorage() : gameEventContext(0), privatePlayerId(0)
|
|
{
|
|
}
|
|
|
|
GameEventStorage::~GameEventStorage()
|
|
{
|
|
delete gameEventContext;
|
|
for (int i = 0; i < gameEventList.size(); ++i)
|
|
delete gameEventList[i];
|
|
}
|
|
|
|
void GameEventStorage::setGameEventContext(const ::google::protobuf::Message &_gameEventContext)
|
|
{
|
|
delete gameEventContext;
|
|
gameEventContext = new GameEventContext;
|
|
gameEventContext->GetReflection()
|
|
->MutableMessage(gameEventContext, _gameEventContext.GetDescriptor()->FindExtensionByName("ext"))
|
|
->CopyFrom(_gameEventContext);
|
|
}
|
|
|
|
void GameEventStorage::enqueueGameEvent(const ::google::protobuf::Message &event,
|
|
int playerId,
|
|
GameEventStorageItem::EventRecipients recipients,
|
|
int _privatePlayerId)
|
|
{
|
|
gameEventList.append(new GameEventStorageItem(event, playerId, recipients));
|
|
if (_privatePlayerId != -1)
|
|
privatePlayerId = _privatePlayerId;
|
|
}
|
|
|
|
void GameEventStorage::sendToGame(Server_Game *game)
|
|
{
|
|
if (gameEventList.isEmpty())
|
|
return;
|
|
|
|
auto *contPrivate = new GameEventContainer;
|
|
auto *contOthers = new GameEventContainer;
|
|
int id = privatePlayerId;
|
|
if (forcedByJudge != -1) {
|
|
contPrivate->set_forced_by_judge(forcedByJudge);
|
|
contOthers->set_forced_by_judge(forcedByJudge);
|
|
if (overwriteOwnership) {
|
|
id = forcedByJudge;
|
|
setOverwriteOwnership(false);
|
|
}
|
|
}
|
|
|
|
for (const auto &i : gameEventList) {
|
|
const GameEvent &event = i->getGameEvent();
|
|
const GameEventStorageItem::EventRecipients recipients = i->getRecipients();
|
|
if (recipients.testFlag(GameEventStorageItem::SendToPrivate))
|
|
contPrivate->add_event_list()->CopyFrom(event);
|
|
if (recipients.testFlag(GameEventStorageItem::SendToOthers))
|
|
contOthers->add_event_list()->CopyFrom(event);
|
|
}
|
|
if (gameEventContext) {
|
|
contPrivate->mutable_context()->CopyFrom(*gameEventContext);
|
|
contOthers->mutable_context()->CopyFrom(*gameEventContext);
|
|
}
|
|
game->sendGameEventContainer(contPrivate, GameEventStorageItem::SendToPrivate, id);
|
|
game->sendGameEventContainer(contOthers, GameEventStorageItem::SendToOthers, id);
|
|
}
|
|
|
|
ResponseContainer::ResponseContainer(int _cmdId) : cmdId(_cmdId), responseExtension(0)
|
|
{
|
|
}
|
|
|
|
ResponseContainer::~ResponseContainer()
|
|
{
|
|
delete responseExtension;
|
|
for (int i = 0; i < preResponseQueue.size(); ++i)
|
|
delete preResponseQueue[i].second;
|
|
for (int i = 0; i < postResponseQueue.size(); ++i)
|
|
delete postResponseQueue[i].second;
|
|
}
|