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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines