First commit with actual human testing involved.

* Fix some bugs.
    * Reset bannode information properly, fixing being unable to join your own server.
    * Write to the buffer before saving the kick/ban reason, rather than after.
* Improve the print output for the `showbanlist` command.
    * Includes username.
    * Includes remaining time as seen by a kicked joiner.
    * Hides expired bans.
* Improve the messages for ban/kick related refused joins.
    * Replace the Reason with the actual admin-provided reason for refused connection.
    * Replace the "Server refuses connection" header with "You have been [banned/temporarily kicked] from the server", the previous given Reason.
    * Fudge the time reported for temporary kicks so that a user is encouraged to return slightly after their tempkick ends, rather than before.
* Add an extra newline to the M_StartMessage for being kicked/banned with a reason provided.
This commit is contained in:
toaster 2022-06-15 16:56:22 +01:00
parent 40f7be7676
commit 3498f1cff1

View file

@ -2642,7 +2642,9 @@ static void CL_ConnectToServer(void)
static void Command_ShowBan(void) //Print out ban list static void Command_ShowBan(void) //Print out ban list
{ {
size_t i; size_t i;
const char *address, *mask, *reason; const char *address, *mask, *reason, *username;
time_t unbanTime = NO_BAN_TIME;
const time_t curTime = time(NULL);
if (I_GetBanAddress) if (I_GetBanAddress)
CONS_Printf(M_GetText("Ban List:\n")); CONS_Printf(M_GetText("Ban List:\n"));
@ -2651,22 +2653,43 @@ static void Command_ShowBan(void) //Print out ban list
for (i = 0; (address = I_GetBanAddress(i)) != NULL; i++) for (i = 0; (address = I_GetBanAddress(i)) != NULL; i++)
{ {
if (!I_GetBanMask || (mask = I_GetBanMask(i)) == NULL) unbanTime = NO_BAN_TIME;
CONS_Printf("%s: %s ", sizeu1(i+1), address); if (I_GetUnbanTime)
else unbanTime = I_GetUnbanTime(i);
CONS_Printf("%s: %s/%s ", sizeu1(i+1), address, mask);
if (I_GetUnbanTime && I_GetUnbanTime(i) != NO_BAN_TIME) if (unbanTime != NO_BAN_TIME && curTime >= unbanTime)
{ continue;
// todo: maybe try to actually print out the time remaining,
// and/or the datetime of the unbanning? CONS_Printf("%s: ", sizeu1(i+1));
CONS_Printf("(temporary) ");
} if (I_GetBanUsername && (username = I_GetBanUsername(i)) != NULL)
CONS_Printf("%s - ", username);
if (!I_GetBanMask || (mask = I_GetBanMask(i)) == NULL)
CONS_Printf("%s", address);
else
CONS_Printf("%s/%s", address, mask);
if (I_GetBanReason && (reason = I_GetBanReason(i)) != NULL) if (I_GetBanReason && (reason = I_GetBanReason(i)) != NULL)
CONS_Printf("(%s)\n", reason); CONS_Printf(" - %s", reason);
else
CONS_Printf("\n"); if (unbanTime != NO_BAN_TIME)
{
// these are fudged a little to match what a joiner sees
int minutes = ((unbanTime - curTime) + 30) / 60;
int hours = (minutes + 1) / 60;
int days = (hours + 1) / 24;
if (days)
CONS_Printf(" (%d day%s)", days, days > 1 ? "s" : "");
else if (hours)
CONS_Printf(" (%d hour%s)", hours, hours > 1 ? "s" : "");
else if (minutes)
CONS_Printf(" (%d minute%s)", minutes, minutes > 1 ? "s" : "");
else
CONS_Printf(" (<1 minute)");
}
CONS_Printf("\n");
} }
if (i == 0 && !address) if (i == 0 && !address)
@ -3428,6 +3451,11 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
msg = KICK_MSG_CON_FAIL; msg = KICK_MSG_CON_FAIL;
} }
if (msg == KICK_MSG_CUSTOM_BAN || msg == KICK_MSG_CUSTOM_KICK)
{
READSTRINGN(*p, reason, MAX_REASONLENGTH+1);
}
//CONS_Printf("\x82%s ", player_names[pnum]); //CONS_Printf("\x82%s ", player_names[pnum]);
// Save bans here. Used to be split between here and the actual command, depending on // Save bans here. Used to be split between here and the actual command, depending on
@ -3534,12 +3562,10 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
kickreason = KR_BAN; kickreason = KR_BAN;
break; break;
case KICK_MSG_CUSTOM_KICK: case KICK_MSG_CUSTOM_KICK:
READSTRINGN(*p, reason, MAX_REASONLENGTH+1);
HU_AddChatText(va("\x82*%s has been kicked (%s)", player_names[pnum], reason), false); HU_AddChatText(va("\x82*%s has been kicked (%s)", player_names[pnum], reason), false);
kickreason = KR_KICK; kickreason = KR_KICK;
break; break;
case KICK_MSG_CUSTOM_BAN: case KICK_MSG_CUSTOM_BAN:
READSTRINGN(*p, reason, MAX_REASONLENGTH+1);
HU_AddChatText(va("\x82*%s has been banned (%s)", player_names[pnum], reason), false); HU_AddChatText(va("\x82*%s has been banned (%s)", player_names[pnum], reason), false);
kickreason = KR_BAN; kickreason = KR_BAN;
break; break;
@ -3561,9 +3587,9 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
else if (msg == KICK_MSG_BANNED) else if (msg == KICK_MSG_BANNED)
M_StartMessage(M_GetText("You have been banned by the server\n\nPress ESC\n"), NULL, MM_NOTHING); M_StartMessage(M_GetText("You have been banned by the server\n\nPress ESC\n"), NULL, MM_NOTHING);
else if (msg == KICK_MSG_CUSTOM_KICK) else if (msg == KICK_MSG_CUSTOM_KICK)
M_StartMessage(va(M_GetText("You have been kicked\n(%s)\nPress ESC\n"), reason), NULL, MM_NOTHING); M_StartMessage(va(M_GetText("You have been kicked\n(%s)\n\nPress ESC\n"), reason), NULL, MM_NOTHING);
else if (msg == KICK_MSG_CUSTOM_BAN) else if (msg == KICK_MSG_CUSTOM_BAN)
M_StartMessage(va(M_GetText("You have been banned\n(%s)\nPress ESC\n"), reason), NULL, MM_NOTHING); M_StartMessage(va(M_GetText("You have been banned\n(%s)\n\nPress ESC\n"), reason), NULL, MM_NOTHING);
else else
M_StartMessage(M_GetText("You have been kicked by the server\n\nPress ESC\n"), NULL, MM_NOTHING); M_StartMessage(M_GetText("You have been kicked by the server\n\nPress ESC\n"), NULL, MM_NOTHING);
} }
@ -3782,6 +3808,8 @@ static void ResetNode(INT32 node)
nodewaiting[node] = 0; nodewaiting[node] = 0;
playerpernode[node] = 0; playerpernode[node] = 0;
sendingsavegame[node] = false; sendingsavegame[node] = false;
bannednode[node].banid = SIZE_MAX;
bannednode[node].timeleft = NO_BAN_TIME;
} }
void SV_ResetServer(void) void SV_ResetServer(void)
@ -4231,27 +4259,39 @@ static void HandleConnect(SINT8 node)
if (bannednode && bannednode[node].banid != SIZE_MAX) if (bannednode && bannednode[node].banid != SIZE_MAX)
{ {
const char *reason = NULL;
// Get the reason...
if (!I_GetBanReason || (reason = I_GetBanReason(bannednode[node].banid)) == NULL)
reason = "No reason given";
if (bannednode[node].timeleft != NO_BAN_TIME) if (bannednode[node].timeleft != NO_BAN_TIME)
{ {
int minutes = bannednode[node].timeleft / 60; // these are fudged a little to allow it to sink in for impatient rejoiners
int hours = minutes / 60; int minutes = (bannednode[node].timeleft + 30) / 60;
int hours = (minutes + 1) / 60;
int days = (hours + 1) / 24;
if (hours) if (days)
{ {
SV_SendRefuse(node, va(M_GetText("You have been temporarily\nkicked from the server.\n(Time remaining: %d hour%s)"), hours, hours > 1 ? "s" : "")); SV_SendRefuse(node, va("K|%s\n(Time remaining: %d day%s)", reason, days, days > 1 ? "s" : ""));
}
else if (hours)
{
SV_SendRefuse(node, va("K|%s\n(Time remaining: %d hour%s)", reason, hours, hours > 1 ? "s" : ""));
} }
else if (minutes) else if (minutes)
{ {
SV_SendRefuse(node, va(M_GetText("You have been temporarily\nkicked from the server.\n(Time remaining: %d minute%s)"), minutes, minutes > 1 ? "s" : "")); SV_SendRefuse(node, va("K|%s\n(Time remaining: %d minute%s)", reason, minutes, minutes > 1 ? "s" : ""));
} }
else else
{ {
SV_SendRefuse(node, M_GetText("You have been temporarily\nkicked from the server.\n(Time remaining: <1 minute)")); SV_SendRefuse(node, va("K|%s\n(Time remaining: <1 minute)", reason));
} }
} }
else else
{ {
SV_SendRefuse(node, M_GetText("You have been banned\nfrom the server.")); SV_SendRefuse(node, va("B|%s", reason));
} }
} }
else if (netbuffer->u.clientcfg._255 != 255 || else if (netbuffer->u.clientcfg._255 != 255 ||
@ -4526,8 +4566,17 @@ static void HandlePacketFromAwayNode(SINT8 node)
CL_Reset(); CL_Reset();
D_StartTitle(); D_StartTitle();
M_StartMessage(va(M_GetText("Server refuses connection\n\nReason:\n%s"), if (reason[1] == '|')
reason), NULL, MM_NOTHING); {
M_StartMessage(va("You have been %sfrom the server\n\nReason:\n%s",
(reason[0] == 'B') ? "banned\n" : "temporarily\nkicked ",
reason+2), NULL, MM_NOTHING);
}
else
{
M_StartMessage(va(M_GetText("Server refuses connection\n\nReason:\n%s"),
reason), NULL, MM_NOTHING);
}
free(reason); free(reason);