mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-04-19 16:51:53 +00:00
Add -noipv4 flag
This commit is contained in:
parent
0c59a46d5a
commit
884e8a547b
2 changed files with 111 additions and 70 deletions
|
@ -63,7 +63,9 @@ consvar_t cv_masterserver_token = CVAR_INIT
|
|||
|
||||
static int hms_started;
|
||||
|
||||
static boolean hms_args_checked;
|
||||
static boolean hms_allow_ipv6;
|
||||
static boolean hms_allow_ipv4;
|
||||
|
||||
static char *hms_api;
|
||||
#ifdef HAVE_THREADS
|
||||
|
@ -134,6 +136,16 @@ HMS_on_read (char *s, size_t _1, size_t n, void *userdata)
|
|||
return n;
|
||||
}
|
||||
|
||||
static void HMS_check_args_once(void)
|
||||
{
|
||||
if (hms_args_checked)
|
||||
return;
|
||||
|
||||
hms_allow_ipv6 = !M_CheckParm("-noipv6");
|
||||
hms_allow_ipv4 = !M_CheckParm("-noipv4");
|
||||
hms_args_checked = true;
|
||||
}
|
||||
|
||||
static struct HMS_buffer *
|
||||
HMS_connect (int proto, const char *format, ...)
|
||||
{
|
||||
|
@ -152,7 +164,6 @@ HMS_connect (int proto, const char *format, ...)
|
|||
|
||||
if (! hms_started)
|
||||
{
|
||||
hms_allow_ipv6 = !M_CheckParm("-noipv6");
|
||||
if (curl_global_init(CURL_GLOBAL_ALL) != 0)
|
||||
{
|
||||
Contact_error();
|
||||
|
@ -234,9 +245,9 @@ HMS_connect (int proto, const char *format, ...)
|
|||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
|
||||
#ifndef NO_IPV6
|
||||
if (proto == PROTO_V6)
|
||||
if (proto == PROTO_V6 || (proto == PROTO_ANY && !hms_allow_ipv4))
|
||||
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
|
||||
if (proto == PROTO_V4)
|
||||
if (proto == PROTO_V4 || (proto == PROTO_ANY && !hms_allow_ipv6))
|
||||
#endif
|
||||
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
|
||||
|
@ -326,6 +337,8 @@ HMS_fetch_rooms (int joining, int query_id)
|
|||
|
||||
(void)query_id;
|
||||
|
||||
HMS_check_args_once();
|
||||
|
||||
hms = HMS_connect(PROTO_ANY, "rooms");
|
||||
|
||||
if (! hms)
|
||||
|
@ -420,18 +433,15 @@ int
|
|||
HMS_register (void)
|
||||
{
|
||||
struct HMS_buffer *hms;
|
||||
int ok;
|
||||
int ok = 0;
|
||||
|
||||
char post[256];
|
||||
|
||||
char *title;
|
||||
|
||||
hms = HMS_connect(PROTO_V4, "rooms/%d/register", ms_RoomId);
|
||||
HMS_check_args_once();
|
||||
|
||||
if (! hms)
|
||||
return 0;
|
||||
|
||||
title = curl_easy_escape(hms->curl, cv_servername.string, 0);
|
||||
title = curl_easy_escape(NULL, cv_servername.string, 0);
|
||||
|
||||
snprintf(post, sizeof post,
|
||||
"port=%d&"
|
||||
|
@ -447,16 +457,24 @@ HMS_register (void)
|
|||
|
||||
curl_free(title);
|
||||
|
||||
curl_easy_setopt(hms->curl, CURLOPT_POSTFIELDS, post);
|
||||
|
||||
ok = HMS_do(hms);
|
||||
|
||||
if (ok)
|
||||
if (hms_allow_ipv4)
|
||||
{
|
||||
hms_server_token = strdup(strtok(hms->buffer, "\n"));
|
||||
}
|
||||
hms = HMS_connect(PROTO_V4, "rooms/%d/register", ms_RoomId);
|
||||
|
||||
HMS_end(hms);
|
||||
if (! hms)
|
||||
return 0;
|
||||
|
||||
curl_easy_setopt(hms->curl, CURLOPT_POSTFIELDS, post);
|
||||
|
||||
ok = HMS_do(hms);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
hms_server_token = strdup(strtok(hms->buffer, "\n"));
|
||||
}
|
||||
|
||||
HMS_end(hms);
|
||||
}
|
||||
|
||||
#ifndef NO_IPV6
|
||||
if (!hms_allow_ipv6)
|
||||
|
@ -486,20 +504,25 @@ int
|
|||
HMS_unlist (void)
|
||||
{
|
||||
struct HMS_buffer *hms;
|
||||
int ok;
|
||||
int ok = 0;
|
||||
|
||||
hms = HMS_connect(PROTO_V4, "servers/%s/unlist", hms_server_token);
|
||||
HMS_check_args_once();
|
||||
|
||||
if (! hms)
|
||||
return 0;
|
||||
if (hms_server_token && hms_allow_ipv4)
|
||||
{
|
||||
hms = HMS_connect(PROTO_V4, "servers/%s/unlist", hms_server_token);
|
||||
|
||||
curl_easy_setopt(hms->curl, CURLOPT_POST, 1);
|
||||
curl_easy_setopt(hms->curl, CURLOPT_POSTFIELDSIZE, 0);
|
||||
if (! hms)
|
||||
return 0;
|
||||
|
||||
ok = HMS_do(hms);
|
||||
HMS_end(hms);
|
||||
curl_easy_setopt(hms->curl, CURLOPT_POST, 1);
|
||||
curl_easy_setopt(hms->curl, CURLOPT_POSTFIELDSIZE, 0);
|
||||
|
||||
free(hms_server_token);
|
||||
ok = HMS_do(hms);
|
||||
HMS_end(hms);
|
||||
|
||||
free(hms_server_token);
|
||||
}
|
||||
|
||||
#ifndef NO_IPV6
|
||||
if (hms_server_token_ipv6 && hms_allow_ipv6)
|
||||
|
@ -526,18 +549,15 @@ int
|
|||
HMS_update (void)
|
||||
{
|
||||
struct HMS_buffer *hms;
|
||||
int ok;
|
||||
int ok = 0;
|
||||
|
||||
char post[256];
|
||||
|
||||
char *title;
|
||||
|
||||
hms = HMS_connect(PROTO_V4, "servers/%s/update", hms_server_token);
|
||||
HMS_check_args_once();
|
||||
|
||||
if (! hms)
|
||||
return 0;
|
||||
|
||||
title = curl_easy_escape(hms->curl, cv_servername.string, 0);
|
||||
title = curl_easy_escape(NULL, cv_servername.string, 0);
|
||||
|
||||
snprintf(post, sizeof post,
|
||||
"title=%s",
|
||||
|
@ -546,10 +566,18 @@ HMS_update (void)
|
|||
|
||||
curl_free(title);
|
||||
|
||||
curl_easy_setopt(hms->curl, CURLOPT_POSTFIELDS, post);
|
||||
if (hms_server_token && hms_allow_ipv4)
|
||||
{
|
||||
hms = HMS_connect(PROTO_V4, "servers/%s/update", hms_server_token);
|
||||
|
||||
ok = HMS_do(hms);
|
||||
HMS_end(hms);
|
||||
if (! hms)
|
||||
return 0;
|
||||
|
||||
curl_easy_setopt(hms->curl, CURLOPT_POSTFIELDS, post);
|
||||
|
||||
ok = HMS_do(hms);
|
||||
HMS_end(hms);
|
||||
}
|
||||
|
||||
#ifndef NO_IPV6
|
||||
if (hms_server_token_ipv6 && hms_allow_ipv6)
|
||||
|
@ -577,6 +605,8 @@ HMS_list_servers (void)
|
|||
char *list;
|
||||
char *p;
|
||||
|
||||
HMS_check_args_once();
|
||||
|
||||
hms = HMS_connect(PROTO_ANY, "servers");
|
||||
|
||||
if (! hms)
|
||||
|
@ -622,6 +652,8 @@ HMS_fetch_servers (msg_server_t *list, int room_number, int query_id)
|
|||
|
||||
int i;
|
||||
|
||||
HMS_check_args_once();
|
||||
|
||||
(void)query_id;
|
||||
|
||||
if (room_number > 0)
|
||||
|
@ -733,6 +765,8 @@ HMS_compare_mod_version (char *buffer, size_t buffer_size)
|
|||
char *version;
|
||||
char *version_name;
|
||||
|
||||
HMS_check_args_once();
|
||||
|
||||
hms = HMS_connect(PROTO_ANY, "versions/%d", MODID);
|
||||
|
||||
if (! hms)
|
||||
|
|
|
@ -908,6 +908,7 @@ static boolean UDP_Socket(void)
|
|||
#ifdef HAVE_IPV6
|
||||
const INT32 b_ipv6 = !M_CheckParm("-noipv6");
|
||||
#endif
|
||||
const INT32 b_ipv4 = !M_CheckParm("-noipv4");
|
||||
const char *serv;
|
||||
|
||||
|
||||
|
@ -929,11 +930,34 @@ static boolean UDP_Socket(void)
|
|||
else
|
||||
serv = clientport_name;
|
||||
|
||||
if (M_CheckParm("-bindaddr"))
|
||||
if (b_ipv4)
|
||||
{
|
||||
while (M_IsNextParm())
|
||||
if (M_CheckParm("-bindaddr"))
|
||||
{
|
||||
gaie = I_getaddrinfo(M_GetNextParm(), serv, &hints, &ai);
|
||||
while (M_IsNextParm())
|
||||
{
|
||||
gaie = I_getaddrinfo(M_GetNextParm(), serv, &hints, &ai);
|
||||
if (gaie == 0)
|
||||
{
|
||||
runp = ai;
|
||||
while (runp != NULL && s < MAXNETNODES+1)
|
||||
{
|
||||
mysockets[s] = UDP_Bind(runp->ai_family, runp->ai_addr, (socklen_t)runp->ai_addrlen);
|
||||
if (mysockets[s] != (SOCKET_TYPE)ERRSOCKET)
|
||||
{
|
||||
FD_SET(mysockets[s], &masterset);
|
||||
myfamily[s] = hints.ai_family;
|
||||
s++;
|
||||
}
|
||||
runp = runp->ai_next;
|
||||
}
|
||||
I_freeaddrinfo(ai);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gaie = I_getaddrinfo("0.0.0.0", serv, &hints, &ai);
|
||||
if (gaie == 0)
|
||||
{
|
||||
runp = ai;
|
||||
|
@ -945,6 +969,13 @@ static boolean UDP_Socket(void)
|
|||
FD_SET(mysockets[s], &masterset);
|
||||
myfamily[s] = hints.ai_family;
|
||||
s++;
|
||||
#ifdef HAVE_MINIUPNPC
|
||||
if (UPNP_support)
|
||||
{
|
||||
I_UPnP_rem(serverport_name, "UDP");
|
||||
I_UPnP_add(NULL, serverport_name, "UDP");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
runp = runp->ai_next;
|
||||
}
|
||||
|
@ -952,33 +983,6 @@ static boolean UDP_Socket(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gaie = I_getaddrinfo("0.0.0.0", serv, &hints, &ai);
|
||||
if (gaie == 0)
|
||||
{
|
||||
runp = ai;
|
||||
while (runp != NULL && s < MAXNETNODES+1)
|
||||
{
|
||||
mysockets[s] = UDP_Bind(runp->ai_family, runp->ai_addr, (socklen_t)runp->ai_addrlen);
|
||||
if (mysockets[s] != (SOCKET_TYPE)ERRSOCKET)
|
||||
{
|
||||
FD_SET(mysockets[s], &masterset);
|
||||
myfamily[s] = hints.ai_family;
|
||||
s++;
|
||||
#ifdef HAVE_MINIUPNPC
|
||||
if (UPNP_support)
|
||||
{
|
||||
I_UPnP_rem(serverport_name, "UDP");
|
||||
I_UPnP_add(NULL, serverport_name, "UDP");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
runp = runp->ai_next;
|
||||
}
|
||||
I_freeaddrinfo(ai);
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_IPV6
|
||||
if (b_ipv6)
|
||||
{
|
||||
|
@ -1045,11 +1049,14 @@ static boolean UDP_Socket(void)
|
|||
|
||||
s = 0;
|
||||
|
||||
// setup broadcast adress to BROADCASTADDR entry
|
||||
broadcastaddress[s].any.sa_family = AF_INET;
|
||||
broadcastaddress[s].ip4.sin_port = htons(atoi(DEFAULTPORT));
|
||||
broadcastaddress[s].ip4.sin_addr.s_addr = htonl(INADDR_BROADCAST);
|
||||
s++;
|
||||
if (b_ipv4)
|
||||
{
|
||||
// setup broadcast adress to BROADCASTADDR entry
|
||||
broadcastaddress[s].any.sa_family = AF_INET;
|
||||
broadcastaddress[s].ip4.sin_port = htons(atoi(DEFAULTPORT));
|
||||
broadcastaddress[s].ip4.sin_addr.s_addr = htonl(INADDR_BROADCAST);
|
||||
s++;
|
||||
}
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
if (b_ipv6)
|
||||
|
|
Loading…
Reference in a new issue