2
// / __ )____ _____ | | / /___ ___________
3
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5
// /_____/\____/____/ |__/|__/\__,_/_/ /____/
7
// A futuristic real-time strategy game.
8
// This file is part of Bos Wars.
10
/**@name netconnect.h - The network connection setup header file. */
12
// (c) Copyright 1998-2008 by Lutz Sammer, Andreas Arens, and Jimmy Salmon
14
// This program is free software; you can redistribute it and/or modify
15
// it under the terms of the GNU General Public License as published by
16
// the Free Software Foundation; only version 2 of the License.
18
// This program is distributed in the hope that it will be useful,
19
// but WITHOUT ANY WARRANTY; without even the implied warranty of
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
// GNU General Public License for more details.
23
// You should have received a copy of the GNU General Public License
24
// along with this program; if not, write to the Free Software
25
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28
#ifndef __NETCONNECT_H__
29
#define __NETCONNECT_H__
36
/*----------------------------------------------------------------------------
38
----------------------------------------------------------------------------*/
40
/// Network protocol major version
41
#define NetworkProtocolMajorVersion StratagusMajorVersion
42
/// Network protocol minor version (maximal 99)
43
#define NetworkProtocolMinorVersion StratagusMinorVersion
44
/// Network protocol patch level (maximal 99)
45
#define NetworkProtocolPatchLevel StratagusPatchLevel
46
/// Network protocol version (1,2,3) -> 10203
47
#define NetworkProtocolVersion \
48
(NetworkProtocolMajorVersion * 10000 + NetworkProtocolMinorVersion * 100 + \
49
NetworkProtocolPatchLevel)
51
/// Network protocol printf format string
52
#define NetworkProtocolFormatString "%d.%d.%d"
53
/// Network protocol printf format arguments
54
#define NetworkProtocolFormatArgs(v) (v) / 10000, ((v) / 100) % 100, (v) % 100
56
#define NetworkDefaultPort 6660 /// Default communication port
58
/*----------------------------------------------------------------------------
60
----------------------------------------------------------------------------*/
63
* Number of bytes in the name of a network player,
64
* including the terminating null character.
66
#define NetPlayerNameSize 16
69
** Network systems active in current game.
73
unsigned char *Serialize() const;
74
void Deserialize(const unsigned char *p);
75
static size_t Size() { return 4+2+2+NetPlayerNameSize; }
77
Uint32 Host; /// Host address
78
Uint16 Port; /// Port on host
79
Uint16 PlyNr; /// Player nummer
80
char PlyName[NetPlayerNameSize]; /// Name of player
84
** Connect state information of network systems active in current game.
86
typedef struct _network_state_ {
87
unsigned char State; /// Menu: ConnectState
88
unsigned short MsgCnt; /// Menu: Counter for state msg of same type (detect unreachable)
93
** Multiplayer game setup menu state
97
unsigned char *Serialize() const;
98
void Deserialize(const unsigned char *p);
99
static size_t Size() { return 1+1+1+1+1+1+1+ 1*PlayerMax + 1*PlayerMax + 4*PlayerMax; }
101
ResourcesOption = UnitsOption = FogOfWar = RevealMap =
102
GameTypeOption = Difficulty = MapRichness = 0;
103
memset(CompOpt, 0, sizeof(CompOpt));
104
memset(Ready, 0, sizeof(Ready));
105
memset(LastFrame, 0, sizeof(LastFrame));
108
Uint8 ResourcesOption; /// Resources option
109
Uint8 UnitsOption; /// Unit # option
110
Uint8 FogOfWar; /// Fog of war option
111
Uint8 RevealMap; /// Reveal all the map
112
Uint8 GameTypeOption; /// Game type option
113
Uint8 Difficulty; /// Difficulty option
114
Uint8 MapRichness; /// Map richness option
115
Uint8 CompOpt[PlayerMax]; /// Free slot option selection {"Available", "Computer", "Closed" }
116
Uint8 Ready[PlayerMax]; /// Client ready state
117
Uint32 LastFrame[PlayerMax]; /// Last message received
122
** Network init message.
124
** @todo Transfering the same data in each message is waste of bandwidth.
125
** I mean the versions and the UID ...
129
unsigned char *Serialize() const;
130
void Deserialize(const unsigned char *p);
131
static size_t Size() { return 1+1+4+4+4+4+4+4+1+256; }
133
Uint8 Type; /// Init message type
134
Uint8 SubType; /// Init message subtype
135
Sint32 Stratagus; /// Stratagus engine version
136
Sint32 Version; /// Network protocol version
137
Uint32 ConfUID; /// Engine configuration UID (Checksum) FIXME: not available yet
138
Uint32 MapUID; /// UID of map to play. FIXME: add MAP name, path, etc
139
Sint32 Lag; /// Lag time
140
Sint32 Updates; /// Update frequency
141
Uint8 HostsCount; /// Number of hosts
144
CNetworkHost Hosts[PlayerMax]; /// Participant information
146
CServerSetup State; /// Server Setup State information
151
** Network init config message subtypes (menu state machine).
153
enum _ic_message_subtype_ {
154
ICMHello, /// Client Request
155
ICMConfig, /// Setup message configure clients
157
ICMEngineMismatch, /// Stratagus engine version doesn't match
158
ICMProtocolMismatch, /// Network protocol version doesn't match
159
ICMEngineConfMismatch, /// Engine configuration isn't identical
160
ICMMapUidMismatch, /// MAP UID doesn't match
162
ICMGameFull, /// No player slots available
163
ICMWelcome, /// Acknowledge for new client connections
165
ICMWaiting, /// Client has received Welcome and is waiting for Map/State
166
ICMMap, /// MapInfo (and Mapinfo Ack)
167
ICMState, /// StateInfo
168
ICMResync, /// Ack StateInfo change
170
ICMServerQuit, /// Server has quit game
171
ICMGoodBye, /// Client wants to leave game
172
ICMSeeYou, /// Client has left game
174
ICMGo, /// Client is ready to run
176
ICMAYT, /// Server asks are you there
177
ICMIAH, /// Client answers I am here
181
** Network Client connect states
183
enum _net_client_con_state_ {
184
ccs_unused = 0, /// Unused.
185
ccs_connecting, /// New client
186
ccs_connected, /// Has received slot info
187
ccs_mapinfo, /// Has received matching map-info
188
ccs_badmap, /// Has received non-matching map-info
189
ccs_synced, /// Client is in sync with server
190
ccs_async, /// Server user has changed selection
191
ccs_changed, /// Client user has made menu selection
192
ccs_detaching, /// Client user wants to detach
193
ccs_disconnected, /// Client has detached
194
ccs_unreachable, /// Server is unreachable
195
ccs_usercanceled, /// Connection canceled by user
196
ccs_nofreeslots, /// Server has no more free slots
197
ccs_serverquits, /// Server quits
198
ccs_goahead, /// Server wants to start game
199
ccs_started, /// Server has started game
200
ccs_incompatibleengine, /// Incompatible engine version
201
ccs_incompatiblenetwork, /// Incompatible netowrk version
204
/*----------------------------------------------------------------------------
206
----------------------------------------------------------------------------*/
208
extern int NetPlayers; /// Network players
209
extern int NetworkPort; /// Local network port to use
211
extern std::string LocalPlayerName; /// Name of local player
213
extern int HostsCount; /// Number of hosts.
214
extern CNetworkHost Hosts[PlayerMax]; /// Host, port, and number of all players.
216
extern int NetConnectRunning; /// Network menu: Setup mode active
217
extern NetworkState NetStates[PlayerMax]; /// Network menu: Server: Client Host states
218
extern unsigned char NetLocalState; /// Network menu: Local Server/Client connect state
219
extern int NetLocalHostsSlot; /// Network menu: Slot # in Hosts array of local client
220
extern int NetLocalPlayerNumber; /// Player number of local client
222
extern CServerSetup ServerSetupState; /// Network menu: Multiplayer Server Menu selections state
223
extern CServerSetup LocalSetupState; /// Network menu: Multiplayer Client Menu selections local state
225
/*----------------------------------------------------------------------------
227
----------------------------------------------------------------------------*/
229
extern void NetworkServerStartGame(void); /// Server user has finally hit the start game button
230
extern void NetworkGamePrepareGameSettings(void);
231
extern void NetworkConnectSetupGame(void); /// Assign Player slot, evaluate Setup state..
233
extern void NetworkInitClientConnect(void); /// Setup network connect state machine for clients
234
extern void NetworkExitClientConnect(void); /// Terminate network connect state machine for clients
235
extern void NetworkInitServerConnect(int openslots); /// Setup network connect state machine for the server
236
extern void NetworkExitServerConnect(void); /// Terminate network connect state machine for the server
237
extern int NetworkParseSetupEvent(const unsigned char *buf, int size); /// Parse a network connect event
238
extern int NetworkSetupServerAddress(const std::string &serveraddr); /// Menu: Setup the server IP
239
extern void NetworkProcessClientRequest(void); /// Menu Loop: Send out client request messages
240
extern void NetworkProcessServerRequest(void); /// Menu Loop: Send out server request messages
241
extern void NetworkServerResyncClients(void); /// Menu Loop: Server: Mark clients state to send stateinfo message
242
extern void NetworkDetachFromServer(void); /// Menu Loop: Client: Send GoodBye to the server and detach
246
#endif // !__NETCONNECT_H__