doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AsyncNetwork.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __ASYNCNETWORK_H__
30 #define __ASYNCNETWORK_H__
31 
32 /*
33 DOOM III gold: 33
34 1.1 beta patch: 34
35 1.1 patch: 35
36 1.2 XP: 36-39
37 1.3 patch: 40
38 1.3.1: 41
39 */
40 const int ASYNC_PROTOCOL_MINOR = 41;
42 #define MAJOR_VERSION(v) ( v >> 16 )
43 
44 const int MAX_ASYNC_CLIENTS = 32;
45 
46 const int MAX_USERCMD_BACKUP = 256;
47 const int MAX_USERCMD_DUPLICATION = 25;
48 const int MAX_USERCMD_RELAY = 10;
49 
50 // index 0 is hardcoded to be the idnet master
51 // which leaves 4 to user customization
52 const int MAX_MASTER_SERVERS = 5;
53 
54 const int MAX_NICKLEN = 32;
55 
56 // max number of servers that will be scanned for at a single IP address
57 const int MAX_SERVER_PORTS = 8;
58 
59 // special game init ids
60 const int GAME_INIT_ID_INVALID = -1;
61 const int GAME_INIT_ID_MAP_LOAD = -2;
62 
63 
64 #include "MsgChannel.h"
65 #include "AsyncServer.h"
66 #include "ServerScan.h"
67 #include "AsyncClient.h"
68 
69 /*
70 ===============================================================================
71 
72  Asynchronous Networking.
73 
74 ===============================================================================
75 */
76 
77 
78 // unreliable server -> client messages
79 enum {
84 };
85 
86 // reliable server -> client messages
87 enum {
97 };
98 
99 // unreliable client -> server messages
100 enum {
104 };
105 
106 // reliable client -> server messages
107 enum {
113 };
114 
115 // server print messages
116 enum {
122 };
123 
124 enum {
128 };
129 
130 enum {
134 };
135 
136 typedef struct master_s {
139  bool resolved;
140 } master_t;
141 
142 
144 public:
145  idAsyncNetwork();
146 
147  static void Init( void );
148  static void Shutdown( void );
149  static bool IsActive( void ) { return ( server.IsActive() || client.IsActive() ); }
150  static void RunFrame( void );
151 
152  static void WriteUserCmdDelta( idBitMsg &msg, const usercmd_t &cmd, const usercmd_t *base );
153  static void ReadUserCmdDelta( const idBitMsg &msg, usercmd_t &cmd, const usercmd_t *base );
154 
155  static bool DuplicateUsercmd( const usercmd_t &previousUserCmd, usercmd_t &currentUserCmd, int frame, int time );
156  static bool UsercmdInputChanged( const usercmd_t &previousUserCmd, const usercmd_t &currentUserCmd );
157 
158  // returns true if the corresponding master is set to something (and could be resolved)
159  static bool GetMasterAddress( int index, netadr_t &adr );
160  // get the hardcoded idnet master, equivalent to GetMasterAddress( 0, .. )
161  static netadr_t GetMasterAddress( void );
162 
163  static void GetNETServers( );
164 
165  static void ExecuteSessionCommand( const char *sessCmd );
166 
169 
170  static idCVar verbose; // verbose output
171  static idCVar allowCheats; // allow cheats
172  static idCVar serverDedicated; // if set run a dedicated server
173  static idCVar serverSnapshotDelay; // number of milliseconds between snapshots
174  static idCVar serverMaxClientRate; // maximum outgoing rate to clients
175  static idCVar clientMaxRate; // maximum rate from server requested by client
176  static idCVar serverMaxUsercmdRelay; // maximum number of usercmds relayed to other clients
177  static idCVar serverZombieTimeout; // time out in seconds for zombie clients
178  static idCVar serverClientTimeout; // time out in seconds for connected clients
179  static idCVar clientServerTimeout; // time out in seconds for server
180  static idCVar serverDrawClient; // the server draws the view of this client
181  static idCVar serverRemoteConsolePassword; // remote console password
182  static idCVar clientPrediction; // how many additional milliseconds the clients runs ahead
183  static idCVar clientMaxPrediction; // max milliseconds into the future a client can run prediction
184  static idCVar clientUsercmdBackup; // how many usercmds the client sends from previous frames
185  static idCVar clientRemoteConsoleAddress; // remote console address
186  static idCVar clientRemoteConsolePassword; // remote console password
187  static idCVar master0; // idnet master server
188  static idCVar master1; // 1st master server
189  static idCVar master2; // 2nd master server
190  static idCVar master3; // 3rd master server
191  static idCVar master4; // 4th master server
192  static idCVar LANServer; // LAN mode
193  static idCVar serverReloadEngine; // reload engine on map change instead of growing the referenced paks
194  static idCVar serverAllowServerMod; // let a pure server start with a different game code than what is referenced in game code
195  static idCVar idleServer; // serverinfo reply, indicates all clients are idle
196  static idCVar clientDownload; // preferred download policy
197 
198  // same message used for offline check and network reply
199  static void BuildInvalidKeyMsg( idStr &msg, bool valid[ 2 ] );
200 
201 private:
202  static int realTime;
203  static master_t masters[ MAX_MASTER_SERVERS]; // master1 etc.
204 
205  static void SpawnServer_f( const idCmdArgs &args );
206  static void NextMap_f( const idCmdArgs &args );
207  static void Connect_f( const idCmdArgs &args );
208  static void Reconnect_f( const idCmdArgs &args );
209  static void GetServerInfo_f( const idCmdArgs &args );
210  static void GetLANServers_f( const idCmdArgs &args );
211  static void ListServers_f( const idCmdArgs &args );
212  static void RemoteConsole_f( const idCmdArgs &args );
213  static void Heartbeat_f( const idCmdArgs &args );
214  static void Kick_f( const idCmdArgs &args );
215  static void CheckNewVersion_f( const idCmdArgs &args );
216  static void UpdateUI_f( const idCmdArgs &args );
217 };
218 
219 #endif /* !__ASYNCNETWORK_H__ */
idCVar * var
Definition: AsyncNetwork.h:137
netadr_t address
Definition: AsyncNetwork.h:138
const int MAX_ASYNC_CLIENTS
Definition: AsyncNetwork.h:44
static void Shutdown(void)
static idCVar serverSnapshotDelay
Definition: AsyncNetwork.h:173
bool IsActive(void) const
Definition: AsyncClient.h:96
static idCVar serverReloadEngine
Definition: AsyncNetwork.h:193
static idCVar serverMaxUsercmdRelay
Definition: AsyncNetwork.h:176
static void Connect_f(const idCmdArgs &args)
bool IsActive(void) const
Definition: AsyncServer.h:143
static int realTime
Definition: AsyncNetwork.h:202
static idCVar clientPrediction
Definition: AsyncNetwork.h:182
static void Init(void)
static idCVar master2
Definition: AsyncNetwork.h:189
const int ASYNC_PROTOCOL_VERSION
Definition: AsyncNetwork.h:41
static idCVar clientDownload
Definition: AsyncNetwork.h:196
#define ASYNC_PROTOCOL_MAJOR
Definition: Licensee.h:77
static idAsyncClient client
Definition: AsyncNetwork.h:168
static idCVar clientMaxPrediction
Definition: AsyncNetwork.h:183
static idCVar LANServer
Definition: AsyncNetwork.h:192
static idCVar master1
Definition: AsyncNetwork.h:188
const int MAX_NICKLEN
Definition: AsyncNetwork.h:54
const int MAX_USERCMD_DUPLICATION
Definition: AsyncNetwork.h:47
static idCVar serverDrawClient
Definition: AsyncNetwork.h:180
static idCVar serverAllowServerMod
Definition: AsyncNetwork.h:194
static idCVar clientRemoteConsoleAddress
Definition: AsyncNetwork.h:185
static void UpdateUI_f(const idCmdArgs &args)
struct master_s master_t
static idCVar serverClientTimeout
Definition: AsyncNetwork.h:178
static idCVar master3
Definition: AsyncNetwork.h:190
static idCVar clientUsercmdBackup
Definition: AsyncNetwork.h:184
const int MAX_MASTER_SERVERS
Definition: AsyncNetwork.h:52
static idCVar serverZombieTimeout
Definition: AsyncNetwork.h:177
static void RemoteConsole_f(const idCmdArgs &args)
static master_t masters[MAX_MASTER_SERVERS]
Definition: AsyncNetwork.h:203
const int GAME_INIT_ID_INVALID
Definition: AsyncNetwork.h:60
static idCVar clientMaxRate
Definition: AsyncNetwork.h:175
static bool IsActive(void)
Definition: AsyncNetwork.h:149
static void GetLANServers_f(const idCmdArgs &args)
GLuint index
Definition: glext.h:3476
const int GAME_INIT_ID_MAP_LOAD
Definition: AsyncNetwork.h:61
static void Reconnect_f(const idCmdArgs &args)
const int ASYNC_PROTOCOL_MINOR
Definition: AsyncNetwork.h:40
static void CheckNewVersion_f(const idCmdArgs &args)
static idAsyncServer server
Definition: AsyncNetwork.h:167
static void WriteUserCmdDelta(idBitMsg &msg, const usercmd_t &cmd, const usercmd_t *base)
static void BuildInvalidKeyMsg(idStr &msg, bool valid[2])
const int MAX_USERCMD_RELAY
Definition: AsyncNetwork.h:48
static void GetNETServers()
static idCVar serverDedicated
Definition: AsyncNetwork.h:172
static void SpawnServer_f(const idCmdArgs &args)
static idCVar master4
Definition: AsyncNetwork.h:191
static void Kick_f(const idCmdArgs &args)
static void Heartbeat_f(const idCmdArgs &args)
static idCVar allowCheats
Definition: AsyncNetwork.h:171
static idCVar serverRemoteConsolePassword
Definition: AsyncNetwork.h:181
static netadr_t GetMasterAddress(void)
static void GetServerInfo_f(const idCmdArgs &args)
const int MAX_SERVER_PORTS
Definition: AsyncNetwork.h:57
static bool UsercmdInputChanged(const usercmd_t &previousUserCmd, const usercmd_t &currentUserCmd)
static void ExecuteSessionCommand(const char *sessCmd)
static idCVar clientRemoteConsolePassword
Definition: AsyncNetwork.h:186
static void RunFrame(void)
static bool DuplicateUsercmd(const usercmd_t &previousUserCmd, usercmd_t &currentUserCmd, int frame, int time)
Definition: Str.h:116
static idCVar serverMaxClientRate
Definition: AsyncNetwork.h:174
static idCVar idleServer
Definition: AsyncNetwork.h:195
const int MAX_USERCMD_BACKUP
Definition: AsyncNetwork.h:46
static idCVar verbose
Definition: AsyncNetwork.h:170
static idCVar clientServerTimeout
Definition: AsyncNetwork.h:179
static void ReadUserCmdDelta(const idBitMsg &msg, usercmd_t &cmd, const usercmd_t *base)
static idCVar master0
Definition: AsyncNetwork.h:187
bool resolved
Definition: AsyncNetwork.h:139
static void ListServers_f(const idCmdArgs &args)
static void NextMap_f(const idCmdArgs &args)