]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/command/common.qh
Remove various SELFPARAM
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / common.qh
1 #pragma once
2
3 #include <common/command/command.qh>
4 REGISTRY(COMMON_COMMANDS, BITS(7))
5 #define COMMON_COMMANDS_from(i) _COMMON_COMMANDS_from(i, NULL)
6 REGISTER_REGISTRY(COMMON_COMMANDS)
7 REGISTRY_SORT(COMMON_COMMANDS)
8
9 #define COMMON_COMMAND(id, description) \
10         CLASS(commoncommand_##id, Command) \
11                 ATTRIB(commoncommand_##id, m_name, string, #id); \
12         ATTRIB(commoncommand_##id, m_description, string, description); \
13         ENDCLASS(commoncommand_##id) \
14     REGISTER(COMMON_COMMANDS, CMD_SV, id, m_id, NEW(commoncommand_##id)); \
15         METHOD(commoncommand_##id, m_invokecmd, void(commoncommand_##id this, int request, entity caller, int arguments, string command))
16
17 STATIC_INIT(COMMON_COMMANDS_aliases) {
18         FOREACH(COMMON_COMMANDS, true, LAMBDA(localcmd(sprintf("alias %1$s \"%2$s %1$s ${* ?}\"\n", it.m_name, "qc_cmd_svcmd"))));
19 }
20
21 #include "vote.qh"
22 #include <common/monsters/spawn.qh>
23
24 #include <common/command/generic.qh>
25 #include <common/command/command.qh>
26
27 // ============================================================
28 //  Shared declarations for server commands, written by Samual
29 //  Last updated: December 30th, 2011
30 // ============================================================
31
32 // client verification results
33 const float CLIENT_ACCEPTABLE = 1;
34 const float CLIENT_DOESNT_EXIST = -1;
35 const float CLIENT_NOT_REAL = -2;
36 const float CLIENT_NOT_BOT = -3;
37
38 // definitions for timeouts
39 const float TIMEOUT_INACTIVE = 0;
40 const float TIMEOUT_LEADTIME = 1;
41 const float TIMEOUT_ACTIVE = 2;
42
43 // timeout which pauses the game by setting the slowmo value extremely low.
44 const float TIMEOUT_SLOWMO_VALUE = 0.0001;
45
46 // global timeout information declarations
47 entity timeout_caller;   // contains the entity of the player who started the last timeout
48 entity timeout_handler;  // responsible for centerprinting the timeout countdowns and playing sounds
49 float sys_frametime;     // gets initialised in worldspawn, saves the value from autocvar_sys_ticrate
50 float orig_slowmo;       // contains the value of autocvar_slowmo so that, after timeout finished, it isn't set to slowmo 1 necessarily
51 float timeout_time;      // contains the time in seconds that the active timeout has left
52 float timeout_leadtime;  // contains the number of seconds left of the leadtime (before the timeout starts)
53 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)
54 .float allowed_timeouts; // contains the number of allowed timeouts for each player
55 .vector lastV_angle;     // used when pausing the game in order to force the player to keep his old view angle fixed
56
57 // allow functions to be used in other code like g_world.qc and teamplay.qc
58 void timeout_handler_think(entity this);
59
60 // used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file
61 void CommonCommand_macro_write_aliases(float fh);
62
63 // keep track of the next token to use for argc
64 float next_token;
65
66 // select the proper prefix for usage and other messages
67 string GetCommandPrefix(entity caller);
68
69 // if client return player nickname, or if server return admin nickname
70 string GetCallerName(entity caller);
71
72 // verify that the client provided is acceptable for kicking
73 float VerifyKickableEntity(entity client);
74
75 // verify that the client provided is acceptable for use
76 float VerifyClientEntity(entity client, float must_be_real, float must_be_bots);
77
78 // if the client is not acceptable, return a string to be used for error messages
79 string GetClientErrorString_color(float clienterror, string original_input, string col);
80 #define GetClientErrorString(clienterror, original_input) GetClientErrorString_color(clienterror, original_input, "^7")
81
82 // is this entity number even in the possible range of entities?
83 float VerifyClientNumber(float tmp_number);
84
85 entity GetIndexedEntity(float argc, float start_index);
86
87 // find a player which matches the input string, and return their entity
88 entity GetFilteredEntity(string input);
89
90 // same thing, but instead return their edict number
91 float GetFilteredNumber(string input);
92
93 // switch between sprint and print depending on whether the receiver is the server or a player
94 void print_to(entity to, string input);
95
96 // ==========================================
97 //  Supporting functions for common commands
98 // ==========================================
99
100 // used by CommonCommand_timeout() and CommonCommand_timein() to handle game pausing and messaging and such.
101 void timeout_handler_reset(entity this);
102
103 void timeout_handler_think(entity this);
104
105 // ===================================================
106 //  Common commands used in both sv_cmd.qc and cmd.qc
107 // ===================================================
108
109 void CommonCommand_cvar_changes(float request, entity caller);
110
111 void CommonCommand_cvar_purechanges(float request, entity caller);
112
113 void CommonCommand_editmob(float request, entity caller, float argc);
114
115 void CommonCommand_info(float request, entity caller, float argc);
116
117 void CommonCommand_ladder(float request, entity caller);
118
119 void CommonCommand_lsmaps(float request, entity caller);
120
121 void CommonCommand_printmaplist(float request, entity caller);
122
123 void CommonCommand_rankings(float request, entity caller);
124
125 void CommonCommand_records(float request, entity caller);
126
127 void CommonCommand_teamstatus(float request, entity caller);
128
129 void CommonCommand_time(float request, entity caller);
130
131 void CommonCommand_timein(float request, entity caller);
132
133 void CommonCommand_timeout(float request, entity caller);
134
135 void CommonCommand_who(float request, entity caller, float argc);
136
137
138 // ==================================
139 //  Macro system for common commands
140 // ==================================
141
142 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
143 COMMON_COMMAND(cvar_changes, "Prints a list of all changed server cvars") { CommonCommand_cvar_changes(request, caller); }
144 COMMON_COMMAND(cvar_purechanges, "Prints a list of all changed gameplay cvars") { CommonCommand_cvar_purechanges(request, caller); }
145 COMMON_COMMAND(editmob, "Modifies a monster or all monsters") { CommonCommand_editmob(request, caller, arguments); }
146 COMMON_COMMAND(info, "Request for unique server information set up by admin") { CommonCommand_info(request, caller, arguments); }
147 COMMON_COMMAND(ladder, "Get information about top players if supported") { CommonCommand_ladder(request, caller); }
148 COMMON_COMMAND(lsmaps, "List maps which can be used with the current game mode") { CommonCommand_lsmaps(request, caller); }
149 COMMON_COMMAND(printmaplist, "Display full server maplist reply") { CommonCommand_printmaplist(request, caller); }
150 COMMON_COMMAND(rankings, "Print information about rankings") { CommonCommand_rankings(request, caller); }
151 COMMON_COMMAND(records, "List top 10 records for the current map") { CommonCommand_records(request, caller); }
152 COMMON_COMMAND(teamstatus, "Show information about player and team scores") { CommonCommand_teamstatus(request, caller); }
153 COMMON_COMMAND(time, "Print different formats/readouts of time") { CommonCommand_time(request, caller); }
154 COMMON_COMMAND(timein, "Resume the game from being paused with a timeout") { CommonCommand_timein(request, caller); }
155 COMMON_COMMAND(timeout, "Call a timeout which pauses the game for certain amount of time unless unpaused") { CommonCommand_timeout(request, caller); }
156 COMMON_COMMAND(vote, "Request an action to be voted upon by players") { VoteCommand(request, caller, arguments, command); }
157 COMMON_COMMAND(who, "Display detailed client information about all players") { CommonCommand_who(request, caller, arguments);}
158
159 void CommonCommand_macro_help(entity caller)
160 {
161         FOREACH(COMMON_COMMANDS, true, LAMBDA(print_to(caller, sprintf("  ^2%s^7: %s\n", it.m_name, it.m_description))));
162 }
163
164 float CommonCommand_macro_command(float argc, entity caller, string command)
165 {
166         string c = strtolower(argv(0));
167         FOREACH(COMMON_COMMANDS, it.m_name == c, LAMBDA(
168                 it.m_invokecmd(it, CMD_REQUEST_COMMAND, caller, argc, command);
169                 return true;
170         ));
171         return false;
172 }
173
174 float CommonCommand_macro_usage(float argc, entity caller)
175 {
176         string c = strtolower(argv(1));
177         FOREACH(COMMON_COMMANDS, it.m_name == c, LAMBDA(
178                 it.m_invokecmd(it, CMD_REQUEST_USAGE, caller, argc, "");
179                 return true;
180         ));
181         return false;
182 }
183
184 void CommonCommand_macro_write_aliases(float fh)
185 {
186         FOREACH(COMMON_COMMANDS, true, LAMBDA(CMD_Write_Alias("qc_cmd_svcmd", it.m_name, it.m_description)));
187 }