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.31 by root, Wed Dec 27 09:28:02 2006 UTC vs.
Revision 1.57 by root, Wed Apr 25 19:19:54 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 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
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <loader.h> 26#include <loader.h>
26#include <sproto.h> 27#include <sproto.h>
27 28
28#include <dirent.h>
29
30extern weathermap_t **weathermap;
31
32/* Handles misc. input request - things like hash table, malloc, maps, 29/* Handles misc. input request - things like hash table, malloc, maps, etc */
33 * who, etc.
34 */
35
36void
37map_info (object *op, char *search)
38{
39 maptile *m;
40 char buf[MAX_BUF], map_path[MAX_BUF];
41 long sec = time (0);
42
43 new_draw_info_format (NDI_UNIQUE, 0, op, "Current time is: %02ld:%02ld:%02ld.", (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
44 new_draw_info (NDI_UNIQUE, 0, op, "Path Pl PlM IM TO Dif Reset");
45
46 for_all_maps (m)
47 {
48 if (search && !strstr (m->path, search))
49 continue; /* Skip unwanted maps */
50
51 /* Print out the last 18 characters of the map name... */
52 if (strlen (m->path) <= 18)
53 strcpy (map_path, m->path);
54 else
55 strcpy (map_path, m->path + strlen (m->path) - 18);
56
57 sprintf (buf, "%-18.18s %2d %2d %1d %4d %2d %02d:%02d:%02d",
58 map_path, m->players, players_on_map (m, FALSE),
59 m->in_memory, m->timeout, m->difficulty,
60 (m->reset_time % 86400) / 3600, (m->reset_time % 3600) / 60, m->reset_time % 60);
61 new_draw_info (NDI_UNIQUE, 0, op, buf);
62 }
63}
64
65/* This command dumps the body information for object *op.
66 * it doesn't care what the params are.
67 * This is mostly meant as a debug command.
68 */
69int
70command_body (object *op, char *params)
71{
72 int i;
73
74 /* Too hard to try and make a header that lines everything up, so just
75 * give a description.
76 */
77 new_draw_info (NDI_UNIQUE, 0, op, "The first column is the name of the body location.");
78 new_draw_info (NDI_UNIQUE, 0, op, "The second column is how many of those locations your body has.");
79 new_draw_info (NDI_UNIQUE, 0, op, "The third column is how many slots in that location are available.");
80 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
81 {
82 /* really debugging - normally body_used should not be set to anything
83 * if body_info isn't also set.
84 */
85 if (op->body_info[i] || op->body_used[i])
86 {
87 new_draw_info_format (NDI_UNIQUE, 0, op, "%-30s %5d %5d", body_locations[i].use_name, op->body_info[i], op->body_used[i]);
88 }
89 }
90 if (!QUERY_FLAG (op, FLAG_USE_ARMOUR))
91 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to wear armor");
92 if (!QUERY_FLAG (op, FLAG_USE_WEAPON))
93 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to use weapons");
94
95 return 1;
96}
97
98 30
99int 31int
100command_motd (object *op, char *params) 32command_motd (object *op, char *params)
101{ 33{
102 display_motd (op); 34 display_motd (op);
103 return 1; 35 return 1;
104} 36}
105 37
106int
107command_bug (object *op, char *params)
108{
109 char buf[MAX_BUF];
110
111 if (params == NULL)
112 {
113 new_draw_info (NDI_UNIQUE, 0, op, "what bugs?");
114 return 1;
115 }
116 strcpy (buf, op->name);
117 strcat (buf, " bug-reports: ");
118 strncat (buf, ++params, MAX_BUF - strlen (buf));
119 buf[MAX_BUF - 1] = '\0';
120 bug_report (buf);
121 LOG (llevError, "%s\n", buf);
122 new_draw_info (NDI_ALL | NDI_UNIQUE, 1, NULL, buf);
123 new_draw_info (NDI_UNIQUE, 0, op, "OK, thanks!");
124 return 1;
125}
126
127/*
128 * Pretty much identical to current map_info, but on a bigger scale
129 * This function returns the name of the players current region, and
130 * a description of it. It is there merely for flavour text.
131 */
132void
133current_region_info (object *op)
134{
135 /*
136 * Ok I /suppose/ I should write a seperate function for this, but it isn't
137 * going to be /that/ slow, and won't get called much
138 */
139 region *r = get_region_by_name (get_name_of_region_for_map (op->map));
140
141 if (!r)
142 return;
143 /* This should only be possible if regions are not operating on this server. */
144
145 new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s. \n %s", get_region_longname (r), get_region_msg (r));
146}
147
148void
149current_map_info (object *op)
150{
151 maptile *m = op->map;
152
153 if (!m)
154 return;
155
156 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", m->name, m->path, get_name_of_region_for_map (m));
157
158 if (QUERY_FLAG (op, FLAG_WIZ))
159 {
160 new_draw_info_format (NDI_UNIQUE, 0, op,
161 "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld",
162 m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout);
163
164 }
165 if (m->msg)
166 new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg);
167}
168
169#ifdef DEBUG_MALLOC_LEVEL 38#ifdef DEBUG_MALLOC_LEVEL
170int 39int
171command_malloc_verify (object *op, char *parms) 40command_malloc_verify (object *op, char *parms)
172{ 41{
173 extern int malloc_verify (void); 42 extern int malloc_verify (void);
174 43
175 if (!malloc_verify ()) 44 if (!malloc_verify ())
176 new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted."); 45 new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted.");
177 else 46 else
178 new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK."); 47 new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK.");
179 return 1; 48 return 1;
181#endif 50#endif
182 51
183int 52int
184command_whereabouts (object *op, char *params) 53command_whereabouts (object *op, char *params)
185{ 54{
186 55 //TODO: should obviously not waste space in struct region for this.
187 region *reg;
188 player *pl;
189
190 /* 56 /*
191 * 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
192 * players there. 58 * players there.
193 * 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....
194 */ 60 */
195 for (reg = first_region; reg != NULL; reg = reg->next) 61 for_all_regions (rgn)
196 {
197 reg->counter = 0; 62 rgn->counter = 0;
198 } 63
199 for_all_players (pl) 64 for_all_players (pl)
200 if (pl->ob->map != NULL) 65 if (pl->ob->map)
201 get_region_by_map (pl->ob->map)->counter++; 66 ++pl->ob->region ()->counter;
202 67
203 /* 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... */
204 for (reg = first_region; reg != NULL; reg = reg->next) 69 for_all_regions (rgn)
205 { 70 {
206 if (reg->longname == NULL && reg->counter > 0) 71 if (!rgn->longname && rgn->counter > 0)
207 { 72 {
208 if (reg->parent != NULL) 73 if (rgn->parent)
209 { 74 {
210 reg->parent->counter += reg->counter; 75 rgn->parent->counter += rgn->counter;
211 reg->counter = 0; 76 rgn->counter = 0;
212 } 77 }
213 else /*uh oh, we shouldn't be here. */ 78 else /*uh oh, we shouldn't be here. */
214 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);
215 } 80 }
216 } 81 }
82
217 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:");
218 for (reg = first_region; reg != NULL; reg = reg->next) 84
85 for_all_regions (rgn)
219 if (reg->counter > 0) 86 if (rgn->counter)
220 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
221 return 1; 89 return 1;
222} 90}
223 91
224typedef struct 92typedef struct
225{ 93{
226 char namebuf[MAX_BUF]; 94 char namebuf[MAX_BUF];
227 int login_order; 95 int login_order;
228} chars_names; 96} chars_names;
229 97
230int 98int
231command_afk (object *op, char *params)
232{
233 if ((op->contr->ns->afk = !op->contr->ns->afk))
234 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK");
235 else
236 new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK");
237
238 return 1;
239}
240
241int
242command_mapinfo (object *op, char *params)
243{
244 current_map_info (op);
245 return 1;
246}
247
248int
249command_whereami (object *op, char *params)
250{
251 current_region_info (op);
252 return 1;
253}
254
255int
256command_maps (object *op, char *params)
257{
258 map_info (op, params);
259 return 1;
260}
261
262int
263command_time (object *op, char *params) 99command_time (object *op, char *params)
264{ 100{
265 print_tod (op); 101 print_tod (op);
266 return 1; 102 return 1;
267} 103}
268 104
269int 105int
270command_weather (object *op, char *params) 106command_weather (object *op, char *params)
271{ 107{
108#if 0
272 int wx, wy, temp, sky; 109 int wx, wy, temp, sky;
273 char buf[MAX_BUF]; 110 char buf[MAX_BUF];
274 111
275 if (settings.dynamiclevel < 1) 112 if (settings.dynamiclevel < 1)
276 return 1; 113 return 1;
392 break; 229 break;
393 case SKY_BLIZZARD: 230 case SKY_BLIZZARD:
394 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!"); 231 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!");
395 break; 232 break;
396 } 233 }
397 return 1; 234#endif
398}
399
400int
401command_archs (object *op, char *params)
402{
403 arch_info (op);
404 return 1; 235 return 1;
405} 236}
406 237
407int 238int
408command_hiscore (object *op, char *params) 239command_hiscore (object *op, char *params)
419 250
420 if (params == NULL || !sscanf (params, "%d", &i)) 251 if (params == NULL || !sscanf (params, "%d", &i))
421 { 252 {
422 sprintf (buf, "Global debug level is %d.", settings.debug); 253 sprintf (buf, "Global debug level is %d.", settings.debug);
423 new_draw_info (NDI_UNIQUE, 0, op, buf); 254 new_draw_info (NDI_UNIQUE, 0, op, buf);
424 return 1;
425 }
426 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
427 {
428 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command.");
429 return 1; 255 return 1;
430 } 256 }
431 settings.debug = (enum LogLevel) FABS (i); 257 settings.debug = (enum LogLevel) FABS (i);
432 sprintf (buf, "Set debug level to %d.", i); 258 sprintf (buf, "Set debug level to %d.", i);
433 new_draw_info (NDI_UNIQUE, 0, op, buf); 259 new_draw_info (NDI_UNIQUE, 0, op, buf);
459 dump_friendly_objects (); 285 dump_friendly_objects ();
460 return 0; 286 return 0;
461} 287}
462 288
463int 289int
464command_dumpmap (object *op, char *params)
465{
466 if (op)
467 dump_map (op->map);
468 return 0;
469}
470
471int
472command_dumpallmaps (object *op, char *params)
473{
474 dump_all_maps ();
475 return 0;
476}
477
478int
479command_printlos (object *op, char *params) 290command_printlos (object *op, char *params)
480{ 291{
481 if (op) 292 if (op)
482 print_los (op); 293 print_los (op);
483 return 0; 294 return 0;
488command_version (object *op, char *params) 299command_version (object *op, char *params)
489{ 300{
490 version (op); 301 version (op);
491 return 0; 302 return 0;
492} 303}
493
494 304
495#ifndef BUG_LOG 305#ifndef BUG_LOG
496# define BUG_LOG "bug_log" 306# define BUG_LOG "bug_log"
497#endif 307#endif
498void 308void
507 } 317 }
508 else 318 else
509 { 319 {
510 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));
511 } 321 }
512}
513
514int
515command_output_sync (object *op, char *params)
516{
517 int val;
518
519 if (!params)
520 {
521 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync);
522 return 1;
523 }
524 val = atoi (params);
525 if (val > 0)
526 {
527 op->contr->outputs_sync = val;
528 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync);
529 }
530 else
531 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync.");
532
533 return 1;
534}
535
536int
537command_output_count (object *op, char *params)
538{
539 int val;
540
541 if (!params)
542 {
543 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count);
544 return 1;
545 }
546 val = atoi (params);
547 if (val > 0)
548 {
549 op->contr->outputs_count = val;
550 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count);
551 }
552 else
553 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
554
555 return 1;
556}
557
558int
559command_listen (object *op, char *params)
560{
561 int i;
562
563 if (params == NULL || !sscanf (params, "%d", &i))
564 {
565 new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening);
566 return 1;
567 }
568 op->contr->listening = (char) i;
569 new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i);
570 return 1;
571} 322}
572 323
573/* Prints out some useful information for the character. Everything we print 324/* Prints out some useful information for the character. Everything we print
574 * 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 -
575 * 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
607int 358int
608command_fix_me (object *op, char *params) 359command_fix_me (object *op, char *params)
609{ 360{
610 sum_weight (op); 361 sum_weight (op);
611 op->update_stats (); 362 op->update_stats ();
612 return 1; 363 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
613}
614 364
615int
616command_players (object *op, char *paramss)
617{
618 char buf[MAX_BUF];
619 char *t;
620 DIR *Dir;
621
622 sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir);
623 t = buf + strlen (buf);
624 if ((Dir = opendir (buf)) != NULL)
625 {
626 const struct dirent *Entry;
627
628 while ((Entry = readdir (Dir)))
629 {
630 /* skip '.' , '..' */
631 if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') ||
632 (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0')))
633 {
634 struct stat Stat;
635
636 strcpy (t, Entry->d_name);
637 if (stat (buf, &Stat) == 0)
638 {
639 /* This was not posix compatible
640 * if ((Stat.st_mode & S_IFMT)==S_IFDIR) {
641 */
642 if (S_ISDIR (Stat.st_mode))
643 {
644 char buf2[MAX_BUF];
645 struct tm *tm = localtime (&Stat.st_mtime);
646
647 sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d",
648 Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
649 new_draw_info (NDI_UNIQUE, 0, op, buf2);
650 }
651 }
652 }
653 }
654 }
655 closedir (Dir);
656 return 0; 365 return 1;
657} 366}
658
659
660 367
661int 368int
662command_logs (object *op, char *params) 369command_logs (object *op, char *params)
663{ 370{
664 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.");
665 372
666 return 1;
667}
668
669int
670command_applymode (object *op, char *params)
671{
672 unapplymode unapply = op->contr->unapply;
673 static const char *const types[] = { "nochoice", "never", "always" };
674
675 if (!params)
676 {
677 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]);
678 return 1;
679 }
680
681 if (!strcmp (params, "nochoice"))
682 op->contr->unapply = unapply_nochoice;
683 else if (!strcmp (params, "never"))
684 op->contr->unapply = unapply_never;
685 else if (!strcmp (params, "always"))
686 op->contr->unapply = unapply_always;
687 else
688 {
689 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
690 return 0;
691 }
692 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
693 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
694 return 1; 373 return 1;
695} 374}
696 375
697int 376int
698command_bowmode (object *op, char *params) 377command_bowmode (object *op, char *params)
718 found++; 397 found++;
719 op->contr->bowtype = (bowtype_t) i; 398 op->contr->bowtype = (bowtype_t) i;
720 break; 399 break;
721 } 400 }
722 } 401 }
402
723 if (!found) 403 if (!found)
724 { 404 {
725 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 405 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
726 for (i = 0; i <= bow_bestarrow; i++) 406 for (i = 0; i <= bow_bestarrow; i++)
727 { 407 {
733 strcat (buf, "."); 413 strcat (buf, ".");
734 } 414 }
735 new_draw_info_format (NDI_UNIQUE, 0, op, buf); 415 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
736 return 0; 416 return 0;
737 } 417 }
418
738 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]);
739 return 1;
740}
741
742int
743command_petmode (object *op, char *params)
744{
745 petmode_t oldtype = op->contr->petmode;
746 static const char *const types[] = { "normal", "sad", "defend", "arena" };
747
748 if (!params)
749 {
750 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]);
751 return 1;
752 }
753
754 if (!strcmp (params, "normal"))
755 op->contr->petmode = pet_normal;
756 else if (!strcmp (params, "sad"))
757 op->contr->petmode = pet_sad;
758 else if (!strcmp (params, "defend"))
759 op->contr->petmode = pet_defend;
760 else if (!strcmp (params, "arena"))
761 op->contr->petmode = pet_arena;
762 else
763 {
764 new_draw_info_format (NDI_UNIQUE, 0, op,
765 "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params);
766 return 0;
767 }
768 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]);
769 return 1; 420 return 1;
770} 421}
771 422
772int 423int
773command_showpets (object *op, char *params) 424command_showpets (object *op, char *params)
814 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 465 new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
815 return 0; 466 return 0;
816} 467}
817 468
818int 469int
819command_usekeys (object *op, char *params)
820{
821 usekeytype oldtype = op->contr->usekeys;
822 static const char *const types[] = { "inventory", "keyrings", "containers" };
823
824 if (!params)
825 {
826 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]);
827 return 1;
828 }
829
830 if (!strcmp (params, "inventory"))
831 op->contr->usekeys = key_inventory;
832 else if (!strcmp (params, "keyrings"))
833 op->contr->usekeys = keyrings;
834 else if (!strcmp (params, "containers"))
835 op->contr->usekeys = containers;
836 else
837 {
838 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params);
839 return 0;
840 }
841 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]);
842 return 1;
843}
844
845int
846command_resistances (object *op, char *params) 470command_resistances (object *op, char *params)
847{ 471{
848 int i; 472 int i;
849 473
850 if (!op) 474 if (!op)
886 510
887/* 511/*
888 * Actual commands. 512 * Actual commands.
889 * 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,...)
890 */ 514 */
891
892
893static void
894help_topics (object *op, int what)
895{
896 DIR *dirp;
897 struct dirent *de;
898 char filename[MAX_BUF], line[80];
899 int namelen, linelen = 0;
900
901 switch (what)
902 {
903 case 1:
904 sprintf (filename, "%s/wizhelp", settings.datadir);
905 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
906 break;
907 case 3:
908 sprintf (filename, "%s/mischelp", settings.datadir);
909 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
910 break;
911 default:
912 sprintf (filename, "%s/help", settings.datadir);
913 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
914 break;
915 }
916
917 if (!(dirp = opendir (filename)))
918 return;
919
920 line[0] = '\0';
921 while (de = readdir (dirp))
922 {
923 namelen = strlen (de->d_name);
924 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
925 continue;
926 linelen += namelen + 1;
927 if (linelen > 42)
928 {
929 new_draw_info (NDI_UNIQUE, 0, op, line);
930 sprintf (line, " %s", de->d_name);
931 linelen = namelen + 1;
932 continue;
933 }
934 strcat (line, " ");
935 strcat (line, de->d_name);
936 }
937 new_draw_info (NDI_UNIQUE, 0, op, line);
938 closedir (dirp);
939}
940
941static void
942show_commands (object *op, int what)
943{
944 char line[80];
945 int i, size, namelen, linelen = 0;
946 CommArray_s *ap;
947 extern CommArray_s Commands[], WizCommands[];
948 extern const int CommandsSize, WizCommandsSize;
949
950 switch (what)
951 {
952 case 1:
953 ap = WizCommands;
954 size = WizCommandsSize;
955 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
956 break;
957 case 2:
958 ap = CommunicationCommands;
959 size = CommunicationCommandSize;
960 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
961 break;
962 default:
963 ap = Commands;
964 size = CommandsSize;
965 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
966 break;
967 }
968
969 line[0] = '\0';
970 for (i = 0; i < size; i++)
971 {
972 namelen = strlen (ap[i].name);
973 linelen += namelen + 1;
974 if (linelen > 42)
975 {
976 new_draw_info (NDI_UNIQUE, 0, op, line);
977 sprintf (line, " %s", ap[i].name);
978 linelen = namelen + 1;
979 continue;
980 }
981 strcat (line, " ");
982 strcat (line, ap[i].name);
983 }
984 new_draw_info (NDI_UNIQUE, 0, op, line);
985}
986
987
988int
989command_help (object *op, char *params)
990{
991 struct stat st;
992 FILE *fp;
993 char filename[MAX_BUF], line[MAX_BUF];
994 int len;
995
996 if (op != NULL)
997 clear_win_info (op);
998
999/*
1000 * Main help page?
1001 */
1002 if (!params)
1003 {
1004 sprintf (filename, "%s/def_help", settings.datadir);
1005 if ((fp = fopen (filename, "r")) == NULL)
1006 {
1007 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1008 return 0;
1009 }
1010 while (fgets (line, MAX_BUF, fp))
1011 {
1012 line[MAX_BUF - 1] = '\0';
1013 len = strlen (line) - 1;
1014 if (line[len] == '\n')
1015 line[len] = '\0';
1016 new_draw_info (NDI_UNIQUE, 0, op, line);
1017 }
1018 fclose (fp);
1019 return 0;
1020 }
1021
1022 /*
1023 * Topics list
1024 */
1025 if (!strcmp (params, "topics"))
1026 {
1027 help_topics (op, 3);
1028 help_topics (op, 0);
1029 if (QUERY_FLAG (op, FLAG_WIZ))
1030 help_topics (op, 1);
1031 return 0;
1032 }
1033
1034 /*
1035 * Commands list
1036 */
1037 if (!strcmp (params, "commands"))
1038 {
1039 show_commands (op, 0);
1040 show_commands (op, 2); /* show comm commands */
1041 if (QUERY_FLAG (op, FLAG_WIZ))
1042 show_commands (op, 1);
1043 return 0;
1044 }
1045
1046 /*
1047 * User wants info about command
1048 */
1049 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
1050 {
1051 sprintf (line, "Illegal characters in '%s'", params);
1052 new_draw_info (NDI_UNIQUE, 0, op, line);
1053 return 0;
1054 }
1055
1056 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
1057 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1058 {
1059 if (op)
1060 {
1061 sprintf (filename, "%s/help/%s", settings.datadir, params);
1062 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1063 {
1064 if (QUERY_FLAG (op, FLAG_WIZ))
1065 {
1066 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
1067 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1068 goto nohelp;
1069 }
1070 else
1071 goto nohelp;
1072 }
1073 }
1074 }
1075
1076 /*
1077 * Found that. Just cat it to screen.
1078 */
1079 if ((fp = fopen (filename, "r")) == NULL)
1080 {
1081 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1082 return 0;
1083 }
1084 sprintf (line, "Help about '%s'", params);
1085 new_draw_info (NDI_UNIQUE, 0, op, line);
1086 while (fgets (line, MAX_BUF, fp))
1087 {
1088 line[MAX_BUF - 1] = '\0';
1089 len = strlen (line) - 1;
1090 if (line[len] == '\n')
1091 line[len] = '\0';
1092 new_draw_info (NDI_UNIQUE, 0, op, line);
1093 }
1094 fclose (fp);
1095 return 0;
1096
1097 /*
1098 * No_help -escape
1099 */
1100nohelp:
1101 sprintf (line, "No help available on '%s'", params);
1102 new_draw_info (NDI_UNIQUE, 0, op, line);
1103 return 0;
1104}
1105
1106 515
1107int 516int
1108onoff_value (const char *line) 517onoff_value (const char *line)
1109{ 518{
1110 int i; 519 int i;
1133 return 0; 542 return 0;
1134 } 543 }
1135} 544}
1136 545
1137int 546int
1138command_quit (object *op, char *params)
1139{
1140 new_draw_info (NDI_UNIQUE, 0, op,
1141 "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit.");
1142 return 1;
1143}
1144
1145int
1146command_real_quit (object *op, char *params)
1147{
1148 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):");
1149
1150 op->contr->ns->state = ST_CONFIRM_QUIT;
1151 return 1;
1152}
1153
1154/*
1155 * don't allow people to exit explore mode. It otherwise becomes
1156 * really easy to abuse this.
1157 */
1158int
1159command_explore (object *op, char *params)
1160{
1161 if (settings.explore_mode == FALSE)
1162 return 1;
1163 /*
1164 * I guess this is the best way to see if we are solo or not. Actually,
1165 * are there any cases when first_player->next==NULL and we are not solo?
1166 */
1167 if ((first_player != op->contr) || (first_player->next != NULL))
1168 {
1169 new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party");
1170 }
1171 else if (op->contr->explore)
1172 new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode");
1173 else
1174 {
1175 op->contr->explore = 1;
1176 new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode");
1177 }
1178 return 1;
1179}
1180
1181int
1182command_sound (object *op, char *params)
1183{
1184 if (op->contr->ns->sound)
1185 {
1186 op->contr->ns->sound = 0;
1187 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
1188 }
1189 else
1190 {
1191 op->contr->ns->sound = 1;
1192 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1193 }
1194
1195 return 1;
1196}
1197
1198int
1199explore_mode (void)
1200{
1201 player *pl;
1202
1203 if (settings.explore_mode == TRUE)
1204 {
1205 for (pl = first_player; pl != (player *) NULL; pl = pl->next)
1206 if (pl->explore)
1207 return 1;
1208 }
1209 return 0;
1210}
1211
1212int
1213command_title (object *op, char *params) 547command_title (object *op, char *params)
1214{ 548{
1215 char buf[MAX_BUF]; 549 char buf[MAX_BUF];
1216 550
1217 if (settings.set_title == FALSE) 551 if (settings.set_title == FALSE)
1254 strcpy (op->contr->own_title, params); 588 strcpy (op->contr->own_title, params);
1255 return 1; 589 return 1;
1256} 590}
1257 591
1258int 592int
1259command_save (object *op, char *params)
1260{
1261 if (!op->stats.exp)
1262 new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet.");
1263 else
1264 {
1265 op->contr->save ();
1266 new_draw_info (NDI_UNIQUE, 0, op, "You have been saved.");
1267 }
1268
1269 return 1;
1270}
1271
1272int
1273command_peaceful (object *op, char *params)
1274{
1275 new_draw_info (NDI_UNIQUE, 0, op,
1276 "You cannot change your peaceful setting with this command."
1277 " Please speak to the priest in the temple of Gorokh"
1278 " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again.");
1279
1280/*
1281 if((op->contr->peaceful=!op->contr->peaceful))
1282 new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players.");
1283 else
1284 new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players.");
1285*/
1286 return 1;
1287}
1288
1289int
1290command_wimpy (object *op, char *params)
1291{
1292 int i;
1293 char buf[MAX_BUF];
1294
1295 if (params == NULL || !sscanf (params, "%d", &i))
1296 {
1297 sprintf (buf, "Your current wimpy level is %d.", op->run_away);
1298 new_draw_info (NDI_UNIQUE, 0, op, buf);
1299 return 1;
1300 }
1301 sprintf (buf, "Your new wimpy level is %d.", i);
1302 new_draw_info (NDI_UNIQUE, 0, op, buf);
1303 op->run_away = i;
1304 return 1;
1305}
1306
1307int
1308command_brace (object *op, char *params)
1309{
1310 if (!params)
1311 op->contr->braced = !op->contr->braced;
1312 else
1313 op->contr->braced = onoff_value (params);
1314
1315 if (op->contr->braced)
1316 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1317 else
1318 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1319
1320 op->update_stats ();
1321 return 0;
1322}
1323
1324int
1325command_style_map_info (object *op, char *params)
1326{
1327 extern maptile *styles;
1328 maptile *mp;
1329 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
1330 object *tmp;
1331
1332 for (mp = styles; mp != NULL; mp = mp->next)
1333 {
1334 maps_used++;
1335 mapmem += mp->width * mp->height * (sizeof (object *) + sizeof (mapspace)) + sizeof (maptile);
1336 for (x = 0; x < mp->width; x++)
1337 {
1338 for (y = 0; y < mp->height; y++)
1339 {
1340 for (tmp = GET_MAP_OB (mp, x, y); tmp != NULL; tmp = tmp->above)
1341 objects_used++;
1342 }
1343 }
1344 }
1345 new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used);
1346 new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not");
1347 new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem);
1348 new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used);
1349 new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object));
1350 return 0;
1351}
1352
1353int
1354command_kill_pets (object *op, char *params) 593command_kill_pets (object *op, char *params)
1355{ 594{
1356 objectlink *obl, *next; 595 objectlink *obl, *next;
1357 int counter = 0, removecount = 0; 596 int counter = 0, removecount = 0;
1358 597
1359 if (params == NULL) 598 if (!params)
1360 { 599 {
1361 terminate_all_pets (op); 600 terminate_all_pets (op);
1362 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.");
1363 } 602 }
1364 else 603 else
1365 { 604 {
1366 int target = atoi (params); 605 int target = atoi (params);
1367 606
1368 for (obl = first_friendly_object; obl != NULL; obl = next) 607 for (obl = first_friendly_object; obl; obl = next)
1369 { 608 {
1370 object *ob = obl->ob; 609 object *ob = obl->ob;
1371 610
1372 next = obl->next; 611 next = obl->next;
612
1373 if (ob->owner == op) 613 if (ob->owner == op)
1374 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 614 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1375 { 615 {
1376 ob->destroy (); 616 ob->destroy ();
1377 removecount++; 617 removecount++;
1378 } 618 }
1379 } 619 }
620
1380 if (removecount != 0) 621 if (removecount != 0)
1381 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);
1382 else 623 else
1383 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");
1384 } 625 }
626
1385 return 0; 627 return 0;
1386} 628}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines