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.24 by root, Mon Dec 18 02:35:01 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 (pl = first_player; pl != NULL; pl = pl->next) 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 (QUERY_FLAG (op, FLAG_AFK))
232 {
233 CLEAR_FLAG (op, FLAG_AFK);
234 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK");
235 }
236 else
237 {
238 SET_FLAG (op, FLAG_AFK);
239 new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK");
240 }
241
242 return 1;
243}
244
245int
246command_mapinfo (object *op, char *params)
247{
248 current_map_info (op);
249 return 1;
250}
251
252int
253command_whereami (object *op, char *params)
254{
255 current_region_info (op);
256 return 1;
257}
258
259int
260command_maps (object *op, char *params)
261{
262 map_info (op, params);
263 return 1;
264}
265
266int
267command_time (object *op, char *params) 99command_time (object *op, char *params)
268{ 100{
269 print_tod (op); 101 print_tod (op);
270 return 1; 102 return 1;
271} 103}
272 104
273int 105int
274command_weather (object *op, char *params) 106command_weather (object *op, char *params)
275{ 107{
108#if 0
276 int wx, wy, temp, sky; 109 int wx, wy, temp, sky;
277 char buf[MAX_BUF]; 110 char buf[MAX_BUF];
278 111
279 if (settings.dynamiclevel < 1) 112 if (settings.dynamiclevel < 1)
280 return 1; 113 return 1;
396 break; 229 break;
397 case SKY_BLIZZARD: 230 case SKY_BLIZZARD:
398 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!");
399 break; 232 break;
400 } 233 }
401 return 1; 234#endif
402}
403
404int
405command_archs (object *op, char *params)
406{
407 arch_info (op);
408 return 1; 235 return 1;
409} 236}
410 237
411int 238int
412command_hiscore (object *op, char *params) 239command_hiscore (object *op, char *params)
423 250
424 if (params == NULL || !sscanf (params, "%d", &i)) 251 if (params == NULL || !sscanf (params, "%d", &i))
425 { 252 {
426 sprintf (buf, "Global debug level is %d.", settings.debug); 253 sprintf (buf, "Global debug level is %d.", settings.debug);
427 new_draw_info (NDI_UNIQUE, 0, op, buf); 254 new_draw_info (NDI_UNIQUE, 0, op, buf);
428 return 1;
429 }
430 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
431 {
432 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command.");
433 return 1; 255 return 1;
434 } 256 }
435 settings.debug = (enum LogLevel) FABS (i); 257 settings.debug = (enum LogLevel) FABS (i);
436 sprintf (buf, "Set debug level to %d.", i); 258 sprintf (buf, "Set debug level to %d.", i);
437 new_draw_info (NDI_UNIQUE, 0, op, buf); 259 new_draw_info (NDI_UNIQUE, 0, op, buf);
463 dump_friendly_objects (); 285 dump_friendly_objects ();
464 return 0; 286 return 0;
465} 287}
466 288
467int 289int
468command_dumpmap (object *op, char *params)
469{
470 if (op)
471 dump_map (op->map);
472 return 0;
473}
474
475int
476command_dumpallmaps (object *op, char *params)
477{
478 dump_all_maps ();
479 return 0;
480}
481
482int
483command_printlos (object *op, char *params) 290command_printlos (object *op, char *params)
484{ 291{
485 if (op) 292 if (op)
486 print_los (op); 293 print_los (op);
487 return 0; 294 return 0;
492command_version (object *op, char *params) 299command_version (object *op, char *params)
493{ 300{
494 version (op); 301 version (op);
495 return 0; 302 return 0;
496} 303}
497
498 304
499#ifndef BUG_LOG 305#ifndef BUG_LOG
500# define BUG_LOG "bug_log" 306# define BUG_LOG "bug_log"
501#endif 307#endif
502void 308void
511 } 317 }
512 else 318 else
513 { 319 {
514 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));
515 } 321 }
516}
517
518int
519command_output_sync (object *op, char *params)
520{
521 int val;
522
523 if (!params)
524 {
525 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync);
526 return 1;
527 }
528 val = atoi (params);
529 if (val > 0)
530 {
531 op->contr->outputs_sync = val;
532 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync);
533 }
534 else
535 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync.");
536
537 return 1;
538}
539
540int
541command_output_count (object *op, char *params)
542{
543 int val;
544
545 if (!params)
546 {
547 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count);
548 return 1;
549 }
550 val = atoi (params);
551 if (val > 0)
552 {
553 op->contr->outputs_count = val;
554 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count);
555 }
556 else
557 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
558
559 return 1;
560}
561
562int
563command_listen (object *op, char *params)
564{
565 int i;
566
567 if (params == NULL || !sscanf (params, "%d", &i))
568 {
569 new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening);
570 return 1;
571 }
572 op->contr->listening = (char) i;
573 new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i);
574 return 1;
575} 322}
576 323
577/* Prints out some useful information for the character. Everything we print 324/* Prints out some useful information for the character. Everything we print
578 * 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 -
579 * 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
610 357
611int 358int
612command_fix_me (object *op, char *params) 359command_fix_me (object *op, char *params)
613{ 360{
614 sum_weight (op); 361 sum_weight (op);
615 fix_player (op); 362 op->update_stats ();
616 return 1; 363 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
617}
618 364
619int
620command_players (object *op, char *paramss)
621{
622 char buf[MAX_BUF];
623 char *t;
624 DIR *Dir;
625
626 sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir);
627 t = buf + strlen (buf);
628 if ((Dir = opendir (buf)) != NULL)
629 {
630 const struct dirent *Entry;
631
632 while ((Entry = readdir (Dir)))
633 {
634 /* skip '.' , '..' */
635 if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') ||
636 (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0')))
637 {
638 struct stat Stat;
639
640 strcpy (t, Entry->d_name);
641 if (stat (buf, &Stat) == 0)
642 {
643 /* This was not posix compatible
644 * if ((Stat.st_mode & S_IFMT)==S_IFDIR) {
645 */
646 if (S_ISDIR (Stat.st_mode))
647 {
648 char buf2[MAX_BUF];
649 struct tm *tm = localtime (&Stat.st_mtime);
650
651 sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d",
652 Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
653 new_draw_info (NDI_UNIQUE, 0, op, buf2);
654 }
655 }
656 }
657 }
658 }
659 closedir (Dir);
660 return 0; 365 return 1;
661} 366}
662
663
664 367
665int 368int
666command_logs (object *op, char *params) 369command_logs (object *op, char *params)
667{ 370{
668 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.");
669 372
670 return 1;
671}
672
673int
674command_applymode (object *op, char *params)
675{
676 unapplymode unapply = op->contr->unapply;
677 static const char *const types[] = { "nochoice", "never", "always" };
678
679 if (!params)
680 {
681 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]);
682 return 1;
683 }
684
685 if (!strcmp (params, "nochoice"))
686 op->contr->unapply = unapply_nochoice;
687 else if (!strcmp (params, "never"))
688 op->contr->unapply = unapply_never;
689 else if (!strcmp (params, "always"))
690 op->contr->unapply = unapply_always;
691 else
692 {
693 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
694 return 0;
695 }
696 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
697 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
698 return 1; 373 return 1;
699} 374}
700 375
701int 376int
702command_bowmode (object *op, char *params) 377command_bowmode (object *op, char *params)
722 found++; 397 found++;
723 op->contr->bowtype = (bowtype_t) i; 398 op->contr->bowtype = (bowtype_t) i;
724 break; 399 break;
725 } 400 }
726 } 401 }
402
727 if (!found) 403 if (!found)
728 { 404 {
729 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 405 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
730 for (i = 0; i <= bow_bestarrow; i++) 406 for (i = 0; i <= bow_bestarrow; i++)
731 { 407 {
737 strcat (buf, "."); 413 strcat (buf, ".");
738 } 414 }
739 new_draw_info_format (NDI_UNIQUE, 0, op, buf); 415 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
740 return 0; 416 return 0;
741 } 417 }
418
742 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]);
743 return 1;
744}
745
746int
747command_petmode (object *op, char *params)
748{
749 petmode_t oldtype = op->contr->petmode;
750 static const char *const types[] = { "normal", "sad", "defend", "arena" };
751
752 if (!params)
753 {
754 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]);
755 return 1;
756 }
757
758 if (!strcmp (params, "normal"))
759 op->contr->petmode = pet_normal;
760 else if (!strcmp (params, "sad"))
761 op->contr->petmode = pet_sad;
762 else if (!strcmp (params, "defend"))
763 op->contr->petmode = pet_defend;
764 else if (!strcmp (params, "arena"))
765 op->contr->petmode = pet_arena;
766 else
767 {
768 new_draw_info_format (NDI_UNIQUE, 0, op,
769 "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params);
770 return 0;
771 }
772 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]);
773 return 1; 420 return 1;
774} 421}
775 422
776int 423int
777command_showpets (object *op, char *params) 424command_showpets (object *op, char *params)
818 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 465 new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
819 return 0; 466 return 0;
820} 467}
821 468
822int 469int
823command_usekeys (object *op, char *params)
824{
825 usekeytype oldtype = op->contr->usekeys;
826 static const char *const types[] = { "inventory", "keyrings", "containers" };
827
828 if (!params)
829 {
830 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]);
831 return 1;
832 }
833
834 if (!strcmp (params, "inventory"))
835 op->contr->usekeys = key_inventory;
836 else if (!strcmp (params, "keyrings"))
837 op->contr->usekeys = keyrings;
838 else if (!strcmp (params, "containers"))
839 op->contr->usekeys = containers;
840 else
841 {
842 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params);
843 return 0;
844 }
845 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]);
846 return 1;
847}
848
849int
850command_resistances (object *op, char *params) 470command_resistances (object *op, char *params)
851{ 471{
852 int i; 472 int i;
853 473
854 if (!op) 474 if (!op)
890 510
891/* 511/*
892 * Actual commands. 512 * Actual commands.
893 * 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,...)
894 */ 514 */
895
896
897static void
898help_topics (object *op, int what)
899{
900 DIR *dirp;
901 struct dirent *de;
902 char filename[MAX_BUF], line[80];
903 int namelen, linelen = 0;
904
905 switch (what)
906 {
907 case 1:
908 sprintf (filename, "%s/wizhelp", settings.datadir);
909 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
910 break;
911 case 3:
912 sprintf (filename, "%s/mischelp", settings.datadir);
913 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
914 break;
915 default:
916 sprintf (filename, "%s/help", settings.datadir);
917 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
918 break;
919 }
920
921 if (!(dirp = opendir (filename)))
922 return;
923
924 line[0] = '\0';
925 while (de = readdir (dirp))
926 {
927 namelen = strlen (de->d_name);
928 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
929 continue;
930 linelen += namelen + 1;
931 if (linelen > 42)
932 {
933 new_draw_info (NDI_UNIQUE, 0, op, line);
934 sprintf (line, " %s", de->d_name);
935 linelen = namelen + 1;
936 continue;
937 }
938 strcat (line, " ");
939 strcat (line, de->d_name);
940 }
941 new_draw_info (NDI_UNIQUE, 0, op, line);
942 closedir (dirp);
943}
944
945static void
946show_commands (object *op, int what)
947{
948 char line[80];
949 int i, size, namelen, linelen = 0;
950 CommArray_s *ap;
951 extern CommArray_s Commands[], WizCommands[];
952 extern const int CommandsSize, WizCommandsSize;
953
954 switch (what)
955 {
956 case 1:
957 ap = WizCommands;
958 size = WizCommandsSize;
959 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
960 break;
961 case 2:
962 ap = CommunicationCommands;
963 size = CommunicationCommandSize;
964 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
965 break;
966 default:
967 ap = Commands;
968 size = CommandsSize;
969 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
970 break;
971 }
972
973 line[0] = '\0';
974 for (i = 0; i < size; i++)
975 {
976 namelen = strlen (ap[i].name);
977 linelen += namelen + 1;
978 if (linelen > 42)
979 {
980 new_draw_info (NDI_UNIQUE, 0, op, line);
981 sprintf (line, " %s", ap[i].name);
982 linelen = namelen + 1;
983 continue;
984 }
985 strcat (line, " ");
986 strcat (line, ap[i].name);
987 }
988 new_draw_info (NDI_UNIQUE, 0, op, line);
989}
990
991
992int
993command_help (object *op, char *params)
994{
995 struct stat st;
996 FILE *fp;
997 char filename[MAX_BUF], line[MAX_BUF];
998 int len;
999
1000 if (op != NULL)
1001 clear_win_info (op);
1002
1003/*
1004 * Main help page?
1005 */
1006 if (!params)
1007 {
1008 sprintf (filename, "%s/def_help", settings.datadir);
1009 if ((fp = fopen (filename, "r")) == NULL)
1010 {
1011 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1012 return 0;
1013 }
1014 while (fgets (line, MAX_BUF, fp))
1015 {
1016 line[MAX_BUF - 1] = '\0';
1017 len = strlen (line) - 1;
1018 if (line[len] == '\n')
1019 line[len] = '\0';
1020 new_draw_info (NDI_UNIQUE, 0, op, line);
1021 }
1022 fclose (fp);
1023 return 0;
1024 }
1025
1026 /*
1027 * Topics list
1028 */
1029 if (!strcmp (params, "topics"))
1030 {
1031 help_topics (op, 3);
1032 help_topics (op, 0);
1033 if (QUERY_FLAG (op, FLAG_WIZ))
1034 help_topics (op, 1);
1035 return 0;
1036 }
1037
1038 /*
1039 * Commands list
1040 */
1041 if (!strcmp (params, "commands"))
1042 {
1043 show_commands (op, 0);
1044 show_commands (op, 2); /* show comm commands */
1045 if (QUERY_FLAG (op, FLAG_WIZ))
1046 show_commands (op, 1);
1047 return 0;
1048 }
1049
1050 /*
1051 * User wants info about command
1052 */
1053 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
1054 {
1055 sprintf (line, "Illegal characters in '%s'", params);
1056 new_draw_info (NDI_UNIQUE, 0, op, line);
1057 return 0;
1058 }
1059
1060 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
1061 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1062 {
1063 if (op)
1064 {
1065 sprintf (filename, "%s/help/%s", settings.datadir, params);
1066 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1067 {
1068 if (QUERY_FLAG (op, FLAG_WIZ))
1069 {
1070 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
1071 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1072 goto nohelp;
1073 }
1074 else
1075 goto nohelp;
1076 }
1077 }
1078 }
1079
1080 /*
1081 * Found that. Just cat it to screen.
1082 */
1083 if ((fp = fopen (filename, "r")) == NULL)
1084 {
1085 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1086 return 0;
1087 }
1088 sprintf (line, "Help about '%s'", params);
1089 new_draw_info (NDI_UNIQUE, 0, op, line);
1090 while (fgets (line, MAX_BUF, fp))
1091 {
1092 line[MAX_BUF - 1] = '\0';
1093 len = strlen (line) - 1;
1094 if (line[len] == '\n')
1095 line[len] = '\0';
1096 new_draw_info (NDI_UNIQUE, 0, op, line);
1097 }
1098 fclose (fp);
1099 return 0;
1100
1101 /*
1102 * No_help -escape
1103 */
1104nohelp:
1105 sprintf (line, "No help available on '%s'", params);
1106 new_draw_info (NDI_UNIQUE, 0, op, line);
1107 return 0;
1108}
1109
1110 515
1111int 516int
1112onoff_value (const char *line) 517onoff_value (const char *line)
1113{ 518{
1114 int i; 519 int i;
1137 return 0; 542 return 0;
1138 } 543 }
1139} 544}
1140 545
1141int 546int
1142command_quit (object *op, char *params)
1143{
1144 new_draw_info (NDI_UNIQUE, 0, op,
1145 "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit.");
1146 return 1;
1147}
1148
1149int
1150command_real_quit (object *op, char *params)
1151{
1152 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):");
1153
1154 op->contr->state = ST_CONFIRM_QUIT;
1155 return 1;
1156}
1157
1158/*
1159 * don't allow people to exit explore mode. It otherwise becomes
1160 * really easy to abuse this.
1161 */
1162int
1163command_explore (object *op, char *params)
1164{
1165 if (settings.explore_mode == FALSE)
1166 return 1;
1167 /*
1168 * I guess this is the best way to see if we are solo or not. Actually,
1169 * are there any cases when first_player->next==NULL and we are not solo?
1170 */
1171 if ((first_player != op->contr) || (first_player->next != NULL))
1172 {
1173 new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party");
1174 }
1175 else if (op->contr->explore)
1176 new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode");
1177 else
1178 {
1179 op->contr->explore = 1;
1180 new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode");
1181 }
1182 return 1;
1183}
1184
1185int
1186command_sound (object *op, char *params)
1187{
1188 if (op->contr->socket->sound)
1189 {
1190 op->contr->socket->sound = 0;
1191 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
1192 }
1193 else
1194 {
1195 op->contr->socket->sound = 1;
1196 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1197 }
1198
1199 return 1;
1200}
1201
1202/* Perhaps these should be in player.c, but that file is
1203 * already a bit big.
1204 */
1205
1206void
1207receive_player_name (object *op, char k)
1208{
1209
1210 if (!check_name (op->contr, op->contr->write_buf + 1))
1211 {
1212 get_name (op);
1213 return;
1214 }
1215 op->name = op->contr->write_buf + 1;
1216 op->name_pl = op->contr->write_buf + 1;
1217 new_draw_info (NDI_UNIQUE, 0, op, op->contr->write_buf);
1218 op->contr->name_changed = 1;
1219 get_password (op);
1220}
1221
1222void
1223receive_player_password (object *op, char k)
1224{
1225
1226 unsigned int pwd_len = strlen (op->contr->write_buf);
1227
1228 if (pwd_len <= 1 || pwd_len > 17)
1229 {
1230 get_name (op);
1231 return;
1232 }
1233 new_draw_info (NDI_UNIQUE, 0, op, " "); /* To hide the password better */
1234
1235 if (checkbanned (op->name, op->contr->socket->host))
1236 {
1237 LOG (llevInfo, "Banned player tried to add: [%s@%s]\n", &op->name, op->contr->socket->host);
1238 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, "You are not allowed to play.");
1239 get_name (op);
1240 return;
1241 }
1242
1243 if (op->contr->state == ST_CONFIRM_PASSWORD)
1244 {
1245 if (!check_password (op->contr->write_buf + 1, op->contr->password))
1246 {
1247 new_draw_info (NDI_UNIQUE, 0, op, "The passwords did not match.");
1248 get_name (op);
1249 return;
1250 }
1251 clear_win_info (op);
1252 display_motd (op);
1253 new_draw_info (NDI_UNIQUE, 0, op, " ");
1254 new_draw_info (NDI_UNIQUE, 0, op, "Welcome, Brave New Warrior!");
1255 new_draw_info (NDI_UNIQUE, 0, op, " ");
1256 Roll_Again (op);
1257 op->contr->state = ST_ROLL_STAT;
1258 return;
1259 }
1260 strcpy (op->contr->password, crypt_string (op->contr->write_buf + 1, NULL));
1261 op->contr->state = ST_ROLL_STAT;
1262 check_login (op);
1263 return;
1264}
1265
1266
1267int
1268explore_mode (void)
1269{
1270 player *pl;
1271
1272 if (settings.explore_mode == TRUE)
1273 {
1274 for (pl = first_player; pl != (player *) NULL; pl = pl->next)
1275 if (pl->explore)
1276 return 1;
1277 }
1278 return 0;
1279}
1280
1281
1282int
1283command_title (object *op, char *params) 547command_title (object *op, char *params)
1284{ 548{
1285 char buf[MAX_BUF]; 549 char buf[MAX_BUF];
1286 550
1287 if (settings.set_title == FALSE) 551 if (settings.set_title == FALSE)
1324 strcpy (op->contr->own_title, params); 588 strcpy (op->contr->own_title, params);
1325 return 1; 589 return 1;
1326} 590}
1327 591
1328int 592int
1329command_save (object *op, char *params)
1330{
1331// if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_CLERIC) {
1332// new_draw_info(NDI_UNIQUE, 0, op, "You can not save on unholy ground");
1333// } else
1334 if (!op->stats.exp)
1335 {
1336 new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet.");
1337 }
1338 else
1339 {
1340 if (save_player (op, 1))
1341 new_draw_info (NDI_UNIQUE, 0, op, "You have been saved.");
1342 else
1343 new_draw_info (NDI_UNIQUE, 0, op, "SAVE FAILED!");
1344 }
1345 return 1;
1346}
1347
1348
1349int
1350command_peaceful (object *op, char *params)
1351{
1352 new_draw_info (NDI_UNIQUE, 0, op,
1353 "You cannot change your peaceful setting with this command."
1354 " Please speak to the priest in the temple of Gorokh"
1355 " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again.");
1356
1357/*
1358 if((op->contr->peaceful=!op->contr->peaceful))
1359 new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players.");
1360 else
1361 new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players.");
1362*/
1363 return 1;
1364}
1365
1366
1367
1368int
1369command_wimpy (object *op, char *params)
1370{
1371 int i;
1372 char buf[MAX_BUF];
1373
1374 if (params == NULL || !sscanf (params, "%d", &i))
1375 {
1376 sprintf (buf, "Your current wimpy level is %d.", op->run_away);
1377 new_draw_info (NDI_UNIQUE, 0, op, buf);
1378 return 1;
1379 }
1380 sprintf (buf, "Your new wimpy level is %d.", i);
1381 new_draw_info (NDI_UNIQUE, 0, op, buf);
1382 op->run_away = i;
1383 return 1;
1384}
1385
1386
1387int
1388command_brace (object *op, char *params)
1389{
1390 if (!params)
1391 op->contr->braced = !op->contr->braced;
1392 else
1393 op->contr->braced = onoff_value (params);
1394
1395 if (op->contr->braced)
1396 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1397 else
1398 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1399
1400 fix_player (op);
1401 return 0;
1402}
1403
1404int
1405command_style_map_info (object *op, char *params)
1406{
1407 extern maptile *styles;
1408 maptile *mp;
1409 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
1410 object *tmp;
1411
1412 for (mp = styles; mp != NULL; mp = mp->next)
1413 {
1414 maps_used++;
1415 mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile);
1416 for (x = 0; x < MAP_WIDTH (mp); x++)
1417 {
1418 for (y = 0; y < MAP_HEIGHT (mp); y++)
1419 {
1420 for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above)
1421 objects_used++;
1422 }
1423 }
1424 }
1425 new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used);
1426 new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not");
1427 new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem);
1428 new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used);
1429 new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object));
1430 return 0;
1431}
1432
1433int
1434command_kill_pets (object *op, char *params) 593command_kill_pets (object *op, char *params)
1435{ 594{
1436 objectlink *obl, *next; 595 objectlink *obl, *next;
1437 int counter = 0, removecount = 0; 596 int counter = 0, removecount = 0;
1438 597
1439 if (params == NULL) 598 if (!params)
1440 { 599 {
1441 terminate_all_pets (op); 600 terminate_all_pets (op);
1442 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.");
1443 } 602 }
1444 else 603 else
1445 { 604 {
1446 int target = atoi (params); 605 int target = atoi (params);
1447 606
1448 for (obl = first_friendly_object; obl != NULL; obl = next) 607 for (obl = first_friendly_object; obl; obl = next)
1449 { 608 {
1450 object *ob = obl->ob; 609 object *ob = obl->ob;
1451 610
1452 next = obl->next; 611 next = obl->next;
612
1453 if (ob->owner == op) 613 if (ob->owner == op)
1454 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 614 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1455 { 615 {
1456 ob->destroy (); 616 ob->destroy ();
1457 removecount++; 617 removecount++;
1458 } 618 }
1459 } 619 }
620
1460 if (removecount != 0) 621 if (removecount != 0)
1461 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);
1462 else 623 else
1463 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");
1464 } 625 }
626
1465 return 0; 627 return 0;
1466} 628}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines