1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <loader.h> |
26 | #include <loader.h> |
26 | #ifndef __CEXTRACT__ |
|
|
27 | # include <sproto.h> |
27 | #include <sproto.h> |
28 | #endif |
|
|
29 | |
|
|
30 | extern weathermap_t **weathermap; |
|
|
31 | |
28 | |
32 | /* Handles misc. input request - things like hash table, malloc, maps, |
29 | /* Handles misc. input request - things like hash table, malloc, maps, |
33 | * who, etc. |
30 | * who, etc. |
34 | */ |
31 | */ |
35 | |
|
|
36 | void |
|
|
37 | map_info (object *op, char *search) |
|
|
38 | { |
|
|
39 | maptile *m; |
|
|
40 | char buf[MAX_BUF], map_path[MAX_BUF]; |
|
|
41 | long sec = seconds (); |
|
|
42 | |
|
|
43 | new_draw_info_format (NDI_UNIQUE, 0, op, "Current time is: %02ld:%02ld:%02ld.", (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60); |
|
|
44 | new_draw_info (NDI_UNIQUE, 0, op, "Path Pl PlM IM TO Dif Reset"); |
|
|
45 | for (m = first_map; m != NULL; m = m->next) |
|
|
46 | { |
|
|
47 | |
|
|
48 | if (search && strstr (m->path, search) == NULL) |
|
|
49 | continue; /* Skip unwanted maps */ |
|
|
50 | /* Print out the last 18 characters of the map name... */ |
|
|
51 | if (strlen (m->path) <= 18) |
|
|
52 | strcpy (map_path, m->path); |
|
|
53 | else |
|
|
54 | strcpy (map_path, m->path + strlen (m->path) - 18); |
|
|
55 | sprintf (buf, "%-18.18s %2d %2d %1d %4d %2d %02d:%02d:%02d", |
|
|
56 | map_path, m->players, players_on_map (m, FALSE), |
|
|
57 | m->in_memory, m->timeout, m->difficulty, |
|
|
58 | (MAP_WHEN_RESET (m) % 86400) / 3600, (MAP_WHEN_RESET (m) % 3600) / 60, MAP_WHEN_RESET (m) % 60); |
|
|
59 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
60 | } |
|
|
61 | } |
|
|
62 | |
32 | |
63 | /* This command dumps the body information for object *op. |
33 | /* This command dumps the body information for object *op. |
64 | * it doesn't care what the params are. |
34 | * it doesn't care what the params are. |
65 | * This is mostly meant as a debug command. |
35 | * This is mostly meant as a debug command. |
66 | */ |
36 | */ |
… | |
… | |
109 | if (params == NULL) |
79 | if (params == NULL) |
110 | { |
80 | { |
111 | new_draw_info (NDI_UNIQUE, 0, op, "what bugs?"); |
81 | new_draw_info (NDI_UNIQUE, 0, op, "what bugs?"); |
112 | return 1; |
82 | return 1; |
113 | } |
83 | } |
114 | strcpy (buf, op->name); |
84 | assign (buf, op->name); |
115 | strcat (buf, " bug-reports: "); |
85 | strcat (buf, " bug-reports: "); |
116 | strncat (buf, ++params, MAX_BUF - strlen (buf)); |
86 | strncat (buf, ++params, MAX_BUF - strlen (buf)); |
117 | buf[MAX_BUF - 1] = '\0'; |
87 | buf[MAX_BUF - 1] = '\0'; |
118 | bug_report (buf); |
88 | bug_report (buf); |
119 | LOG (llevError, "%s\n", buf); |
89 | LOG (llevError, "%s\n", buf); |
… | |
… | |
128 | * a description of it. It is there merely for flavour text. |
98 | * a description of it. It is there merely for flavour text. |
129 | */ |
99 | */ |
130 | void |
100 | void |
131 | current_region_info (object *op) |
101 | current_region_info (object *op) |
132 | { |
102 | { |
133 | /* |
103 | if (region *reg = op->region ()) |
134 | * Ok I /suppose/ I should write a seperate function for this, but it isn't |
|
|
135 | * going to be /that/ slow, and won't get called much |
|
|
136 | */ |
|
|
137 | region *r = get_region_by_name (get_name_of_region_for_map (op->map)); |
|
|
138 | |
|
|
139 | if (!r) |
|
|
140 | return; |
|
|
141 | /* This should only be possible if regions are not operating on this server. */ |
|
|
142 | |
|
|
143 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s. \n %s", get_region_longname (r), get_region_msg (r)); |
104 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are %s.\n%s", ®->longname, ®->msg); |
144 | } |
105 | } |
145 | |
106 | |
146 | void |
107 | void |
147 | current_map_info (object *op) |
108 | current_map_info (object *op) |
148 | { |
109 | { |
149 | maptile *m = op->map; |
110 | maptile *m = op->map; |
150 | |
111 | |
151 | if (!m) |
112 | if (!m) |
152 | return; |
113 | return; |
153 | |
114 | |
154 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", m->name, m->path, get_name_of_region_for_map (m)); |
115 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) %s", &m->name, &m->path, &op->region ()->longname); |
155 | |
116 | |
156 | if (QUERY_FLAG (op, FLAG_WIZ)) |
117 | if (QUERY_FLAG (op, FLAG_WIZ)) |
157 | { |
|
|
158 | new_draw_info_format (NDI_UNIQUE, 0, op, |
118 | new_draw_info_format (NDI_UNIQUE, 0, op, |
159 | "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld", |
119 | "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld", |
160 | m->players, m->difficulty, MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m), MAP_TIMEOUT (m)); |
120 | m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout); |
161 | |
121 | |
162 | } |
|
|
163 | if (m->msg) |
122 | if (m->msg) |
164 | new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); |
123 | new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); |
165 | } |
124 | } |
166 | |
125 | |
167 | #ifdef DEBUG_MALLOC_LEVEL |
126 | #ifdef DEBUG_MALLOC_LEVEL |
… | |
… | |
179 | #endif |
138 | #endif |
180 | |
139 | |
181 | int |
140 | int |
182 | command_whereabouts (object *op, char *params) |
141 | command_whereabouts (object *op, char *params) |
183 | { |
142 | { |
184 | |
143 | //TODO: should obviously not waste space in struct region for this. |
185 | region *reg; |
|
|
186 | player *pl; |
|
|
187 | |
|
|
188 | /* |
144 | /* |
189 | * reset the counter on the region, then use it to store the number of |
145 | * reset the counter on the region, then use it to store the number of |
190 | * players there. |
146 | * players there. |
191 | * I don't know how thread-safe this would be, I suspect not very.... |
147 | * I don't know how thread-safe this would be, I suspect not very.... |
192 | */ |
148 | */ |
193 | for (reg = first_region; reg != NULL; reg = reg->next) |
149 | for_all_regions (rgn) |
194 | { |
|
|
195 | reg->counter = 0; |
150 | rgn->counter = 0; |
196 | } |
151 | |
197 | for (pl = first_player; pl != NULL; pl = pl->next) |
152 | for_all_players (pl) |
198 | if (pl->ob->map != NULL) |
153 | if (pl->ob->map) |
199 | get_region_by_map (pl->ob->map)->counter++; |
154 | ++pl->ob->region ()->counter; |
200 | |
155 | |
201 | /* we only want to print out by places with a 'longname' field... */ |
156 | /* we only want to print out by places with a 'longname' field... */ |
202 | for (reg = first_region; reg != NULL; reg = reg->next) |
157 | for_all_regions (rgn) |
203 | { |
158 | { |
204 | if (reg->longname == NULL && reg->counter > 0) |
159 | if (!rgn->longname && rgn->counter > 0) |
205 | { |
160 | { |
206 | if (reg->parent != NULL) |
161 | if (rgn->parent) |
207 | { |
162 | { |
208 | reg->parent->counter += reg->counter; |
163 | rgn->parent->counter += rgn->counter; |
209 | reg->counter = 0; |
164 | rgn->counter = 0; |
210 | } |
165 | } |
211 | else /*uh oh, we shouldn't be here. */ |
166 | else /*uh oh, we shouldn't be here. */ |
212 | LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name); |
167 | LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", &rgn->name); |
213 | } |
168 | } |
214 | } |
169 | } |
|
|
170 | |
215 | new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); |
171 | new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); |
216 | for (reg = first_region; reg != NULL; reg = reg->next) |
172 | |
|
|
173 | for_all_regions (rgn) |
217 | if (reg->counter > 0) |
174 | if (rgn->counter) |
218 | new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg)); |
175 | new_draw_info_format (NDI_UNIQUE, 0, op, "%u players %s", rgn->counter, &rgn->longname); |
|
|
176 | |
219 | return 1; |
177 | return 1; |
220 | } |
178 | } |
221 | |
179 | |
222 | typedef struct |
180 | typedef struct |
223 | { |
181 | { |
224 | char namebuf[MAX_BUF]; |
182 | char namebuf[MAX_BUF]; |
225 | int login_order; |
183 | int login_order; |
226 | } chars_names; |
184 | } chars_names; |
227 | |
185 | |
228 | /*local functon for qsort comparison*/ |
|
|
229 | static int |
|
|
230 | name_cmp (const chars_names * c1, const chars_names * c2) |
|
|
231 | { |
|
|
232 | return strcasecmp (c1->namebuf, c2->namebuf); |
|
|
233 | } |
|
|
234 | |
|
|
235 | int |
186 | int |
236 | command_afk (object *op, char *params) |
187 | command_afk (object *op, char *params) |
237 | { |
188 | { |
238 | if QUERY_FLAG |
189 | if ((op->contr->ns->afk = !op->contr->ns->afk)) |
239 | (op, FLAG_AFK) |
|
|
240 | { |
|
|
241 | CLEAR_FLAG (op, FLAG_AFK); |
|
|
242 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK"); |
190 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK"); |
243 | } |
|
|
244 | else |
191 | else |
245 | { |
|
|
246 | SET_FLAG (op, FLAG_AFK); |
|
|
247 | new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK"); |
192 | new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK"); |
248 | } |
193 | |
249 | return 1; |
194 | return 1; |
250 | } |
195 | } |
251 | |
196 | |
252 | int |
197 | int |
253 | command_mapinfo (object *op, char *params) |
198 | command_mapinfo (object *op, char *params) |
… | |
… | |
262 | current_region_info (op); |
207 | current_region_info (op); |
263 | return 1; |
208 | return 1; |
264 | } |
209 | } |
265 | |
210 | |
266 | int |
211 | int |
267 | command_maps (object *op, char *params) |
|
|
268 | { |
|
|
269 | map_info (op, params); |
|
|
270 | return 1; |
|
|
271 | } |
|
|
272 | |
|
|
273 | int |
|
|
274 | command_time (object *op, char *params) |
212 | command_time (object *op, char *params) |
275 | { |
213 | { |
276 | print_tod (op); |
214 | print_tod (op); |
277 | return 1; |
215 | return 1; |
278 | } |
216 | } |
279 | |
217 | |
280 | int |
218 | int |
281 | command_weather (object *op, char *params) |
219 | command_weather (object *op, char *params) |
282 | { |
220 | { |
|
|
221 | #if 0 |
283 | int wx, wy, temp, sky; |
222 | int wx, wy, temp, sky; |
284 | char buf[MAX_BUF]; |
223 | char buf[MAX_BUF]; |
285 | |
224 | |
286 | if (settings.dynamiclevel < 1) |
225 | if (settings.dynamiclevel < 1) |
287 | return 1; |
226 | return 1; |
… | |
… | |
403 | break; |
342 | break; |
404 | case SKY_BLIZZARD: |
343 | case SKY_BLIZZARD: |
405 | new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!"); |
344 | new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!"); |
406 | break; |
345 | break; |
407 | } |
346 | } |
408 | return 1; |
347 | #endif |
409 | } |
|
|
410 | |
|
|
411 | int |
|
|
412 | command_archs (object *op, char *params) |
|
|
413 | { |
|
|
414 | arch_info (op); |
|
|
415 | return 1; |
348 | return 1; |
416 | } |
349 | } |
417 | |
350 | |
418 | int |
351 | int |
419 | command_hiscore (object *op, char *params) |
352 | command_hiscore (object *op, char *params) |
… | |
… | |
453 | int |
386 | int |
454 | command_dumpbelow (object *op, char *params) |
387 | command_dumpbelow (object *op, char *params) |
455 | { |
388 | { |
456 | if (op && op->below) |
389 | if (op && op->below) |
457 | { |
390 | { |
458 | dump_object (op->below); |
391 | char *dump = dump_object (op->below); |
459 | new_draw_info (NDI_UNIQUE, 0, op, errmsg); |
392 | new_draw_info (NDI_UNIQUE, 0, op, dump); |
|
|
393 | free (dump); |
460 | /* Let's push that item on the dm's stack */ |
394 | /* Let's push that item on the dm's stack */ |
461 | dm_stack_push (op->contr, op->below->count); |
395 | dm_stack_push (op->contr, op->below->count); |
462 | } |
396 | } |
463 | return 0; |
397 | return 0; |
464 | } |
398 | } |
465 | |
399 | |
466 | int |
400 | int |
467 | command_wizpass (object *op, char *params) |
|
|
468 | { |
|
|
469 | int i; |
|
|
470 | |
|
|
471 | if (!op) |
|
|
472 | return 0; |
|
|
473 | |
|
|
474 | if (!params) |
|
|
475 | i = (QUERY_FLAG (op, FLAG_WIZPASS)) ? 0 : 1; |
|
|
476 | else |
|
|
477 | i = onoff_value (params); |
|
|
478 | |
|
|
479 | if (i) |
|
|
480 | { |
|
|
481 | new_draw_info (NDI_UNIQUE, 0, op, "You will now walk through walls.\n"); |
|
|
482 | SET_FLAG (op, FLAG_WIZPASS); |
|
|
483 | } |
|
|
484 | else |
|
|
485 | { |
|
|
486 | new_draw_info (NDI_UNIQUE, 0, op, "You will now be stopped by walls.\n"); |
|
|
487 | CLEAR_FLAG (op, FLAG_WIZPASS); |
|
|
488 | } |
|
|
489 | return 0; |
|
|
490 | } |
|
|
491 | |
|
|
492 | int |
|
|
493 | command_wizcast (object *op, char *params) |
|
|
494 | { |
|
|
495 | int i; |
|
|
496 | |
|
|
497 | if (!op) |
|
|
498 | return 0; |
|
|
499 | |
|
|
500 | if (!params) |
|
|
501 | i = (QUERY_FLAG (op, FLAG_WIZCAST)) ? 0 : 1; |
|
|
502 | else |
|
|
503 | i = onoff_value (params); |
|
|
504 | |
|
|
505 | if (i) |
|
|
506 | { |
|
|
507 | new_draw_info (NDI_UNIQUE, 0, op, "You can now cast spells anywhere."); |
|
|
508 | SET_FLAG (op, FLAG_WIZCAST); |
|
|
509 | } |
|
|
510 | else |
|
|
511 | { |
|
|
512 | new_draw_info (NDI_UNIQUE, 0, op, "You now cannot cast spells in no-magic areas."); |
|
|
513 | CLEAR_FLAG (op, FLAG_WIZCAST); |
|
|
514 | } |
|
|
515 | return 0; |
|
|
516 | } |
|
|
517 | |
|
|
518 | int |
|
|
519 | command_dumpallobjects (object *op, char *params) |
|
|
520 | { |
|
|
521 | dump_all_objects (); |
|
|
522 | return 0; |
|
|
523 | } |
|
|
524 | |
|
|
525 | int |
|
|
526 | command_dumpfriendlyobjects (object *op, char *params) |
401 | command_dumpfriendlyobjects (object *op, char *params) |
527 | { |
402 | { |
528 | dump_friendly_objects (); |
403 | dump_friendly_objects (); |
529 | return 0; |
|
|
530 | } |
|
|
531 | |
|
|
532 | int |
|
|
533 | command_dumpallarchetypes (object *op, char *params) |
|
|
534 | { |
|
|
535 | dump_all_archetypes (); |
|
|
536 | return 0; |
|
|
537 | } |
|
|
538 | |
|
|
539 | int |
|
|
540 | command_dumpmap (object *op, char *params) |
|
|
541 | { |
|
|
542 | if (op) |
|
|
543 | dump_map (op->map); |
|
|
544 | return 0; |
|
|
545 | } |
|
|
546 | |
|
|
547 | int |
|
|
548 | command_dumpallmaps (object *op, char *params) |
|
|
549 | { |
|
|
550 | dump_all_maps (); |
|
|
551 | return 0; |
404 | return 0; |
552 | } |
405 | } |
553 | |
406 | |
554 | int |
407 | int |
555 | command_printlos (object *op, char *params) |
408 | command_printlos (object *op, char *params) |
… | |
… | |
564 | command_version (object *op, char *params) |
417 | command_version (object *op, char *params) |
565 | { |
418 | { |
566 | version (op); |
419 | version (op); |
567 | return 0; |
420 | return 0; |
568 | } |
421 | } |
569 | |
|
|
570 | |
422 | |
571 | #ifndef BUG_LOG |
423 | #ifndef BUG_LOG |
572 | # define BUG_LOG "bug_log" |
424 | # define BUG_LOG "bug_log" |
573 | #endif |
425 | #endif |
574 | void |
426 | void |
… | |
… | |
654 | int |
506 | int |
655 | command_statistics (object *pl, char *params) |
507 | command_statistics (object *pl, char *params) |
656 | { |
508 | { |
657 | if (!pl->contr) |
509 | if (!pl->contr) |
658 | return 1; |
510 | return 1; |
659 | #ifndef WIN32 |
|
|
660 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %lld", pl->stats.exp); |
|
|
661 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %lld", level_exp (pl->level + 1, pl->expmul)); |
|
|
662 | #else |
|
|
663 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %I64d", pl->stats.exp); |
511 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp); |
664 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %I64d", level_exp (pl->level + 1, pl->expmul)); |
512 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul)); |
665 | #endif |
|
|
666 | new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); |
513 | new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); |
667 | |
514 | |
668 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", |
515 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", |
669 | pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); |
516 | pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); |
670 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", |
517 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", |
… | |
… | |
687 | |
534 | |
688 | int |
535 | int |
689 | command_fix_me (object *op, char *params) |
536 | command_fix_me (object *op, char *params) |
690 | { |
537 | { |
691 | sum_weight (op); |
538 | sum_weight (op); |
692 | fix_player (op); |
539 | op->update_stats (); |
693 | return 1; |
|
|
694 | } |
|
|
695 | |
|
|
696 | int |
|
|
697 | command_players (object *op, char *paramss) |
|
|
698 | { |
|
|
699 | char buf[MAX_BUF]; |
|
|
700 | char *t; |
|
|
701 | DIR *Dir; |
|
|
702 | |
|
|
703 | sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir); |
|
|
704 | t = buf + strlen (buf); |
|
|
705 | if ((Dir = opendir (buf)) != NULL) |
|
|
706 | { |
|
|
707 | const struct dirent *Entry; |
|
|
708 | |
|
|
709 | while ((Entry = readdir (Dir)) != NULL) |
|
|
710 | { |
|
|
711 | /* skip '.' , '..' */ |
|
|
712 | if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') || |
|
|
713 | (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0'))) |
|
|
714 | { |
|
|
715 | struct stat Stat; |
|
|
716 | |
|
|
717 | strcpy (t, Entry->d_name); |
|
|
718 | if (stat (buf, &Stat) == 0) |
|
|
719 | { |
|
|
720 | /* This was not posix compatible |
|
|
721 | * if ((Stat.st_mode & S_IFMT)==S_IFDIR) { |
|
|
722 | */ |
|
|
723 | if (S_ISDIR (Stat.st_mode)) |
|
|
724 | { |
|
|
725 | char buf2[MAX_BUF]; |
|
|
726 | struct tm *tm = localtime (&Stat.st_mtime); |
|
|
727 | |
|
|
728 | sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d", |
|
|
729 | Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); |
|
|
730 | new_draw_info (NDI_UNIQUE, 0, op, buf2); |
|
|
731 | } |
|
|
732 | } |
|
|
733 | } |
|
|
734 | } |
|
|
735 | } |
|
|
736 | closedir (Dir); |
|
|
737 | return 0; |
540 | return 1; |
738 | } |
541 | } |
739 | |
|
|
740 | |
|
|
741 | |
542 | |
742 | int |
543 | int |
743 | command_logs (object *op, char *params) |
544 | command_logs (object *op, char *params) |
744 | { |
545 | { |
745 | new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); |
546 | new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); |
… | |
… | |
768 | else |
569 | else |
769 | { |
570 | { |
770 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params); |
571 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params); |
771 | return 0; |
572 | return 0; |
772 | } |
573 | } |
|
|
574 | |
773 | new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s", |
575 | new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s", |
774 | (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]); |
576 | (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]); |
775 | return 1; |
577 | return 1; |
776 | } |
578 | } |
777 | |
579 | |
… | |
… | |
799 | found++; |
601 | found++; |
800 | op->contr->bowtype = (bowtype_t) i; |
602 | op->contr->bowtype = (bowtype_t) i; |
801 | break; |
603 | break; |
802 | } |
604 | } |
803 | } |
605 | } |
|
|
606 | |
804 | if (!found) |
607 | if (!found) |
805 | { |
608 | { |
806 | sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
609 | sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
807 | for (i = 0; i <= bow_bestarrow; i++) |
610 | for (i = 0; i <= bow_bestarrow; i++) |
808 | { |
611 | { |
… | |
… | |
814 | strcat (buf, "."); |
617 | strcat (buf, "."); |
815 | } |
618 | } |
816 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
619 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
817 | return 0; |
620 | return 0; |
818 | } |
621 | } |
|
|
622 | |
819 | new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
623 | new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
820 | return 1; |
624 | return 1; |
821 | } |
625 | } |
822 | |
626 | |
823 | int |
627 | int |
… | |
… | |
862 | for (obl = first_friendly_object; obl != NULL; obl = next) |
666 | for (obl = first_friendly_object; obl != NULL; obl = next) |
863 | { |
667 | { |
864 | object *ob = obl->ob; |
668 | object *ob = obl->ob; |
865 | |
669 | |
866 | next = obl->next; |
670 | next = obl->next; |
867 | if (get_owner (ob) == op) |
671 | if (ob->owner == op) |
868 | { |
672 | { |
869 | if (target == 0) |
673 | if (target == 0) |
870 | { |
674 | { |
871 | if (counter == 0) |
675 | if (counter == 0) |
872 | new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); |
676 | new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); |
… | |
… | |
979 | char filename[MAX_BUF], line[80]; |
783 | char filename[MAX_BUF], line[80]; |
980 | int namelen, linelen = 0; |
784 | int namelen, linelen = 0; |
981 | |
785 | |
982 | switch (what) |
786 | switch (what) |
983 | { |
787 | { |
984 | case 1: |
788 | case 1: |
985 | sprintf (filename, "%s/wizhelp", settings.datadir); |
789 | sprintf (filename, "%s/wizhelp", settings.datadir); |
986 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
790 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
987 | break; |
791 | break; |
988 | case 3: |
792 | case 3: |
989 | sprintf (filename, "%s/mischelp", settings.datadir); |
793 | sprintf (filename, "%s/mischelp", settings.datadir); |
990 | new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); |
794 | new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); |
991 | break; |
795 | break; |
992 | default: |
796 | default: |
993 | sprintf (filename, "%s/help", settings.datadir); |
797 | sprintf (filename, "%s/help", settings.datadir); |
994 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
798 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
995 | break; |
799 | break; |
996 | } |
800 | } |
|
|
801 | |
997 | if (!(dirp = opendir (filename))) |
802 | if (!(dirp = opendir (filename))) |
998 | return; |
803 | return; |
999 | |
804 | |
1000 | line[0] = '\0'; |
805 | line[0] = '\0'; |
1001 | for (de = readdir (dirp); de; de = readdir (dirp)) |
806 | while ((de = readdir (dirp))) |
1002 | { |
807 | { |
1003 | namelen = NAMLEN (de); |
808 | namelen = strlen (de->d_name); |
1004 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
809 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
1005 | continue; |
810 | continue; |
1006 | linelen += namelen + 1; |
811 | linelen += namelen + 1; |
1007 | if (linelen > 42) |
812 | if (linelen > 42) |
1008 | { |
813 | { |
… | |
… | |
1213 | return 0; |
1018 | return 0; |
1214 | } |
1019 | } |
1215 | } |
1020 | } |
1216 | |
1021 | |
1217 | int |
1022 | int |
1218 | command_quit (object *op, char *params) |
|
|
1219 | { |
|
|
1220 | new_draw_info (NDI_UNIQUE, 0, op, |
|
|
1221 | "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit."); |
|
|
1222 | return 1; |
|
|
1223 | } |
|
|
1224 | |
|
|
1225 | int |
|
|
1226 | command_real_quit (object *op, char *params) |
|
|
1227 | { |
|
|
1228 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):"); |
|
|
1229 | |
|
|
1230 | op->contr->state = ST_CONFIRM_QUIT; |
|
|
1231 | return 1; |
|
|
1232 | } |
|
|
1233 | |
|
|
1234 | /* |
|
|
1235 | * don't allow people to exit explore mode. It otherwise becomes |
|
|
1236 | * really easy to abuse this. |
|
|
1237 | */ |
|
|
1238 | int |
|
|
1239 | command_explore (object *op, char *params) |
|
|
1240 | { |
|
|
1241 | if (settings.explore_mode == FALSE) |
|
|
1242 | return 1; |
|
|
1243 | /* |
|
|
1244 | * I guess this is the best way to see if we are solo or not. Actually, |
|
|
1245 | * are there any cases when first_player->next==NULL and we are not solo? |
|
|
1246 | */ |
|
|
1247 | if ((first_player != op->contr) || (first_player->next != NULL)) |
|
|
1248 | { |
|
|
1249 | new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party"); |
|
|
1250 | } |
|
|
1251 | else if (op->contr->explore) |
|
|
1252 | new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode"); |
|
|
1253 | else |
|
|
1254 | { |
|
|
1255 | op->contr->explore = 1; |
|
|
1256 | new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode"); |
|
|
1257 | } |
|
|
1258 | return 1; |
|
|
1259 | } |
|
|
1260 | |
|
|
1261 | int |
|
|
1262 | command_sound (object *op, char *params) |
1023 | command_sound (object *op, char *params) |
1263 | { |
1024 | { |
1264 | if (op->contr->socket.sound) |
1025 | if (op->contr->ns->sound) |
1265 | { |
1026 | { |
1266 | op->contr->socket.sound = 0; |
1027 | op->contr->ns->sound = 0; |
1267 | new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden..."); |
1028 | new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden..."); |
1268 | } |
1029 | } |
1269 | else |
1030 | else |
1270 | { |
1031 | { |
1271 | op->contr->socket.sound = 1; |
1032 | op->contr->ns->sound = 1; |
1272 | new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled."); |
1033 | new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled."); |
1273 | } |
1034 | } |
1274 | return 1; |
|
|
1275 | } |
|
|
1276 | |
1035 | |
1277 | /* Perhaps these should be in player.c, but that file is |
|
|
1278 | * already a bit big. |
|
|
1279 | */ |
|
|
1280 | |
|
|
1281 | void |
|
|
1282 | receive_player_name (object *op, char k) |
|
|
1283 | { |
|
|
1284 | |
|
|
1285 | if (!check_name (op->contr, op->contr->write_buf + 1)) |
|
|
1286 | { |
|
|
1287 | get_name (op); |
|
|
1288 | return; |
|
|
1289 | } |
|
|
1290 | op->name = op->contr->write_buf + 1; |
|
|
1291 | op->name_pl = op->contr->write_buf + 1; |
|
|
1292 | new_draw_info (NDI_UNIQUE, 0, op, op->contr->write_buf); |
|
|
1293 | op->contr->name_changed = 1; |
|
|
1294 | get_password (op); |
|
|
1295 | } |
|
|
1296 | |
|
|
1297 | void |
|
|
1298 | receive_player_password (object *op, char k) |
|
|
1299 | { |
|
|
1300 | |
|
|
1301 | unsigned int pwd_len = strlen (op->contr->write_buf); |
|
|
1302 | |
|
|
1303 | if (pwd_len <= 1 || pwd_len > 17) |
|
|
1304 | { |
|
|
1305 | get_name (op); |
|
|
1306 | return; |
|
|
1307 | } |
|
|
1308 | new_draw_info (NDI_UNIQUE, 0, op, " "); /* To hide the password better */ |
|
|
1309 | |
|
|
1310 | if (checkbanned (op->name, op->contr->socket.host)) |
|
|
1311 | { |
|
|
1312 | LOG (llevInfo, "Banned player tried to add: [%s@%s]\n", &op->name, op->contr->socket.host); |
|
|
1313 | new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, "You are not allowed to play."); |
|
|
1314 | get_name (op); |
|
|
1315 | return; |
|
|
1316 | } |
|
|
1317 | |
|
|
1318 | if (op->contr->state == ST_CONFIRM_PASSWORD) |
|
|
1319 | { |
|
|
1320 | if (!check_password (op->contr->write_buf + 1, op->contr->password)) |
|
|
1321 | { |
|
|
1322 | new_draw_info (NDI_UNIQUE, 0, op, "The passwords did not match."); |
|
|
1323 | get_name (op); |
|
|
1324 | return; |
|
|
1325 | } |
|
|
1326 | clear_win_info (op); |
|
|
1327 | display_motd (op); |
|
|
1328 | new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
1329 | new_draw_info (NDI_UNIQUE, 0, op, "Welcome, Brave New Warrior!"); |
|
|
1330 | new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
1331 | Roll_Again (op); |
|
|
1332 | op->contr->state = ST_ROLL_STAT; |
|
|
1333 | return; |
|
|
1334 | } |
|
|
1335 | strcpy (op->contr->password, crypt_string (op->contr->write_buf + 1, NULL)); |
|
|
1336 | op->contr->state = ST_ROLL_STAT; |
|
|
1337 | check_login (op); |
|
|
1338 | return; |
|
|
1339 | } |
|
|
1340 | |
|
|
1341 | |
|
|
1342 | int |
|
|
1343 | explore_mode (void) |
|
|
1344 | { |
|
|
1345 | player *pl; |
|
|
1346 | |
|
|
1347 | if (settings.explore_mode == TRUE) |
|
|
1348 | { |
|
|
1349 | for (pl = first_player; pl != (player *) NULL; pl = pl->next) |
|
|
1350 | if (pl->explore) |
|
|
1351 | return 1; |
|
|
1352 | } |
|
|
1353 | return 0; |
1036 | return 1; |
1354 | } |
1037 | } |
1355 | |
|
|
1356 | |
1038 | |
1357 | int |
1039 | int |
1358 | command_title (object *op, char *params) |
1040 | command_title (object *op, char *params) |
1359 | { |
1041 | { |
1360 | char buf[MAX_BUF]; |
1042 | char buf[MAX_BUF]; |
… | |
… | |
1399 | strcpy (op->contr->own_title, params); |
1081 | strcpy (op->contr->own_title, params); |
1400 | return 1; |
1082 | return 1; |
1401 | } |
1083 | } |
1402 | |
1084 | |
1403 | int |
1085 | int |
1404 | command_save (object *op, char *params) |
|
|
1405 | { |
|
|
1406 | // if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_CLERIC) { |
|
|
1407 | // new_draw_info(NDI_UNIQUE, 0, op, "You can not save on unholy ground"); |
|
|
1408 | // } else |
|
|
1409 | if (!op->stats.exp) |
|
|
1410 | { |
|
|
1411 | new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet."); |
|
|
1412 | } |
|
|
1413 | else |
|
|
1414 | { |
|
|
1415 | if (save_player (op, 1)) |
|
|
1416 | new_draw_info (NDI_UNIQUE, 0, op, "You have been saved."); |
|
|
1417 | else |
|
|
1418 | new_draw_info (NDI_UNIQUE, 0, op, "SAVE FAILED!"); |
|
|
1419 | } |
|
|
1420 | return 1; |
|
|
1421 | } |
|
|
1422 | |
|
|
1423 | |
|
|
1424 | int |
|
|
1425 | command_peaceful (object *op, char *params) |
1086 | command_peaceful (object *op, char *params) |
1426 | { |
1087 | { |
1427 | new_draw_info (NDI_UNIQUE, 0, op, |
1088 | new_draw_info (NDI_UNIQUE, 0, op, |
1428 | "You cannot change your peaceful setting with this command." |
1089 | "You cannot change your peaceful setting with this command." |
1429 | " Please speak to the priest in the temple of Gorokh" |
1090 | " Please speak to the priest in the temple of Gorokh" |
… | |
… | |
1436 | new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players."); |
1097 | new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players."); |
1437 | */ |
1098 | */ |
1438 | return 1; |
1099 | return 1; |
1439 | } |
1100 | } |
1440 | |
1101 | |
1441 | |
|
|
1442 | |
|
|
1443 | int |
1102 | int |
1444 | command_wimpy (object *op, char *params) |
1103 | command_wimpy (object *op, char *params) |
1445 | { |
1104 | { |
1446 | int i; |
1105 | int i; |
1447 | char buf[MAX_BUF]; |
1106 | char buf[MAX_BUF]; |
… | |
… | |
1456 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1115 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1457 | op->run_away = i; |
1116 | op->run_away = i; |
1458 | return 1; |
1117 | return 1; |
1459 | } |
1118 | } |
1460 | |
1119 | |
1461 | |
|
|
1462 | int |
1120 | int |
1463 | command_brace (object *op, char *params) |
1121 | command_brace (object *op, char *params) |
1464 | { |
1122 | { |
1465 | if (!params) |
1123 | if (!params) |
1466 | op->contr->braced = !op->contr->braced; |
1124 | op->contr->braced = !op->contr->braced; |
… | |
… | |
1470 | if (op->contr->braced) |
1128 | if (op->contr->braced) |
1471 | new_draw_info (NDI_UNIQUE, 0, op, "You are braced."); |
1129 | new_draw_info (NDI_UNIQUE, 0, op, "You are braced."); |
1472 | else |
1130 | else |
1473 | new_draw_info (NDI_UNIQUE, 0, op, "Not braced."); |
1131 | new_draw_info (NDI_UNIQUE, 0, op, "Not braced."); |
1474 | |
1132 | |
1475 | fix_player (op); |
1133 | op->update_stats (); |
1476 | return 0; |
|
|
1477 | } |
|
|
1478 | |
|
|
1479 | int |
|
|
1480 | command_style_map_info (object *op, char *params) |
|
|
1481 | { |
|
|
1482 | extern maptile *styles; |
|
|
1483 | maptile *mp; |
|
|
1484 | int maps_used = 0, mapmem = 0, objects_used = 0, x, y; |
|
|
1485 | object *tmp; |
|
|
1486 | |
|
|
1487 | for (mp = styles; mp != NULL; mp = mp->next) |
|
|
1488 | { |
|
|
1489 | maps_used++; |
|
|
1490 | mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile); |
|
|
1491 | for (x = 0; x < MAP_WIDTH (mp); x++) |
|
|
1492 | { |
|
|
1493 | for (y = 0; y < MAP_HEIGHT (mp); y++) |
|
|
1494 | { |
|
|
1495 | for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above) |
|
|
1496 | objects_used++; |
|
|
1497 | } |
|
|
1498 | } |
|
|
1499 | } |
|
|
1500 | new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used); |
|
|
1501 | new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not"); |
|
|
1502 | new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem); |
|
|
1503 | new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used); |
|
|
1504 | new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object)); |
|
|
1505 | return 0; |
1134 | return 0; |
1506 | } |
1135 | } |
1507 | |
1136 | |
1508 | int |
1137 | int |
1509 | command_kill_pets (object *op, char *params) |
1138 | command_kill_pets (object *op, char *params) |
… | |
… | |
1523 | for (obl = first_friendly_object; obl != NULL; obl = next) |
1152 | for (obl = first_friendly_object; obl != NULL; obl = next) |
1524 | { |
1153 | { |
1525 | object *ob = obl->ob; |
1154 | object *ob = obl->ob; |
1526 | |
1155 | |
1527 | next = obl->next; |
1156 | next = obl->next; |
1528 | if (get_owner (ob) == op) |
1157 | if (ob->owner == op) |
1529 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
1158 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
1530 | { |
1159 | { |
1531 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
|
|
1532 | remove_ob (ob); |
|
|
1533 | remove_friendly_object (ob); |
|
|
1534 | free_object (ob); |
1160 | ob->destroy (); |
1535 | removecount++; |
1161 | removecount++; |
1536 | } |
1162 | } |
1537 | } |
1163 | } |
1538 | if (removecount != 0) |
1164 | if (removecount != 0) |
1539 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
1165 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |