ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.11
Committed: Fri Sep 29 19:28:43 2006 UTC (17 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.10: +0 -190 lines
Log Message:
remove who command

File Contents

# Content
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen
6
7 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 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 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 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22 */
23
24 #include <global.h>
25 #include <loader.h>
26 #ifndef __CEXTRACT__
27 # include <sproto.h>
28 #endif
29
30 extern weathermap_t **weathermap;
31
32 /* Handles misc. input request - things like hash table, malloc, maps,
33 * who, etc.
34 */
35
36 void
37 map_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 */
67 int
68 command_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
97 int
98 command_motd (object *op, char *params)
99 {
100 display_motd (op);
101 return 1;
102 }
103
104 int
105 command_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 */
130 void
131 current_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
146 void
147 current_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
168 int
169 command_malloc_verify (object *op, char *parms)
170 {
171 extern int malloc_verify (void);
172
173 if (!malloc_verify ())
174 new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted.");
175 else
176 new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK.");
177 return 1;
178 }
179 #endif
180
181 int
182 command_whereabouts (object *op, char *params)
183 {
184
185 region *reg;
186 player *pl;
187
188 /*
189 * reset the counter on the region, then use it to store the number of
190 * players there.
191 * I don't know how thread-safe this would be, I suspect not very....
192 */
193 for (reg = first_region; reg != NULL; reg = reg->next)
194 {
195 reg->counter = 0;
196 }
197 for (pl = first_player; pl != NULL; pl = pl->next)
198 if (pl->ob->map != NULL)
199 get_region_by_map (pl->ob->map)->counter++;
200
201 /* we only want to print out by places with a 'longname' field... */
202 for (reg = first_region; reg != NULL; reg = reg->next)
203 {
204 if (reg->longname == NULL && reg->counter > 0)
205 {
206 if (reg->parent != NULL)
207 {
208 reg->parent->counter += reg->counter;
209 reg->counter = 0;
210 }
211 else /*uh oh, we shouldn't be here. */
212 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name);
213 }
214 }
215 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:");
216 for (reg = first_region; reg != NULL; reg = reg->next)
217 if (reg->counter > 0)
218 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg));
219 return 1;
220 }
221
222 typedef struct
223 {
224 char namebuf[MAX_BUF];
225 int login_order;
226 } chars_names;
227
228 /*local functon for qsort comparison*/
229 static int
230 name_cmp (const chars_names * c1, const chars_names * c2)
231 {
232 return strcasecmp (c1->namebuf, c2->namebuf);
233 }
234
235 int
236 command_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
252 int
253 command_mapinfo (object *op, char *params)
254 {
255 current_map_info (op);
256 return 1;
257 }
258
259 int
260 command_whereami (object *op, char *params)
261 {
262 current_region_info (op);
263 return 1;
264 }
265
266 int
267 command_maps (object *op, char *params)
268 {
269 map_info (op, params);
270 return 1;
271 }
272
273 int
274 command_time (object *op, char *params)
275 {
276 print_tod (op);
277 return 1;
278 }
279
280 int
281 command_weather (object *op, char *params)
282 {
283 int wx, wy, temp, sky;
284 char buf[MAX_BUF];
285
286 if (settings.dynamiclevel < 1)
287 return 1;
288
289 if (op->map == NULL)
290 return 1;
291
292 if (worldmap_to_weathermap (op->x, op->y, &wx, &wy, op->map) != 0)
293 return 1;
294
295 if (QUERY_FLAG (op, FLAG_WIZ))
296 {
297 /* dump the weather, Dm style! Yo! */
298 new_draw_info_format (NDI_UNIQUE, 0, op, "Real temp: %d", real_world_temperature (op->x, op->y, op->map));
299 new_draw_info_format (NDI_UNIQUE, 0, op, "Base temp: %d", weathermap[wx][wy].temp);
300 new_draw_info_format (NDI_UNIQUE, 0, op, "Humid: %d", weathermap[wx][wy].humid);
301 new_draw_info_format (NDI_UNIQUE, 0, op, "Wind: dir=%d speed=%d", weathermap[wx][wy].winddir, weathermap[wx][wy].windspeed);
302 new_draw_info_format (NDI_UNIQUE, 0, op, "Pressure: %d", weathermap[wx][wy].pressure);
303 new_draw_info_format (NDI_UNIQUE, 0, op, "Avg Elevation: %d", weathermap[wx][wy].avgelev);
304 new_draw_info_format (NDI_UNIQUE, 0, op, "Rainfall: %d Water: %d", weathermap[wx][wy].rainfall, weathermap[wx][wy].water);
305 }
306
307 temp = real_world_temperature (op->x, op->y, op->map);
308 new_draw_info_format (NDI_UNIQUE, 0, op, "It's currently %d degrees " "Centigrade out.", temp);
309
310 /* humid */
311 if (weathermap[wx][wy].humid < 20)
312 new_draw_info (NDI_UNIQUE, 0, op, "It is very dry.");
313 else if (weathermap[wx][wy].humid < 40)
314 new_draw_info (NDI_UNIQUE, 0, op, "It is very comfortable today.");
315 else if (weathermap[wx][wy].humid < 60)
316 new_draw_info (NDI_UNIQUE, 0, op, "It is a bit muggy.");
317 else if (weathermap[wx][wy].humid < 80)
318 new_draw_info (NDI_UNIQUE, 0, op, "It is muggy.");
319 else
320 new_draw_info (NDI_UNIQUE, 0, op, "It is uncomfortably muggy.");
321
322 /* wind */
323 switch (weathermap[wx][wy].winddir)
324 {
325 case 1:
326 sprintf (buf, "north");
327 break;
328 case 2:
329 sprintf (buf, "northeast");
330 break;
331 case 3:
332 sprintf (buf, "east");
333 break;
334 case 4:
335 sprintf (buf, "southeast");
336 break;
337 case 5:
338 sprintf (buf, "south");
339 break;
340 case 6:
341 sprintf (buf, "southwest");
342 break;
343 case 7:
344 sprintf (buf, "west");
345 break;
346 case 8:
347 sprintf (buf, "northwest");
348 break;
349 }
350 if (weathermap[wx][wy].windspeed < 5)
351 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a mild breeze " "coming from the %s.", buf);
352 else if (weathermap[wx][wy].windspeed < 10)
353 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong breeze " "coming from the %s.", buf);
354 else if (weathermap[wx][wy].windspeed < 15)
355 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a light wind " "coming from the %s.", buf);
356 else if (weathermap[wx][wy].windspeed < 25)
357 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong wind " "coming from the %s.", buf);
358 else if (weathermap[wx][wy].windspeed < 35)
359 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a heavy wind " "coming from the %s.", buf);
360 else
361 new_draw_info_format (NDI_UNIQUE, 0, op, "The wind from the %s is " "incredibly strong!", buf);
362
363 sky = weathermap[wx][wy].sky;
364 if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG)
365 sky += 10; /*let it snow */
366 switch (sky)
367 {
368 case SKY_CLEAR:
369 new_draw_info (NDI_UNIQUE, 0, op, "There isn''t a cloud in the sky.");
370 break;
371 case SKY_LIGHTCLOUD:
372 new_draw_info (NDI_UNIQUE, 0, op, "There are a few light clouds in the sky.");
373 break;
374 case SKY_OVERCAST:
375 new_draw_info (NDI_UNIQUE, 0, op, "The sky is cloudy and dreary.");
376 break;
377 case SKY_LIGHT_RAIN:
378 new_draw_info (NDI_UNIQUE, 0, op, "It is raining softly.");
379 break;
380 case SKY_RAIN:
381 new_draw_info (NDI_UNIQUE, 0, op, "It is raining.");
382 break;
383 case SKY_HEAVY_RAIN:
384 new_draw_info (NDI_UNIQUE, 0, op, "It is raining heavily.");
385 break;
386 case SKY_HURRICANE:
387 new_draw_info (NDI_UNIQUE, 0, op, "There is a heavy storm! You should go inside!");
388 break;
389 case SKY_FOG:
390 new_draw_info (NDI_UNIQUE, 0, op, "It''s foggy and miserable.");
391 break;
392 case SKY_HAIL:
393 new_draw_info (NDI_UNIQUE, 0, op, "It''s hailing out! Take cover!");
394 break;
395 case SKY_LIGHT_SNOW:
396 new_draw_info (NDI_UNIQUE, 0, op, "Snow is gently falling from the sky.");
397 break;
398 case SKY_SNOW:
399 new_draw_info (NDI_UNIQUE, 0, op, "It''s snowing out.");
400 break;
401 case SKY_HEAVY_SNOW:
402 new_draw_info (NDI_UNIQUE, 0, op, "The snow is falling very heavily now.");
403 break;
404 case SKY_BLIZZARD:
405 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!");
406 break;
407 }
408 return 1;
409 }
410
411 int
412 command_archs (object *op, char *params)
413 {
414 arch_info (op);
415 return 1;
416 }
417
418 int
419 command_hiscore (object *op, char *params)
420 {
421 display_high_score (op, op == NULL ? 9999 : 50, params);
422 return 1;
423 }
424
425 int
426 command_debug (object *op, char *params)
427 {
428 int i;
429 char buf[MAX_BUF];
430
431 if (params == NULL || !sscanf (params, "%d", &i))
432 {
433 sprintf (buf, "Global debug level is %d.", settings.debug);
434 new_draw_info (NDI_UNIQUE, 0, op, buf);
435 return 1;
436 }
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);
443 sprintf (buf, "Set debug level to %d.", i);
444 new_draw_info (NDI_UNIQUE, 0, op, buf);
445 return 1;
446 }
447
448
449 /*
450 * Those dumps should be just one dump with good parser
451 */
452
453 int
454 command_dumpbelow (object *op, char *params)
455 {
456 if (op && op->below)
457 {
458 dump_object (op->below);
459 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
460 /* Let's push that item on the dm's stack */
461 dm_stack_push (op->contr, op->below->count);
462 }
463 return 0;
464 }
465
466 int
467 command_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
492 int
493 command_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
518 int
519 command_dumpallobjects (object *op, char *params)
520 {
521 dump_all_objects ();
522 return 0;
523 }
524
525 int
526 command_dumpfriendlyobjects (object *op, char *params)
527 {
528 dump_friendly_objects ();
529 return 0;
530 }
531
532 int
533 command_dumpallarchetypes (object *op, char *params)
534 {
535 dump_all_archetypes ();
536 return 0;
537 }
538
539 int
540 command_dumpmap (object *op, char *params)
541 {
542 if (op)
543 dump_map (op->map);
544 return 0;
545 }
546
547 int
548 command_dumpallmaps (object *op, char *params)
549 {
550 dump_all_maps ();
551 return 0;
552 }
553
554 int
555 command_printlos (object *op, char *params)
556 {
557 if (op)
558 print_los (op);
559 return 0;
560 }
561
562
563 int
564 command_version (object *op, char *params)
565 {
566 version (op);
567 return 0;
568 }
569
570
571 #ifndef BUG_LOG
572 # define BUG_LOG "bug_log"
573 #endif
574 void
575 bug_report (const char *reportstring)
576 {
577 FILE *fp;
578
579 if ((fp = fopen (BUG_LOG, "a")) != NULL)
580 {
581 fprintf (fp, "%s\n", reportstring);
582 fclose (fp);
583 }
584 else
585 {
586 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
587 }
588 }
589
590 int
591 command_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
612 int
613 command_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
634 int
635 command_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
650 * 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
652 * no meaning here.
653 */
654 int
655 command_statistics (object *pl, char *params)
656 {
657 if (!pl->contr)
658 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);
664 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %I64d", level_exp (pl->level + 1, pl->expmul));
665 #endif
666 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
667
668 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);
670 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d",
671 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex);
672 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d",
673 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con);
674 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d",
675 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int);
676 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d",
677 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis);
678 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d",
679 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow);
680 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d",
681 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->clone.stats.Cha);
682 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
683
684 /* Can't think of anything else to print right now */
685 return 0;
686 }
687
688 int
689 command_fix_me (object *op, char *params)
690 {
691 sum_weight (op);
692 fix_player (op);
693 return 1;
694 }
695
696 int
697 command_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;
738 }
739
740
741
742 int
743 command_logs (object *op, char *params)
744 {
745 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
746
747 return 1;
748 }
749
750 int
751 command_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;
776 }
777
778 int
779 command_bowmode (object *op, char *params)
780 {
781 bowtype_t oldtype = op->contr->bowtype;
782 static const char *const types[] = { "normal", "threewide", "spreadshot", "firenorth",
783 "firene", "fireeast", "firese", "firesouth",
784 "firesw", "firewest", "firenw", "bestarrow"
785 };
786 char buf[MAX_BUF];
787 int i, found;
788
789 if (!params)
790 {
791 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode is set to %s", types[op->contr->bowtype]);
792 return 1;
793 }
794
795 for (i = 0, found = 0; i <= bow_bestarrow; i++)
796 {
797 if (!strcmp (params, types[i]))
798 {
799 found++;
800 op->contr->bowtype = (bowtype_t) i;
801 break;
802 }
803 }
804 if (!found)
805 {
806 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
807 for (i = 0; i <= bow_bestarrow; i++)
808 {
809 strcat (buf, " ");
810 strcat (buf, types[i]);
811 if (i < bow_nw)
812 strcat (buf, ",");
813 else
814 strcat (buf, ".");
815 }
816 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
817 return 0;
818 }
819 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
823 int
824 command_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;
851 }
852
853 int
854 command_showpets (object *op, char *params)
855 {
856 objectlink *obl, *next;
857 int counter = 0, target = 0;
858 int have_shown_pet = 0;
859
860 if (params != NULL)
861 target = atoi (params);
862 for (obl = first_friendly_object; obl != NULL; obl = next)
863 {
864 object *ob = obl->ob;
865
866 next = obl->next;
867 if (get_owner (ob) == op)
868 {
869 if (target == 0)
870 {
871 if (counter == 0)
872 new_draw_info (NDI_UNIQUE, 0, op, "Pets:");
873 new_draw_info_format (NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, &ob->name, ob->level);
874 }
875 else if (!have_shown_pet && ++counter == target)
876 {
877 new_draw_info_format (NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name);
878 new_draw_info_format (NDI_UNIQUE, 0, op, "%d/%d HP, %d/%d SP", ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp);
879 /* this is not a nice way to do this, it should be made to be more like the statistics command */
880 new_draw_info_format (NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str);
881 new_draw_info_format (NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex);
882 new_draw_info_format (NDI_UNIQUE, 0, op, "Con %d", ob->stats.Con);
883 new_draw_info_format (NDI_UNIQUE, 0, op, "Int %d", ob->stats.Int);
884 new_draw_info_format (NDI_UNIQUE, 0, op, "Wis %d", ob->stats.Wis);
885 new_draw_info_format (NDI_UNIQUE, 0, op, "Cha %d", ob->stats.Cha);
886 new_draw_info_format (NDI_UNIQUE, 0, op, "Pow %d", ob->stats.Pow);
887 new_draw_info_format (NDI_UNIQUE, 0, op, "wc %d damage %d ac %d ", ob->stats.wc, ob->stats.dam, ob->stats.ac);
888 have_shown_pet = 1;
889 }
890 }
891 }
892 if (counter == 0)
893 new_draw_info (NDI_UNIQUE, 0, op, "you have no pets.");
894 else if (target != 0 && have_shown_pet == 0)
895 new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
896 return 0;
897 }
898
899 int
900 command_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
926 int
927 command_resistances (object *op, char *params)
928 {
929 int i;
930
931 if (!op)
932 return 0;
933
934 for (i = 0; i < NROFATTACKS; i++)
935 {
936 if (i == ATNR_INTERNAL)
937 continue;
938
939 new_draw_info_format (NDI_UNIQUE, 0, op, "%-20s %+5d", attacktype_desc[i], op->resist[i]);
940 }
941
942 /* If dragon player, let's display natural resistances */
943 if (is_dragon_pl (op))
944 {
945 int attack;
946 object *tmp;
947
948 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
949 {
950 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0))
951 {
952 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:");
953 for (attack = 0; attack < NROFATTACKS; attack++)
954 {
955 if (atnr_is_dragon_enabled (attack))
956 {
957 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %d", change_resist_msg[attack], tmp->resist[attack]);
958 }
959 }
960 break;
961 }
962 }
963 }
964
965 return 0;
966 }
967
968 /*
969 * Actual commands.
970 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
971 */
972
973
974 static void
975 help_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
1021 static void
1022 show_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
1068 int
1069 command_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 */
1180 nohelp:
1181 sprintf (line, "No help available on '%s'", params);
1182 new_draw_info (NDI_UNIQUE, 0, op, line);
1183 return 0;
1184 }
1185
1186
1187 int
1188 onoff_value (const char *line)
1189 {
1190 int i;
1191
1192 if (sscanf (line, "%d", &i))
1193 return (i != 0);
1194 switch (line[0])
1195 {
1196 case 'o':
1197 switch (line[1])
1198 {
1199 case 'n':
1200 return 1; /* on */
1201 default:
1202 return 0; /* o[ff] */
1203 }
1204 case 'y': /* y[es] */
1205 case 'k': /* k[ylla] */
1206 case 's':
1207 case 'd':
1208 return 1;
1209 case 'n': /* n[o] */
1210 case 'e': /* e[i] */
1211 case 'u':
1212 default:
1213 return 0;
1214 }
1215 }
1216
1217 int
1218 command_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
1225 int
1226 command_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 */
1238 int
1239 command_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
1261 int
1262 command_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
1281 void
1282 receive_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
1297 void
1298 receive_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
1342 int
1343 explore_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
1357 int
1358 command_title (object *op, char *params)
1359 {
1360 char buf[MAX_BUF];
1361
1362 if (settings.set_title == FALSE)
1363 {
1364 new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title.");
1365 return 1;
1366 }
1367
1368 /* dragon players cannot change titles */
1369 if (is_dragon_pl (op))
1370 {
1371 new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles.");
1372 return 1;
1373 }
1374
1375 if (params == NULL)
1376 {
1377 if (op->contr->own_title[0] == '\0')
1378 sprintf (buf, "Your title is '%s'.", op->contr->title);
1379 else
1380 sprintf (buf, "Your title is '%s'.", op->contr->own_title);
1381 new_draw_info (NDI_UNIQUE, 0, op, buf);
1382 return 1;
1383 }
1384 if (strcmp (params, "clear") == 0 || strcmp (params, "default") == 0)
1385 {
1386 if (op->contr->own_title[0] == '\0')
1387 new_draw_info (NDI_UNIQUE, 0, op, "Your title is the default title.");
1388 else
1389 new_draw_info (NDI_UNIQUE, 0, op, "Title set to default.");
1390 op->contr->own_title[0] = '\0';
1391 return 1;
1392 }
1393
1394 if ((int) strlen (params) >= MAX_NAME)
1395 {
1396 new_draw_info (NDI_UNIQUE, 0, op, "Title too long.");
1397 return 1;
1398 }
1399 strcpy (op->contr->own_title, params);
1400 return 1;
1401 }
1402
1403 int
1404 command_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
1424 int
1425 command_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
1443 int
1444 command_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
1462 int
1463 command_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
1479 int
1480 command_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
1508 int
1509 command_kill_pets (object *op, char *params)
1510 {
1511 objectlink *obl, *next;
1512 int counter = 0, removecount = 0;
1513
1514 if (params == NULL)
1515 {
1516 terminate_all_pets (op);
1517 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
1518 }
1519 else
1520 {
1521 int target = atoi (params);
1522
1523 for (obl = first_friendly_object; obl != NULL; obl = next)
1524 {
1525 object *ob = obl->ob;
1526
1527 next = obl->next;
1528 if (get_owner (ob) == op)
1529 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1530 {
1531 if (!QUERY_FLAG (ob, FLAG_REMOVED))
1532 remove_ob (ob);
1533 remove_friendly_object (ob);
1534 free_object (ob);
1535 removecount++;
1536 }
1537 }
1538 if (removecount != 0)
1539 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
1540 else
1541 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
1542 }
1543 return 0;
1544 }