# HG changeset patch
# User Binary Code
# Date 1706199794 28800
#      Thu Jan 25 08:23:14 2024 -0800
# Node ID 5e6b463fcca4681a5c679f28f4eddddb28ef35a4
# Parent  66e32614ce369e431701728be0512ef7a3e349e6
Add ACS function BanFromGame, and CVar sv_allowacsbanfunction, to allow mods to give timed bans to players if the CVar is enabled.

diff -r 66e32614ce36 -r 5e6b463fcca4 docs/zandronum-history.txt
--- a/docs/zandronum-history.txt	Mon Nov 27 18:34:26 2023 -0500
+++ b/docs/zandronum-history.txt	Thu Jan 25 08:23:14 2024 -0800
@@ -47,6 +47,7 @@
 +	- Added the forcerename and forcerename_idx CCMDs, which forcibly change a player's name to a random generic one. [DrinkyBird]
 +	- Added the GAMEEVENT_PLAYERLEAVESSERVER EVENT script type, which fires when a player disconnects from the server. [DrinkyBird]
 +	- Added the dmflag "sv_nospawntelefog", preventing teleport fog from spawning when a player does. [Kaminsky]
++	- Added the BanFromGame ACS function, allowing mods to give timed bans to players if sv_allowacsbanfunction is set to true. [Binary]
 -	- Fixed: clients didn't initialize a sector's friction properly in some cases due to a superfluous check that wasn't removed earlier. [Kaminsky]
 -	- Fixed: the server wouldn't initialize compatflags and compatflags2 properly if entered as command line parameters. [Kaminsky]
 -	- Fixed: serverinfo CVars entered on the command line were restored in reverse order. [Kaminsky]
diff -r 66e32614ce36 -r 5e6b463fcca4 src/p_acs.cpp
--- a/src/p_acs.cpp	Mon Nov 27 18:34:26 2023 -0500
+++ b/src/p_acs.cpp	Thu Jan 25 08:23:14 2024 -0800
@@ -92,12 +92,16 @@
 #include "chat.h"
 #include "maprotation.h"
 #include "scoreboard.h"
+#include "sv_ban.h"
 
 #include "g_shared/a_pickups.h"
 
 // [BB] A std::pair inside TArray inside TArray didn't seem to work.
 std::vector<TArray<std::pair<FString, FString> > > g_dbQueries;
 
+// [Binary] Allow mods to use the BanFromGame function.
+CVAR (Bool, sv_allowacsbanfunction, true, CVAR_SERVERINFO | CVAR_NOSETBYACS)
+
 //
 // [TP] Overridable system time property
 //
@@ -5403,6 +5407,7 @@
 	ACSF_LumpReadGlobal,
 	ACSF_LumpGetInfo,
 	ACSF_LumpClose,
+	ACSF_BanFromGame, // [Binary] Added BanFromGame to function set.
 
 	// ZDaemon
 	ACSF_GetTeamScore = 19620,	// (int team)
@@ -8275,6 +8280,25 @@
 				return 0;
 			}
 
+		// [Binary] Function to temporarily ban players, from 1-60 minutes.
+		case ACSF_BanFromGame:
+		{
+			// Only call the function on the server's end if ACS bans are allowed.
+			if ( NETWORK_GetState() == NETSTATE_SERVER && sv_allowacsbanfunction)
+			{
+				int playerIndex = args[0];
+				if(PLAYER_IsValidPlayer( playerIndex ))
+				{
+					int duration = clamp(args[1], 1, 60);
+					FString Output;
+					Output.Format("%dmin", duration);
+					SERVERBAN_BanPlayer( playerIndex, Output.GetChars( ), (argCount >= 3) ? FBehavior::StaticLookupString( args[2] ) : NULL);
+					return 1;
+				}
+			}
+			return 0;
+		}
+
 		case ACSF_GetActorFloorTexture:
 		{
 			auto a = SingleActorFromTID(args[0], activator);
