Do not query DNS for holepunchserver more than once per tic

This commit is contained in:
James R 2022-08-21 03:45:55 -07:00 committed by toaster
parent 0c1e311331
commit 295880351a

View file

@ -141,6 +141,7 @@
#define MAXBANS 100
#include "i_system.h"
#include "i_time.h"
#include "i_net.h"
#include "d_net.h"
#include "d_netfil.h"
@ -1354,18 +1355,29 @@ static void rendezvous(int size)
char *host = strtok(addrs, ":");
char *port = strtok(NULL, ":");
mysockaddr_t rzv;
static mysockaddr_t rzv;
static tic_t refreshtic = (tic_t)-1;
if (SOCK_GetAddr(&rzv.ip4, host, (port ? port : "7777"), false))
tic_t tic = I_GetTime();
if (tic != refreshtic)
{
if (SOCK_GetAddr(&rzv.ip4, host, (port ? port : "7777"), false))
{
refreshtic = tic;
}
else
{
CONS_Alert(CONS_ERROR, "Failed to contact rendezvous server (%s).\n",
cv_rendezvousserver.string);
}
}
if (tic == refreshtic)
{
holepunchpacket->magic = hole_punch_magic;
sendto(mysockets[0], doomcom->data, size, 0, &rzv.any, sizeof rzv.ip4);
}
else
{
CONS_Alert(CONS_ERROR, "Failed to contact rendezvous server (%s).\n",
cv_rendezvousserver.string);
}
free(addrs);
}