]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/command/common.qh
Merge branch 'master' into develop
[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 allowed_timeouts; // contains the number of allowed timeouts for each player
62 .vector lastV_angle;     // used when pausing the game in order to force the player to keep his old view angle fixed
63
64 // allow functions to be used in other code like world.qc and teamplay.qc
65 void timeout_handler_think(entity this);
66
67 // used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file
68 void CommonCommand_macro_write_aliases(float fh);
69
70 // keep track of the next token to use for argc
71 float next_token;
72
73 // select the proper prefix for usage and other messages
74 string GetCommandPrefix(entity caller);
75
76 // if client return player nickname, or if server return admin nickname
77 string GetCallerName(entity caller);
78
79 // verify that the client provided is acceptable for kicking
80 float VerifyKickableEntity(entity client);
81
82 // verify that the client provided is acceptable for use
83 float VerifyClientEntity(entity client, float must_be_real, float must_be_bots);
84
85 // if the client is not acceptable, return a string to be used for error messages
86 string GetClientErrorString_color(float clienterror, string original_input, string col);
87 #define GetClientErrorString(clienterror, original_input) GetClientErrorString_color(clienterror, original_input, "^7")
88
89 // is this entity number even in the possible range of entities?
90 float VerifyClientNumber(float tmp_number);
91
92 entity GetIndexedEntity(int argc, float start_index);
93
94 // find a player which matches the input string, and return their entity
95 entity GetFilteredEntity(string input);
96
97 // switch between sprint and print depending on whether the receiver is the server or a player
98 void print_to(entity to, string input);
99
100 // ==========================================
101 //  Supporting functions for common commands
102 // ==========================================
103
104 // used by CommonCommand_timeout() and CommonCommand_timein() to handle game pausing and messaging and such.
105 void timeout_handler_reset(entity this);
106
107 void timeout_handler_think(entity this);
108
109 // ===================================================
110 //  Common commands used in both sv_cmd.qc and cmd.qc
111 // ===================================================
112
113 void CommonCommand_cvar_changes(int request, entity caller);
114
115 void CommonCommand_cvar_purechanges(int request, entity caller);
116
117 void CommonCommand_editmob(int request, entity caller, int argc);
118
119 void CommonCommand_info(int request, entity caller, int argc);
120
121 void CommonCommand_ladder(int request, entity caller);
122
123 void CommonCommand_lsmaps(int request, entity caller);
124
125 void CommonCommand_printmaplist(int request, entity caller);
126
127 void CommonCommand_rankings(int request, entity caller);
128
129 void CommonCommand_records(int request, entity caller);
130
131 void CommonCommand_teamstatus(int request, entity caller);
132
133 void CommonCommand_time(int request, entity caller);
134
135 void CommonCommand_timein(int request, entity caller);
136
137 void CommonCommand_timeout(int request, entity caller);
138
139 void CommonCommand_who(int request, entity caller, int argc);
140
141
142 // ==================================
143 //  Macro system for common commands
144 // ==================================
145
146 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
147 COMMON_COMMAND(cvar_changes, "Prints a list of all changed server cvars") { CommonCommand_cvar_changes(request, caller); }
148 COMMON_COMMAND(cvar_purechanges, "Prints a list of all changed gameplay cvars") { CommonCommand_cvar_purechanges(request, caller); }
149 COMMON_COMMAND(editmob, "Modifies a monster or all monsters") { CommonCommand_editmob(request, caller, arguments); }
150 COMMON_COMMAND(info, "Request for unique server information set up by admin") { CommonCommand_info(request, caller, arguments); }
151 COMMON_COMMAND(ladder, "Get information about top players if supported") { CommonCommand_ladder(request, caller); }
152 COMMON_COMMAND(lsmaps, "List maps which can be used with the current game mode") { CommonCommand_lsmaps(request, caller); }
153 COMMON_COMMAND(printmaplist, "Display full server maplist reply") { CommonCommand_printmaplist(request, caller); }
154 COMMON_COMMAND(rankings, "Print information about rankings") { CommonCommand_rankings(request, caller); }
155 COMMON_COMMAND(records, "Print records for the current gametype") { CommonCommand_records(request, caller); }
156 COMMON_COMMAND(teamstatus, "Show information about player and team scores") { CommonCommand_teamstatus(request, caller); }
157 COMMON_COMMAND(time, "Print different formats/readouts of time") { CommonCommand_time(request, caller); }
158 COMMON_COMMAND(timein, "Resume the game from being paused with a timeout") { CommonCommand_timein(request, caller); }
159 COMMON_COMMAND(timeout, "Call a timeout which pauses the game for certain amount of time unless unpaused") { CommonCommand_timeout(request, caller); }
160 COMMON_COMMAND(vote, "Request an action to be voted upon by players") { VoteCommand(request, caller, arguments, command); }
161 COMMON_COMMAND(who, "Display detailed client information about all players") { CommonCommand_who(request, caller, arguments);}
162
163 void CommonCommand_macro_help(entity caller)
164 {
165         FOREACH(COMMON_COMMANDS, true, { print_to(caller, sprintf("  ^2%s^7: %s", it.m_name, it.m_description)); });
166 }
167
168 float CommonCommand_macro_command(int argc, entity caller, string command)
169 {
170         string c = strtolower(argv(0));
171         FOREACH(COMMON_COMMANDS, it.m_name == c, {
172                 it.m_invokecmd(it, CMD_REQUEST_COMMAND, caller, argc, command);
173                 return true;
174         });
175         return false;
176 }
177
178 float CommonCommand_macro_usage(int argc, entity caller)
179 {
180         string c = strtolower(argv(1));
181         FOREACH(COMMON_COMMANDS, it.m_name == c, {
182                 it.m_invokecmd(it, CMD_REQUEST_USAGE, caller, argc, "");
183                 return true;
184         });
185         return false;
186 }
187
188 void CommonCommand_macro_write_aliases(float fh)
189 {
190         FOREACH(COMMON_COMMANDS, true, { CMD_Write_Alias("qc_cmd_svcmd", it.m_name, it.m_description); });
191 }