… | |
… | |
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 | int |
|
|
75 | command_bug (object *op, char *params) |
|
|
76 | { |
|
|
77 | char buf[MAX_BUF]; |
|
|
78 | |
|
|
79 | if (params == NULL) |
|
|
80 | { |
|
|
81 | new_draw_info (NDI_UNIQUE, 0, op, "what bugs?"); |
|
|
82 | return 1; |
|
|
83 | } |
|
|
84 | assign (buf, op->name); |
|
|
85 | strcat (buf, " bug-reports: "); |
|
|
86 | strncat (buf, ++params, MAX_BUF - strlen (buf)); |
|
|
87 | buf[MAX_BUF - 1] = '\0'; |
|
|
88 | bug_report (buf); |
|
|
89 | LOG (llevError, "%s\n", buf); |
|
|
90 | new_draw_info (NDI_ALL | NDI_UNIQUE, 1, NULL, buf); |
|
|
91 | new_draw_info (NDI_UNIQUE, 0, op, "OK, thanks!"); |
|
|
92 | return 1; |
|
|
93 | } |
|
|
94 | |
|
|
95 | /* |
|
|
96 | * Pretty much identical to current map_info, but on a bigger scale |
|
|
97 | * This function returns the name of the players current region, and |
|
|
98 | * a description of it. It is there merely for flavour text. |
|
|
99 | */ |
|
|
100 | void |
|
|
101 | current_region_info (object *op) |
|
|
102 | { |
|
|
103 | if (region *reg = op->region ()) |
|
|
104 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are %s.\n%s", ®->longname, ®->msg); |
|
|
105 | } |
|
|
106 | |
|
|
107 | void |
|
|
108 | current_map_info (object *op) |
|
|
109 | { |
|
|
110 | maptile *m = op->map; |
|
|
111 | |
|
|
112 | if (!m) |
|
|
113 | return; |
|
|
114 | |
|
|
115 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) %s", &m->name, &m->path, &op->region ()->longname); |
|
|
116 | |
|
|
117 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
118 | new_draw_info_format (NDI_UNIQUE, 0, op, |
|
|
119 | "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld", |
|
|
120 | m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout); |
|
|
121 | |
|
|
122 | if (m->msg) |
|
|
123 | new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); |
|
|
124 | } |
|
|
125 | |
|
|
126 | #ifdef DEBUG_MALLOC_LEVEL |
38 | #ifdef DEBUG_MALLOC_LEVEL |
127 | int |
39 | int |
128 | command_malloc_verify (object *op, char *parms) |
40 | command_malloc_verify (object *op, char *parms) |
129 | { |
41 | { |
130 | extern int malloc_verify (void); |
42 | extern int malloc_verify (void); |
131 | |
43 | |
132 | if (!malloc_verify ()) |
44 | if (!malloc_verify ()) |
133 | new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted."); |
45 | new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted."); |
134 | else |
46 | else |
135 | new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK."); |
47 | new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK."); |
136 | return 1; |
48 | return 1; |
… | |
… | |
180 | typedef struct |
92 | typedef struct |
181 | { |
93 | { |
182 | char namebuf[MAX_BUF]; |
94 | char namebuf[MAX_BUF]; |
183 | int login_order; |
95 | int login_order; |
184 | } chars_names; |
96 | } chars_names; |
185 | |
|
|
186 | int |
|
|
187 | command_afk (object *op, char *params) |
|
|
188 | { |
|
|
189 | if ((op->contr->ns->afk = !op->contr->ns->afk)) |
|
|
190 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK"); |
|
|
191 | else |
|
|
192 | new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK"); |
|
|
193 | |
|
|
194 | return 1; |
|
|
195 | } |
|
|
196 | |
|
|
197 | int |
|
|
198 | command_mapinfo (object *op, char *params) |
|
|
199 | { |
|
|
200 | current_map_info (op); |
|
|
201 | return 1; |
|
|
202 | } |
|
|
203 | |
|
|
204 | int |
|
|
205 | command_whereami (object *op, char *params) |
|
|
206 | { |
|
|
207 | current_region_info (op); |
|
|
208 | return 1; |
|
|
209 | } |
|
|
210 | |
97 | |
211 | int |
98 | int |
212 | command_time (object *op, char *params) |
99 | command_time (object *op, char *params) |
213 | { |
100 | { |
214 | print_tod (op); |
101 | print_tod (op); |
… | |
… | |
365 | { |
252 | { |
366 | sprintf (buf, "Global debug level is %d.", settings.debug); |
253 | sprintf (buf, "Global debug level is %d.", settings.debug); |
367 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
254 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
368 | return 1; |
255 | return 1; |
369 | } |
256 | } |
370 | if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) |
|
|
371 | { |
|
|
372 | new_draw_info (NDI_UNIQUE, 0, op, "Privileged command."); |
|
|
373 | return 1; |
|
|
374 | } |
|
|
375 | settings.debug = (enum LogLevel) FABS (i); |
257 | settings.debug = (enum LogLevel) FABS (i); |
376 | sprintf (buf, "Set debug level to %d.", i); |
258 | sprintf (buf, "Set debug level to %d.", i); |
377 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
259 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
378 | return 1; |
260 | return 1; |
379 | } |
261 | } |
… | |
… | |
435 | } |
317 | } |
436 | else |
318 | else |
437 | { |
319 | { |
438 | 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)); |
439 | } |
321 | } |
440 | } |
|
|
441 | |
|
|
442 | int |
|
|
443 | command_output_sync (object *op, char *params) |
|
|
444 | { |
|
|
445 | int val; |
|
|
446 | |
|
|
447 | if (!params) |
|
|
448 | { |
|
|
449 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync); |
|
|
450 | return 1; |
|
|
451 | } |
|
|
452 | val = atoi (params); |
|
|
453 | if (val > 0) |
|
|
454 | { |
|
|
455 | op->contr->outputs_sync = val; |
|
|
456 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync); |
|
|
457 | } |
|
|
458 | else |
|
|
459 | new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync."); |
|
|
460 | |
|
|
461 | return 1; |
|
|
462 | } |
|
|
463 | |
|
|
464 | int |
|
|
465 | command_output_count (object *op, char *params) |
|
|
466 | { |
|
|
467 | int val; |
|
|
468 | |
|
|
469 | if (!params) |
|
|
470 | { |
|
|
471 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count); |
|
|
472 | return 1; |
|
|
473 | } |
|
|
474 | val = atoi (params); |
|
|
475 | if (val > 0) |
|
|
476 | { |
|
|
477 | op->contr->outputs_count = val; |
|
|
478 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count); |
|
|
479 | } |
|
|
480 | else |
|
|
481 | new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count."); |
|
|
482 | |
|
|
483 | return 1; |
|
|
484 | } |
|
|
485 | |
|
|
486 | int |
|
|
487 | command_listen (object *op, char *params) |
|
|
488 | { |
|
|
489 | int i; |
|
|
490 | |
|
|
491 | if (params == NULL || !sscanf (params, "%d", &i)) |
|
|
492 | { |
|
|
493 | new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening); |
|
|
494 | return 1; |
|
|
495 | } |
|
|
496 | op->contr->listening = (char) i; |
|
|
497 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i); |
|
|
498 | return 1; |
|
|
499 | } |
322 | } |
500 | |
323 | |
501 | /* Prints out some useful information for the character. Everything we print |
324 | /* Prints out some useful information for the character. Everything we print |
502 | * 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 - |
503 | * 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 |
… | |
… | |
535 | int |
358 | int |
536 | command_fix_me (object *op, char *params) |
359 | command_fix_me (object *op, char *params) |
537 | { |
360 | { |
538 | sum_weight (op); |
361 | sum_weight (op); |
539 | op->update_stats (); |
362 | op->update_stats (); |
|
|
363 | new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed."); |
|
|
364 | |
540 | return 1; |
365 | return 1; |
541 | } |
366 | } |
542 | |
367 | |
543 | int |
368 | int |
544 | command_logs (object *op, char *params) |
369 | command_logs (object *op, char *params) |
545 | { |
370 | { |
546 | 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."); |
547 | |
372 | |
548 | return 1; |
|
|
549 | } |
|
|
550 | |
|
|
551 | int |
|
|
552 | command_applymode (object *op, char *params) |
|
|
553 | { |
|
|
554 | unapplymode unapply = op->contr->unapply; |
|
|
555 | static const char *const types[] = { "nochoice", "never", "always" }; |
|
|
556 | |
|
|
557 | if (!params) |
|
|
558 | { |
|
|
559 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]); |
|
|
560 | return 1; |
|
|
561 | } |
|
|
562 | |
|
|
563 | if (!strcmp (params, "nochoice")) |
|
|
564 | op->contr->unapply = unapply_nochoice; |
|
|
565 | else if (!strcmp (params, "never")) |
|
|
566 | op->contr->unapply = unapply_never; |
|
|
567 | else if (!strcmp (params, "always")) |
|
|
568 | op->contr->unapply = unapply_always; |
|
|
569 | else |
|
|
570 | { |
|
|
571 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params); |
|
|
572 | return 0; |
|
|
573 | } |
|
|
574 | |
|
|
575 | new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s", |
|
|
576 | (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]); |
|
|
577 | return 1; |
373 | return 1; |
578 | } |
374 | } |
579 | |
375 | |
580 | int |
376 | int |
581 | command_bowmode (object *op, char *params) |
377 | command_bowmode (object *op, char *params) |
… | |
… | |
619 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
415 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
620 | return 0; |
416 | return 0; |
621 | } |
417 | } |
622 | |
418 | |
623 | 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]); |
624 | return 1; |
|
|
625 | } |
|
|
626 | |
|
|
627 | int |
|
|
628 | command_petmode (object *op, char *params) |
|
|
629 | { |
|
|
630 | petmode_t oldtype = op->contr->petmode; |
|
|
631 | static const char *const types[] = { "normal", "sad", "defend", "arena" }; |
|
|
632 | |
|
|
633 | if (!params) |
|
|
634 | { |
|
|
635 | new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]); |
|
|
636 | return 1; |
|
|
637 | } |
|
|
638 | |
|
|
639 | if (!strcmp (params, "normal")) |
|
|
640 | op->contr->petmode = pet_normal; |
|
|
641 | else if (!strcmp (params, "sad")) |
|
|
642 | op->contr->petmode = pet_sad; |
|
|
643 | else if (!strcmp (params, "defend")) |
|
|
644 | op->contr->petmode = pet_defend; |
|
|
645 | else if (!strcmp (params, "arena")) |
|
|
646 | op->contr->petmode = pet_arena; |
|
|
647 | else |
|
|
648 | { |
|
|
649 | new_draw_info_format (NDI_UNIQUE, 0, op, |
|
|
650 | "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params); |
|
|
651 | return 0; |
|
|
652 | } |
|
|
653 | new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]); |
|
|
654 | return 1; |
420 | return 1; |
655 | } |
421 | } |
656 | |
422 | |
657 | int |
423 | int |
658 | command_showpets (object *op, char *params) |
424 | command_showpets (object *op, char *params) |
… | |
… | |
699 | new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); |
465 | new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); |
700 | return 0; |
466 | return 0; |
701 | } |
467 | } |
702 | |
468 | |
703 | int |
469 | int |
704 | command_usekeys (object *op, char *params) |
|
|
705 | { |
|
|
706 | usekeytype oldtype = op->contr->usekeys; |
|
|
707 | static const char *const types[] = { "inventory", "keyrings", "containers" }; |
|
|
708 | |
|
|
709 | if (!params) |
|
|
710 | { |
|
|
711 | new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]); |
|
|
712 | return 1; |
|
|
713 | } |
|
|
714 | |
|
|
715 | if (!strcmp (params, "inventory")) |
|
|
716 | op->contr->usekeys = key_inventory; |
|
|
717 | else if (!strcmp (params, "keyrings")) |
|
|
718 | op->contr->usekeys = keyrings; |
|
|
719 | else if (!strcmp (params, "containers")) |
|
|
720 | op->contr->usekeys = containers; |
|
|
721 | else |
|
|
722 | { |
|
|
723 | new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params); |
|
|
724 | return 0; |
|
|
725 | } |
|
|
726 | new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]); |
|
|
727 | return 1; |
|
|
728 | } |
|
|
729 | |
|
|
730 | int |
|
|
731 | command_resistances (object *op, char *params) |
470 | command_resistances (object *op, char *params) |
732 | { |
471 | { |
733 | int i; |
472 | int i; |
734 | |
473 | |
735 | if (!op) |
474 | if (!op) |
… | |
… | |
771 | |
510 | |
772 | /* |
511 | /* |
773 | * Actual commands. |
512 | * Actual commands. |
774 | * 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,...) |
775 | */ |
514 | */ |
776 | |
|
|
777 | |
|
|
778 | static void |
|
|
779 | help_topics (object *op, int what) |
|
|
780 | { |
|
|
781 | DIR *dirp; |
|
|
782 | struct dirent *de; |
|
|
783 | char filename[MAX_BUF], line[80]; |
|
|
784 | int namelen, linelen = 0; |
|
|
785 | |
|
|
786 | switch (what) |
|
|
787 | { |
|
|
788 | case 1: |
|
|
789 | sprintf (filename, "%s/wizhelp", settings.datadir); |
|
|
790 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
|
|
791 | break; |
|
|
792 | case 3: |
|
|
793 | sprintf (filename, "%s/mischelp", settings.datadir); |
|
|
794 | new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); |
|
|
795 | break; |
|
|
796 | default: |
|
|
797 | sprintf (filename, "%s/help", settings.datadir); |
|
|
798 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
|
|
799 | break; |
|
|
800 | } |
|
|
801 | |
|
|
802 | if (!(dirp = opendir (filename))) |
|
|
803 | return; |
|
|
804 | |
|
|
805 | line[0] = '\0'; |
|
|
806 | while ((de = readdir (dirp))) |
|
|
807 | { |
|
|
808 | namelen = strlen (de->d_name); |
|
|
809 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
|
|
810 | continue; |
|
|
811 | linelen += namelen + 1; |
|
|
812 | if (linelen > 42) |
|
|
813 | { |
|
|
814 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
815 | sprintf (line, " %s", de->d_name); |
|
|
816 | linelen = namelen + 1; |
|
|
817 | continue; |
|
|
818 | } |
|
|
819 | strcat (line, " "); |
|
|
820 | strcat (line, de->d_name); |
|
|
821 | } |
|
|
822 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
823 | closedir (dirp); |
|
|
824 | } |
|
|
825 | |
|
|
826 | static void |
|
|
827 | show_commands (object *op, int what) |
|
|
828 | { |
|
|
829 | char line[80]; |
|
|
830 | int i, size, namelen, linelen = 0; |
|
|
831 | CommArray_s *ap; |
|
|
832 | extern CommArray_s Commands[], WizCommands[]; |
|
|
833 | extern const int CommandsSize, WizCommandsSize; |
|
|
834 | |
|
|
835 | switch (what) |
|
|
836 | { |
|
|
837 | case 1: |
|
|
838 | ap = WizCommands; |
|
|
839 | size = WizCommandsSize; |
|
|
840 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
|
|
841 | break; |
|
|
842 | case 2: |
|
|
843 | ap = CommunicationCommands; |
|
|
844 | size = CommunicationCommandSize; |
|
|
845 | new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:"); |
|
|
846 | break; |
|
|
847 | default: |
|
|
848 | ap = Commands; |
|
|
849 | size = CommandsSize; |
|
|
850 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
|
|
851 | break; |
|
|
852 | } |
|
|
853 | |
|
|
854 | line[0] = '\0'; |
|
|
855 | for (i = 0; i < size; i++) |
|
|
856 | { |
|
|
857 | namelen = strlen (ap[i].name); |
|
|
858 | linelen += namelen + 1; |
|
|
859 | if (linelen > 42) |
|
|
860 | { |
|
|
861 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
862 | sprintf (line, " %s", ap[i].name); |
|
|
863 | linelen = namelen + 1; |
|
|
864 | continue; |
|
|
865 | } |
|
|
866 | strcat (line, " "); |
|
|
867 | strcat (line, ap[i].name); |
|
|
868 | } |
|
|
869 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
870 | } |
|
|
871 | |
|
|
872 | |
|
|
873 | int |
|
|
874 | command_help (object *op, char *params) |
|
|
875 | { |
|
|
876 | struct stat st; |
|
|
877 | FILE *fp; |
|
|
878 | char filename[MAX_BUF], line[MAX_BUF]; |
|
|
879 | int len; |
|
|
880 | |
|
|
881 | if (op != NULL) |
|
|
882 | clear_win_info (op); |
|
|
883 | |
|
|
884 | /* |
|
|
885 | * Main help page? |
|
|
886 | */ |
|
|
887 | if (!params) |
|
|
888 | { |
|
|
889 | sprintf (filename, "%s/def_help", settings.datadir); |
|
|
890 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
891 | { |
|
|
892 | LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno)); |
|
|
893 | return 0; |
|
|
894 | } |
|
|
895 | while (fgets (line, MAX_BUF, fp)) |
|
|
896 | { |
|
|
897 | line[MAX_BUF - 1] = '\0'; |
|
|
898 | len = strlen (line) - 1; |
|
|
899 | if (line[len] == '\n') |
|
|
900 | line[len] = '\0'; |
|
|
901 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
902 | } |
|
|
903 | fclose (fp); |
|
|
904 | return 0; |
|
|
905 | } |
|
|
906 | |
|
|
907 | /* |
|
|
908 | * Topics list |
|
|
909 | */ |
|
|
910 | if (!strcmp (params, "topics")) |
|
|
911 | { |
|
|
912 | help_topics (op, 3); |
|
|
913 | help_topics (op, 0); |
|
|
914 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
915 | help_topics (op, 1); |
|
|
916 | return 0; |
|
|
917 | } |
|
|
918 | |
|
|
919 | /* |
|
|
920 | * Commands list |
|
|
921 | */ |
|
|
922 | if (!strcmp (params, "commands")) |
|
|
923 | { |
|
|
924 | show_commands (op, 0); |
|
|
925 | show_commands (op, 2); /* show comm commands */ |
|
|
926 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
927 | show_commands (op, 1); |
|
|
928 | return 0; |
|
|
929 | } |
|
|
930 | |
|
|
931 | /* |
|
|
932 | * User wants info about command |
|
|
933 | */ |
|
|
934 | if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/')) |
|
|
935 | { |
|
|
936 | sprintf (line, "Illegal characters in '%s'", params); |
|
|
937 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
938 | return 0; |
|
|
939 | } |
|
|
940 | |
|
|
941 | sprintf (filename, "%s/mischelp/%s", settings.datadir, params); |
|
|
942 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
943 | { |
|
|
944 | if (op) |
|
|
945 | { |
|
|
946 | sprintf (filename, "%s/help/%s", settings.datadir, params); |
|
|
947 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
948 | { |
|
|
949 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
950 | { |
|
|
951 | sprintf (filename, "%s/wizhelp/%s", settings.datadir, params); |
|
|
952 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
953 | goto nohelp; |
|
|
954 | } |
|
|
955 | else |
|
|
956 | goto nohelp; |
|
|
957 | } |
|
|
958 | } |
|
|
959 | } |
|
|
960 | |
|
|
961 | /* |
|
|
962 | * Found that. Just cat it to screen. |
|
|
963 | */ |
|
|
964 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
965 | { |
|
|
966 | LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno)); |
|
|
967 | return 0; |
|
|
968 | } |
|
|
969 | sprintf (line, "Help about '%s'", params); |
|
|
970 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
971 | while (fgets (line, MAX_BUF, fp)) |
|
|
972 | { |
|
|
973 | line[MAX_BUF - 1] = '\0'; |
|
|
974 | len = strlen (line) - 1; |
|
|
975 | if (line[len] == '\n') |
|
|
976 | line[len] = '\0'; |
|
|
977 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
978 | } |
|
|
979 | fclose (fp); |
|
|
980 | return 0; |
|
|
981 | |
|
|
982 | /* |
|
|
983 | * No_help -escape |
|
|
984 | */ |
|
|
985 | nohelp: |
|
|
986 | sprintf (line, "No help available on '%s'", params); |
|
|
987 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
988 | return 0; |
|
|
989 | } |
|
|
990 | |
|
|
991 | |
515 | |
992 | int |
516 | int |
993 | onoff_value (const char *line) |
517 | onoff_value (const char *line) |
994 | { |
518 | { |
995 | int i; |
519 | int i; |
… | |
… | |
1018 | return 0; |
542 | return 0; |
1019 | } |
543 | } |
1020 | } |
544 | } |
1021 | |
545 | |
1022 | int |
546 | int |
1023 | command_sound (object *op, char *params) |
|
|
1024 | { |
|
|
1025 | if (op->contr->ns->sound) |
|
|
1026 | { |
|
|
1027 | op->contr->ns->sound = 0; |
|
|
1028 | new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden..."); |
|
|
1029 | } |
|
|
1030 | else |
|
|
1031 | { |
|
|
1032 | op->contr->ns->sound = 1; |
|
|
1033 | new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled."); |
|
|
1034 | } |
|
|
1035 | |
|
|
1036 | return 1; |
|
|
1037 | } |
|
|
1038 | |
|
|
1039 | int |
|
|
1040 | command_title (object *op, char *params) |
547 | command_title (object *op, char *params) |
1041 | { |
548 | { |
1042 | char buf[MAX_BUF]; |
549 | char buf[MAX_BUF]; |
1043 | |
550 | |
1044 | if (settings.set_title == FALSE) |
551 | if (settings.set_title == FALSE) |
… | |
… | |
1081 | strcpy (op->contr->own_title, params); |
588 | strcpy (op->contr->own_title, params); |
1082 | return 1; |
589 | return 1; |
1083 | } |
590 | } |
1084 | |
591 | |
1085 | int |
592 | int |
1086 | command_peaceful (object *op, char *params) |
|
|
1087 | { |
|
|
1088 | new_draw_info (NDI_UNIQUE, 0, op, |
|
|
1089 | "You cannot change your peaceful setting with this command." |
|
|
1090 | " Please speak to the priest in the temple of Gorokh" |
|
|
1091 | " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again."); |
|
|
1092 | |
|
|
1093 | /* |
|
|
1094 | if((op->contr->peaceful=!op->contr->peaceful)) |
|
|
1095 | new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players."); |
|
|
1096 | else |
|
|
1097 | new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players."); |
|
|
1098 | */ |
|
|
1099 | return 1; |
|
|
1100 | } |
|
|
1101 | |
|
|
1102 | int |
|
|
1103 | command_wimpy (object *op, char *params) |
|
|
1104 | { |
|
|
1105 | int i; |
|
|
1106 | char buf[MAX_BUF]; |
|
|
1107 | |
|
|
1108 | if (params == NULL || !sscanf (params, "%d", &i)) |
|
|
1109 | { |
|
|
1110 | sprintf (buf, "Your current wimpy level is %d.", op->run_away); |
|
|
1111 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
1112 | return 1; |
|
|
1113 | } |
|
|
1114 | sprintf (buf, "Your new wimpy level is %d.", i); |
|
|
1115 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
1116 | op->run_away = i; |
|
|
1117 | return 1; |
|
|
1118 | } |
|
|
1119 | |
|
|
1120 | int |
|
|
1121 | command_brace (object *op, char *params) |
|
|
1122 | { |
|
|
1123 | if (!params) |
|
|
1124 | op->contr->braced = !op->contr->braced; |
|
|
1125 | else |
|
|
1126 | op->contr->braced = onoff_value (params); |
|
|
1127 | |
|
|
1128 | if (op->contr->braced) |
|
|
1129 | new_draw_info (NDI_UNIQUE, 0, op, "You are braced."); |
|
|
1130 | else |
|
|
1131 | new_draw_info (NDI_UNIQUE, 0, op, "Not braced."); |
|
|
1132 | |
|
|
1133 | op->update_stats (); |
|
|
1134 | return 0; |
|
|
1135 | } |
|
|
1136 | |
|
|
1137 | int |
|
|
1138 | command_kill_pets (object *op, char *params) |
593 | command_kill_pets (object *op, char *params) |
1139 | { |
594 | { |
1140 | objectlink *obl, *next; |
595 | objectlink *obl, *next; |
1141 | int counter = 0, removecount = 0; |
596 | int counter = 0, removecount = 0; |
1142 | |
597 | |
1143 | if (params == NULL) |
598 | if (!params) |
1144 | { |
599 | { |
1145 | terminate_all_pets (op); |
600 | terminate_all_pets (op); |
1146 | 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."); |
1147 | } |
602 | } |
1148 | else |
603 | else |
1149 | { |
604 | { |
1150 | int target = atoi (params); |
605 | int target = atoi (params); |
1151 | |
606 | |
1152 | for (obl = first_friendly_object; obl != NULL; obl = next) |
607 | for (obl = first_friendly_object; obl; obl = next) |
1153 | { |
608 | { |
1154 | object *ob = obl->ob; |
609 | object *ob = obl->ob; |
1155 | |
610 | |
1156 | next = obl->next; |
611 | next = obl->next; |
|
|
612 | |
1157 | if (ob->owner == op) |
613 | if (ob->owner == op) |
1158 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
614 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
1159 | { |
615 | { |
1160 | ob->destroy (); |
616 | ob->destroy (); |
1161 | removecount++; |
617 | removecount++; |
1162 | } |
618 | } |
1163 | } |
619 | } |
|
|
620 | |
1164 | if (removecount != 0) |
621 | if (removecount != 0) |
1165 | 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); |
1166 | else |
623 | else |
1167 | 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"); |
1168 | } |
625 | } |
|
|
626 | |
1169 | return 0; |
627 | return 0; |
1170 | } |
628 | } |