ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.33
Committed: Sat Dec 30 10:16:11 2006 UTC (17 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.32: +38 -56 lines
Log Message:
preliminary snapshot check-in, DO NOT USE IN PRODUCTION SYSTEMS
See the Changes file for details

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 #include <sproto.h>
27
28 #include <dirent.h>
29
30 /* Handles misc. input request - things like hash table, malloc, maps,
31 * who, etc.
32 */
33
34 //TODO
35 #if 0
36 void
37 map_info (object *op, char *search)
38 {
39 maptile *m;
40 char buf[MAX_BUF], map_path[31];
41 long sec = time (0);
42
43 new_draw_info_format (NDI_UNIQUE, 0, op, "Current time is: %02ld:%02ld:%02ld.", (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
44 new_draw_info (NDI_UNIQUE, 0, op, "Path Pl PlM IM TO Dif Reset");
45
46 for (maps_container::iterator i = maps.begin (); i != maps.end (); ++i)
47 {
48 maptile *m = i->second;
49
50 if (search && !strstr (m->path, search))
51 continue; /* Skip unwanted maps */
52
53 /* Print out the last 30 characters of the map name... */
54 strcpy (map_path, m->path + max (0, (int)strlen (m->path) - 30));
55
56 sprintf (buf, "%-30.30s %2d %2d %1d %4d %2d %02d:%02d:%02d",
57 map_path, m->players, players_on_map (m, FALSE),
58 m->in_memory, m->timeout, m->difficulty,
59 (m->reset_time % 86400) / 3600, (m->reset_time % 3600) / 60, m->reset_time % 60);
60 new_draw_info (NDI_UNIQUE, 0, op, buf);
61 }
62 }
63
64 int
65 command_style_map_info (object *op, char *params)
66 {
67 extern maptile *styles;
68 maptile *mp;
69 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
70 object *tmp;
71
72 for (mp = styles; mp != NULL; mp = mp->next)
73 {
74 maps_used++;
75 mapmem += mp->width * mp->height * (sizeof (object *) + sizeof (mapspace)) + sizeof (maptile);
76 for (x = 0; x < mp->width; x++)
77 {
78 for (y = 0; y < mp->height; y++)
79 {
80 for (tmp = GET_MAP_OB (mp, x, y); tmp != NULL; tmp = tmp->above)
81 objects_used++;
82 }
83 }
84 }
85 new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used);
86 new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not");
87 new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem);
88 new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used);
89 new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object));
90 return 0;
91 }
92 #endif
93
94 /* This command dumps the body information for object *op.
95 * it doesn't care what the params are.
96 * This is mostly meant as a debug command.
97 */
98 int
99 command_body (object *op, char *params)
100 {
101 int i;
102
103 /* Too hard to try and make a header that lines everything up, so just
104 * give a description.
105 */
106 new_draw_info (NDI_UNIQUE, 0, op, "The first column is the name of the body location.");
107 new_draw_info (NDI_UNIQUE, 0, op, "The second column is how many of those locations your body has.");
108 new_draw_info (NDI_UNIQUE, 0, op, "The third column is how many slots in that location are available.");
109 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
110 {
111 /* really debugging - normally body_used should not be set to anything
112 * if body_info isn't also set.
113 */
114 if (op->body_info[i] || op->body_used[i])
115 {
116 new_draw_info_format (NDI_UNIQUE, 0, op, "%-30s %5d %5d", body_locations[i].use_name, op->body_info[i], op->body_used[i]);
117 }
118 }
119 if (!QUERY_FLAG (op, FLAG_USE_ARMOUR))
120 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to wear armor");
121 if (!QUERY_FLAG (op, FLAG_USE_WEAPON))
122 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to use weapons");
123
124 return 1;
125 }
126
127
128 int
129 command_motd (object *op, char *params)
130 {
131 display_motd (op);
132 return 1;
133 }
134
135 int
136 command_bug (object *op, char *params)
137 {
138 char buf[MAX_BUF];
139
140 if (params == NULL)
141 {
142 new_draw_info (NDI_UNIQUE, 0, op, "what bugs?");
143 return 1;
144 }
145 strcpy (buf, op->name);
146 strcat (buf, " bug-reports: ");
147 strncat (buf, ++params, MAX_BUF - strlen (buf));
148 buf[MAX_BUF - 1] = '\0';
149 bug_report (buf);
150 LOG (llevError, "%s\n", buf);
151 new_draw_info (NDI_ALL | NDI_UNIQUE, 1, NULL, buf);
152 new_draw_info (NDI_UNIQUE, 0, op, "OK, thanks!");
153 return 1;
154 }
155
156 /*
157 * Pretty much identical to current map_info, but on a bigger scale
158 * This function returns the name of the players current region, and
159 * a description of it. It is there merely for flavour text.
160 */
161 void
162 current_region_info (object *op)
163 {
164 /*
165 * Ok I /suppose/ I should write a seperate function for this, but it isn't
166 * going to be /that/ slow, and won't get called much
167 */
168 region *r = get_region_by_name (get_name_of_region_for_map (op->map));
169
170 if (!r)
171 return;
172 /* This should only be possible if regions are not operating on this server. */
173
174 new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s. \n %s", get_region_longname (r), get_region_msg (r));
175 }
176
177 void
178 current_map_info (object *op)
179 {
180 maptile *m = op->map;
181
182 if (!m)
183 return;
184
185 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", &m->name, &m->path, get_name_of_region_for_map (m));
186
187 if (QUERY_FLAG (op, FLAG_WIZ))
188 {
189 new_draw_info_format (NDI_UNIQUE, 0, op,
190 "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld",
191 m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout);
192
193 }
194 if (m->msg)
195 new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg);
196 }
197
198 #ifdef DEBUG_MALLOC_LEVEL
199 int
200 command_malloc_verify (object *op, char *parms)
201 {
202 extern int malloc_verify (void);
203
204 if (!malloc_verify ())
205 new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted.");
206 else
207 new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK.");
208 return 1;
209 }
210 #endif
211
212 int
213 command_whereabouts (object *op, char *params)
214 {
215
216 region *reg;
217 player *pl;
218
219 /*
220 * reset the counter on the region, then use it to store the number of
221 * players there.
222 * I don't know how thread-safe this would be, I suspect not very....
223 */
224 for (reg = first_region; reg != NULL; reg = reg->next)
225 {
226 reg->counter = 0;
227 }
228 for_all_players (pl)
229 if (pl->ob->map != NULL)
230 get_region_by_map (pl->ob->map)->counter++;
231
232 /* we only want to print out by places with a 'longname' field... */
233 for (reg = first_region; reg != NULL; reg = reg->next)
234 {
235 if (reg->longname == NULL && reg->counter > 0)
236 {
237 if (reg->parent != NULL)
238 {
239 reg->parent->counter += reg->counter;
240 reg->counter = 0;
241 }
242 else /*uh oh, we shouldn't be here. */
243 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name);
244 }
245 }
246 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:");
247 for (reg = first_region; reg != NULL; reg = reg->next)
248 if (reg->counter > 0)
249 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg));
250 return 1;
251 }
252
253 typedef struct
254 {
255 char namebuf[MAX_BUF];
256 int login_order;
257 } chars_names;
258
259 int
260 command_afk (object *op, char *params)
261 {
262 if ((op->contr->ns->afk = !op->contr->ns->afk))
263 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK");
264 else
265 new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK");
266
267 return 1;
268 }
269
270 int
271 command_mapinfo (object *op, char *params)
272 {
273 current_map_info (op);
274 return 1;
275 }
276
277 int
278 command_whereami (object *op, char *params)
279 {
280 current_region_info (op);
281 return 1;
282 }
283
284 int
285 command_time (object *op, char *params)
286 {
287 print_tod (op);
288 return 1;
289 }
290
291 int
292 command_weather (object *op, char *params)
293 {
294 #if 0
295 int wx, wy, temp, sky;
296 char buf[MAX_BUF];
297
298 if (settings.dynamiclevel < 1)
299 return 1;
300
301 if (op->map == NULL)
302 return 1;
303
304 if (worldmap_to_weathermap (op->x, op->y, &wx, &wy, op->map) != 0)
305 return 1;
306
307 if (QUERY_FLAG (op, FLAG_WIZ))
308 {
309 /* dump the weather, Dm style! Yo! */
310 new_draw_info_format (NDI_UNIQUE, 0, op, "Real temp: %d", real_world_temperature (op->x, op->y, op->map));
311 new_draw_info_format (NDI_UNIQUE, 0, op, "Base temp: %d", weathermap[wx][wy].temp);
312 new_draw_info_format (NDI_UNIQUE, 0, op, "Humid: %d", weathermap[wx][wy].humid);
313 new_draw_info_format (NDI_UNIQUE, 0, op, "Wind: dir=%d speed=%d", weathermap[wx][wy].winddir, weathermap[wx][wy].windspeed);
314 new_draw_info_format (NDI_UNIQUE, 0, op, "Pressure: %d", weathermap[wx][wy].pressure);
315 new_draw_info_format (NDI_UNIQUE, 0, op, "Avg Elevation: %d", weathermap[wx][wy].avgelev);
316 new_draw_info_format (NDI_UNIQUE, 0, op, "Rainfall: %d Water: %d", weathermap[wx][wy].rainfall, weathermap[wx][wy].water);
317 }
318
319 temp = real_world_temperature (op->x, op->y, op->map);
320 new_draw_info_format (NDI_UNIQUE, 0, op, "It's currently %d degrees " "Centigrade out.", temp);
321
322 /* humid */
323 if (weathermap[wx][wy].humid < 20)
324 new_draw_info (NDI_UNIQUE, 0, op, "It is very dry.");
325 else if (weathermap[wx][wy].humid < 40)
326 new_draw_info (NDI_UNIQUE, 0, op, "It is very comfortable today.");
327 else if (weathermap[wx][wy].humid < 60)
328 new_draw_info (NDI_UNIQUE, 0, op, "It is a bit muggy.");
329 else if (weathermap[wx][wy].humid < 80)
330 new_draw_info (NDI_UNIQUE, 0, op, "It is muggy.");
331 else
332 new_draw_info (NDI_UNIQUE, 0, op, "It is uncomfortably muggy.");
333
334 /* wind */
335 switch (weathermap[wx][wy].winddir)
336 {
337 case 1:
338 sprintf (buf, "north");
339 break;
340 case 2:
341 sprintf (buf, "northeast");
342 break;
343 case 3:
344 sprintf (buf, "east");
345 break;
346 case 4:
347 sprintf (buf, "southeast");
348 break;
349 case 5:
350 sprintf (buf, "south");
351 break;
352 case 6:
353 sprintf (buf, "southwest");
354 break;
355 case 7:
356 sprintf (buf, "west");
357 break;
358 case 8:
359 sprintf (buf, "northwest");
360 break;
361 }
362 if (weathermap[wx][wy].windspeed < 5)
363 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a mild breeze " "coming from the %s.", buf);
364 else if (weathermap[wx][wy].windspeed < 10)
365 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong breeze " "coming from the %s.", buf);
366 else if (weathermap[wx][wy].windspeed < 15)
367 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a light wind " "coming from the %s.", buf);
368 else if (weathermap[wx][wy].windspeed < 25)
369 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong wind " "coming from the %s.", buf);
370 else if (weathermap[wx][wy].windspeed < 35)
371 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a heavy wind " "coming from the %s.", buf);
372 else
373 new_draw_info_format (NDI_UNIQUE, 0, op, "The wind from the %s is " "incredibly strong!", buf);
374
375 sky = weathermap[wx][wy].sky;
376 if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG)
377 sky += 10; /*let it snow */
378 switch (sky)
379 {
380 case SKY_CLEAR:
381 new_draw_info (NDI_UNIQUE, 0, op, "There isn''t a cloud in the sky.");
382 break;
383 case SKY_LIGHTCLOUD:
384 new_draw_info (NDI_UNIQUE, 0, op, "There are a few light clouds in the sky.");
385 break;
386 case SKY_OVERCAST:
387 new_draw_info (NDI_UNIQUE, 0, op, "The sky is cloudy and dreary.");
388 break;
389 case SKY_LIGHT_RAIN:
390 new_draw_info (NDI_UNIQUE, 0, op, "It is raining softly.");
391 break;
392 case SKY_RAIN:
393 new_draw_info (NDI_UNIQUE, 0, op, "It is raining.");
394 break;
395 case SKY_HEAVY_RAIN:
396 new_draw_info (NDI_UNIQUE, 0, op, "It is raining heavily.");
397 break;
398 case SKY_HURRICANE:
399 new_draw_info (NDI_UNIQUE, 0, op, "There is a heavy storm! You should go inside!");
400 break;
401 case SKY_FOG:
402 new_draw_info (NDI_UNIQUE, 0, op, "It''s foggy and miserable.");
403 break;
404 case SKY_HAIL:
405 new_draw_info (NDI_UNIQUE, 0, op, "It''s hailing out! Take cover!");
406 break;
407 case SKY_LIGHT_SNOW:
408 new_draw_info (NDI_UNIQUE, 0, op, "Snow is gently falling from the sky.");
409 break;
410 case SKY_SNOW:
411 new_draw_info (NDI_UNIQUE, 0, op, "It''s snowing out.");
412 break;
413 case SKY_HEAVY_SNOW:
414 new_draw_info (NDI_UNIQUE, 0, op, "The snow is falling very heavily now.");
415 break;
416 case SKY_BLIZZARD:
417 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!");
418 break;
419 }
420 #endif
421 return 1;
422 }
423
424 int
425 command_archs (object *op, char *params)
426 {
427 arch_info (op);
428 return 1;
429 }
430
431 int
432 command_hiscore (object *op, char *params)
433 {
434 display_high_score (op, op == NULL ? 9999 : 50, params);
435 return 1;
436 }
437
438 int
439 command_debug (object *op, char *params)
440 {
441 int i;
442 char buf[MAX_BUF];
443
444 if (params == NULL || !sscanf (params, "%d", &i))
445 {
446 sprintf (buf, "Global debug level is %d.", settings.debug);
447 new_draw_info (NDI_UNIQUE, 0, op, buf);
448 return 1;
449 }
450 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
451 {
452 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command.");
453 return 1;
454 }
455 settings.debug = (enum LogLevel) FABS (i);
456 sprintf (buf, "Set debug level to %d.", i);
457 new_draw_info (NDI_UNIQUE, 0, op, buf);
458 return 1;
459 }
460
461
462 /*
463 * Those dumps should be just one dump with good parser
464 */
465
466 int
467 command_dumpbelow (object *op, char *params)
468 {
469 if (op && op->below)
470 {
471 char *dump = dump_object (op->below);
472 new_draw_info (NDI_UNIQUE, 0, op, dump);
473 free (dump);
474 /* Let's push that item on the dm's stack */
475 dm_stack_push (op->contr, op->below->count);
476 }
477 return 0;
478 }
479
480 int
481 command_dumpfriendlyobjects (object *op, char *params)
482 {
483 dump_friendly_objects ();
484 return 0;
485 }
486
487 int
488 command_printlos (object *op, char *params)
489 {
490 if (op)
491 print_los (op);
492 return 0;
493 }
494
495
496 int
497 command_version (object *op, char *params)
498 {
499 version (op);
500 return 0;
501 }
502
503 #ifndef BUG_LOG
504 # define BUG_LOG "bug_log"
505 #endif
506 void
507 bug_report (const char *reportstring)
508 {
509 FILE *fp;
510
511 if ((fp = fopen (BUG_LOG, "a")) != NULL)
512 {
513 fprintf (fp, "%s\n", reportstring);
514 fclose (fp);
515 }
516 else
517 {
518 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
519 }
520 }
521
522 int
523 command_output_sync (object *op, char *params)
524 {
525 int val;
526
527 if (!params)
528 {
529 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync);
530 return 1;
531 }
532 val = atoi (params);
533 if (val > 0)
534 {
535 op->contr->outputs_sync = val;
536 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync);
537 }
538 else
539 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync.");
540
541 return 1;
542 }
543
544 int
545 command_output_count (object *op, char *params)
546 {
547 int val;
548
549 if (!params)
550 {
551 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count);
552 return 1;
553 }
554 val = atoi (params);
555 if (val > 0)
556 {
557 op->contr->outputs_count = val;
558 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count);
559 }
560 else
561 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
562
563 return 1;
564 }
565
566 int
567 command_listen (object *op, char *params)
568 {
569 int i;
570
571 if (params == NULL || !sscanf (params, "%d", &i))
572 {
573 new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening);
574 return 1;
575 }
576 op->contr->listening = (char) i;
577 new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i);
578 return 1;
579 }
580
581 /* Prints out some useful information for the character. Everything we print
582 * out can be determined by the docs, so we aren't revealing anything extra -
583 * rather, we are making it convenient to find the values. params have
584 * no meaning here.
585 */
586 int
587 command_statistics (object *pl, char *params)
588 {
589 if (!pl->contr)
590 return 1;
591 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
592 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
593 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
594
595 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d",
596 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str);
597 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d",
598 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex);
599 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d",
600 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con);
601 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d",
602 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int);
603 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d",
604 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis);
605 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d",
606 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow);
607 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d",
608 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->clone.stats.Cha);
609 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
610
611 /* Can't think of anything else to print right now */
612 return 0;
613 }
614
615 int
616 command_fix_me (object *op, char *params)
617 {
618 sum_weight (op);
619 op->update_stats ();
620 return 1;
621 }
622
623 int
624 command_players (object *op, char *paramss)
625 {
626 char buf[MAX_BUF];
627 char *t;
628 DIR *Dir;
629
630 sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir);
631 t = buf + strlen (buf);
632 if ((Dir = opendir (buf)) != NULL)
633 {
634 const struct dirent *Entry;
635
636 while ((Entry = readdir (Dir)))
637 {
638 /* skip '.' , '..' */
639 if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') ||
640 (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0')))
641 {
642 struct stat Stat;
643
644 strcpy (t, Entry->d_name);
645 if (stat (buf, &Stat) == 0)
646 {
647 /* This was not posix compatible
648 * if ((Stat.st_mode & S_IFMT)==S_IFDIR) {
649 */
650 if (S_ISDIR (Stat.st_mode))
651 {
652 char buf2[MAX_BUF];
653 struct tm *tm = localtime (&Stat.st_mtime);
654
655 sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d",
656 Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
657 new_draw_info (NDI_UNIQUE, 0, op, buf2);
658 }
659 }
660 }
661 }
662 }
663 closedir (Dir);
664 return 0;
665 }
666
667
668
669 int
670 command_logs (object *op, char *params)
671 {
672 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
673
674 return 1;
675 }
676
677 int
678 command_applymode (object *op, char *params)
679 {
680 unapplymode unapply = op->contr->unapply;
681 static const char *const types[] = { "nochoice", "never", "always" };
682
683 if (!params)
684 {
685 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]);
686 return 1;
687 }
688
689 if (!strcmp (params, "nochoice"))
690 op->contr->unapply = unapply_nochoice;
691 else if (!strcmp (params, "never"))
692 op->contr->unapply = unapply_never;
693 else if (!strcmp (params, "always"))
694 op->contr->unapply = unapply_always;
695 else
696 {
697 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
698 return 0;
699 }
700 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
701 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
702 return 1;
703 }
704
705 int
706 command_bowmode (object *op, char *params)
707 {
708 bowtype_t oldtype = op->contr->bowtype;
709 static const char *const types[] = { "normal", "threewide", "spreadshot", "firenorth",
710 "firene", "fireeast", "firese", "firesouth",
711 "firesw", "firewest", "firenw", "bestarrow"
712 };
713 char buf[MAX_BUF];
714 int i, found;
715
716 if (!params)
717 {
718 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode is set to %s", types[op->contr->bowtype]);
719 return 1;
720 }
721
722 for (i = 0, found = 0; i <= bow_bestarrow; i++)
723 {
724 if (!strcmp (params, types[i]))
725 {
726 found++;
727 op->contr->bowtype = (bowtype_t) i;
728 break;
729 }
730 }
731 if (!found)
732 {
733 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
734 for (i = 0; i <= bow_bestarrow; i++)
735 {
736 strcat (buf, " ");
737 strcat (buf, types[i]);
738 if (i < bow_nw)
739 strcat (buf, ",");
740 else
741 strcat (buf, ".");
742 }
743 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
744 return 0;
745 }
746 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]);
747 return 1;
748 }
749
750 int
751 command_petmode (object *op, char *params)
752 {
753 petmode_t oldtype = op->contr->petmode;
754 static const char *const types[] = { "normal", "sad", "defend", "arena" };
755
756 if (!params)
757 {
758 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]);
759 return 1;
760 }
761
762 if (!strcmp (params, "normal"))
763 op->contr->petmode = pet_normal;
764 else if (!strcmp (params, "sad"))
765 op->contr->petmode = pet_sad;
766 else if (!strcmp (params, "defend"))
767 op->contr->petmode = pet_defend;
768 else if (!strcmp (params, "arena"))
769 op->contr->petmode = pet_arena;
770 else
771 {
772 new_draw_info_format (NDI_UNIQUE, 0, op,
773 "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params);
774 return 0;
775 }
776 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]);
777 return 1;
778 }
779
780 int
781 command_showpets (object *op, char *params)
782 {
783 objectlink *obl, *next;
784 int counter = 0, target = 0;
785 int have_shown_pet = 0;
786
787 if (params != NULL)
788 target = atoi (params);
789 for (obl = first_friendly_object; obl != NULL; obl = next)
790 {
791 object *ob = obl->ob;
792
793 next = obl->next;
794 if (ob->owner == op)
795 {
796 if (target == 0)
797 {
798 if (counter == 0)
799 new_draw_info (NDI_UNIQUE, 0, op, "Pets:");
800 new_draw_info_format (NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, &ob->name, ob->level);
801 }
802 else if (!have_shown_pet && ++counter == target)
803 {
804 new_draw_info_format (NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name);
805 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);
806 /* this is not a nice way to do this, it should be made to be more like the statistics command */
807 new_draw_info_format (NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str);
808 new_draw_info_format (NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex);
809 new_draw_info_format (NDI_UNIQUE, 0, op, "Con %d", ob->stats.Con);
810 new_draw_info_format (NDI_UNIQUE, 0, op, "Int %d", ob->stats.Int);
811 new_draw_info_format (NDI_UNIQUE, 0, op, "Wis %d", ob->stats.Wis);
812 new_draw_info_format (NDI_UNIQUE, 0, op, "Cha %d", ob->stats.Cha);
813 new_draw_info_format (NDI_UNIQUE, 0, op, "Pow %d", ob->stats.Pow);
814 new_draw_info_format (NDI_UNIQUE, 0, op, "wc %d damage %d ac %d ", ob->stats.wc, ob->stats.dam, ob->stats.ac);
815 have_shown_pet = 1;
816 }
817 }
818 }
819 if (counter == 0)
820 new_draw_info (NDI_UNIQUE, 0, op, "you have no pets.");
821 else if (target != 0 && have_shown_pet == 0)
822 new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
823 return 0;
824 }
825
826 int
827 command_usekeys (object *op, char *params)
828 {
829 usekeytype oldtype = op->contr->usekeys;
830 static const char *const types[] = { "inventory", "keyrings", "containers" };
831
832 if (!params)
833 {
834 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]);
835 return 1;
836 }
837
838 if (!strcmp (params, "inventory"))
839 op->contr->usekeys = key_inventory;
840 else if (!strcmp (params, "keyrings"))
841 op->contr->usekeys = keyrings;
842 else if (!strcmp (params, "containers"))
843 op->contr->usekeys = containers;
844 else
845 {
846 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params);
847 return 0;
848 }
849 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]);
850 return 1;
851 }
852
853 int
854 command_resistances (object *op, char *params)
855 {
856 int i;
857
858 if (!op)
859 return 0;
860
861 for (i = 0; i < NROFATTACKS; i++)
862 {
863 if (i == ATNR_INTERNAL)
864 continue;
865
866 new_draw_info_format (NDI_UNIQUE, 0, op, "%-20s %+5d", attacktype_desc[i], op->resist[i]);
867 }
868
869 /* If dragon player, let's display natural resistances */
870 if (is_dragon_pl (op))
871 {
872 int attack;
873 object *tmp;
874
875 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
876 {
877 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0))
878 {
879 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:");
880 for (attack = 0; attack < NROFATTACKS; attack++)
881 {
882 if (atnr_is_dragon_enabled (attack))
883 {
884 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %d", change_resist_msg[attack], tmp->resist[attack]);
885 }
886 }
887 break;
888 }
889 }
890 }
891
892 return 0;
893 }
894
895 /*
896 * Actual commands.
897 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
898 */
899
900
901 static void
902 help_topics (object *op, int what)
903 {
904 DIR *dirp;
905 struct dirent *de;
906 char filename[MAX_BUF], line[80];
907 int namelen, linelen = 0;
908
909 switch (what)
910 {
911 case 1:
912 sprintf (filename, "%s/wizhelp", settings.datadir);
913 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
914 break;
915 case 3:
916 sprintf (filename, "%s/mischelp", settings.datadir);
917 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
918 break;
919 default:
920 sprintf (filename, "%s/help", settings.datadir);
921 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
922 break;
923 }
924
925 if (!(dirp = opendir (filename)))
926 return;
927
928 line[0] = '\0';
929 while (de = readdir (dirp))
930 {
931 namelen = strlen (de->d_name);
932 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
933 continue;
934 linelen += namelen + 1;
935 if (linelen > 42)
936 {
937 new_draw_info (NDI_UNIQUE, 0, op, line);
938 sprintf (line, " %s", de->d_name);
939 linelen = namelen + 1;
940 continue;
941 }
942 strcat (line, " ");
943 strcat (line, de->d_name);
944 }
945 new_draw_info (NDI_UNIQUE, 0, op, line);
946 closedir (dirp);
947 }
948
949 static void
950 show_commands (object *op, int what)
951 {
952 char line[80];
953 int i, size, namelen, linelen = 0;
954 CommArray_s *ap;
955 extern CommArray_s Commands[], WizCommands[];
956 extern const int CommandsSize, WizCommandsSize;
957
958 switch (what)
959 {
960 case 1:
961 ap = WizCommands;
962 size = WizCommandsSize;
963 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
964 break;
965 case 2:
966 ap = CommunicationCommands;
967 size = CommunicationCommandSize;
968 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
969 break;
970 default:
971 ap = Commands;
972 size = CommandsSize;
973 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
974 break;
975 }
976
977 line[0] = '\0';
978 for (i = 0; i < size; i++)
979 {
980 namelen = strlen (ap[i].name);
981 linelen += namelen + 1;
982 if (linelen > 42)
983 {
984 new_draw_info (NDI_UNIQUE, 0, op, line);
985 sprintf (line, " %s", ap[i].name);
986 linelen = namelen + 1;
987 continue;
988 }
989 strcat (line, " ");
990 strcat (line, ap[i].name);
991 }
992 new_draw_info (NDI_UNIQUE, 0, op, line);
993 }
994
995
996 int
997 command_help (object *op, char *params)
998 {
999 struct stat st;
1000 FILE *fp;
1001 char filename[MAX_BUF], line[MAX_BUF];
1002 int len;
1003
1004 if (op != NULL)
1005 clear_win_info (op);
1006
1007 /*
1008 * Main help page?
1009 */
1010 if (!params)
1011 {
1012 sprintf (filename, "%s/def_help", settings.datadir);
1013 if ((fp = fopen (filename, "r")) == NULL)
1014 {
1015 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1016 return 0;
1017 }
1018 while (fgets (line, MAX_BUF, fp))
1019 {
1020 line[MAX_BUF - 1] = '\0';
1021 len = strlen (line) - 1;
1022 if (line[len] == '\n')
1023 line[len] = '\0';
1024 new_draw_info (NDI_UNIQUE, 0, op, line);
1025 }
1026 fclose (fp);
1027 return 0;
1028 }
1029
1030 /*
1031 * Topics list
1032 */
1033 if (!strcmp (params, "topics"))
1034 {
1035 help_topics (op, 3);
1036 help_topics (op, 0);
1037 if (QUERY_FLAG (op, FLAG_WIZ))
1038 help_topics (op, 1);
1039 return 0;
1040 }
1041
1042 /*
1043 * Commands list
1044 */
1045 if (!strcmp (params, "commands"))
1046 {
1047 show_commands (op, 0);
1048 show_commands (op, 2); /* show comm commands */
1049 if (QUERY_FLAG (op, FLAG_WIZ))
1050 show_commands (op, 1);
1051 return 0;
1052 }
1053
1054 /*
1055 * User wants info about command
1056 */
1057 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
1058 {
1059 sprintf (line, "Illegal characters in '%s'", params);
1060 new_draw_info (NDI_UNIQUE, 0, op, line);
1061 return 0;
1062 }
1063
1064 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
1065 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1066 {
1067 if (op)
1068 {
1069 sprintf (filename, "%s/help/%s", settings.datadir, params);
1070 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1071 {
1072 if (QUERY_FLAG (op, FLAG_WIZ))
1073 {
1074 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
1075 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1076 goto nohelp;
1077 }
1078 else
1079 goto nohelp;
1080 }
1081 }
1082 }
1083
1084 /*
1085 * Found that. Just cat it to screen.
1086 */
1087 if ((fp = fopen (filename, "r")) == NULL)
1088 {
1089 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1090 return 0;
1091 }
1092 sprintf (line, "Help about '%s'", params);
1093 new_draw_info (NDI_UNIQUE, 0, op, line);
1094 while (fgets (line, MAX_BUF, fp))
1095 {
1096 line[MAX_BUF - 1] = '\0';
1097 len = strlen (line) - 1;
1098 if (line[len] == '\n')
1099 line[len] = '\0';
1100 new_draw_info (NDI_UNIQUE, 0, op, line);
1101 }
1102 fclose (fp);
1103 return 0;
1104
1105 /*
1106 * No_help -escape
1107 */
1108 nohelp:
1109 sprintf (line, "No help available on '%s'", params);
1110 new_draw_info (NDI_UNIQUE, 0, op, line);
1111 return 0;
1112 }
1113
1114
1115 int
1116 onoff_value (const char *line)
1117 {
1118 int i;
1119
1120 if (sscanf (line, "%d", &i))
1121 return (i != 0);
1122 switch (line[0])
1123 {
1124 case 'o':
1125 switch (line[1])
1126 {
1127 case 'n':
1128 return 1; /* on */
1129 default:
1130 return 0; /* o[ff] */
1131 }
1132 case 'y': /* y[es] */
1133 case 'k': /* k[ylla] */
1134 case 's':
1135 case 'd':
1136 return 1;
1137 case 'n': /* n[o] */
1138 case 'e': /* e[i] */
1139 case 'u':
1140 default:
1141 return 0;
1142 }
1143 }
1144
1145 int
1146 command_quit (object *op, char *params)
1147 {
1148 new_draw_info (NDI_UNIQUE, 0, op,
1149 "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit.");
1150 return 1;
1151 }
1152
1153 int
1154 command_real_quit (object *op, char *params)
1155 {
1156 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):");
1157
1158 op->contr->ns->state = ST_CONFIRM_QUIT;
1159 return 1;
1160 }
1161
1162 /*
1163 * don't allow people to exit explore mode. It otherwise becomes
1164 * really easy to abuse this.
1165 */
1166 int
1167 command_explore (object *op, char *params)
1168 {
1169 if (settings.explore_mode == FALSE)
1170 return 1;
1171 /*
1172 * I guess this is the best way to see if we are solo or not. Actually,
1173 * are there any cases when first_player->next==NULL and we are not solo?
1174 */
1175 if ((first_player != op->contr) || (first_player->next != NULL))
1176 {
1177 new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party");
1178 }
1179 else if (op->contr->explore)
1180 new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode");
1181 else
1182 {
1183 op->contr->explore = 1;
1184 new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode");
1185 }
1186 return 1;
1187 }
1188
1189 int
1190 command_sound (object *op, char *params)
1191 {
1192 if (op->contr->ns->sound)
1193 {
1194 op->contr->ns->sound = 0;
1195 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
1196 }
1197 else
1198 {
1199 op->contr->ns->sound = 1;
1200 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1201 }
1202
1203 return 1;
1204 }
1205
1206 int
1207 explore_mode (void)
1208 {
1209 player *pl;
1210
1211 if (settings.explore_mode == TRUE)
1212 {
1213 for (pl = first_player; pl != (player *) NULL; pl = pl->next)
1214 if (pl->explore)
1215 return 1;
1216 }
1217 return 0;
1218 }
1219
1220 int
1221 command_title (object *op, char *params)
1222 {
1223 char buf[MAX_BUF];
1224
1225 if (settings.set_title == FALSE)
1226 {
1227 new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title.");
1228 return 1;
1229 }
1230
1231 /* dragon players cannot change titles */
1232 if (is_dragon_pl (op))
1233 {
1234 new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles.");
1235 return 1;
1236 }
1237
1238 if (params == NULL)
1239 {
1240 if (op->contr->own_title[0] == '\0')
1241 sprintf (buf, "Your title is '%s'.", op->contr->title);
1242 else
1243 sprintf (buf, "Your title is '%s'.", op->contr->own_title);
1244 new_draw_info (NDI_UNIQUE, 0, op, buf);
1245 return 1;
1246 }
1247 if (strcmp (params, "clear") == 0 || strcmp (params, "default") == 0)
1248 {
1249 if (op->contr->own_title[0] == '\0')
1250 new_draw_info (NDI_UNIQUE, 0, op, "Your title is the default title.");
1251 else
1252 new_draw_info (NDI_UNIQUE, 0, op, "Title set to default.");
1253 op->contr->own_title[0] = '\0';
1254 return 1;
1255 }
1256
1257 if ((int) strlen (params) >= MAX_NAME)
1258 {
1259 new_draw_info (NDI_UNIQUE, 0, op, "Title too long.");
1260 return 1;
1261 }
1262 strcpy (op->contr->own_title, params);
1263 return 1;
1264 }
1265
1266 int
1267 command_save (object *op, char *params)
1268 {
1269 if (!op->stats.exp)
1270 new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet.");
1271 else
1272 {
1273 op->contr->save ();
1274 new_draw_info (NDI_UNIQUE, 0, op, "You have been saved.");
1275 }
1276
1277 return 1;
1278 }
1279
1280 int
1281 command_peaceful (object *op, char *params)
1282 {
1283 new_draw_info (NDI_UNIQUE, 0, op,
1284 "You cannot change your peaceful setting with this command."
1285 " Please speak to the priest in the temple of Gorokh"
1286 " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again.");
1287
1288 /*
1289 if((op->contr->peaceful=!op->contr->peaceful))
1290 new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players.");
1291 else
1292 new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players.");
1293 */
1294 return 1;
1295 }
1296
1297 int
1298 command_wimpy (object *op, char *params)
1299 {
1300 int i;
1301 char buf[MAX_BUF];
1302
1303 if (params == NULL || !sscanf (params, "%d", &i))
1304 {
1305 sprintf (buf, "Your current wimpy level is %d.", op->run_away);
1306 new_draw_info (NDI_UNIQUE, 0, op, buf);
1307 return 1;
1308 }
1309 sprintf (buf, "Your new wimpy level is %d.", i);
1310 new_draw_info (NDI_UNIQUE, 0, op, buf);
1311 op->run_away = i;
1312 return 1;
1313 }
1314
1315 int
1316 command_brace (object *op, char *params)
1317 {
1318 if (!params)
1319 op->contr->braced = !op->contr->braced;
1320 else
1321 op->contr->braced = onoff_value (params);
1322
1323 if (op->contr->braced)
1324 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1325 else
1326 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1327
1328 op->update_stats ();
1329 return 0;
1330 }
1331
1332 int
1333 command_kill_pets (object *op, char *params)
1334 {
1335 objectlink *obl, *next;
1336 int counter = 0, removecount = 0;
1337
1338 if (params == NULL)
1339 {
1340 terminate_all_pets (op);
1341 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
1342 }
1343 else
1344 {
1345 int target = atoi (params);
1346
1347 for (obl = first_friendly_object; obl != NULL; obl = next)
1348 {
1349 object *ob = obl->ob;
1350
1351 next = obl->next;
1352 if (ob->owner == op)
1353 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1354 {
1355 ob->destroy ();
1356 removecount++;
1357 }
1358 }
1359 if (removecount != 0)
1360 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
1361 else
1362 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
1363 }
1364 return 0;
1365 }