From f4362e4a0c4ef6c943d801a0d7364c1fe8a3e853 Mon Sep 17 00:00:00 2001
From: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Date: Sun, 6 Nov 2011 15:17:21 +0200
Subject: [PATCH] Flood protection of object spawning and pasting. Defaulted to
 1 second

---
 defaultXonotic.cfg               |  1 +
 qcsrc/server/autocvars.qh        |  1 +
 qcsrc/server/mutators/sandbox.qc | 15 ++++++++++++++-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg
index 78a228581..c5d5e24b9 100644
--- a/defaultXonotic.cfg
+++ b/defaultXonotic.cfg
@@ -552,6 +552,7 @@ set g_sandbox_info 1 "print object information to the server. 1 prints info abou
 set g_sandbox_storage_name default "name of the selected storage to use"
 set g_sandbox_storage_autosave 5 "storage is automatically saved every specified number of seconds"
 set g_sandbox_storage_autoload 1 "if a storage file exists for the given map, automatically load it at startup"
+set g_sandbox_editor_flood 1 "players must wait this many seconds between spawning objects"
 set g_sandbox_editor_maxobjects 1000 "maximum number of objects that may exist at a time"
 set g_sandbox_editor_free 1 "0 = players can only copy or edit their own objects, 1 = players can copy but not edit other objects, 2 = players can copy and edit all object"
 set g_sandbox_editor_distance_spawn 200 "distance at which objects spawn in front of the player"
diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh
index 38c11fc4f..12952390b 100644
--- a/qcsrc/server/autocvars.qh
+++ b/qcsrc/server/autocvars.qh
@@ -1209,6 +1209,7 @@ float autocvar_g_sandbox_info;
 string autocvar_g_sandbox_storage_name;
 float autocvar_g_sandbox_storage_autosave;
 float autocvar_g_sandbox_storage_autoload;
+float autocvar_g_sandbox_editor_flood;
 float autocvar_g_sandbox_editor_maxobjects;
 float autocvar_g_sandbox_editor_free;
 float autocvar_g_sandbox_editor_distance_spawn;
diff --git a/qcsrc/server/mutators/sandbox.qc b/qcsrc/server/mutators/sandbox.qc
index 2f33f841c..1700964e4 100644
--- a/qcsrc/server/mutators/sandbox.qc
+++ b/qcsrc/server/mutators/sandbox.qc
@@ -1,5 +1,6 @@
 const float MAX_STORAGE_ATTACHMENTS = 16;
 float object_count;
+.float object_flood;
 .entity object_attach;
 .string material;
 
@@ -443,6 +444,12 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
 
 			// ---------------- COMMAND: OBJECT, SPAWN ----------------
 			case "object_spawn":
+				if(time < self.object_flood)
+				{
+					print_to(self, strcat("^1SANDBOX - WARNING: ^7Flood protection active. Please wait ^3", ftos(self.object_flood - time), " ^7seconds beofore spawning another object"));
+					return TRUE;
+				}
+				self.object_flood = time + autocvar_g_sandbox_editor_flood;
 				if(object_count >= autocvar_g_sandbox_editor_maxobjects)
 				{
 					print_to(self, strcat("^1SANDBOX - WARNING: ^7Cannot spawn any more objects. Up to ^3", ftos(autocvar_g_sandbox_editor_maxobjects), " ^7objects may exist at a time"));
@@ -453,7 +460,7 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
 					print_to(self, "^1SANDBOX - WARNING: ^7Attempted to spawn an object without specifying a model. Please specify the path to your model file after the 'object_spawn' command");
 					return TRUE;
 				}
-				else if not(fexists(argv(2)))
+				if not(fexists(argv(2)))
 				{
 					print_to(self, "^1SANDBOX - WARNING: ^7Attempted to spawn an object with a non-existent model. Make sure the path to your model file is correct");
 					return TRUE;
@@ -501,6 +508,12 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
 
 					case "paste":
 						// spawns a new object using the properties in the player's clipboard cvar
+						if(time < self.object_flood)
+						{
+							print_to(self, strcat("^1SANDBOX - WARNING: ^7Flood protection active. Please wait ^3", ftos(self.object_flood - time), " ^7seconds beofore spawning another object"));
+							return TRUE;
+						}
+						self.object_flood = time + autocvar_g_sandbox_editor_flood;
 						if(!argv(3)) // no object in clipboard
 						{
 							print_to(self, "^1SANDBOX - WARNING: ^7No object in clipboard. You must copy an object before you can paste it");
-- 
2.39.5