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