doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AsyncClient.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 __ASYNCCLIENT_H__
30 #define __ASYNCCLIENT_H__
31 
32 /*
33 ===============================================================================
34 
35  Network Client for asynchronous networking.
36 
37 ===============================================================================
38 */
39 
40 typedef enum {
48 
49 typedef enum {
52 } authKeyMsg_t;
53 
54 typedef enum {
60 
61 typedef enum {
68 
69 typedef struct {
72  int size;
73  int checksum;
74 } pakDlEntry_t;
75 
77 public:
78  idAsyncClient();
79 
80  void Shutdown( void );
81  bool InitPort( void );
82  void ClosePort( void );
83  void ConnectToServer( const netadr_t adr );
84  void ConnectToServer( const char *address );
85  void Reconnect( void );
86  void DisconnectFromServer( void );
87  void GetServerInfo( const netadr_t adr );
88  void GetServerInfo( const char *address );
89  void GetLANServers( void );
90  void GetNETServers( void );
91  void ListServers( void );
92  void ClearServers( void );
93  void RemoteConsole( const char *command );
94  bool IsPortInitialized() { return clientPort.GetPort() != 0; }
95 
96  bool IsActive( void ) const { return active; }
97  int GetLocalClientNum( void ) const { return clientNum; }
98  int GetPrediction( void ) const;
99  int GetTimeSinceLastPacket( void ) const;
100  int GetOutgoingRate( void ) const;
101  int GetIncomingRate( void ) const;
102  float GetOutgoingCompression( void ) const;
103  float GetIncomingCompression( void ) const;
104  float GetIncomingPacketLoss( void ) const;
105  int GetPredictedFrames( void ) const { return lastFrameDelta; }
106 
107  void RunFrame( void );
108  void SendReliableGameMessage( const idBitMsg &msg );
109 
110  void SendVersionCheck( bool fromMenu = false );
111  // pass NULL for the keys you don't care to auth for
112  // returns false if internet link doesn't appear to be available
113  bool SendAuthCheck( const char *cdkey, const char *xpkey );
114 
115  void PacifierUpdate( void );
116 
118 
119 private:
120  bool active; // true if client is active
121  int realTime; // absolute time
122 
123  int clientTime; // client local time
124  idPort clientPort; // UDP port
125  int clientId; // client identification
126  int clientDataChecksum; // checksum of the data used by the client
127  int clientNum; // client number on server
128  clientState_t clientState; // client state
129  int clientPrediction; // how far the client predicts ahead
130  int clientPredictTime; // prediction time used to send user commands
131 
132  netadr_t serverAddress; // IP address of server
133  int serverId; // server identification
134  int serverChallenge; // challenge from server
135  int serverMessageSequence; // sequence number of last server message
136 
137  netadr_t lastRconAddress; // last rcon address we emitted to
138  int lastRconTime; // when last rcon emitted
139 
140  idMsgChannel channel; // message channel to server
141  int lastConnectTime; // last time a connect message was sent
142  int lastEmptyTime; // last time an empty message was sent
143  int lastPacketTime; // last time a packet was received from the server
144  int lastSnapshotTime; // last time a snapshot was received
145 
146  int snapshotSequence; // sequence number of the last received snapshot
147  int snapshotGameFrame; // game frame number of the last received snapshot
148  int snapshotGameTime; // game time of the last received snapshot
149 
150  int gameInitId; // game initialization identification
151  int gameFrame; // local game frame
152  int gameTime; // local game time
153  int gameTimeResidual; // left over time from previous frame
154 
156 
158 
168 
170  int dltotal;
171  int dlnow;
172 
174 
175  int dlRequest; // randomized number to keep track of the requests
176  int dlChecksums[ MAX_PURE_PAKS ]; // 0-terminated, first element is the game pak checksum or 0
177  int dlCount; // total number of paks we request download for ( including the game pak )
178  idList<pakDlEntry_t>dlList; // list of paks to download, with url and name
180  int totalDlSize; // for partial progress stuff
181 
182  void Clear( void );
183  void ClearPendingPackets( void );
184  void DuplicateUsercmds( int frame, int time );
185  void SendUserInfoToServer( void );
186  void SendEmptyToServer( bool force = false, bool mapLoad = false );
187  void SendPingResponseToServer( int time );
188  void SendUsercmdsToServer( void );
189  void InitGame( int serverGameInitId, int serverGameFrame, int serverGameTime, const idDict &serverSI );
190  void ProcessUnreliableServerMessage( const idBitMsg &msg );
191  void ProcessReliableServerMessages( void );
192  void ProcessChallengeResponseMessage( const netadr_t from, const idBitMsg &msg );
193  void ProcessConnectResponseMessage( const netadr_t from, const idBitMsg &msg );
194  void ProcessDisconnectMessage( const netadr_t from, const idBitMsg &msg );
195  void ProcessInfoResponseMessage( const netadr_t from, const idBitMsg &msg );
196  void ProcessPrintMessage( const netadr_t from, const idBitMsg &msg );
197  void ProcessServersListMessage( const netadr_t from, const idBitMsg &msg );
198  void ProcessAuthKeyMessage( const netadr_t from, const idBitMsg &msg );
199  void ProcessVersionMessage( const netadr_t from, const idBitMsg &msg );
200  void ConnectionlessMessage( const netadr_t from, const idBitMsg &msg );
201  void ProcessMessage( const netadr_t from, idBitMsg &msg );
202  void SetupConnection( void );
203  void ProcessPureMessage( const netadr_t from, const idBitMsg &msg );
204  bool ValidatePureServerChecksums( const netadr_t from, const idBitMsg &msg );
205  void ProcessReliableMessagePure( const idBitMsg &msg );
206  static const char* HandleGuiCommand( const char *cmd );
207  const char* HandleGuiCommandInternal( const char *cmd );
208  void SendVersionDLUpdate( int state );
209  void HandleDownloads( void );
210  void Idle( void );
211  int UpdateTime( int clamp );
212  void ReadLocalizedServerString( const idBitMsg &msg, char* out, int maxLen );
213  bool CheckTimeout( void );
214  void ProcessDownloadInfoMessage( const netadr_t from, const idBitMsg &msg );
215  int GetDownloadRequest( const int checksums[ MAX_PURE_PAKS ], int count, int gamePakChecksum );
216 };
217 
218 #endif /* !__ASYNCCLIENT_H__ */
void ProcessAuthKeyMessage(const netadr_t from, const idBitMsg &msg)
const int MAX_ASYNC_CLIENTS
Definition: AsyncNetwork.h:44
void Shutdown(void)
Definition: AsyncClient.cpp:99
usercmd_t userCmds[MAX_USERCMD_BACKUP][MAX_ASYNC_CLIENTS]
Definition: AsyncClient.h:155
void ClearServers(void)
idStr updateFallback
Definition: AsyncClient.h:166
void ProcessInfoResponseMessage(const netadr_t from, const idBitMsg &msg)
backgroundDownload_t backgroundDownload
Definition: AsyncClient.h:169
int dlChecksums[MAX_PURE_PAKS]
Definition: AsyncClient.h:176
bool IsActive(void) const
Definition: AsyncClient.h:96
void SendPingResponseToServer(int time)
void ProcessChallengeResponseMessage(const netadr_t from, const idBitMsg &msg)
bool CheckTimeout(void)
void HandleDownloads(void)
int GetDownloadRequest(const int checksums[MAX_PURE_PAKS], int count, int gamePakChecksum)
static const char * HandleGuiCommand(const char *cmd)
void ProcessReliableServerMessages(void)
bool IsPortInitialized()
Definition: AsyncClient.h:94
void Clear(void)
Definition: AsyncClient.cpp:57
int size
Definition: AsyncClient.h:72
int snapshotSequence
Definition: AsyncClient.h:146
void Reconnect(void)
int clientDataChecksum
Definition: AsyncClient.h:126
int GetPredictedFrames(void) const
Definition: AsyncClient.h:105
void GetServerInfo(const netadr_t adr)
int gameTimeResidual
Definition: AsyncClient.h:153
void ClosePort(void)
netadr_t lastRconAddress
Definition: AsyncClient.h:137
Definition: AsyncClient.h:69
void SendReliableGameMessage(const idBitMsg &msg)
void ConnectToServer(const netadr_t adr)
float GetIncomingCompression(void) const
void SendEmptyToServer(bool force=false, bool mapLoad=false)
idUserInterface * guiNetMenu
Definition: AsyncClient.h:157
idPort clientPort
Definition: AsyncClient.h:124
void SendVersionDLUpdate(int state)
idList< pakDlEntry_t > dlList
Definition: AsyncClient.h:178
void ClearPendingPackets(void)
int clientPredictTime
Definition: AsyncClient.h:130
void GetNETServers(void)
void SendVersionCheck(bool fromMenu=false)
bool updateDirectDownload
Definition: AsyncClient.h:163
dlMime_t
Definition: FileSystem.h:86
bool showUpdateMessage
Definition: AsyncClient.h:167
clientState_t
Definition: AsyncClient.h:40
clientUpdateState_t
Definition: AsyncClient.h:61
idStr updateFile
Definition: AsyncClient.h:164
int snapshotGameTime
Definition: AsyncClient.h:148
GLuint GLuint GLsizei count
Definition: glext.h:2845
int UpdateTime(int clamp)
void ProcessPrintMessage(const netadr_t from, const idBitMsg &msg)
int checksum
Definition: AsyncClient.h:73
int GetPrediction(void) const
void PacifierUpdate(void)
const char * HandleGuiCommandInternal(const char *cmd)
float GetIncomingPacketLoss(void) const
Definition: Dict.h:65
idServerScan serverList
Definition: AsyncClient.h:117
void ProcessUnreliableServerMessage(const idBitMsg &msg)
authBadKeyStatus_t
Definition: AsyncClient.h:54
float GetOutgoingCompression(void) const
void SetupConnection(void)
void RunFrame(void)
int clientPrediction
Definition: AsyncClient.h:129
clientUpdateState_t updateState
Definition: AsyncClient.h:159
void ProcessMessage(const netadr_t from, idBitMsg &msg)
bool InitPort(void)
void ProcessServersListMessage(const netadr_t from, const idBitMsg &msg)
int GetOutgoingRate(void) const
netadr_t serverAddress
Definition: AsyncClient.h:132
bool ValidatePureServerChecksums(const netadr_t from, const idBitMsg &msg)
int GetLocalClientNum(void) const
Definition: AsyncClient.h:97
dlMime_t updateMime
Definition: AsyncClient.h:165
void GetLANServers(void)
void InitGame(int serverGameInitId, int serverGameFrame, int serverGameTime, const idDict &serverSI)
void ProcessPureMessage(const netadr_t from, const idBitMsg &msg)
int serverMessageSequence
Definition: AsyncClient.h:135
Definition: Str.h:116
void ProcessReliableMessagePure(const idBitMsg &msg)
bool SendAuthCheck(const char *cdkey, const char *xpkey)
GLuint address
Definition: glext.h:5165
idMsgChannel channel
Definition: AsyncClient.h:140
void DuplicateUsercmds(int frame, int time)
void RemoteConsole(const char *command)
void ProcessDisconnectMessage(const netadr_t from, const idBitMsg &msg)
void ProcessDownloadInfoMessage(const netadr_t from, const idBitMsg &msg)
int GetTimeSinceLastPacket(void) const
int snapshotGameFrame
Definition: AsyncClient.h:147
int lastSnapshotTime
Definition: AsyncClient.h:144
int GetPort(void) const
Definition: sys_public.h:419
const int MAX_USERCMD_BACKUP
Definition: AsyncNetwork.h:46
void SendUserInfoToServer(void)
void SendUsercmdsToServer(void)
authKeyMsg_t
Definition: AsyncClient.h:49
int GetIncomingRate(void) const
void Idle(void)
void ProcessVersionMessage(const netadr_t from, const idBitMsg &msg)
void ReadLocalizedServerString(const idBitMsg &msg, char *out, int maxLen)
void DisconnectFromServer(void)
void ProcessConnectResponseMessage(const netadr_t from, const idBitMsg &msg)
idStr filename
Definition: AsyncClient.h:71
void ListServers(void)
clientState_t clientState
Definition: AsyncClient.h:128
idStr url
Definition: AsyncClient.h:70
void ConnectionlessMessage(const netadr_t from, const idBitMsg &msg)