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

Comparing deliantra/server/server/c_misc.C (file contents):
Revision 1.13 by root, Mon Oct 2 00:22:01 2006 UTC vs.
Revision 1.49 by pippijn, Fri Mar 2 10:15:40 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)
430 331
431 if (params == NULL || !sscanf (params, "%d", &i)) 332 if (params == NULL || !sscanf (params, "%d", &i))
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;
436 }
437 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
438 {
439 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command.");
440 return 1; 336 return 1;
441 } 337 }
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);
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_dumpallobjects (object *op, char *params)
468{
469 dump_all_objects ();
470 return 0;
471}
472
473int
474command_dumpfriendlyobjects (object *op, char *params) 364command_dumpfriendlyobjects (object *op, char *params)
475{ 365{
476 dump_friendly_objects (); 366 dump_friendly_objects ();
477 return 0;
478}
479
480int
481command_dumpallarchetypes (object *op, char *params)
482{
483 dump_all_archetypes ();
484 return 0;
485}
486
487int
488command_dumpmap (object *op, char *params)
489{
490 if (op)
491 dump_map (op->map);
492 return 0;
493}
494
495int
496command_dumpallmaps (object *op, char *params)
497{
498 dump_all_maps ();
499 return 0; 367 return 0;
500} 368}
501 369
502int 370int
503command_printlos (object *op, char *params) 371command_printlos (object *op, char *params)
512command_version (object *op, char *params) 380command_version (object *op, char *params)
513{ 381{
514 version (op); 382 version (op);
515 return 0; 383 return 0;
516} 384}
517
518 385
519#ifndef BUG_LOG 386#ifndef BUG_LOG
520# define BUG_LOG "bug_log" 387# define BUG_LOG "bug_log"
521#endif 388#endif
522void 389void
577 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count."); 444 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
578 445
579 return 1; 446 return 1;
580} 447}
581 448
582int
583command_listen (object *op, char *params)
584{
585 int i;
586
587 if (params == NULL || !sscanf (params, "%d", &i))
588 {
589 new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening);
590 return 1;
591 }
592 op->contr->listening = (char) i;
593 new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i);
594 return 1;
595}
596
597/* Prints out some useful information for the character. Everything we print 449/* Prints out some useful information for the character. Everything we print
598 * out can be determined by the docs, so we aren't revealing anything extra - 450 * out can be determined by the docs, so we aren't revealing anything extra -
599 * rather, we are making it convenient to find the values. params have 451 * rather, we are making it convenient to find the values. params have
600 * no meaning here. 452 * no meaning here.
601 */ 453 */
602int 454int
603command_statistics (object *pl, char *params) 455command_statistics (object *pl, char *params)
604{ 456{
605 if (!pl->contr) 457 if (!pl->contr)
606 return 1; 458 return 1;
607#ifndef WIN32
608 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %lld", pl->stats.exp);
609 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %lld", level_exp (pl->level + 1, pl->expmul));
610#else
611 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %I64d", pl->stats.exp); 459 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
612 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %I64d", level_exp (pl->level + 1, pl->expmul)); 460 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
613#endif
614 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); 461 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
615 462
616 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 463 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d",
617 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); 464 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str);
618 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", 465 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d",
635 482
636int 483int
637command_fix_me (object *op, char *params) 484command_fix_me (object *op, char *params)
638{ 485{
639 sum_weight (op); 486 sum_weight (op);
640 fix_player (op); 487 op->update_stats ();
641 return 1;
642}
643
644int
645command_players (object *op, char *paramss)
646{
647 char buf[MAX_BUF];
648 char *t;
649 DIR *Dir;
650
651 sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir);
652 t = buf + strlen (buf);
653 if ((Dir = opendir (buf)) != NULL)
654 {
655 const struct dirent *Entry;
656
657 while ((Entry = readdir (Dir)) != NULL)
658 {
659 /* skip '.' , '..' */
660 if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') ||
661 (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0')))
662 {
663 struct stat Stat;
664
665 strcpy (t, Entry->d_name);
666 if (stat (buf, &Stat) == 0)
667 {
668 /* This was not posix compatible
669 * if ((Stat.st_mode & S_IFMT)==S_IFDIR) {
670 */
671 if (S_ISDIR (Stat.st_mode))
672 {
673 char buf2[MAX_BUF];
674 struct tm *tm = localtime (&Stat.st_mtime);
675
676 sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d",
677 Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
678 new_draw_info (NDI_UNIQUE, 0, op, buf2);
679 }
680 }
681 }
682 }
683 }
684 closedir (Dir);
685 return 0; 488 return 1;
686} 489}
687
688
689 490
690int 491int
691command_logs (object *op, char *params) 492command_logs (object *op, char *params)
692{ 493{
693 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); 494 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
716 else 517 else
717 { 518 {
718 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params); 519 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
719 return 0; 520 return 0;
720 } 521 }
522
721 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s", 523 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
722 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]); 524 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
723 return 1; 525 return 1;
724} 526}
725 527
747 found++; 549 found++;
748 op->contr->bowtype = (bowtype_t) i; 550 op->contr->bowtype = (bowtype_t) i;
749 break; 551 break;
750 } 552 }
751 } 553 }
554
752 if (!found) 555 if (!found)
753 { 556 {
754 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 557 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
755 for (i = 0; i <= bow_bestarrow; i++) 558 for (i = 0; i <= bow_bestarrow; i++)
756 { 559 {
762 strcat (buf, "."); 565 strcat (buf, ".");
763 } 566 }
764 new_draw_info_format (NDI_UNIQUE, 0, op, buf); 567 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
765 return 0; 568 return 0;
766 } 569 }
570
767 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); 571 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]);
768 return 1; 572 return 1;
769} 573}
770 574
771int 575int
810 for (obl = first_friendly_object; obl != NULL; obl = next) 614 for (obl = first_friendly_object; obl != NULL; obl = next)
811 { 615 {
812 object *ob = obl->ob; 616 object *ob = obl->ob;
813 617
814 next = obl->next; 618 next = obl->next;
815 if (get_owner (ob) == op) 619 if (ob->owner == op)
816 { 620 {
817 if (target == 0) 621 if (target == 0)
818 { 622 {
819 if (counter == 0) 623 if (counter == 0)
820 new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); 624 new_draw_info (NDI_UNIQUE, 0, op, "Pets:");
927 char filename[MAX_BUF], line[80]; 731 char filename[MAX_BUF], line[80];
928 int namelen, linelen = 0; 732 int namelen, linelen = 0;
929 733
930 switch (what) 734 switch (what)
931 { 735 {
932 case 1: 736 case 1:
933 sprintf (filename, "%s/wizhelp", settings.datadir); 737 sprintf (filename, "%s/wizhelp", settings.datadir);
934 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); 738 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
935 break; 739 break;
936 case 3: 740 case 3:
937 sprintf (filename, "%s/mischelp", settings.datadir); 741 sprintf (filename, "%s/mischelp", settings.datadir);
938 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); 742 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
939 break; 743 break;
940 default: 744 default:
941 sprintf (filename, "%s/help", settings.datadir); 745 sprintf (filename, "%s/help", settings.datadir);
942 new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); 746 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
943 break; 747 break;
944 } 748 }
749
945 if (!(dirp = opendir (filename))) 750 if (!(dirp = opendir (filename)))
946 return; 751 return;
947 752
948 line[0] = '\0'; 753 line[0] = '\0';
949 for (de = readdir (dirp); de; de = readdir (dirp)) 754 while ((de = readdir (dirp)))
950 { 755 {
951 namelen = NAMLEN (de); 756 namelen = strlen (de->d_name);
952 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) 757 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
953 continue; 758 continue;
954 linelen += namelen + 1; 759 linelen += namelen + 1;
955 if (linelen > 42) 760 if (linelen > 42)
956 { 761 {
1161 return 0; 966 return 0;
1162 } 967 }
1163} 968}
1164 969
1165int 970int
1166command_quit (object *op, char *params) 971command_sound (object *op, char *params)
1167{ 972{
1168 new_draw_info (NDI_UNIQUE, 0, op, 973 if (op->contr->ns->sound)
1169 "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit.");
1170 return 1;
1171}
1172
1173int
1174command_real_quit (object *op, char *params)
1175{
1176 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):");
1177
1178 op->contr->state = ST_CONFIRM_QUIT;
1179 return 1;
1180}
1181
1182/*
1183 * don't allow people to exit explore mode. It otherwise becomes
1184 * really easy to abuse this.
1185 */
1186int
1187command_explore (object *op, char *params)
1188{
1189 if (settings.explore_mode == FALSE)
1190 return 1;
1191 /*
1192 * I guess this is the best way to see if we are solo or not. Actually,
1193 * are there any cases when first_player->next==NULL and we are not solo?
1194 */
1195 if ((first_player != op->contr) || (first_player->next != NULL))
1196 {
1197 new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party");
1198 } 974 {
1199 else if (op->contr->explore) 975 op->contr->ns->sound = 0;
1200 new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode"); 976 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
977 }
1201 else 978 else
1202 { 979 {
1203 op->contr->explore = 1;
1204 new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode");
1205 }
1206 return 1;
1207}
1208
1209int
1210command_sound (object *op, char *params)
1211{
1212 if (op->contr->socket.sound)
1213 {
1214 op->contr->socket.sound = 0;
1215 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
1216 }
1217 else
1218 {
1219 op->contr->socket.sound = 1; 980 op->contr->ns->sound = 1;
1220 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled."); 981 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1221 } 982 }
1222 return 1;
1223}
1224 983
1225/* Perhaps these should be in player.c, but that file is
1226 * already a bit big.
1227 */
1228
1229void
1230receive_player_name (object *op, char k)
1231{
1232
1233 if (!check_name (op->contr, op->contr->write_buf + 1))
1234 {
1235 get_name (op);
1236 return;
1237 }
1238 op->name = op->contr->write_buf + 1;
1239 op->name_pl = op->contr->write_buf + 1;
1240 new_draw_info (NDI_UNIQUE, 0, op, op->contr->write_buf);
1241 op->contr->name_changed = 1;
1242 get_password (op);
1243}
1244
1245void
1246receive_player_password (object *op, char k)
1247{
1248
1249 unsigned int pwd_len = strlen (op->contr->write_buf);
1250
1251 if (pwd_len <= 1 || pwd_len > 17)
1252 {
1253 get_name (op);
1254 return;
1255 }
1256 new_draw_info (NDI_UNIQUE, 0, op, " "); /* To hide the password better */
1257
1258 if (checkbanned (op->name, op->contr->socket.host))
1259 {
1260 LOG (llevInfo, "Banned player tried to add: [%s@%s]\n", &op->name, op->contr->socket.host);
1261 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, "You are not allowed to play.");
1262 get_name (op);
1263 return;
1264 }
1265
1266 if (op->contr->state == ST_CONFIRM_PASSWORD)
1267 {
1268 if (!check_password (op->contr->write_buf + 1, op->contr->password))
1269 {
1270 new_draw_info (NDI_UNIQUE, 0, op, "The passwords did not match.");
1271 get_name (op);
1272 return;
1273 }
1274 clear_win_info (op);
1275 display_motd (op);
1276 new_draw_info (NDI_UNIQUE, 0, op, " ");
1277 new_draw_info (NDI_UNIQUE, 0, op, "Welcome, Brave New Warrior!");
1278 new_draw_info (NDI_UNIQUE, 0, op, " ");
1279 Roll_Again (op);
1280 op->contr->state = ST_ROLL_STAT;
1281 return;
1282 }
1283 strcpy (op->contr->password, crypt_string (op->contr->write_buf + 1, NULL));
1284 op->contr->state = ST_ROLL_STAT;
1285 check_login (op);
1286 return;
1287}
1288
1289
1290int
1291explore_mode (void)
1292{
1293 player *pl;
1294
1295 if (settings.explore_mode == TRUE)
1296 {
1297 for (pl = first_player; pl != (player *) NULL; pl = pl->next)
1298 if (pl->explore)
1299 return 1;
1300 }
1301 return 0; 984 return 1;
1302} 985}
1303
1304 986
1305int 987int
1306command_title (object *op, char *params) 988command_title (object *op, char *params)
1307{ 989{
1308 char buf[MAX_BUF]; 990 char buf[MAX_BUF];
1347 strcpy (op->contr->own_title, params); 1029 strcpy (op->contr->own_title, params);
1348 return 1; 1030 return 1;
1349} 1031}
1350 1032
1351int 1033int
1352command_save (object *op, char *params)
1353{
1354// if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_CLERIC) {
1355// new_draw_info(NDI_UNIQUE, 0, op, "You can not save on unholy ground");
1356// } else
1357 if (!op->stats.exp)
1358 {
1359 new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet.");
1360 }
1361 else
1362 {
1363 if (save_player (op, 1))
1364 new_draw_info (NDI_UNIQUE, 0, op, "You have been saved.");
1365 else
1366 new_draw_info (NDI_UNIQUE, 0, op, "SAVE FAILED!");
1367 }
1368 return 1;
1369}
1370
1371
1372int
1373command_peaceful (object *op, char *params)
1374{
1375 new_draw_info (NDI_UNIQUE, 0, op,
1376 "You cannot change your peaceful setting with this command."
1377 " Please speak to the priest in the temple of Gorokh"
1378 " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again.");
1379
1380/*
1381 if((op->contr->peaceful=!op->contr->peaceful))
1382 new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players.");
1383 else
1384 new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players.");
1385*/
1386 return 1;
1387}
1388
1389
1390
1391int
1392command_wimpy (object *op, char *params)
1393{
1394 int i;
1395 char buf[MAX_BUF];
1396
1397 if (params == NULL || !sscanf (params, "%d", &i))
1398 {
1399 sprintf (buf, "Your current wimpy level is %d.", op->run_away);
1400 new_draw_info (NDI_UNIQUE, 0, op, buf);
1401 return 1;
1402 }
1403 sprintf (buf, "Your new wimpy level is %d.", i);
1404 new_draw_info (NDI_UNIQUE, 0, op, buf);
1405 op->run_away = i;
1406 return 1;
1407}
1408
1409
1410int
1411command_brace (object *op, char *params)
1412{
1413 if (!params)
1414 op->contr->braced = !op->contr->braced;
1415 else
1416 op->contr->braced = onoff_value (params);
1417
1418 if (op->contr->braced)
1419 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1420 else
1421 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1422
1423 fix_player (op);
1424 return 0;
1425}
1426
1427int
1428command_style_map_info (object *op, char *params)
1429{
1430 extern maptile *styles;
1431 maptile *mp;
1432 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
1433 object *tmp;
1434
1435 for (mp = styles; mp != NULL; mp = mp->next)
1436 {
1437 maps_used++;
1438 mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile);
1439 for (x = 0; x < MAP_WIDTH (mp); x++)
1440 {
1441 for (y = 0; y < MAP_HEIGHT (mp); y++)
1442 {
1443 for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above)
1444 objects_used++;
1445 }
1446 }
1447 }
1448 new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used);
1449 new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not");
1450 new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem);
1451 new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used);
1452 new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object));
1453 return 0;
1454}
1455
1456int
1457command_kill_pets (object *op, char *params) 1034command_kill_pets (object *op, char *params)
1458{ 1035{
1459 objectlink *obl, *next; 1036 objectlink *obl, *next;
1460 int counter = 0, removecount = 0; 1037 int counter = 0, removecount = 0;
1461 1038
1471 for (obl = first_friendly_object; obl != NULL; obl = next) 1048 for (obl = first_friendly_object; obl != NULL; obl = next)
1472 { 1049 {
1473 object *ob = obl->ob; 1050 object *ob = obl->ob;
1474 1051
1475 next = obl->next; 1052 next = obl->next;
1476 if (get_owner (ob) == op) 1053 if (ob->owner == op)
1477 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 1054 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1478 { 1055 {
1479 if (!QUERY_FLAG (ob, FLAG_REMOVED))
1480 remove_ob (ob);
1481 remove_friendly_object (ob);
1482 free_object (ob); 1056 ob->destroy ();
1483 removecount++; 1057 removecount++;
1484 } 1058 }
1485 } 1059 }
1486 if (removecount != 0) 1060 if (removecount != 0)
1487 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); 1061 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines