ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
(Generate patch)

Comparing deliantra/server/server/c_misc.C (file contents):
Revision 1.51 by pippijn, Fri Mar 2 10:55:00 2007 UTC vs.
Revision 1.56 by root, Wed Apr 18 18:03:18 2007 UTC

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 */
37int
38command_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
67int 31int
68command_motd (object *op, char *params) 32command_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 */
79void
80current_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", &reg->longname, &reg->msg);
84}
85
86void
87current_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
106int 39int
107command_malloc_verify (object *op, char *parms) 40command_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;
159typedef struct 92typedef 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
165int
166command_mapinfo (object *op, char *params)
167{
168 current_map_info (op);
169 return 1;
170}
171
172int
173command_whereami (object *op, char *params)
174{
175 current_region_info (op);
176 return 1;
177}
178 97
179int 98int
180command_time (object *op, char *params) 99command_time (object *op, char *params)
181{ 100{
182 print_tod (op); 101 print_tod (op);
398 } 317 }
399 else 318 else
400 { 319 {
401 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno)); 320 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
402 } 321 }
403}
404
405int
406command_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
427int
428command_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} 322}
448 323
449/* Prints out some useful information for the character. Everything we print 324/* 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 - 325 * 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 326 * rather, we are making it convenient to find the values. params have
636/* 511/*
637 * Actual commands. 512 * Actual commands.
638 * 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,...)
639 */ 514 */
640 515
641
642static void
643help_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
690static void
691show_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
737int
738command_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 */
849nohelp:
850 sprintf (line, "No help available on '%s'", params);
851 new_draw_info (NDI_UNIQUE, 0, op, line);
852 return 0;
853}
854
855
856int 516int
857onoff_value (const char *line) 517onoff_value (const char *line)
858{ 518{
859 int i; 519 int i;
860 520
947 for (obl = first_friendly_object; obl != NULL; obl = next) 607 for (obl = first_friendly_object; obl != NULL; obl = next)
948 { 608 {
949 object *ob = obl->ob; 609 object *ob = obl->ob;
950 610
951 next = obl->next; 611 next = obl->next;
612
952 if (ob->owner == op) 613 if (ob->owner == op)
953 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 614 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
954 { 615 {
955 ob->destroy (); 616 ob->destroy ();
956 removecount++; 617 removecount++;
957 } 618 }
958 } 619 }
620
959 if (removecount != 0) 621 if (removecount != 0)
960 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);
961 else 623 else
962 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");
963 } 625 }
626
964 return 0; 627 return 0;
965} 628}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines