AsyncNetwork.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code 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 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #ifndef __ASYNCNETWORK_H__
  21. #define __ASYNCNETWORK_H__
  22. /*
  23. DOOM III gold: 33
  24. 1.1 beta patch: 34
  25. 1.1 patch: 35
  26. 1.2 XP: 36-39
  27. 1.3 patch: 40
  28. 1.3.1: 41
  29. */
  30. const int ASYNC_PROTOCOL_MINOR = 41;
  31. const int ASYNC_PROTOCOL_VERSION = ( ASYNC_PROTOCOL_MAJOR << 16 ) + ASYNC_PROTOCOL_MINOR;
  32. #define MAJOR_VERSION(v) ( v >> 16 )
  33. const int MAX_ASYNC_CLIENTS = 32;
  34. const int MAX_USERCMD_BACKUP = 256;
  35. const int MAX_USERCMD_DUPLICATION = 25;
  36. const int MAX_USERCMD_RELAY = 10;
  37. // index 0 is hardcoded to be the idnet master
  38. // which leaves 4 to user customization
  39. const int MAX_MASTER_SERVERS = 5;
  40. const int MAX_NICKLEN = 32;
  41. // max number of servers that will be scanned for at a single IP address
  42. const int MAX_SERVER_PORTS = 8;
  43. // special game init ids
  44. const int GAME_INIT_ID_INVALID = -1;
  45. const int GAME_INIT_ID_MAP_LOAD = -2;
  46. #include "MsgChannel.h"
  47. #include "AsyncServer.h"
  48. #include "ServerScan.h"
  49. #include "AsyncClient.h"
  50. /*
  51. ===============================================================================
  52. Asynchronous Networking.
  53. ===============================================================================
  54. */
  55. // unreliable server -> client messages
  56. enum {
  57. SERVER_UNRELIABLE_MESSAGE_EMPTY = 0,
  58. SERVER_UNRELIABLE_MESSAGE_PING,
  59. SERVER_UNRELIABLE_MESSAGE_GAMEINIT,
  60. SERVER_UNRELIABLE_MESSAGE_SNAPSHOT
  61. };
  62. // reliable server -> client messages
  63. enum {
  64. SERVER_RELIABLE_MESSAGE_PURE = 0,
  65. SERVER_RELIABLE_MESSAGE_RELOAD,
  66. SERVER_RELIABLE_MESSAGE_CLIENTINFO,
  67. SERVER_RELIABLE_MESSAGE_SYNCEDCVARS,
  68. SERVER_RELIABLE_MESSAGE_PRINT,
  69. SERVER_RELIABLE_MESSAGE_DISCONNECT,
  70. SERVER_RELIABLE_MESSAGE_APPLYSNAPSHOT,
  71. SERVER_RELIABLE_MESSAGE_GAME,
  72. SERVER_RELIABLE_MESSAGE_ENTERGAME
  73. };
  74. // unreliable client -> server messages
  75. enum {
  76. CLIENT_UNRELIABLE_MESSAGE_EMPTY = 0,
  77. CLIENT_UNRELIABLE_MESSAGE_PINGRESPONSE,
  78. CLIENT_UNRELIABLE_MESSAGE_USERCMD
  79. };
  80. // reliable client -> server messages
  81. enum {
  82. CLIENT_RELIABLE_MESSAGE_PURE = 0,
  83. CLIENT_RELIABLE_MESSAGE_CLIENTINFO,
  84. CLIENT_RELIABLE_MESSAGE_PRINT,
  85. CLIENT_RELIABLE_MESSAGE_DISCONNECT,
  86. CLIENT_RELIABLE_MESSAGE_GAME
  87. };
  88. // server print messages
  89. enum {
  90. SERVER_PRINT_MISC = 0,
  91. SERVER_PRINT_BADPROTOCOL,
  92. SERVER_PRINT_RCON,
  93. SERVER_PRINT_GAMEDENY,
  94. SERVER_PRINT_BADCHALLENGE
  95. };
  96. enum {
  97. SERVER_DL_REDIRECT = 1,
  98. SERVER_DL_LIST,
  99. SERVER_DL_NONE
  100. };
  101. enum {
  102. SERVER_PAK_NO = 0,
  103. SERVER_PAK_YES,
  104. SERVER_PAK_END
  105. };
  106. typedef struct master_s {
  107. idCVar * var;
  108. netadr_t address;
  109. bool resolved;
  110. } master_t;
  111. class idAsyncNetwork {
  112. public:
  113. idAsyncNetwork();
  114. static void Init( void );
  115. static void Shutdown( void );
  116. static bool IsActive( void ) { return ( server.IsActive() || client.IsActive() ); }
  117. static void RunFrame( void );
  118. static void WriteUserCmdDelta( idBitMsg &msg, const usercmd_t &cmd, const usercmd_t *base );
  119. static void ReadUserCmdDelta( const idBitMsg &msg, usercmd_t &cmd, const usercmd_t *base );
  120. static bool DuplicateUsercmd( const usercmd_t &previousUserCmd, usercmd_t &currentUserCmd, int frame, int time );
  121. static bool UsercmdInputChanged( const usercmd_t &previousUserCmd, const usercmd_t &currentUserCmd );
  122. // returns true if the corresponding master is set to something (and could be resolved)
  123. static bool GetMasterAddress( int index, netadr_t &adr );
  124. // get the hardcoded idnet master, equivalent to GetMasterAddress( 0, .. )
  125. static netadr_t GetMasterAddress( void );
  126. static void GetNETServers( );
  127. static void ExecuteSessionCommand( const char *sessCmd );
  128. static idAsyncServer server;
  129. static idAsyncClient client;
  130. static idCVar verbose; // verbose output
  131. static idCVar allowCheats; // allow cheats
  132. static idCVar serverDedicated; // if set run a dedicated server
  133. static idCVar serverSnapshotDelay; // number of milliseconds between snapshots
  134. static idCVar serverMaxClientRate; // maximum outgoing rate to clients
  135. static idCVar clientMaxRate; // maximum rate from server requested by client
  136. static idCVar serverMaxUsercmdRelay; // maximum number of usercmds relayed to other clients
  137. static idCVar serverZombieTimeout; // time out in seconds for zombie clients
  138. static idCVar serverClientTimeout; // time out in seconds for connected clients
  139. static idCVar clientServerTimeout; // time out in seconds for server
  140. static idCVar serverDrawClient; // the server draws the view of this client
  141. static idCVar serverRemoteConsolePassword; // remote console password
  142. static idCVar clientPrediction; // how many additional milliseconds the clients runs ahead
  143. static idCVar clientMaxPrediction; // max milliseconds into the future a client can run prediction
  144. static idCVar clientUsercmdBackup; // how many usercmds the client sends from previous frames
  145. static idCVar clientRemoteConsoleAddress; // remote console address
  146. static idCVar clientRemoteConsolePassword; // remote console password
  147. static idCVar master0; // idnet master server
  148. static idCVar master1; // 1st master server
  149. static idCVar master2; // 2nd master server
  150. static idCVar master3; // 3rd master server
  151. static idCVar master4; // 4th master server
  152. static idCVar LANServer; // LAN mode
  153. static idCVar serverReloadEngine; // reload engine on map change instead of growing the referenced paks
  154. static idCVar serverAllowServerMod; // let a pure server start with a different game code than what is referenced in game code
  155. static idCVar idleServer; // serverinfo reply, indicates all clients are idle
  156. static idCVar clientDownload; // preferred download policy
  157. // same message used for offline check and network reply
  158. static void BuildInvalidKeyMsg( idStr &msg, bool valid[ 2 ] );
  159. private:
  160. static int realTime;
  161. static master_t masters[ MAX_MASTER_SERVERS]; // master1 etc.
  162. static void SpawnServer_f( const idCmdArgs &args );
  163. static void NextMap_f( const idCmdArgs &args );
  164. static void Connect_f( const idCmdArgs &args );
  165. static void Reconnect_f( const idCmdArgs &args );
  166. static void GetServerInfo_f( const idCmdArgs &args );
  167. static void GetLANServers_f( const idCmdArgs &args );
  168. static void ListServers_f( const idCmdArgs &args );
  169. static void RemoteConsole_f( const idCmdArgs &args );
  170. static void Heartbeat_f( const idCmdArgs &args );
  171. static void Kick_f( const idCmdArgs &args );
  172. static void CheckNewVersion_f( const idCmdArgs &args );
  173. static void UpdateUI_f( const idCmdArgs &args );
  174. };
  175. #endif /* !__ASYNCNETWORK_H__ */