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.50 by pippijn, Fri Mar 2 10:43:01 2007 UTC vs.
Revision 1.57 by root, Wed Apr 25 19:19:54 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
483int 358int
484command_fix_me (object *op, char *params) 359command_fix_me (object *op, char *params)
485{ 360{
486 sum_weight (op); 361 sum_weight (op);
487 op->update_stats (); 362 op->update_stats ();
363 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
364
488 return 1; 365 return 1;
489} 366}
490 367
491int 368int
492command_logs (object *op, char *params) 369command_logs (object *op, char *params)
493{ 370{
494 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); 371 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
495 372
496 return 1;
497}
498
499int
500command_applymode (object *op, char *params)
501{
502 unapplymode unapply = op->contr->unapply;
503 static const char *const types[] = { "nochoice", "never", "always" };
504
505 if (!params)
506 {
507 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]);
508 return 1;
509 }
510
511 if (!strcmp (params, "nochoice"))
512 op->contr->unapply = unapply_nochoice;
513 else if (!strcmp (params, "never"))
514 op->contr->unapply = unapply_never;
515 else if (!strcmp (params, "always"))
516 op->contr->unapply = unapply_always;
517 else
518 {
519 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
520 return 0;
521 }
522
523 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
524 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
525 return 1; 373 return 1;
526} 374}
527 375
528int 376int
529command_bowmode (object *op, char *params) 377command_bowmode (object *op, char *params)
567 new_draw_info_format (NDI_UNIQUE, 0, op, buf); 415 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
568 return 0; 416 return 0;
569 } 417 }
570 418
571 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); 419 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]);
572 return 1;
573}
574
575int
576command_petmode (object *op, char *params)
577{
578 petmode_t oldtype = op->contr->petmode;
579 static const char *const types[] = { "normal", "sad", "defend", "arena" };
580
581 if (!params)
582 {
583 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]);
584 return 1;
585 }
586
587 if (!strcmp (params, "normal"))
588 op->contr->petmode = pet_normal;
589 else if (!strcmp (params, "sad"))
590 op->contr->petmode = pet_sad;
591 else if (!strcmp (params, "defend"))
592 op->contr->petmode = pet_defend;
593 else if (!strcmp (params, "arena"))
594 op->contr->petmode = pet_arena;
595 else
596 {
597 new_draw_info_format (NDI_UNIQUE, 0, op,
598 "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params);
599 return 0;
600 }
601 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]);
602 return 1; 420 return 1;
603} 421}
604 422
605int 423int
606command_showpets (object *op, char *params) 424command_showpets (object *op, char *params)
693/* 511/*
694 * Actual commands. 512 * Actual commands.
695 * 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,...)
696 */ 514 */
697 515
698
699static void
700help_topics (object *op, int what)
701{
702 DIR *dirp;
703 struct dirent *de;
704 char filename[MAX_BUF], line[80];
705 int namelen, linelen = 0;
706
707 switch (what)
708 {
709 case 1:
710 sprintf (filename, "%s/wizhelp", settings.datadir);
711 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
712 break;
713 case 3:
714 sprintf (filename, "%s/mischelp", settings.datadir);
715 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
716 break;
717 default:
718 sprintf (filename, "%s/help", settings.datadir);
719 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
720 break;
721 }
722
723 if (!(dirp = opendir (filename)))
724 return;
725
726 line[0] = '\0';
727 while ((de = readdir (dirp)))
728 {
729 namelen = strlen (de->d_name);
730 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
731 continue;
732 linelen += namelen + 1;
733 if (linelen > 42)
734 {
735 new_draw_info (NDI_UNIQUE, 0, op, line);
736 sprintf (line, " %s", de->d_name);
737 linelen = namelen + 1;
738 continue;
739 }
740 strcat (line, " ");
741 strcat (line, de->d_name);
742 }
743 new_draw_info (NDI_UNIQUE, 0, op, line);
744 closedir (dirp);
745}
746
747static void
748show_commands (object *op, int what)
749{
750 char line[80];
751 int i, size, namelen, linelen = 0;
752 CommArray_s *ap;
753 extern CommArray_s Commands[], WizCommands[];
754 extern const int CommandsSize, WizCommandsSize;
755
756 switch (what)
757 {
758 case 1:
759 ap = WizCommands;
760 size = WizCommandsSize;
761 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
762 break;
763 case 2:
764 ap = CommunicationCommands;
765 size = CommunicationCommandSize;
766 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
767 break;
768 default:
769 ap = Commands;
770 size = CommandsSize;
771 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
772 break;
773 }
774
775 line[0] = '\0';
776 for (i = 0; i < size; i++)
777 {
778 namelen = strlen (ap[i].name);
779 linelen += namelen + 1;
780 if (linelen > 42)
781 {
782 new_draw_info (NDI_UNIQUE, 0, op, line);
783 sprintf (line, " %s", ap[i].name);
784 linelen = namelen + 1;
785 continue;
786 }
787 strcat (line, " ");
788 strcat (line, ap[i].name);
789 }
790 new_draw_info (NDI_UNIQUE, 0, op, line);
791}
792
793
794int
795command_help (object *op, char *params)
796{
797 struct stat st;
798 FILE *fp;
799 char filename[MAX_BUF], line[MAX_BUF];
800 int len;
801
802 if (op != NULL)
803 clear_win_info (op);
804
805/*
806 * Main help page?
807 */
808 if (!params)
809 {
810 sprintf (filename, "%s/def_help", settings.datadir);
811 if ((fp = fopen (filename, "r")) == NULL)
812 {
813 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
814 return 0;
815 }
816 while (fgets (line, MAX_BUF, fp))
817 {
818 line[MAX_BUF - 1] = '\0';
819 len = strlen (line) - 1;
820 if (line[len] == '\n')
821 line[len] = '\0';
822 new_draw_info (NDI_UNIQUE, 0, op, line);
823 }
824 fclose (fp);
825 return 0;
826 }
827
828 /*
829 * Topics list
830 */
831 if (!strcmp (params, "topics"))
832 {
833 help_topics (op, 3);
834 help_topics (op, 0);
835 if (QUERY_FLAG (op, FLAG_WIZ))
836 help_topics (op, 1);
837 return 0;
838 }
839
840 /*
841 * Commands list
842 */
843 if (!strcmp (params, "commands"))
844 {
845 show_commands (op, 0);
846 show_commands (op, 2); /* show comm commands */
847 if (QUERY_FLAG (op, FLAG_WIZ))
848 show_commands (op, 1);
849 return 0;
850 }
851
852 /*
853 * User wants info about command
854 */
855 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
856 {
857 sprintf (line, "Illegal characters in '%s'", params);
858 new_draw_info (NDI_UNIQUE, 0, op, line);
859 return 0;
860 }
861
862 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
863 if (stat (filename, &st) || !S_ISREG (st.st_mode))
864 {
865 if (op)
866 {
867 sprintf (filename, "%s/help/%s", settings.datadir, params);
868 if (stat (filename, &st) || !S_ISREG (st.st_mode))
869 {
870 if (QUERY_FLAG (op, FLAG_WIZ))
871 {
872 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
873 if (stat (filename, &st) || !S_ISREG (st.st_mode))
874 goto nohelp;
875 }
876 else
877 goto nohelp;
878 }
879 }
880 }
881
882 /*
883 * Found that. Just cat it to screen.
884 */
885 if ((fp = fopen (filename, "r")) == NULL)
886 {
887 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
888 return 0;
889 }
890 sprintf (line, "Help about '%s'", params);
891 new_draw_info (NDI_UNIQUE, 0, op, line);
892 while (fgets (line, MAX_BUF, fp))
893 {
894 line[MAX_BUF - 1] = '\0';
895 len = strlen (line) - 1;
896 if (line[len] == '\n')
897 line[len] = '\0';
898 new_draw_info (NDI_UNIQUE, 0, op, line);
899 }
900 fclose (fp);
901 return 0;
902
903 /*
904 * No_help -escape
905 */
906nohelp:
907 sprintf (line, "No help available on '%s'", params);
908 new_draw_info (NDI_UNIQUE, 0, op, line);
909 return 0;
910}
911
912
913int 516int
914onoff_value (const char *line) 517onoff_value (const char *line)
915{ 518{
916 int i; 519 int i;
917 520
990command_kill_pets (object *op, char *params) 593command_kill_pets (object *op, char *params)
991{ 594{
992 objectlink *obl, *next; 595 objectlink *obl, *next;
993 int counter = 0, removecount = 0; 596 int counter = 0, removecount = 0;
994 597
995 if (params == NULL) 598 if (!params)
996 { 599 {
997 terminate_all_pets (op); 600 terminate_all_pets (op);
998 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); 601 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
999 } 602 }
1000 else 603 else
1001 { 604 {
1002 int target = atoi (params); 605 int target = atoi (params);
1003 606
1004 for (obl = first_friendly_object; obl != NULL; obl = next) 607 for (obl = first_friendly_object; obl; obl = next)
1005 { 608 {
1006 object *ob = obl->ob; 609 object *ob = obl->ob;
1007 610
1008 next = obl->next; 611 next = obl->next;
612
1009 if (ob->owner == op) 613 if (ob->owner == op)
1010 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 614 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1011 { 615 {
1012 ob->destroy (); 616 ob->destroy ();
1013 removecount++; 617 removecount++;
1014 } 618 }
1015 } 619 }
620
1016 if (removecount != 0) 621 if (removecount != 0)
1017 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);
1018 else 623 else
1019 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");
1020 } 625 }
626
1021 return 0; 627 return 0;
1022} 628}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines