File: NetPacksLobby.h

package info (click to toggle)
vcmi 0.99%2Bdfsg%2Bgit20190113.f06c8a87-2
  • links: PTS, VCS
  • area: contrib
  • in suites: bullseye
  • size: 11,136 kB
  • sloc: cpp: 142,615; sh: 315; objc: 248; makefile: 32; ansic: 28; python: 13
file content (311 lines) | stat: -rw-r--r-- 7,342 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*
 * NetPacksLobby.h, part of VCMI engine
 *
 * Authors: listed in file AUTHORS in main folder
 *
 * License: GNU General Public License v2.0 or later
 * Full text of license available in license.txt file, in main folder
 *
 */
#pragma once

#include "NetPacksBase.h"

#include "StartInfo.h"

class CCampaignState;
class CLobbyScreen;
class CServerHandler;
class CMapInfo;
struct StartInfo;
class CMapGenOptions;
struct ClientPlayer;
class CVCMIServer;

struct CPackForLobby : public CPack
{
	bool checkClientPermissions(CVCMIServer * srv) const
	{
		return false;
	}

	bool applyOnServer(CVCMIServer * srv)
	{
		return true;
	}

	void applyOnServerAfterAnnounce(CVCMIServer * srv) {}

	bool applyOnLobbyHandler(CServerHandler * handler)
	{
		return true;
	}

	void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler) {}
};

struct CLobbyPackToPropagate : public CPackForLobby
{

};

struct CLobbyPackToServer : public CPackForLobby
{
	bool checkClientPermissions(CVCMIServer * srv) const;
	void applyOnServerAfterAnnounce(CVCMIServer * srv);
};

struct LobbyClientConnected : public CLobbyPackToPropagate
{
	// Set by client before sending pack to server
	std::string uuid;
	std::vector<std::string> names;
	StartInfo::EMode mode;
	// Changed by server before announcing pack
	int clientId;
	int hostClientId;

	LobbyClientConnected()
		: mode(StartInfo::INVALID), clientId(-1), hostClientId(-1)
	{}

	bool checkClientPermissions(CVCMIServer * srv) const;
	bool applyOnLobbyHandler(CServerHandler * handler);
	void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);
	bool applyOnServer(CVCMIServer * srv);
	void applyOnServerAfterAnnounce(CVCMIServer * srv);

	template <typename Handler> void serialize(Handler & h, const int version)
	{
		h & uuid;
		h & names;
		h & mode;

		h & clientId;
		h & hostClientId;
	}
};

struct LobbyClientDisconnected : public CLobbyPackToPropagate
{
	int clientId;
	bool shutdownServer;

	LobbyClientDisconnected() : shutdownServer(false) {}
	bool checkClientPermissions(CVCMIServer * srv) const;
	bool applyOnServer(CVCMIServer * srv);
	void applyOnServerAfterAnnounce(CVCMIServer * srv);
	bool applyOnLobbyHandler(CServerHandler * handler);
	void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & clientId;
		h & shutdownServer;
	}
};

struct LobbyChatMessage : public CLobbyPackToPropagate
{
	std::string playerName, message;

	bool checkClientPermissions(CVCMIServer * srv) const;
	void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & playerName;
		h & message;
	}
};

struct LobbyGuiAction : public CLobbyPackToPropagate
{
	enum EAction : ui8 {
		NONE, NO_TAB, OPEN_OPTIONS, OPEN_SCENARIO_LIST, OPEN_RANDOM_MAP_OPTIONS
	} action;

	LobbyGuiAction() : action(NONE) {}
	bool checkClientPermissions(CVCMIServer * srv) const;
	void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & action;
	}
};

struct LobbyStartGame : public CLobbyPackToPropagate
{
	// Set by server
	std::shared_ptr<StartInfo> initializedStartInfo;

	LobbyStartGame() : initializedStartInfo(nullptr) {}
	bool checkClientPermissions(CVCMIServer * srv) const;
	bool applyOnServer(CVCMIServer * srv);
	void applyOnServerAfterAnnounce(CVCMIServer * srv);
	bool applyOnLobbyHandler(CServerHandler * handler);
	void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & initializedStartInfo;
	}
};

struct LobbyChangeHost : public CLobbyPackToPropagate
{
	int newHostConnectionId;

	LobbyChangeHost() : newHostConnectionId(-1) {}
	bool checkClientPermissions(CVCMIServer * srv) const;
	bool applyOnServer(CVCMIServer * srv);
	bool applyOnServerAfterAnnounce(CVCMIServer * srv);

	template <typename Handler> void serialize(Handler & h, const int version)
	{
		h & newHostConnectionId;
	}
};

struct LobbyUpdateState : public CLobbyPackToPropagate
{
	LobbyState state;
	bool hostChanged; // Used on client-side only

	LobbyUpdateState() : hostChanged(false) {}
	bool applyOnLobbyHandler(CServerHandler * handler);
	void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & state;
	}
};

struct LobbySetMap : public CLobbyPackToServer
{
	std::shared_ptr<CMapInfo> mapInfo;
	std::shared_ptr<CMapGenOptions> mapGenOpts;

	LobbySetMap() : mapInfo(nullptr), mapGenOpts(nullptr) {}
	bool applyOnServer(CVCMIServer * srv);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & mapInfo;
		h & mapGenOpts;
	}
};

struct LobbySetCampaign : public CLobbyPackToServer
{
	std::shared_ptr<CCampaignState> ourCampaign;

	LobbySetCampaign() {}
	bool applyOnServer(CVCMIServer * srv);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & ourCampaign;
	}
};

struct LobbySetCampaignMap : public CLobbyPackToServer
{
	int mapId;

	LobbySetCampaignMap() : mapId(-1) {}
	bool applyOnServer(CVCMIServer * srv);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & mapId;
	}
};

struct LobbySetCampaignBonus : public CLobbyPackToServer
{
	int bonusId;

	LobbySetCampaignBonus() : bonusId(-1) {}
	bool applyOnServer(CVCMIServer * srv);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & bonusId;
	}
};

struct LobbyChangePlayerOption : public CLobbyPackToServer
{
	enum EWhat : ui8 {UNKNOWN, TOWN, HERO, BONUS};
	ui8 what;
	si8 direction; //-1 or +1
	PlayerColor color;

	LobbyChangePlayerOption() : what(UNKNOWN), direction(0), color(PlayerColor::CANNOT_DETERMINE) {}
	bool checkClientPermissions(CVCMIServer * srv) const;
	bool applyOnServer(CVCMIServer * srv);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & what;
		h & direction;
		h & color;
	}
};

struct LobbySetPlayer : public CLobbyPackToServer
{
	PlayerColor clickedColor;

	LobbySetPlayer() : clickedColor(PlayerColor::CANNOT_DETERMINE){}
	bool applyOnServer(CVCMIServer * srv);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & clickedColor;
	}
};

struct LobbySetTurnTime : public CLobbyPackToServer
{
	ui8 turnTime;

	LobbySetTurnTime() : turnTime(0) {}
	bool applyOnServer(CVCMIServer * srv);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & turnTime;
	}
};

struct LobbySetDifficulty : public CLobbyPackToServer
{
	ui8 difficulty;

	LobbySetDifficulty() : difficulty(0) {}
	bool applyOnServer(CVCMIServer * srv);

	template <typename Handler> void serialize(Handler &h, const int version)
	{
		h & difficulty;
	}
};

struct LobbyForceSetPlayer : public CLobbyPackToServer
{
	ui8 targetConnectedPlayer;
	PlayerColor targetPlayerColor;

	LobbyForceSetPlayer() : targetConnectedPlayer(-1), targetPlayerColor(PlayerColor::CANNOT_DETERMINE) {}
	bool applyOnServer(CVCMIServer * srv);

	template <typename Handler> void serialize(Handler & h, const int version)
	{
		h & targetConnectedPlayer;
		h & targetPlayerColor;
	}
};