1 /*=============================================================================
2 Blobby Volley 2
3 Copyright (C) 2006 Jonathan Sieber (jonathan_sieber@yahoo.de)
4 Copyright (C) 2006 Daniel Knobe (daniel-knobe@web.de)
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 =============================================================================*/
20 
21 #pragma once
22 
23 #include <string>
24 #include <iosfwd>
25 #include <stdint.h>
26 
27 #include "raknet/PacketEnumerations.h"
28 #include "raknet/NetworkTypes.h"
29 #include "raknet/BitStream.h"
30 #include "BlobbyDebug.h"
31 
32 enum MessageType
33 {
34 	ID_GENERIC_MESSAGE = ID_RESERVED9 + 1,
35 	ID_INPUT_UPDATE,
36 	ID_PHYSIC_UPDATE,
37 	ID_WIN_NOTIFICATION,
38 	ID_OPPONENT_DISCONNECTED,
39 	ID_BALL_RESET,
40 	ID_COLLISION,
41 	ID_CURRENTLY_UNUSED_2,	// was ID_BALL_PLAYER_COLLISION, now handled via ID_COLLISION
42 	ID_GAME_READY,
43 	ID_ENTER_SERVER,
44 	ID_PAUSE,
45 	ID_UNPAUSE,
46 	ID_BLOBBY_SERVER_PRESENT,
47 	ID_VERSION_MISMATCH,
48 	ID_CURRENTLY_UNUSED,	// this value is to ensure network protocol compatibility between 0.9c and 1.0
49 	ID_REPLAY,
50 	ID_CHAT_MESSAGE,
51 	ID_UPDATE_SCORE,		// no longer used, as ID_PHYSIC_UPDATE also contains the score information, and ID_BALL_RESET also works as a sync point for clocks
52 	ID_RULES_CHECKSUM,
53 	ID_RULES,
54 	ID_SERVER_STATUS,
55 	ID_CHALLENGE
56 };
57 
58 // General Information:
59 // 	Because the client may choose their side and the server rotates
60 // 	everything if necessary, PlayerSide informations may not be
61 // 	correct on all peers. When the server sends a side information
62 // 	to a client, the information has to be converted into the view
63 // 	of the client.
64 
65 // ID_INPUT_UPDATE = 63:
66 // 	Description:
67 // 		This packet is sent from client to server every frame.
68 // 		It contains the current input state as three booleans.
69 // 	Structure:
70 // 		ID_INPUT_UPDATE
71 // 		ID_TIMESTAMP
72 // 		timestamp (int)
73 // 		left keypress (bool)
74 // 		right keypress (bool)
75 // 		up keypress (bool)
76 //
77 // ID_PHYSIC_UPDATE:
78 // 	Description:
79 // 		The server sends this information of the current physics state
80 // 		to all clients every frame. Local physic states will always
81 // 		be overwritten.
82 // 	Structure:
83 // 		ID_PHYSIC_UPDATE
84 // 		ID_TIMESTAMP
85 // 		timestamp (int)
86 //		packet_number (unsigned char)
87 // 		Physic data (analysed by PhysicWorld)
88 //
89 // ID_WIN_NOTIFICATION
90 // 	Description:
91 // 		Message sent from server to all clients when a player
92 // 		won the game. The appended enum tells the client which
93 // 		player won.
94 // 	Structure:
95 // 		ID_WIN_NOTIFICATION
96 // 		winning player (PlayerSide)
97 //
98 // ID_BALL_RESET
99 // 	Description:
100 // 		 Message sent from server to all clients when the ball
101 // 		 is reset to the starting position. It includes an information
102 // 		 about the current point state and is used to synchronize
103 //		 the clocks.
104 // 	Structure:
105 // 		ID_BALL_RESET
106 // 		serving player (PlayerSide)
107 // 		left score (int)
108 // 		right score (int)
109 //		time (int)
110 //
111 // ID_COLLISION
112 // 	Description:
113 // 		Message sent from server to all clients when the ball
114 // 		hits a player or the ground.  It is the only valid reason for a player
115 // 		collision sound. The event attribute contains the DuelMatch Event that
116 //		caused the packet to be sent, intensity contains the hit intensity (only valid for player collisions)
117 // 	Structure:
118 // 		ID_BALL_PLAYER_COLLISION
119 //		event (int)
120 // 		intensity (float)
121 //
122 // ID_GAME_READY
123 // 	Description:
124 // 		Message sent from server to client when all clients are
125 // 		ready. The input is enabled after this message on the client.
126 // 		The attribute opponent name carrys the name of the connected
127 // 		opponent.
128 // 	Structure:
129 // 		ID_GAME_READY
130 //		gamespeed (int)
131 // 		opponent name (char[16])
132 //		opponent color (int)
133 //
134 // ID_ENTER_SERVER
135 // 	Description:
136 // 		Message sent from client to server after connecting to it.
137 // 		The side attribute tells the server on which side the client
138 // 		wants to play. The name attribute reports to players name,
139 // 		truncated to 16 characters. Color is the network color.
140 // 	Structure:
141 // 		ID_ENTER_SERVER
142 // 		side (PlayerSide)
143 // 		name (char[16])
144 //		color (int)
145 //
146 // ID_PAUSE
147 // 	Description:
148 // 		Sent from client to server, this message can be seen as a request
149 // 		to pause the game. From server to client it is an acknowledgement
150 // 		of the pause and request demand to display an appropriate dialog.
151 // 	Structure:
152 // 		ID_PAUSE
153 //
154 // ID_UNPAUSE
155 // 	Description:
156 // 		As ID_PAUSE, this packets is an acknowledgement if sent from a client
157 // 		and a request if sent from the server.
158 // 	Structure:
159 // 		ID_UNPAUSE
160 //
161 // ID_OPPONENTED_DISCONNECTED
162 // 	Description:
163 // 		Sent from server to client when an opponent left the game
164 // 	Structure:
165 // 		ID_OPPONENT_DISCONNECTED
166 //
167 // ID_BLOBBY_SERVER_PRESENT
168 // 	Description:
169 // 		Sent from client to probe a server and from server to client
170 // 		as answer to the same packet.
171 // 		Sent with version number since alpha 7 in the first case.
172 // 	Structure:
173 // 		ID_BLOBBY_SERVER_PRESENT
174 // 		major (int)
175 // 		minor (int)
176 //
177 // ID_VERSION_MISMATCH
178 // 	Description:
179 // 		Sent from server to client if the version number
180 // 		differes from the one of the server.
181 // 	Structure:
182 // 		ID_VERSION_MISMATCH
183 //		server_major (int)
184 //		server_minor (int)
185 //
186 // ID_REPLAY
187 // 	Description:
188 // 		Sent from client to server to request a replay
189 // 		Sent from server to client to transmitt the replay
190 // 	Structure:
191 // 		ID_REPLAY
192 //		size (int)
193 //		data
194 //
195 // ID_RULES_CHECKSUM
196 // 	Description:
197 // 		Sent from server to client to tell rules file checksum
198 // 		Client should send ID_RULES after receiving ID_RULES_CHECKSUM
199 // 			to tell server if he needs rules file transmitting
200 // 	Structure:
201 // 		ID_RULES_CHECKSUM
202 //		checksum (int)
203 //
204 // ID_RULES
205 // 	Description:
206 // 		Sent from client to server to request a rules file
207 // 		Sent from server to client to transmit the rules file
208 // 		Game is starting only after transmitting a rules file
209 // 	Structure (from client to server):
210 // 		ID_RULES
211 //		needRules (bool)
212 // 	Structure (from server to client):
213 // 		ID_RULES
214 //		size (int)
215 //		data
216 //
217 // ID_SERVER_STATUS
218 // 	Description:
219 //		Sent from server to waiting clients with information about the
220 //		current server status
221 //	Structure:
222 //		ID_SERVER_STATUS
223 //		vector<string> playernames
224 //
225 // ID_CHALLENGE
226 // 	Description:
227 //		Sent when the client wants to start a game. If desired opponent is set, the server looks for that
228 //		opponent and matches these players.
229 //		Sent from the server when another player wants to start a game with this client.
230 //	Structure:
231 //		ID_CHALLENGE
232 //		PlayerID opponent
233 //
234 
235 
236 class IUserConfigReader;
237 
238 struct ServerInfo : public ObjectCounter<ServerInfo>
239 {
240 	// read server info from a bit stream, additionally, the server address and port are needed
241 	ServerInfo(RakNet::BitStream& stream, const char* ip, uint16_t port);
242 	// read server info from a user config object
243 	ServerInfo(const IUserConfigReader& config);
244 	ServerInfo(const std::string& playername);
245 
246 	void writeToBitstream(RakNet::BitStream& stream);
247 
248 	/// \todo maybe we should define ServerInfo a little bit more
249 	///			as e.g., hostname can be left uninitialised on server
250 	/// we combine to functionsalities here: server information and server addresses.
251 	int activegames;
252 	int gamespeed;
253 	uint16_t port;
254 	char hostname[64];
255 	char name[32];
256 	int waitingplayers;
257 	char description[192];
258 
259 	char rulestitle[32];
260 	char rulesauthor[32];
261 
262 	static const size_t BLOBBY_SERVER_PRESENT_PACKET_SIZE;
263 };
264 
265 bool operator == (const ServerInfo& lval, const ServerInfo& rval);
266 std::ostream& operator<<(std::ostream& stream, const ServerInfo& val);
267