ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.12
Committed: Mon Oct 2 00:10:58 2006 UTC (17 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.11: +0 -26 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 elmex 1.1 /*
2     CrossFire, A Multiplayer game for X-windows
3    
4     Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5     Copyright (C) 1992 Frank Tore Johansen
6    
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20    
21 root 1.8 The authors can be reached via e-mail at <crossfire@schmorp.de>
22 elmex 1.1 */
23    
24     #include <global.h>
25     #include <loader.h>
26     #ifndef __CEXTRACT__
27 root 1.7 # include <sproto.h>
28 elmex 1.1 #endif
29    
30     extern weathermap_t **weathermap;
31    
32     /* Handles misc. input request - things like hash table, malloc, maps,
33     * who, etc.
34     */
35    
36 root 1.7 void
37     map_info (object *op, char *search)
38     {
39 root 1.9 maptile *m;
40 elmex 1.1 char buf[MAX_BUF], map_path[MAX_BUF];
41 root 1.7 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 elmex 1.1 }
62    
63     /* This command dumps the body information for object *op.
64     * it doesn't care what the params are.
65     * This is mostly meant as a debug command.
66     */
67 root 1.7 int
68     command_body (object *op, char *params)
69 elmex 1.1 {
70 root 1.7 int i;
71 elmex 1.1
72 root 1.7 /* 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 root 1.3 }
87 elmex 1.1 }
88 root 1.7 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 elmex 1.1
93 root 1.7 return 1;
94 elmex 1.1 }
95    
96    
97 root 1.7 int
98     command_motd (object *op, char *params)
99 elmex 1.1 {
100 root 1.7 display_motd (op);
101     return 1;
102 elmex 1.1 }
103    
104 root 1.7 int
105     command_bug (object *op, char *params)
106 elmex 1.1 {
107 root 1.7 char buf[MAX_BUF];
108 elmex 1.1
109 root 1.7 if (params == NULL)
110     {
111     new_draw_info (NDI_UNIQUE, 0, op, "what bugs?");
112 elmex 1.1 return 1;
113     }
114 root 1.7 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 elmex 1.1 }
124    
125     /*
126     * Pretty much identical to current map_info, but on a bigger scale
127     * This function returns the name of the players current region, and
128     * a description of it. It is there merely for flavour text.
129     */
130 root 1.7 void
131     current_region_info (object *op)
132     {
133     /*
134     * Ok I /suppose/ I should write a seperate function for this, but it isn't
135     * going to be /that/ slow, and won't get called much
136     */
137     region *r = get_region_by_name (get_name_of_region_for_map (op->map));
138 elmex 1.1
139 root 1.7 if (!r)
140     return;
141     /* This should only be possible if regions are not operating on this server. */
142 elmex 1.1
143 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s. \n %s", get_region_longname (r), get_region_msg (r));
144 elmex 1.1 }
145    
146 root 1.7 void
147     current_map_info (object *op)
148     {
149 root 1.9 maptile *m = op->map;
150 elmex 1.1
151 root 1.7 if (!m)
152     return;
153 elmex 1.1
154 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", m->name, m->path, get_name_of_region_for_map (m));
155 elmex 1.1
156 root 1.7 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 elmex 1.1
162     }
163 root 1.7 if (m->msg)
164     new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg);
165 elmex 1.1 }
166    
167     #ifdef DEBUG_MALLOC_LEVEL
168 root 1.7 int
169     command_malloc_verify (object *op, char *parms)
170 elmex 1.1 {
171 root 1.7 extern int malloc_verify (void);
172 elmex 1.1
173 root 1.7 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 elmex 1.1 #endif
180    
181 root 1.7 int
182     command_whereabouts (object *op, char *params)
183     {
184    
185     region *reg;
186     player *pl;
187 elmex 1.1
188 root 1.7 /*
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 root 1.3 }
211 root 1.7 else /*uh oh, we shouldn't be here. */
212     LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name);
213 root 1.3 }
214     }
215 root 1.7 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 elmex 1.1 }
221    
222     typedef struct
223 root 1.7 {
224     char namebuf[MAX_BUF];
225     int login_order;
226     } chars_names;
227 elmex 1.1
228     /*local functon for qsort comparison*/
229 root 1.7 static int
230     name_cmp (const chars_names * c1, const chars_names * c2)
231     {
232     return strcasecmp (c1->namebuf, c2->namebuf);
233     }
234    
235     int
236     command_afk (object *op, char *params)
237     {
238     if QUERY_FLAG
239     (op, FLAG_AFK)
240     {
241     CLEAR_FLAG (op, FLAG_AFK);
242     new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK");
243     }
244     else
245 elmex 1.1 {
246 root 1.7 SET_FLAG (op, FLAG_AFK);
247     new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK");
248 elmex 1.1 }
249 root 1.7 return 1;
250 elmex 1.1 }
251    
252 root 1.7 int
253     command_mapinfo (object *op, char *params)
254 elmex 1.1 {
255 root 1.7 current_map_info (op);
256     return 1;
257     }
258 elmex 1.1
259 root 1.7 int
260     command_whereami (object *op, char *params)
261 elmex 1.1 {
262 root 1.7 current_region_info (op);
263     return 1;
264 elmex 1.1 }
265    
266 root 1.7 int
267     command_maps (object *op, char *params)
268 elmex 1.1 {
269 root 1.7 map_info (op, params);
270     return 1;
271     }
272 elmex 1.1
273 root 1.7 int
274     command_time (object *op, char *params)
275 elmex 1.1 {
276 root 1.2 print_tod (op);
277     return 1;
278     }
279 elmex 1.1
280 root 1.7 int
281     command_weather (object *op, char *params)
282 elmex 1.1 {
283 root 1.7 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 elmex 1.1
322 root 1.7 /* 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 elmex 1.1
363 root 1.7 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 elmex 1.1 }
408 root 1.7 return 1;
409 elmex 1.1 }
410    
411 root 1.7 int
412     command_archs (object *op, char *params)
413 elmex 1.1 {
414 root 1.7 arch_info (op);
415     return 1;
416     }
417 elmex 1.1
418 root 1.7 int
419     command_hiscore (object *op, char *params)
420 elmex 1.1 {
421 root 1.7 display_high_score (op, op == NULL ? 9999 : 50, params);
422     return 1;
423     }
424 elmex 1.1
425 root 1.7 int
426     command_debug (object *op, char *params)
427 elmex 1.1 {
428 root 1.7 int i;
429     char buf[MAX_BUF];
430    
431     if (params == NULL || !sscanf (params, "%d", &i))
432     {
433     sprintf (buf, "Global debug level is %d.", settings.debug);
434     new_draw_info (NDI_UNIQUE, 0, op, buf);
435 elmex 1.1 return 1;
436     }
437 root 1.7 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
438     {
439     new_draw_info (NDI_UNIQUE, 0, op, "Privileged command.");
440 elmex 1.1 return 1;
441     }
442 root 1.7 settings.debug = (enum LogLevel) FABS (i);
443     sprintf (buf, "Set debug level to %d.", i);
444     new_draw_info (NDI_UNIQUE, 0, op, buf);
445     return 1;
446     }
447 elmex 1.1
448    
449     /*
450     * Those dumps should be just one dump with good parser
451     */
452    
453 root 1.7 int
454     command_dumpbelow (object *op, char *params)
455 elmex 1.1 {
456 root 1.7 if (op && op->below)
457     {
458     dump_object (op->below);
459     new_draw_info (NDI_UNIQUE, 0, op, errmsg);
460 elmex 1.1 /* Let's push that item on the dm's stack */
461 root 1.7 dm_stack_push (op->contr, op->below->count);
462     }
463 elmex 1.1 return 0;
464     }
465    
466 root 1.7 int
467     command_wizcast (object *op, char *params)
468 elmex 1.1 {
469     int i;
470    
471     if (!op)
472     return 0;
473    
474     if (!params)
475 root 1.7 i = (QUERY_FLAG (op, FLAG_WIZCAST)) ? 0 : 1;
476 elmex 1.1 else
477 root 1.7 i = onoff_value (params);
478 elmex 1.1
479 root 1.7 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 elmex 1.1 return 0;
490     }
491    
492 root 1.7 int
493     command_dumpallobjects (object *op, char *params)
494 elmex 1.1 {
495 root 1.7 dump_all_objects ();
496 elmex 1.1 return 0;
497     }
498    
499 root 1.7 int
500     command_dumpfriendlyobjects (object *op, char *params)
501 elmex 1.1 {
502 root 1.7 dump_friendly_objects ();
503 elmex 1.1 return 0;
504     }
505    
506 root 1.7 int
507     command_dumpallarchetypes (object *op, char *params)
508 elmex 1.1 {
509 root 1.7 dump_all_archetypes ();
510 elmex 1.1 return 0;
511 root 1.7 }
512 elmex 1.1
513 root 1.7 int
514     command_dumpmap (object *op, char *params)
515 elmex 1.1 {
516 root 1.7 if (op)
517     dump_map (op->map);
518 elmex 1.1 return 0;
519     }
520    
521 root 1.7 int
522     command_dumpallmaps (object *op, char *params)
523 elmex 1.1 {
524 root 1.7 dump_all_maps ();
525 elmex 1.1 return 0;
526     }
527    
528 root 1.7 int
529     command_printlos (object *op, char *params)
530 elmex 1.1 {
531     if (op)
532 root 1.7 print_los (op);
533 elmex 1.1 return 0;
534     }
535    
536    
537 root 1.7 int
538     command_version (object *op, char *params)
539 elmex 1.1 {
540 root 1.7 version (op);
541     return 0;
542 elmex 1.1 }
543    
544    
545     #ifndef BUG_LOG
546 root 1.7 # define BUG_LOG "bug_log"
547 elmex 1.1 #endif
548 root 1.7 void
549     bug_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 elmex 1.1 }
562 root 1.7 }
563    
564     int
565     command_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 elmex 1.1
583 root 1.7 return 1;
584 elmex 1.1 }
585    
586 root 1.7 int
587     command_output_count (object *op, char *params)
588 elmex 1.1 {
589 root 1.7 int val;
590 elmex 1.1
591 root 1.7 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 elmex 1.1 }
596 root 1.7 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 elmex 1.1
605 root 1.7 return 1;
606 elmex 1.1 }
607    
608 root 1.7 int
609     command_listen (object *op, char *params)
610 elmex 1.1 {
611     int i;
612    
613 root 1.7 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 elmex 1.1 return 1;
617     }
618 root 1.7 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 elmex 1.1 }
622    
623     /* 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 -
625     * rather, we are making it convenient to find the values. params have
626     * no meaning here.
627     */
628 root 1.7 int
629     command_statistics (object *pl, char *params)
630 elmex 1.1 {
631 root 1.7 if (!pl->contr)
632     return 1;
633 elmex 1.1 #ifndef WIN32
634 root 1.7 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 elmex 1.1 #else
637 root 1.7 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 elmex 1.1 #endif
640 root 1.7 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
641 elmex 1.1
642 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d",
643     pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str);
644     new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d",
645     pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex);
646     new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d",
647     pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con);
648     new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d",
649     pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int);
650     new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d",
651     pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis);
652     new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d",
653     pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow);
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 elmex 1.1
658 root 1.7 /* Can't think of anything else to print right now */
659     return 0;
660 elmex 1.1 }
661    
662 root 1.7 int
663     command_fix_me (object *op, char *params)
664 elmex 1.1 {
665 root 1.7 sum_weight (op);
666     fix_player (op);
667     return 1;
668 elmex 1.1 }
669    
670 root 1.7 int
671     command_players (object *op, char *paramss)
672 elmex 1.1 {
673 root 1.7 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 root 1.3 {
689 root 1.7 struct stat Stat;
690 elmex 1.1
691 root 1.7 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 root 1.3 }
706     }
707     }
708     }
709 elmex 1.1 }
710 root 1.7 closedir (Dir);
711     return 0;
712 elmex 1.1 }
713    
714    
715    
716 root 1.7 int
717     command_logs (object *op, char *params)
718 elmex 1.1 {
719 root 1.10 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
720 elmex 1.1
721 root 1.7 return 1;
722 elmex 1.1 }
723    
724 root 1.7 int
725     command_applymode (object *op, char *params)
726 elmex 1.1 {
727 root 1.7 unapplymode unapply = op->contr->unapply;
728     static const char *const types[] = { "nochoice", "never", "always" };
729 elmex 1.1
730 root 1.7 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;
750 elmex 1.1 }
751    
752 root 1.7 int
753     command_bowmode (object *op, char *params)
754 elmex 1.1 {
755 root 1.7 bowtype_t oldtype = op->contr->bowtype;
756     static const char *const types[] = { "normal", "threewide", "spreadshot", "firenorth",
757     "firene", "fireeast", "firese", "firesouth",
758     "firesw", "firewest", "firenw", "bestarrow"
759     };
760     char buf[MAX_BUF];
761     int i, found;
762    
763     if (!params)
764     {
765     new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode is set to %s", types[op->contr->bowtype]);
766     return 1;
767     }
768    
769     for (i = 0, found = 0; i <= bow_bestarrow; i++)
770     {
771     if (!strcmp (params, types[i]))
772     {
773     found++;
774     op->contr->bowtype = (bowtype_t) i;
775     break;
776 root 1.3 }
777 elmex 1.1 }
778 root 1.7 if (!found)
779     {
780     sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
781     for (i = 0; i <= bow_bestarrow; i++)
782     {
783     strcat (buf, " ");
784     strcat (buf, types[i]);
785     if (i < bow_nw)
786     strcat (buf, ",");
787     else
788     strcat (buf, ".");
789 root 1.3 }
790 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
791     return 0;
792 elmex 1.1 }
793 root 1.7 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;
795 elmex 1.1 }
796    
797 root 1.7 int
798     command_petmode (object *op, char *params)
799 elmex 1.1 {
800 root 1.7 petmode_t oldtype = op->contr->petmode;
801     static const char *const types[] = { "normal", "sad", "defend", "arena" };
802 elmex 1.1
803 root 1.7 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 elmex 1.1 }
826    
827 root 1.7 int
828     command_showpets (object *op, char *params)
829 elmex 1.1 {
830 root 1.7 objectlink *obl, *next;
831     int counter = 0, target = 0;
832     int have_shown_pet = 0;
833    
834     if (params != NULL)
835     target = atoi (params);
836     for (obl = first_friendly_object; obl != NULL; obl = next)
837     {
838     object *ob = obl->ob;
839    
840     next = obl->next;
841     if (get_owner (ob) == op)
842     {
843     if (target == 0)
844     {
845     if (counter == 0)
846     new_draw_info (NDI_UNIQUE, 0, op, "Pets:");
847     new_draw_info_format (NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, &ob->name, ob->level);
848     }
849     else if (!have_shown_pet && ++counter == target)
850     {
851     new_draw_info_format (NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name);
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);
853     /* this is not a nice way to do this, it should be made to be more like the statistics command */
854     new_draw_info_format (NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str);
855     new_draw_info_format (NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex);
856     new_draw_info_format (NDI_UNIQUE, 0, op, "Con %d", ob->stats.Con);
857     new_draw_info_format (NDI_UNIQUE, 0, op, "Int %d", ob->stats.Int);
858     new_draw_info_format (NDI_UNIQUE, 0, op, "Wis %d", ob->stats.Wis);
859     new_draw_info_format (NDI_UNIQUE, 0, op, "Cha %d", ob->stats.Cha);
860     new_draw_info_format (NDI_UNIQUE, 0, op, "Pow %d", ob->stats.Pow);
861     new_draw_info_format (NDI_UNIQUE, 0, op, "wc %d damage %d ac %d ", ob->stats.wc, ob->stats.dam, ob->stats.ac);
862     have_shown_pet = 1;
863 root 1.3 }
864     }
865 elmex 1.1 }
866 root 1.7 if (counter == 0)
867     new_draw_info (NDI_UNIQUE, 0, op, "you have no pets.");
868     else if (target != 0 && have_shown_pet == 0)
869     new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
870     return 0;
871 elmex 1.1 }
872    
873 root 1.7 int
874     command_usekeys (object *op, char *params)
875 elmex 1.1 {
876 root 1.7 usekeytype oldtype = op->contr->usekeys;
877     static const char *const types[] = { "inventory", "keyrings", "containers" };
878 elmex 1.1
879 root 1.7 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;
898 elmex 1.1 }
899    
900 root 1.7 int
901     command_resistances (object *op, char *params)
902 elmex 1.1 {
903 root 1.7 int i;
904 elmex 1.1
905 root 1.7 if (!op)
906     return 0;
907    
908     for (i = 0; i < NROFATTACKS; i++)
909     {
910     if (i == ATNR_INTERNAL)
911     continue;
912 elmex 1.1
913 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, "%-20s %+5d", attacktype_desc[i], op->resist[i]);
914 elmex 1.1 }
915    
916 root 1.7 /* If dragon player, let's display natural resistances */
917     if (is_dragon_pl (op))
918     {
919     int attack;
920     object *tmp;
921    
922     for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
923 elmex 1.1 {
924 root 1.7 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0))
925 elmex 1.1 {
926 root 1.7 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:");
927     for (attack = 0; attack < NROFATTACKS; attack++)
928 elmex 1.1 {
929 root 1.7 if (atnr_is_dragon_enabled (attack))
930 elmex 1.1 {
931 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %d", change_resist_msg[attack], tmp->resist[attack]);
932 elmex 1.1 }
933     }
934 root 1.7 break;
935 elmex 1.1 }
936     }
937 root 1.7 }
938 elmex 1.1
939 root 1.7 return 0;
940 elmex 1.1 }
941 root 1.7
942 elmex 1.1 /*
943     * Actual commands.
944     * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
945     */
946    
947    
948 root 1.7 static void
949     help_topics (object *op, int what)
950 elmex 1.1 {
951 root 1.7 DIR *dirp;
952     struct dirent *de;
953     char filename[MAX_BUF], line[80];
954     int namelen, linelen = 0;
955    
956     switch (what)
957     {
958 root 1.3 case 1:
959 root 1.7 sprintf (filename, "%s/wizhelp", settings.datadir);
960     new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
961     break;
962 root 1.3 case 3:
963 root 1.7 sprintf (filename, "%s/mischelp", settings.datadir);
964     new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
965     break;
966 root 1.3 default:
967 root 1.7 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     {
983     new_draw_info (NDI_UNIQUE, 0, op, line);
984     sprintf (line, " %s", de->d_name);
985     linelen = namelen + 1;
986     continue;
987 root 1.3 }
988 root 1.7 strcat (line, " ");
989     strcat (line, de->d_name);
990 elmex 1.1 }
991 root 1.7 new_draw_info (NDI_UNIQUE, 0, op, line);
992     closedir (dirp);
993 elmex 1.1 }
994    
995 root 1.7 static void
996     show_commands (object *op, int what)
997 elmex 1.1 {
998     char line[80];
999 root 1.7 int i, size, namelen, linelen = 0;
1000 elmex 1.1 CommArray_s *ap;
1001     extern CommArray_s Commands[], WizCommands[];
1002     extern const int CommandsSize, WizCommandsSize;
1003 root 1.7
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 elmex 1.1 }
1040    
1041    
1042 root 1.7 int
1043     command_help (object *op, char *params)
1044 elmex 1.1 {
1045     struct stat st;
1046     FILE *fp;
1047     char filename[MAX_BUF], line[MAX_BUF];
1048     int len;
1049    
1050 root 1.7 if (op != NULL)
1051     clear_win_info (op);
1052 elmex 1.1
1053     /*
1054     * Main help page?
1055     */
1056 root 1.7 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 elmex 1.1 return 0;
1074     }
1075    
1076     /*
1077     * Topics list
1078     */
1079 root 1.7 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 elmex 1.1 }
1087 root 1.7
1088 elmex 1.1 /*
1089     * Commands list
1090     */
1091 root 1.7 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 elmex 1.1
1100     /*
1101     * User wants info about command
1102     */
1103 root 1.7 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 elmex 1.1
1110 root 1.7 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 elmex 1.1
1130     /*
1131     * Found that. Just cat it to screen.
1132     */
1133 root 1.7 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 elmex 1.1 }
1148 root 1.7 fclose (fp);
1149 elmex 1.1 return 0;
1150    
1151     /*
1152     * No_help -escape
1153     */
1154 root 1.7 nohelp:
1155     sprintf (line, "No help available on '%s'", params);
1156     new_draw_info (NDI_UNIQUE, 0, op, line);
1157 elmex 1.1 return 0;
1158     }
1159    
1160    
1161 root 1.7 int
1162     onoff_value (const char *line)
1163 elmex 1.1 {
1164     int i;
1165    
1166 root 1.7 if (sscanf (line, "%d", &i))
1167 elmex 1.1 return (i != 0);
1168 root 1.7 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 elmex 1.1 }
1190    
1191 root 1.7 int
1192     command_quit (object *op, char *params)
1193 elmex 1.1 {
1194 root 1.7 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;
1197 elmex 1.1 }
1198    
1199 root 1.7 int
1200     command_real_quit (object *op, char *params)
1201 elmex 1.1 {
1202 root 1.7 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):");
1203 elmex 1.1
1204 root 1.7 op->contr->state = ST_CONFIRM_QUIT;
1205     return 1;
1206     }
1207 elmex 1.1
1208     /*
1209     * don't allow people to exit explore mode. It otherwise becomes
1210     * really easy to abuse this.
1211     */
1212 root 1.7 int
1213     command_explore (object *op, char *params)
1214 elmex 1.1 {
1215 root 1.7 if (settings.explore_mode == FALSE)
1216     return 1;
1217 elmex 1.1 /*
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 root 1.7 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 elmex 1.1 }
1232 root 1.7 return 1;
1233 elmex 1.1 }
1234    
1235 root 1.7 int
1236     command_sound (object *op, char *params)
1237 elmex 1.1 {
1238 root 1.7 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 elmex 1.1 }
1248 root 1.7 return 1;
1249 elmex 1.1 }
1250    
1251     /* Perhaps these should be in player.c, but that file is
1252     * already a bit big.
1253     */
1254    
1255 root 1.7 void
1256     receive_player_name (object *op, char k)
1257     {
1258 elmex 1.1
1259 root 1.7 if (!check_name (op->contr, op->contr->write_buf + 1))
1260     {
1261     get_name (op);
1262     return;
1263 elmex 1.1 }
1264 root 1.7 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 elmex 1.1 }
1270    
1271 root 1.7 void
1272     receive_player_password (object *op, char k)
1273     {
1274    
1275     unsigned int pwd_len = strlen (op->contr->write_buf);
1276 elmex 1.1
1277 root 1.7 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 elmex 1.1
1284 root 1.7 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 elmex 1.1
1292 root 1.7 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 elmex 1.1 return;
1308     }
1309 root 1.7 strcpy (op->contr->password, crypt_string (op->contr->write_buf + 1, NULL));
1310     op->contr->state = ST_ROLL_STAT;
1311     check_login (op);
1312 elmex 1.1 return;
1313     }
1314    
1315    
1316 root 1.7 int
1317     explore_mode (void)
1318     {
1319     player *pl;
1320 elmex 1.1
1321 root 1.7 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 elmex 1.1 }
1327 root 1.7 return 0;
1328 elmex 1.1 }
1329    
1330    
1331 root 1.7 int
1332     command_title (object *op, char *params)
1333 elmex 1.1 {
1334 root 1.7 char buf[MAX_BUF];
1335    
1336     if (settings.set_title == FALSE)
1337     {
1338     new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title.");
1339     return 1;
1340 elmex 1.1 }
1341 root 1.7
1342     /* dragon players cannot change titles */
1343     if (is_dragon_pl (op))
1344     {
1345     new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles.");
1346     return 1;
1347     }
1348    
1349     if (params == NULL)
1350     {
1351     if (op->contr->own_title[0] == '\0')
1352     sprintf (buf, "Your title is '%s'.", op->contr->title);
1353     else
1354     sprintf (buf, "Your title is '%s'.", op->contr->own_title);
1355     new_draw_info (NDI_UNIQUE, 0, op, buf);
1356     return 1;
1357     }
1358     if (strcmp (params, "clear") == 0 || strcmp (params, "default") == 0)
1359     {
1360     if (op->contr->own_title[0] == '\0')
1361     new_draw_info (NDI_UNIQUE, 0, op, "Your title is the default title.");
1362     else
1363     new_draw_info (NDI_UNIQUE, 0, op, "Title set to default.");
1364     op->contr->own_title[0] = '\0';
1365     return 1;
1366     }
1367    
1368     if ((int) strlen (params) >= MAX_NAME)
1369     {
1370     new_draw_info (NDI_UNIQUE, 0, op, "Title too long.");
1371     return 1;
1372     }
1373     strcpy (op->contr->own_title, params);
1374     return 1;
1375 elmex 1.1 }
1376    
1377 root 1.7 int
1378     command_save (object *op, char *params)
1379 elmex 1.1 {
1380     // if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_CLERIC) {
1381 root 1.7 // new_draw_info(NDI_UNIQUE, 0, op, "You can not save on unholy ground");
1382 elmex 1.1 // } else
1383 root 1.7 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 elmex 1.1 }
1394 root 1.7 return 1;
1395 elmex 1.1 }
1396    
1397    
1398 root 1.7 int
1399     command_peaceful (object *op, char *params)
1400 elmex 1.1 {
1401 root 1.7 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 elmex 1.1
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 root 1.7 return 1;
1413 elmex 1.1 }
1414    
1415    
1416    
1417 root 1.7 int
1418     command_wimpy (object *op, char *params)
1419 elmex 1.1 {
1420 root 1.7 int i;
1421     char buf[MAX_BUF];
1422 elmex 1.1
1423 root 1.7 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 elmex 1.1 }
1434    
1435    
1436 root 1.7 int
1437     command_brace (object *op, char *params)
1438 elmex 1.1 {
1439     if (!params)
1440 root 1.7 op->contr->braced = !op->contr->braced;
1441 elmex 1.1 else
1442 root 1.7 op->contr->braced = onoff_value (params);
1443 elmex 1.1
1444 root 1.7 if (op->contr->braced)
1445     new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1446 elmex 1.1 else
1447 root 1.7 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1448 elmex 1.1
1449 root 1.7 fix_player (op);
1450 elmex 1.1 return 0;
1451     }
1452    
1453 root 1.7 int
1454     command_style_map_info (object *op, char *params)
1455 elmex 1.1 {
1456 root 1.9 extern maptile *styles;
1457     maptile *mp;
1458 root 1.7 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 root 1.9 mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile);
1465 root 1.7 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 root 1.3 }
1472     }
1473 elmex 1.1 }
1474 root 1.7 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 elmex 1.1 }
1481    
1482 root 1.7 int
1483     command_kill_pets (object *op, char *params)
1484 elmex 1.1 {
1485 root 1.7 objectlink *obl, *next;
1486     int counter = 0, removecount = 0;
1487    
1488     if (params == NULL)
1489     {
1490     terminate_all_pets (op);
1491     new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
1492     }
1493     else
1494     {
1495     int target = atoi (params);
1496    
1497     for (obl = first_friendly_object; obl != NULL; obl = next)
1498     {
1499     object *ob = obl->ob;
1500    
1501     next = obl->next;
1502     if (get_owner (ob) == op)
1503     if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1504     {
1505     if (!QUERY_FLAG (ob, FLAG_REMOVED))
1506     remove_ob (ob);
1507     remove_friendly_object (ob);
1508     free_object (ob);
1509 root 1.3 removecount++;
1510 root 1.7 }
1511 root 1.3 }
1512 root 1.7 if (removecount != 0)
1513     new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
1514     else
1515     new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
1516 elmex 1.1 }
1517 root 1.7 return 0;
1518 elmex 1.1 }