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.37 by root, Wed Jan 17 22:13:10 2007 UTC vs.
Revision 1.72 by root, Fri Dec 19 22:47:29 2008 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 (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * 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,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#include <loader.h> 25#include <loader.h>
27#include <sproto.h> 26#include <sproto.h>
28 27
29#include <dirent.h>
30
31/* Handles misc. input request - things like hash table, malloc, maps, 28/* Handles misc. input request - things like hash table, malloc, maps, etc */
32 * who, etc.
33 */
34
35/* This command dumps the body information for object *op.
36 * it doesn't care what the params are.
37 * This is mostly meant as a debug command.
38 */
39int
40command_body (object *op, char *params)
41{
42 int i;
43
44 /* Too hard to try and make a header that lines everything up, so just
45 * give a description.
46 */
47 new_draw_info (NDI_UNIQUE, 0, op, "The first column is the name of the body location.");
48 new_draw_info (NDI_UNIQUE, 0, op, "The second column is how many of those locations your body has.");
49 new_draw_info (NDI_UNIQUE, 0, op, "The third column is how many slots in that location are available.");
50 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
51 {
52 /* really debugging - normally body_used should not be set to anything
53 * if body_info isn't also set.
54 */
55 if (op->body_info[i] || op->body_used[i])
56 {
57 new_draw_info_format (NDI_UNIQUE, 0, op, "%-30s %5d %5d", body_locations[i].use_name, op->body_info[i], op->body_used[i]);
58 }
59 }
60 if (!QUERY_FLAG (op, FLAG_USE_ARMOUR))
61 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to wear armor");
62 if (!QUERY_FLAG (op, FLAG_USE_WEAPON))
63 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to use weapons");
64
65 return 1;
66}
67
68 29
69int 30int
70command_motd (object *op, char *params) 31command_motd (object *op, char *params)
71{ 32{
72 display_motd (op); 33 display_motd (op);
73 return 1;
74}
75
76int
77command_bug (object *op, char *params)
78{
79 char buf[MAX_BUF];
80
81 if (params == NULL)
82 {
83 new_draw_info (NDI_UNIQUE, 0, op, "what bugs?");
84 return 1;
85 }
86 strcpy (buf, op->name);
87 strcat (buf, " bug-reports: ");
88 strncat (buf, ++params, MAX_BUF - strlen (buf));
89 buf[MAX_BUF - 1] = '\0';
90 bug_report (buf);
91 LOG (llevError, "%s\n", buf);
92 new_draw_info (NDI_ALL | NDI_UNIQUE, 1, NULL, buf);
93 new_draw_info (NDI_UNIQUE, 0, op, "OK, thanks!");
94 return 1;
95}
96
97/*
98 * Pretty much identical to current map_info, but on a bigger scale
99 * This function returns the name of the players current region, and
100 * a description of it. It is there merely for flavour text.
101 */
102void
103current_region_info (object *op)
104{
105 /*
106 * Ok I /suppose/ I should write a seperate function for this, but it isn't
107 * going to be /that/ slow, and won't get called much
108 */
109 region *r = get_region_by_name (get_name_of_region_for_map (op->map));
110
111 if (!r)
112 return;
113 /* This should only be possible if regions are not operating on this server. */
114
115 new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s. \n %s", get_region_longname (r), get_region_msg (r));
116}
117
118void
119current_map_info (object *op)
120{
121 maptile *m = op->map;
122
123 if (!m)
124 return;
125
126 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", &m->name, &m->path, get_name_of_region_for_map (m));
127
128 if (QUERY_FLAG (op, FLAG_WIZ))
129 {
130 new_draw_info_format (NDI_UNIQUE, 0, op,
131 "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld",
132 m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout);
133
134 }
135 if (m->msg)
136 new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg);
137}
138
139#ifdef DEBUG_MALLOC_LEVEL
140int
141command_malloc_verify (object *op, char *parms)
142{
143 extern int malloc_verify (void);
144
145 if (!malloc_verify ())
146 new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted.");
147 else
148 new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK.");
149 return 1;
150}
151#endif
152
153int
154command_whereabouts (object *op, char *params)
155{
156
157 region *reg;
158 player *pl;
159
160 /*
161 * reset the counter on the region, then use it to store the number of
162 * players there.
163 * I don't know how thread-safe this would be, I suspect not very....
164 */
165 for (reg = first_region; reg != NULL; reg = reg->next)
166 {
167 reg->counter = 0;
168 }
169 for_all_players (pl)
170 if (pl->ob->map != NULL)
171 get_region_by_map (pl->ob->map)->counter++;
172
173 /* we only want to print out by places with a 'longname' field... */
174 for (reg = first_region; reg != NULL; reg = reg->next)
175 {
176 if (reg->longname == NULL && reg->counter > 0)
177 {
178 if (reg->parent != NULL)
179 {
180 reg->parent->counter += reg->counter;
181 reg->counter = 0;
182 }
183 else /*uh oh, we shouldn't be here. */
184 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name);
185 }
186 }
187 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:");
188 for (reg = first_region; reg != NULL; reg = reg->next)
189 if (reg->counter > 0)
190 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg));
191 return 1; 34 return 1;
192} 35}
193 36
194typedef struct 37typedef struct
195{ 38{
196 char namebuf[MAX_BUF]; 39 char namebuf[MAX_BUF];
197 int login_order; 40 int login_order;
198} chars_names; 41} chars_names;
199 42
200int 43int
201command_afk (object *op, char *params)
202{
203 if ((op->contr->ns->afk = !op->contr->ns->afk))
204 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK");
205 else
206 new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK");
207
208 return 1;
209}
210
211int
212command_mapinfo (object *op, char *params)
213{
214 current_map_info (op);
215 return 1;
216}
217
218int
219command_whereami (object *op, char *params)
220{
221 current_region_info (op);
222 return 1;
223}
224
225int
226command_time (object *op, char *params) 44command_time (object *op, char *params)
227{ 45{
228 print_tod (op); 46 print_tod (op);
229 return 1;
230}
231
232int
233command_weather (object *op, char *params)
234{
235#if 0
236 int wx, wy, temp, sky;
237 char buf[MAX_BUF];
238
239 if (settings.dynamiclevel < 1)
240 return 1;
241
242 if (op->map == NULL)
243 return 1;
244
245 if (worldmap_to_weathermap (op->x, op->y, &wx, &wy, op->map) != 0)
246 return 1;
247
248 if (QUERY_FLAG (op, FLAG_WIZ))
249 {
250 /* dump the weather, Dm style! Yo! */
251 new_draw_info_format (NDI_UNIQUE, 0, op, "Real temp: %d", real_world_temperature (op->x, op->y, op->map));
252 new_draw_info_format (NDI_UNIQUE, 0, op, "Base temp: %d", weathermap[wx][wy].temp);
253 new_draw_info_format (NDI_UNIQUE, 0, op, "Humid: %d", weathermap[wx][wy].humid);
254 new_draw_info_format (NDI_UNIQUE, 0, op, "Wind: dir=%d speed=%d", weathermap[wx][wy].winddir, weathermap[wx][wy].windspeed);
255 new_draw_info_format (NDI_UNIQUE, 0, op, "Pressure: %d", weathermap[wx][wy].pressure);
256 new_draw_info_format (NDI_UNIQUE, 0, op, "Avg Elevation: %d", weathermap[wx][wy].avgelev);
257 new_draw_info_format (NDI_UNIQUE, 0, op, "Rainfall: %d Water: %d", weathermap[wx][wy].rainfall, weathermap[wx][wy].water);
258 }
259
260 temp = real_world_temperature (op->x, op->y, op->map);
261 new_draw_info_format (NDI_UNIQUE, 0, op, "It's currently %d degrees " "Centigrade out.", temp);
262
263 /* humid */
264 if (weathermap[wx][wy].humid < 20)
265 new_draw_info (NDI_UNIQUE, 0, op, "It is very dry.");
266 else if (weathermap[wx][wy].humid < 40)
267 new_draw_info (NDI_UNIQUE, 0, op, "It is very comfortable today.");
268 else if (weathermap[wx][wy].humid < 60)
269 new_draw_info (NDI_UNIQUE, 0, op, "It is a bit muggy.");
270 else if (weathermap[wx][wy].humid < 80)
271 new_draw_info (NDI_UNIQUE, 0, op, "It is muggy.");
272 else
273 new_draw_info (NDI_UNIQUE, 0, op, "It is uncomfortably muggy.");
274
275 /* wind */
276 switch (weathermap[wx][wy].winddir)
277 {
278 case 1:
279 sprintf (buf, "north");
280 break;
281 case 2:
282 sprintf (buf, "northeast");
283 break;
284 case 3:
285 sprintf (buf, "east");
286 break;
287 case 4:
288 sprintf (buf, "southeast");
289 break;
290 case 5:
291 sprintf (buf, "south");
292 break;
293 case 6:
294 sprintf (buf, "southwest");
295 break;
296 case 7:
297 sprintf (buf, "west");
298 break;
299 case 8:
300 sprintf (buf, "northwest");
301 break;
302 }
303 if (weathermap[wx][wy].windspeed < 5)
304 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a mild breeze " "coming from the %s.", buf);
305 else if (weathermap[wx][wy].windspeed < 10)
306 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong breeze " "coming from the %s.", buf);
307 else if (weathermap[wx][wy].windspeed < 15)
308 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a light wind " "coming from the %s.", buf);
309 else if (weathermap[wx][wy].windspeed < 25)
310 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong wind " "coming from the %s.", buf);
311 else if (weathermap[wx][wy].windspeed < 35)
312 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a heavy wind " "coming from the %s.", buf);
313 else
314 new_draw_info_format (NDI_UNIQUE, 0, op, "The wind from the %s is " "incredibly strong!", buf);
315
316 sky = weathermap[wx][wy].sky;
317 if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG)
318 sky += 10; /*let it snow */
319 switch (sky)
320 {
321 case SKY_CLEAR:
322 new_draw_info (NDI_UNIQUE, 0, op, "There isn''t a cloud in the sky.");
323 break;
324 case SKY_LIGHTCLOUD:
325 new_draw_info (NDI_UNIQUE, 0, op, "There are a few light clouds in the sky.");
326 break;
327 case SKY_OVERCAST:
328 new_draw_info (NDI_UNIQUE, 0, op, "The sky is cloudy and dreary.");
329 break;
330 case SKY_LIGHT_RAIN:
331 new_draw_info (NDI_UNIQUE, 0, op, "It is raining softly.");
332 break;
333 case SKY_RAIN:
334 new_draw_info (NDI_UNIQUE, 0, op, "It is raining.");
335 break;
336 case SKY_HEAVY_RAIN:
337 new_draw_info (NDI_UNIQUE, 0, op, "It is raining heavily.");
338 break;
339 case SKY_HURRICANE:
340 new_draw_info (NDI_UNIQUE, 0, op, "There is a heavy storm! You should go inside!");
341 break;
342 case SKY_FOG:
343 new_draw_info (NDI_UNIQUE, 0, op, "It''s foggy and miserable.");
344 break;
345 case SKY_HAIL:
346 new_draw_info (NDI_UNIQUE, 0, op, "It''s hailing out! Take cover!");
347 break;
348 case SKY_LIGHT_SNOW:
349 new_draw_info (NDI_UNIQUE, 0, op, "Snow is gently falling from the sky.");
350 break;
351 case SKY_SNOW:
352 new_draw_info (NDI_UNIQUE, 0, op, "It''s snowing out.");
353 break;
354 case SKY_HEAVY_SNOW:
355 new_draw_info (NDI_UNIQUE, 0, op, "The snow is falling very heavily now.");
356 break;
357 case SKY_BLIZZARD:
358 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!");
359 break;
360 }
361#endif
362 return 1;
363}
364
365int
366command_archs (object *op, char *params)
367{
368 arch_info (op);
369 return 1;
370}
371
372int
373command_hiscore (object *op, char *params)
374{
375 display_high_score (op, op == NULL ? 9999 : 50, params);
376 return 1; 47 return 1;
377} 48}
378 49
379int 50int
380command_debug (object *op, char *params) 51command_debug (object *op, char *params)
386 { 57 {
387 sprintf (buf, "Global debug level is %d.", settings.debug); 58 sprintf (buf, "Global debug level is %d.", settings.debug);
388 new_draw_info (NDI_UNIQUE, 0, op, buf); 59 new_draw_info (NDI_UNIQUE, 0, op, buf);
389 return 1; 60 return 1;
390 } 61 }
391 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) 62
392 { 63 settings.debug = i;
393 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command."); 64
394 return 1;
395 }
396 settings.debug = (enum LogLevel) FABS (i);
397 sprintf (buf, "Set debug level to %d.", i); 65 sprintf (buf, "Set debug level to %d.", i);
398 new_draw_info (NDI_UNIQUE, 0, op, buf); 66 new_draw_info (NDI_UNIQUE, 0, op, buf);
399 return 1; 67 return 1;
400} 68}
401 69
424 dump_friendly_objects (); 92 dump_friendly_objects ();
425 return 0; 93 return 0;
426} 94}
427 95
428int 96int
429command_printlos (object *op, char *params)
430{
431 if (op)
432 print_los (op);
433 return 0;
434}
435
436
437int
438command_version (object *op, char *params) 97command_version (object *op, char *params)
439{ 98{
440 version (op); 99 version (op);
441 return 0; 100 return 0;
442} 101}
458 { 117 {
459 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno)); 118 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
460 } 119 }
461} 120}
462 121
463int
464command_output_sync (object *op, char *params)
465{
466 int val;
467
468 if (!params)
469 {
470 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync);
471 return 1;
472 }
473 val = atoi (params);
474 if (val > 0)
475 {
476 op->contr->outputs_sync = val;
477 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync);
478 }
479 else
480 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync.");
481
482 return 1;
483}
484
485int
486command_output_count (object *op, char *params)
487{
488 int val;
489
490 if (!params)
491 {
492 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count);
493 return 1;
494 }
495 val = atoi (params);
496 if (val > 0)
497 {
498 op->contr->outputs_count = val;
499 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count);
500 }
501 else
502 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
503
504 return 1;
505}
506
507int
508command_listen (object *op, char *params)
509{
510 int i;
511
512 if (params == NULL || !sscanf (params, "%d", &i))
513 {
514 new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening);
515 return 1;
516 }
517 op->contr->listening = (char) i;
518 new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i);
519 return 1;
520}
521
522/* Prints out some useful information for the character. Everything we print 122/* Prints out some useful information for the character. Everything we print
523 * out can be determined by the docs, so we aren't revealing anything extra - 123 * out can be determined by the docs, so we aren't revealing anything extra -
524 * rather, we are making it convenient to find the values. params have 124 * rather, we are making it convenient to find the values. params have
525 * no meaning here. 125 * no meaning here.
526 */ 126 */
532 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp); 132 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
533 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul)); 133 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
534 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); 134 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
535 135
536 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 136 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d",
537 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); 137 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->stats.Str);
538 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", 138 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d",
539 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex); 139 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->stats.Dex);
540 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d", 140 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d",
541 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con); 141 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->stats.Con);
542 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d", 142 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d",
543 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int); 143 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->stats.Int);
544 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d", 144 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d",
545 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis); 145 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->stats.Wis);
546 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d", 146 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d",
547 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow); 147 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->stats.Pow);
548 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d", 148 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d",
549 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->clone.stats.Cha); 149 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->stats.Cha);
550 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile"); 150 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
551 151
552 /* Can't think of anything else to print right now */ 152 /* Can't think of anything else to print right now */
553 return 0; 153 return 0;
554} 154}
555 155
556int 156int
557command_fix_me (object *op, char *params) 157command_fix_me (object *op, char *params)
558{ 158{
559 sum_weight (op); 159 op->update_weight ();
560 op->update_stats (); 160 op->update_stats ();
561 return 1; 161 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
562}
563 162
564int
565command_players (object *op, char *paramss)
566{
567 char buf[MAX_BUF];
568 char *t;
569 DIR *Dir;
570
571 sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir);
572 t = buf + strlen (buf);
573 if ((Dir = opendir (buf)) != NULL)
574 {
575 const struct dirent *Entry;
576
577 while ((Entry = readdir (Dir)))
578 {
579 /* skip '.' , '..' */
580 if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') ||
581 (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0')))
582 {
583 struct stat Stat;
584
585 strcpy (t, Entry->d_name);
586 if (stat (buf, &Stat) == 0)
587 {
588 /* This was not posix compatible
589 * if ((Stat.st_mode & S_IFMT)==S_IFDIR) {
590 */
591 if (S_ISDIR (Stat.st_mode))
592 {
593 char buf2[MAX_BUF];
594 struct tm *tm = localtime (&Stat.st_mtime);
595
596 sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d",
597 Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
598 new_draw_info (NDI_UNIQUE, 0, op, buf2);
599 }
600 }
601 }
602 }
603 }
604 closedir (Dir);
605 return 0;
606}
607
608
609
610int
611command_logs (object *op, char *params)
612{
613 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
614
615 return 1;
616}
617
618int
619command_applymode (object *op, char *params)
620{
621 unapplymode unapply = op->contr->unapply;
622 static const char *const types[] = { "nochoice", "never", "always" };
623
624 if (!params)
625 {
626 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]);
627 return 1;
628 }
629
630 if (!strcmp (params, "nochoice"))
631 op->contr->unapply = unapply_nochoice;
632 else if (!strcmp (params, "never"))
633 op->contr->unapply = unapply_never;
634 else if (!strcmp (params, "always"))
635 op->contr->unapply = unapply_always;
636 else
637 {
638 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
639 return 0;
640 }
641 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
642 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
643 return 1; 163 return 1;
644} 164}
645 165
646int 166int
647command_bowmode (object *op, char *params) 167command_bowmode (object *op, char *params)
667 found++; 187 found++;
668 op->contr->bowtype = (bowtype_t) i; 188 op->contr->bowtype = (bowtype_t) i;
669 break; 189 break;
670 } 190 }
671 } 191 }
192
672 if (!found) 193 if (!found)
673 { 194 {
674 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 195 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
675 for (i = 0; i <= bow_bestarrow; i++) 196 for (i = 0; i <= bow_bestarrow; i++)
676 { 197 {
682 strcat (buf, "."); 203 strcat (buf, ".");
683 } 204 }
684 new_draw_info_format (NDI_UNIQUE, 0, op, buf); 205 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
685 return 0; 206 return 0;
686 } 207 }
208
687 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); 209 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]);
688 return 1;
689}
690
691int
692command_petmode (object *op, char *params)
693{
694 petmode_t oldtype = op->contr->petmode;
695 static const char *const types[] = { "normal", "sad", "defend", "arena" };
696
697 if (!params)
698 {
699 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]);
700 return 1;
701 }
702
703 if (!strcmp (params, "normal"))
704 op->contr->petmode = pet_normal;
705 else if (!strcmp (params, "sad"))
706 op->contr->petmode = pet_sad;
707 else if (!strcmp (params, "defend"))
708 op->contr->petmode = pet_defend;
709 else if (!strcmp (params, "arena"))
710 op->contr->petmode = pet_arena;
711 else
712 {
713 new_draw_info_format (NDI_UNIQUE, 0, op,
714 "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params);
715 return 0;
716 }
717 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]);
718 return 1; 210 return 1;
719} 211}
720 212
721int 213int
722command_showpets (object *op, char *params) 214command_showpets (object *op, char *params)
763 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 255 new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
764 return 0; 256 return 0;
765} 257}
766 258
767int 259int
768command_usekeys (object *op, char *params)
769{
770 usekeytype oldtype = op->contr->usekeys;
771 static const char *const types[] = { "inventory", "keyrings", "containers" };
772
773 if (!params)
774 {
775 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]);
776 return 1;
777 }
778
779 if (!strcmp (params, "inventory"))
780 op->contr->usekeys = key_inventory;
781 else if (!strcmp (params, "keyrings"))
782 op->contr->usekeys = keyrings;
783 else if (!strcmp (params, "containers"))
784 op->contr->usekeys = containers;
785 else
786 {
787 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params);
788 return 0;
789 }
790 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]);
791 return 1;
792}
793
794int
795command_resistances (object *op, char *params) 260command_resistances (object *op, char *params)
796{ 261{
797 int i; 262 int i;
798 263
799 if (!op) 264 if (!op)
813 int attack; 278 int attack;
814 object *tmp; 279 object *tmp;
815 280
816 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 281 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
817 { 282 {
818 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) 283 if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force)
819 { 284 {
820 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); 285 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:");
821 for (attack = 0; attack < NROFATTACKS; attack++) 286 for (attack = 0; attack < NROFATTACKS; attack++)
822 { 287 {
823 if (atnr_is_dragon_enabled (attack)) 288 if (atnr_is_dragon_enabled (attack))
835 300
836/* 301/*
837 * Actual commands. 302 * Actual commands.
838 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) 303 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
839 */ 304 */
840
841
842static void
843help_topics (object *op, int what)
844{
845 DIR *dirp;
846 struct dirent *de;
847 char filename[MAX_BUF], line[80];
848 int namelen, linelen = 0;
849
850 switch (what)
851 {
852 case 1:
853 sprintf (filename, "%s/wizhelp", settings.datadir);
854 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
855 break;
856 case 3:
857 sprintf (filename, "%s/mischelp", settings.datadir);
858 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
859 break;
860 default:
861 sprintf (filename, "%s/help", settings.datadir);
862 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
863 break;
864 }
865
866 if (!(dirp = opendir (filename)))
867 return;
868
869 line[0] = '\0';
870 while (de = readdir (dirp))
871 {
872 namelen = strlen (de->d_name);
873 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
874 continue;
875 linelen += namelen + 1;
876 if (linelen > 42)
877 {
878 new_draw_info (NDI_UNIQUE, 0, op, line);
879 sprintf (line, " %s", de->d_name);
880 linelen = namelen + 1;
881 continue;
882 }
883 strcat (line, " ");
884 strcat (line, de->d_name);
885 }
886 new_draw_info (NDI_UNIQUE, 0, op, line);
887 closedir (dirp);
888}
889
890static void
891show_commands (object *op, int what)
892{
893 char line[80];
894 int i, size, namelen, linelen = 0;
895 CommArray_s *ap;
896 extern CommArray_s Commands[], WizCommands[];
897 extern const int CommandsSize, WizCommandsSize;
898
899 switch (what)
900 {
901 case 1:
902 ap = WizCommands;
903 size = WizCommandsSize;
904 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
905 break;
906 case 2:
907 ap = CommunicationCommands;
908 size = CommunicationCommandSize;
909 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
910 break;
911 default:
912 ap = Commands;
913 size = CommandsSize;
914 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
915 break;
916 }
917
918 line[0] = '\0';
919 for (i = 0; i < size; i++)
920 {
921 namelen = strlen (ap[i].name);
922 linelen += namelen + 1;
923 if (linelen > 42)
924 {
925 new_draw_info (NDI_UNIQUE, 0, op, line);
926 sprintf (line, " %s", ap[i].name);
927 linelen = namelen + 1;
928 continue;
929 }
930 strcat (line, " ");
931 strcat (line, ap[i].name);
932 }
933 new_draw_info (NDI_UNIQUE, 0, op, line);
934}
935
936
937int
938command_help (object *op, char *params)
939{
940 struct stat st;
941 FILE *fp;
942 char filename[MAX_BUF], line[MAX_BUF];
943 int len;
944
945 if (op != NULL)
946 clear_win_info (op);
947
948/*
949 * Main help page?
950 */
951 if (!params)
952 {
953 sprintf (filename, "%s/def_help", settings.datadir);
954 if ((fp = fopen (filename, "r")) == NULL)
955 {
956 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
957 return 0;
958 }
959 while (fgets (line, MAX_BUF, fp))
960 {
961 line[MAX_BUF - 1] = '\0';
962 len = strlen (line) - 1;
963 if (line[len] == '\n')
964 line[len] = '\0';
965 new_draw_info (NDI_UNIQUE, 0, op, line);
966 }
967 fclose (fp);
968 return 0;
969 }
970
971 /*
972 * Topics list
973 */
974 if (!strcmp (params, "topics"))
975 {
976 help_topics (op, 3);
977 help_topics (op, 0);
978 if (QUERY_FLAG (op, FLAG_WIZ))
979 help_topics (op, 1);
980 return 0;
981 }
982
983 /*
984 * Commands list
985 */
986 if (!strcmp (params, "commands"))
987 {
988 show_commands (op, 0);
989 show_commands (op, 2); /* show comm commands */
990 if (QUERY_FLAG (op, FLAG_WIZ))
991 show_commands (op, 1);
992 return 0;
993 }
994
995 /*
996 * User wants info about command
997 */
998 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
999 {
1000 sprintf (line, "Illegal characters in '%s'", params);
1001 new_draw_info (NDI_UNIQUE, 0, op, line);
1002 return 0;
1003 }
1004
1005 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
1006 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1007 {
1008 if (op)
1009 {
1010 sprintf (filename, "%s/help/%s", settings.datadir, params);
1011 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1012 {
1013 if (QUERY_FLAG (op, FLAG_WIZ))
1014 {
1015 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
1016 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1017 goto nohelp;
1018 }
1019 else
1020 goto nohelp;
1021 }
1022 }
1023 }
1024
1025 /*
1026 * Found that. Just cat it to screen.
1027 */
1028 if ((fp = fopen (filename, "r")) == NULL)
1029 {
1030 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1031 return 0;
1032 }
1033 sprintf (line, "Help about '%s'", params);
1034 new_draw_info (NDI_UNIQUE, 0, op, line);
1035 while (fgets (line, MAX_BUF, fp))
1036 {
1037 line[MAX_BUF - 1] = '\0';
1038 len = strlen (line) - 1;
1039 if (line[len] == '\n')
1040 line[len] = '\0';
1041 new_draw_info (NDI_UNIQUE, 0, op, line);
1042 }
1043 fclose (fp);
1044 return 0;
1045
1046 /*
1047 * No_help -escape
1048 */
1049nohelp:
1050 sprintf (line, "No help available on '%s'", params);
1051 new_draw_info (NDI_UNIQUE, 0, op, line);
1052 return 0;
1053}
1054
1055 305
1056int 306int
1057onoff_value (const char *line) 307onoff_value (const char *line)
1058{ 308{
1059 int i; 309 int i;
1082 return 0; 332 return 0;
1083 } 333 }
1084} 334}
1085 335
1086int 336int
1087command_sound (object *op, char *params)
1088{
1089 if (op->contr->ns->sound)
1090 {
1091 op->contr->ns->sound = 0;
1092 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
1093 }
1094 else
1095 {
1096 op->contr->ns->sound = 1;
1097 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1098 }
1099
1100 return 1;
1101}
1102
1103int
1104command_title (object *op, char *params) 337command_title (object *op, char *params)
1105{ 338{
1106 char buf[MAX_BUF]; 339 char buf[MAX_BUF];
1107 340
1108 if (settings.set_title == FALSE) 341 if (settings.set_title == FALSE)
1145 strcpy (op->contr->own_title, params); 378 strcpy (op->contr->own_title, params);
1146 return 1; 379 return 1;
1147} 380}
1148 381
1149int 382int
1150command_peaceful (object *op, char *params)
1151{
1152 new_draw_info (NDI_UNIQUE, 0, op,
1153 "You cannot change your peaceful setting with this command."
1154 " Please speak to the priest in the temple of Gorokh"
1155 " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again.");
1156
1157/*
1158 if((op->contr->peaceful=!op->contr->peaceful))
1159 new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players.");
1160 else
1161 new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players.");
1162*/
1163 return 1;
1164}
1165
1166int
1167command_wimpy (object *op, char *params)
1168{
1169 int i;
1170 char buf[MAX_BUF];
1171
1172 if (params == NULL || !sscanf (params, "%d", &i))
1173 {
1174 sprintf (buf, "Your current wimpy level is %d.", op->run_away);
1175 new_draw_info (NDI_UNIQUE, 0, op, buf);
1176 return 1;
1177 }
1178 sprintf (buf, "Your new wimpy level is %d.", i);
1179 new_draw_info (NDI_UNIQUE, 0, op, buf);
1180 op->run_away = i;
1181 return 1;
1182}
1183
1184int
1185command_brace (object *op, char *params)
1186{
1187 if (!params)
1188 op->contr->braced = !op->contr->braced;
1189 else
1190 op->contr->braced = onoff_value (params);
1191
1192 if (op->contr->braced)
1193 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1194 else
1195 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1196
1197 op->update_stats ();
1198 return 0;
1199}
1200
1201int
1202command_kill_pets (object *op, char *params) 383command_kill_pets (object *op, char *params)
1203{ 384{
1204 objectlink *obl, *next; 385 objectlink *obl, *next;
1205 int counter = 0, removecount = 0; 386 int counter = 0, removecount = 0;
1206 387
1207 if (params == NULL) 388 if (!params)
1208 { 389 {
1209 terminate_all_pets (op); 390 terminate_all_pets (op);
1210 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); 391 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
1211 } 392 }
1212 else 393 else
1213 { 394 {
1214 int target = atoi (params); 395 int target = atoi (params);
1215 396
1216 for (obl = first_friendly_object; obl != NULL; obl = next) 397 for (obl = first_friendly_object; obl; obl = next)
1217 { 398 {
1218 object *ob = obl->ob; 399 object *ob = obl->ob;
1219 400
1220 next = obl->next; 401 next = obl->next;
402
1221 if (ob->owner == op) 403 if (ob->owner == op)
1222 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 404 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1223 { 405 {
1224 ob->destroy (); 406 ob->destroy ();
1225 removecount++; 407 removecount++;
1226 } 408 }
1227 } 409 }
410
1228 if (removecount != 0) 411 if (removecount != 0)
1229 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); 412 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
1230 else 413 else
1231 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); 414 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
1232 } 415 }
416
1233 return 0; 417 return 0;
1234} 418}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines