2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
29 #ifndef __SERVERSCAN_H__
30 #define __SERVERSCAN_H__
33 ===============================================================================
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
39 ===============================================================================
42 // storage for incoming servers / server scan
49 // the menu gui uses a hard-coded control type to display a list of network games
54 int id; // idnet mode sends an id for each server in list
56 char nickname[ MAX_NICKLEN ][ MAX_ASYNC_CLIENTS ];
57 short pings[ MAX_ASYNC_CLIENTS ];
58 int rate[ MAX_ASYNC_CLIENTS ];
72 class idServerScan : public idList<networkServer_t> {
76 int InfoResponse( networkServer_t &server );
78 // add an internet server - ( store a numeric id along with it )
79 void AddServer( int id, const char *srv );
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
87 // scan the current list of servers - used for refreshes and while receiving a fresh list
93 // called each game frame. Updates the scanner state, takes care of ongoing scans
103 scan_state_t GetState() { return scan_state; }
104 void SetState( scan_state_t );
106 bool GetBestPing( networkServer_t &serv );
108 // prepare for a LAN scan. idAsyncClient does the network job (UDP broadcast), we do the storage
109 void SetupLANScan( );
111 void GUIConfig( idUserInterface *pGUI, const char *name );
112 // update the GUI fields with information about the currently selected server
113 void GUIUpdateSelected( void );
119 // there is an internal toggle, call twice with same sort to switch
120 void SetSorting( serverSort_t sort );
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
130 scan_state_t scan_state;
132 bool incoming_net; // set to true while new servers are fed through AddServer
133 bool incoming_useTimeout;
134 int incoming_lastTime;
136 int lan_pingtime; // holds the time of LAN scan
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
143 idList<inServer_t> net_servers;
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 )
148 idUserInterface *m_pGUI;
152 bool m_sortAscending;
153 idList<int> m_sortedServers; // use ascending for the walking order
156 int challenge; // challenge for current scan
158 int endWaitTime; // when to stop waiting on a port init
161 void LocalClear( ); // we need to clear some internal data as well
163 void EmitGetInfo( netadr_t &serv );
164 void GUIAdd( int id, const networkServer_t server );
165 bool IsFiltered( const networkServer_t server );
167 static int Cmp( const int *a, const int *b );
170 #endif /* !__SERVERSCAN_H__ */