X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fcommand%2Fcommon.qh;h=27dd13a2d6f9c376aa950794616a3bdf55a1dbf0;hp=ac99e32dc46d2583a677e3d687d6a067dde510ee;hb=2f215c603bf1b4dd44b9d166180f535c88602e9f;hpb=b4a0a5ea0f964c0a88877d1903580684ce73f307 diff --git a/qcsrc/server/command/common.qh b/qcsrc/server/command/common.qh index ac99e32dc..27dd13a2d 100644 --- a/qcsrc/server/command/common.qh +++ b/qcsrc/server/command/common.qh @@ -1,10 +1,27 @@ -#ifndef COMMAND_COMMON_H -#define COMMAND_COMMON_H +#pragma once + +#include +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(commoncommand_##id this, 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 -#include "../../common/command/generic.qh" -#include "../../common/command/shared_defs.qh" +#include // ============================================================ // Shared declarations for server commands, written by Samual @@ -26,18 +43,18 @@ const float TIMEOUT_ACTIVE = 2; const float TIMEOUT_SLOWMO_VALUE = 0.0001; // global timeout information declarations -entity timeout_caller; // contains the entity of the player who started the last timeout -entity timeout_handler; // responsible for centerprinting the timeout countdowns and playing sounds -float sys_frametime; // gets initialised in worldspawn, saves the value from autocvar_sys_ticrate -float orig_slowmo; // contains the value of autocvar_slowmo so that, after timeout finished, it isn't set to slowmo 1 necessarily -float timeout_time; // contains the time in seconds that the active timeout has left -float timeout_leadtime; // contains the number of seconds left of the leadtime (before the timeout starts) -float timeout_status; // (values: 0, 1, 2) contains whether a timeout is not active (0), was called but still at leadtime (1) or is active (2) +entity timeout_caller; // contains the entity of the player who started the last timeout +entity timeout_handler; // responsible for centerprinting the timeout countdowns and playing sounds +float sys_frametime; // gets initialised in worldspawn, saves the value from autocvar_sys_ticrate +float orig_slowmo; // contains the value of autocvar_slowmo so that, after timeout finished, it isn't set to slowmo 1 necessarily +float timeout_time; // contains the time in seconds that the active timeout has left +float timeout_leadtime; // contains the number of seconds left of the leadtime (before the timeout starts) +float timeout_status; // (values: 0, 1, 2) contains whether a timeout is not active (0), was called but still at leadtime (1) or is active (2) .float allowed_timeouts; // contains the number of allowed timeouts for each player -.vector lastV_angle; //used when pausing the game in order to force the player to keep his old view angle fixed +.vector lastV_angle; // used when pausing the game in order to force the player to keep his old view angle fixed // allow functions to be used in other code like g_world.qc and teamplay.qc -void timeout_handler_think(); +void timeout_handler_think(entity this); // used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file void CommonCommand_macro_write_aliases(float fh); @@ -59,7 +76,7 @@ float VerifyClientEntity(entity client, float must_be_real, float must_be_bots); // if the client is not acceptable, return a string to be used for error messages string GetClientErrorString_color(float clienterror, string original_input, string col); -#define GetClientErrorString(clienterror,original_input) GetClientErrorString_color(clienterror,original_input,"^7") +#define GetClientErrorString(clienterror, original_input) GetClientErrorString_color(clienterror, original_input, "^7") // is this entity number even in the possible range of entities? float VerifyClientNumber(float tmp_number); @@ -80,9 +97,9 @@ void print_to(entity to, string input); // ========================================== // used by CommonCommand_timeout() and CommonCommand_timein() to handle game pausing and messaging and such. -void timeout_handler_reset(); +void timeout_handler_reset(entity this); -void timeout_handler_think(); +void timeout_handler_think(entity this); // =================================================== // Common commands used in both sv_cmd.qc and cmd.qc @@ -92,6 +109,8 @@ void CommonCommand_cvar_changes(float request, entity caller); void CommonCommand_cvar_purechanges(float request, entity caller); +void CommonCommand_editmob(float request, entity caller, float argc); + void CommonCommand_info(float request, entity caller, float argc); void CommonCommand_ladder(float request, entity caller); @@ -120,66 +139,48 @@ 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("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 - - return; + FOREACH(COMMON_COMMANDS, true, LAMBDA(print_to(caller, sprintf(" ^2%s^7: %s", 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(it, 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(it, 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 - - return; + FOREACH(COMMON_COMMANDS, true, LAMBDA(CMD_Write_Alias("qc_cmd_svcmd", it.m_name, it.m_description))); } - - -#endif