# HG changeset patch
# User Binary Code
# Date 1706133084 28800
#      Wed Jan 24 13:51:24 2024 -0800
# Node ID 5f09e8cada6ac37390658c0b9e1788f81aee828d
# 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 5f09e8cada6a docs/zandronum-history.txt
--- a/docs/zandronum-history.txt	Mon Nov 27 18:34:26 2023 -0500
+++ b/docs/zandronum-history.txt	Wed Jan 24 13:51:24 2024 -0800
@@ -20,6 +20,7 @@
 *+	- Added support for custom vote types using the new VOTEINFO lump. [Dusk]
 *+	- Added support for voice chat. Audio is encoded and decoded using Opus, allowing it to be transmitted over the network with minimal bandwidth usage and decent quality. Any unwanted noise in the audio is also removed with RNNoise before it's sent to the server. [Kaminsky]
 +	- Added the +NOMORPHLIMITATIONS flag, allowing morphs to switch weapons, play sounds, and be affected by speed powerups. [geNia/Binary]
++	- Added the BanFromGame ACS function, allowing mods to give timed bans to players if sv_allowacsbanfunction is set to true. [Binary]
 +	- Added CVars: "con_interpolate" and "con_speed" which interpolates and controls how fast the console moves. Based on featues from ZCC. [Kaminsky]
 +	- Added ACS functions: "GetCurrentMapPosition", "GetEventResult", "GetActorSectorLocation", and "ChangeTeamScore". [Kaminsky]
 +	- Added an optional parameter to the ACS function GetChatMessage to let color codes to stay in chat messages. [Kaminsky]
diff -r 66e32614ce36 -r 5f09e8cada6a src/c_cmds.cpp
--- a/src/c_cmds.cpp	Mon Nov 27 18:34:26 2023 -0500
+++ b/src/c_cmds.cpp	Wed Jan 24 13:51:24 2024 -0800
@@ -101,6 +101,9 @@
 CVAR (Bool, sv_logfilenametimestamp, true, CVAR_ARCHIVE)
 CVAR (Bool, sv_logfile_append, false, CVAR_ARCHIVE)
 
+// [Binary] Allow mods to use the BanFromGame function.
+CVAR (Bool, sv_allowacsbanfunction, true, CVAR_SERVERINFO | CVAR_NOSETBYACS)
+
 CCMD (toggleconsole)
 {
 	C_ToggleConsole();
diff -r 66e32614ce36 -r 5f09e8cada6a src/p_acs.cpp
--- a/src/p_acs.cpp	Mon Nov 27 18:34:26 2023 -0500
+++ b/src/p_acs.cpp	Wed Jan 24 13:51:24 2024 -0800
@@ -95,6 +95,9 @@
 
 #include "g_shared/a_pickups.h"
 
+// [Binary] New #includes.
+#include "sv_ban.h"
+
 // [BB] A std::pair inside TArray inside TArray didn't seem to work.
 std::vector<TArray<std::pair<FString, FString> > > g_dbQueries;
 
@@ -5403,12 +5406,16 @@
 	ACSF_LumpReadGlobal,
 	ACSF_LumpGetInfo,
 	ACSF_LumpClose,
+	ACSF_BanFromGame, // [Binary] Added BanFromGame to function set.
 
 	// ZDaemon
 	ACSF_GetTeamScore = 19620,	// (int team)
 	ACSF_SetTeamScore,			// (int team, int value)
 };
 
+// [Binary] Define the CVar BanFromGame relies on.
+EXTERN_CVAR (Bool, sv_allowacsbanfunction)
+
 int DLevelScript::SideFromID(int id, int side)
 {
 	if (side != 0 && side != 1) return -1;
@@ -8289,6 +8296,25 @@
 			break;
 		}
 
+		// [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;
+				} else return 0;
+			} else return 0;
+			break;
+		}
+
 		default:
 			break;
 	}
