doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ServerScan.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 __SERVERSCAN_H__
30 #define __SERVERSCAN_H__
31 
32 /*
33 ===============================================================================
34 
35  Scan for servers, on the LAN or from a list
36  Update a listDef GUI through usage of idListGUI class
37  When updating large lists of servers, sends out getInfo in small batches to avoid congestion
38 
39 ===============================================================================
40 */
41 
42 // storage for incoming servers / server scan
43 typedef struct {
45  int id;
46  int time;
47 } inServer_t;
48 
49 // the menu gui uses a hard-coded control type to display a list of network games
50 typedef struct {
53  int ping;
54  int id; // idnet mode sends an id for each server in list
55  int clients;
56  char nickname[ MAX_NICKLEN ][ MAX_ASYNC_CLIENTS ];
57  short pings[ MAX_ASYNC_CLIENTS ];
58  int rate[ MAX_ASYNC_CLIENTS ];
59  int OSMask;
60  int challenge;
62 
63 typedef enum {
70 } serverSort_t;
71 
72 class idServerScan : public idList<networkServer_t> {
73 public:
74  idServerScan( );
75 
76  int InfoResponse( networkServer_t &server );
77 
78  // add an internet server - ( store a numeric id along with it )
79  void AddServer( int id, const char *srv );
80 
81  // we are going to feed server entries to be pinged
82  // if timeout is true, use a timeout once we start AddServer to trigger EndServers and decide the scan is done
83  void StartServers( bool timeout );
84  // we are done filling up the list of server entries
85  void EndServers( );
86 
87  // scan the current list of servers - used for refreshes and while receiving a fresh list
88  void NetScan( );
89 
90  // clear
91  void Clear( );
92 
93  // called each game frame. Updates the scanner state, takes care of ongoing scans
94  void RunFrame( );
95 
96  typedef enum {
97  IDLE = 0,
101  } scan_state_t;
102 
104  void SetState( scan_state_t );
105 
106  bool GetBestPing( networkServer_t &serv );
107 
108  // prepare for a LAN scan. idAsyncClient does the network job (UDP broadcast), we do the storage
109  void SetupLANScan( );
110 
111  void GUIConfig( idUserInterface *pGUI, const char *name );
112  // update the GUI fields with information about the currently selected server
113  void GUIUpdateSelected( void );
114 
115  void Shutdown( );
116 
117  void ApplyFilter( );
118 
119  // there is an internal toggle, call twice with same sort to switch
120  void SetSorting( serverSort_t sort );
121 
122  int GetChallenge( );
123 
124 private:
125  static const int MAX_PINGREQUESTS = 32; // how many servers to query at once
126  static const int REPLY_TIMEOUT = 999; // how long should we wait for a reply from a game server
127  static const int INCOMING_TIMEOUT = 1500; // when we got an incoming server list, how long till we decide the list is done
128  static const int REFRESH_START = 10000; // how long to wait when sending the initial refresh request
129 
131 
132  bool incoming_net; // set to true while new servers are fed through AddServer
135 
136  int lan_pingtime; // holds the time of LAN scan
137 
138  // servers we're waiting for a reply from
139  // won't exceed MAX_PINGREQUESTS elements
140  // holds index of net_servers elements, indexed by 'from' string
142 
144  // where we are in net_servers list for getInfo emissions ( NET_SCAN only )
145  // we may either be waiting on MAX_PINGREQUESTS, or for net_servers to grow some more ( through AddServer )
146  int cur_info;
147 
150 
153  idList<int> m_sortedServers; // use ascending for the walking order
154 
156  int challenge; // challenge for current scan
157 
158  int endWaitTime; // when to stop waiting on a port init
159 
160 private:
161  void LocalClear( ); // we need to clear some internal data as well
162 
163  void EmitGetInfo( netadr_t &serv );
164  void GUIAdd( int id, const networkServer_t server );
165  bool IsFiltered( const networkServer_t server );
166 
167  static int Cmp( const int *a, const int *b );
168 };
169 
170 #endif /* !__SERVERSCAN_H__ */
int InfoResponse(networkServer_t &server)
Definition: ServerScan.cpp:125
static const int INCOMING_TIMEOUT
Definition: ServerScan.h:127
void GUIUpdateSelected(void)
Definition: ServerScan.cpp:385
scan_state_t GetState()
Definition: ServerScan.h:103
bool incoming_net
Definition: ServerScan.h:132
const int MAX_ASYNC_CLIENTS
Definition: AsyncNetwork.h:44
int incoming_lastTime
Definition: ServerScan.h:134
netadr_t adr
Definition: ServerScan.h:51
bool IsFiltered(const networkServer_t server)
Definition: ServerScan.cpp:501
static const int MAX_PINGREQUESTS
Definition: ServerScan.h:125
bool incoming_useTimeout
Definition: ServerScan.h:133
int lan_pingtime
Definition: ServerScan.h:136
void RunFrame()
Definition: ServerScan.cpp:293
idDict net_info
Definition: ServerScan.h:141
idStr screenshot
Definition: ServerScan.h:155
int GetChallenge()
Definition: ServerScan.cpp:245
const int MAX_NICKLEN
Definition: AsyncNetwork.h:54
static const int REPLY_TIMEOUT
Definition: ServerScan.h:126
netadr_t adr
Definition: ServerScan.h:44
void GUIAdd(int id, const networkServer_t server)
Definition: ServerScan.cpp:434
serverSort_t m_sort
Definition: ServerScan.h:151
void LocalClear()
Definition: ServerScan.cpp:67
void ApplyFilter()
Definition: ServerScan.cpp:477
scan_state_t scan_state
Definition: ServerScan.h:130
void SetState(scan_state_t)
idUserInterface * m_pGUI
Definition: ServerScan.h:148
static int Cmp(const int *a, const int *b)
Definition: ServerScan.cpp:588
Definition: Dict.h:65
static const int REFRESH_START
Definition: ServerScan.h:128
void EndServers()
Definition: ServerScan.cpp:213
void AddServer(int id, const char *srv)
Definition: ServerScan.cpp:189
void GUIConfig(idUserInterface *pGUI, const char *name)
Definition: ServerScan.cpp:372
void StartServers(bool timeout)
Definition: ServerScan.cpp:225
GLubyte GLubyte GLubyte a
Definition: glext.h:4662
GLubyte GLubyte b
Definition: glext.h:4662
void NetScan()
Definition: ServerScan.cpp:254
idList< inServer_t > net_servers
Definition: ServerScan.h:143
const GLcharARB * name
Definition: glext.h:3629
void EmitGetInfo(netadr_t &serv)
Definition: ServerScan.cpp:236
idListGUI * listGUI
Definition: ServerScan.h:149
Definition: Str.h:116
void SetSorting(serverSort_t sort)
Definition: ServerScan.cpp:627
void Shutdown()
Definition: ServerScan.cpp:96
serverSort_t
Definition: ServerScan.h:63
void SetupLANScan()
Definition: ServerScan.cpp:111
void Clear()
Definition: ServerScan.cpp:86
idDict serverInfo
Definition: ServerScan.h:52
idList< int > m_sortedServers
Definition: ServerScan.h:153
Definition: List.h:84
bool GetBestPing(networkServer_t &serv)
Definition: ServerScan.cpp:352
bool m_sortAscending
Definition: ServerScan.h:152