Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
common.qh
Go to the documentation of this file.
1#pragma once
2
10
12REGISTRY(COMMON_COMMANDS, BITS(7))
13REGISTER_REGISTRY(COMMON_COMMANDS)
14REGISTRY_SORT(COMMON_COMMANDS)
15
16REGISTRY_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
26STATIC_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
34
35// ============================================================
36// Shared declarations for server commands, written by Samual
37// Last updated: December 30th, 2011
38// ============================================================
39
40// client verification results
41const float CLIENT_ACCEPTABLE = 1;
42const float CLIENT_DOESNT_EXIST = -1;
43const float CLIENT_NOT_REAL = -2;
44const float CLIENT_NOT_BOT = -3;
45
46// definitions for timeouts
47const float TIMEOUT_INACTIVE = 0;
48const float TIMEOUT_LEADTIME = 1;
49const float TIMEOUT_ACTIVE = 2;
50
51// timeout which pauses the game by setting the slowmo value extremely low.
52const float TIMEOUT_SLOWMO_VALUE = 0.0001;
53
54// global timeout information declarations
55entity timeout_caller; // contains the entity of the player who started the last timeout
56entity timeout_handler; // responsible for centerprinting the timeout countdowns and playing sounds
57float sys_frametime; // gets initialised in worldspawn, saves the value from autocvar_sys_ticrate
58float orig_slowmo; // contains the value of autocvar_slowmo so that, after timeout finished, it isn't set to slowmo 1 necessarily
59float timeout_time; // contains the time in seconds that the active timeout has left
60float 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 their old view angle fixed
63
64// allow functions to be used in other code like world.qc and teamplay.qc
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
72
73// select the proper prefix for usage and other messages
74string GetCommandPrefix(entity caller);
75
76// if client return player nickname, or if server return admin nickname
77string GetCallerName(entity caller);
78
79// verify that the client provided is acceptable for kicking
81
82// verify that the client provided is acceptable for use
83int VerifyClientEntity(entity client, bool must_be_real, bool must_be_bots);
84
85// if the client is not acceptable, return a string to be used for error messages
86string GetClientErrorString_color(int 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?
90bool VerifyClientNumber(int num);
91
92entity GetIndexedEntity(int argc, int start_index);
93
94// find a player which matches the input string, and return their entity
95entity GetFilteredEntity(string input);
96
97// switch between sprint and print depending on whether the receiver is the server or a player
98void 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.
106
108
109// ===================================================
110// Common commands used in both sv_cmd.qc and cmd.qc
111// ===================================================
112
113void CommonCommand_cvar_changes(int request, entity caller);
114
115void CommonCommand_cvar_purechanges(int request, entity caller);
116
117void CommonCommand_editmob(int request, entity caller, int argc);
118
119void CommonCommand_info(int request, entity caller, int argc);
120
121void CommonCommand_ladder(int request, entity caller);
122
123void CommonCommand_lsmaps(int request, entity caller);
124
125void CommonCommand_printmaplist(int request, entity caller);
126
127void CommonCommand_rankings(int request, entity caller);
128
129void CommonCommand_records(int request, entity caller);
130
131void CommonCommand_teamstatus(int request, entity caller);
132
133void CommonCommand_time(int request, entity caller);
134
135void CommonCommand_timein(int request, entity caller);
136
137void CommonCommand_timeout(int request, entity caller);
138
139void 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 ;)
147COMMON_COMMAND(cvar_changes, "Prints a list of all changed server cvars") { CommonCommand_cvar_changes(request, caller); }
148COMMON_COMMAND(cvar_purechanges, "Prints a list of all changed gameplay cvars") { CommonCommand_cvar_purechanges(request, caller); }
149COMMON_COMMAND(editmob, "Modifies a monster or all monsters") { CommonCommand_editmob(request, caller, arguments); }
150COMMON_COMMAND(info, "Request for unique server information set up by admin") { CommonCommand_info(request, caller, arguments); }
151COMMON_COMMAND(ladder, "Get information about top players if supported") { CommonCommand_ladder(request, caller); }
152COMMON_COMMAND(lsmaps, "List maps which can be used with the current gametype") { CommonCommand_lsmaps(request, caller); }
153COMMON_COMMAND(printmaplist, "Display full server maplist reply") { CommonCommand_printmaplist(request, caller); }
154COMMON_COMMAND(rankings, "Print information about rankings") { CommonCommand_rankings(request, caller); }
155COMMON_COMMAND(records, "Print records for the current gametype") { CommonCommand_records(request, caller); }
156COMMON_COMMAND(teamstatus, "Show information about player and team scores") { CommonCommand_teamstatus(request, caller); }
157COMMON_COMMAND(time, "Print different formats/readouts of time") { CommonCommand_time(request, caller); }
158COMMON_COMMAND(timein, "Resume the game from being paused with a timeout") { CommonCommand_timein(request, caller); }
159COMMON_COMMAND(timeout, "Call a timeout which pauses the game for certain amount of time unless unpaused") { CommonCommand_timeout(request, caller); }
160COMMON_COMMAND(vote, "Request an action to be voted upon by players") { VoteCommand(request, caller, arguments, command); }
161COMMON_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
168float 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
178float 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}
#define BITS(n)
Definition bits.qh:9
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
string strtolower(string s)
float time
#define CMD_Write_Alias(execute, command, description)
Definition generic.qh:34
#define FOREACH(list, cond, body)
Definition iter.qh:19
void localcmd(string command,...)
string argv(float n)
#define NULL
Definition post.qh:14
#define REGISTRY_SORT(...)
Definition registry.qh:128
#define REGISTER_REGISTRY(id)
Definition registry.qh:229
#define REGISTRY(id, max)
Declare a new registry.
Definition registry.qh:26
#define REGISTRY_DEFINE_GET(id, null)
Definition registry.qh:40
float CommonCommand_macro_usage(int argc, entity caller)
Definition common.qh:178
bool autocvar_sv_timeout
Definition common.qh:5
void CommonCommand_cvar_purechanges(int request, entity caller)
Definition common.qc:293
void CommonCommand_macro_help(entity caller)
Definition common.qh:163
float timeout_leadtime
Definition common.qh:60
void CommonCommand_printmaplist(int request, entity caller)
Definition common.qc:524
const float TIMEOUT_INACTIVE
Definition common.qh:47
void CommonCommand_lsmaps(int request, entity caller)
Definition common.qc:504
int next_token
Definition common.qh:71
const float TIMEOUT_SLOWMO_VALUE
Definition common.qh:52
entity timeout_handler
Definition common.qh:56
void CommonCommand_editmob(int request, entity caller, int argc)
Definition common.qc:314
float timeout_time
Definition common.qh:59
void print_to(entity to, string input)
Definition common.qc:171
string autocvar_sv_adminnick
Definition common.qh:3
void timeout_handler_reset(entity this)
Definition common.qc:182
string GetCommandPrefix(entity caller)
Definition common.qc:26
void CommonCommand_records(int request, entity caller)
Definition common.qc:564
float CommonCommand_macro_command(int argc, entity caller, string command)
Definition common.qh:168
const float CLIENT_ACCEPTABLE
Definition common.qh:41
const float CLIENT_NOT_BOT
Definition common.qh:44
entity timeout_caller
Definition common.qh:55
entity GetIndexedEntity(int argc, int start_index)
Definition common.qc:82
const float CLIENT_DOESNT_EXIST
Definition common.qh:42
float orig_slowmo
Definition common.qh:58
bool autocvar_sv_status_privacy
Definition common.qh:4
int autocvar_sv_timeout_number
Definition common.qh:8
vector lastV_angle
Definition common.qh:62
int VerifyClientEntity(entity client, bool must_be_real, bool must_be_bots)
Definition common.qc:47
string GetClientErrorString_color(int clienterror, string original_input, string col)
#define COMMON_COMMAND(id, description)
Definition common.qh:18
void CommonCommand_ladder(int request, entity caller)
Definition common.qc:484
const float TIMEOUT_ACTIVE
Definition common.qh:49
const float CLIENT_NOT_REAL
Definition common.qh:43
float autocvar_sv_timeout_leadtime
Definition common.qh:6
void CommonCommand_teamstatus(int request, entity caller)
Definition common.qc:593
void CommonCommand_timeout(int request, entity caller)
Definition common.qc:695
void CommonCommand_who(int request, entity caller, int argc)
Definition common.qc:764
float allowed_timeouts
Definition common.qh:61
float sys_frametime
Definition common.qh:57
float autocvar_sv_timeout_length
Definition common.qh:7
void timeout_handler_think(entity this)
Definition common.qc:195
const float TIMEOUT_LEADTIME
Definition common.qh:48
float autocvar_sv_timeout_resumetime
Definition common.qh:9
void CommonCommand_info(int request, entity caller, int argc)
Definition common.qc:460
bool VerifyClientNumber(int num)
Definition common.qc:77
void CommonCommand_timein(int request, entity caller)
Definition common.qc:639
void CommonCommand_macro_write_aliases(int fh)
Definition common.qh:188
void CommonCommand_rankings(int request, entity caller)
Definition common.qc:544
string GetCallerName(entity caller)
Definition common.qc:33
void CommonCommand_cvar_changes(int request, entity caller)
Definition common.qc:272
void CommonCommand_time(int request, entity caller)
Definition common.qc:613
int VerifyKickableEntity(entity client)
Definition common.qc:40
entity GetFilteredEntity(string input)
Definition common.qc:143
void VoteCommand(int request, entity caller, int argc, string vote_command)
Definition vote.qc:1431
#define STATIC_INIT(func)
during worldspawn
Definition static.qh:32
string cvar_changes
Definition world.qh:45
string cvar_purechanges
Definition world.qh:46