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.12 by root, Mon Oct 2 00:10:58 2006 UTC vs.
Revision 1.86 by root, Fri Jan 27 22:01:46 2012 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
8 it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
9 the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
10 (at your option) any later version. 11 * 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 Affero GNU General Public License
18 along with this program; if not, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
20 21 *
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <loader.h>
26#ifndef __CEXTRACT__
27# include <sproto.h> 26#include <sproto.h>
28#endif
29 27
30extern weathermap_t **weathermap;
31
32/* Handles misc. input request - things like hash table, malloc, maps, 28/* 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
97int
98command_motd (object *op, char *params)
99{
100 display_motd (op);
101 return 1;
102}
103
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
168int
169command_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
181int
182command_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
222typedef struct
223{
224 char namebuf[MAX_BUF];
225 int login_order;
226} chars_names;
227
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 29
273int 30int
274command_time (object *op, char *params) 31command_time (object *op, char *params)
275{ 32{
276 print_tod (op); 33 print_tod (op);
277 return 1;
278}
279
280int
281command_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
411int
412command_archs (object *op, char *params)
413{
414 arch_info (op);
415 return 1;
416}
417
418int
419command_hiscore (object *op, char *params)
420{
421 display_high_score (op, op == NULL ? 9999 : 50, params);
422 return 1; 34 return 1;
423} 35}
424 36
425int 37int
426command_debug (object *op, char *params) 38command_debug (object *op, char *params)
432 { 44 {
433 sprintf (buf, "Global debug level is %d.", settings.debug); 45 sprintf (buf, "Global debug level is %d.", settings.debug);
434 new_draw_info (NDI_UNIQUE, 0, op, buf); 46 new_draw_info (NDI_UNIQUE, 0, op, buf);
435 return 1; 47 return 1;
436 } 48 }
437 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) 49
438 { 50 settings.debug = i;
439 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command."); 51
440 return 1;
441 }
442 settings.debug = (enum LogLevel) FABS (i);
443 sprintf (buf, "Set debug level to %d.", i); 52 sprintf (buf, "Set debug level to %d.", i);
444 new_draw_info (NDI_UNIQUE, 0, op, buf); 53 new_draw_info (NDI_UNIQUE, 0, op, buf);
445 return 1; 54 return 1;
446} 55}
447
448 56
449/* 57/*
450 * Those dumps should be just one dump with good parser 58 * Those dumps should be just one dump with good parser
451 */ 59 */
452 60
453int 61int
454command_dumpbelow (object *op, char *params) 62command_dumpbelow (object *op, char *params)
455{ 63{
456 if (op && op->below) 64 if (op && op->below)
457 { 65 {
458 dump_object (op->below); 66 char *dump = dump_object (op->below);
459 new_draw_info (NDI_UNIQUE, 0, op, errmsg); 67 new_draw_info (NDI_UNIQUE, 0, op, dump);
68 free (dump);
460 /* Let's push that item on the dm's stack */ 69 /* Let's push that item on the dm's stack */
461 dm_stack_push (op->contr, op->below->count); 70 dm_stack_push (op->contr, op->below->count);
462 } 71 }
463 return 0; 72 return 0;
464} 73}
465 74
466int 75int
467command_wizcast (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_WIZCAST)) ? 0 : 1;
476 else
477 i = onoff_value (params);
478
479 if (i)
480 {
481 new_draw_info (NDI_UNIQUE, 0, op, "You can now cast spells anywhere.");
482 SET_FLAG (op, FLAG_WIZCAST);
483 }
484 else
485 {
486 new_draw_info (NDI_UNIQUE, 0, op, "You now cannot cast spells in no-magic areas.");
487 CLEAR_FLAG (op, FLAG_WIZCAST);
488 }
489 return 0;
490}
491
492int
493command_dumpallobjects (object *op, char *params)
494{
495 dump_all_objects ();
496 return 0;
497}
498
499int
500command_dumpfriendlyobjects (object *op, char *params)
501{
502 dump_friendly_objects ();
503 return 0;
504}
505
506int
507command_dumpallarchetypes (object *op, char *params)
508{
509 dump_all_archetypes ();
510 return 0;
511}
512
513int
514command_dumpmap (object *op, char *params)
515{
516 if (op)
517 dump_map (op->map);
518 return 0;
519}
520
521int
522command_dumpallmaps (object *op, char *params)
523{
524 dump_all_maps ();
525 return 0;
526}
527
528int
529command_printlos (object *op, char *params)
530{
531 if (op)
532 print_los (op);
533 return 0;
534}
535
536
537int
538command_version (object *op, char *params) 76command_version (object *op, char *params)
539{ 77{
540 version (op); 78 version (op);
541 return 0; 79 return 0;
542}
543
544
545#ifndef BUG_LOG
546# define BUG_LOG "bug_log"
547#endif
548void
549bug_report (const char *reportstring)
550{
551 FILE *fp;
552
553 if ((fp = fopen (BUG_LOG, "a")) != NULL)
554 {
555 fprintf (fp, "%s\n", reportstring);
556 fclose (fp);
557 }
558 else
559 {
560 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
561 }
562}
563
564int
565command_output_sync (object *op, char *params)
566{
567 int val;
568
569 if (!params)
570 {
571 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync);
572 return 1;
573 }
574 val = atoi (params);
575 if (val > 0)
576 {
577 op->contr->outputs_sync = val;
578 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync);
579 }
580 else
581 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync.");
582
583 return 1;
584}
585
586int
587command_output_count (object *op, char *params)
588{
589 int val;
590
591 if (!params)
592 {
593 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count);
594 return 1;
595 }
596 val = atoi (params);
597 if (val > 0)
598 {
599 op->contr->outputs_count = val;
600 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count);
601 }
602 else
603 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
604
605 return 1;
606}
607
608int
609command_listen (object *op, char *params)
610{
611 int i;
612
613 if (params == NULL || !sscanf (params, "%d", &i))
614 {
615 new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening);
616 return 1;
617 }
618 op->contr->listening = (char) i;
619 new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i);
620 return 1;
621} 80}
622 81
623/* Prints out some useful information for the character. Everything we print 82/* Prints out some useful information for the character. Everything we print
624 * out can be determined by the docs, so we aren't revealing anything extra - 83 * out can be determined by the docs, so we aren't revealing anything extra -
625 * rather, we are making it convenient to find the values. params have 84 * rather, we are making it convenient to find the values. params have
628int 87int
629command_statistics (object *pl, char *params) 88command_statistics (object *pl, char *params)
630{ 89{
631 if (!pl->contr) 90 if (!pl->contr)
632 return 1; 91 return 1;
633#ifndef WIN32
634 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %lld", pl->stats.exp);
635 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %lld", level_exp (pl->level + 1, pl->expmul));
636#else
637 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %I64d", pl->stats.exp);
638 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %I64d", level_exp (pl->level + 1, pl->expmul));
639#endif
640 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
641 92
642 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 93 dynbuf_text &msg = msg_dynbuf; msg.clear ();
643 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); 94
644 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", 95 msg << " Experience: " << pl->stats.exp << '\n'
645 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex); 96 << " Next Level: " << level_exp (pl->level + 1, pl->expmul) << '\n'
646 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d", 97 << "\n Stat Nat/Real/Max\n";
647 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con); 98
648 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d", 99 for (int i = 0; i < NUM_STATS; ++i)
649 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int); 100 msg.printf (" %s %2d/ %3d/%3d\n", short_stat_name [i], pl->contr->orig_stats.stat (i), pl->stats.stat (i), 20 + pl->arch->stats.stat (i));
650 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d", 101
651 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis); 102 msg << "\nYou are " << (pl->contr->peaceful ? "peaceful" : "hostile") << '.';
652 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d", 103
653 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow); 104 pl->contr->infobox (MSG_CHANNEL ("statistics"), msg);
654 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d",
655 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->clone.stats.Cha);
656 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
657 105
658 /* Can't think of anything else to print right now */ 106 /* Can't think of anything else to print right now */
659 return 0; 107 return 0;
660} 108}
661 109
662int 110int
663command_fix_me (object *op, char *params) 111command_fix_me (object *op, char *params)
664{ 112{
665 sum_weight (op); 113 op->update_weight ();
666 fix_player (op); 114 op->update_stats ();
667 return 1; 115 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
668}
669 116
670int
671command_players (object *op, char *paramss)
672{
673 char buf[MAX_BUF];
674 char *t;
675 DIR *Dir;
676
677 sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir);
678 t = buf + strlen (buf);
679 if ((Dir = opendir (buf)) != NULL)
680 {
681 const struct dirent *Entry;
682
683 while ((Entry = readdir (Dir)) != NULL)
684 {
685 /* skip '.' , '..' */
686 if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') ||
687 (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0')))
688 {
689 struct stat Stat;
690
691 strcpy (t, Entry->d_name);
692 if (stat (buf, &Stat) == 0)
693 {
694 /* This was not posix compatible
695 * if ((Stat.st_mode & S_IFMT)==S_IFDIR) {
696 */
697 if (S_ISDIR (Stat.st_mode))
698 {
699 char buf2[MAX_BUF];
700 struct tm *tm = localtime (&Stat.st_mtime);
701
702 sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d",
703 Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
704 new_draw_info (NDI_UNIQUE, 0, op, buf2);
705 }
706 }
707 }
708 }
709 }
710 closedir (Dir);
711 return 0;
712}
713
714
715
716int
717command_logs (object *op, char *params)
718{
719 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
720
721 return 1;
722}
723
724int
725command_applymode (object *op, char *params)
726{
727 unapplymode unapply = op->contr->unapply;
728 static const char *const types[] = { "nochoice", "never", "always" };
729
730 if (!params)
731 {
732 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]);
733 return 1;
734 }
735
736 if (!strcmp (params, "nochoice"))
737 op->contr->unapply = unapply_nochoice;
738 else if (!strcmp (params, "never"))
739 op->contr->unapply = unapply_never;
740 else if (!strcmp (params, "always"))
741 op->contr->unapply = unapply_always;
742 else
743 {
744 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
745 return 0;
746 }
747 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
748 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
749 return 1; 117 return 1;
750} 118}
751 119
752int 120int
753command_bowmode (object *op, char *params) 121command_bowmode (object *op, char *params)
754{ 122{
755 bowtype_t oldtype = op->contr->bowtype; 123 bowtype_t oldtype = op->contr->bowtype;
756 static const char *const types[] = { "normal", "threewide", "spreadshot", "firenorth", 124 static const char *const types[] = {
125 "normal", "threewide", "spreadshot", "firenorth",
757 "firene", "fireeast", "firese", "firesouth", 126 "firene", "fireeast", "firese", "firesouth",
758 "firesw", "firewest", "firenw", "bestarrow" 127 "firesw", "firewest", "firenw", "bestarrow"
759 }; 128 };
760 char buf[MAX_BUF]; 129 char buf[MAX_BUF];
761 int i, found; 130 int i, found;
773 found++; 142 found++;
774 op->contr->bowtype = (bowtype_t) i; 143 op->contr->bowtype = (bowtype_t) i;
775 break; 144 break;
776 } 145 }
777 } 146 }
147
778 if (!found) 148 if (!found)
779 { 149 {
780 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 150 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
151
781 for (i = 0; i <= bow_bestarrow; i++) 152 for (i = 0; i <= bow_bestarrow; i++)
782 { 153 {
783 strcat (buf, " "); 154 strcat (buf, " ");
784 strcat (buf, types[i]); 155 strcat (buf, types[i]);
785 if (i < bow_nw) 156 if (i < bow_nw)
788 strcat (buf, "."); 159 strcat (buf, ".");
789 } 160 }
790 new_draw_info_format (NDI_UNIQUE, 0, op, buf); 161 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
791 return 0; 162 return 0;
792 } 163 }
164
793 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); 165 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]);
794 return 1; 166 return 1;
795} 167}
796 168
797int 169int
798command_petmode (object *op, char *params)
799{
800 petmode_t oldtype = op->contr->petmode;
801 static const char *const types[] = { "normal", "sad", "defend", "arena" };
802
803 if (!params)
804 {
805 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]);
806 return 1;
807 }
808
809 if (!strcmp (params, "normal"))
810 op->contr->petmode = pet_normal;
811 else if (!strcmp (params, "sad"))
812 op->contr->petmode = pet_sad;
813 else if (!strcmp (params, "defend"))
814 op->contr->petmode = pet_defend;
815 else if (!strcmp (params, "arena"))
816 op->contr->petmode = pet_arena;
817 else
818 {
819 new_draw_info_format (NDI_UNIQUE, 0, op,
820 "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params);
821 return 0;
822 }
823 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]);
824 return 1;
825}
826
827int
828command_showpets (object *op, char *params) 170command_showpets (object *op, char *params)
829{ 171{
830 objectlink *obl, *next;
831 int counter = 0, target = 0; 172 int counter = 0, target = 0;
832 int have_shown_pet = 0; 173 int have_shown_pet = 0;
833 174
175 dynbuf_text &msg = msg_dynbuf; msg.clear ();
176
834 if (params != NULL) 177 if (params)
835 target = atoi (params); 178 target = atoi (params);
179
836 for (obl = first_friendly_object; obl != NULL; obl = next) 180 for (objectlink *obl = first_friendly_object; obl; obl = obl->next)
837 { 181 {
838 object *ob = obl->ob; 182 object *ob = obl->ob;
839 183
840 next = obl->next;
841 if (get_owner (ob) == op) 184 if (ob->owner == op)
842 { 185 {
843 if (target == 0) 186 if (target == 0)
844 { 187 {
845 if (counter == 0) 188 if (counter == 0)
846 new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); 189 msg << "T<Pets>\n\n";
190
847 new_draw_info_format (NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, &ob->name, ob->level); 191 msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level);
848 } 192 }
849 else if (!have_shown_pet && ++counter == target) 193 else if (!have_shown_pet && ++counter == target)
850 { 194 {
851 new_draw_info_format (NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name); 195 msg.printf ("T<%s>\n\n"
852 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); 196 " level %d\n"
853 /* this is not a nice way to do this, it should be made to be more like the statistics command */ 197 " %d/%d HP, %d/%d SP\n"
854 new_draw_info_format (NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str); 198 " Str %2d\n"
855 new_draw_info_format (NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex); 199 " Dex %2d\n"
856 new_draw_info_format (NDI_UNIQUE, 0, op, "Con %d", ob->stats.Con); 200 " Con %2d\n"
857 new_draw_info_format (NDI_UNIQUE, 0, op, "Int %d", ob->stats.Int); 201 " Int %2d\n"
858 new_draw_info_format (NDI_UNIQUE, 0, op, "Wis %d", ob->stats.Wis); 202 " Wis %2d\n"
859 new_draw_info_format (NDI_UNIQUE, 0, op, "Cha %d", ob->stats.Cha); 203 " Cha %2d\n"
860 new_draw_info_format (NDI_UNIQUE, 0, op, "Pow %d", ob->stats.Pow); 204 " Pow %2d\n"
861 new_draw_info_format (NDI_UNIQUE, 0, op, "wc %d damage %d ac %d ", ob->stats.wc, ob->stats.dam, ob->stats.ac); 205 " wc %d damage %d ac %d\n",
206 &ob->name,
207 ob->level,
208 ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp,
209 ob->stats.Str,
210 ob->stats.Dex,
211 ob->stats.Con,
212 ob->stats.Int,
213 ob->stats.Wis,
214 ob->stats.Cha,
215 ob->stats.Pow,
216 ob->stats.wc, ob->stats.dam, ob->stats.ac);
217
862 have_shown_pet = 1; 218 have_shown_pet = 1;
863 } 219 }
864 } 220 }
865 } 221 }
222
866 if (counter == 0) 223 if (counter == 0)
867 new_draw_info (NDI_UNIQUE, 0, op, "you have no pets."); 224 msg << "you have no pets.";
868 else if (target != 0 && have_shown_pet == 0) 225 else if (target != 0 && have_shown_pet == 0)
869 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 226 msg << "no such pet.";
870 return 0;
871}
872 227
873int 228 op->contr->infobox (MSG_CHANNEL ("pets"), msg);
874command_usekeys (object *op, char *params)
875{
876 usekeytype oldtype = op->contr->usekeys;
877 static const char *const types[] = { "inventory", "keyrings", "containers" };
878 229
879 if (!params)
880 {
881 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]);
882 return 1;
883 }
884
885 if (!strcmp (params, "inventory"))
886 op->contr->usekeys = key_inventory;
887 else if (!strcmp (params, "keyrings"))
888 op->contr->usekeys = keyrings;
889 else if (!strcmp (params, "containers"))
890 op->contr->usekeys = containers;
891 else
892 {
893 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params);
894 return 0;
895 }
896 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]);
897 return 1; 230 return 0;
898} 231}
899 232
900int 233int
901command_resistances (object *op, char *params) 234command_resistances (object *op, char *params)
902{ 235{
903 int i; 236 dynbuf_text &msg = msg_dynbuf; msg.clear ();
904 237
905 if (!op) 238 msg << "Resistances:\n\n";
906 return 0;
907 239
908 for (i = 0; i < NROFATTACKS; i++) 240 for (int i = 0; i < NROFATTACKS; i++)
909 {
910 if (i == ATNR_INTERNAL) 241 if (i != ATNR_INTERNAL)
911 continue; 242 msg.printf (" %-20s %+4d\n", attacktype_desc [i], op->resist [i]);
912
913 new_draw_info_format (NDI_UNIQUE, 0, op, "%-20s %+5d", attacktype_desc[i], op->resist[i]);
914 }
915 243
916 /* If dragon player, let's display natural resistances */ 244 /* If dragon player, let's display natural resistances */
917 if (is_dragon_pl (op)) 245 if (op->is_dragon ())
918 {
919 int attack;
920 object *tmp;
921
922 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 246 for (object *tmp = op->inv; tmp; tmp = tmp->below)
923 {
924 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) 247 if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force)
925 { 248 {
926 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); 249 msg << "\nOf those, these are natural skin resistances:\n\n";
250
927 for (attack = 0; attack < NROFATTACKS; attack++) 251 for (int attack = 0; attack < NROFATTACKS; attack++)
928 {
929 if (atnr_is_dragon_enabled (attack)) 252 if (atnr_is_dragon_enabled (attack))
930 { 253 msg.printf (" %-20s %+4d\n", change_resist_msg [attack], tmp->resist [attack]);
931 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %d", change_resist_msg[attack], tmp->resist[attack]);
932 }
933 }
934 break;
935 }
936 }
937 }
938 254
939 return 0;
940}
941
942/*
943 * Actual commands.
944 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
945 */
946
947
948static void
949help_topics (object *op, int what)
950{
951 DIR *dirp;
952 struct dirent *de;
953 char filename[MAX_BUF], line[80];
954 int namelen, linelen = 0;
955
956 switch (what)
957 {
958 case 1:
959 sprintf (filename, "%s/wizhelp", settings.datadir);
960 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
961 break; 255 break;
962 case 3:
963 sprintf (filename, "%s/mischelp", settings.datadir);
964 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
965 break;
966 default:
967 sprintf (filename, "%s/help", settings.datadir);
968 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
969 break;
970 }
971 if (!(dirp = opendir (filename)))
972 return;
973
974 line[0] = '\0';
975 for (de = readdir (dirp); de; de = readdir (dirp))
976 {
977 namelen = NAMLEN (de);
978 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
979 continue;
980 linelen += namelen + 1;
981 if (linelen > 42)
982 { 256 }
983 new_draw_info (NDI_UNIQUE, 0, op, line);
984 sprintf (line, " %s", de->d_name);
985 linelen = namelen + 1;
986 continue;
987 }
988 strcat (line, " ");
989 strcat (line, de->d_name);
990 }
991 new_draw_info (NDI_UNIQUE, 0, op, line);
992 closedir (dirp);
993}
994 257
995static void 258 op->contr->infobox (MSG_CHANNEL ("resistances"), msg);
996show_commands (object *op, int what)
997{
998 char line[80];
999 int i, size, namelen, linelen = 0;
1000 CommArray_s *ap;
1001 extern CommArray_s Commands[], WizCommands[];
1002 extern const int CommandsSize, WizCommandsSize;
1003 259
1004 switch (what)
1005 {
1006 case 1:
1007 ap = WizCommands;
1008 size = WizCommandsSize;
1009 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
1010 break;
1011 case 2:
1012 ap = CommunicationCommands;
1013 size = CommunicationCommandSize;
1014 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
1015 break;
1016 default:
1017 ap = Commands;
1018 size = CommandsSize;
1019 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
1020 break;
1021 }
1022
1023 line[0] = '\0';
1024 for (i = 0; i < size; i++)
1025 {
1026 namelen = strlen (ap[i].name);
1027 linelen += namelen + 1;
1028 if (linelen > 42)
1029 {
1030 new_draw_info (NDI_UNIQUE, 0, op, line);
1031 sprintf (line, " %s", ap[i].name);
1032 linelen = namelen + 1;
1033 continue;
1034 }
1035 strcat (line, " ");
1036 strcat (line, ap[i].name);
1037 }
1038 new_draw_info (NDI_UNIQUE, 0, op, line);
1039}
1040
1041
1042int
1043command_help (object *op, char *params)
1044{
1045 struct stat st;
1046 FILE *fp;
1047 char filename[MAX_BUF], line[MAX_BUF];
1048 int len;
1049
1050 if (op != NULL)
1051 clear_win_info (op);
1052
1053/*
1054 * Main help page?
1055 */
1056 if (!params)
1057 {
1058 sprintf (filename, "%s/def_help", settings.datadir);
1059 if ((fp = fopen (filename, "r")) == NULL)
1060 {
1061 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1062 return 0;
1063 }
1064 while (fgets (line, MAX_BUF, fp))
1065 {
1066 line[MAX_BUF - 1] = '\0';
1067 len = strlen (line) - 1;
1068 if (line[len] == '\n')
1069 line[len] = '\0';
1070 new_draw_info (NDI_UNIQUE, 0, op, line);
1071 }
1072 fclose (fp);
1073 return 0;
1074 }
1075
1076 /*
1077 * Topics list
1078 */
1079 if (!strcmp (params, "topics"))
1080 {
1081 help_topics (op, 3);
1082 help_topics (op, 0);
1083 if (QUERY_FLAG (op, FLAG_WIZ))
1084 help_topics (op, 1);
1085 return 0;
1086 }
1087
1088 /*
1089 * Commands list
1090 */
1091 if (!strcmp (params, "commands"))
1092 {
1093 show_commands (op, 0);
1094 show_commands (op, 2); /* show comm commands */
1095 if (QUERY_FLAG (op, FLAG_WIZ))
1096 show_commands (op, 1);
1097 return 0;
1098 }
1099
1100 /*
1101 * User wants info about command
1102 */
1103 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
1104 {
1105 sprintf (line, "Illegal characters in '%s'", params);
1106 new_draw_info (NDI_UNIQUE, 0, op, line);
1107 return 0;
1108 }
1109
1110 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
1111 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1112 {
1113 if (op)
1114 {
1115 sprintf (filename, "%s/help/%s", settings.datadir, params);
1116 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1117 {
1118 if (QUERY_FLAG (op, FLAG_WIZ))
1119 {
1120 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
1121 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1122 goto nohelp;
1123 }
1124 else
1125 goto nohelp;
1126 }
1127 }
1128 }
1129
1130 /*
1131 * Found that. Just cat it to screen.
1132 */
1133 if ((fp = fopen (filename, "r")) == NULL)
1134 {
1135 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1136 return 0;
1137 }
1138 sprintf (line, "Help about '%s'", params);
1139 new_draw_info (NDI_UNIQUE, 0, op, line);
1140 while (fgets (line, MAX_BUF, fp))
1141 {
1142 line[MAX_BUF - 1] = '\0';
1143 len = strlen (line) - 1;
1144 if (line[len] == '\n')
1145 line[len] = '\0';
1146 new_draw_info (NDI_UNIQUE, 0, op, line);
1147 }
1148 fclose (fp);
1149 return 0;
1150
1151 /*
1152 * No_help -escape
1153 */
1154nohelp:
1155 sprintf (line, "No help available on '%s'", params);
1156 new_draw_info (NDI_UNIQUE, 0, op, line);
1157 return 0;
1158}
1159
1160
1161int
1162onoff_value (const char *line)
1163{
1164 int i;
1165
1166 if (sscanf (line, "%d", &i))
1167 return (i != 0);
1168 switch (line[0])
1169 {
1170 case 'o':
1171 switch (line[1])
1172 {
1173 case 'n':
1174 return 1; /* on */
1175 default:
1176 return 0; /* o[ff] */
1177 }
1178 case 'y': /* y[es] */
1179 case 'k': /* k[ylla] */
1180 case 's':
1181 case 'd':
1182 return 1;
1183 case 'n': /* n[o] */
1184 case 'e': /* e[i] */
1185 case 'u':
1186 default:
1187 return 0;
1188 }
1189}
1190
1191int
1192command_quit (object *op, char *params)
1193{
1194 new_draw_info (NDI_UNIQUE, 0, op,
1195 "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit.");
1196 return 1; 260 return 0;
1197} 261}
1198
1199int
1200command_real_quit (object *op, char *params)
1201{
1202 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):");
1203
1204 op->contr->state = ST_CONFIRM_QUIT;
1205 return 1;
1206}
1207
1208/*
1209 * don't allow people to exit explore mode. It otherwise becomes
1210 * really easy to abuse this.
1211 */
1212int
1213command_explore (object *op, char *params)
1214{
1215 if (settings.explore_mode == FALSE)
1216 return 1;
1217 /*
1218 * I guess this is the best way to see if we are solo or not. Actually,
1219 * are there any cases when first_player->next==NULL and we are not solo?
1220 */
1221 if ((first_player != op->contr) || (first_player->next != NULL))
1222 {
1223 new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party");
1224 }
1225 else if (op->contr->explore)
1226 new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode");
1227 else
1228 {
1229 op->contr->explore = 1;
1230 new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode");
1231 }
1232 return 1;
1233}
1234
1235int
1236command_sound (object *op, char *params)
1237{
1238 if (op->contr->socket.sound)
1239 {
1240 op->contr->socket.sound = 0;
1241 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
1242 }
1243 else
1244 {
1245 op->contr->socket.sound = 1;
1246 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1247 }
1248 return 1;
1249}
1250
1251/* Perhaps these should be in player.c, but that file is
1252 * already a bit big.
1253 */
1254
1255void
1256receive_player_name (object *op, char k)
1257{
1258
1259 if (!check_name (op->contr, op->contr->write_buf + 1))
1260 {
1261 get_name (op);
1262 return;
1263 }
1264 op->name = op->contr->write_buf + 1;
1265 op->name_pl = op->contr->write_buf + 1;
1266 new_draw_info (NDI_UNIQUE, 0, op, op->contr->write_buf);
1267 op->contr->name_changed = 1;
1268 get_password (op);
1269}
1270
1271void
1272receive_player_password (object *op, char k)
1273{
1274
1275 unsigned int pwd_len = strlen (op->contr->write_buf);
1276
1277 if (pwd_len <= 1 || pwd_len > 17)
1278 {
1279 get_name (op);
1280 return;
1281 }
1282 new_draw_info (NDI_UNIQUE, 0, op, " "); /* To hide the password better */
1283
1284 if (checkbanned (op->name, op->contr->socket.host))
1285 {
1286 LOG (llevInfo, "Banned player tried to add: [%s@%s]\n", &op->name, op->contr->socket.host);
1287 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, "You are not allowed to play.");
1288 get_name (op);
1289 return;
1290 }
1291
1292 if (op->contr->state == ST_CONFIRM_PASSWORD)
1293 {
1294 if (!check_password (op->contr->write_buf + 1, op->contr->password))
1295 {
1296 new_draw_info (NDI_UNIQUE, 0, op, "The passwords did not match.");
1297 get_name (op);
1298 return;
1299 }
1300 clear_win_info (op);
1301 display_motd (op);
1302 new_draw_info (NDI_UNIQUE, 0, op, " ");
1303 new_draw_info (NDI_UNIQUE, 0, op, "Welcome, Brave New Warrior!");
1304 new_draw_info (NDI_UNIQUE, 0, op, " ");
1305 Roll_Again (op);
1306 op->contr->state = ST_ROLL_STAT;
1307 return;
1308 }
1309 strcpy (op->contr->password, crypt_string (op->contr->write_buf + 1, NULL));
1310 op->contr->state = ST_ROLL_STAT;
1311 check_login (op);
1312 return;
1313}
1314
1315
1316int
1317explore_mode (void)
1318{
1319 player *pl;
1320
1321 if (settings.explore_mode == TRUE)
1322 {
1323 for (pl = first_player; pl != (player *) NULL; pl = pl->next)
1324 if (pl->explore)
1325 return 1;
1326 }
1327 return 0;
1328}
1329
1330 262
1331int 263int
1332command_title (object *op, char *params) 264command_title (object *op, char *params)
1333{ 265{
1334 char buf[MAX_BUF]; 266 char buf[MAX_BUF];
1338 new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title."); 270 new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title.");
1339 return 1; 271 return 1;
1340 } 272 }
1341 273
1342 /* dragon players cannot change titles */ 274 /* dragon players cannot change titles */
1343 if (is_dragon_pl (op)) 275 if (op->is_dragon ())
1344 { 276 {
1345 new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles."); 277 new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles.");
1346 return 1; 278 return 1;
1347 } 279 }
1348 280
1373 strcpy (op->contr->own_title, params); 305 strcpy (op->contr->own_title, params);
1374 return 1; 306 return 1;
1375} 307}
1376 308
1377int 309int
1378command_save (object *op, char *params)
1379{
1380// if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_CLERIC) {
1381// new_draw_info(NDI_UNIQUE, 0, op, "You can not save on unholy ground");
1382// } else
1383 if (!op->stats.exp)
1384 {
1385 new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet.");
1386 }
1387 else
1388 {
1389 if (save_player (op, 1))
1390 new_draw_info (NDI_UNIQUE, 0, op, "You have been saved.");
1391 else
1392 new_draw_info (NDI_UNIQUE, 0, op, "SAVE FAILED!");
1393 }
1394 return 1;
1395}
1396
1397
1398int
1399command_peaceful (object *op, char *params)
1400{
1401 new_draw_info (NDI_UNIQUE, 0, op,
1402 "You cannot change your peaceful setting with this command."
1403 " Please speak to the priest in the temple of Gorokh"
1404 " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again.");
1405
1406/*
1407 if((op->contr->peaceful=!op->contr->peaceful))
1408 new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players.");
1409 else
1410 new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players.");
1411*/
1412 return 1;
1413}
1414
1415
1416
1417int
1418command_wimpy (object *op, char *params)
1419{
1420 int i;
1421 char buf[MAX_BUF];
1422
1423 if (params == NULL || !sscanf (params, "%d", &i))
1424 {
1425 sprintf (buf, "Your current wimpy level is %d.", op->run_away);
1426 new_draw_info (NDI_UNIQUE, 0, op, buf);
1427 return 1;
1428 }
1429 sprintf (buf, "Your new wimpy level is %d.", i);
1430 new_draw_info (NDI_UNIQUE, 0, op, buf);
1431 op->run_away = i;
1432 return 1;
1433}
1434
1435
1436int
1437command_brace (object *op, char *params)
1438{
1439 if (!params)
1440 op->contr->braced = !op->contr->braced;
1441 else
1442 op->contr->braced = onoff_value (params);
1443
1444 if (op->contr->braced)
1445 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1446 else
1447 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1448
1449 fix_player (op);
1450 return 0;
1451}
1452
1453int
1454command_style_map_info (object *op, char *params)
1455{
1456 extern maptile *styles;
1457 maptile *mp;
1458 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
1459 object *tmp;
1460
1461 for (mp = styles; mp != NULL; mp = mp->next)
1462 {
1463 maps_used++;
1464 mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile);
1465 for (x = 0; x < MAP_WIDTH (mp); x++)
1466 {
1467 for (y = 0; y < MAP_HEIGHT (mp); y++)
1468 {
1469 for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above)
1470 objects_used++;
1471 }
1472 }
1473 }
1474 new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used);
1475 new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not");
1476 new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem);
1477 new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used);
1478 new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object));
1479 return 0;
1480}
1481
1482int
1483command_kill_pets (object *op, char *params) 310command_kill_pets (object *op, char *params)
1484{ 311{
1485 objectlink *obl, *next; 312 objectlink *obl, *next;
1486 int counter = 0, removecount = 0; 313 int counter = 0, removecount = 0;
1487 314
1488 if (params == NULL) 315 if (!params)
1489 { 316 {
1490 terminate_all_pets (op); 317 terminate_all_pets (op);
1491 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); 318 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
1492 } 319 }
1493 else 320 else
1494 { 321 {
1495 int target = atoi (params); 322 int target = atoi (params);
1496 323
1497 for (obl = first_friendly_object; obl != NULL; obl = next) 324 for (obl = first_friendly_object; obl; obl = next)
1498 { 325 {
1499 object *ob = obl->ob; 326 object *ob = obl->ob;
1500 327
1501 next = obl->next; 328 next = obl->next;
329
1502 if (get_owner (ob) == op) 330 if (ob->owner == op)
1503 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 331 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1504 { 332 {
1505 if (!QUERY_FLAG (ob, FLAG_REMOVED))
1506 remove_ob (ob);
1507 remove_friendly_object (ob);
1508 free_object (ob); 333 ob->destroy ();
1509 removecount++; 334 removecount++;
1510 } 335 }
1511 } 336 }
337
1512 if (removecount != 0) 338 if (removecount != 0)
1513 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); 339 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
1514 else 340 else
1515 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); 341 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
1516 } 342 }
343
1517 return 0; 344 return 0;
1518} 345}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines