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.52 by pippijn, Fri Mar 2 11:07:59 2007 UTC vs.
Revision 1.60 by root, Mon Jun 4 12:19:09 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software; you can redistribute it and/or modify it
9 * it under the terms of the GNU General Public License as published by 9 * under the terms of the GNU General Public License as published by the Free
10 * the Free Software Foundation; either version 2 of the License, or 10 * Software Foundation; either version 2 of the License, or (at your option)
11 * (at your option) any later version. 11 * any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful, but
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * GNU General Public License for more details. 16 * for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License along
19 * along with this program; if not, write to the Free Software 19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 21 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 23 */
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);
333 { 252 {
334 sprintf (buf, "Global debug level is %d.", settings.debug); 253 sprintf (buf, "Global debug level is %d.", settings.debug);
335 new_draw_info (NDI_UNIQUE, 0, op, buf); 254 new_draw_info (NDI_UNIQUE, 0, op, buf);
336 return 1; 255 return 1;
337 } 256 }
338 settings.debug = (enum LogLevel) FABS (i); 257
258 settings.debug = i;
259
339 sprintf (buf, "Set debug level to %d.", i); 260 sprintf (buf, "Set debug level to %d.", i);
340 new_draw_info (NDI_UNIQUE, 0, op, buf); 261 new_draw_info (NDI_UNIQUE, 0, op, buf);
341 return 1; 262 return 1;
342} 263}
343 264
569 int attack; 490 int attack;
570 object *tmp; 491 object *tmp;
571 492
572 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 493 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
573 { 494 {
574 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) 495 if ((tmp->type == FORCE) && (strcmp (tmp->arch->archname, "dragon_skin_force") == 0))
575 { 496 {
576 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); 497 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:");
577 for (attack = 0; attack < NROFATTACKS; attack++) 498 for (attack = 0; attack < NROFATTACKS; attack++)
578 { 499 {
579 if (atnr_is_dragon_enabled (attack)) 500 if (atnr_is_dragon_enabled (attack))
591 512
592/* 513/*
593 * Actual commands. 514 * Actual commands.
594 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) 515 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
595 */ 516 */
596
597
598static void
599help_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
646static void
647show_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
693int
694command_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 */
805nohelp:
806 sprintf (line, "No help available on '%s'", params);
807 new_draw_info (NDI_UNIQUE, 0, op, line);
808 return 0;
809}
810
811 517
812int 518int
813onoff_value (const char *line) 519onoff_value (const char *line)
814{ 520{
815 int i; 521 int i;
889command_kill_pets (object *op, char *params) 595command_kill_pets (object *op, char *params)
890{ 596{
891 objectlink *obl, *next; 597 objectlink *obl, *next;
892 int counter = 0, removecount = 0; 598 int counter = 0, removecount = 0;
893 599
894 if (params == NULL) 600 if (!params)
895 { 601 {
896 terminate_all_pets (op); 602 terminate_all_pets (op);
897 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); 603 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
898 } 604 }
899 else 605 else
900 { 606 {
901 int target = atoi (params); 607 int target = atoi (params);
902 608
903 for (obl = first_friendly_object; obl != NULL; obl = next) 609 for (obl = first_friendly_object; obl; obl = next)
904 { 610 {
905 object *ob = obl->ob; 611 object *ob = obl->ob;
906 612
907 next = obl->next; 613 next = obl->next;
614
908 if (ob->owner == op) 615 if (ob->owner == op)
909 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 616 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
910 { 617 {
911 ob->destroy (); 618 ob->destroy ();
912 removecount++; 619 removecount++;
913 } 620 }
914 } 621 }
622
915 if (removecount != 0) 623 if (removecount != 0)
916 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); 624 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
917 else 625 else
918 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); 626 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
919 } 627 }
628
920 return 0; 629 return 0;
921} 630}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines