Cockatrice/common/server/server_response_containers.h
ebbit1q f0c3860032
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
squash #6156 (#6161)
* 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
2025-09-20 14:37:12 +02:00

131 lines
3.4 KiB
C++

#ifndef SERVER_RESPONSE_CONTAINERS_H
#define SERVER_RESPONSE_CONTAINERS_H
#include "pb/server_message.pb.h"
#include <QList>
#include <QPair>
namespace google
{
namespace protobuf
{
class Message;
}
} // namespace google
class Server_Game;
class GameEventStorageItem
{
public:
enum EventRecipient
{
SendToPrivate = 0x01,
SendToOthers = 0x02
};
Q_DECLARE_FLAGS(EventRecipients, EventRecipient)
private:
GameEvent *event;
EventRecipients recipients;
public:
GameEventStorageItem(const ::google::protobuf::Message &_event, int _playerId, EventRecipients _recipients);
~GameEventStorageItem();
const GameEvent &getGameEvent() const
{
return *event;
}
EventRecipients getRecipients() const
{
return recipients;
}
};
Q_DECLARE_OPERATORS_FOR_FLAGS(GameEventStorageItem::EventRecipients)
class GameEventStorage
{
private:
::google::protobuf::Message *gameEventContext;
QList<GameEventStorageItem *> gameEventList;
int privatePlayerId;
int forcedByJudge = -1;
bool overwriteOwnership = false;
public:
GameEventStorage();
~GameEventStorage();
void setGameEventContext(const ::google::protobuf::Message &_gameEventContext);
::google::protobuf::Message *getGameEventContext() const
{
return gameEventContext;
}
const QList<GameEventStorageItem *> &getGameEventList() const
{
return gameEventList;
}
int getPrivatePlayerId() const
{
return privatePlayerId;
}
void setForcedByJudge(int playerId)
{
forcedByJudge = playerId;
}
void setOverwriteOwnership(bool shouldOverwriteOwnership)
{
overwriteOwnership = shouldOverwriteOwnership;
}
void enqueueGameEvent(const ::google::protobuf::Message &event,
int playerId,
GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate |
GameEventStorageItem::SendToOthers,
int _privatePlayerId = -1);
void sendToGame(Server_Game *game);
};
class ResponseContainer
{
private:
int cmdId;
::google::protobuf::Message *responseExtension;
QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *>> preResponseQueue, postResponseQueue;
public:
ResponseContainer(int _cmdId);
~ResponseContainer();
int getCmdId() const
{
return cmdId;
}
void setResponseExtension(::google::protobuf::Message *_responseExtension)
{
responseExtension = _responseExtension;
}
::google::protobuf::Message *getResponseExtension() const
{
return responseExtension;
}
void enqueuePreResponseItem(ServerMessage::MessageType type, ::google::protobuf::Message *item)
{
preResponseQueue.append(qMakePair(type, item));
}
void enqueuePostResponseItem(ServerMessage::MessageType type, ::google::protobuf::Message *item)
{
postResponseQueue.append(qMakePair(type, item));
}
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *>> &getPreResponseQueue() const
{
return preResponseQueue;
}
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *>> &getPostResponseQueue() const
{
return postResponseQueue;
}
};
#endif