mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-28 20:20:43 +00:00
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.
This commit is contained in:
parent
55be74396f
commit
8addea0d45
3 changed files with 110 additions and 77 deletions
|
@ -180,7 +180,7 @@ consvar_t cv_playbackspeed = {"playbackspeed", "1", 0, playbackspeed_cons_t, NUL
|
||||||
|
|
||||||
consvar_t cv_httpsource = {"http_source", "", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL};
|
consvar_t cv_httpsource = {"http_source", "", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, 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)
|
static inline void *G_DcpyTiccmd(void* dest, const ticcmd_t* src, const size_t n)
|
||||||
{
|
{
|
||||||
|
@ -2674,6 +2674,10 @@ static void Command_ShowBan(void) //Print out ban list
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean bansLoaded = false;
|
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)
|
void D_SaveBan(void)
|
||||||
{
|
{
|
||||||
|
@ -2700,6 +2704,9 @@ void D_SaveBan(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add header.
|
||||||
|
fprintf(f, "BANFORMAT %d\n", BANFORMAT);
|
||||||
|
|
||||||
for (i = 0; (address = I_GetBanAddress(i)) != NULL; i++)
|
for (i = 0; (address = I_GetBanAddress(i)) != NULL; i++)
|
||||||
{
|
{
|
||||||
if (I_GetUnbanTime)
|
if (I_GetUnbanTime)
|
||||||
|
@ -2759,6 +2766,7 @@ void D_LoadBan(boolean warning)
|
||||||
const char *username, *reason;
|
const char *username, *reason;
|
||||||
time_t unbanTime = NO_BAN_TIME;
|
time_t unbanTime = NO_BAN_TIME;
|
||||||
char buffer[MAX_WADPATH];
|
char buffer[MAX_WADPATH];
|
||||||
|
boolean banmode = 0;
|
||||||
|
|
||||||
if (!I_ClearBans)
|
if (!I_ClearBans)
|
||||||
return;
|
return;
|
||||||
|
@ -2779,15 +2787,35 @@ void D_LoadBan(boolean warning)
|
||||||
|
|
||||||
for (i = 0; fgets(buffer, (int)sizeof(buffer), f); i++)
|
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");
|
mask = strtok(NULL, " \t\r\n");
|
||||||
|
|
||||||
|
if (i == 0 && !strncmp(address, "BANFORMAT", 9))
|
||||||
|
{
|
||||||
|
banmode = atoi(mask);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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"));
|
unbanTime = atoi(strtok(NULL, " \"\t\r\n"));
|
||||||
|
|
||||||
username = strtok(NULL, "\"\t\r\n"); // go until next "
|
username = strtok(NULL, "\"\t\r\n"); // go until next "
|
||||||
|
|
||||||
strtok(NULL, "\"\t\r\n"); // remove first "
|
strtok(NULL, "\"\t\r\n"); // remove first "
|
||||||
reason = strtok(NULL, "\"\r\n"); // go until next "
|
reason = strtok(NULL, "\"\r\n"); // go until next "
|
||||||
|
}
|
||||||
|
|
||||||
I_SetBanAddress(address, mask);
|
I_SetBanAddress(address, mask);
|
||||||
|
|
||||||
|
@ -2804,6 +2832,8 @@ void D_LoadBan(boolean warning)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef BANFORMAT
|
||||||
|
|
||||||
static void Command_ReloadBan(void) //recheck ban.txt
|
static void Command_ReloadBan(void) //recheck ban.txt
|
||||||
{
|
{
|
||||||
D_LoadBan(true);
|
D_LoadBan(true);
|
||||||
|
@ -3507,9 +3537,6 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
|
||||||
#ifdef DUMPCONSISTENCY
|
#ifdef DUMPCONSISTENCY
|
||||||
if (msg == KICK_MSG_CON_FAIL) SV_SavedGame();
|
if (msg == KICK_MSG_CON_FAIL) SV_SavedGame();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LUAh_GameQuit(false);
|
|
||||||
|
|
||||||
D_QuitNetGame();
|
D_QuitNetGame();
|
||||||
CL_Reset();
|
CL_Reset();
|
||||||
D_StartTitle();
|
D_StartTitle();
|
||||||
|
|
|
@ -1085,14 +1085,14 @@ boolean EnsurePlayerNameIsGood(char *name, INT32 playernum)
|
||||||
if (len > 1)
|
if (len > 1)
|
||||||
{
|
{
|
||||||
name[len-1] = '\0';
|
name[len-1] = '\0';
|
||||||
if (!IsNameGood (name, playernum))
|
if (!EnsurePlayerNameIsGood(name, playernum))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (len == 1) // Agh!
|
else if (len == 1) // Agh!
|
||||||
{
|
{
|
||||||
// Last ditch effort...
|
// Last ditch effort...
|
||||||
sprintf(name, "%d", M_RandomKey(10));
|
sprintf(name, "%d", M_RandomKey(10));
|
||||||
if (!IsNameGood (name, playernum))
|
if (!EnsurePlayerNameIsGood(name, playernum))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1232,12 +1232,12 @@ static void CleanupPlayerName(INT32 playernum, const char *newname)
|
||||||
* \param newname New name for that player. Should be good, but won't
|
* \param newname New name for that player. Should be good, but won't
|
||||||
* necessarily be if the client is maliciously modified or
|
* necessarily be if the client is maliciously modified or
|
||||||
* buggy.
|
* buggy.
|
||||||
* \sa CleanupPlayerName, IsNameGood
|
* \sa CleanupPlayerName, EnsurePlayerNameIsGood
|
||||||
* \author Graue <graue@oceanbase.org>
|
* \author Graue <graue@oceanbase.org>
|
||||||
*/
|
*/
|
||||||
static void SetPlayerName(INT32 playernum, char *newname)
|
static void SetPlayerName(INT32 playernum, char *newname)
|
||||||
{
|
{
|
||||||
if (IsNameGood(newname, playernum))
|
if (EnsurePlayerNameIsGood(newname, playernum))
|
||||||
{
|
{
|
||||||
if (strcasecmp(newname, player_names[playernum]) != 0)
|
if (strcasecmp(newname, player_names[playernum]) != 0)
|
||||||
{
|
{
|
||||||
|
|
134
src/i_tcp.c
134
src/i_tcp.c
|
@ -1527,70 +1527,6 @@ static boolean SOCK_Ban(INT32 node)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean SOCK_SetBanAddress(const char *address, const char *mask)
|
|
||||||
{
|
|
||||||
#ifdef NONET
|
|
||||||
(void)address;
|
|
||||||
(void)mask;
|
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
struct my_addrinfo *ai, *runp, hints;
|
|
||||||
int gaie;
|
|
||||||
|
|
||||||
if (!address)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
memset(&hints, 0x00, sizeof(hints));
|
|
||||||
hints.ai_flags = 0;
|
|
||||||
hints.ai_family = AF_UNSPEC;
|
|
||||||
hints.ai_socktype = SOCK_DGRAM;
|
|
||||||
hints.ai_protocol = IPPROTO_UDP;
|
|
||||||
|
|
||||||
gaie = I_getaddrinfo(address, "0", &hints, &ai);
|
|
||||||
if (gaie != 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
runp = ai;
|
|
||||||
|
|
||||||
while (runp != NULL)
|
|
||||||
{
|
|
||||||
INT32 ban;
|
|
||||||
|
|
||||||
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)
|
|
||||||
banned[ban].mask = 128;
|
|
||||||
#endif
|
|
||||||
else
|
|
||||||
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
|
|
||||||
|
|
||||||
// Set defaults, in case anything funny happens.
|
|
||||||
SOCK_SetBanUsername(NULL);
|
|
||||||
SOCK_SetBanReason(NULL);
|
|
||||||
SOCK_SetUnbanTime(NO_BAN_TIME);
|
|
||||||
|
|
||||||
runp = runp->ai_next;
|
|
||||||
}
|
|
||||||
|
|
||||||
I_freeaddrinfo(ai);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean SOCK_SetBanUsername(const char *username)
|
static boolean SOCK_SetBanUsername(const char *username)
|
||||||
{
|
{
|
||||||
#ifdef NONET
|
#ifdef NONET
|
||||||
|
@ -1646,6 +1582,76 @@ static boolean SOCK_SetUnbanTime(time_t timestamp)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean SOCK_SetBanAddress(const char *address, const char *mask)
|
||||||
|
{
|
||||||
|
#ifdef NONET
|
||||||
|
(void)address;
|
||||||
|
(void)mask;
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
struct my_addrinfo *ai, *runp, hints;
|
||||||
|
int gaie;
|
||||||
|
|
||||||
|
if (!address)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
memset(&hints, 0x00, sizeof(hints));
|
||||||
|
hints.ai_flags = 0;
|
||||||
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
hints.ai_socktype = SOCK_DGRAM;
|
||||||
|
hints.ai_protocol = IPPROTO_UDP;
|
||||||
|
|
||||||
|
gaie = I_getaddrinfo(address, "0", &hints, &ai);
|
||||||
|
if (gaie != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
runp = ai;
|
||||||
|
|
||||||
|
while (runp != NULL)
|
||||||
|
{
|
||||||
|
INT32 ban;
|
||||||
|
UINT8 numericalmask;
|
||||||
|
|
||||||
|
ban = numbans;
|
||||||
|
AddBannedIndex();
|
||||||
|
|
||||||
|
memcpy(&banned[ban].address, runp->ai_addr, runp->ai_addrlen);
|
||||||
|
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
if (runp->ai_family == AF_INET6)
|
||||||
|
banned[ban].mask = 128;
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
banned[ban].mask = 32;
|
||||||
|
|
||||||
|
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);
|
||||||
|
SOCK_SetBanReason(NULL);
|
||||||
|
SOCK_SetUnbanTime(NO_BAN_TIME);
|
||||||
|
|
||||||
|
runp = runp->ai_next;
|
||||||
|
}
|
||||||
|
|
||||||
|
I_freeaddrinfo(ai);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static void SOCK_ClearBans(void)
|
static void SOCK_ClearBans(void)
|
||||||
{
|
{
|
||||||
numbans = 0;
|
numbans = 0;
|
||||||
|
|
Loading…
Reference in a new issue