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.11 by root, Fri Sep 29 19:28:43 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#ifndef __CEXTRACT__
27# include <sproto.h> 27#include <sproto.h>
28#endif
29 28
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 = seconds ();
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
228/*local functon for qsort comparison*/
229static int
230name_cmp (const chars_names * c1, const chars_names * c2)
231{
232 return strcasecmp (c1->namebuf, c2->namebuf);
233}
234
235int
236command_afk (object *op, char *params)
237{
238 if QUERY_FLAG
239 (op, FLAG_AFK)
240 {
241 CLEAR_FLAG (op, FLAG_AFK);
242 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK");
243 }
244 else
245 {
246 SET_FLAG (op, FLAG_AFK);
247 new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK");
248 }
249 return 1;
250}
251
252int
253command_mapinfo (object *op, char *params)
254{
255 current_map_info (op);
256 return 1;
257}
258
259int
260command_whereami (object *op, char *params)
261{
262 current_region_info (op);
263 return 1;
264}
265
266int
267command_maps (object *op, char *params)
268{
269 map_info (op, params);
270 return 1;
271}
272
273int 98int
274command_time (object *op, char *params) 99command_time (object *op, char *params)
275{ 100{
276 print_tod (op); 101 print_tod (op);
277 return 1; 102 return 1;
278} 103}
279 104
280int 105int
281command_weather (object *op, char *params) 106command_weather (object *op, char *params)
282{ 107{
108#if 0
283 int wx, wy, temp, sky; 109 int wx, wy, temp, sky;
284 char buf[MAX_BUF]; 110 char buf[MAX_BUF];
285 111
286 if (settings.dynamiclevel < 1) 112 if (settings.dynamiclevel < 1)
287 return 1; 113 return 1;
403 break; 229 break;
404 case SKY_BLIZZARD: 230 case SKY_BLIZZARD:
405 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!");
406 break; 232 break;
407 } 233 }
408 return 1; 234#endif
409}
410
411int
412command_archs (object *op, char *params)
413{
414 arch_info (op);
415 return 1; 235 return 1;
416} 236}
417 237
418int 238int
419command_hiscore (object *op, char *params) 239command_hiscore (object *op, char *params)
432 { 252 {
433 sprintf (buf, "Global debug level is %d.", settings.debug); 253 sprintf (buf, "Global debug level is %d.", settings.debug);
434 new_draw_info (NDI_UNIQUE, 0, op, buf); 254 new_draw_info (NDI_UNIQUE, 0, op, buf);
435 return 1; 255 return 1;
436 } 256 }
437 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
438 {
439 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command.");
440 return 1;
441 }
442 settings.debug = (enum LogLevel) FABS (i); 257 settings.debug = (enum LogLevel) FABS (i);
443 sprintf (buf, "Set debug level to %d.", i); 258 sprintf (buf, "Set debug level to %d.", i);
444 new_draw_info (NDI_UNIQUE, 0, op, buf); 259 new_draw_info (NDI_UNIQUE, 0, op, buf);
445 return 1; 260 return 1;
446} 261}
453int 268int
454command_dumpbelow (object *op, char *params) 269command_dumpbelow (object *op, char *params)
455{ 270{
456 if (op && op->below) 271 if (op && op->below)
457 { 272 {
458 dump_object (op->below); 273 char *dump = dump_object (op->below);
459 new_draw_info (NDI_UNIQUE, 0, op, errmsg); 274 new_draw_info (NDI_UNIQUE, 0, op, dump);
275 free (dump);
460 /* Let's push that item on the dm's stack */ 276 /* Let's push that item on the dm's stack */
461 dm_stack_push (op->contr, op->below->count); 277 dm_stack_push (op->contr, op->below->count);
462 } 278 }
463 return 0; 279 return 0;
464} 280}
465 281
466int 282int
467command_wizpass (object *op, char *params)
468{
469 int i;
470
471 if (!op)
472 return 0;
473
474 if (!params)
475 i = (QUERY_FLAG (op, FLAG_WIZPASS)) ? 0 : 1;
476 else
477 i = onoff_value (params);
478
479 if (i)
480 {
481 new_draw_info (NDI_UNIQUE, 0, op, "You will now walk through walls.\n");
482 SET_FLAG (op, FLAG_WIZPASS);
483 }
484 else
485 {
486 new_draw_info (NDI_UNIQUE, 0, op, "You will now be stopped by walls.\n");
487 CLEAR_FLAG (op, FLAG_WIZPASS);
488 }
489 return 0;
490}
491
492int
493command_wizcast (object *op, char *params)
494{
495 int i;
496
497 if (!op)
498 return 0;
499
500 if (!params)
501 i = (QUERY_FLAG (op, FLAG_WIZCAST)) ? 0 : 1;
502 else
503 i = onoff_value (params);
504
505 if (i)
506 {
507 new_draw_info (NDI_UNIQUE, 0, op, "You can now cast spells anywhere.");
508 SET_FLAG (op, FLAG_WIZCAST);
509 }
510 else
511 {
512 new_draw_info (NDI_UNIQUE, 0, op, "You now cannot cast spells in no-magic areas.");
513 CLEAR_FLAG (op, FLAG_WIZCAST);
514 }
515 return 0;
516}
517
518int
519command_dumpallobjects (object *op, char *params)
520{
521 dump_all_objects ();
522 return 0;
523}
524
525int
526command_dumpfriendlyobjects (object *op, char *params) 283command_dumpfriendlyobjects (object *op, char *params)
527{ 284{
528 dump_friendly_objects (); 285 dump_friendly_objects ();
529 return 0;
530}
531
532int
533command_dumpallarchetypes (object *op, char *params)
534{
535 dump_all_archetypes ();
536 return 0;
537}
538
539int
540command_dumpmap (object *op, char *params)
541{
542 if (op)
543 dump_map (op->map);
544 return 0;
545}
546
547int
548command_dumpallmaps (object *op, char *params)
549{
550 dump_all_maps ();
551 return 0; 286 return 0;
552} 287}
553 288
554int 289int
555command_printlos (object *op, char *params) 290command_printlos (object *op, char *params)
564command_version (object *op, char *params) 299command_version (object *op, char *params)
565{ 300{
566 version (op); 301 version (op);
567 return 0; 302 return 0;
568} 303}
569
570 304
571#ifndef BUG_LOG 305#ifndef BUG_LOG
572# define BUG_LOG "bug_log" 306# define BUG_LOG "bug_log"
573#endif 307#endif
574void 308void
585 { 319 {
586 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));
587 } 321 }
588} 322}
589 323
590int
591command_output_sync (object *op, char *params)
592{
593 int val;
594
595 if (!params)
596 {
597 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync);
598 return 1;
599 }
600 val = atoi (params);
601 if (val > 0)
602 {
603 op->contr->outputs_sync = val;
604 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync);
605 }
606 else
607 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync.");
608
609 return 1;
610}
611
612int
613command_output_count (object *op, char *params)
614{
615 int val;
616
617 if (!params)
618 {
619 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count);
620 return 1;
621 }
622 val = atoi (params);
623 if (val > 0)
624 {
625 op->contr->outputs_count = val;
626 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count);
627 }
628 else
629 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
630
631 return 1;
632}
633
634int
635command_listen (object *op, char *params)
636{
637 int i;
638
639 if (params == NULL || !sscanf (params, "%d", &i))
640 {
641 new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening);
642 return 1;
643 }
644 op->contr->listening = (char) i;
645 new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i);
646 return 1;
647}
648
649/* Prints out some useful information for the character. Everything we print 324/* Prints out some useful information for the character. Everything we print
650 * 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 -
651 * 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
652 * no meaning here. 327 * no meaning here.
653 */ 328 */
654int 329int
655command_statistics (object *pl, char *params) 330command_statistics (object *pl, char *params)
656{ 331{
657 if (!pl->contr) 332 if (!pl->contr)
658 return 1; 333 return 1;
659#ifndef WIN32
660 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %lld", pl->stats.exp);
661 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %lld", level_exp (pl->level + 1, pl->expmul));
662#else
663 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %I64d", pl->stats.exp); 334 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
664 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %I64d", level_exp (pl->level + 1, pl->expmul)); 335 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
665#endif
666 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); 336 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
667 337
668 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 338 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d",
669 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); 339 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str);
670 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", 340 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d",
687 357
688int 358int
689command_fix_me (object *op, char *params) 359command_fix_me (object *op, char *params)
690{ 360{
691 sum_weight (op); 361 sum_weight (op);
692 fix_player (op); 362 op->update_stats ();
693 return 1; 363 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
694}
695 364
696int
697command_players (object *op, char *paramss)
698{
699 char buf[MAX_BUF];
700 char *t;
701 DIR *Dir;
702
703 sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir);
704 t = buf + strlen (buf);
705 if ((Dir = opendir (buf)) != NULL)
706 {
707 const struct dirent *Entry;
708
709 while ((Entry = readdir (Dir)) != NULL)
710 {
711 /* skip '.' , '..' */
712 if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') ||
713 (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0')))
714 {
715 struct stat Stat;
716
717 strcpy (t, Entry->d_name);
718 if (stat (buf, &Stat) == 0)
719 {
720 /* This was not posix compatible
721 * if ((Stat.st_mode & S_IFMT)==S_IFDIR) {
722 */
723 if (S_ISDIR (Stat.st_mode))
724 {
725 char buf2[MAX_BUF];
726 struct tm *tm = localtime (&Stat.st_mtime);
727
728 sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d",
729 Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
730 new_draw_info (NDI_UNIQUE, 0, op, buf2);
731 }
732 }
733 }
734 }
735 }
736 closedir (Dir);
737 return 0; 365 return 1;
738} 366}
739
740
741 367
742int 368int
743command_logs (object *op, char *params) 369command_logs (object *op, char *params)
744{ 370{
745 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.");
746 372
747 return 1;
748}
749
750int
751command_applymode (object *op, char *params)
752{
753 unapplymode unapply = op->contr->unapply;
754 static const char *const types[] = { "nochoice", "never", "always" };
755
756 if (!params)
757 {
758 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]);
759 return 1;
760 }
761
762 if (!strcmp (params, "nochoice"))
763 op->contr->unapply = unapply_nochoice;
764 else if (!strcmp (params, "never"))
765 op->contr->unapply = unapply_never;
766 else if (!strcmp (params, "always"))
767 op->contr->unapply = unapply_always;
768 else
769 {
770 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
771 return 0;
772 }
773 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
774 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
775 return 1; 373 return 1;
776} 374}
777 375
778int 376int
779command_bowmode (object *op, char *params) 377command_bowmode (object *op, char *params)
799 found++; 397 found++;
800 op->contr->bowtype = (bowtype_t) i; 398 op->contr->bowtype = (bowtype_t) i;
801 break; 399 break;
802 } 400 }
803 } 401 }
402
804 if (!found) 403 if (!found)
805 { 404 {
806 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 405 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
807 for (i = 0; i <= bow_bestarrow; i++) 406 for (i = 0; i <= bow_bestarrow; i++)
808 { 407 {
814 strcat (buf, "."); 413 strcat (buf, ".");
815 } 414 }
816 new_draw_info_format (NDI_UNIQUE, 0, op, buf); 415 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
817 return 0; 416 return 0;
818 } 417 }
418
819 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]);
820 return 1;
821}
822
823int
824command_petmode (object *op, char *params)
825{
826 petmode_t oldtype = op->contr->petmode;
827 static const char *const types[] = { "normal", "sad", "defend", "arena" };
828
829 if (!params)
830 {
831 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]);
832 return 1;
833 }
834
835 if (!strcmp (params, "normal"))
836 op->contr->petmode = pet_normal;
837 else if (!strcmp (params, "sad"))
838 op->contr->petmode = pet_sad;
839 else if (!strcmp (params, "defend"))
840 op->contr->petmode = pet_defend;
841 else if (!strcmp (params, "arena"))
842 op->contr->petmode = pet_arena;
843 else
844 {
845 new_draw_info_format (NDI_UNIQUE, 0, op,
846 "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params);
847 return 0;
848 }
849 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]);
850 return 1; 420 return 1;
851} 421}
852 422
853int 423int
854command_showpets (object *op, char *params) 424command_showpets (object *op, char *params)
862 for (obl = first_friendly_object; obl != NULL; obl = next) 432 for (obl = first_friendly_object; obl != NULL; obl = next)
863 { 433 {
864 object *ob = obl->ob; 434 object *ob = obl->ob;
865 435
866 next = obl->next; 436 next = obl->next;
867 if (get_owner (ob) == op) 437 if (ob->owner == op)
868 { 438 {
869 if (target == 0) 439 if (target == 0)
870 { 440 {
871 if (counter == 0) 441 if (counter == 0)
872 new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); 442 new_draw_info (NDI_UNIQUE, 0, op, "Pets:");
895 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 465 new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
896 return 0; 466 return 0;
897} 467}
898 468
899int 469int
900command_usekeys (object *op, char *params)
901{
902 usekeytype oldtype = op->contr->usekeys;
903 static const char *const types[] = { "inventory", "keyrings", "containers" };
904
905 if (!params)
906 {
907 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]);
908 return 1;
909 }
910
911 if (!strcmp (params, "inventory"))
912 op->contr->usekeys = key_inventory;
913 else if (!strcmp (params, "keyrings"))
914 op->contr->usekeys = keyrings;
915 else if (!strcmp (params, "containers"))
916 op->contr->usekeys = containers;
917 else
918 {
919 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params);
920 return 0;
921 }
922 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]);
923 return 1;
924}
925
926int
927command_resistances (object *op, char *params) 470command_resistances (object *op, char *params)
928{ 471{
929 int i; 472 int i;
930 473
931 if (!op) 474 if (!op)
967 510
968/* 511/*
969 * Actual commands. 512 * Actual commands.
970 * 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,...)
971 */ 514 */
972
973
974static void
975help_topics (object *op, int what)
976{
977 DIR *dirp;
978 struct dirent *de;
979 char filename[MAX_BUF], line[80];
980 int namelen, linelen = 0;
981
982 switch (what)
983 {
984 case 1:
985 sprintf (filename, "%s/wizhelp", settings.datadir);
986 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
987 break;
988 case 3:
989 sprintf (filename, "%s/mischelp", settings.datadir);
990 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
991 break;
992 default:
993 sprintf (filename, "%s/help", settings.datadir);
994 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
995 break;
996 }
997 if (!(dirp = opendir (filename)))
998 return;
999
1000 line[0] = '\0';
1001 for (de = readdir (dirp); de; de = readdir (dirp))
1002 {
1003 namelen = NAMLEN (de);
1004 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
1005 continue;
1006 linelen += namelen + 1;
1007 if (linelen > 42)
1008 {
1009 new_draw_info (NDI_UNIQUE, 0, op, line);
1010 sprintf (line, " %s", de->d_name);
1011 linelen = namelen + 1;
1012 continue;
1013 }
1014 strcat (line, " ");
1015 strcat (line, de->d_name);
1016 }
1017 new_draw_info (NDI_UNIQUE, 0, op, line);
1018 closedir (dirp);
1019}
1020
1021static void
1022show_commands (object *op, int what)
1023{
1024 char line[80];
1025 int i, size, namelen, linelen = 0;
1026 CommArray_s *ap;
1027 extern CommArray_s Commands[], WizCommands[];
1028 extern const int CommandsSize, WizCommandsSize;
1029
1030 switch (what)
1031 {
1032 case 1:
1033 ap = WizCommands;
1034 size = WizCommandsSize;
1035 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
1036 break;
1037 case 2:
1038 ap = CommunicationCommands;
1039 size = CommunicationCommandSize;
1040 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
1041 break;
1042 default:
1043 ap = Commands;
1044 size = CommandsSize;
1045 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
1046 break;
1047 }
1048
1049 line[0] = '\0';
1050 for (i = 0; i < size; i++)
1051 {
1052 namelen = strlen (ap[i].name);
1053 linelen += namelen + 1;
1054 if (linelen > 42)
1055 {
1056 new_draw_info (NDI_UNIQUE, 0, op, line);
1057 sprintf (line, " %s", ap[i].name);
1058 linelen = namelen + 1;
1059 continue;
1060 }
1061 strcat (line, " ");
1062 strcat (line, ap[i].name);
1063 }
1064 new_draw_info (NDI_UNIQUE, 0, op, line);
1065}
1066
1067
1068int
1069command_help (object *op, char *params)
1070{
1071 struct stat st;
1072 FILE *fp;
1073 char filename[MAX_BUF], line[MAX_BUF];
1074 int len;
1075
1076 if (op != NULL)
1077 clear_win_info (op);
1078
1079/*
1080 * Main help page?
1081 */
1082 if (!params)
1083 {
1084 sprintf (filename, "%s/def_help", settings.datadir);
1085 if ((fp = fopen (filename, "r")) == NULL)
1086 {
1087 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1088 return 0;
1089 }
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 /*
1103 * Topics list
1104 */
1105 if (!strcmp (params, "topics"))
1106 {
1107 help_topics (op, 3);
1108 help_topics (op, 0);
1109 if (QUERY_FLAG (op, FLAG_WIZ))
1110 help_topics (op, 1);
1111 return 0;
1112 }
1113
1114 /*
1115 * Commands list
1116 */
1117 if (!strcmp (params, "commands"))
1118 {
1119 show_commands (op, 0);
1120 show_commands (op, 2); /* show comm commands */
1121 if (QUERY_FLAG (op, FLAG_WIZ))
1122 show_commands (op, 1);
1123 return 0;
1124 }
1125
1126 /*
1127 * User wants info about command
1128 */
1129 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
1130 {
1131 sprintf (line, "Illegal characters in '%s'", params);
1132 new_draw_info (NDI_UNIQUE, 0, op, line);
1133 return 0;
1134 }
1135
1136 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
1137 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1138 {
1139 if (op)
1140 {
1141 sprintf (filename, "%s/help/%s", settings.datadir, params);
1142 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1143 {
1144 if (QUERY_FLAG (op, FLAG_WIZ))
1145 {
1146 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
1147 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1148 goto nohelp;
1149 }
1150 else
1151 goto nohelp;
1152 }
1153 }
1154 }
1155
1156 /*
1157 * Found that. Just cat it to screen.
1158 */
1159 if ((fp = fopen (filename, "r")) == NULL)
1160 {
1161 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1162 return 0;
1163 }
1164 sprintf (line, "Help about '%s'", params);
1165 new_draw_info (NDI_UNIQUE, 0, op, line);
1166 while (fgets (line, MAX_BUF, fp))
1167 {
1168 line[MAX_BUF - 1] = '\0';
1169 len = strlen (line) - 1;
1170 if (line[len] == '\n')
1171 line[len] = '\0';
1172 new_draw_info (NDI_UNIQUE, 0, op, line);
1173 }
1174 fclose (fp);
1175 return 0;
1176
1177 /*
1178 * No_help -escape
1179 */
1180nohelp:
1181 sprintf (line, "No help available on '%s'", params);
1182 new_draw_info (NDI_UNIQUE, 0, op, line);
1183 return 0;
1184}
1185
1186 515
1187int 516int
1188onoff_value (const char *line) 517onoff_value (const char *line)
1189{ 518{
1190 int i; 519 int i;
1213 return 0; 542 return 0;
1214 } 543 }
1215} 544}
1216 545
1217int 546int
1218command_quit (object *op, char *params)
1219{
1220 new_draw_info (NDI_UNIQUE, 0, op,
1221 "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit.");
1222 return 1;
1223}
1224
1225int
1226command_real_quit (object *op, char *params)
1227{
1228 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):");
1229
1230 op->contr->state = ST_CONFIRM_QUIT;
1231 return 1;
1232}
1233
1234/*
1235 * don't allow people to exit explore mode. It otherwise becomes
1236 * really easy to abuse this.
1237 */
1238int
1239command_explore (object *op, char *params)
1240{
1241 if (settings.explore_mode == FALSE)
1242 return 1;
1243 /*
1244 * I guess this is the best way to see if we are solo or not. Actually,
1245 * are there any cases when first_player->next==NULL and we are not solo?
1246 */
1247 if ((first_player != op->contr) || (first_player->next != NULL))
1248 {
1249 new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party");
1250 }
1251 else if (op->contr->explore)
1252 new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode");
1253 else
1254 {
1255 op->contr->explore = 1;
1256 new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode");
1257 }
1258 return 1;
1259}
1260
1261int
1262command_sound (object *op, char *params)
1263{
1264 if (op->contr->socket.sound)
1265 {
1266 op->contr->socket.sound = 0;
1267 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
1268 }
1269 else
1270 {
1271 op->contr->socket.sound = 1;
1272 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1273 }
1274 return 1;
1275}
1276
1277/* Perhaps these should be in player.c, but that file is
1278 * already a bit big.
1279 */
1280
1281void
1282receive_player_name (object *op, char k)
1283{
1284
1285 if (!check_name (op->contr, op->contr->write_buf + 1))
1286 {
1287 get_name (op);
1288 return;
1289 }
1290 op->name = op->contr->write_buf + 1;
1291 op->name_pl = op->contr->write_buf + 1;
1292 new_draw_info (NDI_UNIQUE, 0, op, op->contr->write_buf);
1293 op->contr->name_changed = 1;
1294 get_password (op);
1295}
1296
1297void
1298receive_player_password (object *op, char k)
1299{
1300
1301 unsigned int pwd_len = strlen (op->contr->write_buf);
1302
1303 if (pwd_len <= 1 || pwd_len > 17)
1304 {
1305 get_name (op);
1306 return;
1307 }
1308 new_draw_info (NDI_UNIQUE, 0, op, " "); /* To hide the password better */
1309
1310 if (checkbanned (op->name, op->contr->socket.host))
1311 {
1312 LOG (llevInfo, "Banned player tried to add: [%s@%s]\n", &op->name, op->contr->socket.host);
1313 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, "You are not allowed to play.");
1314 get_name (op);
1315 return;
1316 }
1317
1318 if (op->contr->state == ST_CONFIRM_PASSWORD)
1319 {
1320 if (!check_password (op->contr->write_buf + 1, op->contr->password))
1321 {
1322 new_draw_info (NDI_UNIQUE, 0, op, "The passwords did not match.");
1323 get_name (op);
1324 return;
1325 }
1326 clear_win_info (op);
1327 display_motd (op);
1328 new_draw_info (NDI_UNIQUE, 0, op, " ");
1329 new_draw_info (NDI_UNIQUE, 0, op, "Welcome, Brave New Warrior!");
1330 new_draw_info (NDI_UNIQUE, 0, op, " ");
1331 Roll_Again (op);
1332 op->contr->state = ST_ROLL_STAT;
1333 return;
1334 }
1335 strcpy (op->contr->password, crypt_string (op->contr->write_buf + 1, NULL));
1336 op->contr->state = ST_ROLL_STAT;
1337 check_login (op);
1338 return;
1339}
1340
1341
1342int
1343explore_mode (void)
1344{
1345 player *pl;
1346
1347 if (settings.explore_mode == TRUE)
1348 {
1349 for (pl = first_player; pl != (player *) NULL; pl = pl->next)
1350 if (pl->explore)
1351 return 1;
1352 }
1353 return 0;
1354}
1355
1356
1357int
1358command_title (object *op, char *params) 547command_title (object *op, char *params)
1359{ 548{
1360 char buf[MAX_BUF]; 549 char buf[MAX_BUF];
1361 550
1362 if (settings.set_title == FALSE) 551 if (settings.set_title == FALSE)
1399 strcpy (op->contr->own_title, params); 588 strcpy (op->contr->own_title, params);
1400 return 1; 589 return 1;
1401} 590}
1402 591
1403int 592int
1404command_save (object *op, char *params)
1405{
1406// if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_CLERIC) {
1407// new_draw_info(NDI_UNIQUE, 0, op, "You can not save on unholy ground");
1408// } else
1409 if (!op->stats.exp)
1410 {
1411 new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet.");
1412 }
1413 else
1414 {
1415 if (save_player (op, 1))
1416 new_draw_info (NDI_UNIQUE, 0, op, "You have been saved.");
1417 else
1418 new_draw_info (NDI_UNIQUE, 0, op, "SAVE FAILED!");
1419 }
1420 return 1;
1421}
1422
1423
1424int
1425command_peaceful (object *op, char *params)
1426{
1427 new_draw_info (NDI_UNIQUE, 0, op,
1428 "You cannot change your peaceful setting with this command."
1429 " Please speak to the priest in the temple of Gorokh"
1430 " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again.");
1431
1432/*
1433 if((op->contr->peaceful=!op->contr->peaceful))
1434 new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players.");
1435 else
1436 new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players.");
1437*/
1438 return 1;
1439}
1440
1441
1442
1443int
1444command_wimpy (object *op, char *params)
1445{
1446 int i;
1447 char buf[MAX_BUF];
1448
1449 if (params == NULL || !sscanf (params, "%d", &i))
1450 {
1451 sprintf (buf, "Your current wimpy level is %d.", op->run_away);
1452 new_draw_info (NDI_UNIQUE, 0, op, buf);
1453 return 1;
1454 }
1455 sprintf (buf, "Your new wimpy level is %d.", i);
1456 new_draw_info (NDI_UNIQUE, 0, op, buf);
1457 op->run_away = i;
1458 return 1;
1459}
1460
1461
1462int
1463command_brace (object *op, char *params)
1464{
1465 if (!params)
1466 op->contr->braced = !op->contr->braced;
1467 else
1468 op->contr->braced = onoff_value (params);
1469
1470 if (op->contr->braced)
1471 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1472 else
1473 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1474
1475 fix_player (op);
1476 return 0;
1477}
1478
1479int
1480command_style_map_info (object *op, char *params)
1481{
1482 extern maptile *styles;
1483 maptile *mp;
1484 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
1485 object *tmp;
1486
1487 for (mp = styles; mp != NULL; mp = mp->next)
1488 {
1489 maps_used++;
1490 mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile);
1491 for (x = 0; x < MAP_WIDTH (mp); x++)
1492 {
1493 for (y = 0; y < MAP_HEIGHT (mp); y++)
1494 {
1495 for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above)
1496 objects_used++;
1497 }
1498 }
1499 }
1500 new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used);
1501 new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not");
1502 new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem);
1503 new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used);
1504 new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object));
1505 return 0;
1506}
1507
1508int
1509command_kill_pets (object *op, char *params) 593command_kill_pets (object *op, char *params)
1510{ 594{
1511 objectlink *obl, *next; 595 objectlink *obl, *next;
1512 int counter = 0, removecount = 0; 596 int counter = 0, removecount = 0;
1513 597
1514 if (params == NULL) 598 if (!params)
1515 { 599 {
1516 terminate_all_pets (op); 600 terminate_all_pets (op);
1517 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.");
1518 } 602 }
1519 else 603 else
1520 { 604 {
1521 int target = atoi (params); 605 int target = atoi (params);
1522 606
1523 for (obl = first_friendly_object; obl != NULL; obl = next) 607 for (obl = first_friendly_object; obl; obl = next)
1524 { 608 {
1525 object *ob = obl->ob; 609 object *ob = obl->ob;
1526 610
1527 next = obl->next; 611 next = obl->next;
612
1528 if (get_owner (ob) == op) 613 if (ob->owner == op)
1529 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 614 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1530 { 615 {
1531 if (!QUERY_FLAG (ob, FLAG_REMOVED))
1532 remove_ob (ob);
1533 remove_friendly_object (ob);
1534 free_object (ob); 616 ob->destroy ();
1535 removecount++; 617 removecount++;
1536 } 618 }
1537 } 619 }
620
1538 if (removecount != 0) 621 if (removecount != 0)
1539 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);
1540 else 623 else
1541 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");
1542 } 625 }
626
1543 return 0; 627 return 0;
1544} 628}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines