Debian Codegraph @

server/commands.c

raw symbols SCIP
1 /*
2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
3 *
4 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
6 *
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
10 *
11 * The authors can be reached via e-mail at <[email protected]>.
12 */
13
14 /**
15 * @file
16 * Contains the definition for all in-game commands a player can issue.
17 */
18
19 #include "global.h"
20
21 #include <ctype.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include "commands.h"
26 #include "sproto.h"
27
28 /* Added times to all the commands. However, this was quickly done,
29 * and probably needs more refinements. All socket and DM commands
30 * take 0 time.
31 */
32
33 /**
34 * Normal game commands.
35 */
36 command_array_struct Commands[] = {
37 { "afk", command_afk, 0.0 },
38 { "apply", command_apply, 1.0 }, /* should be variable */
39 { "applymode", command_applymode, 1.0 }, /* should be variable */
40 { "body", command_body, 0.0 },
41 { "bowmode", command_bowmode, 0.0 },
42 { "brace", command_brace, 0.0 },
43 { "cast", command_cast, 0.2 }, /* Is this right? */
44 { "delete", command_delete, 0.0 },
45 { "disarm", command_disarm, 1.0 },
46 { "dm", command_dm, 0.0 },
47 { "dmhide", command_dmhide, 0.0 }, /* Like dm, but don't tell a dm arrived, hide player */
48 { "drop", command_drop, 1.0 },
49 { "dropall", command_dropall, 1.0 },
50 { "empty", command_empty, 1.0 },
51 { "examine", command_examine, 0.5 },
52 { "fix_me", command_fix_me, 0.0 },
53 { "forget_spell", command_forget_spell, 0.0 },
54 { "get", command_take, 1.0 },
55 { "help", command_help, 0.0 },
56 { "hiscore", command_hiscore, 0.0 },
57 { "inventory", command_inventory, 0.0 },
58 { "invoke", command_invoke, 1.0 },
59 { "killpets", command_kill_pets, 0.0 },
60 { "language", command_language, 0.0 },
61 { "listen", command_listen, 0.0 },
62 { "lock", command_lock_item, 0.0 },
63 { "maps", command_maps, 0.0 },
64 { "mapinfo", command_mapinfo, 0.0 },
65 { "mark", command_mark, 0.0 },
66 { "motd", command_motd, 0.0 },
67 { "news", command_news, 0.0 },
68 { "party", command_party, 0.0 },
69 { "party_rejoin", command_party_rejoin, 0.0 },
70 { "passwd", command_passwd, 0.0 },
71 { "peaceful", command_peaceful, 0.0 },
72 { "petmode", command_petmode, 0.0 },
73 { "pickup", command_pickup, 1.0 },
74 { "prepare", command_prepare, 1.0 },
75 { "printlos", command_printlos, 0.0 },
76 { "quit", command_quit, 0.0 },
77 { "ready_skill", command_rskill, 1.0 },
78 { "rename", command_rename_item, 0.0 },
79 { "resistances", command_resistances, 0.0 },
80 { "rotateshoottype", command_rotateshoottype, 0.0 },
81 { "rules", command_rules, 0.0 },
82 { "save", command_save, 0.0 },
83 { "skills", command_skills, 0.0 }, /* shows player list of skills */
84 { "use_skill", command_uskill, 1.0 },
85 { "search", command_search, 1.0 },
86 { "search-items", command_search_items, 0.0 },
87 { "showpets", command_showpets, 1.0 },
88 { "sound", command_sound, 0.0 },
89 { "statistics", command_statistics, 0.0 },
90 { "take", command_take, 1.0 },
91 { "throw", command_throw, 1.0 },
92 { "time", command_time, 0.0 },
93 { "title", command_title, 0.0 },
94 { "use", command_use, 1.0 },
95 { "usekeys", command_usekeys, 0.0 },
96 { "whereabouts", command_whereabouts, 0.0 },
97 { "whereami", command_whereami, 0.0 },
98 { "unarmed_skill", command_unarmed_skill, 0.0 },
99 #ifdef DEBUG_MALLOC_LEVEL
100 { "verify", command_malloc_verify, 0.0 },
101 #endif
102 { "version", command_version, 0.0 },
103 { "wimpy", command_wimpy, 0.0 },
104 { "who", command_who, 0.0 },
105 /*
106 * directional commands
107 */
108 { "stay", command_stay, 1.0 }, /* 1.0 because it is used when using a
109 * skill on yourself */
110 { "north", command_north, 1.0 },
111 { "east", command_east, 1.0 },
112 { "south", command_south, 1.0 },
113 { "west", command_west, 1.0 },
114 { "northeast", command_northeast, 1.0 },
115 { "southeast", command_southeast, 1.0 },
116 { "southwest", command_southwest, 1.0 },
117 { "northwest", command_northwest, 1.0 },
118 { "run", command_run, 1.0 },
119 { "run_stop", command_run_stop, 0.0 },
120 { "fire", command_fire, 1.0 },
121 { "fire_stop", command_fire_stop, 0.0 },
122 { "face", command_face, 0.0 },
123 { "quest", command_quest, 0.0 },
124 { "knowledge", command_knowledge, 0.0 }
125 };
126
127 /** Length of ::Commands array. */
128 const int CommandsSize = sizeof(Commands)/sizeof(command_array_struct);
129
130 /** Chat/shout related commands. */
131 command_array_struct CommunicationCommands [] = {
132 { "tell", command_tell, 0.1 },
133 { "reply", command_reply, 0.0 },
134 { "say", command_say, 0.1 },
135 { "gsay", command_gsay, 1.0 },
136 { "shout", command_shout, 0.1 },
137 { "chat", command_chat, 0.1 },
138 { "me", command_me, 0.1 },
139 { "cointoss", command_cointoss, 0.0 },
140 { "orcknuckle", command_orcknuckle, 0.0 },
141 /*
142 * begin emotions
143 */
144 { "nod", command_nod, 0.0 },
145 { "dance", command_dance, 0.0 },
146 { "kiss", command_kiss, 0.0 },
147 { "bounce", command_bounce, 0.0 },
148 { "smile", command_smile, 0.0 },
149 { "cackle", command_cackle, 0.0 },
150 { "laugh", command_laugh, 0.0 },
151 { "giggle", command_giggle, 0.0 },
152 { "shake", command_shake, 0.0 },
153 { "puke", command_puke, 0.0 },
154 { "growl", command_growl, 0.0 },
155 { "scream", command_scream, 0.0 },
156 { "sigh", command_sigh, 0.0 },
157 { "sulk", command_sulk, 0.0 },
158 { "hug", command_hug, 0.0 },
159 { "cry", command_cry, 0.0 },
160 { "poke", command_poke, 0.0 },
161 { "accuse", command_accuse, 0.0 },
162 { "grin", command_grin, 0.0 },
163 { "bow", command_bow, 0.0 },
164 { "clap", command_clap, 0.0 },
165 { "blush", command_blush, 0.0 },
166 { "burp", command_burp, 0.0 },
167 { "chuckle", command_chuckle, 0.0 },
168 { "cough", command_cough, 0.0 },
169 { "flip", command_flip, 0.0 },
170 { "frown", command_frown, 0.0 },
171 { "gasp", command_gasp, 0.0 },
172 { "glare", command_glare, 0.0 },
173 { "groan", command_groan, 0.0 },
174 { "hiccup", command_hiccup, 0.0 },
175 { "lick", command_lick, 0.0 },
176 { "pout", command_pout, 0.0 },
177 { "shiver", command_shiver, 0.0 },
178 { "shrug", command_shrug, 0.0 },
179 { "slap", command_slap, 0.0 },
180 { "smirk", command_smirk, 0.0 },
181 { "snap", command_snap, 0.0 },
182 { "sneeze", command_sneeze, 0.0 },
183 { "snicker", command_snicker, 0.0 },
184 { "sniff", command_sniff, 0.0 },
185 { "snore", command_snore, 0.0 },
186 { "spit", command_spit, 0.0 },
187 { "strut", command_strut, 0.0 },
188 { "thank", command_thank, 0.0 },
189 { "twiddle", command_twiddle, 0.0 },
190 { "wave", command_wave, 0.0 },
191 { "whistle", command_whistle, 0.0 },
192 { "wink", command_wink, 0.0 },
193 { "yawn", command_yawn, 0.0 },
194 { "beg", command_beg, 0.0 },
195 { "bleed", command_bleed, 0.0 },
196 { "cringe", command_cringe, 0.0 },
197 { "think", command_think, 0.0 }
198 };
199
200 /** Length of the ::CommunicationCommands array. */
201 const int CommunicationCommandSize = sizeof(CommunicationCommands)/sizeof(command_array_struct);
202
203 /** Wizard commands. */
204 command_array_struct WizCommands [] = {
205 { "abil", command_abil, 0.0 },
206 { "addexp", command_addexp, 0.0 },
207 { "archs", command_archs, 0.0 },
208 { "arrest", command_arrest, 0.0 },
209 { "banish", command_banish, 0.0 },
210 { "create", command_create, 0.0 },
211 { "debug", command_debug, 0.0 },
212 { "diff", command_diff, 0.0 },
213 { "dmtell", command_dmtell, 0.0 },
214 { "dump", command_dump, 0.0 },
215 { "dumpabove", command_dumpabove, 0.0 },
216 { "dumpbelow", command_dumpbelow, 0.0 },
217 { "dumpfriendlyobjects", command_dumpfriendlyobjects, 0.0 },
218 { "dumpallarchetypes", command_dumpallarchetypes, 0.0 },
219 { "dumpallmaps", command_dumpallmaps, 0.0 },
220 { "dumpallobjects", command_dumpallobjects, 0.0 },
221 { "dumpmap", command_dumpmap, 0.0 },
222 { "follow", command_follow, 0.0 },
223 { "free", command_free, 0.0 },
224 { "freeze", command_freeze, 0.0 },
225 { "goto", command_goto, 0.0 },
226 { "hide", command_hide, 0.0 },
227 { "insert_into", command_insert_into, 0.0 },
228 { "invisible", command_invisible, 0.0 },
229 { "kick", command_kick, 0.0 },
230 { "learn_special_prayer", command_learn_special_prayer, 0.0 },
231 { "learn_spell", command_learn_spell, 0.0 },
232 { "malloc", command_malloc, 0.0 },
233 { "nodm", command_nowiz, 0.0 },
234 { "nowiz", command_nowiz, 0.0 },
235 { "patch", command_patch, 0.0 },
236 { "players", command_players, 0.0 },
237 { "plugin", command_loadplugin, 0.0 },
238 { "pluglist", command_listplugins, 0.0 },
239 { "plugout", command_unloadplugin, 0.0 },
240 { "purge_quest_state", command_purge_quest, 0.0 },
241 { "purge_quests", command_purge_quest_definitions, 0.0 },
242 { "remove", command_remove, 0.0 },
243 { "reset", command_reset, 0.0 },
244 { "set_god", command_setgod, 0.0 },
245 { "settings", command_settings, 0.0 },
246 { "server_speed", command_speed, 0.0 },
247 { "shutdown", command_shutdown, 0.0 },
248 { "ssdumptable", command_ssdumptable, 0.0 },
249 { "stack_clear", command_stack_clear, 0.0 },
250 { "stack_list", command_stack_list, 0.0 },
251 { "stack_pop", command_stack_pop, 0.0 },
252 { "stack_push", command_stack_push, 0.0 },
253 { "stats", command_stats, 0.0 },
254 { "strings", command_strings, 0.0 },
255 { "style_info", command_style_map_info, 0.0 }, /* Costly command, so make it wiz only */
256 { "summon", command_summon, 0.0 },
257 { "teleport", command_teleport, 0.0 },
258 { "toggle_shout", command_toggle_shout, 0.0 },
259 { "wizpass", command_wizpass, 0.0 },
260 { "wizcast", command_wizcast, 0.0 },
261 { "overlay_save", command_overlay_save, 0.0 },
262 { "overlay_reset", command_overlay_reset, 0.0 },
263 /* { "possess", command_possess, 0.0 }, */
264 { "mon_aggr", command_mon_aggr, 0.0 },
265 { "loadtest", command_loadtest, 0.0 },
266 };
267 /** Length of ::WizCommands array. */
268 const int WizCommandsSize = sizeof(WizCommands)/sizeof(command_array_struct);
269
270 /**
271 * Comparison function for 2 command_array_struct.
272 * @param a
273 * @param b
274 * commands to compare.
275 * @retval -1
276 * a is less than b.
277 * @retval 0
278 * a equals b.
279 * @retval 1
280 * a is greater than b.
281 */
282 static int compare_A(const void *a, const void *b) {
283 return strcmp(((const command_array_struct *)a)->name, ((const command_array_struct *)b)->name);
284 }
285
286 /**
287 * Sorts the command arrays for easy search through bsearch().
288 */
289 void init_commands(void) {
290 qsort(Commands, CommandsSize, sizeof(command_array_struct), compare_A);
291 qsort(CommunicationCommands, CommunicationCommandSize, sizeof(command_array_struct), compare_A);
292 qsort(WizCommands, WizCommandsSize, sizeof(command_array_struct), compare_A);
293 }