00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __NETCONNECT_H__
00029 #define __NETCONNECT_H__
00030
00032
00033 #include <string>
00034 #include "SDL.h"
00035
00036
00037
00038
00039
00041 #define NetworkProtocolMajorVersion StratagusMajorVersion
00043 #define NetworkProtocolMinorVersion StratagusMinorVersion
00045 #define NetworkProtocolPatchLevel StratagusPatchLevel
00047 #define NetworkProtocolVersion \
00048 (NetworkProtocolMajorVersion * 10000 + NetworkProtocolMinorVersion * 100 + \
00049 NetworkProtocolPatchLevel)
00050
00052 #define NetworkProtocolFormatString "%d.%d.%d"
00054 #define NetworkProtocolFormatArgs(v) (v) / 10000, ((v) / 100) % 100, (v) % 100
00055
00056 #define NetworkDefaultPort 6660
00057
00058
00059
00060
00061
00065 class CNetworkHost {
00066 public:
00067 unsigned char *Serialize() const;
00068 void Deserialize(const unsigned char *p);
00069 static size_t Size() { return 4+2+2+16; }
00070
00071 Uint32 Host;
00072 Uint16 Port;
00073 Uint16 PlyNr;
00074 char PlyName[16];
00075 };
00076
00080 typedef struct _network_state_ {
00081 unsigned char State;
00082 unsigned short MsgCnt;
00083
00084 } NetworkState;
00085
00089 class CServerSetup {
00090 public:
00091 unsigned char *Serialize() const;
00092 void Deserialize(const unsigned char *p);
00093 static size_t Size() { return 1+1+1+1+1+1+1+ 1*PlayerMax + 1*PlayerMax + 4*PlayerMax; }
00094 void Clear() {
00095 ResourcesOption = UnitsOption = FogOfWar = RevealMap =
00096 GameTypeOption = Difficulty = MapRichness = 0;
00097 memset(CompOpt, 0, sizeof(CompOpt));
00098 memset(Ready, 0, sizeof(Ready));
00099 memset(LastFrame, 0, sizeof(LastFrame));
00100 }
00101
00102 Uint8 ResourcesOption;
00103 Uint8 UnitsOption;
00104 Uint8 FogOfWar;
00105 Uint8 RevealMap;
00106 Uint8 GameTypeOption;
00107 Uint8 Difficulty;
00108 Uint8 MapRichness;
00109 Uint8 CompOpt[PlayerMax];
00110 Uint8 Ready[PlayerMax];
00111 Uint32 LastFrame[PlayerMax];
00112
00113 };
00114
00121 class CInitMessage {
00122 public:
00123 unsigned char *Serialize() const;
00124 void Deserialize(const unsigned char *p);
00125 static size_t Size() { return 1+1+4+4+4+4+4+4+1+256; }
00126
00127 Uint8 Type;
00128 Uint8 SubType;
00129 Sint32 Stratagus;
00130 Sint32 Version;
00131 Uint32 ConfUID;
00132 Uint32 MapUID;
00133 Sint32 Lag;
00134 Sint32 Updates;
00135 Uint8 HostsCount;
00136
00137 union {
00138 CNetworkHost Hosts[PlayerMax];
00139 char MapPath[256];
00140 CServerSetup State;
00141 } u;
00142 };
00143
00147 enum _ic_message_subtype_ {
00148 ICMHello,
00149 ICMConfig,
00150
00151 ICMEngineMismatch,
00152 ICMProtocolMismatch,
00153 ICMEngineConfMismatch,
00154 ICMMapUidMismatch,
00155
00156 ICMGameFull,
00157 ICMWelcome,
00158
00159 ICMWaiting,
00160 ICMMap,
00161 ICMState,
00162 ICMResync,
00163
00164 ICMServerQuit,
00165 ICMGoodBye,
00166 ICMSeeYou,
00167
00168 ICMGo,
00169
00170 ICMAYT,
00171 ICMIAH,
00172 };
00173
00177 enum _net_client_con_state_ {
00178 ccs_unused = 0,
00179 ccs_connecting,
00180 ccs_connected,
00181 ccs_mapinfo,
00182 ccs_badmap,
00183 ccs_synced,
00184 ccs_async,
00185 ccs_changed,
00186 ccs_detaching,
00187 ccs_disconnected,
00188 ccs_unreachable,
00189 ccs_usercanceled,
00190 ccs_nofreeslots,
00191 ccs_serverquits,
00192 ccs_goahead,
00193 ccs_started,
00194 ccs_incompatibleengine,
00195 ccs_incompatiblenetwork,
00196 };
00197
00198
00199
00200
00201
00202 extern std::string NetworkArg;
00203 extern int NetPlayers;
00204 extern int NetworkPort;
00205
00206 extern std::string LocalPlayerName;
00207
00208 extern int HostsCount;
00209 extern CNetworkHost Hosts[PlayerMax];
00210
00211 extern int NetConnectRunning;
00212 extern NetworkState NetStates[PlayerMax];
00213 extern unsigned char NetLocalState;
00214 extern int NetLocalHostsSlot;
00215 extern int NetLocalPlayerNumber;
00216
00217 extern CServerSetup ServerSetupState;
00218 extern CServerSetup LocalSetupState;
00219
00220
00221
00222
00223
00224 extern void NetworkServerStartGame(void);
00225 extern void NetworkGamePrepareGameSettings(void);
00226 extern void NetworkConnectSetupGame(void);
00227
00228 extern void NetworkInitClientConnect(void);
00229 extern void NetworkExitClientConnect(void);
00230 extern void NetworkInitServerConnect(int openslots);
00231 extern void NetworkExitServerConnect(void);
00232 extern int NetworkParseSetupEvent(const unsigned char *buf, int size);
00233 extern int NetworkSetupServerAddress(const std::string &serveraddr);
00234 extern void NetworkProcessClientRequest(void);
00235 extern void NetworkProcessServerRequest(void);
00236 extern void NetworkServerResyncClients(void);
00237 extern void NetworkDetachFromServer(void);
00238
00240
00241 #endif // !__NETCONNECT_H__