Core 1.4 specific changes.

* Ensure it can compile.
    * Removing vanilla 2.2 properties that slipped in to previous commits.
    * Rearranging i_tcp.c to avoid implicit declaration.
    * Complete rename of `IsNameGood` to `EnsurePlayerNameIsGood`.
* Add "BANFORMAT" header, for versioning support.
* Add conversion from 1.3-and-earlier format to new system.
* Don't ban the entire internet - convert zero-masks to the most specific ones.

# Conflicts:
#	src/d_netcmd.c
#	src/i_tcp.c
This commit is contained in:
toaster 2022-06-14 20:23:59 +01:00
parent a477182ea7
commit 4ad6220f3e
2 changed files with 52 additions and 19 deletions

View file

@ -189,7 +189,7 @@ consvar_t cv_playbackspeed = CVAR_INIT ("playbackspeed", "1", 0, playbackspeed_c
consvar_t cv_httpsource = CVAR_INIT ("http_source", "", CV_SAVE, NULL, NULL);
consvar_t cv_kicktime = CVAR_INIT ("kicktime", "10", CV_SAVE, CV_Unsigned, NULL);
consvar_t cv_kicktime = {"kicktime", "10", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL};
static inline void *G_DcpyTiccmd(void* dest, const ticcmd_t* src, const size_t n)
{
@ -2090,6 +2090,10 @@ static void Command_ShowBan(void) //Print out ban list
}
static boolean bansLoaded = false;
// If you're a community contributor looking to improve how bans are written, please
// offer your changes back to our Git repository. Kart Krew reserve the right to
// utilise format numbers in use by community builds for different layouts.
#define BANFORMAT 1
void D_SaveBan(void)
{
@ -2116,6 +2120,9 @@ void D_SaveBan(void)
return;
}
// Add header.
fprintf(f, "BANFORMAT %d\n", BANFORMAT);
for (i = 0; (address = I_GetBanAddress(i)) != NULL; i++)
{
if (I_GetUnbanTime)
@ -2177,6 +2184,7 @@ void D_LoadBan(boolean warning)
const char *username, *reason;
time_t unbanTime = NO_BAN_TIME;
char buffer[MAX_WADPATH];
boolean banmode = 0;
if (!I_ClearBans)
return;
@ -2197,15 +2205,35 @@ void D_LoadBan(boolean warning)
for (i = 0; fgets(buffer, (int)sizeof(buffer), f); i++)
{
address = strtok(buffer, "/\t\r\n");
address = strtok(buffer, " /\t\r\n");
mask = strtok(NULL, " \t\r\n");
unbanTime = atoi(strtok(NULL, " \"\t\r\n"));
if (i == 0 && !strncmp(address, "BANFORMAT", 9))
{
banmode = atoi(mask);
continue;
}
username = strtok(NULL, "\"\t\r\n"); // go until next "
// One-way legacy format conversion -- the game will crash otherwise
if (banmode == 0)
{
unbanTime = NO_BAN_TIME;
username = NULL; // not guaranteed to be accurate, but only sane substitute
reason = strtok(NULL, "\r\n");
if (reason[0] == 'N' && reason[1] == 'A' && reason[2] == '\0')
{
reason = NULL;
}
}
else
{
unbanTime = atoi(strtok(NULL, " \"\t\r\n"));
strtok(NULL, "\"\t\r\n"); // remove first "
reason = strtok(NULL, "\"\r\n"); // go until next "
username = strtok(NULL, "\"\t\r\n"); // go until next "
strtok(NULL, "\"\t\r\n"); // remove first "
reason = strtok(NULL, "\"\r\n"); // go until next "
}
I_SetBanAddress(address, mask);
@ -2222,6 +2250,8 @@ void D_LoadBan(boolean warning)
fclose(f);
}
#undef BANFORMAT
static void Command_ReloadBan(void) //recheck ban.txt
{
D_LoadBan(true);
@ -2912,9 +2942,6 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
#ifdef DUMPCONSISTENCY
if (msg == KICK_MSG_CON_FAIL) SV_SavedGame();
#endif
LUAh_GameQuit(false);
D_QuitNetGame();
CL_Reset();
D_StartTitle();

View file

@ -1638,27 +1638,33 @@ static boolean SOCK_SetBanAddress(const char *address, const char *mask)
while (runp != NULL)
{
INT32 ban;
UINT8 numericalmask;
ban = numbans;
AddBannedIndex();
memcpy(&banned[ban].address, runp->ai_addr, runp->ai_addrlen);
if (mask)
banned[ban].mask = (UINT8)atoi(mask);
#ifdef HAVE_IPV6
else if (runp->ai_family == AF_INET6)
if (runp->ai_family == AF_INET6)
banned[ban].mask = 128;
#endif
else
#endif
banned[ban].mask = 32;
if (banned[ban].mask > 32 && runp->ai_family == AF_INET)
banned[ban].mask = 32;
#ifdef HAVE_IPV6
else if (banned[ban].mask > 128 && runp->ai_family == AF_INET6)
banned[ban].mask = 128;
#endif
if (mask)
{
numericalmask = (UINT8)atoi(mask);
}
else
{
numericalmask = 0;
}
if (numericalmask > 0 && numericalmask < banned[ban].mask)
{
banned[ban].mask = numericalmask;
}
// Set defaults, in case anything funny happens.
SOCK_SetBanUsername(NULL);