]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Common commands (client-server): register
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 6 Dec 2015 06:41:15 +0000 (17:41 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 6 Dec 2015 06:41:46 +0000 (17:41 +1100)
qcsrc/common/command/all.qh
qcsrc/common/command/command.qh
qcsrc/common/command/generic.qc
qcsrc/common/debug.qh
qcsrc/server/command/all.qh
qcsrc/server/command/common.qh
qcsrc/server/command/sv_cmd.qc

index 9e16238d17af8dea6150ee44c210229052ae5227..efe9f72684f8a554d65eab872dadea820bb1c16d 100644 (file)
@@ -13,7 +13,7 @@ REGISTRY_SORT(GENERIC_COMMANDS)
        ATTRIB(genericcommand_##id, m_description, string, description); \
        ENDCLASS(genericcommand_##id) \
     REGISTER(GENERIC_COMMANDS, CMD_G, id, m_id, NEW(genericcommand_##id)); \
-       METHOD(genericcommand_##id, m_invokecmd, void(int request, int arguments, string command))
+       METHOD(genericcommand_##id, m_invokecmd, void(int request, entity caller, int arguments, string command))
 
 STATIC_INIT(GENERIC_COMMANDS_aliases) {
        FOREACH(GENERIC_COMMANDS, true, LAMBDA(localcmd(sprintf("alias %1$s \"%2$s %1$s ${* ?}\"\n", it.m_name, "qc_cmd_svmenu"))));
index 31909549a68f82d1d39bfc348601961ab1ca8a48..beda2288c9ff97e9bc7ee2ad4fcdb2426b263b62 100644 (file)
@@ -7,7 +7,7 @@ const int CMD_REQUEST_USAGE = 2;
 CLASS(Command, Object)
        ATTRIB(Command, m_name, string, string_null);
        ATTRIB(Command, m_description, string, string_null);
-       METHOD(Command, m_invokecmd, void(int request, int arguments, string command)) { }
+       METHOD(Command, m_invokecmd, void(int request, entity caller, int arguments, string command)) { }
 ENDCLASS(Command)
 
 #endif
index 9a50894c04116d52427c33abe093a404ff2be72e..6fb73cf1e41295f8da2d811615fa02e54e4488e5 100644 (file)
@@ -559,7 +559,7 @@ float GenericCommand_macro_command(float argc, string command)
 {
        string c = strtolower(argv(0));
        FOREACH(GENERIC_COMMANDS, it.m_name == c, LAMBDA(
-               it.m_invokecmd(CMD_REQUEST_COMMAND, argc, command);
+               it.m_invokecmd(CMD_REQUEST_COMMAND, NULL, argc, command);
                return true;
        ));
        return false;
@@ -569,7 +569,7 @@ float GenericCommand_macro_usage(float argc)
 {
        string c = strtolower(argv(1));
        FOREACH(GENERIC_COMMANDS, it.m_name == c, LAMBDA(
-               it.m_invokecmd(CMD_REQUEST_USAGE, argc, "");
+               it.m_invokecmd(CMD_REQUEST_USAGE, NULL, argc, "");
                return true;
        ));
        return false;
index 5ead52479d9efda26f400c984c566edb1b23060e..c5345b32a33b4112a5aae9a49a37600290c69d4a 100644 (file)
@@ -81,7 +81,7 @@ bool autocvar_debugdraw;
 #endif
 
 #ifdef SVQC
-       GENERIC_COMMAND(debugdraw_sv, "Dump all server entities")
+       COMMON_COMMAND(debugdraw_sv, "Dump all server entities")
        {
                switch (request)
                {
index 301b90e8d14e1e3c72a801ecf18f77ff70fc951c..13bca963cc33a0937987914dee9767ce63273b4a 100644 (file)
@@ -13,7 +13,7 @@ REGISTRY_SORT(SERVER_COMMANDS)
        ATTRIB(servercommand_##id, m_description, string, description); \
        ENDCLASS(servercommand_##id) \
     REGISTER(SERVER_COMMANDS, CMD_SV, id, m_id, NEW(servercommand_##id)); \
-       METHOD(servercommand_##id, m_invokecmd, void(int request, int arguments, string command))
+       METHOD(servercommand_##id, m_invokecmd, void(int request, entity caller, int arguments, string command))
 
 STATIC_INIT(SERVER_COMMANDS_aliases) {
        FOREACH(SERVER_COMMANDS, true, LAMBDA(localcmd(sprintf("alias %1$s \"%2$s %1$s ${* ?}\"\n", it.m_name, "qc_cmd_svcmd"))));
index 2a1a2b42fd16d45008c89e2875617947f09bcd63..08b8b848fdd43e7cc1111e025609cc6d334e7648 100644 (file)
@@ -1,6 +1,24 @@
 #ifndef COMMAND_COMMON_H
 #define COMMAND_COMMON_H
 
+#include "../../common/command/command.qh"
+REGISTRY(COMMON_COMMANDS, BITS(7))
+#define COMMON_COMMANDS_from(i) _COMMON_COMMANDS_from(i, NULL)
+REGISTER_REGISTRY(COMMON_COMMANDS)
+REGISTRY_SORT(COMMON_COMMANDS)
+
+#define COMMON_COMMAND(id, description) \
+       CLASS(commoncommand_##id, Command) \
+               ATTRIB(commoncommand_##id, m_name, string, #id); \
+       ATTRIB(commoncommand_##id, m_description, string, description); \
+       ENDCLASS(commoncommand_##id) \
+    REGISTER(COMMON_COMMANDS, CMD_SV, id, m_id, NEW(commoncommand_##id)); \
+       METHOD(commoncommand_##id, m_invokecmd, void(int request, entity caller, int arguments, string command))
+
+STATIC_INIT(COMMON_COMMANDS_aliases) {
+       FOREACH(COMMON_COMMANDS, true, LAMBDA(localcmd(sprintf("alias %1$s \"%2$s %1$s ${* ?}\"\n", it.m_name, "qc_cmd_svcmd"))));
+}
+
 #include "vote.qh"
 #include "../../common/monsters/spawn.qh"
 
@@ -123,62 +141,50 @@ void CommonCommand_who(float request, entity caller, float argc);
 // ==================================
 
 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
-#define COMMON_COMMANDS(request, caller, arguments, command) \
-       COMMON_COMMAND("cvar_changes", CommonCommand_cvar_changes(request, caller), "Prints a list of all changed server cvars") \
-       COMMON_COMMAND("cvar_purechanges", CommonCommand_cvar_purechanges(request, caller), "Prints a list of all changed gameplay cvars") \
-       COMMON_COMMAND("editmob", CommonCommand_editmob(request, caller, arguments), "Modifies a monster or all monsters") \
-       COMMON_COMMAND("info", CommonCommand_info(request, caller, arguments), "Request for unique server information set up by admin") \
-       COMMON_COMMAND("ladder", CommonCommand_ladder(request, caller), "Get information about top players if supported") \
-       COMMON_COMMAND("lsmaps", CommonCommand_lsmaps(request, caller), "List maps which can be used with the current game mode") \
-       COMMON_COMMAND("printmaplist", CommonCommand_printmaplist(request, caller), "Display full server maplist reply") \
-       COMMON_COMMAND("rankings", CommonCommand_rankings(request, caller), "Print information about rankings") \
-       COMMON_COMMAND("records", CommonCommand_records(request, caller), "List top 10 records for the current map") \
-       COMMON_COMMAND("teamstatus", CommonCommand_teamstatus(request, caller), "Show information about player and team scores") \
-       COMMON_COMMAND("time", CommonCommand_time(request, caller), "Print different formats/readouts of time") \
-       COMMON_COMMAND("timein", CommonCommand_timein(request, caller), "Resume the game from being paused with a timeout") \
-       COMMON_COMMAND("timeout", CommonCommand_timeout(request, caller), "Call a timeout which pauses the game for certain amount of time unless unpaused") \
-       COMMON_COMMAND("vote", VoteCommand(request, caller, arguments, command), "Request an action to be voted upon by players") \
-       COMMON_COMMAND("who", CommonCommand_who(request, caller, arguments), "Display detailed client information about all players") \
-       /* nothing */
+COMMON_COMMAND(cvar_changes, "Prints a list of all changed server cvars") { CommonCommand_cvar_changes(request, caller); }
+COMMON_COMMAND(cvar_purechanges, "Prints a list of all changed gameplay cvars") { CommonCommand_cvar_purechanges(request, caller); }
+COMMON_COMMAND(editmob, "Modifies a monster or all monsters") { CommonCommand_editmob(request, caller, arguments); }
+COMMON_COMMAND(info, "Request for unique server information set up by admin") { CommonCommand_info(request, caller, arguments); }
+COMMON_COMMAND(ladder, "Get information about top players if supported") { CommonCommand_ladder(request, caller); }
+COMMON_COMMAND(lsmaps, "List maps which can be used with the current game mode") { CommonCommand_lsmaps(request, caller); }
+COMMON_COMMAND(printmaplist, "Display full server maplist reply") { CommonCommand_printmaplist(request, caller); }
+COMMON_COMMAND(rankings, "Print information about rankings") { CommonCommand_rankings(request, caller); }
+COMMON_COMMAND(records, "List top 10 records for the current map") { CommonCommand_records(request, caller); }
+COMMON_COMMAND(teamstatus, "Show information about player and team scores") { CommonCommand_teamstatus(request, caller); }
+COMMON_COMMAND(time, "Print different formats/readouts of time") { CommonCommand_time(request, caller); }
+COMMON_COMMAND(timein, "Resume the game from being paused with a timeout") { CommonCommand_timein(request, caller); }
+COMMON_COMMAND(timeout, "Call a timeout which pauses the game for certain amount of time unless unpaused") { CommonCommand_timeout(request, caller); }
+COMMON_COMMAND(vote, "Request an action to be voted upon by players") { VoteCommand(request, caller, arguments, command); }
+COMMON_COMMAND(who, "Display detailed client information about all players") { CommonCommand_who(request, caller, arguments);}
 
 void CommonCommand_macro_help(entity caller)
 {
-       #define COMMON_COMMAND(name, function, description) \
-               { print_to(caller, strcat("  ^2", name, "^7: ", description)); }
-
-       COMMON_COMMANDS(0, caller, 0, "");
-#undef COMMON_COMMAND
+       FOREACH(COMMON_COMMANDS, true, LAMBDA(print_to(caller, sprintf("  ^2%s^7: %s\n", it.m_name, it.m_description))));
 }
 
 float CommonCommand_macro_command(float argc, entity caller, string command)
 {
-       #define COMMON_COMMAND(name, function, description) \
-               { if (name == strtolower(argv(0))) { function; return true; } }
-
-       COMMON_COMMANDS(CMD_REQUEST_COMMAND, caller, argc, command);
-#undef COMMON_COMMAND
-
+       string c = strtolower(argv(0));
+       FOREACH(COMMON_COMMANDS, it.m_name == c, LAMBDA(
+               it.m_invokecmd(CMD_REQUEST_COMMAND, caller, argc, command);
+               return true;
+       ));
        return false;
 }
 
 float CommonCommand_macro_usage(float argc, entity caller)
 {
-       #define COMMON_COMMAND(name, function, description) \
-               { if (name == strtolower(argv(1))) { function; return true; } }
-
-       COMMON_COMMANDS(CMD_REQUEST_USAGE, caller, argc, "");
-#undef COMMON_COMMAND
-
+       string c = strtolower(argv(1));
+       FOREACH(COMMON_COMMANDS, it.m_name == c, LAMBDA(
+               it.m_invokecmd(CMD_REQUEST_USAGE, caller, argc, "");
+               return true;
+       ));
        return false;
 }
 
 void CommonCommand_macro_write_aliases(float fh)
 {
-       #define COMMON_COMMAND(name, function, description) \
-               { CMD_Write_Alias("qc_cmd_svcmd", name, description); }
-
-       COMMON_COMMANDS(0, world, 0, "");
-#undef COMMON_COMMAND
+       FOREACH(COMMON_COMMANDS, true, LAMBDA(CMD_Write_Alias("qc_cmd_svcmd", it.m_name, it.m_description)));
 }
 
 
index 7796dec686e50402f7fce9a4b7472d76fbcbda56..38e6222d6109131355521362eda560d4b2d32142 100644 (file)
@@ -1822,7 +1822,7 @@ float GameCommand_macro_command(float argc, string command)
 {
        string c = strtolower(argv(0));
        FOREACH(SERVER_COMMANDS, it.m_name == c, LAMBDA(
-               it.m_invokecmd(CMD_REQUEST_COMMAND, argc, command);
+               it.m_invokecmd(CMD_REQUEST_COMMAND, NULL, argc, command);
                return true;
        ));
        return false;
@@ -1832,7 +1832,7 @@ float GameCommand_macro_usage(float argc)
 {
        string c = strtolower(argv(1));
        FOREACH(SERVER_COMMANDS, it.m_name == c, LAMBDA(
-               it.m_invokecmd(CMD_REQUEST_USAGE, argc, "");
+               it.m_invokecmd(CMD_REQUEST_USAGE, NULL, argc, "");
                return true;
        ));
        return false;