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.37 by root, Wed Jan 17 22:13:10 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#include <dirent.h>
30
31/* Handles misc. input request - things like hash table, malloc, maps, 29/* Handles misc. input request - things like hash table, malloc, maps, etc */
32 * who, etc.
33 */
34
35/* This command dumps the body information for object *op.
36 * it doesn't care what the params are.
37 * This is mostly meant as a debug command.
38 */
39int
40command_body (object *op, char *params)
41{
42 int i;
43
44 /* Too hard to try and make a header that lines everything up, so just
45 * give a description.
46 */
47 new_draw_info (NDI_UNIQUE, 0, op, "The first column is the name of the body location.");
48 new_draw_info (NDI_UNIQUE, 0, op, "The second column is how many of those locations your body has.");
49 new_draw_info (NDI_UNIQUE, 0, op, "The third column is how many slots in that location are available.");
50 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
51 {
52 /* really debugging - normally body_used should not be set to anything
53 * if body_info isn't also set.
54 */
55 if (op->body_info[i] || op->body_used[i])
56 {
57 new_draw_info_format (NDI_UNIQUE, 0, op, "%-30s %5d %5d", body_locations[i].use_name, op->body_info[i], op->body_used[i]);
58 }
59 }
60 if (!QUERY_FLAG (op, FLAG_USE_ARMOUR))
61 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to wear armor");
62 if (!QUERY_FLAG (op, FLAG_USE_WEAPON))
63 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to use weapons");
64
65 return 1;
66}
67
68 30
69int 31int
70command_motd (object *op, char *params) 32command_motd (object *op, char *params)
71{ 33{
72 display_motd (op); 34 display_motd (op);
73 return 1; 35 return 1;
74} 36}
75 37
76int
77command_bug (object *op, char *params)
78{
79 char buf[MAX_BUF];
80
81 if (params == NULL)
82 {
83 new_draw_info (NDI_UNIQUE, 0, op, "what bugs?");
84 return 1;
85 }
86 strcpy (buf, op->name);
87 strcat (buf, " bug-reports: ");
88 strncat (buf, ++params, MAX_BUF - strlen (buf));
89 buf[MAX_BUF - 1] = '\0';
90 bug_report (buf);
91 LOG (llevError, "%s\n", buf);
92 new_draw_info (NDI_ALL | NDI_UNIQUE, 1, NULL, buf);
93 new_draw_info (NDI_UNIQUE, 0, op, "OK, thanks!");
94 return 1;
95}
96
97/*
98 * Pretty much identical to current map_info, but on a bigger scale
99 * This function returns the name of the players current region, and
100 * a description of it. It is there merely for flavour text.
101 */
102void
103current_region_info (object *op)
104{
105 /*
106 * Ok I /suppose/ I should write a seperate function for this, but it isn't
107 * going to be /that/ slow, and won't get called much
108 */
109 region *r = get_region_by_name (get_name_of_region_for_map (op->map));
110
111 if (!r)
112 return;
113 /* This should only be possible if regions are not operating on this server. */
114
115 new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s. \n %s", get_region_longname (r), get_region_msg (r));
116}
117
118void
119current_map_info (object *op)
120{
121 maptile *m = op->map;
122
123 if (!m)
124 return;
125
126 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", &m->name, &m->path, get_name_of_region_for_map (m));
127
128 if (QUERY_FLAG (op, FLAG_WIZ))
129 {
130 new_draw_info_format (NDI_UNIQUE, 0, op,
131 "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld",
132 m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout);
133
134 }
135 if (m->msg)
136 new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg);
137}
138
139#ifdef DEBUG_MALLOC_LEVEL 38#ifdef DEBUG_MALLOC_LEVEL
140int 39int
141command_malloc_verify (object *op, char *parms) 40command_malloc_verify (object *op, char *parms)
142{ 41{
143 extern int malloc_verify (void); 42 extern int malloc_verify (void);
144 43
145 if (!malloc_verify ()) 44 if (!malloc_verify ())
146 new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted."); 45 new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted.");
147 else 46 else
148 new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK."); 47 new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK.");
149 return 1; 48 return 1;
151#endif 50#endif
152 51
153int 52int
154command_whereabouts (object *op, char *params) 53command_whereabouts (object *op, char *params)
155{ 54{
156 55 //TODO: should obviously not waste space in struct region for this.
157 region *reg;
158 player *pl;
159
160 /* 56 /*
161 * reset the counter on the region, then use it to store the number of 57 * reset the counter on the region, then use it to store the number of
162 * players there. 58 * players there.
163 * I don't know how thread-safe this would be, I suspect not very.... 59 * I don't know how thread-safe this would be, I suspect not very....
164 */ 60 */
165 for (reg = first_region; reg != NULL; reg = reg->next) 61 for_all_regions (rgn)
166 {
167 reg->counter = 0; 62 rgn->counter = 0;
168 } 63
169 for_all_players (pl) 64 for_all_players (pl)
170 if (pl->ob->map != NULL) 65 if (pl->ob->map)
171 get_region_by_map (pl->ob->map)->counter++; 66 ++pl->ob->region ()->counter;
172 67
173 /* we only want to print out by places with a 'longname' field... */ 68 /* we only want to print out by places with a 'longname' field... */
174 for (reg = first_region; reg != NULL; reg = reg->next) 69 for_all_regions (rgn)
175 { 70 {
176 if (reg->longname == NULL && reg->counter > 0) 71 if (!rgn->longname && rgn->counter > 0)
177 { 72 {
178 if (reg->parent != NULL) 73 if (rgn->parent)
179 { 74 {
180 reg->parent->counter += reg->counter; 75 rgn->parent->counter += rgn->counter;
181 reg->counter = 0; 76 rgn->counter = 0;
182 } 77 }
183 else /*uh oh, we shouldn't be here. */ 78 else /*uh oh, we shouldn't be here. */
184 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name); 79 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", &rgn->name);
185 } 80 }
186 } 81 }
82
187 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); 83 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:");
188 for (reg = first_region; reg != NULL; reg = reg->next) 84
85 for_all_regions (rgn)
189 if (reg->counter > 0) 86 if (rgn->counter)
190 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg)); 87 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players %s", rgn->counter, &rgn->longname);
88
191 return 1; 89 return 1;
192} 90}
193 91
194typedef struct 92typedef struct
195{ 93{
196 char namebuf[MAX_BUF]; 94 char namebuf[MAX_BUF];
197 int login_order; 95 int login_order;
198} chars_names; 96} chars_names;
199
200int
201command_afk (object *op, char *params)
202{
203 if ((op->contr->ns->afk = !op->contr->ns->afk))
204 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK");
205 else
206 new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK");
207
208 return 1;
209}
210
211int
212command_mapinfo (object *op, char *params)
213{
214 current_map_info (op);
215 return 1;
216}
217
218int
219command_whereami (object *op, char *params)
220{
221 current_region_info (op);
222 return 1;
223}
224 97
225int 98int
226command_time (object *op, char *params) 99command_time (object *op, char *params)
227{ 100{
228 print_tod (op); 101 print_tod (op);
361#endif 234#endif
362 return 1; 235 return 1;
363} 236}
364 237
365int 238int
366command_archs (object *op, char *params)
367{
368 arch_info (op);
369 return 1;
370}
371
372int
373command_hiscore (object *op, char *params) 239command_hiscore (object *op, char *params)
374{ 240{
375 display_high_score (op, op == NULL ? 9999 : 50, params); 241 display_high_score (op, op == NULL ? 9999 : 50, params);
376 return 1; 242 return 1;
377} 243}
384 250
385 if (params == NULL || !sscanf (params, "%d", &i)) 251 if (params == NULL || !sscanf (params, "%d", &i))
386 { 252 {
387 sprintf (buf, "Global debug level is %d.", settings.debug); 253 sprintf (buf, "Global debug level is %d.", settings.debug);
388 new_draw_info (NDI_UNIQUE, 0, op, buf); 254 new_draw_info (NDI_UNIQUE, 0, op, buf);
389 return 1;
390 }
391 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
392 {
393 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command.");
394 return 1; 255 return 1;
395 } 256 }
396 settings.debug = (enum LogLevel) FABS (i); 257 settings.debug = (enum LogLevel) FABS (i);
397 sprintf (buf, "Set debug level to %d.", i); 258 sprintf (buf, "Set debug level to %d.", i);
398 new_draw_info (NDI_UNIQUE, 0, op, buf); 259 new_draw_info (NDI_UNIQUE, 0, op, buf);
456 } 317 }
457 else 318 else
458 { 319 {
459 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));
460 } 321 }
461}
462
463int
464command_output_sync (object *op, char *params)
465{
466 int val;
467
468 if (!params)
469 {
470 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync);
471 return 1;
472 }
473 val = atoi (params);
474 if (val > 0)
475 {
476 op->contr->outputs_sync = val;
477 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync);
478 }
479 else
480 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync.");
481
482 return 1;
483}
484
485int
486command_output_count (object *op, char *params)
487{
488 int val;
489
490 if (!params)
491 {
492 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count);
493 return 1;
494 }
495 val = atoi (params);
496 if (val > 0)
497 {
498 op->contr->outputs_count = val;
499 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count);
500 }
501 else
502 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
503
504 return 1;
505}
506
507int
508command_listen (object *op, char *params)
509{
510 int i;
511
512 if (params == NULL || !sscanf (params, "%d", &i))
513 {
514 new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening);
515 return 1;
516 }
517 op->contr->listening = (char) i;
518 new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i);
519 return 1;
520} 322}
521 323
522/* Prints out some useful information for the character. Everything we print 324/* Prints out some useful information for the character. Everything we print
523 * 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 -
524 * 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
556int 358int
557command_fix_me (object *op, char *params) 359command_fix_me (object *op, char *params)
558{ 360{
559 sum_weight (op); 361 sum_weight (op);
560 op->update_stats (); 362 op->update_stats ();
561 return 1; 363 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
562}
563 364
564int
565command_players (object *op, char *paramss)
566{
567 char buf[MAX_BUF];
568 char *t;
569 DIR *Dir;
570
571 sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir);
572 t = buf + strlen (buf);
573 if ((Dir = opendir (buf)) != NULL)
574 {
575 const struct dirent *Entry;
576
577 while ((Entry = readdir (Dir)))
578 {
579 /* skip '.' , '..' */
580 if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') ||
581 (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0')))
582 {
583 struct stat Stat;
584
585 strcpy (t, Entry->d_name);
586 if (stat (buf, &Stat) == 0)
587 {
588 /* This was not posix compatible
589 * if ((Stat.st_mode & S_IFMT)==S_IFDIR) {
590 */
591 if (S_ISDIR (Stat.st_mode))
592 {
593 char buf2[MAX_BUF];
594 struct tm *tm = localtime (&Stat.st_mtime);
595
596 sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d",
597 Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
598 new_draw_info (NDI_UNIQUE, 0, op, buf2);
599 }
600 }
601 }
602 }
603 }
604 closedir (Dir);
605 return 0; 365 return 1;
606} 366}
607
608
609 367
610int 368int
611command_logs (object *op, char *params) 369command_logs (object *op, char *params)
612{ 370{
613 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.");
614 372
615 return 1;
616}
617
618int
619command_applymode (object *op, char *params)
620{
621 unapplymode unapply = op->contr->unapply;
622 static const char *const types[] = { "nochoice", "never", "always" };
623
624 if (!params)
625 {
626 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]);
627 return 1;
628 }
629
630 if (!strcmp (params, "nochoice"))
631 op->contr->unapply = unapply_nochoice;
632 else if (!strcmp (params, "never"))
633 op->contr->unapply = unapply_never;
634 else if (!strcmp (params, "always"))
635 op->contr->unapply = unapply_always;
636 else
637 {
638 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
639 return 0;
640 }
641 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
642 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
643 return 1; 373 return 1;
644} 374}
645 375
646int 376int
647command_bowmode (object *op, char *params) 377command_bowmode (object *op, char *params)
667 found++; 397 found++;
668 op->contr->bowtype = (bowtype_t) i; 398 op->contr->bowtype = (bowtype_t) i;
669 break; 399 break;
670 } 400 }
671 } 401 }
402
672 if (!found) 403 if (!found)
673 { 404 {
674 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 405 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
675 for (i = 0; i <= bow_bestarrow; i++) 406 for (i = 0; i <= bow_bestarrow; i++)
676 { 407 {
682 strcat (buf, "."); 413 strcat (buf, ".");
683 } 414 }
684 new_draw_info_format (NDI_UNIQUE, 0, op, buf); 415 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
685 return 0; 416 return 0;
686 } 417 }
418
687 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]);
688 return 1;
689}
690
691int
692command_petmode (object *op, char *params)
693{
694 petmode_t oldtype = op->contr->petmode;
695 static const char *const types[] = { "normal", "sad", "defend", "arena" };
696
697 if (!params)
698 {
699 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]);
700 return 1;
701 }
702
703 if (!strcmp (params, "normal"))
704 op->contr->petmode = pet_normal;
705 else if (!strcmp (params, "sad"))
706 op->contr->petmode = pet_sad;
707 else if (!strcmp (params, "defend"))
708 op->contr->petmode = pet_defend;
709 else if (!strcmp (params, "arena"))
710 op->contr->petmode = pet_arena;
711 else
712 {
713 new_draw_info_format (NDI_UNIQUE, 0, op,
714 "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params);
715 return 0;
716 }
717 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]);
718 return 1; 420 return 1;
719} 421}
720 422
721int 423int
722command_showpets (object *op, char *params) 424command_showpets (object *op, char *params)
763 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 465 new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
764 return 0; 466 return 0;
765} 467}
766 468
767int 469int
768command_usekeys (object *op, char *params)
769{
770 usekeytype oldtype = op->contr->usekeys;
771 static const char *const types[] = { "inventory", "keyrings", "containers" };
772
773 if (!params)
774 {
775 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]);
776 return 1;
777 }
778
779 if (!strcmp (params, "inventory"))
780 op->contr->usekeys = key_inventory;
781 else if (!strcmp (params, "keyrings"))
782 op->contr->usekeys = keyrings;
783 else if (!strcmp (params, "containers"))
784 op->contr->usekeys = containers;
785 else
786 {
787 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params);
788 return 0;
789 }
790 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]);
791 return 1;
792}
793
794int
795command_resistances (object *op, char *params) 470command_resistances (object *op, char *params)
796{ 471{
797 int i; 472 int i;
798 473
799 if (!op) 474 if (!op)
835 510
836/* 511/*
837 * Actual commands. 512 * Actual commands.
838 * 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,...)
839 */ 514 */
840
841
842static void
843help_topics (object *op, int what)
844{
845 DIR *dirp;
846 struct dirent *de;
847 char filename[MAX_BUF], line[80];
848 int namelen, linelen = 0;
849
850 switch (what)
851 {
852 case 1:
853 sprintf (filename, "%s/wizhelp", settings.datadir);
854 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
855 break;
856 case 3:
857 sprintf (filename, "%s/mischelp", settings.datadir);
858 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
859 break;
860 default:
861 sprintf (filename, "%s/help", settings.datadir);
862 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
863 break;
864 }
865
866 if (!(dirp = opendir (filename)))
867 return;
868
869 line[0] = '\0';
870 while (de = readdir (dirp))
871 {
872 namelen = strlen (de->d_name);
873 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
874 continue;
875 linelen += namelen + 1;
876 if (linelen > 42)
877 {
878 new_draw_info (NDI_UNIQUE, 0, op, line);
879 sprintf (line, " %s", de->d_name);
880 linelen = namelen + 1;
881 continue;
882 }
883 strcat (line, " ");
884 strcat (line, de->d_name);
885 }
886 new_draw_info (NDI_UNIQUE, 0, op, line);
887 closedir (dirp);
888}
889
890static void
891show_commands (object *op, int what)
892{
893 char line[80];
894 int i, size, namelen, linelen = 0;
895 CommArray_s *ap;
896 extern CommArray_s Commands[], WizCommands[];
897 extern const int CommandsSize, WizCommandsSize;
898
899 switch (what)
900 {
901 case 1:
902 ap = WizCommands;
903 size = WizCommandsSize;
904 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
905 break;
906 case 2:
907 ap = CommunicationCommands;
908 size = CommunicationCommandSize;
909 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
910 break;
911 default:
912 ap = Commands;
913 size = CommandsSize;
914 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
915 break;
916 }
917
918 line[0] = '\0';
919 for (i = 0; i < size; i++)
920 {
921 namelen = strlen (ap[i].name);
922 linelen += namelen + 1;
923 if (linelen > 42)
924 {
925 new_draw_info (NDI_UNIQUE, 0, op, line);
926 sprintf (line, " %s", ap[i].name);
927 linelen = namelen + 1;
928 continue;
929 }
930 strcat (line, " ");
931 strcat (line, ap[i].name);
932 }
933 new_draw_info (NDI_UNIQUE, 0, op, line);
934}
935
936
937int
938command_help (object *op, char *params)
939{
940 struct stat st;
941 FILE *fp;
942 char filename[MAX_BUF], line[MAX_BUF];
943 int len;
944
945 if (op != NULL)
946 clear_win_info (op);
947
948/*
949 * Main help page?
950 */
951 if (!params)
952 {
953 sprintf (filename, "%s/def_help", settings.datadir);
954 if ((fp = fopen (filename, "r")) == NULL)
955 {
956 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
957 return 0;
958 }
959 while (fgets (line, MAX_BUF, fp))
960 {
961 line[MAX_BUF - 1] = '\0';
962 len = strlen (line) - 1;
963 if (line[len] == '\n')
964 line[len] = '\0';
965 new_draw_info (NDI_UNIQUE, 0, op, line);
966 }
967 fclose (fp);
968 return 0;
969 }
970
971 /*
972 * Topics list
973 */
974 if (!strcmp (params, "topics"))
975 {
976 help_topics (op, 3);
977 help_topics (op, 0);
978 if (QUERY_FLAG (op, FLAG_WIZ))
979 help_topics (op, 1);
980 return 0;
981 }
982
983 /*
984 * Commands list
985 */
986 if (!strcmp (params, "commands"))
987 {
988 show_commands (op, 0);
989 show_commands (op, 2); /* show comm commands */
990 if (QUERY_FLAG (op, FLAG_WIZ))
991 show_commands (op, 1);
992 return 0;
993 }
994
995 /*
996 * User wants info about command
997 */
998 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
999 {
1000 sprintf (line, "Illegal characters in '%s'", params);
1001 new_draw_info (NDI_UNIQUE, 0, op, line);
1002 return 0;
1003 }
1004
1005 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
1006 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1007 {
1008 if (op)
1009 {
1010 sprintf (filename, "%s/help/%s", settings.datadir, params);
1011 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1012 {
1013 if (QUERY_FLAG (op, FLAG_WIZ))
1014 {
1015 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
1016 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1017 goto nohelp;
1018 }
1019 else
1020 goto nohelp;
1021 }
1022 }
1023 }
1024
1025 /*
1026 * Found that. Just cat it to screen.
1027 */
1028 if ((fp = fopen (filename, "r")) == NULL)
1029 {
1030 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1031 return 0;
1032 }
1033 sprintf (line, "Help about '%s'", params);
1034 new_draw_info (NDI_UNIQUE, 0, op, line);
1035 while (fgets (line, MAX_BUF, fp))
1036 {
1037 line[MAX_BUF - 1] = '\0';
1038 len = strlen (line) - 1;
1039 if (line[len] == '\n')
1040 line[len] = '\0';
1041 new_draw_info (NDI_UNIQUE, 0, op, line);
1042 }
1043 fclose (fp);
1044 return 0;
1045
1046 /*
1047 * No_help -escape
1048 */
1049nohelp:
1050 sprintf (line, "No help available on '%s'", params);
1051 new_draw_info (NDI_UNIQUE, 0, op, line);
1052 return 0;
1053}
1054
1055 515
1056int 516int
1057onoff_value (const char *line) 517onoff_value (const char *line)
1058{ 518{
1059 int i; 519 int i;
1082 return 0; 542 return 0;
1083 } 543 }
1084} 544}
1085 545
1086int 546int
1087command_sound (object *op, char *params)
1088{
1089 if (op->contr->ns->sound)
1090 {
1091 op->contr->ns->sound = 0;
1092 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
1093 }
1094 else
1095 {
1096 op->contr->ns->sound = 1;
1097 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1098 }
1099
1100 return 1;
1101}
1102
1103int
1104command_title (object *op, char *params) 547command_title (object *op, char *params)
1105{ 548{
1106 char buf[MAX_BUF]; 549 char buf[MAX_BUF];
1107 550
1108 if (settings.set_title == FALSE) 551 if (settings.set_title == FALSE)
1145 strcpy (op->contr->own_title, params); 588 strcpy (op->contr->own_title, params);
1146 return 1; 589 return 1;
1147} 590}
1148 591
1149int 592int
1150command_peaceful (object *op, char *params)
1151{
1152 new_draw_info (NDI_UNIQUE, 0, op,
1153 "You cannot change your peaceful setting with this command."
1154 " Please speak to the priest in the temple of Gorokh"
1155 " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again.");
1156
1157/*
1158 if((op->contr->peaceful=!op->contr->peaceful))
1159 new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players.");
1160 else
1161 new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players.");
1162*/
1163 return 1;
1164}
1165
1166int
1167command_wimpy (object *op, char *params)
1168{
1169 int i;
1170 char buf[MAX_BUF];
1171
1172 if (params == NULL || !sscanf (params, "%d", &i))
1173 {
1174 sprintf (buf, "Your current wimpy level is %d.", op->run_away);
1175 new_draw_info (NDI_UNIQUE, 0, op, buf);
1176 return 1;
1177 }
1178 sprintf (buf, "Your new wimpy level is %d.", i);
1179 new_draw_info (NDI_UNIQUE, 0, op, buf);
1180 op->run_away = i;
1181 return 1;
1182}
1183
1184int
1185command_brace (object *op, char *params)
1186{
1187 if (!params)
1188 op->contr->braced = !op->contr->braced;
1189 else
1190 op->contr->braced = onoff_value (params);
1191
1192 if (op->contr->braced)
1193 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1194 else
1195 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1196
1197 op->update_stats ();
1198 return 0;
1199}
1200
1201int
1202command_kill_pets (object *op, char *params) 593command_kill_pets (object *op, char *params)
1203{ 594{
1204 objectlink *obl, *next; 595 objectlink *obl, *next;
1205 int counter = 0, removecount = 0; 596 int counter = 0, removecount = 0;
1206 597
1207 if (params == NULL) 598 if (!params)
1208 { 599 {
1209 terminate_all_pets (op); 600 terminate_all_pets (op);
1210 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.");
1211 } 602 }
1212 else 603 else
1213 { 604 {
1214 int target = atoi (params); 605 int target = atoi (params);
1215 606
1216 for (obl = first_friendly_object; obl != NULL; obl = next) 607 for (obl = first_friendly_object; obl; obl = next)
1217 { 608 {
1218 object *ob = obl->ob; 609 object *ob = obl->ob;
1219 610
1220 next = obl->next; 611 next = obl->next;
612
1221 if (ob->owner == op) 613 if (ob->owner == op)
1222 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 614 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1223 { 615 {
1224 ob->destroy (); 616 ob->destroy ();
1225 removecount++; 617 removecount++;
1226 } 618 }
1227 } 619 }
620
1228 if (removecount != 0) 621 if (removecount != 0)
1229 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);
1230 else 623 else
1231 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");
1232 } 625 }
626
1233 return 0; 627 return 0;
1234} 628}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines