1 #ifndef SERVER_RESPONSE_CONTAINERS_H
2 #define SERVER_RESPONSE_CONTAINERS_H
3
4 #include "pb/server_message.pb.h"
5
6 #include <QList>
7 #include <QPair>
8
9 namespace google
10 {
11 namespace protobuf
12 {
13 class Message;
14 }
15 } // namespace google
16 class Server_Game;
17
18 class GameEventStorageItem
19 {
20 public:
21 enum EventRecipient
22 {
23 SendToPrivate = 0x01,
24 SendToOthers = 0x02
25 };
26 Q_DECLARE_FLAGS(EventRecipients, EventRecipient)
27 private:
28 GameEvent *event;
29 EventRecipients recipients;
30
31 public:
32 GameEventStorageItem(const ::google::protobuf::Message &_event, int _playerId, EventRecipients _recipients);
33 ~GameEventStorageItem();
34
getGameEvent()35 const GameEvent &getGameEvent() const
36 {
37 return *event;
38 }
getRecipients()39 EventRecipients getRecipients() const
40 {
41 return recipients;
42 }
43 };
Q_DECLARE_OPERATORS_FOR_FLAGS(GameEventStorageItem::EventRecipients)44 Q_DECLARE_OPERATORS_FOR_FLAGS(GameEventStorageItem::EventRecipients)
45
46 class GameEventStorage
47 {
48 private:
49 ::google::protobuf::Message *gameEventContext;
50 QList<GameEventStorageItem *> gameEventList;
51 int privatePlayerId;
52 int forcedByJudge = -1;
53
54 public:
55 GameEventStorage();
56 ~GameEventStorage();
57
58 void setGameEventContext(const ::google::protobuf::Message &_gameEventContext);
59 ::google::protobuf::Message *getGameEventContext() const
60 {
61 return gameEventContext;
62 }
63 const QList<GameEventStorageItem *> &getGameEventList() const
64 {
65 return gameEventList;
66 }
67 int getPrivatePlayerId() const
68 {
69 return privatePlayerId;
70 }
71 void setForcedByJudge(int playerId)
72 {
73 forcedByJudge = playerId;
74 }
75
76 void enqueueGameEvent(const ::google::protobuf::Message &event,
77 int playerId,
78 GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate |
79 GameEventStorageItem::SendToOthers,
80 int _privatePlayerId = -1);
81 void sendToGame(Server_Game *game);
82 };
83
84 class ResponseContainer
85 {
86 private:
87 int cmdId;
88 ::google::protobuf::Message *responseExtension;
89 QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *>> preResponseQueue, postResponseQueue;
90
91 public:
92 ResponseContainer(int _cmdId);
93 ~ResponseContainer();
94
getCmdId()95 int getCmdId() const
96 {
97 return cmdId;
98 }
setResponseExtension(::google::protobuf::Message * _responseExtension)99 void setResponseExtension(::google::protobuf::Message *_responseExtension)
100 {
101 responseExtension = _responseExtension;
102 }
getResponseExtension()103 ::google::protobuf::Message *getResponseExtension() const
104 {
105 return responseExtension;
106 }
enqueuePreResponseItem(ServerMessage::MessageType type,::google::protobuf::Message * item)107 void enqueuePreResponseItem(ServerMessage::MessageType type, ::google::protobuf::Message *item)
108 {
109 preResponseQueue.append(qMakePair(type, item));
110 }
enqueuePostResponseItem(ServerMessage::MessageType type,::google::protobuf::Message * item)111 void enqueuePostResponseItem(ServerMessage::MessageType type, ::google::protobuf::Message *item)
112 {
113 postResponseQueue.append(qMakePair(type, item));
114 }
getPreResponseQueue()115 const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *>> &getPreResponseQueue() const
116 {
117 return preResponseQueue;
118 }
getPostResponseQueue()119 const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *>> &getPostResponseQueue() const
120 {
121 return postResponseQueue;
122 }
123 };
124
125 #endif
126