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