]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Allow mutators to define menu commands
authorTimePath <andrew.hardaker1995@gmail.com>
Tue, 25 Aug 2015 22:54:10 +0000 (08:54 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Tue, 25 Aug 2015 22:54:10 +0000 (08:54 +1000)
qcsrc/client/command/cl_cmd.qc
qcsrc/client/mutators/events.qh
qcsrc/common/mutators/events.qh
qcsrc/menu/command/menu_cmd.qc
qcsrc/menu/progs.src
qcsrc/server/mutators/events.qh

index 9fe33a4fc00cf06d88bc51a93c45d1a20c5f72b0..d153dd52b6fd1b3b0f81c8410fd309b776ed4b00 100644 (file)
@@ -555,7 +555,7 @@ void GameCommand(string command)
        // continue as usual and scan for normal commands
        if (GenericCommand(command)// handled by common/command/generic.qc
        || LocalCommand_macro_command(argc) // handled by one of the above LocalCommand_* functions
-       || MUTATOR_CALLHOOK(CSQC_ConsoleCommand, s, argc, command) // handled by a mutator
+       || MUTATOR_CALLHOOK(GameCommand, s, argc, command) // handled by a mutator
        ) return;
 
        // nothing above caught the command, must be invalid
index 16ae922f220ba774fb3dfdc892eb411de9b89da1..026f4bd7490f60971c04281eb5f9c6a4066f5b77 100644 (file)
@@ -3,38 +3,6 @@
 
 #include "../../common/mutators/base.qh"
 
-// globals
-
-string cmd_name;
-int cmd_argc;
-string cmd_string;
-
-/**
- * Called when a client command is parsed
- * NOTE: hooks MUST start with if (MUTATOR_RETURNVALUE) return false;
- * NOTE: return true if you handled the command, return false to continue handling
- * NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
- * // example:
- * MUTATOR_HOOKFUNCTION(foo, CSQC_ConsoleCommand) {
- *     if (MUTATOR_RETURNVALUE) return false; // command was already handled
- *     if (cmd_name == "echocvar" && cmd_argc >= 2) {
- *         print(cvar_string(argv(1)), "\n");
- *         return true;
- *     }
- *     if (cmd_name == "echostring" && cmd_argc >= 2) {
- *         print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
- *         return true;
- *     }
- *     return false;
- * }
- */
-#define EV_CSQC_ConsoleCommand(i, o) \
-    /** command name */ i(string, cmd_name) \
-    /** also, argv() can be used */ i(int, cmd_argc) \
-    /** whole command, use only if you really have to */ i(string, cmd_string) \
-    /**/
-MUTATOR_HOOKABLE(CSQC_ConsoleCommand, EV_CSQC_ConsoleCommand);
-
 /* Called when the crosshair is being updated */
 MUTATOR_HOOKABLE(UpdateCrosshair, EV_NO_ARGS);
 
index eb46486b6b8e6ca4a00ed7f4fedcd6fee7990c37..12984a924b2bb0c17ed009f31eea71ac7eaf8fd4 100644 (file)
@@ -39,4 +39,34 @@ MUTATOR_HOOKABLE(BuildMutatorsString, EV_BuildMutatorsString);
     /**/
 MUTATOR_HOOKABLE(BuildMutatorsPrettyString, EV_BuildMutatorsPrettyString);
 
+string cmd_name;
+int cmd_argc;
+string cmd_string;
+
+/**
+ * Called when a game command is parsed
+ * NOTE: hooks MUST start with if (MUTATOR_RETURNVALUE) return false;
+ * NOTE: return true if you handled the command, return false to continue handling
+ * NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
+ * // example:
+ * MUTATOR_HOOKFUNCTION(foo, GameCommand) {
+ *     if (MUTATOR_RETURNVALUE) return false; // command was already handled
+ *     if (cmd_name == "echocvar" && cmd_argc >= 2) {
+ *         print(cvar_string(argv(1)), "\n");
+ *         return true;
+ *     }
+ *     if (cmd_name == "echostring" && cmd_argc >= 2) {
+ *         print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
+ *         return true;
+ *     }
+ *     return false;
+ * }
+ */
+#define EV_GameCommand(i, o) \
+    /** command name */ i(string, cmd_name) \
+    /** also, argv() can be used */ i(int, cmd_argc) \
+    /** whole command, use only if you really have to */ i(string, cmd_string) \
+    /**/
+MUTATOR_HOOKABLE(GameCommand, EV_GameCommand);
+
 #endif
index 3f3f72f5753f61a291966d325f64ea0481d53bd3..b03a9f6cc8a857aff404eff3d6463a6f362eaf72 100644 (file)
@@ -36,10 +36,10 @@ void _dumptree_close(entity pass, entity me)
 
 float updateConwidths(float width, float height, float pixelheight);
 
-void GameCommand(string theCommand)
+void GameCommand(string command)
 {
-       float argc;
-       argc = tokenize_console(theCommand);
+       int argc = tokenize_console(command);
+       string s = strtolower(argv(0));
 
        if(argv(0) == "help" || argc == 0)
        {
@@ -53,7 +53,7 @@ void GameCommand(string theCommand)
                return;
        }
 
-       if(GenericCommand(theCommand))
+       if(GenericCommand(command))
                return;
 
        if(argv(0) == "sync")
@@ -130,5 +130,7 @@ void GameCommand(string theCommand)
                return;
        }
 
+       if (MUTATOR_CALLHOOK(GameCommand, s, argc, command)) return; // handled by a mutator
+
        print(_("Invalid command. For a list of supported commands, try menu_cmd help.\n"));
 }
index 2bde451f8dc381aa80209319872bda56b69427be..d1d2a226269a5904020b0e0b92cb112e30da8bb3 100644 (file)
@@ -24,6 +24,7 @@ xonotic/util.qc
 
 ../common/items/all.qc
 ../common/monsters/all.qc
+../common/mutators/all.qc
 ../common/vehicles/all.qc
 ../common/weapons/all.qc
 
index 71542d543646272a29184fefad9194f175e475f3..14de9f3ab933398ea3c2ededca48f3da3e515fb8 100644 (file)
@@ -347,38 +347,8 @@ MUTATOR_HOOKABLE(PlayerRegen, EV_PlayerRegen);
  */
 MUTATOR_HOOKABLE(PlayerUseKey, EV_NO_ARGS);
 
-/**
- * called when a client command is parsed
- * NOTE: hooks MUST start with if (MUTATOR_RETURNVALUE) return false;
- * NOTE: return true if you handled the command, return false to continue handling
- * NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
- * // example:
- * MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
- * {
- *     if (MUTATOR_RETURNVALUE) // command was already handled?
- *         return false;
- *     if (cmd_name == "echocvar" && cmd_argc >= 2)
- *     {
- *         print(cvar_string(argv(1)), "\n");
- *         return true;
- *     }
- *     if (cmd_name == "echostring" && cmd_argc >= 2)
- *     {
- *         print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
- *         return true;
- *     }
- *     return false;
- * }
- */
-#define EV_SV_ParseClientCommand(i, o) \
-    /** command name */ i(string, cmd_name) \
-    /** also, argv() can be used */ i(int, cmd_argc) \
-    /** whole command, use only if you really have to */ i(string, cmd_string) \
-    /**/
-string cmd_name;
-int cmd_argc;
-string cmd_string;
-MUTATOR_HOOKABLE(SV_ParseClientCommand, EV_SV_ParseClientCommand);
+/** Called when a client command is parsed, same structure as GameCommand */
+MUTATOR_HOOKABLE(SV_ParseClientCommand, EV_GameCommand);
 
 /**
  * called when a spawnpoint is being evaluated