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