#include "../mapvoting.qh"
#include "../miscfunctions.qh"
+#include "../mutators/events.qh"
+
#include "../../common/mapinfo.qh"
#include "../../common/command/generic.qh"
// argc: 1 - 2 - 3 - 4
// argv: 0 - 1 - 2 - 3
// cmd vote - master - login - password
-
- if(strtolower(argv(0)) == "help")
+ string s = strtolower(argv(0));
+ if (s == "help")
{
if(argc == 1)
{
return;
}
}
- else if(GenericCommand(command))
- {
- return; // handled by common/command/generic.qc
- }
- else if(LocalCommand_macro_command(argc)) // continue as usual and scan for normal commands
- {
- return; // handled by one of the above LocalCommand_* functions
- }
+ // 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
+ ) return;
// nothing above caught the command, must be invalid
print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
#ifndef CAMERATEST
}
#endif
-
- return;
}
-bool ConsoleCommand_macro_normal(int argc)
+bool ConsoleCommand_macro_normal(string s, int argc)
{
#define CONSOLE_COMMAND(name,execution) \
- { if(name == strtolower(argv(0))) { { execution } return true; } }
+ { if (name == s) { { execution } return true; } }
CONSOLE_COMMANDS_NORMAL();
#undef CONSOLE_COMMAND
return false;
}
-bool ConsoleCommand_macro_movement(int argc)
+bool ConsoleCommand_macro_movement(string s, int argc)
{
if(camera_active)
{
#define CONSOLE_COMMAND(name,execution) \
- { if(name == strtolower(argv(0))) { { execution } return true; } }
+ { if (name == s) { { execution } return true; } }
CONSOLE_COMMANDS_MOVEMENT();
#undef CONSOLE_COMMAND
bool CSQC_ConsoleCommand(string command)
{
int argc = tokenize_console(command);
-
- if(ConsoleCommand_macro_normal(argc))
- {
- return true;
- }
- else if(ConsoleCommand_macro_movement(argc))
- {
- return true;
- }
-
- // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
-
- return false;
+ string s = strtolower(argv(0));
+ // Return value should be true if CSQC handled the command, otherwise return false to have the engine handle it.
+ return (ConsoleCommand_macro_normal(s, argc)
+ || ConsoleCommand_macro_movement(s, argc)
+ );
}
--- /dev/null
+#ifndef CLIENT_MUTATORS_EVENTS_H
+#define CLIENT_MUTATORS_EVENTS_H
+
+#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);
+
+#endif