OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
gstats.h
1/******
2gstats.h
3GameSpy Stats/Tracking SDK
4
5Copyright 1999-2007 GameSpy Industries, Inc
6
7******
8
9Please see the GameSpy Stats and Tracking SDK documentation for more info
10
1108-23-00 - DDW
12Fixed a problem that prevented opening/closing/re-opening of the connection within
13a single session.
14
15*****/
16
17#ifndef _GSTATS_H_
18#define _GSTATS_H_
19
20
21/********
22INCLUDES
23********/
24#include "../common/gsCommon.h"
25#include "gbucket.h"
26
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#if defined(_WIN32)
33 // Warnings are generated because we store function ptrs into a void* array
34#pragma warning(disable: 4152) // function to data ptr
35#pragma warning(disable: 4055) // data to function ptr
36#endif
37
38
39/********
40TYPEDEFS
41********/
42
43
44/* The abstracted "game" structure */
45typedef struct statsgame_s *statsgame_t;
46
47/* All of the operations you can do on a bucket */
48typedef enum {bo_set, bo_add, bo_sub, bo_mult, bo_div, bo_concat, bo_avg} bucketop_t;
49#define NUMOPS 7
50
51/* The types of buckets (server info, team info, or player info) */
52typedef enum {bl_server, bl_team, bl_player} bucketlevel_t;
53
54/* Init states for async initialization */
55typedef enum {init_none, init_failed, init_connecting, init_awaitchallenge, init_awaitsessionkey, init_complete} initstate_t;
56
57/* Used by the bucket operation macros */
58typedef void *(*BucketFunc)(bucketset_t set, char *name,void *value);
59typedef int (*SetIntFunc)(statsgame_t game,char *name, BucketFunc func, int value, int index);
60typedef double (*SetFloatFunc)(statsgame_t game,char *name, BucketFunc func, double value, int index);
61typedef char *(*SetStringFunc)(statsgame_t game,char *name, BucketFunc func, char *value, int index);
62extern BucketFunc bucketfuncs[NUMOPS];
63extern void * bopfuncs[][3];
64
65/********
66DEFINES
67********/
68/* Error codes */
69#define GE_NOERROR 0
70#define GE_NOSOCKET 1 /* Unable to create a socket */
71#define GE_NODNS 2 /* Unable to resolve a DNS name */
72#define GE_NOCONNECT 3 /* Unable to connect to stats server, or connection lost */
73#define GE_BUSY 4 /* Not used */
74#define GE_DATAERROR 5 /* Bad data from the stats server */
75#define GE_CONNECTING 6 /* Connect did no immediately complete. Call InitStatsThink() */
76#define GE_TIMEDOUT 7 /* Connect attempt timed out */
77
78/* Types of snapshots, update (any snapshot that is not final) or final */
79#define SNAP_UPDATE 0
80#define SNAP_FINAL 1
81
82/* If you want to allow disk logging in case the stats server isn't available.
83This has SERIOUS security repercussions, so please read the docs before turning this on */
84#define ALLOW_DISK
85
86#if defined(NOFILE)
87 #undef ALLOW_DISK
88#endif /* make sure it's never defined on platforms with no disk! */
89
90/********
91VARS
92********/
93
94/* You need to fill these in with your game-specific info */
95extern char gcd_secret_key[256];
96extern char gcd_gamename[256];
97
98/* The hostname of the stats server.
99If the app resolves the hostname, an
100IP can be stored here before calling
101InitStatsConnection */
102extern char StatsServerHostname[64];
103
104
105/********
106PROTOTYPES
107********/
108#ifndef GSI_UNICODE
109#define GenerateAuth GenerateAuthA
110#define SendGameSnapShot SendGameSnapShotA
111#define NewPlayer NewPlayerA
112#define NewTeam NewTeamA
113#else
114#define GenerateAuth GenerateAuthW
115#define SendGameSnapShot SendGameSnapShotW
116#define NewPlayer NewPlayerW
117#define NewTeam NewTeamW
118#endif
119
120/********
121InitStatsConnection
122
123DESCRIPTION
124Opens a connection to the stats server. Should be done before calling
125NewGame or any of the bucket/snapshot functions. May block for 1-2 secs
126while the connection is established so you will want to do this before
127gameplay starts or in another thread.
128
129PARAMETERS
130gameport: integer port associated with your server (may be the same as
131 your developer spec query port). Used only to help players differentiate
132 between servers on the same machine (no queries are done on it). If not
133 appropriate for your game, pass in 0.
134
135RETURNS
136GE_NODNS: Unable to resolve stats server DNS
137GE_NOSOCKET: Unable to create data socket
138GE_NOCONNECT: Unable to connect to stats server
139GE_DATAERROR: Unable to receive challenge from stats server, or bad challenge
140GE_NOERROR: Connected to stats server and ready to send data
141
142Note: You can still call ANY of the other Stats SDK functions, even if the
143connection fails. If you have disk logging enabled, these calls will be logged
144for future sending, otherwise they will be discarded.
145*********/
146int InitStatsConnection(int gameport);
147int InitStatsAsync(int gameport, gsi_time theInitTimeout);
148int InitStatsThink();
149
150
151/********
152StatsThink
153
154DESCRIPTION
155Eats up any incoming keep-alive messages that are sent by the stats server.
156Returns any errors occur because of a socket problem or if the SDK was
157not completely initialized.
158
159RETURNS
1601 if no errors occured during read, 0 on all other errors
161********/
162int StatsThink();
163
164/********
165IsStatsConnected
166
167DESCRIPTION
168Returns whether or not you are currently connected to the stats server. Even
169if your initial connection was successful, you may lose connection later and
170want to try to reconnnect
171
172RETURNS
1731 if connected, 0 otherwise
174*********/
175int IsStatsConnected();
176
177/********
178CloseStatsConnection
179
180DESCRIPTION
181Closes the connection to the stats server. You should do this when done
182with the connection.
183*********/
184void CloseStatsConnection(void);
185
186/********
187GetChallenge
188
189DESCRIPTION
190Returns a string that should be sent to clients for authentication
191(using GenerateAuth). You do not have to free the string when done.
192This string will be constant for the entire length of the game and is
193generated during the call to NewGame.
194
195PARAMETERS
196game: Game to return the challenge string for. If game is NULL, the last
197 game created with NewGame will be used.
198
199RETURNS
200A string to send to clients so they can authorize. If you game is NULL and
201you haven't created a game with NewGame, it returns "NULLGAME".
202*********/
203char *GetChallenge(statsgame_t game);
204
205/********
206GenerateAuth
207
208DESCRIPTION
209Should be used on the CLIENT SIDE to generate an authentication reply
210(auth_N) for a given challenge and password (CD Key or Profile password)
211
212PARAMETERS
213challenge: The challenge string sent by the server. On the server this
214 should be generated with GetChallenge
215password: The CD Key (un-hashed) or profile password
216response: The output authentication string
217
218RETURNS
219A pointer to response
220*********/
221char *GenerateAuth(const char *challenge, const gsi_char *password,/*[out]*/char response[33]);
222
223/********
224NewGame
225
226DESCRIPTION
227Creates a new game for logging and registers it with the stats server.
228Creates all the game structures, including buckets if needed.
229
230PARAMETERS
231usebuckets: Set to 1 for bucket based logging, 0 if you are going to create
232 the snapshots yourself. See the SDK for more info.
233
234RETURNS
235A pointer to the new game. If you are not connected, and disk logging is
236disabled, this will be NULL. You can still pass NULL to any function without
237causing any errors.
238Note: The last game created by NewGame is stored internally.
239If you only create / use one game at a time, you can simply discard
240the return value and pass NULL for game into all of the bucket and snapshot functions.
241*********/
242statsgame_t NewGame(int usebuckets);
243
244/********
245FreeGame
246
247DESCRIPTION
248Frees a game and its associated structures (including buckets). You should
249send a final snapshot for the game (using SendGameSnapShot with SNAP_FINAL)
250before freeing the game.
251
252PARAMETERS
253game: The game you want to free. If set to NULL, it will free the last
254 game created with NewGame.
255*********/
256void FreeGame(statsgame_t game);
257
258/********
259SendGameSnapShot
260
261DESCRIPTION
262Sends a snapshot of information about the current game. If bucket based
263logging is enabled the snapshot will be generated from the buckets, otherwise
264you should provide it in "snapshot".
265
266PARAMETERS
267game: The game to send a snapshot for. If set to NULL, the last game
268 created with NewGame will be used.
269snapshot: The snapshot to send. If you are using buckets, this will not be
270 used, so you can pass in NULL
271final: If this is SNAP_UPDATE, the game is marked as in progress, if it
272 is SNAP_FINAL, the game is marked as complete.
273
274RETURNS
275GE_DATAERROR: If game is NULL and the last game created by NewGame failed
276 (because the connection was lost and disk logging is disabled)
277GE_NOCONNECT: If the connection is lost and disk logging is disabled
278GE_NOERROR: The update was sent, or disk logging is enabled and the game was logged
279*********/
280int SendGameSnapShot(statsgame_t game, const gsi_char *snapshot, int final);
281
282/******************************
283BUCKET FUNCTION PROTOTYPES
284These functions are only used for bucket-based logging
285*******************************/
286
287/********
288Bucket_____Op
289
290DESCRIPTION
291Performs an operation on a bucket for a game. If the bucket doesn't exist already,
292the call will set the bucket to whatever "value" is.
293You can always create each bucket explicitly by using bo_set with whatever initial
294value you want the bucket to have.
295Valid operations include set, add, subtract, multiply, divide, concat, and average.
296Each bucket type (int, float, or string) has its own operation function, always call
297the same one for each bucket (i.e. don't create a bucket with BucketIntOp then try to
298add a float with BucketFloatOp).
299
300PARAMETERS
301game: The game to send containing the bucket you want to operate on.
302 If set to NULL, the last game created with NewGame will be used.
303name: The name of the bucket to update. Note that for player or team buckets, this name
304 does NOT include the "_" or "_t" (e.g. "score" for player score, not "score_N"). The underscore
305 and number will be added automatically.
306operation: One of the bucketop_t enums defined above
307value: Argument for the operation (bucket OP= value, e.g. bucket += value, bucket *= value)
308bucketlevel: One of the bucketlevel_t enums defined above. Determines whether you are
309 referring to a server, player, or team bucket. Note that you can have seperate buckets of
310 each type with the same name (e.g. "score" player bucket for each player and "score" team
311 bucket for each team)
312index: For player or team buckets, the game index of the player or team (as passed to NewPlayer or
313 NewTeam). This will be translated to the actual index internally.
314 Not used for server buckets (bl_server).
315*********/
316#define BucketIntOp(game, name, operation, value, bucketlevel, index) (((SetIntFunc)bopfuncs[bucketlevel][bt_int])(game,name,bucketfuncs[operation],value,index) )
317#define BucketFloatOp(game, name, operation, value, bucketlevel, index) (((SetFloatFunc)bopfuncs[bucketlevel][bt_float])(game,name,bucketfuncs[operation],value,index) )
318#define BucketStringOp(game, name, operation, value, bucketlevel, index) (((SetStringFunc)bopfuncs[bucketlevel][bt_string])(game,name,bucketfuncs[operation],value,index) )
319
320/********
321NewPlayer
322
323DESCRIPTION
324Adds a "player" to the game and assigns them an internal player number. Sets
325their connect time to the number of seconds since NewGame was called.
326
327PARAMETERS
328game: The game to add the player to. If set to NULL, the last game created
329 with NewGame will be used.
330pnum: Your internal reference for this player, use this value in any calls
331 to the Bucket___Op functions.
332name: The name for this player. If you don't have one yet, set it to empty ("")
333 then call: BucketStringOp(game,"player",bo_set,realplayername, bl_player, pnum)
334 when you get a realplayername.
335**********/
336void NewPlayer(statsgame_t game,int pnum, gsi_char *name);
337
338/********
339RemovePlayer
340
341DESCRIPTION
342Removes a "player" from the game and sets their disconnect time to the
343number of seconds since NewGame was called.
344
345PARAMETERS
346game: The game to remove the player from. If set to NULL, the last game created
347 with NewGame will be used.
348pnum: Your internal reference for this player, use this value in any calls
349 to the Bucket___Op functions.
350**********/
351void RemovePlayer(statsgame_t game,int pnum);
352
353/*********
354NewTeam
355RemoveTeam
356
357DESCRIPTION
358See the player functions above. These function the same, except for teams
359**********/
360void NewTeam(statsgame_t game,int tnum, gsi_char *name);
361void RemoveTeam(statsgame_t game,int tnum);
362
363/*********
364GetPlayerIndex
365GetTeamIndex
366
367DESCRIPTION
368Gets the gstats reference number for that player or team. For
369example, if you start the game and players 0, 1, and 2 join, then player 1
370leaves, and another player 1 joins, the new player 1 will be referenced
371by gstats as 3. If player 3 joins, it will be referenced as player 4, and so on.
372Normally this doesn't matter to you, but if you want to do a key name or key value
373that references a player or team number (for example, setting a player's team number),
374you need to use the translated values.
375
376PARAMETERS
377game: The game to retrieve the translated value for. If set to NULL,the last game created
378 with NewGame will be used.
379pnum/tnum: Your internal player or team number (as sent to NewTeam/NewPlayer)
380**********/
381int GetPlayerIndex(statsgame_t game, int pnum);
382int GetTeamIndex(statsgame_t game, int tnum);
383
384
385#ifdef __cplusplus
386}
387#endif
388
389#endif
Definition gstats.c:33