From b335141f208e550a760aa5fde4b8a563a3ede884 Mon Sep 17 00:00:00 2001 From: Samual Date: Wed, 28 Dec 2011 16:58:15 -0500 Subject: [PATCH] Add a generic command to dump all commands from a program into a file -- makes it incredibly useful for updating/maintaining commands.cfg file, just like the hud_config stuff --- qcsrc/client/command/cl_cmd.qc | 11 +++++ qcsrc/client/command/cl_cmd.qh | 5 +- qcsrc/common/command/generic.qc | 81 ++++++++++++++++++++++++++++++++- qcsrc/common/command/generic.qh | 7 ++- qcsrc/server/command/cmd.qc | 10 ++++ qcsrc/server/command/cmd.qh | 3 ++ qcsrc/server/command/common.qc | 11 +++++ qcsrc/server/command/common.qh | 5 +- qcsrc/server/command/sv_cmd.qc | 11 +++++ qcsrc/server/command/sv_cmd.qh | 3 ++ 10 files changed, 142 insertions(+), 5 deletions(-) diff --git a/qcsrc/client/command/cl_cmd.qc b/qcsrc/client/command/cl_cmd.qc index 9babf43db..f16de6ea3 100644 --- a/qcsrc/client/command/cl_cmd.qc +++ b/qcsrc/client/command/cl_cmd.qc @@ -342,6 +342,17 @@ float LocalCommand_macro_usage(float argc) return FALSE; } +void LocalCommand_macro_write_aliases(float fh) +{ + #define CLIENT_COMMAND(name,function,description) \ + { CMD_Write_Alias("cl_cmd", name, description); } + + CLIENT_COMMANDS(0, 0) + #undef CLIENT_COMMAND + + return; +} + // ========================================= // Main Function Called By Engine (cl_cmd) diff --git a/qcsrc/client/command/cl_cmd.qh b/qcsrc/client/command/cl_cmd.qh index 6e562af92..f2db76a2c 100644 --- a/qcsrc/client/command/cl_cmd.qh +++ b/qcsrc/client/command/cl_cmd.qh @@ -4,4 +4,7 @@ // ============================================== void Cmd_HUD_SetFields(float); -void Cmd_HUD_Help(); \ No newline at end of file +void Cmd_HUD_Help(); + +// used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file +void LocalCommand_macro_write_aliases(float fh); \ No newline at end of file diff --git a/qcsrc/common/command/generic.qc b/qcsrc/common/command/generic.qc index 61977f678..8508ef354 100644 --- a/qcsrc/common/command/generic.qc +++ b/qcsrc/common/command/generic.qc @@ -1,5 +1,5 @@ // ========================================================= -// Generic program common command code, reworked by Samual +// Generic program common command code, written by Samual // Last updated: December 28th, 2011 // ========================================================= @@ -56,6 +56,70 @@ void GenericCommand_addtolist(float request, float argc) } } +void GenericCommand_dumpcommands(float request) +{ + switch(request) + { + case CMD_REQUEST_COMMAND: + { + float fh; + string filename = strcat(GetProgramCommandPrefix(), "_dump.txt"); + fh = fopen(filename, FILE_WRITE); + + if(fh >= 0) + { +#ifdef SVQC + + // write sv_cmd aliases + CMD_Write("dump of server console commands:\n"); + GameCommand_macro_write_aliases(fh); + + // write client only aliases + CMD_Write("\ndump of networked client only commands:\n"); + ClientCommand_macro_write_aliases(fh); + + // write common aliases + CMD_Write("\ndump of common commands:\n"); + CommonCommand_macro_write_aliases(fh); + + // write ban aliases + CMD_Write("\ndump of ban commands:\n"); + +#endif + +#ifdef CSQC + + // write cl_cmd aliases + CMD_Write("dump of client commands:\n"); + LocalCommand_macro_write_aliases(fh); + +#endif + + // write generic commands + CMD_Write("\ndump of generic commands:\n"); + GenericCommand_macro_write_aliases(fh); + + print("Completed dump of aliases in ^2", GetProgramCommandPrefix(), "_dump.txt^7.\n"); + + fclose(fh); + } + else + { + print("^1Error: ^7Could not dump to file!\n"); + } + return; + } + + default: + case CMD_REQUEST_USAGE: + { + print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpcommands")); + print(" No arguments required.\n"); + return; + } + } +} + void GenericCommand_maplist(float request, float argc) { switch(request) @@ -132,6 +196,7 @@ void GenericCommand_maplist(float request, float argc) } default: + print("Incorrect parameters for ^2maplist^7\n"); case CMD_REQUEST_USAGE: { print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " maplist command [map]")); // todo @@ -210,7 +275,7 @@ void GenericCommand_(float request) default: case CMD_REQUEST_USAGE: { - print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " "))); + print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " ")); print(" No arguments required.\n"); return; } @@ -225,6 +290,7 @@ void GenericCommand_(float request) // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;) #define GENERIC_COMMANDS(request,arguments,command) \ GENERIC_COMMAND("addtolist", GenericCommand_addtolist(request, arguments), "Add a string to a cvar at the end of a list") \ + GENERIC_COMMAND("dumpcommands", GenericCommand_dumpcommands(request), "Dump all commands on the program to *_cmd_dump.txt") \ GENERIC_COMMAND("maplist", GenericCommand_maplist(request, arguments), "Automatic control of maplist") \ GENERIC_COMMAND("rpn", GenericCommand_rpn(request, arguments, command), "RPN calculator") \ GENERIC_COMMAND("settemp", GenericCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored later") \ @@ -263,6 +329,17 @@ float GenericCommand_macro_usage(float argc) return FALSE; } + +void GenericCommand_macro_write_aliases(float fh) +{ + #define GENERIC_COMMAND(name,function,description) \ + { CMD_Write_Alias("qc_cmd_svmenu", name, description); } + + GENERIC_COMMANDS(0, 0, "") + #undef GENERIC_COMMAND + + return; +} // =========================================== diff --git a/qcsrc/common/command/generic.qh b/qcsrc/common/command/generic.qh index 4533eb67b..3078a0f05 100644 --- a/qcsrc/common/command/generic.qh +++ b/qcsrc/common/command/generic.qh @@ -9,4 +9,9 @@ float GenericCommand(string command); // Returns command prefix specific for whatever program it is compiled in -string GetProgramCommandPrefix(void); \ No newline at end of file +string GetProgramCommandPrefix(void); + +// used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file +#define CMD_Write(s) fputs(fh, s) +#define CMD_Write_Alias(execute,command,description) CMD_Write(sprintf("alias %-20s \"%-13s %-20s ${* ?}\" // %s\n", command, execute, command, description)) +void GenericCommand_macro_write_aliases(float fh); \ No newline at end of file diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index 4ba8e1185..19be426d5 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -598,6 +598,16 @@ float ClientCommand_macro_usage(float argc) return FALSE; } +void ClientCommand_macro_write_aliases(float fh) +{ + #define CLIENT_COMMAND(name,function,description) \ + { CMD_Write_Alias("cmd", name, description); } + + CLIENT_COMMANDS(0, 0, "") + #undef CLIENT_COMMAND + + return; +} // ====================================== // Main Function Called By Engine (cmd) diff --git a/qcsrc/server/command/cmd.qh b/qcsrc/server/command/cmd.qh index 4a0d771e1..e64cbc267 100644 --- a/qcsrc/server/command/cmd.qh +++ b/qcsrc/server/command/cmd.qh @@ -9,3 +9,6 @@ .float checkfail; string MapVote_Suggest(string m); + +// used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file +void ClientCommand_macro_write_aliases(float fh); \ No newline at end of file diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index 821bf15c8..9247dffea 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -717,3 +717,14 @@ float CommonCommand_macro_usage(float argc) 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, 0, "") + #undef COMMON_COMMAND + + return; +} \ No newline at end of file diff --git a/qcsrc/server/command/common.qh b/qcsrc/server/command/common.qh index f11a25338..9f719892b 100644 --- a/qcsrc/server/command/common.qh +++ b/qcsrc/server/command/common.qh @@ -29,4 +29,7 @@ float timeout_status; // (values: 0, 1, 2) contains whether a timeout is not act .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(); \ No newline at end of file +void timeout_handler_think(); + +// used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file +void CommonCommand_macro_write_aliases(float fh); \ No newline at end of file diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index ec756d451..9f0dcdd1e 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -1711,6 +1711,17 @@ float GameCommand_macro_usage(float argc) return FALSE; } + +void GameCommand_macro_write_aliases(float fh) +{ + #define SERVER_COMMAND(name,function,description) \ + { CMD_Write_Alias("sv_cmd", name, description); } + + SERVER_COMMANDS(0, 0, "") + #undef SERVER_COMMAND + + return; +} // ========================================= diff --git a/qcsrc/server/command/sv_cmd.qh b/qcsrc/server/command/sv_cmd.qh index 6ccfb1c7b..03bd80cef 100644 --- a/qcsrc/server/command/sv_cmd.qh +++ b/qcsrc/server/command/sv_cmd.qh @@ -11,3 +11,6 @@ void race_deleteTime(string map, float pos); #define SHUFFLETEAMS_MAX_TEAMS 4 float shuffleteams_players[SHUFFLETEAMS_MAX_PLAYERS]; // maximum of 255 player slots float shuffleteams_teams[SHUFFLETEAMS_MAX_TEAMS]; // maximum of 4 teams + +// used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file +void GameCommand_macro_write_aliases(float fh); \ No newline at end of file -- 2.39.2