AsyncClient.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 __ASYNCCLIENT_H__
  21. #define __ASYNCCLIENT_H__
  22. /*
  23. ===============================================================================
  24. Network Client for asynchronous networking.
  25. ===============================================================================
  26. */
  27. typedef enum {
  28. CS_DISCONNECTED,
  29. CS_PURERESTART,
  30. CS_CHALLENGING,
  31. CS_CONNECTING,
  32. CS_CONNECTED,
  33. CS_INGAME
  34. } clientState_t;
  35. typedef enum {
  36. AUTHKEY_BADKEY,
  37. AUTHKEY_GUID
  38. } authKeyMsg_t;
  39. typedef enum {
  40. AUTHKEY_BAD_INVALID,
  41. AUTHKEY_BAD_BANNED,
  42. AUTHKEY_BAD_INUSE,
  43. AUTHKEY_BAD_MSG
  44. } authBadKeyStatus_t;
  45. typedef enum {
  46. UPDATE_NONE,
  47. UPDATE_SENT,
  48. UPDATE_READY,
  49. UPDATE_DLING,
  50. UPDATE_DONE
  51. } clientUpdateState_t;
  52. typedef struct {
  53. idStr url;
  54. idStr filename;
  55. int size;
  56. int checksum;
  57. } pakDlEntry_t;
  58. class idAsyncClient {
  59. public:
  60. idAsyncClient();
  61. void Shutdown( void );
  62. bool InitPort( void );
  63. void ClosePort( void );
  64. void ConnectToServer( const netadr_t adr );
  65. void ConnectToServer( const char *address );
  66. void Reconnect( void );
  67. void DisconnectFromServer( void );
  68. void GetServerInfo( const netadr_t adr );
  69. void GetServerInfo( const char *address );
  70. void GetLANServers( void );
  71. void GetNETServers( void );
  72. void ListServers( void );
  73. void ClearServers( void );
  74. void RemoteConsole( const char *command );
  75. bool IsPortInitialized() { return clientPort.GetPort() != 0; }
  76. bool IsActive( void ) const { return active; }
  77. int GetLocalClientNum( void ) const { return clientNum; }
  78. int GetPrediction( void ) const;
  79. int GetTimeSinceLastPacket( void ) const;
  80. int GetOutgoingRate( void ) const;
  81. int GetIncomingRate( void ) const;
  82. float GetOutgoingCompression( void ) const;
  83. float GetIncomingCompression( void ) const;
  84. float GetIncomingPacketLoss( void ) const;
  85. int GetPredictedFrames( void ) const { return lastFrameDelta; }
  86. void RunFrame( void );
  87. void SendReliableGameMessage( const idBitMsg &msg );
  88. void SendVersionCheck( bool fromMenu = false );
  89. // pass NULL for the keys you don't care to auth for
  90. // returns false if internet link doesn't appear to be available
  91. bool SendAuthCheck( const char *cdkey, const char *xpkey );
  92. void PacifierUpdate( void );
  93. idServerScan serverList;
  94. //bc
  95. void SendBugreport(const char *text);
  96. private:
  97. bool active; // true if client is active
  98. int realTime; // absolute time
  99. int clientTime; // client local time
  100. idPort clientPort; // UDP port
  101. int clientId; // client identification
  102. int clientDataChecksum; // checksum of the data used by the client
  103. int clientNum; // client number on server
  104. clientState_t clientState; // client state
  105. int clientPrediction; // how far the client predicts ahead
  106. int clientPredictTime; // prediction time used to send user commands
  107. netadr_t serverAddress; // IP address of server
  108. int serverId; // server identification
  109. int serverChallenge; // challenge from server
  110. int serverMessageSequence; // sequence number of last server message
  111. netadr_t lastRconAddress; // last rcon address we emitted to
  112. int lastRconTime; // when last rcon emitted
  113. idMsgChannel channel; // message channel to server
  114. int lastConnectTime; // last time a connect message was sent
  115. int lastEmptyTime; // last time an empty message was sent
  116. int lastPacketTime; // last time a packet was received from the server
  117. int lastSnapshotTime; // last time a snapshot was received
  118. int snapshotSequence; // sequence number of the last received snapshot
  119. int snapshotGameFrame; // game frame number of the last received snapshot
  120. int snapshotGameTime; // game time of the last received snapshot
  121. int gameInitId; // game initialization identification
  122. int gameFrame; // local game frame
  123. int gameTime; // local game time
  124. int gameTimeResidual; // left over time from previous frame
  125. usercmd_t userCmds[MAX_USERCMD_BACKUP][MAX_ASYNC_CLIENTS];
  126. idUserInterface * guiNetMenu;
  127. clientUpdateState_t updateState;
  128. int updateSentTime;
  129. idStr updateMSG;
  130. idStr updateURL;
  131. bool updateDirectDownload;
  132. idStr updateFile;
  133. dlMime_t updateMime;
  134. idStr updateFallback;
  135. bool showUpdateMessage;
  136. backgroundDownload_t backgroundDownload;
  137. int dltotal;
  138. int dlnow;
  139. int lastFrameDelta;
  140. int dlRequest; // randomized number to keep track of the requests
  141. int dlChecksums[ MAX_PURE_PAKS ]; // 0-terminated, first element is the game pak checksum or 0
  142. int dlCount; // total number of paks we request download for ( including the game pak )
  143. idList<pakDlEntry_t>dlList; // list of paks to download, with url and name
  144. int currentDlSize;
  145. int totalDlSize; // for partial progress stuff
  146. void Clear( void );
  147. void ClearPendingPackets( void );
  148. void DuplicateUsercmds( int frame, int time );
  149. void SendUserInfoToServer( void );
  150. void SendEmptyToServer( bool force = false, bool mapLoad = false );
  151. void SendPingResponseToServer( int time );
  152. void SendUsercmdsToServer( void );
  153. void InitGame( int serverGameInitId, int serverGameFrame, int serverGameTime, const idDict &serverSI );
  154. void ProcessUnreliableServerMessage( const idBitMsg &msg );
  155. void ProcessReliableServerMessages( void );
  156. void ProcessChallengeResponseMessage( const netadr_t from, const idBitMsg &msg );
  157. void ProcessConnectResponseMessage( const netadr_t from, const idBitMsg &msg );
  158. void ProcessDisconnectMessage( const netadr_t from, const idBitMsg &msg );
  159. void ProcessInfoResponseMessage( const netadr_t from, const idBitMsg &msg );
  160. void ProcessPrintMessage( const netadr_t from, const idBitMsg &msg );
  161. void ProcessServersListMessage( const netadr_t from, const idBitMsg &msg );
  162. void ProcessAuthKeyMessage( const netadr_t from, const idBitMsg &msg );
  163. void ProcessVersionMessage( const netadr_t from, const idBitMsg &msg );
  164. void ConnectionlessMessage( const netadr_t from, const idBitMsg &msg );
  165. void ProcessMessage( const netadr_t from, idBitMsg &msg );
  166. void SetupConnection( void );
  167. void ProcessPureMessage( const netadr_t from, const idBitMsg &msg );
  168. bool ValidatePureServerChecksums( const netadr_t from, const idBitMsg &msg );
  169. void ProcessReliableMessagePure( const idBitMsg &msg );
  170. static const char* HandleGuiCommand( const char *cmd );
  171. const char* HandleGuiCommandInternal( const char *cmd );
  172. void SendVersionDLUpdate( int state );
  173. void HandleDownloads( void );
  174. void Idle( void );
  175. int UpdateTime( int clamp );
  176. void ReadLocalizedServerString( const idBitMsg &msg, char* out, int maxLen );
  177. bool CheckTimeout( void );
  178. void ProcessDownloadInfoMessage( const netadr_t from, const idBitMsg &msg );
  179. int GetDownloadRequest( const int checksums[ MAX_PURE_PAKS ], int count, int gamePakChecksum );
  180. };
  181. #endif /* !__ASYNCCLIENT_H__ */