From f39bd03e10523a0d25bfbfefcfcf31c4377bad95 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Mon, 18 Feb 2019 00:58:08 -0500 Subject: [PATCH 1/4] Add command to ban an IP address. --- src/d_clisrv.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 7516df2e..7be04682 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2756,6 +2756,32 @@ static void Command_Ban(void) } +static void Command_BanIP(void) +{ + if (COM_Argc() < 2) + { + CONS_Printf(M_GetText("banip : ban an ip address\n")); + return; + } + + if (server) // Only the server can use this, otherwise does nothing. + { + const char *address = (COM_Argv(1)); + const char *reason = (COM_Argv(2)); + + if (I_SetBanAddress && I_SetBanAddress(address, NULL)) + { + CONS_Printf("Banned ip address for:%s\n", reason); + Ban_Add(reason); + D_SaveBan(); + } + else + { + return; + } + } +} + static void Command_Kick(void) { if (COM_Argc() < 2) @@ -3062,6 +3088,7 @@ void D_ClientServerInit(void) COM_AddCommand("getplayernum", Command_GetPlayerNum); COM_AddCommand("kick", Command_Kick); COM_AddCommand("ban", Command_Ban); + COM_AddCommand("banip", Command_BanIP); COM_AddCommand("clearbans", Command_ClearBans); COM_AddCommand("showbanlist", Command_ShowBan); COM_AddCommand("reloadbans", Command_ReloadBan); From 69156054448f628ac1ed19bba4aa74e1f1627d29 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Mon, 18 Feb 2019 01:03:39 -0500 Subject: [PATCH 2/4] Save ban list right after banning. --- src/d_clisrv.c | 3 +++ src/djgppdos/i_system.c | 3 --- src/sdl/i_system.c | 3 --- src/sdl12/i_system.c | 3 --- src/win32/win_sys.c | 3 --- 5 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 7be04682..5ad2e92a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2725,7 +2725,10 @@ static void Command_Ban(void) else { if (server) // only the server is allowed to do this right now + { Ban_Add(COM_Argv(2)); + D_SaveBan(); // save the ban list + } if (COM_Argc() == 2) { diff --git a/src/djgppdos/i_system.c b/src/djgppdos/i_system.c index bc3c8b2b..5970f5ae 100644 --- a/src/djgppdos/i_system.c +++ b/src/djgppdos/i_system.c @@ -615,9 +615,6 @@ void I_Quit (void) //added:16-02-98: when recording a demo, should exit using 'q' key, // but sometimes we forget and use 'F10'.. so save here too. M_SaveConfig (NULL); //save game config, cvars.. -#ifndef NONET - D_SaveBan(); // save the ban list -#endif G_SaveGameData(); // Tails 12-08-2002 if (demorecording) G_CheckDemoStatus(); diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index f360072a..6d72d9bb 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -3054,9 +3054,6 @@ void I_Quit(void) quiting = SDL_FALSE; I_ShutdownConsole(); M_SaveConfig(NULL); //save game config, cvars.. -#ifndef NONET - D_SaveBan(); // save the ban list -#endif G_SaveGameData(false); // Tails 12-08-2002 //added:16-02-98: when recording a demo, should exit using 'q' key, // but sometimes we forget and use 'F10'.. so save here too. diff --git a/src/sdl12/i_system.c b/src/sdl12/i_system.c index d055a4ca..a841860f 100644 --- a/src/sdl12/i_system.c +++ b/src/sdl12/i_system.c @@ -2975,9 +2975,6 @@ void I_Quit(void) quiting = SDL_FALSE; I_ShutdownConsole(); M_SaveConfig(NULL); //save game config, cvars.. -#ifndef NONET - D_SaveBan(); // save the ban list -#endif G_SaveGameData(); // Tails 12-08-2002 //added:16-02-98: when recording a demo, should exit using 'q' key, // but sometimes we forget and use 'F10'.. so save here too. diff --git a/src/win32/win_sys.c b/src/win32/win_sys.c index fa9d6d64..47250334 100644 --- a/src/win32/win_sys.c +++ b/src/win32/win_sys.c @@ -639,9 +639,6 @@ void I_Error(const char *error, ...) if (!errorcount) { M_SaveConfig(NULL); // save game config, cvars.. -#ifndef NONET - D_SaveBan(); // save the ban list -#endif G_SaveGameData(); } From a2316389d2a169815181c98132d9b98262cc9c80 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Mon, 18 Feb 2019 02:04:58 -0500 Subject: [PATCH 3/4] Save when quitting the game. Also use default reason if not custom reason is given. --- src/d_clisrv.c | 14 ++++++++++++-- src/djgppdos/i_system.c | 3 +++ src/sdl/i_system.c | 3 +++ src/sdl12/i_system.c | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 5ad2e92a..ea8077d6 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2770,11 +2770,21 @@ static void Command_BanIP(void) if (server) // Only the server can use this, otherwise does nothing. { const char *address = (COM_Argv(1)); - const char *reason = (COM_Argv(2)); + const char *reason; + + if (COM_Argc() == 2) + reason = NULL; + else + reason = COM_Argv(2); + if (I_SetBanAddress && I_SetBanAddress(address, NULL)) { - CONS_Printf("Banned ip address for:%s\n", reason); + if (reason) + CONS_Printf("Banned ip address %s for: %s\n", address, reason); + else + CONS_Printf("Banned ip address %s\n", address); + Ban_Add(reason); D_SaveBan(); } diff --git a/src/djgppdos/i_system.c b/src/djgppdos/i_system.c index 5970f5ae..bc3c8b2b 100644 --- a/src/djgppdos/i_system.c +++ b/src/djgppdos/i_system.c @@ -615,6 +615,9 @@ void I_Quit (void) //added:16-02-98: when recording a demo, should exit using 'q' key, // but sometimes we forget and use 'F10'.. so save here too. M_SaveConfig (NULL); //save game config, cvars.. +#ifndef NONET + D_SaveBan(); // save the ban list +#endif G_SaveGameData(); // Tails 12-08-2002 if (demorecording) G_CheckDemoStatus(); diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 6d72d9bb..f360072a 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -3054,6 +3054,9 @@ void I_Quit(void) quiting = SDL_FALSE; I_ShutdownConsole(); M_SaveConfig(NULL); //save game config, cvars.. +#ifndef NONET + D_SaveBan(); // save the ban list +#endif G_SaveGameData(false); // Tails 12-08-2002 //added:16-02-98: when recording a demo, should exit using 'q' key, // but sometimes we forget and use 'F10'.. so save here too. diff --git a/src/sdl12/i_system.c b/src/sdl12/i_system.c index a841860f..d055a4ca 100644 --- a/src/sdl12/i_system.c +++ b/src/sdl12/i_system.c @@ -2975,6 +2975,9 @@ void I_Quit(void) quiting = SDL_FALSE; I_ShutdownConsole(); M_SaveConfig(NULL); //save game config, cvars.. +#ifndef NONET + D_SaveBan(); // save the ban list +#endif G_SaveGameData(); // Tails 12-08-2002 //added:16-02-98: when recording a demo, should exit using 'q' key, // but sometimes we forget and use 'F10'.. so save here too. From 0913a623fb35e6073773fc3e5ba7034fdfbfbff3 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Tue, 19 Feb 2019 21:22:35 -0500 Subject: [PATCH 4/4] Some small changes. --- src/d_clisrv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index ea8077d6..2054d166 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2781,9 +2781,9 @@ static void Command_BanIP(void) if (I_SetBanAddress && I_SetBanAddress(address, NULL)) { if (reason) - CONS_Printf("Banned ip address %s for: %s\n", address, reason); + CONS_Printf("Banned IP address %s for: %s\n", address, reason); else - CONS_Printf("Banned ip address %s\n", address); + CONS_Printf("Banned IP address %s\n", address); Ban_Add(reason); D_SaveBan();