2020-04-14 04:20:29 +00:00
|
|
|
// SONIC ROBO BLAST 2 KART
|
2020-03-01 10:36:56 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 2020 by James R.
|
|
|
|
//
|
|
|
|
// This program is free software distributed under the
|
|
|
|
// terms of the GNU General Public License, version 2.
|
|
|
|
// See the 'LICENSE' file for more details.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// \brief HTTP based master server
|
|
|
|
|
2020-04-13 01:25:59 +00:00
|
|
|
/*
|
|
|
|
Documentation available here.
|
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
<https://ms.kartkrew.org/tools/api/2/>
|
2020-04-13 01:25:59 +00:00
|
|
|
*/
|
|
|
|
|
2020-08-17 04:42:58 +00:00
|
|
|
#ifdef HAVE_CURL
|
2020-03-01 10:36:56 +00:00
|
|
|
#include <curl/curl.h>
|
2020-08-17 04:42:58 +00:00
|
|
|
#endif
|
2020-03-01 10:36:56 +00:00
|
|
|
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "d_clisrv.h"
|
|
|
|
#include "command.h"
|
2020-05-13 22:29:17 +00:00
|
|
|
#include "m_argv.h"
|
2020-04-27 02:46:35 +00:00
|
|
|
#include "m_menu.h"
|
2020-03-01 10:36:56 +00:00
|
|
|
#include "mserv.h"
|
|
|
|
#include "i_tcp.h"/* for current_port */
|
2020-04-28 21:21:57 +00:00
|
|
|
#include "i_threads.h"
|
2020-04-13 00:51:05 +00:00
|
|
|
|
2020-05-15 00:19:25 +00:00
|
|
|
/* reasonable default I guess?? */
|
|
|
|
#define DEFAULT_BUFFER_SIZE (4096)
|
|
|
|
|
2020-04-13 00:51:05 +00:00
|
|
|
/* I just stop myself from making macros anymore. */
|
|
|
|
#define Blame( ... ) \
|
|
|
|
CONS_Printf("\x85" __VA_ARGS__)
|
2020-03-01 10:36:56 +00:00
|
|
|
|
2020-05-13 02:22:15 +00:00
|
|
|
static void MasterServer_Debug_OnChange (void);
|
|
|
|
|
2020-05-15 20:20:40 +00:00
|
|
|
consvar_t cv_masterserver_timeout = {
|
|
|
|
"masterserver_timeout", "5", CV_SAVE, CV_Unsigned,
|
|
|
|
NULL, 0, NULL, NULL, 0, 0, NULL/* C90 moment */
|
|
|
|
};
|
|
|
|
|
2020-03-01 19:39:27 +00:00
|
|
|
consvar_t cv_masterserver_debug = {
|
2020-05-13 02:22:15 +00:00
|
|
|
"masterserver_debug", "Off", CV_SAVE|CV_CALL, CV_OnOff,
|
|
|
|
MasterServer_Debug_OnChange, 0, NULL, NULL, 0, 0, NULL/* C90 moment */
|
2020-03-01 19:39:27 +00:00
|
|
|
};
|
|
|
|
|
2020-06-13 06:47:08 +00:00
|
|
|
consvar_t cv_masterserver_token = {
|
|
|
|
"masterserver_token", "", CV_SAVE, NULL,
|
|
|
|
NULL, 0, NULL, NULL, 0, 0, NULL/* C90 moment */
|
|
|
|
};
|
|
|
|
|
2020-08-17 04:42:58 +00:00
|
|
|
#ifdef MASTERSERVER
|
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
static int hms_started;
|
|
|
|
|
2020-04-28 21:21:57 +00:00
|
|
|
static char *hms_api;
|
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
static I_mutex hms_api_mutex;
|
|
|
|
#endif
|
|
|
|
|
2020-04-13 01:25:59 +00:00
|
|
|
static char *hms_server_token;
|
2020-03-01 10:36:56 +00:00
|
|
|
|
|
|
|
struct HMS_buffer
|
|
|
|
{
|
|
|
|
CURL *curl;
|
|
|
|
char *buffer;
|
|
|
|
int needle;
|
|
|
|
int end;
|
|
|
|
};
|
|
|
|
|
2020-04-13 00:51:05 +00:00
|
|
|
static void
|
2020-04-13 01:27:01 +00:00
|
|
|
Contact_error (void)
|
2020-04-13 00:51:05 +00:00
|
|
|
{
|
|
|
|
CONS_Alert(CONS_ERROR,
|
|
|
|
"There was a problem contacting the master server...\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
static size_t
|
|
|
|
HMS_on_read (char *s, size_t _1, size_t n, void *userdata)
|
|
|
|
{
|
|
|
|
struct HMS_buffer *buffer;
|
2020-05-15 00:19:25 +00:00
|
|
|
size_t blocks;
|
|
|
|
|
2020-04-14 06:31:26 +00:00
|
|
|
(void)_1;
|
2020-05-15 00:19:25 +00:00
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
buffer = userdata;
|
2020-05-15 00:19:25 +00:00
|
|
|
|
|
|
|
if (n >= (size_t)( buffer->end - buffer->needle ))
|
2020-03-01 10:36:56 +00:00
|
|
|
{
|
2020-05-15 00:19:25 +00:00
|
|
|
/* resize to next multiple of buffer size */
|
|
|
|
blocks = ( n / DEFAULT_BUFFER_SIZE + 1 );
|
2020-06-15 02:13:22 +00:00
|
|
|
buffer->end += ( blocks * DEFAULT_BUFFER_SIZE );
|
2020-05-15 00:19:25 +00:00
|
|
|
|
|
|
|
buffer->buffer = realloc(buffer->buffer, buffer->end);
|
2020-03-01 10:36:56 +00:00
|
|
|
}
|
2020-05-15 00:19:25 +00:00
|
|
|
|
|
|
|
memcpy(&buffer->buffer[buffer->needle], s, n);
|
|
|
|
buffer->needle += n;
|
|
|
|
|
|
|
|
return n;
|
2020-03-01 10:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct HMS_buffer *
|
|
|
|
HMS_connect (const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
CURL *curl;
|
|
|
|
char *url;
|
2020-06-13 06:47:08 +00:00
|
|
|
char *quack_token;
|
2020-03-01 10:36:56 +00:00
|
|
|
size_t seek;
|
2020-06-13 06:47:08 +00:00
|
|
|
size_t token_length;
|
2020-03-01 10:36:56 +00:00
|
|
|
struct HMS_buffer *buffer;
|
|
|
|
|
|
|
|
if (! hms_started)
|
|
|
|
{
|
2020-04-13 00:51:05 +00:00
|
|
|
if (curl_global_init(CURL_GLOBAL_ALL) != 0)
|
|
|
|
{
|
|
|
|
Contact_error();
|
|
|
|
Blame("From curl_global_init.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
atexit(curl_global_cleanup);
|
|
|
|
hms_started = 1;
|
|
|
|
}
|
2020-03-01 10:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
curl = curl_easy_init();
|
|
|
|
|
2020-04-13 00:51:05 +00:00
|
|
|
if (! curl)
|
|
|
|
{
|
|
|
|
Contact_error();
|
|
|
|
Blame("From curl_easy_init.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-06-13 06:47:08 +00:00
|
|
|
if (cv_masterserver_token.string[0])
|
|
|
|
{
|
|
|
|
quack_token = curl_easy_escape(curl, cv_masterserver_token.string, 0);
|
2020-09-11 12:56:40 +00:00
|
|
|
token_length = ( sizeof "&token="-1 )+ strlen(quack_token);
|
2020-06-13 06:47:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
quack_token = NULL;
|
|
|
|
token_length = 0;
|
|
|
|
}
|
|
|
|
|
2020-04-28 21:21:57 +00:00
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
I_lock_mutex(&hms_api_mutex);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
seek = strlen(hms_api) + 1;/* + '/' */
|
2020-03-01 10:36:56 +00:00
|
|
|
|
|
|
|
va_start (ap, format);
|
2020-09-11 12:56:40 +00:00
|
|
|
url = malloc(seek + vsnprintf(0, 0, format, ap) +
|
|
|
|
sizeof "?v=2" - 1 +
|
|
|
|
token_length + 1);
|
2020-03-01 10:36:56 +00:00
|
|
|
va_end (ap);
|
|
|
|
|
2020-04-28 21:21:57 +00:00
|
|
|
sprintf(url, "%s/", hms_api);
|
|
|
|
|
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
I_unlock_mutex(hms_api_mutex);
|
|
|
|
#endif
|
2020-03-01 10:36:56 +00:00
|
|
|
|
|
|
|
va_start (ap, format);
|
2020-06-13 06:47:08 +00:00
|
|
|
seek += vsprintf(&url[seek], format, ap);
|
2020-03-01 10:36:56 +00:00
|
|
|
va_end (ap);
|
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
strcpy(&url[seek], "?v=2");
|
|
|
|
seek += sizeof "?v=2" - 1;
|
|
|
|
|
2020-06-13 06:47:08 +00:00
|
|
|
if (quack_token)
|
2020-09-12 17:32:14 +00:00
|
|
|
sprintf(&url[seek], "&token=%s", quack_token);
|
2020-06-13 06:47:08 +00:00
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
CONS_Printf("HMS: connecting '%s'...\n", url);
|
|
|
|
|
2020-04-27 04:56:59 +00:00
|
|
|
buffer = malloc(sizeof *buffer);
|
2020-03-01 10:36:56 +00:00
|
|
|
buffer->curl = curl;
|
2020-05-15 00:19:25 +00:00
|
|
|
buffer->end = DEFAULT_BUFFER_SIZE;
|
2020-04-27 04:56:59 +00:00
|
|
|
buffer->buffer = malloc(buffer->end);
|
2020-03-01 10:36:56 +00:00
|
|
|
buffer->needle = 0;
|
|
|
|
|
2020-03-01 19:39:27 +00:00
|
|
|
if (cv_masterserver_debug.value)
|
2020-03-01 19:46:02 +00:00
|
|
|
{
|
2020-03-01 19:39:27 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
2020-03-01 19:46:02 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_STDERR, logstream);
|
|
|
|
}
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-05-13 22:29:17 +00:00
|
|
|
if (M_CheckParm("-bindaddr") && M_IsNextParm())
|
|
|
|
{
|
|
|
|
curl_easy_setopt(curl, CURLOPT_INTERFACE, M_GetNextParm());
|
|
|
|
}
|
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
2020-05-13 01:52:05 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-05-15 20:20:40 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, cv_masterserver_timeout.value);
|
2020-03-01 10:36:56 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HMS_on_read);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
|
|
|
|
|
2020-06-13 06:47:08 +00:00
|
|
|
curl_free(quack_token);
|
2020-04-27 04:56:59 +00:00
|
|
|
free(url);
|
2020-03-01 10:36:56 +00:00
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
HMS_do (struct HMS_buffer *buffer)
|
|
|
|
{
|
2020-04-13 00:51:05 +00:00
|
|
|
CURLcode cc;
|
2020-03-01 10:36:56 +00:00
|
|
|
long status;
|
2020-04-13 00:51:05 +00:00
|
|
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
cc = curl_easy_perform(buffer->curl);
|
|
|
|
|
|
|
|
if (cc != CURLE_OK)
|
|
|
|
{
|
|
|
|
Contact_error();
|
|
|
|
Blame(
|
|
|
|
"From curl_easy_perform: %s\n",
|
|
|
|
curl_easy_strerror(cc)
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
buffer->buffer[buffer->needle] = '\0';
|
2020-04-13 00:51:05 +00:00
|
|
|
|
|
|
|
curl_easy_getinfo(buffer->curl, CURLINFO_RESPONSE_CODE, &status);
|
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
if (status != 200)
|
|
|
|
{
|
2020-04-13 00:51:05 +00:00
|
|
|
p = strchr(buffer->buffer, '\n');
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
Contact_error();
|
|
|
|
Blame(
|
|
|
|
"Master server error %ld: %s%s\n",
|
2020-03-01 10:36:56 +00:00
|
|
|
status,
|
2020-04-13 00:51:05 +00:00
|
|
|
buffer->buffer,
|
|
|
|
( (p) ? "" : " (malformed)" )
|
2020-03-01 10:36:56 +00:00
|
|
|
);
|
2020-04-13 00:51:05 +00:00
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
HMS_end (struct HMS_buffer *buffer)
|
|
|
|
{
|
|
|
|
curl_easy_cleanup(buffer->curl);
|
2020-04-27 04:56:59 +00:00
|
|
|
free(buffer->buffer);
|
|
|
|
free(buffer);
|
2020-03-01 10:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
HMS_register (void)
|
|
|
|
{
|
|
|
|
struct HMS_buffer *hms;
|
|
|
|
int ok;
|
|
|
|
|
2020-04-13 01:25:59 +00:00
|
|
|
char post[256];
|
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
char *contact;
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
hms = HMS_connect(
|
|
|
|
"games/%s/%d/servers/register", SRB2APPLICATION, MODVERSION);
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-04-14 23:55:14 +00:00
|
|
|
if (! hms)
|
|
|
|
return 0;
|
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
contact = curl_easy_escape(hms->curl, cv_server_contact.string, 0);
|
2020-04-13 01:25:59 +00:00
|
|
|
|
|
|
|
snprintf(post, sizeof post,
|
|
|
|
"port=%d&"
|
2020-09-11 12:56:40 +00:00
|
|
|
"contact=%s",
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
current_port,
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
contact
|
2020-03-01 10:36:56 +00:00
|
|
|
);
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
curl_free(contact);
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
curl_easy_setopt(hms->curl, CURLOPT_POSTFIELDS, post);
|
|
|
|
|
|
|
|
ok = HMS_do(hms);
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
{
|
2020-04-27 04:56:59 +00:00
|
|
|
hms_server_token = strdup(strtok(hms->buffer, "\n"));
|
2020-03-01 10:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HMS_end(hms);
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2020-04-28 19:33:50 +00:00
|
|
|
int
|
2020-03-01 10:36:56 +00:00
|
|
|
HMS_unlist (void)
|
|
|
|
{
|
|
|
|
struct HMS_buffer *hms;
|
2020-04-28 19:33:50 +00:00
|
|
|
int ok;
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-03-21 03:25:34 +00:00
|
|
|
hms = HMS_connect("servers/%s/unlist", hms_server_token);
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-04-14 23:55:14 +00:00
|
|
|
if (! hms)
|
2020-04-28 19:33:50 +00:00
|
|
|
return 0;
|
2020-04-14 23:55:14 +00:00
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
curl_easy_setopt(hms->curl, CURLOPT_CUSTOMREQUEST, "POST");
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-04-28 19:33:50 +00:00
|
|
|
ok = HMS_do(hms);
|
2020-03-01 10:36:56 +00:00
|
|
|
HMS_end(hms);
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-04-27 04:56:59 +00:00
|
|
|
free(hms_server_token);
|
2020-04-28 19:33:50 +00:00
|
|
|
|
|
|
|
return ok;
|
2020-03-01 10:36:56 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 05:23:01 +00:00
|
|
|
int
|
2020-03-01 10:36:56 +00:00
|
|
|
HMS_update (void)
|
|
|
|
{
|
|
|
|
struct HMS_buffer *hms;
|
2020-04-14 05:23:01 +00:00
|
|
|
int ok;
|
2020-04-13 01:25:59 +00:00
|
|
|
|
|
|
|
char post[256];
|
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
char *title;
|
|
|
|
|
2020-03-21 03:25:34 +00:00
|
|
|
hms = HMS_connect("servers/%s/update", hms_server_token);
|
2020-03-01 10:36:56 +00:00
|
|
|
|
2020-04-14 23:55:14 +00:00
|
|
|
if (! hms)
|
|
|
|
return 0;
|
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
title = curl_easy_escape(hms->curl, cv_servername.string, 0);
|
2020-04-13 01:25:59 +00:00
|
|
|
|
|
|
|
snprintf(post, sizeof post,
|
|
|
|
"title=%s",
|
|
|
|
title
|
|
|
|
);
|
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
curl_free(title);
|
|
|
|
|
|
|
|
curl_easy_setopt(hms->curl, CURLOPT_POSTFIELDS, post);
|
|
|
|
|
2020-04-14 05:23:01 +00:00
|
|
|
ok = HMS_do(hms);
|
2020-03-01 10:36:56 +00:00
|
|
|
HMS_end(hms);
|
2020-04-14 05:23:01 +00:00
|
|
|
|
|
|
|
return ok;
|
2020-03-01 10:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HMS_list_servers (void)
|
|
|
|
{
|
|
|
|
struct HMS_buffer *hms;
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
hms = HMS_connect("games/%s/%d/servers", SRB2APPLICATION, MODVERSION);
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-04-14 23:55:14 +00:00
|
|
|
if (! hms)
|
|
|
|
return;
|
|
|
|
|
2020-03-01 18:59:25 +00:00
|
|
|
if (HMS_do(hms))
|
2020-04-13 01:25:59 +00:00
|
|
|
{
|
|
|
|
CONS_Printf("%s\n", hms->buffer);
|
|
|
|
}
|
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
HMS_end(hms);
|
|
|
|
}
|
|
|
|
|
2020-04-14 05:23:01 +00:00
|
|
|
msg_server_t *
|
2020-09-11 12:56:40 +00:00
|
|
|
HMS_fetch_servers (msg_server_t *list, int query_id)
|
2020-03-01 10:36:56 +00:00
|
|
|
{
|
|
|
|
struct HMS_buffer *hms;
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-04-27 02:46:35 +00:00
|
|
|
int doing_shit;
|
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
char *address;
|
|
|
|
char *port;
|
2020-09-11 12:56:40 +00:00
|
|
|
char *contact;
|
2020-04-13 01:25:59 +00:00
|
|
|
|
|
|
|
char *end;
|
|
|
|
char *p;
|
2020-03-01 10:36:56 +00:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2020-04-27 02:46:35 +00:00
|
|
|
(void)query_id;
|
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
hms = HMS_connect("games/%s/%d/servers", SRB2APPLICATION, MODVERSION);
|
2020-03-01 10:36:56 +00:00
|
|
|
|
2020-04-14 23:55:14 +00:00
|
|
|
if (! hms)
|
|
|
|
return NULL;
|
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
if (HMS_do(hms))
|
|
|
|
{
|
2020-04-27 02:46:35 +00:00
|
|
|
doing_shit = 1;
|
|
|
|
|
2020-03-01 10:36:56 +00:00
|
|
|
p = hms->buffer;
|
|
|
|
i = 0;
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
while (i < MAXSERVERLIST && ( end = strchr(p, '\n') ))
|
2020-03-01 10:36:56 +00:00
|
|
|
{
|
2020-09-11 12:56:40 +00:00
|
|
|
*end = '\0';
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
address = strtok(p, " ");
|
|
|
|
port = strtok(0, " ");
|
|
|
|
contact = strtok(0, "");
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
if (address && port)
|
2020-03-01 10:36:56 +00:00
|
|
|
{
|
2020-04-27 02:46:35 +00:00
|
|
|
#ifdef HAVE_THREADS
|
2020-09-11 12:56:40 +00:00
|
|
|
I_lock_mutex(&ms_QueryId_mutex);
|
|
|
|
{
|
|
|
|
if (query_id != ms_QueryId)
|
|
|
|
doing_shit = 0;
|
|
|
|
}
|
|
|
|
I_unlock_mutex(ms_QueryId_mutex);
|
|
|
|
|
|
|
|
if (! doing_shit)
|
|
|
|
break;
|
2020-04-27 02:46:35 +00:00
|
|
|
#endif
|
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
strlcpy(list[i].ip, address, sizeof list[i].ip);
|
|
|
|
strlcpy(list[i].port, port, sizeof list[i].port);
|
2020-03-01 10:36:56 +00:00
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
if (contact)
|
|
|
|
{
|
|
|
|
strlcpy(list[i].contact, contact, sizeof list[i].contact);
|
|
|
|
}
|
2020-03-01 10:36:56 +00:00
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
list[i].header.buffer[0] = 1;
|
2020-04-13 01:25:59 +00:00
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
i++;
|
2020-03-01 10:36:56 +00:00
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
p = ( end + 1 );/* skip server delimiter */
|
2020-03-01 10:36:56 +00:00
|
|
|
}
|
2020-09-11 12:56:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* malformed so quit the parsing */
|
2020-04-27 02:46:35 +00:00
|
|
|
break;
|
2020-09-11 12:56:40 +00:00
|
|
|
}
|
2020-03-01 10:36:56 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 02:46:35 +00:00
|
|
|
if (doing_shit)
|
|
|
|
list[i].header.buffer[0] = 0;
|
2020-03-01 10:36:56 +00:00
|
|
|
}
|
2020-04-14 05:23:01 +00:00
|
|
|
else
|
|
|
|
list = NULL;
|
2020-03-01 10:36:56 +00:00
|
|
|
|
|
|
|
HMS_end(hms);
|
2020-04-14 05:23:01 +00:00
|
|
|
|
|
|
|
return list;
|
2020-03-01 10:36:56 +00:00
|
|
|
}
|
2020-04-13 03:37:46 +00:00
|
|
|
|
2020-04-14 05:23:01 +00:00
|
|
|
int
|
|
|
|
HMS_compare_mod_version (char *buffer, size_t buffer_size)
|
2020-04-13 03:37:46 +00:00
|
|
|
{
|
|
|
|
struct HMS_buffer *hms;
|
2020-04-14 05:23:01 +00:00
|
|
|
int ok;
|
2020-04-13 03:37:46 +00:00
|
|
|
|
|
|
|
char *version;
|
|
|
|
char *version_name;
|
|
|
|
|
2020-09-11 12:56:40 +00:00
|
|
|
hms = HMS_connect("games/%s/version", SRB2APPLICATION);
|
2020-04-13 03:37:46 +00:00
|
|
|
|
2020-04-14 23:55:14 +00:00
|
|
|
if (! hms)
|
|
|
|
return 0;
|
|
|
|
|
2020-04-14 05:23:01 +00:00
|
|
|
ok = 0;
|
|
|
|
|
2020-04-13 03:37:46 +00:00
|
|
|
if (HMS_do(hms))
|
|
|
|
{
|
|
|
|
version = strtok(hms->buffer, " ");
|
|
|
|
version_name = strtok(0, "\n");
|
|
|
|
|
|
|
|
if (version && version_name)
|
|
|
|
{
|
|
|
|
if (atoi(version) != MODVERSION)
|
|
|
|
{
|
2020-04-14 05:23:01 +00:00
|
|
|
strlcpy(buffer, version_name, buffer_size);
|
|
|
|
ok = 1;
|
2020-04-13 03:37:46 +00:00
|
|
|
}
|
|
|
|
else
|
2020-04-14 05:23:01 +00:00
|
|
|
ok = -1;
|
2020-04-13 03:37:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HMS_end(hms);
|
|
|
|
|
2020-04-14 05:23:01 +00:00
|
|
|
return ok;
|
2020-04-13 03:37:46 +00:00
|
|
|
}
|
2020-04-28 21:21:57 +00:00
|
|
|
|
2020-09-12 00:33:46 +00:00
|
|
|
static char *
|
|
|
|
Strip_trailing_slashes (char *api)
|
|
|
|
{
|
|
|
|
char * p = &api[strlen(api)];
|
|
|
|
|
|
|
|
while (*--p == '/')
|
|
|
|
;
|
|
|
|
|
|
|
|
p[1] = '\0';
|
|
|
|
|
|
|
|
return api;
|
|
|
|
}
|
|
|
|
|
2020-04-28 21:21:57 +00:00
|
|
|
void
|
|
|
|
HMS_set_api (char *api)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
I_lock_mutex(&hms_api_mutex);
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
free(hms_api);
|
2020-09-12 00:33:46 +00:00
|
|
|
hms_api = Strip_trailing_slashes(api);
|
2020-04-28 21:21:57 +00:00
|
|
|
}
|
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
I_unlock_mutex(hms_api_mutex);
|
|
|
|
#endif
|
|
|
|
}
|
2020-05-13 02:22:15 +00:00
|
|
|
|
2020-08-17 04:42:58 +00:00
|
|
|
#endif/*MASTERSERVER*/
|
|
|
|
|
2020-05-13 02:22:15 +00:00
|
|
|
static void
|
|
|
|
MasterServer_Debug_OnChange (void)
|
|
|
|
{
|
2020-08-17 04:42:58 +00:00
|
|
|
#ifdef MASTERSERVER
|
2020-05-13 02:22:15 +00:00
|
|
|
/* TODO: change to 'latest-log.txt' for log files revision. */
|
|
|
|
if (cv_masterserver_debug.value)
|
|
|
|
CONS_Printf("Master server debug messages will appear in log.txt\n");
|
2020-08-17 04:42:58 +00:00
|
|
|
#endif
|
2020-05-13 02:22:15 +00:00
|
|
|
}
|