]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Sandbox: fix some warnings and add useful mutator hooks
authorMario <mario.mario@y7mail.com>
Thu, 25 Jul 2024 13:18:22 +0000 (13:18 +0000)
committerDr. Jaska <drjaska83@gmail.com>
Thu, 25 Jul 2024 13:18:22 +0000 (13:18 +0000)
qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qc
qcsrc/server/mutators/events.qh

index a387af90f1d58f2d6b098a279603e7e9c2e6c279..076378f725ca066ba0f433e3d55fed13d841974d 100644 (file)
@@ -68,7 +68,7 @@ void sandbox_ObjectFunction_Touch(entity this, entity toucher)
 void sandbox_ObjectFunction_Think(entity this)
 {
        // decide if and how this object can be grabbed
-       if(autocvar_g_sandbox_readonly)
+       if(autocvar_g_sandbox_readonly || MUTATOR_CALLHOOK(Sandbox_DragAllowed, this))
                this.grab = 0; // no grabbing
        else if(autocvar_g_sandbox_editor_free < 2 && this.crypto_idfp)
                this.grab = 1; // owner only
@@ -353,7 +353,7 @@ entity sandbox_ObjectPort_Load(entity this, string s, float database)
                        parent = e; // mark parent objects as such
                }
                // properties stored for all objects
-               SANDBOX_GETARG; _setmodel(e, arg);
+               SANDBOX_GETARG; precache_model(arg); _setmodel(e, arg);
                SANDBOX_GETARG; e.skin = stof(arg);
                SANDBOX_GETARG; e.alpha = stof(arg);
                SANDBOX_GETARG; e.colormod = stov(arg);
@@ -389,6 +389,9 @@ entity sandbox_ObjectPort_Load(entity this, string s, float database)
 
 void sandbox_Database_Save()
 {
+       if(MUTATOR_CALLHOOK(Sandbox_SaveAllowed))
+               return;
+
        // saves all objects to the database file
        string file_name;
        float file_get;
@@ -418,6 +421,7 @@ void sandbox_Database_Load()
        {
                if(autocvar_g_sandbox_info > 0)
                        LOG_INFO("^3SANDBOX - SERVER: ^7could not find storage file ^3", file_name, "^7, no objects were loaded");
+               return;
        }
        else
        {
@@ -458,7 +462,7 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand)
 
        if(cmd_name == "g_sandbox")
        {
-               if(autocvar_g_sandbox_readonly)
+               if(autocvar_g_sandbox_readonly || MUTATOR_CALLHOOK(Sandbox_EditAllowed, player))
                {
                        print_to(player, "^2SANDBOX - INFO: ^7Sandbox mode is active, but in read-only mode. Sandbox commands cannot be used");
                        return true;
@@ -531,6 +535,7 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand)
                                }
 
                                e = sandbox_ObjectSpawn(player, false);
+                               precache_model(argv(2));
                                _setmodel(e, argv(2));
 
                                if(autocvar_g_sandbox_info > 0)
index 6dff49f8b62cc9f8438330fbe0cd4b39a927f1e5..0022605caeed1ce8b5e0fd6f1c3533317d214cf6 100644 (file)
@@ -1280,3 +1280,18 @@ MUTATOR_HOOKABLE(AllowRocketJumping, EV_AllowRocketJumping);
     /** player */ i(entity, MUTATOR_ARGV_0_entity) \
     /**/
 MUTATOR_HOOKABLE(W_PlayStrengthSound, EV_W_PlayStrengthSound);
+
+/** Return true to prevent sandbox objects from being dragged */
+#define EV_Sandbox_DragAllowed(i, o) \
+    /** object */ i(entity, MUTATOR_ARGV_0_entity) \
+    /**/
+MUTATOR_HOOKABLE(Sandbox_DragAllowed, EV_Sandbox_DragAllowed);
+
+/** Return true to prevent writing sandbox changes to storage */
+MUTATOR_HOOKABLE(Sandbox_SaveAllowed, EV_NO_ARGS);
+
+/** Return true to prevent the player from editing sandbox objects with commands */
+#define EV_Sandbox_EditAllowed(i, o) \
+    /** player */ i(entity, MUTATOR_ARGV_0_entity) \
+    /**/
+MUTATOR_HOOKABLE(Sandbox_EditAllowed, EV_Sandbox_EditAllowed);