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.
This commit is contained in:
toaster 2022-06-14 22:09:27 +01:00
parent cd6b1b2cd9
commit 7bc59abc30
4 changed files with 20 additions and 18 deletions

View file

@ -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)

View file

@ -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

View file

@ -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);

View file

@ -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;
}