From 7bc59abc30f210e76ab8751e0a1dc22f82d9e3b8 Mon Sep 17 00:00:00 2001 From: toaster Date: Tue, 14 Jun 2022 22:09:27 +0100 Subject: [PATCH] Create a single struct for bannednode and bannednodetimelft, and use the matching ban ID inside that struct. While this commit does not increase the visibility of ban reasons, it makes this possible later. --- src/d_clisrv.c | 6 +++--- src/d_net.c | 3 +-- src/i_net.h | 9 +++++++-- src/i_tcp.c | 20 +++++++++----------- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 4c2579d2..22de9981 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4229,11 +4229,11 @@ static void HandleConnect(SINT8 node) // It's too much effort to legimately fix right now. Just prevent it from reaching that state. UINT8 maxplayers = min((dedicated ? MAXPLAYERS-1 : MAXPLAYERS), cv_maxplayers.value); - if (bannednode && bannednode[node]) + if (bannednode && bannednode[node].banid != SIZE_MAX) { - if (bannednodetimeleft && bannednodetimeleft[node] != NO_BAN_TIME) + if (bannednode[node].timeleft != NO_BAN_TIME) { - int minutes = bannednodetimeleft[node] / 60; + int minutes = bannednode[node].timeleft / 60; int hours = minutes / 60; if (hours) diff --git a/src/d_net.c b/src/d_net.c index 264e7c8b..cccd2088 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -86,8 +86,7 @@ boolean (*I_SetBanAddress) (const char *address, const char *mask) = NULL; boolean (*I_SetBanUsername) (const char *username) = NULL; boolean (*I_SetBanReason) (const char *reason) = NULL; boolean (*I_SetUnbanTime) (time_t timestamp) = NULL; -boolean *bannednode = NULL; -time_t *bannednodetimeleft = NULL; +bannednode_t *bannednode = NULL; // network stats diff --git a/src/i_net.h b/src/i_net.h index 155935f5..a5b1aba8 100644 --- a/src/i_net.h +++ b/src/i_net.h @@ -154,8 +154,13 @@ extern boolean (*I_SetBanAddress) (const char *address,const char *mask); extern boolean (*I_SetBanUsername) (const char *username); extern boolean (*I_SetBanReason) (const char *reason); extern boolean (*I_SetUnbanTime) (time_t timestamp); -extern boolean *bannednode; -extern time_t *bannednodetimeleft; + +typedef struct +{ + size_t banid; + time_t timeleft; +} bannednode_t; +extern bannednode_t *bannednode; /// \brief Called by D_SRB2Main to be defined by extern network driver boolean I_InitNetwork(void); diff --git a/src/i_tcp.c b/src/i_tcp.c index c3d49ccc..d0abb4f9 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -254,8 +254,7 @@ static banned_t *banned; static size_t numbans = 0; static size_t banned_size = 0; -static boolean SOCK_bannednode[MAXNETNODES+1]; /// \note do we really need the +1? -static time_t SOCK_bannednodetimeleft[MAXNETNODES+1]; +static bannednode_t SOCK_bannednode[MAXNETNODES+1]; /// \note do we really need the +1? static boolean init_tcp_driver = false; static const char *serverport_name = DEFAULTPORT; @@ -702,21 +701,21 @@ static boolean SOCK_Get(void) { if (curTime >= banned[i].timestamp) { - SOCK_bannednodetimeleft[j] = NO_BAN_TIME; - SOCK_bannednode[j] = false; + SOCK_bannednode[j].timeleft = NO_BAN_TIME; + SOCK_bannednode[j].banid = SIZE_MAX; DEBFILE("This dude was banned, but enough time has passed\n"); break; } - SOCK_bannednodetimeleft[j] = banned[i].timestamp - curTime; - SOCK_bannednode[j] = true; + SOCK_bannednode[j].timeleft = banned[i].timestamp - curTime; + SOCK_bannednode[j].banid = i; DEBFILE("This dude has been temporarily banned\n"); break; } else { - SOCK_bannednodetimeleft[j] = NO_BAN_TIME; - SOCK_bannednode[j] = true; + SOCK_bannednode[j].timeleft = NO_BAN_TIME; + SOCK_bannednode[j].banid = i; DEBFILE("This dude has been banned\n"); break; } @@ -725,8 +724,8 @@ static boolean SOCK_Get(void) if (i == numbans) { - SOCK_bannednodetimeleft[j] = NO_BAN_TIME; - SOCK_bannednode[j] = false; + SOCK_bannednode[j].timeleft = NO_BAN_TIME; + SOCK_bannednode[j].banid = SIZE_MAX; } return true; @@ -1756,7 +1755,6 @@ boolean I_InitTcpNetwork(void) I_SetBanReason = SOCK_SetBanReason; I_SetUnbanTime = SOCK_SetUnbanTime; bannednode = SOCK_bannednode; - bannednodetimeleft = SOCK_bannednodetimeleft; return ret; }