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 | #include <sproto.h> |
27 | #include <sproto.h> |
27 | |
28 | |
28 | #include <dirent.h> |
|
|
29 | |
|
|
30 | extern weathermap_t **weathermap; |
|
|
31 | |
|
|
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[31]; |
|
|
41 | long sec = time (0); |
|
|
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 | |
|
|
46 | for_all_maps (m) |
|
|
47 | { |
|
|
48 | if (search && !strstr (m->path, search)) |
|
|
49 | continue; /* Skip unwanted maps */ |
|
|
50 | |
|
|
51 | /* Print out the last 30 characters of the map name... */ |
|
|
52 | strcpy (map_path, m->path + max (0, (int)strlen (m->path) - 30)); |
|
|
53 | |
|
|
54 | sprintf (buf, "%-30.30s %2d %2d %1d %4d %2d %02d:%02d:%02d", |
|
|
55 | map_path, m->players, players_on_map (m, FALSE), |
|
|
56 | m->in_memory, m->timeout, m->difficulty, |
|
|
57 | (m->reset_time % 86400) / 3600, (m->reset_time % 3600) / 60, m->reset_time % 60); |
|
|
58 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
59 | } |
|
|
60 | } |
|
|
61 | |
32 | |
62 | /* This command dumps the body information for object *op. |
33 | /* This command dumps the body information for object *op. |
63 | * it doesn't care what the params are. |
34 | * it doesn't care what the params are. |
64 | * This is mostly meant as a debug command. |
35 | * This is mostly meant as a debug command. |
65 | */ |
36 | */ |
… | |
… | |
98 | { |
69 | { |
99 | display_motd (op); |
70 | display_motd (op); |
100 | return 1; |
71 | return 1; |
101 | } |
72 | } |
102 | |
73 | |
103 | int |
|
|
104 | command_bug (object *op, char *params) |
|
|
105 | { |
|
|
106 | char buf[MAX_BUF]; |
|
|
107 | |
|
|
108 | if (params == NULL) |
|
|
109 | { |
|
|
110 | new_draw_info (NDI_UNIQUE, 0, op, "what bugs?"); |
|
|
111 | return 1; |
|
|
112 | } |
|
|
113 | strcpy (buf, op->name); |
|
|
114 | strcat (buf, " bug-reports: "); |
|
|
115 | strncat (buf, ++params, MAX_BUF - strlen (buf)); |
|
|
116 | buf[MAX_BUF - 1] = '\0'; |
|
|
117 | bug_report (buf); |
|
|
118 | LOG (llevError, "%s\n", buf); |
|
|
119 | new_draw_info (NDI_ALL | NDI_UNIQUE, 1, NULL, buf); |
|
|
120 | new_draw_info (NDI_UNIQUE, 0, op, "OK, thanks!"); |
|
|
121 | return 1; |
|
|
122 | } |
|
|
123 | |
|
|
124 | /* |
74 | /* |
125 | * Pretty much identical to current map_info, but on a bigger scale |
75 | * Pretty much identical to current map_info, but on a bigger scale |
126 | * This function returns the name of the players current region, and |
76 | * This function returns the name of the players current region, and |
127 | * a description of it. It is there merely for flavour text. |
77 | * a description of it. It is there merely for flavour text. |
128 | */ |
78 | */ |
129 | void |
79 | void |
130 | current_region_info (object *op) |
80 | current_region_info (object *op) |
131 | { |
81 | { |
132 | /* |
82 | if (region *reg = op->region ()) |
133 | * Ok I /suppose/ I should write a seperate function for this, but it isn't |
|
|
134 | * going to be /that/ slow, and won't get called much |
|
|
135 | */ |
|
|
136 | region *r = get_region_by_name (get_name_of_region_for_map (op->map)); |
|
|
137 | |
|
|
138 | if (!r) |
|
|
139 | return; |
|
|
140 | /* This should only be possible if regions are not operating on this server. */ |
|
|
141 | |
|
|
142 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s. \n %s", get_region_longname (r), get_region_msg (r)); |
83 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are %s.\n%s", ®->longname, ®->msg); |
143 | } |
84 | } |
144 | |
85 | |
145 | void |
86 | void |
146 | current_map_info (object *op) |
87 | current_map_info (object *op) |
147 | { |
88 | { |
148 | maptile *m = op->map; |
89 | maptile *m = op->map; |
149 | |
90 | |
150 | if (!m) |
91 | if (!m) |
151 | return; |
92 | return; |
152 | |
93 | |
153 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", m->name, m->path, get_name_of_region_for_map (m)); |
94 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) %s", &m->name, &m->path, &op->region ()->longname); |
154 | |
95 | |
155 | if (QUERY_FLAG (op, FLAG_WIZ)) |
96 | if (QUERY_FLAG (op, FLAG_WIZ)) |
156 | { |
|
|
157 | new_draw_info_format (NDI_UNIQUE, 0, op, |
97 | new_draw_info_format (NDI_UNIQUE, 0, op, |
158 | "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld", |
98 | "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld", |
159 | m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout); |
99 | m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout); |
160 | |
100 | |
161 | } |
|
|
162 | if (m->msg) |
101 | if (m->msg) |
163 | new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); |
102 | new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); |
164 | } |
103 | } |
165 | |
104 | |
166 | #ifdef DEBUG_MALLOC_LEVEL |
105 | #ifdef DEBUG_MALLOC_LEVEL |
… | |
… | |
178 | #endif |
117 | #endif |
179 | |
118 | |
180 | int |
119 | int |
181 | command_whereabouts (object *op, char *params) |
120 | command_whereabouts (object *op, char *params) |
182 | { |
121 | { |
183 | |
122 | //TODO: should obviously not waste space in struct region for this. |
184 | region *reg; |
|
|
185 | player *pl; |
|
|
186 | |
|
|
187 | /* |
123 | /* |
188 | * reset the counter on the region, then use it to store the number of |
124 | * reset the counter on the region, then use it to store the number of |
189 | * players there. |
125 | * players there. |
190 | * I don't know how thread-safe this would be, I suspect not very.... |
126 | * I don't know how thread-safe this would be, I suspect not very.... |
191 | */ |
127 | */ |
192 | for (reg = first_region; reg != NULL; reg = reg->next) |
128 | for_all_regions (rgn) |
193 | { |
|
|
194 | reg->counter = 0; |
129 | rgn->counter = 0; |
195 | } |
130 | |
196 | for_all_players (pl) |
131 | for_all_players (pl) |
197 | if (pl->ob->map != NULL) |
132 | if (pl->ob->map) |
198 | get_region_by_map (pl->ob->map)->counter++; |
133 | ++pl->ob->region ()->counter; |
199 | |
134 | |
200 | /* we only want to print out by places with a 'longname' field... */ |
135 | /* we only want to print out by places with a 'longname' field... */ |
201 | for (reg = first_region; reg != NULL; reg = reg->next) |
136 | for_all_regions (rgn) |
202 | { |
137 | { |
203 | if (reg->longname == NULL && reg->counter > 0) |
138 | if (!rgn->longname && rgn->counter > 0) |
204 | { |
139 | { |
205 | if (reg->parent != NULL) |
140 | if (rgn->parent) |
206 | { |
141 | { |
207 | reg->parent->counter += reg->counter; |
142 | rgn->parent->counter += rgn->counter; |
208 | reg->counter = 0; |
143 | rgn->counter = 0; |
209 | } |
144 | } |
210 | else /*uh oh, we shouldn't be here. */ |
145 | else /*uh oh, we shouldn't be here. */ |
211 | LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name); |
146 | LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", &rgn->name); |
212 | } |
147 | } |
213 | } |
148 | } |
|
|
149 | |
214 | new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); |
150 | new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); |
215 | for (reg = first_region; reg != NULL; reg = reg->next) |
151 | |
|
|
152 | for_all_regions (rgn) |
216 | if (reg->counter > 0) |
153 | if (rgn->counter) |
217 | new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg)); |
154 | new_draw_info_format (NDI_UNIQUE, 0, op, "%u players %s", rgn->counter, &rgn->longname); |
|
|
155 | |
218 | return 1; |
156 | return 1; |
219 | } |
157 | } |
220 | |
158 | |
221 | typedef struct |
159 | typedef struct |
222 | { |
160 | { |
223 | char namebuf[MAX_BUF]; |
161 | char namebuf[MAX_BUF]; |
224 | int login_order; |
162 | int login_order; |
225 | } chars_names; |
163 | } chars_names; |
226 | |
164 | |
227 | int |
165 | int |
228 | command_afk (object *op, char *params) |
|
|
229 | { |
|
|
230 | if ((op->contr->ns->afk = !op->contr->ns->afk)) |
|
|
231 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK"); |
|
|
232 | else |
|
|
233 | new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK"); |
|
|
234 | |
|
|
235 | return 1; |
|
|
236 | } |
|
|
237 | |
|
|
238 | int |
|
|
239 | command_mapinfo (object *op, char *params) |
166 | command_mapinfo (object *op, char *params) |
240 | { |
167 | { |
241 | current_map_info (op); |
168 | current_map_info (op); |
242 | return 1; |
169 | return 1; |
243 | } |
170 | } |
… | |
… | |
248 | current_region_info (op); |
175 | current_region_info (op); |
249 | return 1; |
176 | return 1; |
250 | } |
177 | } |
251 | |
178 | |
252 | int |
179 | int |
253 | command_maps (object *op, char *params) |
|
|
254 | { |
|
|
255 | map_info (op, params); |
|
|
256 | return 1; |
|
|
257 | } |
|
|
258 | |
|
|
259 | int |
|
|
260 | command_time (object *op, char *params) |
180 | command_time (object *op, char *params) |
261 | { |
181 | { |
262 | print_tod (op); |
182 | print_tod (op); |
263 | return 1; |
183 | return 1; |
264 | } |
184 | } |
265 | |
185 | |
266 | int |
186 | int |
267 | command_weather (object *op, char *params) |
187 | command_weather (object *op, char *params) |
268 | { |
188 | { |
|
|
189 | #if 0 |
269 | int wx, wy, temp, sky; |
190 | int wx, wy, temp, sky; |
270 | char buf[MAX_BUF]; |
191 | char buf[MAX_BUF]; |
271 | |
192 | |
272 | if (settings.dynamiclevel < 1) |
193 | if (settings.dynamiclevel < 1) |
273 | return 1; |
194 | return 1; |
… | |
… | |
389 | break; |
310 | break; |
390 | case SKY_BLIZZARD: |
311 | case SKY_BLIZZARD: |
391 | new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!"); |
312 | new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!"); |
392 | break; |
313 | break; |
393 | } |
314 | } |
394 | return 1; |
315 | #endif |
395 | } |
|
|
396 | |
|
|
397 | int |
|
|
398 | command_archs (object *op, char *params) |
|
|
399 | { |
|
|
400 | arch_info (op); |
|
|
401 | return 1; |
316 | return 1; |
402 | } |
317 | } |
403 | |
318 | |
404 | int |
319 | int |
405 | command_hiscore (object *op, char *params) |
320 | command_hiscore (object *op, char *params) |
… | |
… | |
416 | |
331 | |
417 | if (params == NULL || !sscanf (params, "%d", &i)) |
332 | if (params == NULL || !sscanf (params, "%d", &i)) |
418 | { |
333 | { |
419 | sprintf (buf, "Global debug level is %d.", settings.debug); |
334 | sprintf (buf, "Global debug level is %d.", settings.debug); |
420 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
335 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
421 | return 1; |
|
|
422 | } |
|
|
423 | if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) |
|
|
424 | { |
|
|
425 | new_draw_info (NDI_UNIQUE, 0, op, "Privileged command."); |
|
|
426 | return 1; |
336 | return 1; |
427 | } |
337 | } |
428 | settings.debug = (enum LogLevel) FABS (i); |
338 | settings.debug = (enum LogLevel) FABS (i); |
429 | sprintf (buf, "Set debug level to %d.", i); |
339 | sprintf (buf, "Set debug level to %d.", i); |
430 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
340 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
… | |
… | |
456 | dump_friendly_objects (); |
366 | dump_friendly_objects (); |
457 | return 0; |
367 | return 0; |
458 | } |
368 | } |
459 | |
369 | |
460 | int |
370 | int |
461 | command_dumpmap (object *op, char *params) |
|
|
462 | { |
|
|
463 | if (op) |
|
|
464 | dump_map (op->map); |
|
|
465 | return 0; |
|
|
466 | } |
|
|
467 | |
|
|
468 | int |
|
|
469 | command_dumpallmaps (object *op, char *params) |
|
|
470 | { |
|
|
471 | dump_all_maps (); |
|
|
472 | return 0; |
|
|
473 | } |
|
|
474 | |
|
|
475 | int |
|
|
476 | command_printlos (object *op, char *params) |
371 | command_printlos (object *op, char *params) |
477 | { |
372 | { |
478 | if (op) |
373 | if (op) |
479 | print_los (op); |
374 | print_los (op); |
480 | return 0; |
375 | return 0; |
… | |
… | |
485 | command_version (object *op, char *params) |
380 | command_version (object *op, char *params) |
486 | { |
381 | { |
487 | version (op); |
382 | version (op); |
488 | return 0; |
383 | return 0; |
489 | } |
384 | } |
490 | |
|
|
491 | |
385 | |
492 | #ifndef BUG_LOG |
386 | #ifndef BUG_LOG |
493 | # define BUG_LOG "bug_log" |
387 | # define BUG_LOG "bug_log" |
494 | #endif |
388 | #endif |
495 | void |
389 | void |
… | |
… | |
547 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count); |
441 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count); |
548 | } |
442 | } |
549 | else |
443 | else |
550 | new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count."); |
444 | new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count."); |
551 | |
445 | |
552 | return 1; |
|
|
553 | } |
|
|
554 | |
|
|
555 | int |
|
|
556 | command_listen (object *op, char *params) |
|
|
557 | { |
|
|
558 | int i; |
|
|
559 | |
|
|
560 | if (params == NULL || !sscanf (params, "%d", &i)) |
|
|
561 | { |
|
|
562 | new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening); |
|
|
563 | return 1; |
|
|
564 | } |
|
|
565 | op->contr->listening = (char) i; |
|
|
566 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i); |
|
|
567 | return 1; |
446 | return 1; |
568 | } |
447 | } |
569 | |
448 | |
570 | /* Prints out some useful information for the character. Everything we print |
449 | /* Prints out some useful information for the character. Everything we print |
571 | * out can be determined by the docs, so we aren't revealing anything extra - |
450 | * out can be determined by the docs, so we aren't revealing anything extra - |
… | |
… | |
604 | int |
483 | int |
605 | command_fix_me (object *op, char *params) |
484 | command_fix_me (object *op, char *params) |
606 | { |
485 | { |
607 | sum_weight (op); |
486 | sum_weight (op); |
608 | op->update_stats (); |
487 | op->update_stats (); |
609 | return 1; |
488 | new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed."); |
610 | } |
|
|
611 | |
489 | |
612 | int |
|
|
613 | command_players (object *op, char *paramss) |
|
|
614 | { |
|
|
615 | char buf[MAX_BUF]; |
|
|
616 | char *t; |
|
|
617 | DIR *Dir; |
|
|
618 | |
|
|
619 | sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir); |
|
|
620 | t = buf + strlen (buf); |
|
|
621 | if ((Dir = opendir (buf)) != NULL) |
|
|
622 | { |
|
|
623 | const struct dirent *Entry; |
|
|
624 | |
|
|
625 | while ((Entry = readdir (Dir))) |
|
|
626 | { |
|
|
627 | /* skip '.' , '..' */ |
|
|
628 | if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') || |
|
|
629 | (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0'))) |
|
|
630 | { |
|
|
631 | struct stat Stat; |
|
|
632 | |
|
|
633 | strcpy (t, Entry->d_name); |
|
|
634 | if (stat (buf, &Stat) == 0) |
|
|
635 | { |
|
|
636 | /* This was not posix compatible |
|
|
637 | * if ((Stat.st_mode & S_IFMT)==S_IFDIR) { |
|
|
638 | */ |
|
|
639 | if (S_ISDIR (Stat.st_mode)) |
|
|
640 | { |
|
|
641 | char buf2[MAX_BUF]; |
|
|
642 | struct tm *tm = localtime (&Stat.st_mtime); |
|
|
643 | |
|
|
644 | sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d", |
|
|
645 | Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); |
|
|
646 | new_draw_info (NDI_UNIQUE, 0, op, buf2); |
|
|
647 | } |
|
|
648 | } |
|
|
649 | } |
|
|
650 | } |
|
|
651 | } |
|
|
652 | closedir (Dir); |
|
|
653 | return 0; |
490 | return 1; |
654 | } |
491 | } |
655 | |
|
|
656 | |
|
|
657 | |
492 | |
658 | int |
493 | int |
659 | command_logs (object *op, char *params) |
494 | command_logs (object *op, char *params) |
660 | { |
495 | { |
661 | new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); |
496 | new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); |
662 | |
497 | |
663 | return 1; |
|
|
664 | } |
|
|
665 | |
|
|
666 | int |
|
|
667 | command_applymode (object *op, char *params) |
|
|
668 | { |
|
|
669 | unapplymode unapply = op->contr->unapply; |
|
|
670 | static const char *const types[] = { "nochoice", "never", "always" }; |
|
|
671 | |
|
|
672 | if (!params) |
|
|
673 | { |
|
|
674 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]); |
|
|
675 | return 1; |
|
|
676 | } |
|
|
677 | |
|
|
678 | if (!strcmp (params, "nochoice")) |
|
|
679 | op->contr->unapply = unapply_nochoice; |
|
|
680 | else if (!strcmp (params, "never")) |
|
|
681 | op->contr->unapply = unapply_never; |
|
|
682 | else if (!strcmp (params, "always")) |
|
|
683 | op->contr->unapply = unapply_always; |
|
|
684 | else |
|
|
685 | { |
|
|
686 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params); |
|
|
687 | return 0; |
|
|
688 | } |
|
|
689 | new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s", |
|
|
690 | (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]); |
|
|
691 | return 1; |
498 | return 1; |
692 | } |
499 | } |
693 | |
500 | |
694 | int |
501 | int |
695 | command_bowmode (object *op, char *params) |
502 | command_bowmode (object *op, char *params) |
… | |
… | |
715 | found++; |
522 | found++; |
716 | op->contr->bowtype = (bowtype_t) i; |
523 | op->contr->bowtype = (bowtype_t) i; |
717 | break; |
524 | break; |
718 | } |
525 | } |
719 | } |
526 | } |
|
|
527 | |
720 | if (!found) |
528 | if (!found) |
721 | { |
529 | { |
722 | sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
530 | sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
723 | for (i = 0; i <= bow_bestarrow; i++) |
531 | for (i = 0; i <= bow_bestarrow; i++) |
724 | { |
532 | { |
… | |
… | |
730 | strcat (buf, "."); |
538 | strcat (buf, "."); |
731 | } |
539 | } |
732 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
540 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
733 | return 0; |
541 | return 0; |
734 | } |
542 | } |
|
|
543 | |
735 | new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
544 | new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
736 | return 1; |
|
|
737 | } |
|
|
738 | |
|
|
739 | int |
|
|
740 | command_petmode (object *op, char *params) |
|
|
741 | { |
|
|
742 | petmode_t oldtype = op->contr->petmode; |
|
|
743 | static const char *const types[] = { "normal", "sad", "defend", "arena" }; |
|
|
744 | |
|
|
745 | if (!params) |
|
|
746 | { |
|
|
747 | new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]); |
|
|
748 | return 1; |
|
|
749 | } |
|
|
750 | |
|
|
751 | if (!strcmp (params, "normal")) |
|
|
752 | op->contr->petmode = pet_normal; |
|
|
753 | else if (!strcmp (params, "sad")) |
|
|
754 | op->contr->petmode = pet_sad; |
|
|
755 | else if (!strcmp (params, "defend")) |
|
|
756 | op->contr->petmode = pet_defend; |
|
|
757 | else if (!strcmp (params, "arena")) |
|
|
758 | op->contr->petmode = pet_arena; |
|
|
759 | else |
|
|
760 | { |
|
|
761 | new_draw_info_format (NDI_UNIQUE, 0, op, |
|
|
762 | "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params); |
|
|
763 | return 0; |
|
|
764 | } |
|
|
765 | new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]); |
|
|
766 | return 1; |
545 | return 1; |
767 | } |
546 | } |
768 | |
547 | |
769 | int |
548 | int |
770 | command_showpets (object *op, char *params) |
549 | command_showpets (object *op, char *params) |
… | |
… | |
811 | new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); |
590 | new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); |
812 | return 0; |
591 | return 0; |
813 | } |
592 | } |
814 | |
593 | |
815 | int |
594 | int |
816 | command_usekeys (object *op, char *params) |
|
|
817 | { |
|
|
818 | usekeytype oldtype = op->contr->usekeys; |
|
|
819 | static const char *const types[] = { "inventory", "keyrings", "containers" }; |
|
|
820 | |
|
|
821 | if (!params) |
|
|
822 | { |
|
|
823 | new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]); |
|
|
824 | return 1; |
|
|
825 | } |
|
|
826 | |
|
|
827 | if (!strcmp (params, "inventory")) |
|
|
828 | op->contr->usekeys = key_inventory; |
|
|
829 | else if (!strcmp (params, "keyrings")) |
|
|
830 | op->contr->usekeys = keyrings; |
|
|
831 | else if (!strcmp (params, "containers")) |
|
|
832 | op->contr->usekeys = containers; |
|
|
833 | else |
|
|
834 | { |
|
|
835 | new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params); |
|
|
836 | return 0; |
|
|
837 | } |
|
|
838 | new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]); |
|
|
839 | return 1; |
|
|
840 | } |
|
|
841 | |
|
|
842 | int |
|
|
843 | command_resistances (object *op, char *params) |
595 | command_resistances (object *op, char *params) |
844 | { |
596 | { |
845 | int i; |
597 | int i; |
846 | |
598 | |
847 | if (!op) |
599 | if (!op) |
… | |
… | |
913 | |
665 | |
914 | if (!(dirp = opendir (filename))) |
666 | if (!(dirp = opendir (filename))) |
915 | return; |
667 | return; |
916 | |
668 | |
917 | line[0] = '\0'; |
669 | line[0] = '\0'; |
918 | while (de = readdir (dirp)) |
670 | while ((de = readdir (dirp))) |
919 | { |
671 | { |
920 | namelen = strlen (de->d_name); |
672 | namelen = strlen (de->d_name); |
921 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
673 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
922 | continue; |
674 | continue; |
923 | linelen += namelen + 1; |
675 | linelen += namelen + 1; |
… | |
… | |
1130 | return 0; |
882 | return 0; |
1131 | } |
883 | } |
1132 | } |
884 | } |
1133 | |
885 | |
1134 | int |
886 | int |
1135 | command_quit (object *op, char *params) |
|
|
1136 | { |
|
|
1137 | new_draw_info (NDI_UNIQUE, 0, op, |
|
|
1138 | "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit."); |
|
|
1139 | return 1; |
|
|
1140 | } |
|
|
1141 | |
|
|
1142 | int |
|
|
1143 | command_real_quit (object *op, char *params) |
|
|
1144 | { |
|
|
1145 | send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):"); |
|
|
1146 | |
|
|
1147 | op->contr->ns->state = ST_CONFIRM_QUIT; |
|
|
1148 | return 1; |
|
|
1149 | } |
|
|
1150 | |
|
|
1151 | /* |
|
|
1152 | * don't allow people to exit explore mode. It otherwise becomes |
|
|
1153 | * really easy to abuse this. |
|
|
1154 | */ |
|
|
1155 | int |
|
|
1156 | command_explore (object *op, char *params) |
|
|
1157 | { |
|
|
1158 | if (settings.explore_mode == FALSE) |
|
|
1159 | return 1; |
|
|
1160 | /* |
|
|
1161 | * I guess this is the best way to see if we are solo or not. Actually, |
|
|
1162 | * are there any cases when first_player->next==NULL and we are not solo? |
|
|
1163 | */ |
|
|
1164 | if ((first_player != op->contr) || (first_player->next != NULL)) |
|
|
1165 | { |
|
|
1166 | new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party"); |
|
|
1167 | } |
|
|
1168 | else if (op->contr->explore) |
|
|
1169 | new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode"); |
|
|
1170 | else |
|
|
1171 | { |
|
|
1172 | op->contr->explore = 1; |
|
|
1173 | new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode"); |
|
|
1174 | } |
|
|
1175 | return 1; |
|
|
1176 | } |
|
|
1177 | |
|
|
1178 | int |
|
|
1179 | command_sound (object *op, char *params) |
|
|
1180 | { |
|
|
1181 | if (op->contr->ns->sound) |
|
|
1182 | { |
|
|
1183 | op->contr->ns->sound = 0; |
|
|
1184 | new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden..."); |
|
|
1185 | } |
|
|
1186 | else |
|
|
1187 | { |
|
|
1188 | op->contr->ns->sound = 1; |
|
|
1189 | new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled."); |
|
|
1190 | } |
|
|
1191 | |
|
|
1192 | return 1; |
|
|
1193 | } |
|
|
1194 | |
|
|
1195 | int |
|
|
1196 | explore_mode (void) |
|
|
1197 | { |
|
|
1198 | player *pl; |
|
|
1199 | |
|
|
1200 | if (settings.explore_mode == TRUE) |
|
|
1201 | { |
|
|
1202 | for (pl = first_player; pl != (player *) NULL; pl = pl->next) |
|
|
1203 | if (pl->explore) |
|
|
1204 | return 1; |
|
|
1205 | } |
|
|
1206 | return 0; |
|
|
1207 | } |
|
|
1208 | |
|
|
1209 | int |
|
|
1210 | command_title (object *op, char *params) |
887 | command_title (object *op, char *params) |
1211 | { |
888 | { |
1212 | char buf[MAX_BUF]; |
889 | char buf[MAX_BUF]; |
1213 | |
890 | |
1214 | if (settings.set_title == FALSE) |
891 | if (settings.set_title == FALSE) |
… | |
… | |
1248 | new_draw_info (NDI_UNIQUE, 0, op, "Title too long."); |
925 | new_draw_info (NDI_UNIQUE, 0, op, "Title too long."); |
1249 | return 1; |
926 | return 1; |
1250 | } |
927 | } |
1251 | strcpy (op->contr->own_title, params); |
928 | strcpy (op->contr->own_title, params); |
1252 | return 1; |
929 | return 1; |
1253 | } |
|
|
1254 | |
|
|
1255 | int |
|
|
1256 | command_save (object *op, char *params) |
|
|
1257 | { |
|
|
1258 | if (!op->stats.exp) |
|
|
1259 | new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet."); |
|
|
1260 | else |
|
|
1261 | { |
|
|
1262 | op->contr->save (); |
|
|
1263 | new_draw_info (NDI_UNIQUE, 0, op, "You have been saved."); |
|
|
1264 | } |
|
|
1265 | |
|
|
1266 | return 1; |
|
|
1267 | } |
|
|
1268 | |
|
|
1269 | int |
|
|
1270 | command_peaceful (object *op, char *params) |
|
|
1271 | { |
|
|
1272 | new_draw_info (NDI_UNIQUE, 0, op, |
|
|
1273 | "You cannot change your peaceful setting with this command." |
|
|
1274 | " Please speak to the priest in the temple of Gorokh" |
|
|
1275 | " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again."); |
|
|
1276 | |
|
|
1277 | /* |
|
|
1278 | if((op->contr->peaceful=!op->contr->peaceful)) |
|
|
1279 | new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players."); |
|
|
1280 | else |
|
|
1281 | new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players."); |
|
|
1282 | */ |
|
|
1283 | return 1; |
|
|
1284 | } |
|
|
1285 | |
|
|
1286 | int |
|
|
1287 | command_wimpy (object *op, char *params) |
|
|
1288 | { |
|
|
1289 | int i; |
|
|
1290 | char buf[MAX_BUF]; |
|
|
1291 | |
|
|
1292 | if (params == NULL || !sscanf (params, "%d", &i)) |
|
|
1293 | { |
|
|
1294 | sprintf (buf, "Your current wimpy level is %d.", op->run_away); |
|
|
1295 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
1296 | return 1; |
|
|
1297 | } |
|
|
1298 | sprintf (buf, "Your new wimpy level is %d.", i); |
|
|
1299 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
1300 | op->run_away = i; |
|
|
1301 | return 1; |
|
|
1302 | } |
|
|
1303 | |
|
|
1304 | int |
|
|
1305 | command_brace (object *op, char *params) |
|
|
1306 | { |
|
|
1307 | if (!params) |
|
|
1308 | op->contr->braced = !op->contr->braced; |
|
|
1309 | else |
|
|
1310 | op->contr->braced = onoff_value (params); |
|
|
1311 | |
|
|
1312 | if (op->contr->braced) |
|
|
1313 | new_draw_info (NDI_UNIQUE, 0, op, "You are braced."); |
|
|
1314 | else |
|
|
1315 | new_draw_info (NDI_UNIQUE, 0, op, "Not braced."); |
|
|
1316 | |
|
|
1317 | op->update_stats (); |
|
|
1318 | return 0; |
|
|
1319 | } |
|
|
1320 | |
|
|
1321 | int |
|
|
1322 | command_style_map_info (object *op, char *params) |
|
|
1323 | { |
|
|
1324 | extern maptile *styles; |
|
|
1325 | maptile *mp; |
|
|
1326 | int maps_used = 0, mapmem = 0, objects_used = 0, x, y; |
|
|
1327 | object *tmp; |
|
|
1328 | |
|
|
1329 | for (mp = styles; mp != NULL; mp = mp->next) |
|
|
1330 | { |
|
|
1331 | maps_used++; |
|
|
1332 | mapmem += mp->width * mp->height * (sizeof (object *) + sizeof (mapspace)) + sizeof (maptile); |
|
|
1333 | for (x = 0; x < mp->width; x++) |
|
|
1334 | { |
|
|
1335 | for (y = 0; y < mp->height; y++) |
|
|
1336 | { |
|
|
1337 | for (tmp = GET_MAP_OB (mp, x, y); tmp != NULL; tmp = tmp->above) |
|
|
1338 | objects_used++; |
|
|
1339 | } |
|
|
1340 | } |
|
|
1341 | } |
|
|
1342 | new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used); |
|
|
1343 | new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not"); |
|
|
1344 | new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem); |
|
|
1345 | new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used); |
|
|
1346 | new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object)); |
|
|
1347 | return 0; |
|
|
1348 | } |
930 | } |
1349 | |
931 | |
1350 | int |
932 | int |
1351 | command_kill_pets (object *op, char *params) |
933 | command_kill_pets (object *op, char *params) |
1352 | { |
934 | { |