OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
sb_serverbrowsing.h
1/******
2GameSpy Server Browsing SDK
3
4Copyright 1999-2007 GameSpy Industries, Inc
5
6devsupport@gamespy.com
7
8******
9
10 Please see the GameSpy Server Browsing SDK documentation for more
11 information
12
13******/
14
15
16#ifndef _SB_SERVERBROWSING_H
17#define _SB_SERVERBROWSING_H
18
19#include "../common/gsCommon.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25
26
27/*******************
28ServerBrowser Typedefs
29********************/
30//ServerBrowser is an abstract data type used to represent the server list and query engine objects.
31typedef struct _ServerBrowser *ServerBrowser;
32
33//SBServer is an abstract data type representing a single server.
34#ifndef SBServer
35typedef struct _SBServer *SBServer;
36#endif
37//Simple boolean type used for some functions
38typedef enum {SBFalse, SBTrue} SBBool;
39
40//Error codes that can be returned from functions
41typedef enum
42{
43 sbe_noerror, //no error has occured
44 sbe_socketerror, //a socket function has returned an unexpected error
45 sbe_dnserror, //DNS lookup of master address failed
46 sbe_connecterror, //connection to master server failed
47 sbe_dataerror, //invalid data was returned from master server
48 sbe_allocerror, //memory allocation failed
49 sbe_paramerror, //an invalid parameter was passed to a function
50 sbe_duplicateupdateerror //server update requested on a server that was already being updated
51} SBError;
52
53//States the ServerBrowser object can be in
54typedef enum
55{
56 sb_disconnected, //idle and not connected to the master server
57 sb_listxfer, //downloading list of servers from the master server
58 sb_querying, //querying servers
59 sb_connected //idle but still connected to the master server
60} SBState;
61
62//Callbacks that can occur during server browsing operations
63typedef enum
64{
65 sbc_serveradded, //a server was added to the list, may just have an IP & port at this point
66 sbc_serverupdated, //server information has been updated - either basic or full information is now available about this server
67 sbc_serverupdatefailed, //an attempt to retrieve information about this server, either directly or from the master, failed
68 sbc_serverdeleted, //a server was removed from the list
69 sbc_updatecomplete, //the server query engine is now idle
70 sbc_queryerror, //the master returned an error string for the provided query
71 sbc_serverchallengereceived // received ip verification challenge from server
72} SBCallbackReason;
73
74//Passed to callback to indicate state of attempt to connect to server
75typedef enum
76{
77 sbcs_succeeded,
78 sbcs_failed
79} SBConnectToServerState;
80
81//Prototype for the callback function you need to provide
82typedef void (*ServerBrowserCallback)(ServerBrowser sb, SBCallbackReason reason, SBServer server, void *instance);
83
84//Prototype for the callback function used when connecting to a server
85typedef void (*SBConnectToServerCallback)(ServerBrowser sb, SBConnectToServerState state, SOCKET gamesocket, struct sockaddr_in *remoteaddr, void *instance);
86
87//Maximum length for the SQL filter string
88#define MAX_FILTER_LEN 256
89
90//Version defines for query protocol
91#define QVERSION_GOA 0
92#define QVERSION_QR2 1
93
94/*******************
95ServerBrowser Object Functions
96********************/
97
98#ifndef GSI_UNICODE
99#define ServerBrowserNew ServerBrowserNewA
100#define ServerBrowserUpdate ServerBrowserUpdateA
101#define ServerBrowserLimitUpdate ServerBrowserLimitUpdateA
102#define ServerBrowserAuxUpdateIP ServerBrowserAuxUpdateIPA
103#define ServerBrowserRemoveIP ServerBrowserRemoveIPA
104#define ServerBrowserSendNatNegotiateCookieToServer ServerBrowserSendNatNegotiateCookieToServerA
105#define ServerBrowserSendMessageToServer ServerBrowserSendMessageToServerA
106#define ServerBrowserSort ServerBrowserSortA
107#define SBServerGetStringValue SBServerGetStringValueA
108#define SBServerGetIntValue SBServerGetIntValueA
109#define SBServerGetFloatValue SBServerGetFloatValueA
110#define SBServerGetBoolValue SBServerGetBoolValueA
111#define SBServerGetPlayerStringValue SBServerGetPlayerStringValueA
112#define SBServerGetPlayerIntValue SBServerGetPlayerIntValueA
113#define SBServerGetPlayerFloatValue SBServerGetPlayerFloatValueA
114#define SBServerGetTeamStringValue SBServerGetTeamStringValueA
115#define SBServerGetTeamIntValue SBServerGetTeamIntValueA
116#define SBServerGetTeamFloatValue SBServerGetTeamFloatValueA
117#define ServerBrowserListQueryError ServerBrowserListQueryErrorA
118#define ServerBrowserErrorDesc ServerBrowserErrorDescA
119#define ServerBrowserGetServerByIP ServerBrowserGetServerByIPA
120#else
121#define ServerBrowserNew ServerBrowserNewW
122#define ServerBrowserUpdate ServerBrowserUpdateW
123#define ServerBrowserLimitUpdate ServerBrowserLimitUpdateW
124#define ServerBrowserAuxUpdateIP ServerBrowserAuxUpdateIPW
125#define ServerBrowserRemoveIP ServerBrowserRemoveIPW
126#define ServerBrowserSendNatNegotiateCookieToServer ServerBrowserSendNatNegotiateCookieToServerW
127#define ServerBrowserSendMessageToServer ServerBrowserSendMessageToServerW
128#define ServerBrowserSort ServerBrowserSortW
129#define SBServerGetStringValue SBServerGetStringValueW
130#define SBServerGetIntValue SBServerGetIntValueW
131#define SBServerGetFloatValue SBServerGetFloatValueW
132#define SBServerGetBoolValue SBServerGetBoolValueW
133#define SBServerGetPlayerStringValue SBServerGetPlayerStringValueW
134#define SBServerGetPlayerIntValue SBServerGetPlayerIntValueW
135#define SBServerGetPlayerFloatValue SBServerGetPlayerFloatValueW
136#define SBServerGetTeamStringValue SBServerGetTeamStringValueW
137#define SBServerGetTeamIntValue SBServerGetTeamIntValueW
138#define SBServerGetTeamFloatValue SBServerGetTeamFloatValueW
139#define ServerBrowserListQueryError ServerBrowserListQueryErrorW
140#define ServerBrowserErrorDesc ServerBrowserErrorDescW
141#define ServerBrowserGetServerByIP ServerBrowserGetServerByIPW
142#endif
143/*
144ServerBrowserNew
145----------------
146Creates and returns a new (empty) ServerBrowser object.
147Returns NULL if an allocation error occurs.
148
149queryForGamename - The gamename you are querying for
150queryFromGamename - The gamename you are querying from - generally the same as queryForGamename
151queryFromKey - Secret key that corresponds to the queryFromGamename
152queryFromVersion - A game-specific version identifier (pass 0 unless told otherwise)
153maxConcUpdates - Max number of concurent updates (10-15 for modem users, 20-30 for high-bandwidth)
154queryVersion - Query protocol to use. Use QVERSION_GOA for DeveloperSpec/Query&Reporting1 games, and QVERSION_QR2 for games that use Query & Reporting 2
155callback - The function that will be called with list updates
156instance - User-defined instance data (e.g. structure or object pointer) */
157ServerBrowser ServerBrowserNew(const gsi_char *queryForGamename, const gsi_char *queryFromGamename, const gsi_char *queryFromKey, int queryFromVersion, int maxConcUpdates, int queryVersion, SBBool lanBrowse, ServerBrowserCallback callback, void *instance);
158
159/*
160ServerBrowserFree
161-----------------
162Free a ServerBrowser and all internal sturctures and servers */
163void ServerBrowserFree(ServerBrowser sb);
164
165
166/* ServerBrowserUpdate
167-------------------
168Starts an update by downloading a list of servers from the master server, then querying them.
169
170sb - The server browser object to update
171async - If SBTrue, the update will be initiated, and ServerListThink must be called for processing and querying to occur
172 If SBFalse, the function will not return until the initial list of servers has been completely updated
173disconnectOnComplete - If SBTrue, the connection to the master server will be disconnected immediately after the list is downloaded.
174 If SBFalse, the connection will be left open for additional data queries, and can be closed via ServerBrowserDisconnect
175basicFields - This array of registered QR2 keys is used to determine the fields requested from servers during the initial "basic" update.
176 Only server keys listed in this array will be returned for servers.
177numBasicFields - The number of fields in the basicFields array
178serverFilter - SQL Filter string that will be applied on the master server to limit the list of servers returned.
179 All server keys are available for filtering on the master server, as well as the master-defined "country" and "region" keys.
180 Standard SQL syntax should be used.
181
182ServerBrowserLimitUpdate
183------------------------
184Identical to ServerBrowserUpdate, except that the number of servers returned can be limited
185maxServers - Maximum number of servers to be returned
186*/
187SBError ServerBrowserUpdate(ServerBrowser sb, SBBool async, SBBool disconnectOnComplete, const unsigned char *basicFields, int numBasicFields, const gsi_char *serverFilter);
188SBError ServerBrowserLimitUpdate(ServerBrowser sb, SBBool async, SBBool disconnectOnComplete, const unsigned char *basicFields, int numBasicFields, const gsi_char *serverFilter, int maxServers);
189
190
191/* ServerBrowserThink
192-------------------
193Processes incoming data from the master server and game servers that are being queried. Should be called
194as often as possible while a server list update is in progress (~10ms is ideal). */
195SBError ServerBrowserThink(ServerBrowser sb);
196
197/* ServerBrowserLANUpdate
198-------------------
199Starts an update by searching for servers on the LAN, then querying them. You can specifiy a range of ports to search
200for servers. Generally this should start with your standard query port, and range above it, since the QR and QR2 SDKs will
201automatically allocate higher port numbers when running multiple servers on the same machine. You should limit your search
202to 100 ports or less in most cases to limit flooding of the LAN with broadcast packets.
203
204sb - The server browser object to update
205async - If SBTrue, the update will be initiated, and ServerListThink must be called for processing and querying to occur
206 If SBFalse, the function will not return until the initial list of servers has been completely updated
207startSearchPort - The initial port to begin searching for servers on
208endSearchPort - The final port to search. All ports between start and end will be queried. */
209SBError ServerBrowserLANUpdate(ServerBrowser sb, SBBool async, unsigned short startSearchPort, unsigned short endSearchPort);
210
211/* ServerBrowserAuxUpdateIP
212-------------------
213Manually updates a server given an IP address and query port. Use to manually add servers to the list when you just
214have an IP and port for them.
215
216sb - The server browser object to add the server to
217ip - The dotted IP address of the server e.g. "1.2.3.4"
218port - The query port of the server
219viaMaster - If SBTrue, information about the server will be retrieved from the master server instead of attempting to query the server directly.
220 If a connection to the master server does not exist, it will be made to kept open afterwards.
221 If SBFalse, the server will be contacted directly for information.
222async - If SBTrue, the update will be initiated, and ServerListThink must be called for processing and querying to occur
223 If SBFalse, the function will not return until the server has been successfully or unsuccessfully updated
224fullUpdate - If SBTrue, all server keys/rules/player/team information will be retrieved
225 If SBFalse, only the keys specified in the basicFields array of the ServerBrowserUpdate function will be retrieved */
226SBError ServerBrowserAuxUpdateIP(ServerBrowser sb, const gsi_char *ip, unsigned short port, SBBool viaMaster, SBBool async, SBBool fullUpdate);
227
228/* ServerBrowserAuxUpdateServer
229-------------------
230Manually updates a server object. Generally used to get additional information about a server (for example, to get full rules and
231player information from a server that only has basic information so far), but can also be used to "refresh" the information
232about a given server. Data will automatically be retrieved from the master server directly or from the game server as appropriate.
233When called asynchronously, multiple server update requests can be queued and will be executed by the query engine in turn.
234
235sb - The server browser object to add the server to
236server - Server object to update
237async - If SBTrue, the update will be initiated, and ServerListThink must be called for processing and querying to occur
238 If SBFalse, the function will not return until the server has been successfully or unsuccessfully updated
239fullUpdate - If SBTrue, all server keys/rules/player/team information will be retrieved
240 If SBFalse, only the keys specified in the basicFields array of the ServerBrowserUpdate function will be retrieved */
241SBError ServerBrowserAuxUpdateServer(ServerBrowser sb, SBServer server, SBBool async, SBBool fullUpdate);
242
243
244/* ServerBrowserDisconnects
245-------------------
246Disconnects an idle connection to the master server when it is no longer needed. Note that if you disconnect
247and then request an operation that requires a connection to the master, such as an AuxServerUpdate via the master,
248the connection will be automatically re-established. */
249void ServerBrowserDisconnect(ServerBrowser sb);
250
251
252/* ServerBrowserState
253-------------------
254Returns the current state of the Server Browser object */
255SBState ServerBrowserState(ServerBrowser sb);
256
257/* ServerBrowserRemoveIP
258-------------------
259Removes a server from the list given an IP and query port */
260void ServerBrowserRemoveIP(ServerBrowser sb, const gsi_char *ip, unsigned short port);
261
262/* ServerBrowserRemoveServer
263-------------------
264Removes a server from the list and releases all resources associated with it */
265void ServerBrowserRemoveServer(ServerBrowser sb, SBServer server);
266
267/* ServerBrowserHalt
268-------------------
269Stops a server list update in progress, clears any servers queued to be queried, and disconneects
270from the master server. */
271void ServerBrowserHalt(ServerBrowser sb);
272
273/* ServerBrowserClear
274-------------------
275Removes all the servers from the list and frees all resources associated with them. */
276void ServerBrowserClear(ServerBrowser sb);
277
278/* ServerBrowserErrorDesc
279-------------------
280Returns a human-readable error string for the given error code. */
281const gsi_char *ServerBrowserErrorDesc(ServerBrowser sb, SBError error);
282
283/* ServerBrowserListQueryError
284-------------------
285When a list query error occurs, as indicated by the sbc_queryerror callback, this function allows you to
286obtain the human-readable error string for the error (generally these errors are caused by errors in the
287filter string) */
288const gsi_char *ServerBrowserListQueryError(ServerBrowser sb);
289
290/* ServerBrowserGetServer
291----------------------
292Returns the server at the specified index, or NULL if the index is out of bounds */
293SBServer ServerBrowserGetServer(ServerBrowser sb, int index);
294
295/* ServerBrowserGetServerByIP
296----------------------
297Returns the SBServer with the specified IP, or NULL if the server is not in the list */
298SBServer ServerBrowserGetServerByIP(ServerBrowser sb, const gsi_char* ip, unsigned short port);
299
300/* ServerBrowserCount
301------------------
302Returns the number of servers on the specified list. Indexing is 0 based, so
303the actual server indexes are 0 <= valid index < Count */
304int ServerBrowserCount(ServerBrowser sb);
305
306/* ServerBrowserPendingQueryCount
307------------------
308Returns the number of servers currently being queried or queued to be queried. When this number is 0, the query
309engine is idle */
310int ServerBrowserPendingQueryCount(ServerBrowser sb);
311
312/* ServerBrowserGetMyPublicIP
313------------------
314Returns the public IP address for this computer, as seen by an outside machine (the master server). Use to determine
315if a server you want to connect to is on the same private network or not. Only valid after a call to ServerListUpdate has
316connected to the master server */
317char *ServerBrowserGetMyPublicIP(ServerBrowser sb);
318
319/* ServerBrowserGetMyPublicIPAddr
320------------------
321Same as ServerBrowserGetMyPublicIP except that the address is returned in standard network-byte-order form */
322unsigned int ServerBrowserGetMyPublicIPAddr(ServerBrowser sb);
323
324
325/* ServerBrowserSendNatNegotiateCookieToServer
326------------------
327Sends a cookie value to the server for use with NAT Negotiation */
328SBError ServerBrowserSendNatNegotiateCookieToServer(ServerBrowser sb, const gsi_char *ip, unsigned short port, int cookie);
329
330
331/* ServerBrowserSendMessageToServer
332------------------
333Sends a game-specific message to a server */
334SBError ServerBrowserSendMessageToServer(ServerBrowser sb, const gsi_char *ip, unsigned short port, const char *data, int len);
335
336/* ServerBrowserConnectToServer
337------------------
338Attempts to connect to the server, using natneg if necessary */
339SBError ServerBrowserConnectToServer(ServerBrowser sb, SBServer server, SBConnectToServerCallback callback);
340
341
342/* Comparision types for the ServerBrowserSort function
343int - assume the values are int and do an integer compare
344float - assume the values are float and do a flot compare
345strcase - assume the values are strings and do a case sensitive compare
346stricase - assume the values are strings and do a case insensitive compare */
347typedef enum {sbcm_int, sbcm_float, sbcm_strcase, sbcm_stricase} SBCompareMode;
348
349
350/* ServerBrowserSort
351-----------------
352Sort the server list in either ascending or descending order using the
353specified comparemode.
354sortkey can be a normal server key, or "ping" or "hostaddr" */
355void ServerBrowserSort(ServerBrowser sb, SBBool ascending, const gsi_char *sortkey, SBCompareMode comparemode);
356
357/* ServerBrowserLANSetLocalAddr
358-------------------
359Sets the network adapter to use for LAN broadcasts (optional) */
360void ServerBrowserLANSetLocalAddr(ServerBrowser sb, const char* theAddr);
361
362
363/*******************
364SBServer Object Functions
365********************/
366
367
368// Callback function used for enumerating the keys/values for a server
369typedef void (*SBServerKeyEnumFn)(gsi_char *key, gsi_char *value, void *instance);
370
371
372/* SBServerGetConnectionInfo
373----------------
374Check if Nat Negotiation is requires, based off whether it is a lan game, public ip present and several other facts.
375Returns an IP string to use for NatNeg, or direct connect if possible
376Work for subsequent connection to this server, One of three results will occur
377i) Lan game, connect using ipstring
3782) Internet game, connect using ipstring
3793) nat traversal required, perform nat negotiation using Nat SDK and this ipstring before connecting.
380
381return sb_true if further processing is required... i.e. NAT. sb_false if not.
382fills an IP string
383*/
384SBBool SBServerGetConnectionInfo(ServerBrowser gSB, SBServer server, gsi_u16 PortToConnectTo, char *ipstring_out);
385
386
387/* SBServerHasPrivateAddress
388----------------
389Indicates whether the master server has provided a private address for this server */
390SBBool SBServerHasPrivateAddress(SBServer server);
391
392/* SBServerDirectConnect
393----------------
394Indicates whether the server supports direct UDP connections (if false, NAT Negotiation is required) */
395SBBool SBServerDirectConnect(SBServer server);
396
397/* SBServerGetPing
398----------------
399Returns the ping for the specified server. Ping is measured as the latency from the time a
400query is sent to the server until the data is returned for that query */
401int SBServerGetPing(SBServer server);
402
403
404/* SBServerGetPublicAddress/SBServerGetPrivateAddress
405-------------------
406Returns the string, dotted IP address for the specified server
407The "private" version is only valid when the server has a private address available */
408char *SBServerGetPublicAddress(SBServer server);
409char *SBServerGetPrivateAddress(SBServer server);
410
411/* SBServerGetPublicInetAddress/SBServerGetPrivateInetAddress
412-------------------
413Returns the network-ordered IP address for the specified server */
414unsigned int SBServerGetPublicInetAddress(SBServer server);
415unsigned int SBServerGetPrivateInetAddress(SBServer server);
416
417/* SBServerGetPublicQueryPort/SBServerGetPrivateQueryPort
418----------------
419Returns the "query" port for the specified server. If the game uses a seperate
420"game" port, it can be retrieved via: SBServerGetIntValue(server,"hostport",0) */
421unsigned short SBServerGetPublicQueryPort(SBServer server);
422unsigned short SBServerGetPrivateQueryPort(SBServer server);
423
424
425/* SBServerHasBasicKeys
426----------------
427Returns SBTrue if a server has at least basic keys available for it. "Basic" keys
428are those indicated in the ServerBrowserUpdate function. */
429SBBool SBServerHasBasicKeys(SBServer server);
430
431/* SBServerHasFullKeys
432----------------
433Returns SBTrue if a server has full keys available for it. This includes all server
434rules and player/team keys. */
435SBBool SBServerHasFullKeys(SBServer server);
436
437/* SBServerHasValidPing
438----------------
439Returns SBTrue if a server has a valid ping value for it (otherwise the ping will be 0) */
440SBBool SBServerHasValidPing(SBServer server);
441
442
443/* SBServerGet[]Value
444------------------
445Returns the value for the specified key. If the key does not exist for the
446given server, the default value is returned */
447const gsi_char *SBServerGetStringValue(SBServer server, const gsi_char *keyname, const gsi_char *def);
448int SBServerGetIntValue(SBServer server, const gsi_char *key, int idefault);
449double SBServerGetFloatValue(SBServer server, const gsi_char *key, double fdefault);
450SBBool SBServerGetBoolValue(SBServer server, const gsi_char *key, SBBool bdefault);
451
452
453/* SBServerGetPlayer[]Value / SBServerGetTeam[]Value
454------------------
455Returns the value for the specified key on the specified player or team. If the key does not exist for the
456given server, the default value is returned
457Player keys take the form keyname_N where N is the player index, and team keys take the form
458keyname_tN where N is the team index. You should only specify the keyname for the key in the below functions.
459*/
460const gsi_char *SBServerGetPlayerStringValue(SBServer server, int playernum, const gsi_char *key, const gsi_char *sdefault);
461int SBServerGetPlayerIntValue(SBServer server, int playernum, const gsi_char *key, int idefault);
462double SBServerGetPlayerFloatValue(SBServer server, int playernum, const gsi_char *key, double fdefault);
463
464const gsi_char *SBServerGetTeamStringValue(SBServer server, int teamnum, const gsi_char *key, const gsi_char *sdefault);
465int SBServerGetTeamIntValue(SBServer server, int teamnum, const gsi_char *key, int idefault);
466double SBServerGetTeamFloatValue(SBServer server, int teamnum, const gsi_char *key, double fdefault);
467
468
469/* SBServerEnumKeys
470-----------------
471Enumerates the keys/values for a given server by calling KeyEnumFn with each
472key/value. The user-defined instance data will be passed to the KeyFn callback */
473void SBServerEnumKeys(SBServer server, SBServerKeyEnumFn KeyFn, void *instance);
474
475
476#ifdef __cplusplus
477}
478#endif
479
480#endif
Definition sb_internal.h:273
Definition sb_internal.h:316
Definition puff.c:88