… | |
… | |
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); |
… | |
… | |
592 | /* |
511 | /* |
593 | * Actual commands. |
512 | * Actual commands. |
594 | * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) |
513 | * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) |
595 | */ |
514 | */ |
596 | |
515 | |
597 | |
|
|
598 | static void |
|
|
599 | help_topics (object *op, int what) |
|
|
600 | { |
|
|
601 | DIR *dirp; |
|
|
602 | struct dirent *de; |
|
|
603 | char filename[MAX_BUF], line[80]; |
|
|
604 | int namelen, linelen = 0; |
|
|
605 | |
|
|
606 | switch (what) |
|
|
607 | { |
|
|
608 | case 1: |
|
|
609 | sprintf (filename, "%s/wizhelp", settings.datadir); |
|
|
610 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
|
|
611 | break; |
|
|
612 | case 3: |
|
|
613 | sprintf (filename, "%s/mischelp", settings.datadir); |
|
|
614 | new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); |
|
|
615 | break; |
|
|
616 | default: |
|
|
617 | sprintf (filename, "%s/help", settings.datadir); |
|
|
618 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
|
|
619 | break; |
|
|
620 | } |
|
|
621 | |
|
|
622 | if (!(dirp = opendir (filename))) |
|
|
623 | return; |
|
|
624 | |
|
|
625 | line[0] = '\0'; |
|
|
626 | while ((de = readdir (dirp))) |
|
|
627 | { |
|
|
628 | namelen = strlen (de->d_name); |
|
|
629 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
|
|
630 | continue; |
|
|
631 | linelen += namelen + 1; |
|
|
632 | if (linelen > 42) |
|
|
633 | { |
|
|
634 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
635 | sprintf (line, " %s", de->d_name); |
|
|
636 | linelen = namelen + 1; |
|
|
637 | continue; |
|
|
638 | } |
|
|
639 | strcat (line, " "); |
|
|
640 | strcat (line, de->d_name); |
|
|
641 | } |
|
|
642 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
643 | closedir (dirp); |
|
|
644 | } |
|
|
645 | |
|
|
646 | static void |
|
|
647 | show_commands (object *op, int what) |
|
|
648 | { |
|
|
649 | char line[80]; |
|
|
650 | int i, size, namelen, linelen = 0; |
|
|
651 | CommArray_s *ap; |
|
|
652 | extern CommArray_s Commands[], WizCommands[]; |
|
|
653 | extern const int CommandsSize, WizCommandsSize; |
|
|
654 | |
|
|
655 | switch (what) |
|
|
656 | { |
|
|
657 | case 1: |
|
|
658 | ap = WizCommands; |
|
|
659 | size = WizCommandsSize; |
|
|
660 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
|
|
661 | break; |
|
|
662 | case 2: |
|
|
663 | ap = CommunicationCommands; |
|
|
664 | size = CommunicationCommandSize; |
|
|
665 | new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:"); |
|
|
666 | break; |
|
|
667 | default: |
|
|
668 | ap = Commands; |
|
|
669 | size = CommandsSize; |
|
|
670 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
|
|
671 | break; |
|
|
672 | } |
|
|
673 | |
|
|
674 | line[0] = '\0'; |
|
|
675 | for (i = 0; i < size; i++) |
|
|
676 | { |
|
|
677 | namelen = strlen (ap[i].name); |
|
|
678 | linelen += namelen + 1; |
|
|
679 | if (linelen > 42) |
|
|
680 | { |
|
|
681 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
682 | sprintf (line, " %s", ap[i].name); |
|
|
683 | linelen = namelen + 1; |
|
|
684 | continue; |
|
|
685 | } |
|
|
686 | strcat (line, " "); |
|
|
687 | strcat (line, ap[i].name); |
|
|
688 | } |
|
|
689 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
690 | } |
|
|
691 | |
|
|
692 | |
|
|
693 | int |
|
|
694 | command_help (object *op, char *params) |
|
|
695 | { |
|
|
696 | struct stat st; |
|
|
697 | FILE *fp; |
|
|
698 | char filename[MAX_BUF], line[MAX_BUF]; |
|
|
699 | int len; |
|
|
700 | |
|
|
701 | if (op != NULL) |
|
|
702 | clear_win_info (op); |
|
|
703 | |
|
|
704 | /* |
|
|
705 | * Main help page? |
|
|
706 | */ |
|
|
707 | if (!params) |
|
|
708 | { |
|
|
709 | sprintf (filename, "%s/def_help", settings.datadir); |
|
|
710 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
711 | { |
|
|
712 | LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno)); |
|
|
713 | return 0; |
|
|
714 | } |
|
|
715 | while (fgets (line, MAX_BUF, fp)) |
|
|
716 | { |
|
|
717 | line[MAX_BUF - 1] = '\0'; |
|
|
718 | len = strlen (line) - 1; |
|
|
719 | if (line[len] == '\n') |
|
|
720 | line[len] = '\0'; |
|
|
721 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
722 | } |
|
|
723 | fclose (fp); |
|
|
724 | return 0; |
|
|
725 | } |
|
|
726 | |
|
|
727 | /* |
|
|
728 | * Topics list |
|
|
729 | */ |
|
|
730 | if (!strcmp (params, "topics")) |
|
|
731 | { |
|
|
732 | help_topics (op, 3); |
|
|
733 | help_topics (op, 0); |
|
|
734 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
735 | help_topics (op, 1); |
|
|
736 | return 0; |
|
|
737 | } |
|
|
738 | |
|
|
739 | /* |
|
|
740 | * Commands list |
|
|
741 | */ |
|
|
742 | if (!strcmp (params, "commands")) |
|
|
743 | { |
|
|
744 | show_commands (op, 0); |
|
|
745 | show_commands (op, 2); /* show comm commands */ |
|
|
746 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
747 | show_commands (op, 1); |
|
|
748 | return 0; |
|
|
749 | } |
|
|
750 | |
|
|
751 | /* |
|
|
752 | * User wants info about command |
|
|
753 | */ |
|
|
754 | if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/')) |
|
|
755 | { |
|
|
756 | sprintf (line, "Illegal characters in '%s'", params); |
|
|
757 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
758 | return 0; |
|
|
759 | } |
|
|
760 | |
|
|
761 | sprintf (filename, "%s/mischelp/%s", settings.datadir, params); |
|
|
762 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
763 | { |
|
|
764 | if (op) |
|
|
765 | { |
|
|
766 | sprintf (filename, "%s/help/%s", settings.datadir, params); |
|
|
767 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
768 | { |
|
|
769 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
770 | { |
|
|
771 | sprintf (filename, "%s/wizhelp/%s", settings.datadir, params); |
|
|
772 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
773 | goto nohelp; |
|
|
774 | } |
|
|
775 | else |
|
|
776 | goto nohelp; |
|
|
777 | } |
|
|
778 | } |
|
|
779 | } |
|
|
780 | |
|
|
781 | /* |
|
|
782 | * Found that. Just cat it to screen. |
|
|
783 | */ |
|
|
784 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
785 | { |
|
|
786 | LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno)); |
|
|
787 | return 0; |
|
|
788 | } |
|
|
789 | sprintf (line, "Help about '%s'", params); |
|
|
790 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
791 | while (fgets (line, MAX_BUF, fp)) |
|
|
792 | { |
|
|
793 | line[MAX_BUF - 1] = '\0'; |
|
|
794 | len = strlen (line) - 1; |
|
|
795 | if (line[len] == '\n') |
|
|
796 | line[len] = '\0'; |
|
|
797 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
798 | } |
|
|
799 | fclose (fp); |
|
|
800 | return 0; |
|
|
801 | |
|
|
802 | /* |
|
|
803 | * No_help -escape |
|
|
804 | */ |
|
|
805 | nohelp: |
|
|
806 | sprintf (line, "No help available on '%s'", params); |
|
|
807 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
808 | return 0; |
|
|
809 | } |
|
|
810 | |
|
|
811 | |
|
|
812 | int |
516 | int |
813 | onoff_value (const char *line) |
517 | onoff_value (const char *line) |
814 | { |
518 | { |
815 | int i; |
519 | int i; |
816 | |
520 | |
… | |
… | |
903 | for (obl = first_friendly_object; obl != NULL; obl = next) |
607 | for (obl = first_friendly_object; obl != NULL; obl = next) |
904 | { |
608 | { |
905 | object *ob = obl->ob; |
609 | object *ob = obl->ob; |
906 | |
610 | |
907 | next = obl->next; |
611 | next = obl->next; |
|
|
612 | |
908 | if (ob->owner == op) |
613 | if (ob->owner == op) |
909 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
614 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
910 | { |
615 | { |
911 | ob->destroy (); |
616 | ob->destroy (); |
912 | removecount++; |
617 | removecount++; |
913 | } |
618 | } |
914 | } |
619 | } |
|
|
620 | |
915 | if (removecount != 0) |
621 | if (removecount != 0) |
916 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
622 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
917 | else |
623 | else |
918 | new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
624 | new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
919 | } |
625 | } |
|
|
626 | |
920 | return 0; |
627 | return 0; |
921 | } |
628 | } |