1 | |
|
|
2 | /* |
1 | /* |
3 | * static char *rcsid_c_misc_c = |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
4 | * "$Id: c_misc.C,v 1.7 2006/09/10 15:59:57 root Exp $"; |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
|
|
9 | * the terms of the Affero GNU General Public License as published by the |
|
|
10 | * Free Software Foundation, either version 3 of the License, or (at your |
|
|
11 | * option) any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, |
|
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
16 | * GNU General Public License for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the Affero GNU General Public License |
|
|
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
|
|
21 | * |
|
|
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
5 | */ |
23 | */ |
6 | |
|
|
7 | /* |
|
|
8 | CrossFire, A Multiplayer game for X-windows |
|
|
9 | |
|
|
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
|
|
11 | Copyright (C) 1992 Frank Tore Johansen |
|
|
12 | |
|
|
13 | This program is free software; you can redistribute it and/or modify |
|
|
14 | it under the terms of the GNU General Public License as published by |
|
|
15 | the Free Software Foundation; either version 2 of the License, or |
|
|
16 | (at your option) any later version. |
|
|
17 | |
|
|
18 | This program is distributed in the hope that it will be useful, |
|
|
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
21 | GNU General Public License for more details. |
|
|
22 | |
|
|
23 | You should have received a copy of the GNU General Public License |
|
|
24 | along with this program; if not, write to the Free Software |
|
|
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
26 | |
|
|
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
|
|
28 | */ |
|
|
29 | |
24 | |
30 | #include <global.h> |
25 | #include <global.h> |
31 | #include <loader.h> |
26 | #include <loader.h> |
32 | #ifndef __CEXTRACT__ |
|
|
33 | # include <sproto.h> |
27 | #include <sproto.h> |
34 | #endif |
|
|
35 | |
28 | |
36 | extern weathermap_t **weathermap; |
|
|
37 | |
|
|
38 | /* Handles misc. input request - things like hash table, malloc, maps, |
29 | /* Handles misc. input request - things like hash table, malloc, maps, etc */ |
39 | * who, etc. |
|
|
40 | */ |
|
|
41 | |
|
|
42 | void |
|
|
43 | map_info (object *op, char *search) |
|
|
44 | { |
|
|
45 | mapstruct *m; |
|
|
46 | char buf[MAX_BUF], map_path[MAX_BUF]; |
|
|
47 | long sec = seconds (); |
|
|
48 | |
|
|
49 | new_draw_info_format (NDI_UNIQUE, 0, op, "Current time is: %02ld:%02ld:%02ld.", (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60); |
|
|
50 | new_draw_info (NDI_UNIQUE, 0, op, "Path Pl PlM IM TO Dif Reset"); |
|
|
51 | for (m = first_map; m != NULL; m = m->next) |
|
|
52 | { |
|
|
53 | |
|
|
54 | if (search && strstr (m->path, search) == NULL) |
|
|
55 | continue; /* Skip unwanted maps */ |
|
|
56 | /* Print out the last 18 characters of the map name... */ |
|
|
57 | if (strlen (m->path) <= 18) |
|
|
58 | strcpy (map_path, m->path); |
|
|
59 | else |
|
|
60 | strcpy (map_path, m->path + strlen (m->path) - 18); |
|
|
61 | sprintf (buf, "%-18.18s %2d %2d %1d %4d %2d %02d:%02d:%02d", |
|
|
62 | map_path, m->players, players_on_map (m, FALSE), |
|
|
63 | m->in_memory, m->timeout, m->difficulty, |
|
|
64 | (MAP_WHEN_RESET (m) % 86400) / 3600, (MAP_WHEN_RESET (m) % 3600) / 60, MAP_WHEN_RESET (m) % 60); |
|
|
65 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
66 | } |
|
|
67 | } |
|
|
68 | |
|
|
69 | /* This command dumps the body information for object *op. |
|
|
70 | * it doesn't care what the params are. |
|
|
71 | * This is mostly meant as a debug command. |
|
|
72 | */ |
|
|
73 | int |
|
|
74 | command_body (object *op, char *params) |
|
|
75 | { |
|
|
76 | int i; |
|
|
77 | |
|
|
78 | /* Too hard to try and make a header that lines everything up, so just |
|
|
79 | * give a description. |
|
|
80 | */ |
|
|
81 | new_draw_info (NDI_UNIQUE, 0, op, "The first column is the name of the body location."); |
|
|
82 | new_draw_info (NDI_UNIQUE, 0, op, "The second column is how many of those locations your body has."); |
|
|
83 | new_draw_info (NDI_UNIQUE, 0, op, "The third column is how many slots in that location are available."); |
|
|
84 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
|
|
85 | { |
|
|
86 | /* really debugging - normally body_used should not be set to anything |
|
|
87 | * if body_info isn't also set. |
|
|
88 | */ |
|
|
89 | if (op->body_info[i] || op->body_used[i]) |
|
|
90 | { |
|
|
91 | new_draw_info_format (NDI_UNIQUE, 0, op, "%-30s %5d %5d", body_locations[i].use_name, op->body_info[i], op->body_used[i]); |
|
|
92 | } |
|
|
93 | } |
|
|
94 | if (!QUERY_FLAG (op, FLAG_USE_ARMOUR)) |
|
|
95 | new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to wear armor"); |
|
|
96 | if (!QUERY_FLAG (op, FLAG_USE_WEAPON)) |
|
|
97 | new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to use weapons"); |
|
|
98 | |
|
|
99 | return 1; |
|
|
100 | } |
|
|
101 | |
|
|
102 | |
|
|
103 | int |
|
|
104 | command_motd (object *op, char *params) |
|
|
105 | { |
|
|
106 | display_motd (op); |
|
|
107 | return 1; |
|
|
108 | } |
|
|
109 | |
|
|
110 | int |
|
|
111 | command_bug (object *op, char *params) |
|
|
112 | { |
|
|
113 | char buf[MAX_BUF]; |
|
|
114 | |
|
|
115 | if (params == NULL) |
|
|
116 | { |
|
|
117 | new_draw_info (NDI_UNIQUE, 0, op, "what bugs?"); |
|
|
118 | return 1; |
|
|
119 | } |
|
|
120 | strcpy (buf, op->name); |
|
|
121 | strcat (buf, " bug-reports: "); |
|
|
122 | strncat (buf, ++params, MAX_BUF - strlen (buf)); |
|
|
123 | buf[MAX_BUF - 1] = '\0'; |
|
|
124 | bug_report (buf); |
|
|
125 | LOG (llevError, "%s\n", buf); |
|
|
126 | new_draw_info (NDI_ALL | NDI_UNIQUE, 1, NULL, buf); |
|
|
127 | new_draw_info (NDI_UNIQUE, 0, op, "OK, thanks!"); |
|
|
128 | return 1; |
|
|
129 | } |
|
|
130 | |
|
|
131 | /* |
|
|
132 | * Pretty much identical to current map_info, but on a bigger scale |
|
|
133 | * This function returns the name of the players current region, and |
|
|
134 | * a description of it. It is there merely for flavour text. |
|
|
135 | */ |
|
|
136 | void |
|
|
137 | current_region_info (object *op) |
|
|
138 | { |
|
|
139 | /* |
|
|
140 | * Ok I /suppose/ I should write a seperate function for this, but it isn't |
|
|
141 | * going to be /that/ slow, and won't get called much |
|
|
142 | */ |
|
|
143 | region *r = get_region_by_name (get_name_of_region_for_map (op->map)); |
|
|
144 | |
|
|
145 | if (!r) |
|
|
146 | return; |
|
|
147 | /* This should only be possible if regions are not operating on this server. */ |
|
|
148 | |
|
|
149 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s. \n %s", get_region_longname (r), get_region_msg (r)); |
|
|
150 | } |
|
|
151 | |
|
|
152 | void |
|
|
153 | current_map_info (object *op) |
|
|
154 | { |
|
|
155 | mapstruct *m = op->map; |
|
|
156 | |
|
|
157 | if (!m) |
|
|
158 | return; |
|
|
159 | |
|
|
160 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", m->name, m->path, get_name_of_region_for_map (m)); |
|
|
161 | |
|
|
162 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
163 | { |
|
|
164 | new_draw_info_format (NDI_UNIQUE, 0, op, |
|
|
165 | "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld", |
|
|
166 | m->players, m->difficulty, MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m), MAP_TIMEOUT (m)); |
|
|
167 | |
|
|
168 | } |
|
|
169 | if (m->msg) |
|
|
170 | new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); |
|
|
171 | } |
|
|
172 | |
|
|
173 | #ifdef DEBUG_MALLOC_LEVEL |
|
|
174 | int |
|
|
175 | command_malloc_verify (object *op, char *parms) |
|
|
176 | { |
|
|
177 | extern int malloc_verify (void); |
|
|
178 | |
|
|
179 | if (!malloc_verify ()) |
|
|
180 | new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted."); |
|
|
181 | else |
|
|
182 | new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK."); |
|
|
183 | return 1; |
|
|
184 | } |
|
|
185 | #endif |
|
|
186 | |
|
|
187 | int |
|
|
188 | command_whereabouts (object *op, char *params) |
|
|
189 | { |
|
|
190 | |
|
|
191 | region *reg; |
|
|
192 | player *pl; |
|
|
193 | |
|
|
194 | /* |
|
|
195 | * reset the counter on the region, then use it to store the number of |
|
|
196 | * players there. |
|
|
197 | * I don't know how thread-safe this would be, I suspect not very.... |
|
|
198 | */ |
|
|
199 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
200 | { |
|
|
201 | reg->counter = 0; |
|
|
202 | } |
|
|
203 | for (pl = first_player; pl != NULL; pl = pl->next) |
|
|
204 | if (pl->ob->map != NULL) |
|
|
205 | get_region_by_map (pl->ob->map)->counter++; |
|
|
206 | |
|
|
207 | /* we only want to print out by places with a 'longname' field... */ |
|
|
208 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
209 | { |
|
|
210 | if (reg->longname == NULL && reg->counter > 0) |
|
|
211 | { |
|
|
212 | if (reg->parent != NULL) |
|
|
213 | { |
|
|
214 | reg->parent->counter += reg->counter; |
|
|
215 | reg->counter = 0; |
|
|
216 | } |
|
|
217 | else /*uh oh, we shouldn't be here. */ |
|
|
218 | LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name); |
|
|
219 | } |
|
|
220 | } |
|
|
221 | new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); |
|
|
222 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
223 | if (reg->counter > 0) |
|
|
224 | new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg)); |
|
|
225 | return 1; |
|
|
226 | } |
|
|
227 | |
30 | |
228 | typedef struct |
31 | typedef struct |
229 | { |
32 | { |
230 | char namebuf[MAX_BUF]; |
33 | char namebuf[MAX_BUF]; |
231 | int login_order; |
34 | int login_order; |
232 | } chars_names; |
35 | } chars_names; |
233 | |
36 | |
234 | /*local functon for qsort comparison*/ |
|
|
235 | static int |
|
|
236 | name_cmp (const chars_names * c1, const chars_names * c2) |
|
|
237 | { |
|
|
238 | return strcasecmp (c1->namebuf, c2->namebuf); |
|
|
239 | } |
|
|
240 | |
|
|
241 | int |
|
|
242 | command_who (object *op, char *params) |
|
|
243 | { |
|
|
244 | player *pl; |
|
|
245 | uint16 i; |
|
|
246 | region *reg; |
|
|
247 | char *format; |
|
|
248 | int num_players = 0; |
|
|
249 | int num_wiz = 0; |
|
|
250 | int num_afk = 0; |
|
|
251 | chars_names *chars = NULL; |
|
|
252 | |
|
|
253 | /* |
|
|
254 | * The who formats are defined in config to be blank. They should have been |
|
|
255 | * overridden by the settings file, if there are no entries however, it will |
|
|
256 | * have stayed blank. Since this probably isn't what is wanted, we will check if |
|
|
257 | * new formats have been specified, and if not we will use the old defaults. |
|
|
258 | */ |
|
|
259 | if (!strcmp (settings.who_format, "")) |
|
|
260 | strcpy (settings.who_format, "%N_%T%t%h%d%n[%m]"); |
|
|
261 | if (!strcmp (settings.who_wiz_format, "")) |
|
|
262 | strcpy (settings.who_wiz_format, "%N_%T%t%h%d%nLevel %l [%m](@%i)(%c)"); |
|
|
263 | if (op == NULL || QUERY_FLAG (op, FLAG_WIZ)) |
|
|
264 | format = settings.who_wiz_format; |
|
|
265 | else |
|
|
266 | format = settings.who_format; |
|
|
267 | |
|
|
268 | reg = get_region_from_string (params); |
|
|
269 | |
|
|
270 | for (pl = first_player; pl != NULL; pl = pl->next) |
|
|
271 | { |
|
|
272 | if (pl->ob->map == NULL) |
|
|
273 | continue; |
|
|
274 | if (pl->hidden && !QUERY_FLAG (op, FLAG_WIZ)) |
|
|
275 | continue; |
|
|
276 | |
|
|
277 | if (!region_is_child_of_region (get_region_by_map (pl->ob->map), reg)) |
|
|
278 | continue; |
|
|
279 | |
|
|
280 | if (pl->state == ST_PLAYING || pl->state == ST_GET_PARTY_PASSWORD) |
|
|
281 | { |
|
|
282 | |
|
|
283 | num_players++; |
|
|
284 | chars = (chars_names *) realloc (chars, num_players * sizeof (chars_names)); |
|
|
285 | if (chars == NULL) |
|
|
286 | { |
|
|
287 | new_draw_info (NDI_UNIQUE, 0, op, "who failed - out of memory!"); |
|
|
288 | return 0; |
|
|
289 | } |
|
|
290 | sprintf (chars[num_players - 1].namebuf, "%s", &pl->ob->name); |
|
|
291 | chars[num_players - 1].login_order = num_players; |
|
|
292 | /*Check for WIZ's & AFK's */ |
|
|
293 | if (QUERY_FLAG (pl->ob, FLAG_WIZ)) |
|
|
294 | num_wiz++; |
|
|
295 | if (QUERY_FLAG (pl->ob, FLAG_AFK)) |
|
|
296 | num_afk++; |
|
|
297 | } |
|
|
298 | } |
|
|
299 | if (first_player != (player *) NULL) |
|
|
300 | { |
|
|
301 | if (reg == NULL) |
|
|
302 | new_draw_info_format (NDI_UNIQUE, 0, op, "Total Players (%d) -- WIZ(%d) AFK(%d)", num_players, num_wiz, num_afk); |
|
|
303 | else if (reg->longname == NULL) |
|
|
304 | new_draw_info_format (NDI_UNIQUE, 0, op, "Total Players in %s (%d) -- WIZ(%d) AFK(%d)", reg->name, num_players, num_wiz, num_afk); |
|
|
305 | else |
|
|
306 | new_draw_info_format (NDI_UNIQUE, 0, op, "Total Players in %s (%d) -- WIZ(%d) AFK(%d)", |
|
|
307 | reg->longname, num_players, num_wiz, num_afk); |
|
|
308 | } |
|
|
309 | qsort (chars, num_players, sizeof (chars_names), (int (*)(const void *, const void *)) name_cmp); |
|
|
310 | for (i = 0; i < num_players; i++) |
|
|
311 | display_who_entry (op, find_player (chars[i].namebuf), format); |
|
|
312 | free (chars); |
|
|
313 | return 1; |
|
|
314 | } |
|
|
315 | |
|
|
316 | /* Display a line of 'who' to op, about pl, using the formatting specified by format */ |
|
|
317 | void |
|
|
318 | display_who_entry (object *op, player *pl, const char *format) |
|
|
319 | { |
|
|
320 | char tmpbuf[MAX_BUF]; |
|
|
321 | char outbuf[MAX_BUF]; |
|
|
322 | size_t i; |
|
|
323 | |
|
|
324 | outbuf[0] = '\0'; /* we strcat to this, so reset it here. */ |
|
|
325 | if (pl == NULL) |
|
|
326 | { |
|
|
327 | LOG (llevError, "display_who_entry(): I was passed a null player"); |
|
|
328 | return; |
|
|
329 | } |
|
|
330 | for (i = 0; i <= strlen (format); i++) |
|
|
331 | { |
|
|
332 | if (format[i] == '%') |
|
|
333 | { |
|
|
334 | i++; |
|
|
335 | get_who_escape_code_value (tmpbuf, format[i], pl); |
|
|
336 | strcat (outbuf, tmpbuf); |
|
|
337 | } |
|
|
338 | else if (format[i] == '_') |
|
|
339 | strcat (outbuf, " "); /* allow '_' to be used in place of spaces */ |
|
|
340 | else |
|
|
341 | { |
|
|
342 | sprintf (tmpbuf, "%c", format[i]); |
|
|
343 | strcat (outbuf, tmpbuf); |
|
|
344 | } |
|
|
345 | } |
|
|
346 | new_draw_info (NDI_UNIQUE, 0, op, outbuf); |
|
|
347 | } |
|
|
348 | |
|
|
349 | /* Returns the value of the escape code used in the who format specifier |
|
|
350 | * the values are: |
|
|
351 | * N Name of character |
|
|
352 | * t title of character |
|
|
353 | * T the optional "the " sequence value (depend if player has own_title or not) |
|
|
354 | * c count |
|
|
355 | * n newline |
|
|
356 | * h [Hostile] if character is hostile, nothing otherwise |
|
|
357 | * d [WIZ] if character is a dm, nothing otherwise |
|
|
358 | * a [AFK] if character is afk, nothing otherwise |
|
|
359 | * l the level of the character |
|
|
360 | * m the map path the character is currently on |
|
|
361 | * M the map name of the map the character is currently on |
|
|
362 | * r the region name (eg scorn, wolfsburg) |
|
|
363 | * R the regional title (eg The Kingdom of Scorn, The Port of Wolfsburg) |
|
|
364 | * i player's ip adress |
|
|
365 | * % a literal % |
|
|
366 | * _ a literal underscore |
|
|
367 | */ |
|
|
368 | |
|
|
369 | void |
|
|
370 | get_who_escape_code_value (char *return_val, const char letter, player *pl) |
|
|
371 | { |
|
|
372 | |
|
|
373 | switch (letter) |
|
|
374 | { |
|
|
375 | case 'N': |
|
|
376 | strcpy (return_val, pl->ob->name); |
|
|
377 | break; |
|
|
378 | case 't': |
|
|
379 | strcpy (return_val, (pl->own_title[0] == '\0' ? pl->title : pl->own_title)); |
|
|
380 | break; |
|
|
381 | case 'T': |
|
|
382 | if (pl->own_title[0] == '\0') |
|
|
383 | strcpy (return_val, "the "); |
|
|
384 | else |
|
|
385 | *return_val = '\0'; |
|
|
386 | break; |
|
|
387 | case 'c': |
|
|
388 | sprintf (return_val, "%d", pl->ob->count); |
|
|
389 | break; |
|
|
390 | case 'n': |
|
|
391 | strcpy (return_val, "\n"); |
|
|
392 | break; |
|
|
393 | case 'h': |
|
|
394 | strcpy (return_val, pl->peaceful ? "" : " [Hostile]"); |
|
|
395 | break; |
|
|
396 | case 'l': |
|
|
397 | sprintf (return_val, "%d", pl->ob->level); |
|
|
398 | break; |
|
|
399 | case 'd': |
|
|
400 | strcpy (return_val, (QUERY_FLAG (pl->ob, FLAG_WIZ) ? " [WIZ]" : "")); |
|
|
401 | break; |
|
|
402 | case 'a': |
|
|
403 | strcpy (return_val, (QUERY_FLAG (pl->ob, FLAG_AFK) ? " [AFK]" : "")); |
|
|
404 | break; |
|
|
405 | case 'm': |
|
|
406 | strcpy (return_val, pl->ob->map->path); |
|
|
407 | break; |
|
|
408 | case 'M': |
|
|
409 | strcpy (return_val, pl->ob->map->name ? pl->ob->map->name : "Untitled"); |
|
|
410 | break; |
|
|
411 | case 'r': |
|
|
412 | strcpy (return_val, get_name_of_region_for_map (pl->ob->map)); |
|
|
413 | break; |
|
|
414 | case 'R': |
|
|
415 | strcpy (return_val, get_region_longname (get_region_by_map (pl->ob->map))); |
|
|
416 | break; |
|
|
417 | case 'i': |
|
|
418 | strcpy (return_val, pl->socket.host); |
|
|
419 | break; |
|
|
420 | case '%': |
|
|
421 | strcpy (return_val, "%"); |
|
|
422 | break; |
|
|
423 | case '_': |
|
|
424 | strcpy (return_val, "_"); |
|
|
425 | break; |
|
|
426 | } |
|
|
427 | |
|
|
428 | } |
|
|
429 | |
|
|
430 | |
|
|
431 | int |
|
|
432 | command_afk (object *op, char *params) |
|
|
433 | { |
|
|
434 | if QUERY_FLAG |
|
|
435 | (op, FLAG_AFK) |
|
|
436 | { |
|
|
437 | CLEAR_FLAG (op, FLAG_AFK); |
|
|
438 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK"); |
|
|
439 | } |
|
|
440 | else |
|
|
441 | { |
|
|
442 | SET_FLAG (op, FLAG_AFK); |
|
|
443 | new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK"); |
|
|
444 | } |
|
|
445 | return 1; |
|
|
446 | } |
|
|
447 | |
|
|
448 | int |
|
|
449 | command_mapinfo (object *op, char *params) |
|
|
450 | { |
|
|
451 | current_map_info (op); |
|
|
452 | return 1; |
|
|
453 | } |
|
|
454 | |
|
|
455 | int |
|
|
456 | command_whereami (object *op, char *params) |
|
|
457 | { |
|
|
458 | current_region_info (op); |
|
|
459 | return 1; |
|
|
460 | } |
|
|
461 | |
|
|
462 | int |
|
|
463 | command_maps (object *op, char *params) |
|
|
464 | { |
|
|
465 | map_info (op, params); |
|
|
466 | return 1; |
|
|
467 | } |
|
|
468 | |
|
|
469 | int |
37 | int |
470 | command_time (object *op, char *params) |
38 | command_time (object *op, char *params) |
471 | { |
39 | { |
472 | print_tod (op); |
40 | print_tod (op); |
473 | return 1; |
|
|
474 | } |
|
|
475 | |
|
|
476 | int |
|
|
477 | command_weather (object *op, char *params) |
|
|
478 | { |
|
|
479 | int wx, wy, temp, sky; |
|
|
480 | char buf[MAX_BUF]; |
|
|
481 | |
|
|
482 | if (settings.dynamiclevel < 1) |
|
|
483 | return 1; |
|
|
484 | |
|
|
485 | if (op->map == NULL) |
|
|
486 | return 1; |
|
|
487 | |
|
|
488 | if (worldmap_to_weathermap (op->x, op->y, &wx, &wy, op->map) != 0) |
|
|
489 | return 1; |
|
|
490 | |
|
|
491 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
492 | { |
|
|
493 | /* dump the weather, Dm style! Yo! */ |
|
|
494 | new_draw_info_format (NDI_UNIQUE, 0, op, "Real temp: %d", real_world_temperature (op->x, op->y, op->map)); |
|
|
495 | new_draw_info_format (NDI_UNIQUE, 0, op, "Base temp: %d", weathermap[wx][wy].temp); |
|
|
496 | new_draw_info_format (NDI_UNIQUE, 0, op, "Humid: %d", weathermap[wx][wy].humid); |
|
|
497 | new_draw_info_format (NDI_UNIQUE, 0, op, "Wind: dir=%d speed=%d", weathermap[wx][wy].winddir, weathermap[wx][wy].windspeed); |
|
|
498 | new_draw_info_format (NDI_UNIQUE, 0, op, "Pressure: %d", weathermap[wx][wy].pressure); |
|
|
499 | new_draw_info_format (NDI_UNIQUE, 0, op, "Avg Elevation: %d", weathermap[wx][wy].avgelev); |
|
|
500 | new_draw_info_format (NDI_UNIQUE, 0, op, "Rainfall: %d Water: %d", weathermap[wx][wy].rainfall, weathermap[wx][wy].water); |
|
|
501 | } |
|
|
502 | |
|
|
503 | temp = real_world_temperature (op->x, op->y, op->map); |
|
|
504 | new_draw_info_format (NDI_UNIQUE, 0, op, "It's currently %d degrees " "Centigrade out.", temp); |
|
|
505 | |
|
|
506 | /* humid */ |
|
|
507 | if (weathermap[wx][wy].humid < 20) |
|
|
508 | new_draw_info (NDI_UNIQUE, 0, op, "It is very dry."); |
|
|
509 | else if (weathermap[wx][wy].humid < 40) |
|
|
510 | new_draw_info (NDI_UNIQUE, 0, op, "It is very comfortable today."); |
|
|
511 | else if (weathermap[wx][wy].humid < 60) |
|
|
512 | new_draw_info (NDI_UNIQUE, 0, op, "It is a bit muggy."); |
|
|
513 | else if (weathermap[wx][wy].humid < 80) |
|
|
514 | new_draw_info (NDI_UNIQUE, 0, op, "It is muggy."); |
|
|
515 | else |
|
|
516 | new_draw_info (NDI_UNIQUE, 0, op, "It is uncomfortably muggy."); |
|
|
517 | |
|
|
518 | /* wind */ |
|
|
519 | switch (weathermap[wx][wy].winddir) |
|
|
520 | { |
|
|
521 | case 1: |
|
|
522 | sprintf (buf, "north"); |
|
|
523 | break; |
|
|
524 | case 2: |
|
|
525 | sprintf (buf, "northeast"); |
|
|
526 | break; |
|
|
527 | case 3: |
|
|
528 | sprintf (buf, "east"); |
|
|
529 | break; |
|
|
530 | case 4: |
|
|
531 | sprintf (buf, "southeast"); |
|
|
532 | break; |
|
|
533 | case 5: |
|
|
534 | sprintf (buf, "south"); |
|
|
535 | break; |
|
|
536 | case 6: |
|
|
537 | sprintf (buf, "southwest"); |
|
|
538 | break; |
|
|
539 | case 7: |
|
|
540 | sprintf (buf, "west"); |
|
|
541 | break; |
|
|
542 | case 8: |
|
|
543 | sprintf (buf, "northwest"); |
|
|
544 | break; |
|
|
545 | } |
|
|
546 | if (weathermap[wx][wy].windspeed < 5) |
|
|
547 | new_draw_info_format (NDI_UNIQUE, 0, op, "There is a mild breeze " "coming from the %s.", buf); |
|
|
548 | else if (weathermap[wx][wy].windspeed < 10) |
|
|
549 | new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong breeze " "coming from the %s.", buf); |
|
|
550 | else if (weathermap[wx][wy].windspeed < 15) |
|
|
551 | new_draw_info_format (NDI_UNIQUE, 0, op, "There is a light wind " "coming from the %s.", buf); |
|
|
552 | else if (weathermap[wx][wy].windspeed < 25) |
|
|
553 | new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong wind " "coming from the %s.", buf); |
|
|
554 | else if (weathermap[wx][wy].windspeed < 35) |
|
|
555 | new_draw_info_format (NDI_UNIQUE, 0, op, "There is a heavy wind " "coming from the %s.", buf); |
|
|
556 | else |
|
|
557 | new_draw_info_format (NDI_UNIQUE, 0, op, "The wind from the %s is " "incredibly strong!", buf); |
|
|
558 | |
|
|
559 | sky = weathermap[wx][wy].sky; |
|
|
560 | if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG) |
|
|
561 | sky += 10; /*let it snow */ |
|
|
562 | switch (sky) |
|
|
563 | { |
|
|
564 | case SKY_CLEAR: |
|
|
565 | new_draw_info (NDI_UNIQUE, 0, op, "There isn''t a cloud in the sky."); |
|
|
566 | break; |
|
|
567 | case SKY_LIGHTCLOUD: |
|
|
568 | new_draw_info (NDI_UNIQUE, 0, op, "There are a few light clouds in the sky."); |
|
|
569 | break; |
|
|
570 | case SKY_OVERCAST: |
|
|
571 | new_draw_info (NDI_UNIQUE, 0, op, "The sky is cloudy and dreary."); |
|
|
572 | break; |
|
|
573 | case SKY_LIGHT_RAIN: |
|
|
574 | new_draw_info (NDI_UNIQUE, 0, op, "It is raining softly."); |
|
|
575 | break; |
|
|
576 | case SKY_RAIN: |
|
|
577 | new_draw_info (NDI_UNIQUE, 0, op, "It is raining."); |
|
|
578 | break; |
|
|
579 | case SKY_HEAVY_RAIN: |
|
|
580 | new_draw_info (NDI_UNIQUE, 0, op, "It is raining heavily."); |
|
|
581 | break; |
|
|
582 | case SKY_HURRICANE: |
|
|
583 | new_draw_info (NDI_UNIQUE, 0, op, "There is a heavy storm! You should go inside!"); |
|
|
584 | break; |
|
|
585 | case SKY_FOG: |
|
|
586 | new_draw_info (NDI_UNIQUE, 0, op, "It''s foggy and miserable."); |
|
|
587 | break; |
|
|
588 | case SKY_HAIL: |
|
|
589 | new_draw_info (NDI_UNIQUE, 0, op, "It''s hailing out! Take cover!"); |
|
|
590 | break; |
|
|
591 | case SKY_LIGHT_SNOW: |
|
|
592 | new_draw_info (NDI_UNIQUE, 0, op, "Snow is gently falling from the sky."); |
|
|
593 | break; |
|
|
594 | case SKY_SNOW: |
|
|
595 | new_draw_info (NDI_UNIQUE, 0, op, "It''s snowing out."); |
|
|
596 | break; |
|
|
597 | case SKY_HEAVY_SNOW: |
|
|
598 | new_draw_info (NDI_UNIQUE, 0, op, "The snow is falling very heavily now."); |
|
|
599 | break; |
|
|
600 | case SKY_BLIZZARD: |
|
|
601 | new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!"); |
|
|
602 | break; |
|
|
603 | } |
|
|
604 | return 1; |
|
|
605 | } |
|
|
606 | |
|
|
607 | int |
|
|
608 | command_archs (object *op, char *params) |
|
|
609 | { |
|
|
610 | arch_info (op); |
|
|
611 | return 1; |
|
|
612 | } |
|
|
613 | |
|
|
614 | int |
|
|
615 | command_hiscore (object *op, char *params) |
|
|
616 | { |
|
|
617 | display_high_score (op, op == NULL ? 9999 : 50, params); |
|
|
618 | return 1; |
41 | return 1; |
619 | } |
42 | } |
620 | |
43 | |
621 | int |
44 | int |
622 | command_debug (object *op, char *params) |
45 | command_debug (object *op, char *params) |
… | |
… | |
628 | { |
51 | { |
629 | sprintf (buf, "Global debug level is %d.", settings.debug); |
52 | sprintf (buf, "Global debug level is %d.", settings.debug); |
630 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
53 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
631 | return 1; |
54 | return 1; |
632 | } |
55 | } |
633 | if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) |
56 | |
634 | { |
57 | settings.debug = i; |
635 | new_draw_info (NDI_UNIQUE, 0, op, "Privileged command."); |
58 | |
636 | return 1; |
|
|
637 | } |
|
|
638 | settings.debug = (enum LogLevel) FABS (i); |
|
|
639 | sprintf (buf, "Set debug level to %d.", i); |
59 | sprintf (buf, "Set debug level to %d.", i); |
640 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
60 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
641 | return 1; |
61 | return 1; |
642 | } |
62 | } |
643 | |
|
|
644 | |
63 | |
645 | /* |
64 | /* |
646 | * Those dumps should be just one dump with good parser |
65 | * Those dumps should be just one dump with good parser |
647 | */ |
66 | */ |
648 | |
67 | |
649 | int |
68 | int |
650 | command_dumpbelow (object *op, char *params) |
69 | command_dumpbelow (object *op, char *params) |
651 | { |
70 | { |
652 | if (op && op->below) |
71 | if (op && op->below) |
653 | { |
72 | { |
654 | dump_object (op->below); |
73 | char *dump = dump_object (op->below); |
655 | new_draw_info (NDI_UNIQUE, 0, op, errmsg); |
74 | new_draw_info (NDI_UNIQUE, 0, op, dump); |
|
|
75 | free (dump); |
656 | /* Let's push that item on the dm's stack */ |
76 | /* Let's push that item on the dm's stack */ |
657 | dm_stack_push (op->contr, op->below->count); |
77 | dm_stack_push (op->contr, op->below->count); |
658 | } |
78 | } |
659 | return 0; |
79 | return 0; |
660 | } |
80 | } |
661 | |
81 | |
662 | int |
82 | int |
663 | command_wizpass (object *op, char *params) |
|
|
664 | { |
|
|
665 | int i; |
|
|
666 | |
|
|
667 | if (!op) |
|
|
668 | return 0; |
|
|
669 | |
|
|
670 | if (!params) |
|
|
671 | i = (QUERY_FLAG (op, FLAG_WIZPASS)) ? 0 : 1; |
|
|
672 | else |
|
|
673 | i = onoff_value (params); |
|
|
674 | |
|
|
675 | if (i) |
|
|
676 | { |
|
|
677 | new_draw_info (NDI_UNIQUE, 0, op, "You will now walk through walls.\n"); |
|
|
678 | SET_FLAG (op, FLAG_WIZPASS); |
|
|
679 | } |
|
|
680 | else |
|
|
681 | { |
|
|
682 | new_draw_info (NDI_UNIQUE, 0, op, "You will now be stopped by walls.\n"); |
|
|
683 | CLEAR_FLAG (op, FLAG_WIZPASS); |
|
|
684 | } |
|
|
685 | return 0; |
|
|
686 | } |
|
|
687 | |
|
|
688 | int |
|
|
689 | command_wizcast (object *op, char *params) |
|
|
690 | { |
|
|
691 | int i; |
|
|
692 | |
|
|
693 | if (!op) |
|
|
694 | return 0; |
|
|
695 | |
|
|
696 | if (!params) |
|
|
697 | i = (QUERY_FLAG (op, FLAG_WIZCAST)) ? 0 : 1; |
|
|
698 | else |
|
|
699 | i = onoff_value (params); |
|
|
700 | |
|
|
701 | if (i) |
|
|
702 | { |
|
|
703 | new_draw_info (NDI_UNIQUE, 0, op, "You can now cast spells anywhere."); |
|
|
704 | SET_FLAG (op, FLAG_WIZCAST); |
|
|
705 | } |
|
|
706 | else |
|
|
707 | { |
|
|
708 | new_draw_info (NDI_UNIQUE, 0, op, "You now cannot cast spells in no-magic areas."); |
|
|
709 | CLEAR_FLAG (op, FLAG_WIZCAST); |
|
|
710 | } |
|
|
711 | return 0; |
|
|
712 | } |
|
|
713 | |
|
|
714 | int |
|
|
715 | command_dumpallobjects (object *op, char *params) |
|
|
716 | { |
|
|
717 | dump_all_objects (); |
|
|
718 | return 0; |
|
|
719 | } |
|
|
720 | |
|
|
721 | int |
|
|
722 | command_dumpfriendlyobjects (object *op, char *params) |
|
|
723 | { |
|
|
724 | dump_friendly_objects (); |
|
|
725 | return 0; |
|
|
726 | } |
|
|
727 | |
|
|
728 | int |
|
|
729 | command_dumpallarchetypes (object *op, char *params) |
|
|
730 | { |
|
|
731 | dump_all_archetypes (); |
|
|
732 | return 0; |
|
|
733 | } |
|
|
734 | |
|
|
735 | int |
|
|
736 | command_dumpmap (object *op, char *params) |
|
|
737 | { |
|
|
738 | if (op) |
|
|
739 | dump_map (op->map); |
|
|
740 | return 0; |
|
|
741 | } |
|
|
742 | |
|
|
743 | int |
|
|
744 | command_dumpallmaps (object *op, char *params) |
|
|
745 | { |
|
|
746 | dump_all_maps (); |
|
|
747 | return 0; |
|
|
748 | } |
|
|
749 | |
|
|
750 | int |
|
|
751 | command_printlos (object *op, char *params) |
|
|
752 | { |
|
|
753 | if (op) |
|
|
754 | print_los (op); |
|
|
755 | return 0; |
|
|
756 | } |
|
|
757 | |
|
|
758 | |
|
|
759 | int |
|
|
760 | command_version (object *op, char *params) |
83 | command_version (object *op, char *params) |
761 | { |
84 | { |
762 | version (op); |
85 | version (op); |
763 | return 0; |
86 | return 0; |
764 | } |
|
|
765 | |
|
|
766 | |
|
|
767 | #ifndef BUG_LOG |
|
|
768 | # define BUG_LOG "bug_log" |
|
|
769 | #endif |
|
|
770 | void |
|
|
771 | bug_report (const char *reportstring) |
|
|
772 | { |
|
|
773 | FILE *fp; |
|
|
774 | |
|
|
775 | if ((fp = fopen (BUG_LOG, "a")) != NULL) |
|
|
776 | { |
|
|
777 | fprintf (fp, "%s\n", reportstring); |
|
|
778 | fclose (fp); |
|
|
779 | } |
|
|
780 | else |
|
|
781 | { |
|
|
782 | LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno)); |
|
|
783 | } |
|
|
784 | } |
|
|
785 | |
|
|
786 | int |
|
|
787 | command_output_sync (object *op, char *params) |
|
|
788 | { |
|
|
789 | int val; |
|
|
790 | |
|
|
791 | if (!params) |
|
|
792 | { |
|
|
793 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync); |
|
|
794 | return 1; |
|
|
795 | } |
|
|
796 | val = atoi (params); |
|
|
797 | if (val > 0) |
|
|
798 | { |
|
|
799 | op->contr->outputs_sync = val; |
|
|
800 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync); |
|
|
801 | } |
|
|
802 | else |
|
|
803 | new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync."); |
|
|
804 | |
|
|
805 | return 1; |
|
|
806 | } |
|
|
807 | |
|
|
808 | int |
|
|
809 | command_output_count (object *op, char *params) |
|
|
810 | { |
|
|
811 | int val; |
|
|
812 | |
|
|
813 | if (!params) |
|
|
814 | { |
|
|
815 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count); |
|
|
816 | return 1; |
|
|
817 | } |
|
|
818 | val = atoi (params); |
|
|
819 | if (val > 0) |
|
|
820 | { |
|
|
821 | op->contr->outputs_count = val; |
|
|
822 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count); |
|
|
823 | } |
|
|
824 | else |
|
|
825 | new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count."); |
|
|
826 | |
|
|
827 | return 1; |
|
|
828 | } |
|
|
829 | |
|
|
830 | int |
|
|
831 | command_listen (object *op, char *params) |
|
|
832 | { |
|
|
833 | int i; |
|
|
834 | |
|
|
835 | if (params == NULL || !sscanf (params, "%d", &i)) |
|
|
836 | { |
|
|
837 | new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening); |
|
|
838 | return 1; |
|
|
839 | } |
|
|
840 | op->contr->listening = (char) i; |
|
|
841 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i); |
|
|
842 | return 1; |
|
|
843 | } |
87 | } |
844 | |
88 | |
845 | /* Prints out some useful information for the character. Everything we print |
89 | /* Prints out some useful information for the character. Everything we print |
846 | * out can be determined by the docs, so we aren't revealing anything extra - |
90 | * out can be determined by the docs, so we aren't revealing anything extra - |
847 | * rather, we are making it convenient to find the values. params have |
91 | * rather, we are making it convenient to find the values. params have |
… | |
… | |
850 | int |
94 | int |
851 | command_statistics (object *pl, char *params) |
95 | command_statistics (object *pl, char *params) |
852 | { |
96 | { |
853 | if (!pl->contr) |
97 | if (!pl->contr) |
854 | return 1; |
98 | return 1; |
855 | #ifndef WIN32 |
|
|
856 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %lld", pl->stats.exp); |
|
|
857 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %lld", level_exp (pl->level + 1, pl->expmul)); |
|
|
858 | #else |
|
|
859 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %I64d", pl->stats.exp); |
|
|
860 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %I64d", level_exp (pl->level + 1, pl->expmul)); |
|
|
861 | #endif |
|
|
862 | new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); |
|
|
863 | |
99 | |
864 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", |
100 | dynbuf_text &msg = msg_dynbuf; msg.clear (); |
865 | pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); |
101 | |
866 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", |
102 | msg << " Experience: " << pl->stats.exp << '\n' |
867 | pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex); |
103 | << " Next Level: " << level_exp (pl->level + 1, pl->expmul) << '\n' |
868 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d", |
104 | << "\n Stat Nat/Real/Max\n"; |
869 | pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con); |
105 | |
870 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d", |
106 | for (int i = 0; i < NUM_STATS; ++i) |
871 | pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int); |
107 | msg.printf (" %s %2d/ %3d/%3d\n", short_stat_name [i], pl->contr->orig_stats.stat (i), pl->stats.stat (i), 20 + pl->arch->stats.stat (i)); |
872 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d", |
108 | |
873 | pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis); |
109 | msg << "\nYou are " << (pl->contr->peaceful ? "peaceful" : "hostile") << '.'; |
874 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d", |
110 | |
875 | pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow); |
111 | pl->contr->infobox (MSG_CHANNEL ("statistics"), msg); |
876 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d", |
|
|
877 | pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->clone.stats.Cha); |
|
|
878 | new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile"); |
|
|
879 | |
112 | |
880 | /* Can't think of anything else to print right now */ |
113 | /* Can't think of anything else to print right now */ |
881 | return 0; |
114 | return 0; |
882 | } |
115 | } |
883 | |
116 | |
884 | int |
117 | int |
885 | command_fix_me (object *op, char *params) |
118 | command_fix_me (object *op, char *params) |
886 | { |
119 | { |
887 | sum_weight (op); |
120 | op->update_weight (); |
888 | fix_player (op); |
121 | op->update_stats (); |
889 | return 1; |
122 | new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed."); |
890 | } |
|
|
891 | |
123 | |
892 | int |
|
|
893 | command_players (object *op, char *paramss) |
|
|
894 | { |
|
|
895 | char buf[MAX_BUF]; |
|
|
896 | char *t; |
|
|
897 | DIR *Dir; |
|
|
898 | |
|
|
899 | sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir); |
|
|
900 | t = buf + strlen (buf); |
|
|
901 | if ((Dir = opendir (buf)) != NULL) |
|
|
902 | { |
|
|
903 | const struct dirent *Entry; |
|
|
904 | |
|
|
905 | while ((Entry = readdir (Dir)) != NULL) |
|
|
906 | { |
|
|
907 | /* skip '.' , '..' */ |
|
|
908 | if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') || |
|
|
909 | (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0'))) |
|
|
910 | { |
|
|
911 | struct stat Stat; |
|
|
912 | |
|
|
913 | strcpy (t, Entry->d_name); |
|
|
914 | if (stat (buf, &Stat) == 0) |
|
|
915 | { |
|
|
916 | /* This was not posix compatible |
|
|
917 | * if ((Stat.st_mode & S_IFMT)==S_IFDIR) { |
|
|
918 | */ |
|
|
919 | if (S_ISDIR (Stat.st_mode)) |
|
|
920 | { |
|
|
921 | char buf2[MAX_BUF]; |
|
|
922 | struct tm *tm = localtime (&Stat.st_mtime); |
|
|
923 | |
|
|
924 | sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d", |
|
|
925 | Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); |
|
|
926 | new_draw_info (NDI_UNIQUE, 0, op, buf2); |
|
|
927 | } |
|
|
928 | } |
|
|
929 | } |
|
|
930 | } |
|
|
931 | } |
|
|
932 | closedir (Dir); |
|
|
933 | return 0; |
|
|
934 | } |
|
|
935 | |
|
|
936 | |
|
|
937 | |
|
|
938 | int |
|
|
939 | command_logs (object *op, char *params) |
|
|
940 | { |
|
|
941 | int i; |
|
|
942 | int first; |
|
|
943 | |
|
|
944 | first = 1; |
|
|
945 | for (i = 2; i < socket_info.allocated_sockets; i++) |
|
|
946 | { |
|
|
947 | if (init_sockets[i].old_mode == Old_Listen) |
|
|
948 | { |
|
|
949 | if (first) |
|
|
950 | { |
|
|
951 | new_draw_info (NDI_UNIQUE, 0, op, "Kill-logs are sent to:"); |
|
|
952 | first = 0; |
|
|
953 | } |
|
|
954 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %s", init_sockets[i].host, init_sockets[i].comment); |
|
|
955 | } |
|
|
956 | } |
|
|
957 | if (first) |
|
|
958 | { |
|
|
959 | new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); |
|
|
960 | } |
|
|
961 | return 1; |
|
|
962 | } |
|
|
963 | |
|
|
964 | int |
|
|
965 | command_applymode (object *op, char *params) |
|
|
966 | { |
|
|
967 | unapplymode unapply = op->contr->unapply; |
|
|
968 | static const char *const types[] = { "nochoice", "never", "always" }; |
|
|
969 | |
|
|
970 | if (!params) |
|
|
971 | { |
|
|
972 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]); |
|
|
973 | return 1; |
|
|
974 | } |
|
|
975 | |
|
|
976 | if (!strcmp (params, "nochoice")) |
|
|
977 | op->contr->unapply = unapply_nochoice; |
|
|
978 | else if (!strcmp (params, "never")) |
|
|
979 | op->contr->unapply = unapply_never; |
|
|
980 | else if (!strcmp (params, "always")) |
|
|
981 | op->contr->unapply = unapply_always; |
|
|
982 | else |
|
|
983 | { |
|
|
984 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params); |
|
|
985 | return 0; |
|
|
986 | } |
|
|
987 | new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s", |
|
|
988 | (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]); |
|
|
989 | return 1; |
124 | return 1; |
990 | } |
125 | } |
991 | |
126 | |
992 | int |
127 | int |
993 | command_bowmode (object *op, char *params) |
128 | command_bowmode (object *op, char *params) |
994 | { |
129 | { |
995 | bowtype_t oldtype = op->contr->bowtype; |
130 | bowtype_t oldtype = op->contr->bowtype; |
996 | static const char *const types[] = { "normal", "threewide", "spreadshot", "firenorth", |
131 | static const char *const types[] = { |
|
|
132 | "normal", "threewide", "spreadshot", "firenorth", |
997 | "firene", "fireeast", "firese", "firesouth", |
133 | "firene", "fireeast", "firese", "firesouth", |
998 | "firesw", "firewest", "firenw", "bestarrow" |
134 | "firesw", "firewest", "firenw", "bestarrow" |
999 | }; |
135 | }; |
1000 | char buf[MAX_BUF]; |
136 | char buf[MAX_BUF]; |
1001 | int i, found; |
137 | int i, found; |
… | |
… | |
1013 | found++; |
149 | found++; |
1014 | op->contr->bowtype = (bowtype_t) i; |
150 | op->contr->bowtype = (bowtype_t) i; |
1015 | break; |
151 | break; |
1016 | } |
152 | } |
1017 | } |
153 | } |
|
|
154 | |
1018 | if (!found) |
155 | if (!found) |
1019 | { |
156 | { |
1020 | sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
157 | sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
|
|
158 | |
1021 | for (i = 0; i <= bow_bestarrow; i++) |
159 | for (i = 0; i <= bow_bestarrow; i++) |
1022 | { |
160 | { |
1023 | strcat (buf, " "); |
161 | strcat (buf, " "); |
1024 | strcat (buf, types[i]); |
162 | strcat (buf, types[i]); |
1025 | if (i < bow_nw) |
163 | if (i < bow_nw) |
… | |
… | |
1028 | strcat (buf, "."); |
166 | strcat (buf, "."); |
1029 | } |
167 | } |
1030 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
168 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
1031 | return 0; |
169 | return 0; |
1032 | } |
170 | } |
|
|
171 | |
1033 | new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
172 | new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
1034 | return 1; |
173 | return 1; |
1035 | } |
174 | } |
1036 | |
175 | |
1037 | int |
176 | int |
1038 | command_petmode (object *op, char *params) |
|
|
1039 | { |
|
|
1040 | petmode_t oldtype = op->contr->petmode; |
|
|
1041 | static const char *const types[] = { "normal", "sad", "defend", "arena" }; |
|
|
1042 | |
|
|
1043 | if (!params) |
|
|
1044 | { |
|
|
1045 | new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]); |
|
|
1046 | return 1; |
|
|
1047 | } |
|
|
1048 | |
|
|
1049 | if (!strcmp (params, "normal")) |
|
|
1050 | op->contr->petmode = pet_normal; |
|
|
1051 | else if (!strcmp (params, "sad")) |
|
|
1052 | op->contr->petmode = pet_sad; |
|
|
1053 | else if (!strcmp (params, "defend")) |
|
|
1054 | op->contr->petmode = pet_defend; |
|
|
1055 | else if (!strcmp (params, "arena")) |
|
|
1056 | op->contr->petmode = pet_arena; |
|
|
1057 | else |
|
|
1058 | { |
|
|
1059 | new_draw_info_format (NDI_UNIQUE, 0, op, |
|
|
1060 | "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params); |
|
|
1061 | return 0; |
|
|
1062 | } |
|
|
1063 | new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]); |
|
|
1064 | return 1; |
|
|
1065 | } |
|
|
1066 | |
|
|
1067 | int |
|
|
1068 | command_showpets (object *op, char *params) |
177 | command_showpets (object *op, char *params) |
1069 | { |
178 | { |
1070 | objectlink *obl, *next; |
|
|
1071 | int counter = 0, target = 0; |
179 | int counter = 0, target = 0; |
1072 | int have_shown_pet = 0; |
180 | int have_shown_pet = 0; |
1073 | |
181 | |
|
|
182 | dynbuf_text &msg = msg_dynbuf; msg.clear (); |
|
|
183 | |
1074 | if (params != NULL) |
184 | if (params) |
1075 | target = atoi (params); |
185 | target = atoi (params); |
|
|
186 | |
1076 | for (obl = first_friendly_object; obl != NULL; obl = next) |
187 | for (objectlink *obl = first_friendly_object; obl; obl = obl->next) |
1077 | { |
188 | { |
1078 | object *ob = obl->ob; |
189 | object *ob = obl->ob; |
1079 | |
190 | |
1080 | next = obl->next; |
|
|
1081 | if (get_owner (ob) == op) |
191 | if (ob->owner == op) |
1082 | { |
192 | { |
1083 | if (target == 0) |
193 | if (target == 0) |
1084 | { |
194 | { |
1085 | if (counter == 0) |
195 | if (counter == 0) |
1086 | new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); |
196 | msg << "T<Pets>\n\n"; |
|
|
197 | |
1087 | new_draw_info_format (NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, &ob->name, ob->level); |
198 | msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level); |
1088 | } |
199 | } |
1089 | else if (!have_shown_pet && ++counter == target) |
200 | else if (!have_shown_pet && ++counter == target) |
1090 | { |
201 | { |
1091 | new_draw_info_format (NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name); |
202 | msg.printf ("T<%s>\n\n" |
1092 | new_draw_info_format (NDI_UNIQUE, 0, op, "%d/%d HP, %d/%d SP", ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp); |
203 | " level %d\n" |
1093 | /* this is not a nice way to do this, it should be made to be more like the statistics command */ |
204 | " %d/%d HP, %d/%d SP\n" |
1094 | new_draw_info_format (NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str); |
205 | " Str %2d\n" |
1095 | new_draw_info_format (NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex); |
206 | " Dex %2d\n" |
1096 | new_draw_info_format (NDI_UNIQUE, 0, op, "Con %d", ob->stats.Con); |
207 | " Con %2d\n" |
1097 | new_draw_info_format (NDI_UNIQUE, 0, op, "Int %d", ob->stats.Int); |
208 | " Int %2d\n" |
1098 | new_draw_info_format (NDI_UNIQUE, 0, op, "Wis %d", ob->stats.Wis); |
209 | " Wis %2d\n" |
1099 | new_draw_info_format (NDI_UNIQUE, 0, op, "Cha %d", ob->stats.Cha); |
210 | " Cha %2d\n" |
1100 | new_draw_info_format (NDI_UNIQUE, 0, op, "Pow %d", ob->stats.Pow); |
211 | " Pow %2d\n" |
1101 | new_draw_info_format (NDI_UNIQUE, 0, op, "wc %d damage %d ac %d ", ob->stats.wc, ob->stats.dam, ob->stats.ac); |
212 | " wc %d damage %d ac %d\n", |
|
|
213 | &ob->name, |
|
|
214 | &ob->name, |
|
|
215 | ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp, |
|
|
216 | ob->stats.Str, |
|
|
217 | ob->stats.Dex, |
|
|
218 | ob->stats.Con, |
|
|
219 | ob->stats.Int, |
|
|
220 | ob->stats.Wis, |
|
|
221 | ob->stats.Cha, |
|
|
222 | ob->stats.Pow, |
|
|
223 | ob->stats.wc, ob->stats.dam, ob->stats.ac); |
|
|
224 | |
1102 | have_shown_pet = 1; |
225 | have_shown_pet = 1; |
1103 | } |
226 | } |
1104 | } |
227 | } |
1105 | } |
228 | } |
|
|
229 | |
1106 | if (counter == 0) |
230 | if (counter == 0) |
1107 | new_draw_info (NDI_UNIQUE, 0, op, "you have no pets."); |
231 | msg << "you have no pets."; |
1108 | else if (target != 0 && have_shown_pet == 0) |
232 | else if (target != 0 && have_shown_pet == 0) |
1109 | new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); |
233 | msg << "no such pet."; |
1110 | return 0; |
|
|
1111 | } |
|
|
1112 | |
234 | |
1113 | int |
235 | op->contr->infobox (MSG_CHANNEL ("pets"), msg); |
1114 | command_usekeys (object *op, char *params) |
|
|
1115 | { |
|
|
1116 | usekeytype oldtype = op->contr->usekeys; |
|
|
1117 | static const char *const types[] = { "inventory", "keyrings", "containers" }; |
|
|
1118 | |
236 | |
1119 | if (!params) |
|
|
1120 | { |
|
|
1121 | new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]); |
|
|
1122 | return 1; |
|
|
1123 | } |
|
|
1124 | |
|
|
1125 | if (!strcmp (params, "inventory")) |
|
|
1126 | op->contr->usekeys = key_inventory; |
|
|
1127 | else if (!strcmp (params, "keyrings")) |
|
|
1128 | op->contr->usekeys = keyrings; |
|
|
1129 | else if (!strcmp (params, "containers")) |
|
|
1130 | op->contr->usekeys = containers; |
|
|
1131 | else |
|
|
1132 | { |
|
|
1133 | new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params); |
|
|
1134 | return 0; |
|
|
1135 | } |
|
|
1136 | new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]); |
|
|
1137 | return 1; |
237 | return 0; |
1138 | } |
238 | } |
1139 | |
239 | |
1140 | int |
240 | int |
1141 | command_resistances (object *op, char *params) |
241 | command_resistances (object *op, char *params) |
1142 | { |
242 | { |
1143 | int i; |
243 | dynbuf_text &msg = msg_dynbuf; msg.clear (); |
1144 | |
244 | |
1145 | if (!op) |
245 | msg << "Resistances:\n\n"; |
1146 | return 0; |
|
|
1147 | |
246 | |
1148 | for (i = 0; i < NROFATTACKS; i++) |
247 | for (int i = 0; i < NROFATTACKS; i++) |
1149 | { |
|
|
1150 | if (i == ATNR_INTERNAL) |
248 | if (i != ATNR_INTERNAL) |
1151 | continue; |
249 | msg.printf (" %-20s %+4d\n", attacktype_desc [i], op->resist [i]); |
1152 | |
|
|
1153 | new_draw_info_format (NDI_UNIQUE, 0, op, "%-20s %+5d", attacktype_desc[i], op->resist[i]); |
|
|
1154 | } |
|
|
1155 | |
250 | |
1156 | /* If dragon player, let's display natural resistances */ |
251 | /* If dragon player, let's display natural resistances */ |
1157 | if (is_dragon_pl (op)) |
252 | if (is_dragon_pl (op)) |
1158 | { |
|
|
1159 | int attack; |
|
|
1160 | object *tmp; |
|
|
1161 | |
|
|
1162 | for (tmp = op->inv; tmp != NULL; tmp = tmp->below) |
253 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1163 | { |
|
|
1164 | if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) |
254 | if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force) |
1165 | { |
255 | { |
1166 | new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); |
256 | msg << "\nOf those, these are natural skin resistances:\n\n"; |
|
|
257 | |
1167 | for (attack = 0; attack < NROFATTACKS; attack++) |
258 | for (int attack = 0; attack < NROFATTACKS; attack++) |
1168 | { |
|
|
1169 | if (atnr_is_dragon_enabled (attack)) |
259 | if (atnr_is_dragon_enabled (attack)) |
1170 | { |
260 | msg.printf (" %-20s %+4d\n", change_resist_msg [attack], tmp->resist [attack]); |
1171 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %d", change_resist_msg[attack], tmp->resist[attack]); |
261 | |
1172 | } |
|
|
1173 | } |
|
|
1174 | break; |
262 | break; |
1175 | } |
263 | } |
1176 | } |
264 | |
1177 | } |
265 | op->contr->infobox (MSG_CHANNEL ("resistances"), msg); |
1178 | |
266 | |
1179 | return 0; |
267 | return 0; |
1180 | } |
268 | } |
1181 | |
269 | |
1182 | /* |
270 | /* |
1183 | * Actual commands. |
271 | * Actual commands. |
1184 | * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) |
272 | * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) |
1185 | */ |
273 | */ |
1186 | |
|
|
1187 | |
|
|
1188 | static void |
274 | static int |
1189 | help_topics (object *op, int what) |
|
|
1190 | { |
|
|
1191 | DIR *dirp; |
|
|
1192 | struct dirent *de; |
|
|
1193 | char filename[MAX_BUF], line[80]; |
|
|
1194 | int namelen, linelen = 0; |
|
|
1195 | |
|
|
1196 | switch (what) |
|
|
1197 | { |
|
|
1198 | case 1: |
|
|
1199 | sprintf (filename, "%s/wizhelp", settings.datadir); |
|
|
1200 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
|
|
1201 | break; |
|
|
1202 | case 3: |
|
|
1203 | sprintf (filename, "%s/mischelp", settings.datadir); |
|
|
1204 | new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); |
|
|
1205 | break; |
|
|
1206 | default: |
|
|
1207 | sprintf (filename, "%s/help", settings.datadir); |
|
|
1208 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
|
|
1209 | break; |
|
|
1210 | } |
|
|
1211 | if (!(dirp = opendir (filename))) |
|
|
1212 | return; |
|
|
1213 | |
|
|
1214 | line[0] = '\0'; |
|
|
1215 | for (de = readdir (dirp); de; de = readdir (dirp)) |
|
|
1216 | { |
|
|
1217 | namelen = NAMLEN (de); |
|
|
1218 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
|
|
1219 | continue; |
|
|
1220 | linelen += namelen + 1; |
|
|
1221 | if (linelen > 42) |
|
|
1222 | { |
|
|
1223 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1224 | sprintf (line, " %s", de->d_name); |
|
|
1225 | linelen = namelen + 1; |
|
|
1226 | continue; |
|
|
1227 | } |
|
|
1228 | strcat (line, " "); |
|
|
1229 | strcat (line, de->d_name); |
|
|
1230 | } |
|
|
1231 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1232 | closedir (dirp); |
|
|
1233 | } |
|
|
1234 | |
|
|
1235 | static void |
|
|
1236 | show_commands (object *op, int what) |
|
|
1237 | { |
|
|
1238 | char line[80]; |
|
|
1239 | int i, size, namelen, linelen = 0; |
|
|
1240 | CommArray_s *ap; |
|
|
1241 | extern CommArray_s Commands[], WizCommands[]; |
|
|
1242 | extern const int CommandsSize, WizCommandsSize; |
|
|
1243 | |
|
|
1244 | switch (what) |
|
|
1245 | { |
|
|
1246 | case 1: |
|
|
1247 | ap = WizCommands; |
|
|
1248 | size = WizCommandsSize; |
|
|
1249 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
|
|
1250 | break; |
|
|
1251 | case 2: |
|
|
1252 | ap = CommunicationCommands; |
|
|
1253 | size = CommunicationCommandSize; |
|
|
1254 | new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:"); |
|
|
1255 | break; |
|
|
1256 | default: |
|
|
1257 | ap = Commands; |
|
|
1258 | size = CommandsSize; |
|
|
1259 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
|
|
1260 | break; |
|
|
1261 | } |
|
|
1262 | |
|
|
1263 | line[0] = '\0'; |
|
|
1264 | for (i = 0; i < size; i++) |
|
|
1265 | { |
|
|
1266 | namelen = strlen (ap[i].name); |
|
|
1267 | linelen += namelen + 1; |
|
|
1268 | if (linelen > 42) |
|
|
1269 | { |
|
|
1270 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1271 | sprintf (line, " %s", ap[i].name); |
|
|
1272 | linelen = namelen + 1; |
|
|
1273 | continue; |
|
|
1274 | } |
|
|
1275 | strcat (line, " "); |
|
|
1276 | strcat (line, ap[i].name); |
|
|
1277 | } |
|
|
1278 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1279 | } |
|
|
1280 | |
|
|
1281 | |
|
|
1282 | int |
|
|
1283 | command_help (object *op, char *params) |
|
|
1284 | { |
|
|
1285 | struct stat st; |
|
|
1286 | FILE *fp; |
|
|
1287 | char filename[MAX_BUF], line[MAX_BUF]; |
|
|
1288 | int len; |
|
|
1289 | |
|
|
1290 | if (op != NULL) |
|
|
1291 | clear_win_info (op); |
|
|
1292 | |
|
|
1293 | /* |
|
|
1294 | * Main help page? |
|
|
1295 | */ |
|
|
1296 | if (!params) |
|
|
1297 | { |
|
|
1298 | sprintf (filename, "%s/def_help", settings.datadir); |
|
|
1299 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
1300 | { |
|
|
1301 | LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno)); |
|
|
1302 | return 0; |
|
|
1303 | } |
|
|
1304 | while (fgets (line, MAX_BUF, fp)) |
|
|
1305 | { |
|
|
1306 | line[MAX_BUF - 1] = '\0'; |
|
|
1307 | len = strlen (line) - 1; |
|
|
1308 | if (line[len] == '\n') |
|
|
1309 | line[len] = '\0'; |
|
|
1310 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1311 | } |
|
|
1312 | fclose (fp); |
|
|
1313 | return 0; |
|
|
1314 | } |
|
|
1315 | |
|
|
1316 | /* |
|
|
1317 | * Topics list |
|
|
1318 | */ |
|
|
1319 | if (!strcmp (params, "topics")) |
|
|
1320 | { |
|
|
1321 | help_topics (op, 3); |
|
|
1322 | help_topics (op, 0); |
|
|
1323 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
1324 | help_topics (op, 1); |
|
|
1325 | return 0; |
|
|
1326 | } |
|
|
1327 | |
|
|
1328 | /* |
|
|
1329 | * Commands list |
|
|
1330 | */ |
|
|
1331 | if (!strcmp (params, "commands")) |
|
|
1332 | { |
|
|
1333 | show_commands (op, 0); |
|
|
1334 | show_commands (op, 2); /* show comm commands */ |
|
|
1335 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
1336 | show_commands (op, 1); |
|
|
1337 | return 0; |
|
|
1338 | } |
|
|
1339 | |
|
|
1340 | /* |
|
|
1341 | * User wants info about command |
|
|
1342 | */ |
|
|
1343 | if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/')) |
|
|
1344 | { |
|
|
1345 | sprintf (line, "Illegal characters in '%s'", params); |
|
|
1346 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1347 | return 0; |
|
|
1348 | } |
|
|
1349 | |
|
|
1350 | sprintf (filename, "%s/mischelp/%s", settings.datadir, params); |
|
|
1351 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
1352 | { |
|
|
1353 | if (op) |
|
|
1354 | { |
|
|
1355 | sprintf (filename, "%s/help/%s", settings.datadir, params); |
|
|
1356 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
1357 | { |
|
|
1358 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
1359 | { |
|
|
1360 | sprintf (filename, "%s/wizhelp/%s", settings.datadir, params); |
|
|
1361 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
1362 | goto nohelp; |
|
|
1363 | } |
|
|
1364 | else |
|
|
1365 | goto nohelp; |
|
|
1366 | } |
|
|
1367 | } |
|
|
1368 | } |
|
|
1369 | |
|
|
1370 | /* |
|
|
1371 | * Found that. Just cat it to screen. |
|
|
1372 | */ |
|
|
1373 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
1374 | { |
|
|
1375 | LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno)); |
|
|
1376 | return 0; |
|
|
1377 | } |
|
|
1378 | sprintf (line, "Help about '%s'", params); |
|
|
1379 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1380 | while (fgets (line, MAX_BUF, fp)) |
|
|
1381 | { |
|
|
1382 | line[MAX_BUF - 1] = '\0'; |
|
|
1383 | len = strlen (line) - 1; |
|
|
1384 | if (line[len] == '\n') |
|
|
1385 | line[len] = '\0'; |
|
|
1386 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1387 | } |
|
|
1388 | fclose (fp); |
|
|
1389 | return 0; |
|
|
1390 | |
|
|
1391 | /* |
|
|
1392 | * No_help -escape |
|
|
1393 | */ |
|
|
1394 | nohelp: |
|
|
1395 | sprintf (line, "No help available on '%s'", params); |
|
|
1396 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1397 | return 0; |
|
|
1398 | } |
|
|
1399 | |
|
|
1400 | |
|
|
1401 | int |
|
|
1402 | onoff_value (const char *line) |
275 | onoff_value (const char *line) |
1403 | { |
276 | { |
1404 | int i; |
277 | int i; |
1405 | |
278 | |
1406 | if (sscanf (line, "%d", &i)) |
279 | if (sscanf (line, "%d", &i)) |
… | |
… | |
1427 | return 0; |
300 | return 0; |
1428 | } |
301 | } |
1429 | } |
302 | } |
1430 | |
303 | |
1431 | int |
304 | int |
1432 | command_quit (object *op, char *params) |
|
|
1433 | { |
|
|
1434 | new_draw_info (NDI_UNIQUE, 0, op, |
|
|
1435 | "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit."); |
|
|
1436 | return 1; |
|
|
1437 | } |
|
|
1438 | |
|
|
1439 | int |
|
|
1440 | command_real_quit (object *op, char *params) |
|
|
1441 | { |
|
|
1442 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):"); |
|
|
1443 | |
|
|
1444 | op->contr->state = ST_CONFIRM_QUIT; |
|
|
1445 | return 1; |
|
|
1446 | } |
|
|
1447 | |
|
|
1448 | /* |
|
|
1449 | * don't allow people to exit explore mode. It otherwise becomes |
|
|
1450 | * really easy to abuse this. |
|
|
1451 | */ |
|
|
1452 | int |
|
|
1453 | command_explore (object *op, char *params) |
|
|
1454 | { |
|
|
1455 | if (settings.explore_mode == FALSE) |
|
|
1456 | return 1; |
|
|
1457 | /* |
|
|
1458 | * I guess this is the best way to see if we are solo or not. Actually, |
|
|
1459 | * are there any cases when first_player->next==NULL and we are not solo? |
|
|
1460 | */ |
|
|
1461 | if ((first_player != op->contr) || (first_player->next != NULL)) |
|
|
1462 | { |
|
|
1463 | new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party"); |
|
|
1464 | } |
|
|
1465 | else if (op->contr->explore) |
|
|
1466 | new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode"); |
|
|
1467 | else |
|
|
1468 | { |
|
|
1469 | op->contr->explore = 1; |
|
|
1470 | new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode"); |
|
|
1471 | } |
|
|
1472 | return 1; |
|
|
1473 | } |
|
|
1474 | |
|
|
1475 | int |
|
|
1476 | command_sound (object *op, char *params) |
|
|
1477 | { |
|
|
1478 | if (op->contr->socket.sound) |
|
|
1479 | { |
|
|
1480 | op->contr->socket.sound = 0; |
|
|
1481 | new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden..."); |
|
|
1482 | } |
|
|
1483 | else |
|
|
1484 | { |
|
|
1485 | op->contr->socket.sound = 1; |
|
|
1486 | new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled."); |
|
|
1487 | } |
|
|
1488 | return 1; |
|
|
1489 | } |
|
|
1490 | |
|
|
1491 | /* Perhaps these should be in player.c, but that file is |
|
|
1492 | * already a bit big. |
|
|
1493 | */ |
|
|
1494 | |
|
|
1495 | void |
|
|
1496 | receive_player_name (object *op, char k) |
|
|
1497 | { |
|
|
1498 | |
|
|
1499 | if (!check_name (op->contr, op->contr->write_buf + 1)) |
|
|
1500 | { |
|
|
1501 | get_name (op); |
|
|
1502 | return; |
|
|
1503 | } |
|
|
1504 | op->name = op->contr->write_buf + 1; |
|
|
1505 | op->name_pl = op->contr->write_buf + 1; |
|
|
1506 | new_draw_info (NDI_UNIQUE, 0, op, op->contr->write_buf); |
|
|
1507 | op->contr->name_changed = 1; |
|
|
1508 | get_password (op); |
|
|
1509 | } |
|
|
1510 | |
|
|
1511 | void |
|
|
1512 | receive_player_password (object *op, char k) |
|
|
1513 | { |
|
|
1514 | |
|
|
1515 | unsigned int pwd_len = strlen (op->contr->write_buf); |
|
|
1516 | |
|
|
1517 | if (pwd_len <= 1 || pwd_len > 17) |
|
|
1518 | { |
|
|
1519 | get_name (op); |
|
|
1520 | return; |
|
|
1521 | } |
|
|
1522 | new_draw_info (NDI_UNIQUE, 0, op, " "); /* To hide the password better */ |
|
|
1523 | |
|
|
1524 | if (checkbanned (op->name, op->contr->socket.host)) |
|
|
1525 | { |
|
|
1526 | LOG (llevInfo, "Banned player tried to add: [%s@%s]\n", &op->name, op->contr->socket.host); |
|
|
1527 | new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, "You are not allowed to play."); |
|
|
1528 | get_name (op); |
|
|
1529 | return; |
|
|
1530 | } |
|
|
1531 | |
|
|
1532 | if (op->contr->state == ST_CONFIRM_PASSWORD) |
|
|
1533 | { |
|
|
1534 | if (!check_password (op->contr->write_buf + 1, op->contr->password)) |
|
|
1535 | { |
|
|
1536 | new_draw_info (NDI_UNIQUE, 0, op, "The passwords did not match."); |
|
|
1537 | get_name (op); |
|
|
1538 | return; |
|
|
1539 | } |
|
|
1540 | clear_win_info (op); |
|
|
1541 | display_motd (op); |
|
|
1542 | new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
1543 | new_draw_info (NDI_UNIQUE, 0, op, "Welcome, Brave New Warrior!"); |
|
|
1544 | new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
1545 | Roll_Again (op); |
|
|
1546 | op->contr->state = ST_ROLL_STAT; |
|
|
1547 | return; |
|
|
1548 | } |
|
|
1549 | strcpy (op->contr->password, crypt_string (op->contr->write_buf + 1, NULL)); |
|
|
1550 | op->contr->state = ST_ROLL_STAT; |
|
|
1551 | check_login (op); |
|
|
1552 | return; |
|
|
1553 | } |
|
|
1554 | |
|
|
1555 | |
|
|
1556 | int |
|
|
1557 | explore_mode (void) |
|
|
1558 | { |
|
|
1559 | player *pl; |
|
|
1560 | |
|
|
1561 | if (settings.explore_mode == TRUE) |
|
|
1562 | { |
|
|
1563 | for (pl = first_player; pl != (player *) NULL; pl = pl->next) |
|
|
1564 | if (pl->explore) |
|
|
1565 | return 1; |
|
|
1566 | } |
|
|
1567 | return 0; |
|
|
1568 | } |
|
|
1569 | |
|
|
1570 | |
|
|
1571 | int |
|
|
1572 | command_title (object *op, char *params) |
305 | command_title (object *op, char *params) |
1573 | { |
306 | { |
1574 | char buf[MAX_BUF]; |
307 | char buf[MAX_BUF]; |
1575 | |
308 | |
1576 | if (settings.set_title == FALSE) |
309 | if (settings.set_title == FALSE) |
… | |
… | |
1613 | strcpy (op->contr->own_title, params); |
346 | strcpy (op->contr->own_title, params); |
1614 | return 1; |
347 | return 1; |
1615 | } |
348 | } |
1616 | |
349 | |
1617 | int |
350 | int |
1618 | command_save (object *op, char *params) |
|
|
1619 | { |
|
|
1620 | // if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_CLERIC) { |
|
|
1621 | // new_draw_info(NDI_UNIQUE, 0, op, "You can not save on unholy ground"); |
|
|
1622 | // } else |
|
|
1623 | if (!op->stats.exp) |
|
|
1624 | { |
|
|
1625 | new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet."); |
|
|
1626 | } |
|
|
1627 | else |
|
|
1628 | { |
|
|
1629 | if (save_player (op, 1)) |
|
|
1630 | new_draw_info (NDI_UNIQUE, 0, op, "You have been saved."); |
|
|
1631 | else |
|
|
1632 | new_draw_info (NDI_UNIQUE, 0, op, "SAVE FAILED!"); |
|
|
1633 | } |
|
|
1634 | return 1; |
|
|
1635 | } |
|
|
1636 | |
|
|
1637 | |
|
|
1638 | int |
|
|
1639 | command_peaceful (object *op, char *params) |
|
|
1640 | { |
|
|
1641 | new_draw_info (NDI_UNIQUE, 0, op, |
|
|
1642 | "You cannot change your peaceful setting with this command." |
|
|
1643 | " Please speak to the priest in the temple of Gorokh" |
|
|
1644 | " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again."); |
|
|
1645 | |
|
|
1646 | /* |
|
|
1647 | if((op->contr->peaceful=!op->contr->peaceful)) |
|
|
1648 | new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players."); |
|
|
1649 | else |
|
|
1650 | new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players."); |
|
|
1651 | */ |
|
|
1652 | return 1; |
|
|
1653 | } |
|
|
1654 | |
|
|
1655 | |
|
|
1656 | |
|
|
1657 | int |
|
|
1658 | command_wimpy (object *op, char *params) |
|
|
1659 | { |
|
|
1660 | int i; |
|
|
1661 | char buf[MAX_BUF]; |
|
|
1662 | |
|
|
1663 | if (params == NULL || !sscanf (params, "%d", &i)) |
|
|
1664 | { |
|
|
1665 | sprintf (buf, "Your current wimpy level is %d.", op->run_away); |
|
|
1666 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
1667 | return 1; |
|
|
1668 | } |
|
|
1669 | sprintf (buf, "Your new wimpy level is %d.", i); |
|
|
1670 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
1671 | op->run_away = i; |
|
|
1672 | return 1; |
|
|
1673 | } |
|
|
1674 | |
|
|
1675 | |
|
|
1676 | int |
|
|
1677 | command_brace (object *op, char *params) |
|
|
1678 | { |
|
|
1679 | if (!params) |
|
|
1680 | op->contr->braced = !op->contr->braced; |
|
|
1681 | else |
|
|
1682 | op->contr->braced = onoff_value (params); |
|
|
1683 | |
|
|
1684 | if (op->contr->braced) |
|
|
1685 | new_draw_info (NDI_UNIQUE, 0, op, "You are braced."); |
|
|
1686 | else |
|
|
1687 | new_draw_info (NDI_UNIQUE, 0, op, "Not braced."); |
|
|
1688 | |
|
|
1689 | fix_player (op); |
|
|
1690 | return 0; |
|
|
1691 | } |
|
|
1692 | |
|
|
1693 | int |
|
|
1694 | command_style_map_info (object *op, char *params) |
|
|
1695 | { |
|
|
1696 | extern mapstruct *styles; |
|
|
1697 | mapstruct *mp; |
|
|
1698 | int maps_used = 0, mapmem = 0, objects_used = 0, x, y; |
|
|
1699 | object *tmp; |
|
|
1700 | |
|
|
1701 | for (mp = styles; mp != NULL; mp = mp->next) |
|
|
1702 | { |
|
|
1703 | maps_used++; |
|
|
1704 | mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (mapstruct); |
|
|
1705 | for (x = 0; x < MAP_WIDTH (mp); x++) |
|
|
1706 | { |
|
|
1707 | for (y = 0; y < MAP_HEIGHT (mp); y++) |
|
|
1708 | { |
|
|
1709 | for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above) |
|
|
1710 | objects_used++; |
|
|
1711 | } |
|
|
1712 | } |
|
|
1713 | } |
|
|
1714 | new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used); |
|
|
1715 | new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not"); |
|
|
1716 | new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem); |
|
|
1717 | new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used); |
|
|
1718 | new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object)); |
|
|
1719 | return 0; |
|
|
1720 | } |
|
|
1721 | |
|
|
1722 | int |
|
|
1723 | command_kill_pets (object *op, char *params) |
351 | command_kill_pets (object *op, char *params) |
1724 | { |
352 | { |
1725 | objectlink *obl, *next; |
353 | objectlink *obl, *next; |
1726 | int counter = 0, removecount = 0; |
354 | int counter = 0, removecount = 0; |
1727 | |
355 | |
1728 | if (params == NULL) |
356 | if (!params) |
1729 | { |
357 | { |
1730 | terminate_all_pets (op); |
358 | terminate_all_pets (op); |
1731 | new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); |
359 | new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); |
1732 | } |
360 | } |
1733 | else |
361 | else |
1734 | { |
362 | { |
1735 | int target = atoi (params); |
363 | int target = atoi (params); |
1736 | |
364 | |
1737 | for (obl = first_friendly_object; obl != NULL; obl = next) |
365 | for (obl = first_friendly_object; obl; obl = next) |
1738 | { |
366 | { |
1739 | object *ob = obl->ob; |
367 | object *ob = obl->ob; |
1740 | |
368 | |
1741 | next = obl->next; |
369 | next = obl->next; |
|
|
370 | |
1742 | if (get_owner (ob) == op) |
371 | if (ob->owner == op) |
1743 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
372 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
1744 | { |
373 | { |
1745 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
|
|
1746 | remove_ob (ob); |
|
|
1747 | remove_friendly_object (ob); |
|
|
1748 | free_object (ob); |
374 | ob->destroy (); |
1749 | removecount++; |
375 | removecount++; |
1750 | } |
376 | } |
1751 | } |
377 | } |
|
|
378 | |
1752 | if (removecount != 0) |
379 | if (removecount != 0) |
1753 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
380 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
1754 | else |
381 | else |
1755 | new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
382 | new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
1756 | } |
383 | } |
|
|
384 | |
1757 | return 0; |
385 | return 0; |
1758 | } |
386 | } |