OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
sv_gqueryreporting.h
1/*
2===========================================================================
3Copyright (C) 2025 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23/******
24gqueryreporting.h
25GameSpy Query & Reporting SDK
26
27Copyright 2000 GameSpy Industries, Inc
28
2918002 Skypark Circle
30Irvine, CA 92614
31(949)798-4200
32Fax(949)798-4299
33******
34
35 Please see the GameSpy Query & Reporting SDK documentation for more
36 information
37
38******/
39
40#pragma once
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/********
47ERROR CONSTANTS
48---------------
49These constants are returned from qr_init to signal an error condition
50***************/
51
52#define E_GOA_WSOCKERROR 1
53#define E_GOA_BINDERROR 2
54#define E_GOA_DNSERROR 3
55#define E_GOA_CONNERROR 4
56/*********
57NUM_PORTS_TO_TRY
58----------------
59This value is the maximum number of ports that will be scanned to
60find an open query port, starting from the value passed to qr_init
61as the base port. Generally there is no reason to modify this value.
62***********/
63#define NUM_PORTS_TO_TRY 100
64
65/********
66DEFINES
67********/
68#define MASTER_PORT qr_get_master_port(0)
69//#define MASTER_ADDR "master." GSI_DOMAIN_NAME
70#define MASTER_ADDR qr_get_master_host(0)
71#define FIRST_HB_TIME 30000 /* 30 sec */
72#define HB_TIME 300000 /* 5 minutes */
73#define HB_SEND_DELAY 0 /* currently send to all masters at once, unless it causes problem */
74#define MAX_FIRST_COUNT 10 /* 10 tries = 5 minutes */
75#define MAX_DATA_SIZE 1400
76#define INBUF_LEN 256
77#define BUF_SIZE 1400
78
79/* The hostname of the master server.
80If the app resolves the hostname, an
81IP can be stored here before calling
82qr_init */
83extern char qr_hostname[64];
84
90extern unsigned int qr_get_num_masters();
91extern const char *qr_get_master_host(int index);
92extern int qr_get_master_port(int index);
93
94/********
95qr_querycallback_t
96-------------------
97This is the prototype for the callback functions your game needs to
98implement for each of the four basic query types. The callback works the
99same for each query type.
100
101[outbuf] is a pre-allocated buffer for you to place the query reply. It's size is
102[maxlen] (default is 1400). If you need larger, you can adjust the
103 defines in gqueryreporting.c
104[userdata] is the pointer that was passed into qr_init. You can use this for an
105 object or structure pointer if needed.
106
107Simply fill outbuf with the correct data for the query type (consult the sample
108apps and the GameSpy Developer Spec).
109outbuf should be a NULL terminated ANSI string.
110********/
111typedef void (*qr_querycallback_t)(char* outbuf, int maxlen, void* userdata);
112
113typedef void (*qr_cdkey_process_t)(char* buf, int len, struct sockaddr* fromaddr);
114
115/***********
116qr_t
117----
118This abstract type is used to instantiate multiple instances of the
119Query & Reporting SDK (for example, if you are running multiple servers
120in the same process).
121For most games, you can ignore this value and pass NULL in to all functions
122that require it. A single global instance will be used, similar to how the
123original Developer SDK worked
124************/
125typedef struct qr_implementation_s *qr_t;
126/************
127QR_INIT
128--------
129This creates/binds the sockets needed for heartbeats and queries/replies.
130[qrec] if not null, will be filled with the qr_t instance for this server.
131 If you are not using more than one instance of the Query & Reporting SDK you
132 can pass in NULL for this value.
133[ip] is an optional parameter that determines which dotted IP address to bind to on
134 a multi-homed machine. You can pass NULL to bind to all IP addresses.
135[baseport] is the port to accept queries on. If baseport is not available, the
136 Query and Reporting SDK will scan for an available port in the range of
137 baseport -> baseport + NUM_PORTS_TO_TRY
138 Optionally, you can pass in 0 to have a port chosen automatically
139 (makes it harder for debugging/testing).
140[gamename] is the unique gamename that you were given
141[secretkey] is your unique secret key
142[qr_*_callback] are your data callback functions, this cannot be NULL
143[userdata] is an optional, implementation specific parameter that will be
144 passed to all callback functions. Use it to store an object or structure
145 pointer if needed.
146
147Returns
1480 is successful, otherwise one of the E_GOA constants above.
149************/
150int qr_init(/*[out]*/ qr_t* qrec,
151 const char* ip,
152 int baseport,
153 const char* gamename,
154 const char* secret_key,
155 qr_querycallback_t qr_basic_callback,
156 qr_querycallback_t qr_info_callback,
157 qr_querycallback_t qr_rules_callback,
158 qr_querycallback_t qr_players_callback,
159 void* userdata);
160
161/*******************
162QR_PROCESS_QUERIES
163-------------------
164This function should be called somewhere in your main program loop to
165process any pending server queries and send a heartbeat if 5 minutes has
166elapsed.
167
168Query replies are very latency sensative, so you should make sure this
169function is called at least every 100ms while your game is in progress.
170The function has very low overhead and should not cause any performance
171problems.
172Unless you are using multiple instances of the SDK, you should pass NULl
173for qrec.
174The no_heartbeat version will not send any heartbeats to the master - use
175this if you only want to advertise your server on the LAN.
176********************/
177void qr_process_queries(qr_t qrec);
178void qr_process_queries_no_heartbeat(qr_t qrec);
179
180/*****************
181QR_SEND_STATECHANGED
182--------------------
183This function forces a \statechanged\ heartbeat to be sent immediately.
184Use it any time you have changed the gamestate of your game to signal the
185master to update your status.
186Also use it before your game exits by changing the gamestate to "exiting"
187and sending a statechanged heartbeat. This will insure that your game
188is removed from the list promptly.
189Unless you are using multiple instances of the SDK, you should pass NULl
190for qrec.
191*******************/
192void qr_send_statechanged(qr_t qrec);
193
194/*****************
195QR_SHUTDOWN
196------------
197This function closes the sockets created in qr_init and takes care of
198any misc. cleanup. You should try to call it when before exiting the server
199if qr_init was called.
200If you pass in a qrec that was returned from qr_init, all resources associated
201with that qrec will be freed. If you passed NULL into qr_int, you can pass
202NULL in here as well.
203******************/
204void qr_shutdown(qr_t qrec);
205
206void qr_check_queries(qr_t qrec);
207
208void qr_send_exiting(qr_t qrec);
209
210int get_master_count();
211
212void clear_master_list();
213
214int get_sockaddrin(const char *host, int port, struct sockaddr_in *saddr, struct hostent **savehent);
215
216void add_master(struct sockaddr_in *addr);
217
218#ifdef __cplusplus
219}
220#endif
Definition sv_gqueryreporting.c:138