ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
(Generate patch)

Comparing deliantra/server/server/c_misc.C (file contents):
Revision 1.12 by root, Mon Oct 2 00:10:58 2006 UTC vs.
Revision 1.52 by pippijn, Fri Mar 2 11:07:59 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * 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 * 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 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your 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 GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <loader.h> 26#include <loader.h>
26#ifndef __CEXTRACT__
27# include <sproto.h> 27#include <sproto.h>
28#endif
29
30extern weathermap_t **weathermap;
31 28
32/* Handles misc. input request - things like hash table, malloc, maps, 29/* Handles misc. input request - things like hash table, malloc, maps,
33 * who, etc. 30 * who, etc.
34 */ 31 */
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 32
63/* This command dumps the body information for object *op. 33/* This command dumps the body information for object *op.
64 * it doesn't care what the params are. 34 * it doesn't care what the params are.
65 * This is mostly meant as a debug command. 35 * This is mostly meant as a debug command.
66 */ 36 */
99{ 69{
100 display_motd (op); 70 display_motd (op);
101 return 1; 71 return 1;
102} 72}
103 73
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/* 74/*
126 * Pretty much identical to current map_info, but on a bigger scale 75 * Pretty much identical to current map_info, but on a bigger scale
127 * This function returns the name of the players current region, and 76 * This function returns the name of the players current region, and
128 * a description of it. It is there merely for flavour text. 77 * a description of it. It is there merely for flavour text.
129 */ 78 */
130void 79void
131current_region_info (object *op) 80current_region_info (object *op)
132{ 81{
133 /* 82 if (region *reg = op->region ())
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)); 83 new_draw_info_format (NDI_UNIQUE, 0, op, "You are %s.\n%s", &reg->longname, &reg->msg);
144} 84}
145 85
146void 86void
147current_map_info (object *op) 87current_map_info (object *op)
148{ 88{
149 maptile *m = op->map; 89 maptile *m = op->map;
150 90
151 if (!m) 91 if (!m)
152 return; 92 return;
153 93
154 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", m->name, m->path, get_name_of_region_for_map (m)); 94 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) %s", &m->name, &m->path, &op->region ()->longname);
155 95
156 if (QUERY_FLAG (op, FLAG_WIZ)) 96 if (QUERY_FLAG (op, FLAG_WIZ))
157 {
158 new_draw_info_format (NDI_UNIQUE, 0, op, 97 new_draw_info_format (NDI_UNIQUE, 0, op,
159 "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld", 98 "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)); 99 m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout);
161 100
162 }
163 if (m->msg) 101 if (m->msg)
164 new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); 102 new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg);
165} 103}
166 104
167#ifdef DEBUG_MALLOC_LEVEL 105#ifdef DEBUG_MALLOC_LEVEL
179#endif 117#endif
180 118
181int 119int
182command_whereabouts (object *op, char *params) 120command_whereabouts (object *op, char *params)
183{ 121{
184 122 //TODO: should obviously not waste space in struct region for this.
185 region *reg;
186 player *pl;
187
188 /* 123 /*
189 * reset the counter on the region, then use it to store the number of 124 * reset the counter on the region, then use it to store the number of
190 * players there. 125 * players there.
191 * I don't know how thread-safe this would be, I suspect not very.... 126 * I don't know how thread-safe this would be, I suspect not very....
192 */ 127 */
193 for (reg = first_region; reg != NULL; reg = reg->next) 128 for_all_regions (rgn)
194 {
195 reg->counter = 0; 129 rgn->counter = 0;
196 } 130
197 for (pl = first_player; pl != NULL; pl = pl->next) 131 for_all_players (pl)
198 if (pl->ob->map != NULL) 132 if (pl->ob->map)
199 get_region_by_map (pl->ob->map)->counter++; 133 ++pl->ob->region ()->counter;
200 134
201 /* we only want to print out by places with a 'longname' field... */ 135 /* we only want to print out by places with a 'longname' field... */
202 for (reg = first_region; reg != NULL; reg = reg->next) 136 for_all_regions (rgn)
203 { 137 {
204 if (reg->longname == NULL && reg->counter > 0) 138 if (!rgn->longname && rgn->counter > 0)
205 { 139 {
206 if (reg->parent != NULL) 140 if (rgn->parent)
207 { 141 {
208 reg->parent->counter += reg->counter; 142 rgn->parent->counter += rgn->counter;
209 reg->counter = 0; 143 rgn->counter = 0;
210 } 144 }
211 else /*uh oh, we shouldn't be here. */ 145 else /*uh oh, we shouldn't be here. */
212 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name); 146 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", &rgn->name);
213 } 147 }
214 } 148 }
149
215 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); 150 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:");
216 for (reg = first_region; reg != NULL; reg = reg->next) 151
152 for_all_regions (rgn)
217 if (reg->counter > 0) 153 if (rgn->counter)
218 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg)); 154 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players %s", rgn->counter, &rgn->longname);
155
219 return 1; 156 return 1;
220} 157}
221 158
222typedef struct 159typedef struct
223{ 160{
224 char namebuf[MAX_BUF]; 161 char namebuf[MAX_BUF];
225 int login_order; 162 int login_order;
226} chars_names; 163} chars_names;
227 164
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 165int
253command_mapinfo (object *op, char *params) 166command_mapinfo (object *op, char *params)
254{ 167{
255 current_map_info (op); 168 current_map_info (op);
256 return 1; 169 return 1;
262 current_region_info (op); 175 current_region_info (op);
263 return 1; 176 return 1;
264} 177}
265 178
266int 179int
267command_maps (object *op, char *params)
268{
269 map_info (op, params);
270 return 1;
271}
272
273int
274command_time (object *op, char *params) 180command_time (object *op, char *params)
275{ 181{
276 print_tod (op); 182 print_tod (op);
277 return 1; 183 return 1;
278} 184}
279 185
280int 186int
281command_weather (object *op, char *params) 187command_weather (object *op, char *params)
282{ 188{
189#if 0
283 int wx, wy, temp, sky; 190 int wx, wy, temp, sky;
284 char buf[MAX_BUF]; 191 char buf[MAX_BUF];
285 192
286 if (settings.dynamiclevel < 1) 193 if (settings.dynamiclevel < 1)
287 return 1; 194 return 1;
403 break; 310 break;
404 case SKY_BLIZZARD: 311 case SKY_BLIZZARD:
405 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!"); 312 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!");
406 break; 313 break;
407 } 314 }
408 return 1; 315#endif
409}
410
411int
412command_archs (object *op, char *params)
413{
414 arch_info (op);
415 return 1; 316 return 1;
416} 317}
417 318
418int 319int
419command_hiscore (object *op, char *params) 320command_hiscore (object *op, char *params)
432 { 333 {
433 sprintf (buf, "Global debug level is %d.", settings.debug); 334 sprintf (buf, "Global debug level is %d.", settings.debug);
434 new_draw_info (NDI_UNIQUE, 0, op, buf); 335 new_draw_info (NDI_UNIQUE, 0, op, buf);
435 return 1; 336 return 1;
436 } 337 }
437 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
438 {
439 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command.");
440 return 1;
441 }
442 settings.debug = (enum LogLevel) FABS (i); 338 settings.debug = (enum LogLevel) FABS (i);
443 sprintf (buf, "Set debug level to %d.", i); 339 sprintf (buf, "Set debug level to %d.", i);
444 new_draw_info (NDI_UNIQUE, 0, op, buf); 340 new_draw_info (NDI_UNIQUE, 0, op, buf);
445 return 1; 341 return 1;
446} 342}
453int 349int
454command_dumpbelow (object *op, char *params) 350command_dumpbelow (object *op, char *params)
455{ 351{
456 if (op && op->below) 352 if (op && op->below)
457 { 353 {
458 dump_object (op->below); 354 char *dump = dump_object (op->below);
459 new_draw_info (NDI_UNIQUE, 0, op, errmsg); 355 new_draw_info (NDI_UNIQUE, 0, op, dump);
356 free (dump);
460 /* Let's push that item on the dm's stack */ 357 /* Let's push that item on the dm's stack */
461 dm_stack_push (op->contr, op->below->count); 358 dm_stack_push (op->contr, op->below->count);
462 } 359 }
463 return 0; 360 return 0;
464} 361}
465 362
466int 363int
467command_wizcast (object *op, char *params)
468{
469 int i;
470
471 if (!op)
472 return 0;
473
474 if (!params)
475 i = (QUERY_FLAG (op, FLAG_WIZCAST)) ? 0 : 1;
476 else
477 i = onoff_value (params);
478
479 if (i)
480 {
481 new_draw_info (NDI_UNIQUE, 0, op, "You can now cast spells anywhere.");
482 SET_FLAG (op, FLAG_WIZCAST);
483 }
484 else
485 {
486 new_draw_info (NDI_UNIQUE, 0, op, "You now cannot cast spells in no-magic areas.");
487 CLEAR_FLAG (op, FLAG_WIZCAST);
488 }
489 return 0;
490}
491
492int
493command_dumpallobjects (object *op, char *params)
494{
495 dump_all_objects ();
496 return 0;
497}
498
499int
500command_dumpfriendlyobjects (object *op, char *params) 364command_dumpfriendlyobjects (object *op, char *params)
501{ 365{
502 dump_friendly_objects (); 366 dump_friendly_objects ();
503 return 0;
504}
505
506int
507command_dumpallarchetypes (object *op, char *params)
508{
509 dump_all_archetypes ();
510 return 0;
511}
512
513int
514command_dumpmap (object *op, char *params)
515{
516 if (op)
517 dump_map (op->map);
518 return 0;
519}
520
521int
522command_dumpallmaps (object *op, char *params)
523{
524 dump_all_maps ();
525 return 0; 367 return 0;
526} 368}
527 369
528int 370int
529command_printlos (object *op, char *params) 371command_printlos (object *op, char *params)
538command_version (object *op, char *params) 380command_version (object *op, char *params)
539{ 381{
540 version (op); 382 version (op);
541 return 0; 383 return 0;
542} 384}
543
544 385
545#ifndef BUG_LOG 386#ifndef BUG_LOG
546# define BUG_LOG "bug_log" 387# define BUG_LOG "bug_log"
547#endif 388#endif
548void 389void
559 { 400 {
560 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno)); 401 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
561 } 402 }
562} 403}
563 404
564int
565command_output_sync (object *op, char *params)
566{
567 int val;
568
569 if (!params)
570 {
571 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync);
572 return 1;
573 }
574 val = atoi (params);
575 if (val > 0)
576 {
577 op->contr->outputs_sync = val;
578 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync);
579 }
580 else
581 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync.");
582
583 return 1;
584}
585
586int
587command_output_count (object *op, char *params)
588{
589 int val;
590
591 if (!params)
592 {
593 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count);
594 return 1;
595 }
596 val = atoi (params);
597 if (val > 0)
598 {
599 op->contr->outputs_count = val;
600 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count);
601 }
602 else
603 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
604
605 return 1;
606}
607
608int
609command_listen (object *op, char *params)
610{
611 int i;
612
613 if (params == NULL || !sscanf (params, "%d", &i))
614 {
615 new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening);
616 return 1;
617 }
618 op->contr->listening = (char) i;
619 new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i);
620 return 1;
621}
622
623/* Prints out some useful information for the character. Everything we print 405/* 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 - 406 * 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 407 * rather, we are making it convenient to find the values. params have
626 * no meaning here. 408 * no meaning here.
627 */ 409 */
628int 410int
629command_statistics (object *pl, char *params) 411command_statistics (object *pl, char *params)
630{ 412{
631 if (!pl->contr) 413 if (!pl->contr)
632 return 1; 414 return 1;
633#ifndef WIN32
634 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %lld", pl->stats.exp);
635 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %lld", level_exp (pl->level + 1, pl->expmul));
636#else
637 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %I64d", pl->stats.exp); 415 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
638 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %I64d", level_exp (pl->level + 1, pl->expmul)); 416 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
639#endif
640 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); 417 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
641 418
642 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 419 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); 420 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", 421 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d",
661 438
662int 439int
663command_fix_me (object *op, char *params) 440command_fix_me (object *op, char *params)
664{ 441{
665 sum_weight (op); 442 sum_weight (op);
666 fix_player (op); 443 op->update_stats ();
667 return 1; 444 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
668}
669 445
670int
671command_players (object *op, char *paramss)
672{
673 char buf[MAX_BUF];
674 char *t;
675 DIR *Dir;
676
677 sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir);
678 t = buf + strlen (buf);
679 if ((Dir = opendir (buf)) != NULL)
680 {
681 const struct dirent *Entry;
682
683 while ((Entry = readdir (Dir)) != NULL)
684 {
685 /* skip '.' , '..' */
686 if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') ||
687 (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0')))
688 {
689 struct stat Stat;
690
691 strcpy (t, Entry->d_name);
692 if (stat (buf, &Stat) == 0)
693 {
694 /* This was not posix compatible
695 * if ((Stat.st_mode & S_IFMT)==S_IFDIR) {
696 */
697 if (S_ISDIR (Stat.st_mode))
698 {
699 char buf2[MAX_BUF];
700 struct tm *tm = localtime (&Stat.st_mtime);
701
702 sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d",
703 Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
704 new_draw_info (NDI_UNIQUE, 0, op, buf2);
705 }
706 }
707 }
708 }
709 }
710 closedir (Dir);
711 return 0; 446 return 1;
712} 447}
713
714
715 448
716int 449int
717command_logs (object *op, char *params) 450command_logs (object *op, char *params)
718{ 451{
719 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); 452 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
720 453
721 return 1;
722}
723
724int
725command_applymode (object *op, char *params)
726{
727 unapplymode unapply = op->contr->unapply;
728 static const char *const types[] = { "nochoice", "never", "always" };
729
730 if (!params)
731 {
732 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]);
733 return 1;
734 }
735
736 if (!strcmp (params, "nochoice"))
737 op->contr->unapply = unapply_nochoice;
738 else if (!strcmp (params, "never"))
739 op->contr->unapply = unapply_never;
740 else if (!strcmp (params, "always"))
741 op->contr->unapply = unapply_always;
742 else
743 {
744 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
745 return 0;
746 }
747 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
748 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
749 return 1; 454 return 1;
750} 455}
751 456
752int 457int
753command_bowmode (object *op, char *params) 458command_bowmode (object *op, char *params)
773 found++; 478 found++;
774 op->contr->bowtype = (bowtype_t) i; 479 op->contr->bowtype = (bowtype_t) i;
775 break; 480 break;
776 } 481 }
777 } 482 }
483
778 if (!found) 484 if (!found)
779 { 485 {
780 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 486 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
781 for (i = 0; i <= bow_bestarrow; i++) 487 for (i = 0; i <= bow_bestarrow; i++)
782 { 488 {
788 strcat (buf, "."); 494 strcat (buf, ".");
789 } 495 }
790 new_draw_info_format (NDI_UNIQUE, 0, op, buf); 496 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
791 return 0; 497 return 0;
792 } 498 }
499
793 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); 500 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}
796
797int
798command_petmode (object *op, char *params)
799{
800 petmode_t oldtype = op->contr->petmode;
801 static const char *const types[] = { "normal", "sad", "defend", "arena" };
802
803 if (!params)
804 {
805 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]);
806 return 1;
807 }
808
809 if (!strcmp (params, "normal"))
810 op->contr->petmode = pet_normal;
811 else if (!strcmp (params, "sad"))
812 op->contr->petmode = pet_sad;
813 else if (!strcmp (params, "defend"))
814 op->contr->petmode = pet_defend;
815 else if (!strcmp (params, "arena"))
816 op->contr->petmode = pet_arena;
817 else
818 {
819 new_draw_info_format (NDI_UNIQUE, 0, op,
820 "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params);
821 return 0;
822 }
823 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]);
824 return 1; 501 return 1;
825} 502}
826 503
827int 504int
828command_showpets (object *op, char *params) 505command_showpets (object *op, char *params)
836 for (obl = first_friendly_object; obl != NULL; obl = next) 513 for (obl = first_friendly_object; obl != NULL; obl = next)
837 { 514 {
838 object *ob = obl->ob; 515 object *ob = obl->ob;
839 516
840 next = obl->next; 517 next = obl->next;
841 if (get_owner (ob) == op) 518 if (ob->owner == op)
842 { 519 {
843 if (target == 0) 520 if (target == 0)
844 { 521 {
845 if (counter == 0) 522 if (counter == 0)
846 new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); 523 new_draw_info (NDI_UNIQUE, 0, op, "Pets:");
869 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 546 new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
870 return 0; 547 return 0;
871} 548}
872 549
873int 550int
874command_usekeys (object *op, char *params)
875{
876 usekeytype oldtype = op->contr->usekeys;
877 static const char *const types[] = { "inventory", "keyrings", "containers" };
878
879 if (!params)
880 {
881 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]);
882 return 1;
883 }
884
885 if (!strcmp (params, "inventory"))
886 op->contr->usekeys = key_inventory;
887 else if (!strcmp (params, "keyrings"))
888 op->contr->usekeys = keyrings;
889 else if (!strcmp (params, "containers"))
890 op->contr->usekeys = containers;
891 else
892 {
893 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params);
894 return 0;
895 }
896 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]);
897 return 1;
898}
899
900int
901command_resistances (object *op, char *params) 551command_resistances (object *op, char *params)
902{ 552{
903 int i; 553 int i;
904 554
905 if (!op) 555 if (!op)
953 char filename[MAX_BUF], line[80]; 603 char filename[MAX_BUF], line[80];
954 int namelen, linelen = 0; 604 int namelen, linelen = 0;
955 605
956 switch (what) 606 switch (what)
957 { 607 {
958 case 1: 608 case 1:
959 sprintf (filename, "%s/wizhelp", settings.datadir); 609 sprintf (filename, "%s/wizhelp", settings.datadir);
960 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); 610 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
961 break; 611 break;
962 case 3: 612 case 3:
963 sprintf (filename, "%s/mischelp", settings.datadir); 613 sprintf (filename, "%s/mischelp", settings.datadir);
964 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); 614 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
965 break; 615 break;
966 default: 616 default:
967 sprintf (filename, "%s/help", settings.datadir); 617 sprintf (filename, "%s/help", settings.datadir);
968 new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); 618 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
969 break; 619 break;
970 } 620 }
621
971 if (!(dirp = opendir (filename))) 622 if (!(dirp = opendir (filename)))
972 return; 623 return;
973 624
974 line[0] = '\0'; 625 line[0] = '\0';
975 for (de = readdir (dirp); de; de = readdir (dirp)) 626 while ((de = readdir (dirp)))
976 { 627 {
977 namelen = NAMLEN (de); 628 namelen = strlen (de->d_name);
978 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) 629 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
979 continue; 630 continue;
980 linelen += namelen + 1; 631 linelen += namelen + 1;
981 if (linelen > 42) 632 if (linelen > 42)
982 { 633 {
1187 return 0; 838 return 0;
1188 } 839 }
1189} 840}
1190 841
1191int 842int
1192command_quit (object *op, char *params)
1193{
1194 new_draw_info (NDI_UNIQUE, 0, op,
1195 "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit.");
1196 return 1;
1197}
1198
1199int
1200command_real_quit (object *op, char *params)
1201{
1202 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):");
1203
1204 op->contr->state = ST_CONFIRM_QUIT;
1205 return 1;
1206}
1207
1208/*
1209 * don't allow people to exit explore mode. It otherwise becomes
1210 * really easy to abuse this.
1211 */
1212int
1213command_explore (object *op, char *params)
1214{
1215 if (settings.explore_mode == FALSE)
1216 return 1;
1217 /*
1218 * I guess this is the best way to see if we are solo or not. Actually,
1219 * are there any cases when first_player->next==NULL and we are not solo?
1220 */
1221 if ((first_player != op->contr) || (first_player->next != NULL))
1222 {
1223 new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party");
1224 }
1225 else if (op->contr->explore)
1226 new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode");
1227 else
1228 {
1229 op->contr->explore = 1;
1230 new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode");
1231 }
1232 return 1;
1233}
1234
1235int
1236command_sound (object *op, char *params)
1237{
1238 if (op->contr->socket.sound)
1239 {
1240 op->contr->socket.sound = 0;
1241 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
1242 }
1243 else
1244 {
1245 op->contr->socket.sound = 1;
1246 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1247 }
1248 return 1;
1249}
1250
1251/* Perhaps these should be in player.c, but that file is
1252 * already a bit big.
1253 */
1254
1255void
1256receive_player_name (object *op, char k)
1257{
1258
1259 if (!check_name (op->contr, op->contr->write_buf + 1))
1260 {
1261 get_name (op);
1262 return;
1263 }
1264 op->name = op->contr->write_buf + 1;
1265 op->name_pl = op->contr->write_buf + 1;
1266 new_draw_info (NDI_UNIQUE, 0, op, op->contr->write_buf);
1267 op->contr->name_changed = 1;
1268 get_password (op);
1269}
1270
1271void
1272receive_player_password (object *op, char k)
1273{
1274
1275 unsigned int pwd_len = strlen (op->contr->write_buf);
1276
1277 if (pwd_len <= 1 || pwd_len > 17)
1278 {
1279 get_name (op);
1280 return;
1281 }
1282 new_draw_info (NDI_UNIQUE, 0, op, " "); /* To hide the password better */
1283
1284 if (checkbanned (op->name, op->contr->socket.host))
1285 {
1286 LOG (llevInfo, "Banned player tried to add: [%s@%s]\n", &op->name, op->contr->socket.host);
1287 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, "You are not allowed to play.");
1288 get_name (op);
1289 return;
1290 }
1291
1292 if (op->contr->state == ST_CONFIRM_PASSWORD)
1293 {
1294 if (!check_password (op->contr->write_buf + 1, op->contr->password))
1295 {
1296 new_draw_info (NDI_UNIQUE, 0, op, "The passwords did not match.");
1297 get_name (op);
1298 return;
1299 }
1300 clear_win_info (op);
1301 display_motd (op);
1302 new_draw_info (NDI_UNIQUE, 0, op, " ");
1303 new_draw_info (NDI_UNIQUE, 0, op, "Welcome, Brave New Warrior!");
1304 new_draw_info (NDI_UNIQUE, 0, op, " ");
1305 Roll_Again (op);
1306 op->contr->state = ST_ROLL_STAT;
1307 return;
1308 }
1309 strcpy (op->contr->password, crypt_string (op->contr->write_buf + 1, NULL));
1310 op->contr->state = ST_ROLL_STAT;
1311 check_login (op);
1312 return;
1313}
1314
1315
1316int
1317explore_mode (void)
1318{
1319 player *pl;
1320
1321 if (settings.explore_mode == TRUE)
1322 {
1323 for (pl = first_player; pl != (player *) NULL; pl = pl->next)
1324 if (pl->explore)
1325 return 1;
1326 }
1327 return 0;
1328}
1329
1330
1331int
1332command_title (object *op, char *params) 843command_title (object *op, char *params)
1333{ 844{
1334 char buf[MAX_BUF]; 845 char buf[MAX_BUF];
1335 846
1336 if (settings.set_title == FALSE) 847 if (settings.set_title == FALSE)
1373 strcpy (op->contr->own_title, params); 884 strcpy (op->contr->own_title, params);
1374 return 1; 885 return 1;
1375} 886}
1376 887
1377int 888int
1378command_save (object *op, char *params)
1379{
1380// if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_CLERIC) {
1381// new_draw_info(NDI_UNIQUE, 0, op, "You can not save on unholy ground");
1382// } else
1383 if (!op->stats.exp)
1384 {
1385 new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet.");
1386 }
1387 else
1388 {
1389 if (save_player (op, 1))
1390 new_draw_info (NDI_UNIQUE, 0, op, "You have been saved.");
1391 else
1392 new_draw_info (NDI_UNIQUE, 0, op, "SAVE FAILED!");
1393 }
1394 return 1;
1395}
1396
1397
1398int
1399command_peaceful (object *op, char *params)
1400{
1401 new_draw_info (NDI_UNIQUE, 0, op,
1402 "You cannot change your peaceful setting with this command."
1403 " Please speak to the priest in the temple of Gorokh"
1404 " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again.");
1405
1406/*
1407 if((op->contr->peaceful=!op->contr->peaceful))
1408 new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players.");
1409 else
1410 new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players.");
1411*/
1412 return 1;
1413}
1414
1415
1416
1417int
1418command_wimpy (object *op, char *params)
1419{
1420 int i;
1421 char buf[MAX_BUF];
1422
1423 if (params == NULL || !sscanf (params, "%d", &i))
1424 {
1425 sprintf (buf, "Your current wimpy level is %d.", op->run_away);
1426 new_draw_info (NDI_UNIQUE, 0, op, buf);
1427 return 1;
1428 }
1429 sprintf (buf, "Your new wimpy level is %d.", i);
1430 new_draw_info (NDI_UNIQUE, 0, op, buf);
1431 op->run_away = i;
1432 return 1;
1433}
1434
1435
1436int
1437command_brace (object *op, char *params)
1438{
1439 if (!params)
1440 op->contr->braced = !op->contr->braced;
1441 else
1442 op->contr->braced = onoff_value (params);
1443
1444 if (op->contr->braced)
1445 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1446 else
1447 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1448
1449 fix_player (op);
1450 return 0;
1451}
1452
1453int
1454command_style_map_info (object *op, char *params)
1455{
1456 extern maptile *styles;
1457 maptile *mp;
1458 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
1459 object *tmp;
1460
1461 for (mp = styles; mp != NULL; mp = mp->next)
1462 {
1463 maps_used++;
1464 mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile);
1465 for (x = 0; x < MAP_WIDTH (mp); x++)
1466 {
1467 for (y = 0; y < MAP_HEIGHT (mp); y++)
1468 {
1469 for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above)
1470 objects_used++;
1471 }
1472 }
1473 }
1474 new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used);
1475 new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not");
1476 new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem);
1477 new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used);
1478 new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object));
1479 return 0;
1480}
1481
1482int
1483command_kill_pets (object *op, char *params) 889command_kill_pets (object *op, char *params)
1484{ 890{
1485 objectlink *obl, *next; 891 objectlink *obl, *next;
1486 int counter = 0, removecount = 0; 892 int counter = 0, removecount = 0;
1487 893
1497 for (obl = first_friendly_object; obl != NULL; obl = next) 903 for (obl = first_friendly_object; obl != NULL; obl = next)
1498 { 904 {
1499 object *ob = obl->ob; 905 object *ob = obl->ob;
1500 906
1501 next = obl->next; 907 next = obl->next;
1502 if (get_owner (ob) == op) 908 if (ob->owner == op)
1503 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 909 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1504 { 910 {
1505 if (!QUERY_FLAG (ob, FLAG_REMOVED))
1506 remove_ob (ob);
1507 remove_friendly_object (ob);
1508 free_object (ob); 911 ob->destroy ();
1509 removecount++; 912 removecount++;
1510 } 913 }
1511 } 914 }
1512 if (removecount != 0) 915 if (removecount != 0)
1513 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); 916 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines