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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines