1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
9 | * it under the terms of the GNU General Public License as published by |
9 | * under the terms of the GNU General Public License as published by the Free |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
11 | * (at your option) any later version. |
11 | * any later version. |
12 | * |
12 | * |
13 | * 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, but |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
16 | * GNU General Public License for more details. |
16 | * for more details. |
17 | * |
17 | * |
18 | * 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 along |
19 | * along with this program; if not, write to the Free Software |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <loader.h> |
26 | #include <loader.h> |
27 | #include <sproto.h> |
27 | #include <sproto.h> |
28 | |
28 | |
29 | /* Handles misc. input request - things like hash table, malloc, maps, |
29 | /* Handles misc. input request - things like hash table, malloc, maps, etc */ |
30 | * who, etc. |
|
|
31 | */ |
|
|
32 | |
|
|
33 | /* This command dumps the body information for object *op. |
|
|
34 | * it doesn't care what the params are. |
|
|
35 | * This is mostly meant as a debug command. |
|
|
36 | */ |
|
|
37 | int |
|
|
38 | command_body (object *op, char *params) |
|
|
39 | { |
|
|
40 | int i; |
|
|
41 | |
|
|
42 | /* Too hard to try and make a header that lines everything up, so just |
|
|
43 | * give a description. |
|
|
44 | */ |
|
|
45 | new_draw_info (NDI_UNIQUE, 0, op, "The first column is the name of the body location."); |
|
|
46 | new_draw_info (NDI_UNIQUE, 0, op, "The second column is how many of those locations your body has."); |
|
|
47 | new_draw_info (NDI_UNIQUE, 0, op, "The third column is how many slots in that location are available."); |
|
|
48 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
|
|
49 | { |
|
|
50 | /* really debugging - normally body_used should not be set to anything |
|
|
51 | * if body_info isn't also set. |
|
|
52 | */ |
|
|
53 | if (op->body_info[i] || op->body_used[i]) |
|
|
54 | { |
|
|
55 | new_draw_info_format (NDI_UNIQUE, 0, op, "%-30s %5d %5d", body_locations[i].use_name, op->body_info[i], op->body_used[i]); |
|
|
56 | } |
|
|
57 | } |
|
|
58 | if (!QUERY_FLAG (op, FLAG_USE_ARMOUR)) |
|
|
59 | new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to wear armor"); |
|
|
60 | if (!QUERY_FLAG (op, FLAG_USE_WEAPON)) |
|
|
61 | new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to use weapons"); |
|
|
62 | |
|
|
63 | return 1; |
|
|
64 | } |
|
|
65 | |
|
|
66 | |
30 | |
67 | int |
31 | int |
68 | command_motd (object *op, char *params) |
32 | command_motd (object *op, char *params) |
69 | { |
33 | { |
70 | display_motd (op); |
34 | display_motd (op); |
71 | return 1; |
35 | return 1; |
72 | } |
36 | } |
73 | |
37 | |
74 | /* |
|
|
75 | * Pretty much identical to current map_info, but on a bigger scale |
|
|
76 | * This function returns the name of the players current region, and |
|
|
77 | * a description of it. It is there merely for flavour text. |
|
|
78 | */ |
|
|
79 | void |
|
|
80 | current_region_info (object *op) |
|
|
81 | { |
|
|
82 | if (region *reg = op->region ()) |
|
|
83 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are %s.\n%s", ®->longname, ®->msg); |
|
|
84 | } |
|
|
85 | |
|
|
86 | void |
|
|
87 | current_map_info (object *op) |
|
|
88 | { |
|
|
89 | maptile *m = op->map; |
|
|
90 | |
|
|
91 | if (!m) |
|
|
92 | return; |
|
|
93 | |
|
|
94 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) %s", &m->name, &m->path, &op->region ()->longname); |
|
|
95 | |
|
|
96 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
97 | new_draw_info_format (NDI_UNIQUE, 0, op, |
|
|
98 | "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld", |
|
|
99 | m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout); |
|
|
100 | |
|
|
101 | if (m->msg) |
|
|
102 | new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); |
|
|
103 | } |
|
|
104 | |
|
|
105 | #ifdef DEBUG_MALLOC_LEVEL |
38 | #ifdef DEBUG_MALLOC_LEVEL |
106 | int |
39 | int |
107 | command_malloc_verify (object *op, char *parms) |
40 | command_malloc_verify (object *op, char *parms) |
108 | { |
41 | { |
109 | extern int malloc_verify (void); |
42 | extern int malloc_verify (void); |
110 | |
43 | |
111 | if (!malloc_verify ()) |
44 | if (!malloc_verify ()) |
112 | new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted."); |
45 | new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted."); |
113 | else |
46 | else |
114 | new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK."); |
47 | new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK."); |
115 | return 1; |
48 | return 1; |
… | |
… | |
159 | typedef struct |
92 | typedef struct |
160 | { |
93 | { |
161 | char namebuf[MAX_BUF]; |
94 | char namebuf[MAX_BUF]; |
162 | int login_order; |
95 | int login_order; |
163 | } chars_names; |
96 | } chars_names; |
164 | |
|
|
165 | int |
|
|
166 | command_mapinfo (object *op, char *params) |
|
|
167 | { |
|
|
168 | current_map_info (op); |
|
|
169 | return 1; |
|
|
170 | } |
|
|
171 | |
|
|
172 | int |
|
|
173 | command_whereami (object *op, char *params) |
|
|
174 | { |
|
|
175 | current_region_info (op); |
|
|
176 | return 1; |
|
|
177 | } |
|
|
178 | |
97 | |
179 | int |
98 | int |
180 | command_time (object *op, char *params) |
99 | command_time (object *op, char *params) |
181 | { |
100 | { |
182 | print_tod (op); |
101 | print_tod (op); |
… | |
… | |
333 | { |
252 | { |
334 | sprintf (buf, "Global debug level is %d.", settings.debug); |
253 | sprintf (buf, "Global debug level is %d.", settings.debug); |
335 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
254 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
336 | return 1; |
255 | return 1; |
337 | } |
256 | } |
338 | settings.debug = (enum LogLevel) FABS (i); |
257 | |
|
|
258 | settings.debug = i; |
|
|
259 | |
339 | sprintf (buf, "Set debug level to %d.", i); |
260 | sprintf (buf, "Set debug level to %d.", i); |
340 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
261 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
341 | return 1; |
262 | return 1; |
342 | } |
263 | } |
343 | |
264 | |
… | |
… | |
398 | } |
319 | } |
399 | else |
320 | else |
400 | { |
321 | { |
401 | LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno)); |
322 | LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno)); |
402 | } |
323 | } |
403 | } |
|
|
404 | |
|
|
405 | int |
|
|
406 | command_output_sync (object *op, char *params) |
|
|
407 | { |
|
|
408 | int val; |
|
|
409 | |
|
|
410 | if (!params) |
|
|
411 | { |
|
|
412 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync); |
|
|
413 | return 1; |
|
|
414 | } |
|
|
415 | val = atoi (params); |
|
|
416 | if (val > 0) |
|
|
417 | { |
|
|
418 | op->contr->outputs_sync = val; |
|
|
419 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync); |
|
|
420 | } |
|
|
421 | else |
|
|
422 | new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync."); |
|
|
423 | |
|
|
424 | return 1; |
|
|
425 | } |
|
|
426 | |
|
|
427 | int |
|
|
428 | command_output_count (object *op, char *params) |
|
|
429 | { |
|
|
430 | int val; |
|
|
431 | |
|
|
432 | if (!params) |
|
|
433 | { |
|
|
434 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count); |
|
|
435 | return 1; |
|
|
436 | } |
|
|
437 | val = atoi (params); |
|
|
438 | if (val > 0) |
|
|
439 | { |
|
|
440 | op->contr->outputs_count = val; |
|
|
441 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count); |
|
|
442 | } |
|
|
443 | else |
|
|
444 | new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count."); |
|
|
445 | |
|
|
446 | return 1; |
|
|
447 | } |
324 | } |
448 | |
325 | |
449 | /* Prints out some useful information for the character. Everything we print |
326 | /* Prints out some useful information for the character. Everything we print |
450 | * out can be determined by the docs, so we aren't revealing anything extra - |
327 | * out can be determined by the docs, so we aren't revealing anything extra - |
451 | * rather, we are making it convenient to find the values. params have |
328 | * rather, we are making it convenient to find the values. params have |
… | |
… | |
636 | /* |
513 | /* |
637 | * Actual commands. |
514 | * Actual commands. |
638 | * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) |
515 | * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) |
639 | */ |
516 | */ |
640 | |
517 | |
641 | |
|
|
642 | static void |
|
|
643 | help_topics (object *op, int what) |
|
|
644 | { |
|
|
645 | DIR *dirp; |
|
|
646 | struct dirent *de; |
|
|
647 | char filename[MAX_BUF], line[80]; |
|
|
648 | int namelen, linelen = 0; |
|
|
649 | |
|
|
650 | switch (what) |
|
|
651 | { |
|
|
652 | case 1: |
|
|
653 | sprintf (filename, "%s/wizhelp", settings.datadir); |
|
|
654 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
|
|
655 | break; |
|
|
656 | case 3: |
|
|
657 | sprintf (filename, "%s/mischelp", settings.datadir); |
|
|
658 | new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); |
|
|
659 | break; |
|
|
660 | default: |
|
|
661 | sprintf (filename, "%s/help", settings.datadir); |
|
|
662 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
|
|
663 | break; |
|
|
664 | } |
|
|
665 | |
|
|
666 | if (!(dirp = opendir (filename))) |
|
|
667 | return; |
|
|
668 | |
|
|
669 | line[0] = '\0'; |
|
|
670 | while ((de = readdir (dirp))) |
|
|
671 | { |
|
|
672 | namelen = strlen (de->d_name); |
|
|
673 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
|
|
674 | continue; |
|
|
675 | linelen += namelen + 1; |
|
|
676 | if (linelen > 42) |
|
|
677 | { |
|
|
678 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
679 | sprintf (line, " %s", de->d_name); |
|
|
680 | linelen = namelen + 1; |
|
|
681 | continue; |
|
|
682 | } |
|
|
683 | strcat (line, " "); |
|
|
684 | strcat (line, de->d_name); |
|
|
685 | } |
|
|
686 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
687 | closedir (dirp); |
|
|
688 | } |
|
|
689 | |
|
|
690 | static void |
|
|
691 | show_commands (object *op, int what) |
|
|
692 | { |
|
|
693 | char line[80]; |
|
|
694 | int i, size, namelen, linelen = 0; |
|
|
695 | CommArray_s *ap; |
|
|
696 | extern CommArray_s Commands[], WizCommands[]; |
|
|
697 | extern const int CommandsSize, WizCommandsSize; |
|
|
698 | |
|
|
699 | switch (what) |
|
|
700 | { |
|
|
701 | case 1: |
|
|
702 | ap = WizCommands; |
|
|
703 | size = WizCommandsSize; |
|
|
704 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
|
|
705 | break; |
|
|
706 | case 2: |
|
|
707 | ap = CommunicationCommands; |
|
|
708 | size = CommunicationCommandSize; |
|
|
709 | new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:"); |
|
|
710 | break; |
|
|
711 | default: |
|
|
712 | ap = Commands; |
|
|
713 | size = CommandsSize; |
|
|
714 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
|
|
715 | break; |
|
|
716 | } |
|
|
717 | |
|
|
718 | line[0] = '\0'; |
|
|
719 | for (i = 0; i < size; i++) |
|
|
720 | { |
|
|
721 | namelen = strlen (ap[i].name); |
|
|
722 | linelen += namelen + 1; |
|
|
723 | if (linelen > 42) |
|
|
724 | { |
|
|
725 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
726 | sprintf (line, " %s", ap[i].name); |
|
|
727 | linelen = namelen + 1; |
|
|
728 | continue; |
|
|
729 | } |
|
|
730 | strcat (line, " "); |
|
|
731 | strcat (line, ap[i].name); |
|
|
732 | } |
|
|
733 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
734 | } |
|
|
735 | |
|
|
736 | |
|
|
737 | int |
|
|
738 | command_help (object *op, char *params) |
|
|
739 | { |
|
|
740 | struct stat st; |
|
|
741 | FILE *fp; |
|
|
742 | char filename[MAX_BUF], line[MAX_BUF]; |
|
|
743 | int len; |
|
|
744 | |
|
|
745 | if (op != NULL) |
|
|
746 | clear_win_info (op); |
|
|
747 | |
|
|
748 | /* |
|
|
749 | * Main help page? |
|
|
750 | */ |
|
|
751 | if (!params) |
|
|
752 | { |
|
|
753 | sprintf (filename, "%s/def_help", settings.datadir); |
|
|
754 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
755 | { |
|
|
756 | LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno)); |
|
|
757 | return 0; |
|
|
758 | } |
|
|
759 | while (fgets (line, MAX_BUF, fp)) |
|
|
760 | { |
|
|
761 | line[MAX_BUF - 1] = '\0'; |
|
|
762 | len = strlen (line) - 1; |
|
|
763 | if (line[len] == '\n') |
|
|
764 | line[len] = '\0'; |
|
|
765 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
766 | } |
|
|
767 | fclose (fp); |
|
|
768 | return 0; |
|
|
769 | } |
|
|
770 | |
|
|
771 | /* |
|
|
772 | * Topics list |
|
|
773 | */ |
|
|
774 | if (!strcmp (params, "topics")) |
|
|
775 | { |
|
|
776 | help_topics (op, 3); |
|
|
777 | help_topics (op, 0); |
|
|
778 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
779 | help_topics (op, 1); |
|
|
780 | return 0; |
|
|
781 | } |
|
|
782 | |
|
|
783 | /* |
|
|
784 | * Commands list |
|
|
785 | */ |
|
|
786 | if (!strcmp (params, "commands")) |
|
|
787 | { |
|
|
788 | show_commands (op, 0); |
|
|
789 | show_commands (op, 2); /* show comm commands */ |
|
|
790 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
791 | show_commands (op, 1); |
|
|
792 | return 0; |
|
|
793 | } |
|
|
794 | |
|
|
795 | /* |
|
|
796 | * User wants info about command |
|
|
797 | */ |
|
|
798 | if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/')) |
|
|
799 | { |
|
|
800 | sprintf (line, "Illegal characters in '%s'", params); |
|
|
801 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
802 | return 0; |
|
|
803 | } |
|
|
804 | |
|
|
805 | sprintf (filename, "%s/mischelp/%s", settings.datadir, params); |
|
|
806 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
807 | { |
|
|
808 | if (op) |
|
|
809 | { |
|
|
810 | sprintf (filename, "%s/help/%s", settings.datadir, params); |
|
|
811 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
812 | { |
|
|
813 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
814 | { |
|
|
815 | sprintf (filename, "%s/wizhelp/%s", settings.datadir, params); |
|
|
816 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
817 | goto nohelp; |
|
|
818 | } |
|
|
819 | else |
|
|
820 | goto nohelp; |
|
|
821 | } |
|
|
822 | } |
|
|
823 | } |
|
|
824 | |
|
|
825 | /* |
|
|
826 | * Found that. Just cat it to screen. |
|
|
827 | */ |
|
|
828 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
829 | { |
|
|
830 | LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno)); |
|
|
831 | return 0; |
|
|
832 | } |
|
|
833 | sprintf (line, "Help about '%s'", params); |
|
|
834 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
835 | while (fgets (line, MAX_BUF, fp)) |
|
|
836 | { |
|
|
837 | line[MAX_BUF - 1] = '\0'; |
|
|
838 | len = strlen (line) - 1; |
|
|
839 | if (line[len] == '\n') |
|
|
840 | line[len] = '\0'; |
|
|
841 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
842 | } |
|
|
843 | fclose (fp); |
|
|
844 | return 0; |
|
|
845 | |
|
|
846 | /* |
|
|
847 | * No_help -escape |
|
|
848 | */ |
|
|
849 | nohelp: |
|
|
850 | sprintf (line, "No help available on '%s'", params); |
|
|
851 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
852 | return 0; |
|
|
853 | } |
|
|
854 | |
|
|
855 | |
|
|
856 | int |
518 | int |
857 | onoff_value (const char *line) |
519 | onoff_value (const char *line) |
858 | { |
520 | { |
859 | int i; |
521 | int i; |
860 | |
522 | |
… | |
… | |
933 | command_kill_pets (object *op, char *params) |
595 | command_kill_pets (object *op, char *params) |
934 | { |
596 | { |
935 | objectlink *obl, *next; |
597 | objectlink *obl, *next; |
936 | int counter = 0, removecount = 0; |
598 | int counter = 0, removecount = 0; |
937 | |
599 | |
938 | if (params == NULL) |
600 | if (!params) |
939 | { |
601 | { |
940 | terminate_all_pets (op); |
602 | terminate_all_pets (op); |
941 | new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); |
603 | new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); |
942 | } |
604 | } |
943 | else |
605 | else |
944 | { |
606 | { |
945 | int target = atoi (params); |
607 | int target = atoi (params); |
946 | |
608 | |
947 | for (obl = first_friendly_object; obl != NULL; obl = next) |
609 | for (obl = first_friendly_object; obl; obl = next) |
948 | { |
610 | { |
949 | object *ob = obl->ob; |
611 | object *ob = obl->ob; |
950 | |
612 | |
951 | next = obl->next; |
613 | next = obl->next; |
|
|
614 | |
952 | if (ob->owner == op) |
615 | if (ob->owner == op) |
953 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
616 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
954 | { |
617 | { |
955 | ob->destroy (); |
618 | ob->destroy (); |
956 | removecount++; |
619 | removecount++; |
957 | } |
620 | } |
958 | } |
621 | } |
|
|
622 | |
959 | if (removecount != 0) |
623 | if (removecount != 0) |
960 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
624 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
961 | else |
625 | else |
962 | new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
626 | new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
963 | } |
627 | } |
|
|
628 | |
964 | return 0; |
629 | return 0; |
965 | } |
630 | } |