Xonotic
common.qh
Go to the documentation of this file.
1 #pragma once
2 
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"
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
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 
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 
189 {
190  FOREACH(COMMON_COMMANDS, true, { CMD_Write_Alias("qc_cmd_svcmd", it.m_name, it.m_description); });
191 }
bool autocvar_sv_timeout
Definition: common.qh:5
void CommonCommand_info(int request, entity caller, int argc)
Definition: common.qc:465
float VerifyClientEntity(entity client, float must_be_real, float must_be_bots)
Definition: common.qc:47
void CommonCommand_timein(int request, entity caller)
Definition: common.qc:644
void CommonCommand_lsmaps(int request, entity caller)
Definition: common.qc:509
const float CLIENT_NOT_BOT
Definition: common.qh:44
float CommonCommand_macro_usage(int argc, entity caller)
Definition: common.qh:178
void timeout_handler_reset(entity this)
Definition: common.qc:183
float autocvar_sv_timeout_length
Definition: common.qh:7
void CommonCommand_ladder(int request, entity caller)
Definition: common.qc:489
void CommonCommand_cvar_purechanges(int request, entity caller)
Definition: common.qc:297
STATIC_INIT(g_warpzones)
Definition: common.qh:7
float autocvar_sv_timeout_leadtime
Definition: common.qh:6
entity() spawn
bool autocvar_sv_status_privacy
Definition: common.qh:4
void CommonCommand_macro_help(entity caller)
Definition: common.qh:163
float VerifyKickableEntity(entity client)
Definition: common.qc:40
string GetCallerName(entity caller)
Definition: common.qc:33
void CommonCommand_time(int request, entity caller)
Definition: common.qc:618
void CommonCommand_printmaplist(int request, entity caller)
Definition: common.qc:529
entity GetIndexedEntity(int argc, float start_index)
Definition: common.qc:83
entity to
Definition: self.qh:96
string autocvar_sv_adminnick
Definition: common.qh:3
float timeout_leadtime
Definition: common.qh:60
entity timeout_handler
Definition: common.qh:56
const float TIMEOUT_ACTIVE
Definition: common.qh:49
string GetCommandPrefix(entity caller)
Definition: common.qc:26
const float CLIENT_ACCEPTABLE
Definition: common.qh:41
#define REGISTRY_SORT(...)
Definition: registry.qh:128
const float TIMEOUT_SLOWMO_VALUE
Definition: common.qh:52
const float CLIENT_DOESNT_EXIST
Definition: common.qh:42
void CommonCommand_teamstatus(int request, entity caller)
Definition: common.qc:598
#define REGISTER_REGISTRY(id)
Definition: registry.qh:212
float allowed_timeouts
Definition: common.qh:61
float next_token
Definition: common.qh:71
float sys_frametime
Definition: common.qh:57
#define REGISTRY_DEFINE_GET(id, null)
Definition: registry.qh:40
const float TIMEOUT_INACTIVE
Definition: common.qh:47
void CommonCommand_who(int request, entity caller, int argc)
Definition: common.qc:769
float autocvar_sv_timeout_resumetime
Definition: common.qh:9
int autocvar_sv_timeout_number
Definition: common.qh:8
string cvar_changes
Definition: world.qh:41
#define REGISTRY(id, max)
Declare a new registry.
Definition: registry.qh:26
void CommonCommand_records(int request, entity caller)
Definition: common.qc:569
void CommonCommand_timeout(int request, entity caller)
Definition: common.qc:700
void CommonCommand_editmob(int request, entity caller, int argc)
Definition: common.qc:318
#define NULL
Definition: post.qh:17
#define CMD_Write_Alias(execute, command, description)
Definition: generic.qh:34
string cvar_purechanges
Definition: world.qh:42
string GetClientErrorString_color(float clienterror, string original_input, string col)
Definition: common.qc:57
entity timeout_caller
Definition: common.qh:55
entity GetFilteredEntity(string input)
Definition: common.qc:144
float timeout_time
Definition: common.qh:59
#define COMMON_COMMAND(id, description)
Definition: common.qh:18
void CommonCommand_cvar_changes(int request, entity caller)
Definition: common.qc:276
const float CLIENT_NOT_REAL
Definition: common.qh:43
const float TIMEOUT_LEADTIME
Definition: common.qh:48
float VerifyClientNumber(float tmp_number)
Definition: common.qc:77
void VoteCommand(int request, entity caller, int argc, string vote_command)
Definition: vote.qc:1264
vector lastV_angle
Definition: common.qh:62
void print_to(entity to, string input)
Definition: common.qc:172
void CommonCommand_rankings(int request, entity caller)
Definition: common.qc:549
void CommonCommand_macro_write_aliases(float fh)
Definition: common.qh:188
float time
Definition: csprogsdefs.qc:16
#define FOREACH(list, cond, body)
Definition: iter.qh:19
#define BITS(n)
Definition: bits.qh:9
void timeout_handler_think(entity this)
Definition: common.qc:192
float CommonCommand_macro_command(int argc, entity caller, string command)
Definition: common.qh:168
float orig_slowmo
Definition: common.qh:58