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 | */ |
… | |
… | |
99 | { |
69 | { |
100 | display_motd (op); |
70 | display_motd (op); |
101 | return 1; |
71 | return 1; |
102 | } |
72 | } |
103 | |
73 | |
104 | int |
|
|
105 | command_bug (object *op, char *params) |
|
|
106 | { |
|
|
107 | char buf[MAX_BUF]; |
|
|
108 | |
|
|
109 | if (params == NULL) |
|
|
110 | { |
|
|
111 | new_draw_info (NDI_UNIQUE, 0, op, "what bugs?"); |
|
|
112 | return 1; |
|
|
113 | } |
|
|
114 | strcpy (buf, op->name); |
|
|
115 | strcat (buf, " bug-reports: "); |
|
|
116 | strncat (buf, ++params, MAX_BUF - strlen (buf)); |
|
|
117 | buf[MAX_BUF - 1] = '\0'; |
|
|
118 | bug_report (buf); |
|
|
119 | LOG (llevError, "%s\n", buf); |
|
|
120 | new_draw_info (NDI_ALL | NDI_UNIQUE, 1, NULL, buf); |
|
|
121 | new_draw_info (NDI_UNIQUE, 0, op, "OK, thanks!"); |
|
|
122 | return 1; |
|
|
123 | } |
|
|
124 | |
|
|
125 | /* |
74 | /* |
126 | * 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 |
127 | * This function returns the name of the players current region, and |
76 | * This function returns the name of the players current region, and |
128 | * a description of it. It is there merely for flavour text. |
77 | * a description of it. It is there merely for flavour text. |
129 | */ |
78 | */ |
130 | void |
79 | void |
131 | current_region_info (object *op) |
80 | current_region_info (object *op) |
132 | { |
81 | { |
133 | /* |
82 | 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)); |
83 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are %s.\n%s", ®->longname, ®->msg); |
144 | } |
84 | } |
145 | |
85 | |
146 | void |
86 | void |
147 | current_map_info (object *op) |
87 | current_map_info (object *op) |
148 | { |
88 | { |
149 | maptile *m = op->map; |
89 | maptile *m = op->map; |
150 | |
90 | |
151 | if (!m) |
91 | if (!m) |
152 | return; |
92 | return; |
153 | |
93 | |
154 | 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); |
155 | |
95 | |
156 | if (QUERY_FLAG (op, FLAG_WIZ)) |
96 | if (QUERY_FLAG (op, FLAG_WIZ)) |
157 | { |
|
|
158 | new_draw_info_format (NDI_UNIQUE, 0, op, |
97 | new_draw_info_format (NDI_UNIQUE, 0, op, |
159 | "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", |
160 | m->players, m->difficulty, MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m), MAP_TIMEOUT (m)); |
99 | m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout); |
161 | |
100 | |
162 | } |
|
|
163 | if (m->msg) |
101 | if (m->msg) |
164 | new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); |
102 | new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); |
165 | } |
103 | } |
166 | |
104 | |
167 | #ifdef DEBUG_MALLOC_LEVEL |
105 | #ifdef DEBUG_MALLOC_LEVEL |
… | |
… | |
179 | #endif |
117 | #endif |
180 | |
118 | |
181 | int |
119 | int |
182 | command_whereabouts (object *op, char *params) |
120 | command_whereabouts (object *op, char *params) |
183 | { |
121 | { |
184 | |
122 | //TODO: should obviously not waste space in struct region for this. |
185 | region *reg; |
|
|
186 | player *pl; |
|
|
187 | |
|
|
188 | /* |
123 | /* |
189 | * 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 |
190 | * players there. |
125 | * players there. |
191 | * 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.... |
192 | */ |
127 | */ |
193 | for (reg = first_region; reg != NULL; reg = reg->next) |
128 | for_all_regions (rgn) |
194 | { |
|
|
195 | reg->counter = 0; |
129 | rgn->counter = 0; |
196 | } |
130 | |
197 | for (pl = first_player; pl != NULL; pl = pl->next) |
131 | for_all_players (pl) |
198 | if (pl->ob->map != NULL) |
132 | if (pl->ob->map) |
199 | get_region_by_map (pl->ob->map)->counter++; |
133 | ++pl->ob->region ()->counter; |
200 | |
134 | |
201 | /* 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... */ |
202 | for (reg = first_region; reg != NULL; reg = reg->next) |
136 | for_all_regions (rgn) |
203 | { |
137 | { |
204 | if (reg->longname == NULL && reg->counter > 0) |
138 | if (!rgn->longname && rgn->counter > 0) |
205 | { |
139 | { |
206 | if (reg->parent != NULL) |
140 | if (rgn->parent) |
207 | { |
141 | { |
208 | reg->parent->counter += reg->counter; |
142 | rgn->parent->counter += rgn->counter; |
209 | reg->counter = 0; |
143 | rgn->counter = 0; |
210 | } |
144 | } |
211 | else /*uh oh, we shouldn't be here. */ |
145 | else /*uh oh, we shouldn't be here. */ |
212 | 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); |
213 | } |
147 | } |
214 | } |
148 | } |
|
|
149 | |
215 | 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:"); |
216 | for (reg = first_region; reg != NULL; reg = reg->next) |
151 | |
|
|
152 | for_all_regions (rgn) |
217 | if (reg->counter > 0) |
153 | if (rgn->counter) |
218 | 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 | |
219 | return 1; |
156 | return 1; |
220 | } |
157 | } |
221 | |
158 | |
222 | typedef struct |
159 | typedef struct |
223 | { |
160 | { |
224 | char namebuf[MAX_BUF]; |
161 | char namebuf[MAX_BUF]; |
225 | int login_order; |
162 | int login_order; |
226 | } chars_names; |
163 | } chars_names; |
227 | |
164 | |
228 | int |
165 | int |
229 | command_afk (object *op, char *params) |
|
|
230 | { |
|
|
231 | if QUERY_FLAG |
|
|
232 | (op, FLAG_AFK) |
|
|
233 | { |
|
|
234 | CLEAR_FLAG (op, FLAG_AFK); |
|
|
235 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK"); |
|
|
236 | } |
|
|
237 | else |
|
|
238 | { |
|
|
239 | SET_FLAG (op, FLAG_AFK); |
|
|
240 | new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK"); |
|
|
241 | } |
|
|
242 | return 1; |
|
|
243 | } |
|
|
244 | |
|
|
245 | int |
|
|
246 | command_mapinfo (object *op, char *params) |
166 | command_mapinfo (object *op, char *params) |
247 | { |
167 | { |
248 | current_map_info (op); |
168 | current_map_info (op); |
249 | return 1; |
169 | return 1; |
250 | } |
170 | } |
… | |
… | |
255 | current_region_info (op); |
175 | current_region_info (op); |
256 | return 1; |
176 | return 1; |
257 | } |
177 | } |
258 | |
178 | |
259 | int |
179 | int |
260 | command_maps (object *op, char *params) |
|
|
261 | { |
|
|
262 | map_info (op, params); |
|
|
263 | return 1; |
|
|
264 | } |
|
|
265 | |
|
|
266 | int |
|
|
267 | command_time (object *op, char *params) |
180 | command_time (object *op, char *params) |
268 | { |
181 | { |
269 | print_tod (op); |
182 | print_tod (op); |
270 | return 1; |
183 | return 1; |
271 | } |
184 | } |
272 | |
185 | |
273 | int |
186 | int |
274 | command_weather (object *op, char *params) |
187 | command_weather (object *op, char *params) |
275 | { |
188 | { |
|
|
189 | #if 0 |
276 | int wx, wy, temp, sky; |
190 | int wx, wy, temp, sky; |
277 | char buf[MAX_BUF]; |
191 | char buf[MAX_BUF]; |
278 | |
192 | |
279 | if (settings.dynamiclevel < 1) |
193 | if (settings.dynamiclevel < 1) |
280 | return 1; |
194 | return 1; |
… | |
… | |
396 | break; |
310 | break; |
397 | case SKY_BLIZZARD: |
311 | case SKY_BLIZZARD: |
398 | 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!"); |
399 | break; |
313 | break; |
400 | } |
314 | } |
401 | return 1; |
315 | #endif |
402 | } |
|
|
403 | |
|
|
404 | int |
|
|
405 | command_archs (object *op, char *params) |
|
|
406 | { |
|
|
407 | arch_info (op); |
|
|
408 | return 1; |
316 | return 1; |
409 | } |
317 | } |
410 | |
318 | |
411 | int |
319 | int |
412 | command_hiscore (object *op, char *params) |
320 | command_hiscore (object *op, char *params) |
… | |
… | |
423 | |
331 | |
424 | if (params == NULL || !sscanf (params, "%d", &i)) |
332 | if (params == NULL || !sscanf (params, "%d", &i)) |
425 | { |
333 | { |
426 | sprintf (buf, "Global debug level is %d.", settings.debug); |
334 | sprintf (buf, "Global debug level is %d.", settings.debug); |
427 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
335 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
428 | return 1; |
|
|
429 | } |
|
|
430 | if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) |
|
|
431 | { |
|
|
432 | new_draw_info (NDI_UNIQUE, 0, op, "Privileged command."); |
|
|
433 | return 1; |
336 | return 1; |
434 | } |
337 | } |
435 | settings.debug = (enum LogLevel) FABS (i); |
338 | settings.debug = (enum LogLevel) FABS (i); |
436 | sprintf (buf, "Set debug level to %d.", i); |
339 | sprintf (buf, "Set debug level to %d.", i); |
437 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
340 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
… | |
… | |
463 | dump_friendly_objects (); |
366 | dump_friendly_objects (); |
464 | return 0; |
367 | return 0; |
465 | } |
368 | } |
466 | |
369 | |
467 | int |
370 | int |
468 | command_dumpmap (object *op, char *params) |
|
|
469 | { |
|
|
470 | if (op) |
|
|
471 | dump_map (op->map); |
|
|
472 | return 0; |
|
|
473 | } |
|
|
474 | |
|
|
475 | int |
|
|
476 | command_dumpallmaps (object *op, char *params) |
|
|
477 | { |
|
|
478 | dump_all_maps (); |
|
|
479 | return 0; |
|
|
480 | } |
|
|
481 | |
|
|
482 | int |
|
|
483 | command_printlos (object *op, char *params) |
371 | command_printlos (object *op, char *params) |
484 | { |
372 | { |
485 | if (op) |
373 | if (op) |
486 | print_los (op); |
374 | print_los (op); |
487 | return 0; |
375 | return 0; |
… | |
… | |
492 | command_version (object *op, char *params) |
380 | command_version (object *op, char *params) |
493 | { |
381 | { |
494 | version (op); |
382 | version (op); |
495 | return 0; |
383 | return 0; |
496 | } |
384 | } |
497 | |
|
|
498 | |
385 | |
499 | #ifndef BUG_LOG |
386 | #ifndef BUG_LOG |
500 | # define BUG_LOG "bug_log" |
387 | # define BUG_LOG "bug_log" |
501 | #endif |
388 | #endif |
502 | void |
389 | void |
… | |
… | |
554 | 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); |
555 | } |
442 | } |
556 | else |
443 | else |
557 | 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."); |
558 | |
445 | |
559 | return 1; |
|
|
560 | } |
|
|
561 | |
|
|
562 | int |
|
|
563 | command_listen (object *op, char *params) |
|
|
564 | { |
|
|
565 | int i; |
|
|
566 | |
|
|
567 | if (params == NULL || !sscanf (params, "%d", &i)) |
|
|
568 | { |
|
|
569 | new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening); |
|
|
570 | return 1; |
|
|
571 | } |
|
|
572 | op->contr->listening = (char) i; |
|
|
573 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i); |
|
|
574 | return 1; |
446 | return 1; |
575 | } |
447 | } |
576 | |
448 | |
577 | /* Prints out some useful information for the character. Everything we print |
449 | /* Prints out some useful information for the character. Everything we print |
578 | * 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 - |
… | |
… | |
610 | |
482 | |
611 | int |
483 | int |
612 | command_fix_me (object *op, char *params) |
484 | command_fix_me (object *op, char *params) |
613 | { |
485 | { |
614 | sum_weight (op); |
486 | sum_weight (op); |
615 | fix_player (op); |
487 | op->update_stats (); |
616 | return 1; |
|
|
617 | } |
|
|
618 | |
|
|
619 | int |
|
|
620 | command_players (object *op, char *paramss) |
|
|
621 | { |
|
|
622 | char buf[MAX_BUF]; |
|
|
623 | char *t; |
|
|
624 | DIR *Dir; |
|
|
625 | |
|
|
626 | sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir); |
|
|
627 | t = buf + strlen (buf); |
|
|
628 | if ((Dir = opendir (buf)) != NULL) |
|
|
629 | { |
|
|
630 | const struct dirent *Entry; |
|
|
631 | |
|
|
632 | while ((Entry = readdir (Dir)) != NULL) |
|
|
633 | { |
|
|
634 | /* skip '.' , '..' */ |
|
|
635 | if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') || |
|
|
636 | (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0'))) |
|
|
637 | { |
|
|
638 | struct stat Stat; |
|
|
639 | |
|
|
640 | strcpy (t, Entry->d_name); |
|
|
641 | if (stat (buf, &Stat) == 0) |
|
|
642 | { |
|
|
643 | /* This was not posix compatible |
|
|
644 | * if ((Stat.st_mode & S_IFMT)==S_IFDIR) { |
|
|
645 | */ |
|
|
646 | if (S_ISDIR (Stat.st_mode)) |
|
|
647 | { |
|
|
648 | char buf2[MAX_BUF]; |
|
|
649 | struct tm *tm = localtime (&Stat.st_mtime); |
|
|
650 | |
|
|
651 | sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d", |
|
|
652 | Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); |
|
|
653 | new_draw_info (NDI_UNIQUE, 0, op, buf2); |
|
|
654 | } |
|
|
655 | } |
|
|
656 | } |
|
|
657 | } |
|
|
658 | } |
|
|
659 | closedir (Dir); |
|
|
660 | return 0; |
488 | return 1; |
661 | } |
489 | } |
662 | |
|
|
663 | |
|
|
664 | |
490 | |
665 | int |
491 | int |
666 | command_logs (object *op, char *params) |
492 | command_logs (object *op, char *params) |
667 | { |
493 | { |
668 | new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); |
494 | new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); |
… | |
… | |
691 | else |
517 | else |
692 | { |
518 | { |
693 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params); |
519 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params); |
694 | return 0; |
520 | return 0; |
695 | } |
521 | } |
|
|
522 | |
696 | new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s", |
523 | new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s", |
697 | (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]); |
524 | (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]); |
698 | return 1; |
525 | return 1; |
699 | } |
526 | } |
700 | |
527 | |
… | |
… | |
722 | found++; |
549 | found++; |
723 | op->contr->bowtype = (bowtype_t) i; |
550 | op->contr->bowtype = (bowtype_t) i; |
724 | break; |
551 | break; |
725 | } |
552 | } |
726 | } |
553 | } |
|
|
554 | |
727 | if (!found) |
555 | if (!found) |
728 | { |
556 | { |
729 | sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
557 | sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
730 | for (i = 0; i <= bow_bestarrow; i++) |
558 | for (i = 0; i <= bow_bestarrow; i++) |
731 | { |
559 | { |
… | |
… | |
737 | strcat (buf, "."); |
565 | strcat (buf, "."); |
738 | } |
566 | } |
739 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
567 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
740 | return 0; |
568 | return 0; |
741 | } |
569 | } |
|
|
570 | |
742 | new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
571 | new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
743 | return 1; |
572 | return 1; |
744 | } |
573 | } |
745 | |
574 | |
746 | int |
575 | int |
… | |
… | |
785 | for (obl = first_friendly_object; obl != NULL; obl = next) |
614 | for (obl = first_friendly_object; obl != NULL; obl = next) |
786 | { |
615 | { |
787 | object *ob = obl->ob; |
616 | object *ob = obl->ob; |
788 | |
617 | |
789 | next = obl->next; |
618 | next = obl->next; |
790 | if (get_owner (ob) == op) |
619 | if (ob->owner == op) |
791 | { |
620 | { |
792 | if (target == 0) |
621 | if (target == 0) |
793 | { |
622 | { |
794 | if (counter == 0) |
623 | if (counter == 0) |
795 | new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); |
624 | new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); |
… | |
… | |
902 | char filename[MAX_BUF], line[80]; |
731 | char filename[MAX_BUF], line[80]; |
903 | int namelen, linelen = 0; |
732 | int namelen, linelen = 0; |
904 | |
733 | |
905 | switch (what) |
734 | switch (what) |
906 | { |
735 | { |
907 | case 1: |
736 | case 1: |
908 | sprintf (filename, "%s/wizhelp", settings.datadir); |
737 | sprintf (filename, "%s/wizhelp", settings.datadir); |
909 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
738 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
910 | break; |
739 | break; |
911 | case 3: |
740 | case 3: |
912 | sprintf (filename, "%s/mischelp", settings.datadir); |
741 | sprintf (filename, "%s/mischelp", settings.datadir); |
913 | new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); |
742 | new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); |
914 | break; |
743 | break; |
915 | default: |
744 | default: |
916 | sprintf (filename, "%s/help", settings.datadir); |
745 | sprintf (filename, "%s/help", settings.datadir); |
917 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
746 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
918 | break; |
747 | break; |
919 | } |
748 | } |
|
|
749 | |
920 | if (!(dirp = opendir (filename))) |
750 | if (!(dirp = opendir (filename))) |
921 | return; |
751 | return; |
922 | |
752 | |
923 | line[0] = '\0'; |
753 | line[0] = '\0'; |
924 | for (de = readdir (dirp); de; de = readdir (dirp)) |
754 | while ((de = readdir (dirp))) |
925 | { |
755 | { |
926 | namelen = NAMLEN (de); |
756 | namelen = strlen (de->d_name); |
927 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
757 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
928 | continue; |
758 | continue; |
929 | linelen += namelen + 1; |
759 | linelen += namelen + 1; |
930 | if (linelen > 42) |
760 | if (linelen > 42) |
931 | { |
761 | { |
… | |
… | |
1136 | return 0; |
966 | return 0; |
1137 | } |
967 | } |
1138 | } |
968 | } |
1139 | |
969 | |
1140 | int |
970 | int |
1141 | command_quit (object *op, char *params) |
971 | command_sound (object *op, char *params) |
1142 | { |
972 | { |
1143 | new_draw_info (NDI_UNIQUE, 0, op, |
973 | if (op->contr->ns->sound) |
1144 | "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit."); |
|
|
1145 | return 1; |
|
|
1146 | } |
|
|
1147 | |
|
|
1148 | int |
|
|
1149 | command_real_quit (object *op, char *params) |
|
|
1150 | { |
|
|
1151 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):"); |
|
|
1152 | |
|
|
1153 | op->contr->state = ST_CONFIRM_QUIT; |
|
|
1154 | return 1; |
|
|
1155 | } |
|
|
1156 | |
|
|
1157 | /* |
|
|
1158 | * don't allow people to exit explore mode. It otherwise becomes |
|
|
1159 | * really easy to abuse this. |
|
|
1160 | */ |
|
|
1161 | int |
|
|
1162 | command_explore (object *op, char *params) |
|
|
1163 | { |
|
|
1164 | if (settings.explore_mode == FALSE) |
|
|
1165 | return 1; |
|
|
1166 | /* |
|
|
1167 | * I guess this is the best way to see if we are solo or not. Actually, |
|
|
1168 | * are there any cases when first_player->next==NULL and we are not solo? |
|
|
1169 | */ |
|
|
1170 | if ((first_player != op->contr) || (first_player->next != NULL)) |
|
|
1171 | { |
|
|
1172 | new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party"); |
|
|
1173 | } |
974 | { |
1174 | else if (op->contr->explore) |
975 | op->contr->ns->sound = 0; |
1175 | new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode"); |
976 | new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden..."); |
|
|
977 | } |
1176 | else |
978 | else |
1177 | { |
979 | { |
1178 | op->contr->explore = 1; |
|
|
1179 | new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode"); |
|
|
1180 | } |
|
|
1181 | return 1; |
|
|
1182 | } |
|
|
1183 | |
|
|
1184 | int |
|
|
1185 | command_sound (object *op, char *params) |
|
|
1186 | { |
|
|
1187 | if (op->contr->socket.sound) |
|
|
1188 | { |
|
|
1189 | op->contr->socket.sound = 0; |
|
|
1190 | new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden..."); |
|
|
1191 | } |
|
|
1192 | else |
|
|
1193 | { |
|
|
1194 | op->contr->socket.sound = 1; |
980 | op->contr->ns->sound = 1; |
1195 | new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled."); |
981 | new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled."); |
1196 | } |
982 | } |
1197 | return 1; |
|
|
1198 | } |
|
|
1199 | |
983 | |
1200 | /* Perhaps these should be in player.c, but that file is |
|
|
1201 | * already a bit big. |
|
|
1202 | */ |
|
|
1203 | |
|
|
1204 | void |
|
|
1205 | receive_player_name (object *op, char k) |
|
|
1206 | { |
|
|
1207 | |
|
|
1208 | if (!check_name (op->contr, op->contr->write_buf + 1)) |
|
|
1209 | { |
|
|
1210 | get_name (op); |
|
|
1211 | return; |
|
|
1212 | } |
|
|
1213 | op->name = op->contr->write_buf + 1; |
|
|
1214 | op->name_pl = op->contr->write_buf + 1; |
|
|
1215 | new_draw_info (NDI_UNIQUE, 0, op, op->contr->write_buf); |
|
|
1216 | op->contr->name_changed = 1; |
|
|
1217 | get_password (op); |
|
|
1218 | } |
|
|
1219 | |
|
|
1220 | void |
|
|
1221 | receive_player_password (object *op, char k) |
|
|
1222 | { |
|
|
1223 | |
|
|
1224 | unsigned int pwd_len = strlen (op->contr->write_buf); |
|
|
1225 | |
|
|
1226 | if (pwd_len <= 1 || pwd_len > 17) |
|
|
1227 | { |
|
|
1228 | get_name (op); |
|
|
1229 | return; |
|
|
1230 | } |
|
|
1231 | new_draw_info (NDI_UNIQUE, 0, op, " "); /* To hide the password better */ |
|
|
1232 | |
|
|
1233 | if (checkbanned (op->name, op->contr->socket.host)) |
|
|
1234 | { |
|
|
1235 | LOG (llevInfo, "Banned player tried to add: [%s@%s]\n", &op->name, op->contr->socket.host); |
|
|
1236 | new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, "You are not allowed to play."); |
|
|
1237 | get_name (op); |
|
|
1238 | return; |
|
|
1239 | } |
|
|
1240 | |
|
|
1241 | if (op->contr->state == ST_CONFIRM_PASSWORD) |
|
|
1242 | { |
|
|
1243 | if (!check_password (op->contr->write_buf + 1, op->contr->password)) |
|
|
1244 | { |
|
|
1245 | new_draw_info (NDI_UNIQUE, 0, op, "The passwords did not match."); |
|
|
1246 | get_name (op); |
|
|
1247 | return; |
|
|
1248 | } |
|
|
1249 | clear_win_info (op); |
|
|
1250 | display_motd (op); |
|
|
1251 | new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
1252 | new_draw_info (NDI_UNIQUE, 0, op, "Welcome, Brave New Warrior!"); |
|
|
1253 | new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
1254 | Roll_Again (op); |
|
|
1255 | op->contr->state = ST_ROLL_STAT; |
|
|
1256 | return; |
|
|
1257 | } |
|
|
1258 | strcpy (op->contr->password, crypt_string (op->contr->write_buf + 1, NULL)); |
|
|
1259 | op->contr->state = ST_ROLL_STAT; |
|
|
1260 | check_login (op); |
|
|
1261 | return; |
|
|
1262 | } |
|
|
1263 | |
|
|
1264 | |
|
|
1265 | int |
|
|
1266 | explore_mode (void) |
|
|
1267 | { |
|
|
1268 | player *pl; |
|
|
1269 | |
|
|
1270 | if (settings.explore_mode == TRUE) |
|
|
1271 | { |
|
|
1272 | for (pl = first_player; pl != (player *) NULL; pl = pl->next) |
|
|
1273 | if (pl->explore) |
|
|
1274 | return 1; |
|
|
1275 | } |
|
|
1276 | return 0; |
984 | return 1; |
1277 | } |
985 | } |
1278 | |
|
|
1279 | |
986 | |
1280 | int |
987 | int |
1281 | command_title (object *op, char *params) |
988 | command_title (object *op, char *params) |
1282 | { |
989 | { |
1283 | char buf[MAX_BUF]; |
990 | char buf[MAX_BUF]; |
… | |
… | |
1322 | strcpy (op->contr->own_title, params); |
1029 | strcpy (op->contr->own_title, params); |
1323 | return 1; |
1030 | return 1; |
1324 | } |
1031 | } |
1325 | |
1032 | |
1326 | int |
1033 | int |
1327 | command_save (object *op, char *params) |
|
|
1328 | { |
|
|
1329 | // if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_CLERIC) { |
|
|
1330 | // new_draw_info(NDI_UNIQUE, 0, op, "You can not save on unholy ground"); |
|
|
1331 | // } else |
|
|
1332 | if (!op->stats.exp) |
|
|
1333 | { |
|
|
1334 | new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet."); |
|
|
1335 | } |
|
|
1336 | else |
|
|
1337 | { |
|
|
1338 | if (save_player (op, 1)) |
|
|
1339 | new_draw_info (NDI_UNIQUE, 0, op, "You have been saved."); |
|
|
1340 | else |
|
|
1341 | new_draw_info (NDI_UNIQUE, 0, op, "SAVE FAILED!"); |
|
|
1342 | } |
|
|
1343 | return 1; |
|
|
1344 | } |
|
|
1345 | |
|
|
1346 | |
|
|
1347 | int |
|
|
1348 | command_peaceful (object *op, char *params) |
|
|
1349 | { |
|
|
1350 | new_draw_info (NDI_UNIQUE, 0, op, |
|
|
1351 | "You cannot change your peaceful setting with this command." |
|
|
1352 | " Please speak to the priest in the temple of Gorokh" |
|
|
1353 | " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again."); |
|
|
1354 | |
|
|
1355 | /* |
|
|
1356 | if((op->contr->peaceful=!op->contr->peaceful)) |
|
|
1357 | new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players."); |
|
|
1358 | else |
|
|
1359 | new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players."); |
|
|
1360 | */ |
|
|
1361 | return 1; |
|
|
1362 | } |
|
|
1363 | |
|
|
1364 | |
|
|
1365 | |
|
|
1366 | int |
|
|
1367 | command_wimpy (object *op, char *params) |
|
|
1368 | { |
|
|
1369 | int i; |
|
|
1370 | char buf[MAX_BUF]; |
|
|
1371 | |
|
|
1372 | if (params == NULL || !sscanf (params, "%d", &i)) |
|
|
1373 | { |
|
|
1374 | sprintf (buf, "Your current wimpy level is %d.", op->run_away); |
|
|
1375 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
1376 | return 1; |
|
|
1377 | } |
|
|
1378 | sprintf (buf, "Your new wimpy level is %d.", i); |
|
|
1379 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
1380 | op->run_away = i; |
|
|
1381 | return 1; |
|
|
1382 | } |
|
|
1383 | |
|
|
1384 | |
|
|
1385 | int |
|
|
1386 | command_brace (object *op, char *params) |
|
|
1387 | { |
|
|
1388 | if (!params) |
|
|
1389 | op->contr->braced = !op->contr->braced; |
|
|
1390 | else |
|
|
1391 | op->contr->braced = onoff_value (params); |
|
|
1392 | |
|
|
1393 | if (op->contr->braced) |
|
|
1394 | new_draw_info (NDI_UNIQUE, 0, op, "You are braced."); |
|
|
1395 | else |
|
|
1396 | new_draw_info (NDI_UNIQUE, 0, op, "Not braced."); |
|
|
1397 | |
|
|
1398 | fix_player (op); |
|
|
1399 | return 0; |
|
|
1400 | } |
|
|
1401 | |
|
|
1402 | int |
|
|
1403 | command_style_map_info (object *op, char *params) |
|
|
1404 | { |
|
|
1405 | extern maptile *styles; |
|
|
1406 | maptile *mp; |
|
|
1407 | int maps_used = 0, mapmem = 0, objects_used = 0, x, y; |
|
|
1408 | object *tmp; |
|
|
1409 | |
|
|
1410 | for (mp = styles; mp != NULL; mp = mp->next) |
|
|
1411 | { |
|
|
1412 | maps_used++; |
|
|
1413 | mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile); |
|
|
1414 | for (x = 0; x < MAP_WIDTH (mp); x++) |
|
|
1415 | { |
|
|
1416 | for (y = 0; y < MAP_HEIGHT (mp); y++) |
|
|
1417 | { |
|
|
1418 | for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above) |
|
|
1419 | objects_used++; |
|
|
1420 | } |
|
|
1421 | } |
|
|
1422 | } |
|
|
1423 | new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used); |
|
|
1424 | new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not"); |
|
|
1425 | new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem); |
|
|
1426 | new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used); |
|
|
1427 | new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object)); |
|
|
1428 | return 0; |
|
|
1429 | } |
|
|
1430 | |
|
|
1431 | int |
|
|
1432 | command_kill_pets (object *op, char *params) |
1034 | command_kill_pets (object *op, char *params) |
1433 | { |
1035 | { |
1434 | objectlink *obl, *next; |
1036 | objectlink *obl, *next; |
1435 | int counter = 0, removecount = 0; |
1037 | int counter = 0, removecount = 0; |
1436 | |
1038 | |
… | |
… | |
1446 | for (obl = first_friendly_object; obl != NULL; obl = next) |
1048 | for (obl = first_friendly_object; obl != NULL; obl = next) |
1447 | { |
1049 | { |
1448 | object *ob = obl->ob; |
1050 | object *ob = obl->ob; |
1449 | |
1051 | |
1450 | next = obl->next; |
1052 | next = obl->next; |
1451 | if (get_owner (ob) == op) |
1053 | if (ob->owner == op) |
1452 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
1054 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
1453 | { |
1055 | { |
1454 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
|
|
1455 | remove_ob (ob); |
|
|
1456 | remove_friendly_object (ob); |
|
|
1457 | free_object (ob); |
1056 | ob->destroy (); |
1458 | removecount++; |
1057 | removecount++; |
1459 | } |
1058 | } |
1460 | } |
1059 | } |
1461 | if (removecount != 0) |
1060 | if (removecount != 0) |
1462 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
1061 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |