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

Comparing deliantra/server/server/c_wiz.C (file contents):
Revision 1.8 by root, Sun Sep 10 13:20:27 2006 UTC vs.
Revision 1.28 by root, Sat Dec 30 10:16:11 2006 UTC

1
2/*
3 * static char *rcsid_c_wiz_c =
4 * "$Id: c_wiz.C,v 1.8 2006/09/10 13:20:27 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <global.h> 24#include <global.h>
31#ifndef __CEXTRACT__ 25#ifndef __CEXTRACT__
32# include <sproto.h> 26# include <sproto.h>
53 * other player, or NULL otherwise. 47 * other player, or NULL otherwise.
54 */ 48 */
55static player * 49static player *
56get_other_player_from_name (object *op, char *name) 50get_other_player_from_name (object *op, char *name)
57{ 51{
58 player *pl;
59
60 if (!name) 52 if (!name)
61 return NULL; 53 return NULL;
62 54
63 for (pl = first_player; pl != NULL; pl = pl->next) 55 for_all_players (pl)
64 if (!strncmp (pl->ob->name, name, MAX_NAME)) 56 if (!strncmp (pl->ob->name, name, MAX_NAME))
65 break;
66
67 if (pl == NULL)
68 { 57 {
69 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
70 return NULL;
71 }
72
73 if (pl->ob == op) 58 if (pl->ob == op)
74 { 59 {
75 new_draw_info (NDI_UNIQUE, 0, op, "You can't do that to yourself."); 60 new_draw_info (NDI_UNIQUE, 0, op, "You can't do that to yourself.");
76 return NULL; 61 return NULL;
77 } 62 }
63
78 if (pl->state != ST_PLAYING) 64 if (pl->ns->state != ST_PLAYING)
79 { 65 {
80 new_draw_info (NDI_UNIQUE, 0, op, "That player is in no state for that right now."); 66 new_draw_info (NDI_UNIQUE, 0, op, "That player is in no state for that right now.");
81 return NULL; 67 return NULL;
82 }
83 return pl;
84}
85
86/**
87 * This command will stress server.
88 */
89int
90command_loadtest (object *op, char *params)
91{
92 uint32 x, y;
93 char buf[1024];
94
95 new_draw_info (NDI_UNIQUE, 0, op, "loadtest will stress server through teleporting");
96 new_draw_info (NDI_UNIQUE, 0, op, "at different map places.");
97 new_draw_info (NDI_UNIQUE, 0, op, "use at your own risks.");
98 new_draw_info (NDI_UNIQUE, 0, op, "Very long loop used so server may have to be reset.");
99 new_draw_info (NDI_UNIQUE, 0, op, "type loadtest TRUE to run");
100 new_draw_info_format (NDI_UNIQUE, 0, op, "{%s}", params);
101 if (!params)
102 return 0;
103 if (strncmp (params, "TRUE", 4))
104 return 0;
105
106 new_draw_info_format (NDI_UNIQUE, 0, op, "gogogo");
107 for (x = 0; x < settings.worldmaptilesx; x++)
108 {
109 for (y = 0; y < settings.worldmaptilesy; y++)
110 {
111 sprintf (buf, "/world/world_%d_%d", x + settings.worldmapstartx, y + settings.worldmapstarty);
112 command_goto (op, buf);
113 } 68 }
69
70 return pl;
114 } 71 }
115 72
73 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
116 return 0; 74 return 0;
117} 75}
118 76
119/** 77/**
120 * Actually hides specified player (obviously a DM). 78 * Actually hides specified player (obviously a DM).
164static object * 122static object *
165find_object_both (char *params) 123find_object_both (char *params)
166{ 124{
167 if (!params) 125 if (!params)
168 return NULL; 126 return NULL;
127
169 if (params[0] == '#') 128 if (params[0] == '#')
170 return find_object (atol (params + 1)); 129 return find_object (atol (params + 1));
171 else 130 else
172 return find_object_name (params); 131 return find_object_name (params);
173} 132}
254 now = time (NULL); 213 now = time (NULL);
255 /* 214 /*
256 * Record this as a comment - then we don't have to worry about changing 215 * Record this as a comment - then we don't have to worry about changing
257 * the parsing code. 216 * the parsing code.
258 */ 217 */
259 fprintf (banishfile, "# %s (%s) banned by %s at %s\n", &pl->ob->name, pl->socket.host, &op->name, ctime (&now)); 218 fprintf (banishfile, "# %s (%s) banned by %s at %s\n", &pl->ob->name, pl->ns->host, &op->name, ctime (&now));
260 fprintf (banishfile, "*@%s\n", pl->socket.host); 219 fprintf (banishfile, "*@%s\n", pl->ns->host);
261 fclose (banishfile); 220 fclose (banishfile);
262 221
263 LOG (llevDebug, "! %s banned %s from IP: %s.\n", &op->name, &pl->ob->name, pl->socket.host); 222 LOG (llevDebug, "! %s banned %s from IP: %s.\n", &op->name, &pl->ob->name, pl->ns->host);
264 new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, op, "You banish %s", &pl->ob->name); 223 new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, op, "You banish %s", &pl->ob->name);
265 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s banishes %s from the land!", &op->name, &pl->ob->name); 224 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s banishes %s from the land!", &op->name, &pl->ob->name);
266 command_kick (op, (char *) &pl->ob->name); 225 command_kick (op, (char *) &pl->ob->name);
267 return 1; 226 return 1;
268} 227}
269 228
270int 229int
271command_kick (object *op, char *params) 230command_kick (object *op, char *params)
272{ 231{
273 struct pl *pl; 232 for_all_players (pl)
274
275 for (pl = first_player; pl != NULL; pl = pl->next)
276 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params))) 233 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params)))
277 { 234 {
278 object *op = pl->ob; 235 object *op = pl->ob;
279 236
280 if (!QUERY_FLAG (op, FLAG_REMOVED) && !QUERY_FLAG (op, FLAG_FREED)) 237 if (!QUERY_FLAG (op, FLAG_REMOVED) && !QUERY_FLAG (op, FLAG_FREED))
281 { 238 {
282 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &op->name); 239 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &op->name);
283 strcpy (op->contr->killer, "kicked"); 240 strcpy (op->contr->killer, "kicked");
284 } 241 }
285 242
286 pl->socket.status = Ns_Dead; 243 pl->ns->destroy ();
287 } 244 }
288 245
289 return 1; 246 return 1;
290} 247}
291 248
249//TODO
250#if 0
292int 251int
293command_save_overlay (object *op, char *params) 252command_save_overlay (object *op, char *params)
294{ 253{
295 if (!op) 254 if (!op)
296 return 0; 255 return 0;
307 266
308 ready_map_name (op->map->path, 0); 267 ready_map_name (op->map->path, 0);
309 268
310 return 1; 269 return 1;
311} 270}
271#endif
312 272
313int 273int
314command_shutdown (object *op, char *params) 274command_shutdown (object *op, char *params)
315{ 275{
316 struct pl *pl;
317
318 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) 276 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
319 { 277 {
320 new_draw_info (NDI_UNIQUE, 0, op, "Sorry, you can't shutdown the server."); 278 new_draw_info (NDI_UNIQUE, 0, op, "Sorry, you can't shutdown the server.");
321 return 1; 279 return 1;
322 } 280 }
323 281
324 for (pl = first_player; pl != NULL; pl = pl->next)
325 save_player (pl->ob, 0);
326
327 for (pl = first_player; pl != NULL; pl = pl->next)
328 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
329 leave_map (pl->ob);
330
331 cleanup (); 282 cleanup (0);
283
332 /* not reached */ 284 /* not reached */
333 return 1;
334}
335
336int
337command_goto (object *op, char *params)
338{
339 char *name;
340 object *dummy;
341
342 if (!op)
343 return 0;
344
345 if (params == NULL)
346 {
347 new_draw_info (NDI_UNIQUE, 0, op, "Go to what level?");
348 return 1;
349 }
350
351 name = params;
352 dummy = get_object ();
353 dummy->map = op->map;
354 EXIT_PATH (dummy) = name;
355 dummy->name = name;
356
357 enter_exit (op, dummy);
358 free_object (dummy);
359 if (op->contr->loading == NULL)
360 {
361 new_draw_info_format (NDI_UNIQUE, 0, op, "Difficulty: %d.", op->map->difficulty);
362 }
363
364 return 1;
365}
366
367/* is this function called from somewhere ? -Tero */
368int
369command_generate (object *op, char *params)
370{
371 object *tmp;
372 int nr = 1, i, retry;
373
374 if (!op)
375 return 0;
376
377 if (params != NULL)
378 sscanf (params, "%d", &nr);
379 for (i = 0; i < nr; i++)
380 {
381 retry = 50;
382 while ((tmp = generate_treasure (0, op->map->difficulty)) == NULL && --retry)
383 ;
384 if (tmp != NULL)
385 {
386 tmp = insert_ob_in_ob (tmp, op);
387 if (op->type == PLAYER)
388 esrv_send_item (op, tmp);
389 }
390 }
391
392 return 1; 285 return 1;
393} 286}
394 287
395int 288int
396command_freeze (object *op, char *params) 289command_freeze (object *op, char *params)
434 object *dummy; 327 object *dummy;
435 player *pl; 328 player *pl;
436 329
437 if (!op) 330 if (!op)
438 return 0; 331 return 0;
332
439 if (params == NULL) 333 if (params == NULL)
440 { 334 {
441 new_draw_info (NDI_UNIQUE, 0, op, "Usage: arrest <player>."); 335 new_draw_info (NDI_UNIQUE, 0, op, "Usage: arrest <player>.");
442 return 1; 336 return 1;
443 } 337 }
338
444 pl = get_other_player_from_name (op, params); 339 pl = get_other_player_from_name (op, params);
445 if (!pl) 340 if (!pl)
446 return 1; 341 return 1;
342
447 dummy = get_jail_exit (pl->ob); 343 dummy = get_jail_exit (pl->ob);
448 if (!dummy) 344 if (!dummy)
449 { 345 {
450 /* we have nowhere to send the prisoner.... */ 346 /* we have nowhere to send the prisoner.... */
451 new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them"); 347 new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them");
452 return 0; 348 return 0;
453 } 349 }
454 enter_exit (pl->ob, dummy); 350
455 free_object (dummy); 351 pl->ob->enter_exit (dummy);
352 dummy->destroy ();
456 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested."); 353 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested.");
457 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 354 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
458 LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name); 355 LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name);
459 return 1; 356 return 1;
460} 357}
484 { 381 {
485 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); 382 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player.");
486 return 1; 383 return 1;
487 } 384 }
488 385
489 dummy = get_object (); 386 dummy = object::create ();
490 EXIT_PATH (dummy) = op->map->path; 387 EXIT_PATH (dummy) = op->map->path;
491 EXIT_X (dummy) = op->x + freearr_x[i]; 388 EXIT_X (dummy) = op->x + freearr_x[i];
492 EXIT_Y (dummy) = op->y + freearr_y[i]; 389 EXIT_Y (dummy) = op->y + freearr_y[i];
493 enter_exit (pl->ob, dummy); 390 pl->ob->enter_exit (dummy);
494 free_object (dummy); 391 dummy->destroy ();
495 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); 392 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned.");
496 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 393 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
497 394
498 return 1; 395 return 1;
499} 396}
528 { 425 {
529 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to teleport to."); 426 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to teleport to.");
530 return 1; 427 return 1;
531 } 428 }
532 429
533 dummy = get_object (); 430 dummy = object::create ();
534 EXIT_PATH (dummy) = pl->ob->map->path; 431 EXIT_PATH (dummy) = pl->ob->map->path;
535 EXIT_X (dummy) = pl->ob->x + freearr_x[i]; 432 EXIT_X (dummy) = pl->ob->x + freearr_x[i];
536 EXIT_Y (dummy) = pl->ob->y + freearr_y[i]; 433 EXIT_Y (dummy) = pl->ob->y + freearr_y[i];
537 enter_exit (op, dummy); 434 op->enter_exit (dummy);
538 free_object (dummy); 435 dummy->destroy ();
539 if (!op->contr->hidden) 436 if (!op->contr->hidden)
540 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You see a portal open."); 437 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You see a portal open.");
541 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 438 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
542 return 1; 439 return 1;
543} 440}
572 if (params == NULL) 469 if (params == NULL)
573 { 470 {
574 new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]"); 471 new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]");
575 return 1; 472 return 1;
576 } 473 }
474
577 bp = params; 475 bp = params;
578 476
579 /* We need to know where the line ends */ 477 /* We need to know where the line ends */
580 endline = bp + strlen (bp); 478 endline = bp + strlen (bp);
581 479
588 } 486 }
589 bp++; 487 bp++;
590 set_nrof = 1; 488 set_nrof = 1;
591 LOG (llevDebug, "%s creates: (%d) %s\n", &op->name, nrof, bp); 489 LOG (llevDebug, "%s creates: (%d) %s\n", &op->name, nrof, bp);
592 } 490 }
491
593 if (sscanf (bp, "%d ", &magic)) 492 if (sscanf (bp, "%d ", &magic))
594 { 493 {
595 if ((bp = strchr (bp, ' ')) == NULL) 494 if ((bp = strchr (bp, ' ')) == NULL)
596 { 495 {
597 new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]"); 496 new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]");
598 return 1; 497 return 1;
599 } 498 }
499
600 bp++; 500 bp++;
601 set_magic = 1; 501 set_magic = 1;
602 LOG (llevDebug, "%s creates: (%d) (%d) %s\n", &op->name, nrof, magic, bp); 502 LOG (llevDebug, "%s creates: (%d) (%d) %s\n", &op->name, nrof, magic, bp);
603 } 503 }
504
604 if ((cp = strstr (bp, " of ")) != NULL) 505 if ((cp = strstr (bp, " of ")) != NULL)
605 { 506 {
606 *cp = '\0'; 507 *cp = '\0';
607 cp += 4; 508 cp += 4;
608 } 509 }
510
609 for (bp2 = bp; *bp2; bp2++) 511 for (bp2 = bp; *bp2; bp2++)
610 { 512 {
611 if (*bp2 == ' ') 513 if (*bp2 == ' ')
612 { 514 {
613 *bp2 = '\0'; 515 *bp2 = '\0';
614 bp2++; 516 bp2++;
615 break; 517 break;
616 } 518 }
617 } 519 }
618 520
619 if ((at = find_archetype (bp)) == NULL) 521 if ((at = archetype::find (bp)) == NULL)
620 { 522 {
621 new_draw_info (NDI_UNIQUE, 0, op, "No such archetype."); 523 new_draw_info (NDI_UNIQUE, 0, op, "No such archetype.");
622 return 1; 524 return 1;
623 } 525 }
624 526
630 * Try to find a spell object for this. Note that 532 * Try to find a spell object for this. Note that
631 * we also set up spell_name which is only 533 * we also set up spell_name which is only
632 * the first word. 534 * the first word.
633 */ 535 */
634 536
635 at_spell = find_archetype (cp); 537 at_spell = archetype::find (cp);
636 if (!at_spell || at_spell->clone.type != SPELL) 538 if (!at_spell || at_spell->clone.type != SPELL)
637 at_spell = find_archetype_by_object_name (cp); 539 at_spell = find_archetype_by_object_name (cp);
638 if (!at_spell || at_spell->clone.type != SPELL) 540 if (!at_spell || at_spell->clone.type != SPELL)
639 { 541 {
640 strcpy (spell_name, cp); 542 strcpy (spell_name, cp);
641 fsp = strchr (spell_name, ' '); 543 fsp = strchr (spell_name, ' ');
642 if (fsp) 544 if (fsp)
643 { 545 {
644 *fsp = 0; 546 *fsp = 0;
645 fsp++; 547 fsp++;
646 at_spell = find_archetype (spell_name); 548 at_spell = archetype::find (spell_name);
647 549
648 /* Got a spell, update the first string pointer */ 550 /* Got a spell, update the first string pointer */
649 if (at_spell && at_spell->clone.type == SPELL) 551 if (at_spell && at_spell->clone.type == SPELL)
650 bp2 = cp + strlen (spell_name) + 1; 552 bp2 = cp + strlen (spell_name) + 1;
651 else 553 else
657 * in this case means its an artifact. 559 * in this case means its an artifact.
658 */ 560 */
659 if (!at_spell) 561 if (!at_spell)
660 { 562 {
661 if (find_artifactlist (at->clone.type) == NULL) 563 if (find_artifactlist (at->clone.type) == NULL)
662 {
663 new_draw_info_format (NDI_UNIQUE, 0, op, "No artifact list for type %d\n", at->clone.type); 564 new_draw_info_format (NDI_UNIQUE, 0, op, "No artifact list for type %d\n", at->clone.type);
664 }
665 else 565 else
666 { 566 {
667 art = find_artifactlist (at->clone.type)->items; 567 art = find_artifactlist (at->clone.type)->items;
668 568
669 do 569 do
671 if (!strcmp (art->item->name, cp)) 571 if (!strcmp (art->item->name, cp))
672 break; 572 break;
673 art = art->next; 573 art = art->next;
674 } 574 }
675 while (art != NULL); 575 while (art != NULL);
576
676 if (!art) 577 if (!art)
677 {
678 new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->clone.type, cp); 578 new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->clone.type, cp);
679 }
680 } 579 }
580
681 LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp); 581 LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp);
682 } 582 }
683 } /* if cp */ 583 } /* if cp */
684 584
685 if ((at->clone.type == ROD || at->clone.type == WAND || at->clone.type == SCROLL || 585 if ((at->clone.type == ROD || at->clone.type == WAND || at->clone.type == SCROLL ||
693 * Rather than have two different blocks with a lot of similar code, 593 * Rather than have two different blocks with a lot of similar code,
694 * just create one object, do all the processing, and then determine 594 * just create one object, do all the processing, and then determine
695 * if that one object should be inserted or if we need to make copies. 595 * if that one object should be inserted or if we need to make copies.
696 */ 596 */
697 tmp = arch_to_object (at); 597 tmp = arch_to_object (at);
598
698 if (settings.real_wiz == FALSE) 599 if (settings.real_wiz == FALSE)
699 SET_FLAG (tmp, FLAG_WAS_WIZ); 600 SET_FLAG (tmp, FLAG_WAS_WIZ);
601
700 if (set_magic) 602 if (set_magic)
701 set_abs_magic (tmp, magic); 603 set_abs_magic (tmp, magic);
604
702 if (art) 605 if (art)
703 give_artifact_abilities (tmp, art->item); 606 give_artifact_abilities (tmp, art->item);
607
704 if (need_identify (tmp)) 608 if (need_identify (tmp))
705 { 609 {
706 SET_FLAG (tmp, FLAG_IDENTIFIED); 610 SET_FLAG (tmp, FLAG_IDENTIFIED);
707 CLEAR_FLAG (tmp, FLAG_KNOWN_MAGICAL); 611 CLEAR_FLAG (tmp, FLAG_KNOWN_MAGICAL);
708 } 612 }
717 while (*bp2 && bp2 <= endline) 621 while (*bp2 && bp2 <= endline)
718 { 622 {
719 bp4 = NULL; 623 bp4 = NULL;
720 gotspace = 0; 624 gotspace = 0;
721 gotquote = 0; 625 gotquote = 0;
626
722 /* find the first quote */ 627 /* find the first quote */
723 for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) 628 for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++)
724 { 629 {
725 630
726 /* Found a quote - now lets find the second one */ 631 /* Found a quote - now lets find the second one */
740 else 645 else
741 bp3++; 646 bp3++;
742 } 647 }
743 } 648 }
744 else if (*bp3 == ' ') 649 else if (*bp3 == ' ')
745 {
746 gotspace++; 650 gotspace++;
747 }
748 } 651 }
749 652
750 /* 653 /*
751 * If we got two spaces, send the second one to null. 654 * If we got two spaces, send the second one to null.
752 * if we've reached the end of the line, increase gotspace - 655 * if we've reached the end of the line, increase gotspace -
770 * anyways. 673 * anyways.
771 */ 674 */
772 new_draw_info_format (NDI_UNIQUE, 0, op, "Malformed create line: %s", bp2); 675 new_draw_info_format (NDI_UNIQUE, 0, op, "Malformed create line: %s", bp2);
773 break; 676 break;
774 } 677 }
678
775 /* bp2 should still point to the start of this line, 679 /* bp2 should still point to the start of this line,
776 * with bp3 pointing to the end 680 * with bp3 pointing to the end
777 */ 681 */
778 if (set_variable (tmp, bp2) == -1) 682 if (set_variable (tmp, bp2) == -1)
779 new_draw_info_format (NDI_UNIQUE, 0, op, "Unknown variable %s", bp2); 683 new_draw_info_format (NDI_UNIQUE, 0, op, "Unknown variable %s", bp2);
780 else 684 else
781 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2); 685 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2);
686
782 bp2 = bp3 + 1; 687 bp2 = bp3 + 1;
783 } 688 }
784 689
785 if (at->clone.nrof) 690 if (at->clone.nrof)
786 { 691 {
787 if (at_spell) 692 if (at_spell)
788 insert_ob_in_ob (arch_to_object (at_spell), tmp); 693 insert_ob_in_ob (arch_to_object (at_spell), tmp);
789 694
790 tmp->x = op->x; 695 tmp->x = op->x;
791 tmp->y = op->y; 696 tmp->y = op->y;
697
792 if (set_nrof) 698 if (set_nrof)
793 tmp->nrof = nrof; 699 tmp->nrof = nrof;
700
794 tmp->map = op->map; 701 tmp->map = op->map;
795 702
796 tmp = insert_ob_in_ob (tmp, op); 703 tmp = insert_ob_in_ob (tmp, op);
797 esrv_send_item (op, tmp); 704 esrv_send_item (op, tmp);
798 705
804 else 711 else
805 { 712 {
806 for (i = 0; i < (set_nrof ? nrof : 1); i++) 713 for (i = 0; i < (set_nrof ? nrof : 1); i++)
807 { 714 {
808 archetype *atmp; 715 archetype *atmp;
809 object *prev = NULL, *head = NULL, *dup; 716 object *prev = 0, *head = 0;
810 717
811 for (atmp = at; atmp != NULL; atmp = atmp->more) 718 for (atmp = at; atmp; atmp = atmp->more)
812 { 719 {
813 dup = arch_to_object (atmp); 720 object *dup = arch_to_object (atmp);
814 721
815 if (at_spell) 722 if (at_spell)
816 insert_ob_in_ob (arch_to_object (at_spell), dup); 723 insert_ob_in_ob (arch_to_object (at_spell), dup);
817 724
818 /* 725 /*
819 * The head is what contains all the important bits, 726 * The head is what contains all the important bits,
820 * so just copying it over should be fine. 727 * so just copying it over should be fine.
821 */ 728 */
822 if (head == NULL) 729 if (!head)
823 { 730 {
824 head = dup; 731 head = dup;
825 copy_object (tmp, dup); 732 tmp->copy_to (dup);
826 } 733 }
734
827 if (settings.real_wiz == FALSE) 735 if (settings.real_wiz == FALSE)
828 SET_FLAG (dup, FLAG_WAS_WIZ); 736 SET_FLAG (dup, FLAG_WAS_WIZ);
737
829 dup->x = op->x + dup->arch->clone.x; 738 dup->x = op->x + dup->arch->clone.x;
830 dup->y = op->y + dup->arch->clone.y; 739 dup->y = op->y + dup->arch->clone.y;
831 dup->map = op->map; 740 dup->map = op->map;
832 741
833 if (head != dup) 742 if (head != dup)
834 { 743 {
835 dup->head = head; 744 dup->head = head;
836 prev->more = dup; 745 prev->more = dup;
837 } 746 }
747
838 prev = dup; 748 prev = dup;
839 } 749 }
840 750
841 if (QUERY_FLAG (head, FLAG_ALIVE)) 751 if (QUERY_FLAG (head, FLAG_ALIVE))
842 { 752 {
854 if (out_of_map (op->map, head->x + size_x, head->y + size_y)) 764 if (out_of_map (op->map, head->x + size_x, head->y + size_y))
855 { 765 {
856 if (head->x < size_x || head->y < size_y) 766 if (head->x < size_x || head->y < size_y)
857 { 767 {
858 dm_stack_pop (op->contr); 768 dm_stack_pop (op->contr);
859 free_object (head); 769 head->destroy ();
860 new_draw_info (NDI_UNIQUE, 0, op, "Object too big to insert in map, or wrong position."); 770 new_draw_info (NDI_UNIQUE, 0, op, "Object too big to insert in map, or wrong position.");
861 free_object (tmp); 771 tmp->destroy ();
862 return 1; 772 return 1;
863 } 773 }
864 774
865 check = head; 775 check = head;
776
866 while (check) 777 while (check)
867 { 778 {
868 check->x -= size_x; 779 check->x -= size_x;
869 check->y -= size_y; 780 check->y -= size_y;
870 check = check->more; 781 check = check->more;
882 */ 793 */
883 dm_stack_push (op->contr, head->count); 794 dm_stack_push (op->contr, head->count);
884 795
885 if (at->clone.randomitems != NULL && !at_spell) 796 if (at->clone.randomitems != NULL && !at_spell)
886 create_treasure (at->clone.randomitems, head, GT_APPLY, op->map->difficulty, 0); 797 create_treasure (at->clone.randomitems, head, GT_APPLY, op->map->difficulty, 0);
798
887 esrv_send_item (op, head); 799 esrv_send_item (op, head);
888 } 800 }
889 801
890 /* free the one we used to copy */ 802 /* free the one we used to copy */
891 free_object (tmp); 803 tmp->destroy ();
892 } 804 }
893 805
894 return 1; 806 return 1;
895} 807}
896 808
938 850
939 tmp = get_dm_object (op->contr, &params, NULL); 851 tmp = get_dm_object (op->contr, &params, NULL);
940 if (!tmp) 852 if (!tmp)
941 return 1; 853 return 1;
942 854
943 dump_object (tmp); 855 char *dump = dump_object (tmp);
944 new_draw_info (NDI_UNIQUE, 0, op, errmsg); 856 new_draw_info (NDI_UNIQUE, 0, op, dump);
857 free (dump);
858
945 if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL)) 859 if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL))
946 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); 860 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original");
861
947 return 1; 862 return 1;
948} 863}
949 864
950/** 865/**
951 * When DM is possessing a monster, flip aggression on and off, to allow 866 * When DM is possessing a monster, flip aggression on and off, to allow
1042 victim->body_info[i] = 1; 957 victim->body_info[i] = 1;
1043 958
1044 esrv_new_player (pl, 80); /* just pick a wieght, we don't care */ 959 esrv_new_player (pl, 80); /* just pick a wieght, we don't care */
1045 esrv_send_inventory (victim, victim); 960 esrv_send_inventory (victim, victim);
1046 961
1047 fix_player (victim); 962 victim->update_stats ();
1048 963
1049 do_some_living (victim); 964 do_some_living (victim);
1050 return 1; 965 return 1;
1051} 966}
1052 967
1113 dm_stack_pop (op->contr); 1028 dm_stack_pop (op->contr);
1114 1029
1115 /* Always work on the head - otherwise object will get in odd state */ 1030 /* Always work on the head - otherwise object will get in odd state */
1116 if (tmp->head) 1031 if (tmp->head)
1117 tmp = tmp->head; 1032 tmp = tmp->head;
1118 remove_ob (tmp); 1033 tmp->remove ();
1119 return 1; 1034 return 1;
1120} 1035}
1121 1036
1122int 1037int
1123command_free (object *op, char *params) 1038command_free (object *op, char *params)
1138 dm_stack_pop (op->contr); 1053 dm_stack_pop (op->contr);
1139 1054
1140 if (!QUERY_FLAG (tmp, FLAG_REMOVED)) 1055 if (!QUERY_FLAG (tmp, FLAG_REMOVED))
1141 { 1056 {
1142 new_draw_info (NDI_UNIQUE, 0, op, "Warning, item wasn't removed."); 1057 new_draw_info (NDI_UNIQUE, 0, op, "Warning, item wasn't removed.");
1143 remove_ob (tmp); 1058 tmp->remove ();
1144 } 1059 }
1145 1060
1146 if (tmp->head) 1061 if (tmp->head)
1147 tmp = tmp->head; 1062 tmp = tmp->head;
1148 free_object (tmp); 1063
1064 tmp->destroy ();
1149 return 1; 1065 return 1;
1150} 1066}
1151 1067
1152/** 1068/**
1153 * This adds exp to a player. We now allow adding to a specific skill. 1069 * This adds exp to a player. We now allow adding to a specific skill.
1156command_addexp (object *op, char *params) 1072command_addexp (object *op, char *params)
1157{ 1073{
1158 char buf[MAX_BUF], skill[MAX_BUF]; 1074 char buf[MAX_BUF], skill[MAX_BUF];
1159 int i, q; 1075 int i, q;
1160 object *skillob = NULL; 1076 object *skillob = NULL;
1161 player *pl;
1162 1077
1163 skill[0] = '\0'; 1078 skill[0] = '\0';
1164 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %d %s", buf, &i, skill)) < 2)) 1079 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %d %s", buf, &i, skill)) < 2))
1165 { 1080 {
1166 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); 1081 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>].");
1167 return 1; 1082 return 1;
1168 } 1083 }
1169 1084
1170 for (pl = first_player; pl != NULL; pl = pl->next) 1085 for_all_players (pl)
1171 if (!strncmp (pl->ob->name, buf, MAX_NAME)) 1086 if (!strncmp (pl->ob->name, buf, MAX_NAME))
1172 break;
1173
1174 if (pl == NULL)
1175 { 1087 {
1176 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1177 return 1;
1178 }
1179
1180 if (q >= 3) 1088 if (q >= 3)
1181 { 1089 {
1182 skillob = find_skill_by_name (pl->ob, skill); 1090 skillob = find_skill_by_name (pl->ob, skill);
1183 if (!skillob) 1091 if (!skillob)
1184 { 1092 {
1185 new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find skill %s in %s", skill, buf); 1093 new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find skill %s in %s", skill, buf);
1094 return 1;
1095 }
1096
1097 i = check_exp_adjust (skillob, i);
1098 skillob->stats.exp += i;
1099 calc_perm_exp (skillob);
1100 player_lvl_adj (pl->ob, skillob);
1101 }
1102
1103 pl->ob->stats.exp += i;
1104 calc_perm_exp (pl->ob);
1105 player_lvl_adj (pl->ob, NULL);
1106
1107 if (settings.real_wiz == FALSE)
1108 SET_FLAG (pl->ob, FLAG_WAS_WIZ);
1109
1186 return 1; 1110 return 1;
1187 } 1111 }
1188 1112
1189 i = check_exp_adjust (skillob, i); 1113 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1190 skillob->stats.exp += i;
1191 calc_perm_exp (skillob);
1192 player_lvl_adj (pl->ob, skillob);
1193 }
1194
1195 pl->ob->stats.exp += i;
1196 calc_perm_exp (pl->ob);
1197 player_lvl_adj (pl->ob, NULL);
1198
1199 if (settings.real_wiz == FALSE)
1200 SET_FLAG (pl->ob, FLAG_WAS_WIZ);
1201 return 1; 1114 return 1;
1202} 1115}
1203 1116
1204/**************************************************************************/ 1117/**************************************************************************/
1205 1118
1211 1124
1212int 1125int
1213command_stats (object *op, char *params) 1126command_stats (object *op, char *params)
1214{ 1127{
1215 char thing[20]; 1128 char thing[20];
1216 player *pl;
1217 char buf[MAX_BUF]; 1129 char buf[MAX_BUF];
1218 1130
1219 thing[0] = '\0'; 1131 thing[0] = '\0';
1220 if (params == NULL || !sscanf (params, "%s", thing) || thing == NULL) 1132 if (params == NULL || !sscanf (params, "%s", thing) || thing == NULL)
1221 { 1133 {
1222 new_draw_info (NDI_UNIQUE, 0, op, "Who?"); 1134 new_draw_info (NDI_UNIQUE, 0, op, "Who?");
1223 return 1; 1135 return 1;
1224 } 1136 }
1225 1137
1226 for (pl = first_player; pl != NULL; pl = pl->next) 1138 for_all_players (pl)
1227 if (!strcmp (pl->ob->name, thing)) 1139 if (!strcmp (pl->ob->name, thing))
1228 { 1140 {
1229 sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); 1141 sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp);
1230 new_draw_info (NDI_UNIQUE, 0, op, buf); 1142 new_draw_info (NDI_UNIQUE, 0, op, buf);
1231 sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); 1143 sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp);
1232 new_draw_info (NDI_UNIQUE, 0, op, buf); 1144 new_draw_info (NDI_UNIQUE, 0, op, buf);
1233 sprintf (buf, "Con : %-2d AC : %-4d WC : %d", pl->ob->stats.Con, pl->ob->stats.ac, pl->ob->stats.wc); 1145 sprintf (buf, "Con : %-2d AC : %-4d WC : %d", pl->ob->stats.Con, pl->ob->stats.ac, pl->ob->stats.wc);
1234 new_draw_info (NDI_UNIQUE, 0, op, buf); 1146 new_draw_info (NDI_UNIQUE, 0, op, buf);
1235 sprintf (buf, "Int : %-2d Damage : %d", pl->ob->stats.Int, pl->ob->stats.dam); 1147 sprintf (buf, "Int : %-2d Damage : %d", pl->ob->stats.Int, pl->ob->stats.dam);
1236 new_draw_info (NDI_UNIQUE, 0, op, buf); 1148 new_draw_info (NDI_UNIQUE, 0, op, buf);
1237 sprintf (buf, "Wis : %-2d EXP : %lld", pl->ob->stats.Wis, (long long) pl->ob->stats.exp); 1149 sprintf (buf, "Wis : %-2d EXP : %" PRId64, pl->ob->stats.Wis, pl->ob->stats.exp);
1238 new_draw_info (NDI_UNIQUE, 0, op, buf); 1150 new_draw_info (NDI_UNIQUE, 0, op, buf);
1239 sprintf (buf, "Pow : %-2d Grace : %d", pl->ob->stats.Pow, pl->ob->stats.grace); 1151 sprintf (buf, "Pow : %-2d Grace : %d", pl->ob->stats.Pow, pl->ob->stats.grace);
1240 new_draw_info (NDI_UNIQUE, 0, op, buf); 1152 new_draw_info (NDI_UNIQUE, 0, op, buf);
1241 sprintf (buf, "Cha : %-2d Food : %d", pl->ob->stats.Cha, pl->ob->stats.food); 1153 sprintf (buf, "Cha : %-2d Food : %d", pl->ob->stats.Cha, pl->ob->stats.food);
1242 new_draw_info (NDI_UNIQUE, 0, op, buf); 1154 new_draw_info (NDI_UNIQUE, 0, op, buf);
1243 break; 1155 return 1;
1244 } 1156 }
1245 if (pl == NULL) 1157
1246 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 1158 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1247 return 1; 1159 return 1;
1248} 1160}
1249 1161
1250int 1162int
1251command_abil (object *op, char *params) 1163command_abil (object *op, char *params)
1274 { 1186 {
1275 new_draw_info (NDI_UNIQUE, 0, op, "Illegal range of stat.\n"); 1187 new_draw_info (NDI_UNIQUE, 0, op, "Illegal range of stat.\n");
1276 return 1; 1188 return 1;
1277 } 1189 }
1278 1190
1279 for (pl = first_player; pl != NULL; pl = pl->next) 1191 for_all_players (pl)
1280 { 1192 {
1281 if (!strcmp (pl->ob->name, thing)) 1193 if (!strcmp (pl->ob->name, thing))
1282 { 1194 {
1283 if (settings.real_wiz == FALSE) 1195 if (settings.real_wiz == FALSE)
1284 SET_FLAG (pl->ob, FLAG_WAS_WIZ); 1196 SET_FLAG (pl->ob, FLAG_WAS_WIZ);
1296 pl->ob->stats.Int = iii, pl->orig_stats.Int = iii; 1208 pl->ob->stats.Int = iii, pl->orig_stats.Int = iii;
1297 if (!strcmp ("pow", thing2)) 1209 if (!strcmp ("pow", thing2))
1298 pl->ob->stats.Pow = iii, pl->orig_stats.Pow = iii; 1210 pl->ob->stats.Pow = iii, pl->orig_stats.Pow = iii;
1299 sprintf (buf, "%s has been altered.", &pl->ob->name); 1211 sprintf (buf, "%s has been altered.", &pl->ob->name);
1300 new_draw_info (NDI_UNIQUE, 0, op, buf); 1212 new_draw_info (NDI_UNIQUE, 0, op, buf);
1301 fix_player (pl->ob); 1213 pl->ob->update_stats ();
1302 return 1; 1214 return 1;
1303 } 1215 }
1304 } 1216 }
1305 1217
1306 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 1218 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1307 return 1; 1219 return 1;
1308}
1309
1310int
1311command_reset (object *op, char *params)
1312{
1313 mapstruct *m;
1314 object *dummy = NULL, *tmp = NULL;
1315
1316 if (params == NULL)
1317 {
1318 new_draw_info (NDI_UNIQUE, 0, op, "Reset what map [name]?");
1319 return 1;
1320 }
1321
1322 if (strcmp (params, ".") == 0)
1323 params = op->map->path;
1324 m = has_been_loaded (params);
1325 if (m == NULL)
1326 {
1327 new_draw_info (NDI_UNIQUE, 0, op, "No such map.");
1328 return 1;
1329 }
1330
1331 if (m->in_memory != MAP_SWAPPED)
1332 {
1333 if (m->in_memory != MAP_IN_MEMORY)
1334 {
1335 LOG (llevError, "Tried to swap out map which was not in memory.\n");
1336 return 0;
1337 }
1338
1339 /*
1340 * Only attempt to remove the player that is doing the reset, and not other
1341 * players or wiz's.
1342 */
1343 if (op->map == m)
1344 {
1345 dummy = get_object ();
1346 dummy->map = NULL;
1347 EXIT_X (dummy) = op->x;
1348 EXIT_Y (dummy) = op->y;
1349 EXIT_PATH (dummy) = op->map->path;
1350 remove_ob (op);
1351 op->map = NULL;
1352 tmp = op;
1353 }
1354 swap_map (m);
1355 }
1356
1357 if (m->in_memory == MAP_SWAPPED)
1358 {
1359 LOG (llevDebug, "Resetting map %s.\n", m->path);
1360
1361 /* setting this effectively causes an immediate reload */
1362 m->reset_time = 1;
1363 flush_old_maps ();
1364 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
1365 if (tmp)
1366 {
1367 enter_exit (tmp, dummy);
1368 free_object (dummy);
1369 }
1370 return 1;
1371 }
1372 else
1373 {
1374 player *pl;
1375 int playercount = 0;
1376
1377 /* Need to re-insert player if swap failed for some reason */
1378 if (tmp)
1379 {
1380 insert_ob_in_map (op, m, NULL, 0);
1381 free_object (dummy);
1382 }
1383
1384 new_draw_info (NDI_UNIQUE, 0, op, "Reset failed, couldn't swap map, the following players are on it:");
1385 for (pl = first_player; pl != NULL; pl = pl->next)
1386 {
1387 if (pl->ob->map == m && pl->ob != op)
1388 {
1389 new_draw_info_format (NDI_UNIQUE, 0, op, "%s", &pl->ob->name);
1390 playercount++;
1391 }
1392 }
1393 if (!playercount)
1394 new_draw_info (NDI_UNIQUE, 0, op, "hmm, I don't see any other players on this map, something else is the problem.");
1395 return 1;
1396 }
1397} 1220}
1398 1221
1399int 1222int
1400command_nowiz (object *op, char *params) 1223command_nowiz (object *op, char *params)
1401{ /* 'noadm' is alias */ 1224{ /* 'noadm' is alias */
1471 { 1294 {
1472 new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!"); 1295 new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!");
1473 return 0; 1296 return 0;
1474 } 1297 }
1475 1298
1476 if (checkdm (op, op->name, (params ? params : "*"), op->contr->socket.host)) 1299 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host))
1477 { 1300 {
1478 SET_FLAG (op, FLAG_WIZ); 1301 SET_FLAG (op, FLAG_WIZ);
1479 SET_FLAG (op, FLAG_WAS_WIZ); 1302 SET_FLAG (op, FLAG_WAS_WIZ);
1480 SET_FLAG (op, FLAG_WIZPASS); 1303 SET_FLAG (op, FLAG_WIZPASS);
1481 SET_FLAG (op, FLAG_WIZCAST); 1304 SET_FLAG (op, FLAG_WIZCAST);
1652 new_draw_info_format (NDI_UNIQUE, 0, op, "You already know the spell %s.", &tmp->name); 1475 new_draw_info_format (NDI_UNIQUE, 0, op, "You already know the spell %s.", &tmp->name);
1653 return 0; 1476 return 0;
1654 } 1477 }
1655 1478
1656 do_learn_spell (op, tmp, special_prayer); 1479 do_learn_spell (op, tmp, special_prayer);
1657 free_object (tmp); 1480 tmp->destroy ();
1658 return 1; 1481 return 1;
1659} 1482}
1660 1483
1661int 1484int
1662command_learn_spell (object *op, char *params) 1485command_learn_spell (object *op, char *params)
2074 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); 1897 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!");
2075 return 0; 1898 return 0;
2076 } 1899 }
2077 1900
2078 if (!QUERY_FLAG (right, FLAG_REMOVED)) 1901 if (!QUERY_FLAG (right, FLAG_REMOVED))
2079 remove_ob (right); 1902 right->remove ();
2080 inserted = insert_ob_in_ob (right, left); 1903 inserted = insert_ob_in_ob (right, left);
2081 if (left->type == PLAYER) 1904 if (left->type == PLAYER)
2082 if (inserted == right) 1905 if (inserted == right)
2083 esrv_send_item (left, right); 1906 esrv_send_item (left, right);
2084 else 1907 else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines