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.29 by root, Fri Jan 5 10:50:47 2007 UTC vs.
Revision 1.61 by root, Sat Dec 20 02:32:31 2008 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Deliantra 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 3 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, see <http://www.gnu.org/licenses/>.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
20 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <sproto.h> 25#include <sproto.h>
26#include <spells.h> 26#include <spells.h>
27#include <treasure.h> 27#include <treasure.h>
85 op->contr->hidden = 0; 85 op->contr->hidden = 0;
86 op->invisible = 1; 86 op->invisible = 1;
87 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); 87 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
88 op->map->players++; 88 op->map->players++;
89 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name); 89 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
90
90 if (!silent_dm) 91 if (!silent_dm)
91 {
92 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!"); 92 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
93 }
94 } 93 }
95 else 94 else
96 { 95 {
97 op->contr->hidden = 1; 96 op->contr->hidden = 1;
98 new_draw_info (NDI_UNIQUE, 0, op, "Other players will no longer see you."); 97 new_draw_info (NDI_UNIQUE, 0, op, "Other players will no longer see you.");
99 op->map->players--; 98 op->map->players--;
99
100 if (!silent_dm) 100 if (!silent_dm)
101 {
102 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone.."); 101 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
103 } 102
104 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s leaves the game.", &op->name); 103 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s leaves the game.", &op->name);
105 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s left the game.", &op->name); 104 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s left the game.", &op->name);
106 } 105 }
107} 106}
108 107
172 171
173 become_follower (ob, god); 172 become_follower (ob, god);
174 return 1; 173 return 1;
175} 174}
176 175
177/** 176// TODO: Rewrite banish in perl and get rid of the following two functions
178 * Add player's IP to ban_file and kick them off the server
179 * I know most people have dynamic IPs but this is more of a short term
180 * solution if they have to get a new IP to play maybe they'll calm down.
181 * This uses the banish_file in the local directory *not* the ban_file
182 * The action is logged with a ! for easy searching. -tm
183 */
184int
185command_banish (object *op, char *params)
186{
187 player *pl;
188 FILE *banishfile;
189 char buf[MAX_BUF];
190 time_t now;
191
192 if (!params)
193 {
194 new_draw_info (NDI_UNIQUE, 0, op, "Usage: banish <player>.");
195 return 1;
196 }
197
198 pl = get_other_player_from_name (op, params);
199 if (!pl)
200 return 1;
201
202 sprintf (buf, "%s/%s", settings.localdir, BANISHFILE);
203
204 if ((banishfile = fopen (buf, "a")) == NULL)
205 {
206 LOG (llevDebug, "Could not find file banish_file.\n");
207 new_draw_info (NDI_UNIQUE, 0, op, "Could not find banish_file.");
208 return 0;
209 }
210
211 now = time (NULL);
212 /*
213 * Record this as a comment - then we don't have to worry about changing
214 * the parsing code.
215 */
216 fprintf (banishfile, "# %s (%s) banned by %s at %s\n", &pl->ob->name, pl->ns->host, &op->name, ctime (&now));
217 fprintf (banishfile, "*@%s\n", pl->ns->host);
218 fclose (banishfile);
219
220 LOG (llevDebug, "! %s banned %s from IP: %s.\n", &op->name, &pl->ob->name, pl->ns->host);
221 new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, op, "You banish %s", &pl->ob->name);
222 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s banishes %s from the land!", &op->name, &pl->ob->name);
223 command_kick (op, (char *) &pl->ob->name);
224 return 1;
225}
226
227int 177int
228command_kick (object *op, char *params) 178command_kick (object *op, char *params)
229{ 179{
230 for_all_players (pl) 180 for_all_players (pl)
231 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params))) 181 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params)))
232 { 182 {
233 object *op = pl->ob; 183 object *plop = pl->ob;
234 184
235 if (!QUERY_FLAG (op, FLAG_REMOVED) && !QUERY_FLAG (op, FLAG_FREED)) 185 if (!QUERY_FLAG (plop, FLAG_REMOVED) && !QUERY_FLAG (plop, FLAG_FREED))
236 { 186 {
237 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &op->name); 187 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &plop->name);
238 strcpy (op->contr->killer, "kicked"); 188 plop->contr->killer = op;
239 } 189 }
240 190
241 pl->ns->destroy (); 191 pl->ns->destroy ();
242 } 192 }
243 193
265 ready_map_name (op->map->path, 0); 215 ready_map_name (op->map->path, 0);
266 216
267 return 1; 217 return 1;
268} 218}
269#endif 219#endif
270
271int
272command_shutdown (object *op, char *params)
273{
274 if (op && !QUERY_FLAG (op, FLAG_WIZ))
275 {
276 new_draw_info (NDI_UNIQUE, 0, op, "Sorry, you can't shutdown the server.");
277 return 1;
278 }
279
280 cleanup ("dm initiated shutdown", 0);
281
282 /* not reached */
283 return 1;
284}
285 220
286int 221int
287command_freeze (object *op, char *params) 222command_freeze (object *op, char *params)
288{ 223{
289 int ticks; 224 int ticks;
344 /* we have nowhere to send the prisoner.... */ 279 /* we have nowhere to send the prisoner.... */
345 new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them"); 280 new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them");
346 return 0; 281 return 0;
347 } 282 }
348 283
349 pl->ob->enter_exit (dummy); 284 pl->ob->player_goto (dummy->slaying, dummy->stats.hp, dummy->stats.sp);//TODO
350 dummy->destroy (); 285 dummy->destroy ();
286
351 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested."); 287 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested.");
352 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 288 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
353 LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name); 289 LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name);
354 return 1; 290 return 1;
355} 291}
379 { 315 {
380 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); 316 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player.");
381 return 1; 317 return 1;
382 } 318 }
383 319
384 dummy = object::create (); 320 pl->ob->player_goto (op->map->path, op->x + freearr_x[i], op->y + freearr_y[i]);
385 EXIT_PATH (dummy) = op->map->path;
386 EXIT_X (dummy) = op->x + freearr_x[i];
387 EXIT_Y (dummy) = op->y + freearr_y[i];
388 pl->ob->enter_exit (dummy);
389 dummy->destroy ();
390 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); 321 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned.");
391 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 322 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
392 323
393 return 1;
394}
395
396/**
397 * Teleport next to target player.
398 */
399
400/* mids 01/16/2002 */
401int
402command_teleport (object *op, char *params)
403{
404 int i;
405 object *dummy;
406 player *pl;
407
408 if (!op)
409 return 0;
410
411 if (params == NULL)
412 {
413 new_draw_info (NDI_UNIQUE, 0, op, "Usage: teleport <player>.");
414 return 1;
415 }
416
417 pl = get_other_player_from_name (op, params);
418 if (!pl)
419 return 1;
420
421 i = find_free_spot (pl->ob, pl->ob->map, pl->ob->x, pl->ob->y, 1, 9);
422 if (i == -1)
423 {
424 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to teleport to.");
425 return 1;
426 }
427
428 dummy = object::create ();
429 EXIT_PATH (dummy) = pl->ob->map->path;
430 EXIT_X (dummy) = pl->ob->x + freearr_x[i];
431 EXIT_Y (dummy) = pl->ob->y + freearr_y[i];
432 op->enter_exit (dummy);
433 dummy->destroy ();
434 if (!op->contr->hidden)
435 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You see a portal open.");
436 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
437 return 1; 324 return 1;
438} 325}
439 326
440/** 327/**
441 * This function is a real mess, because we're stucking getting 328 * This function is a real mess, because we're stucking getting
531 * we also set up spell_name which is only 418 * we also set up spell_name which is only
532 * the first word. 419 * the first word.
533 */ 420 */
534 421
535 at_spell = archetype::find (cp); 422 at_spell = archetype::find (cp);
536 if (!at_spell || at_spell->clone.type != SPELL) 423 if (!at_spell || at_spell->type != SPELL)
537 at_spell = find_archetype_by_object_name (cp); 424 at_spell = find_archetype_by_object_name (cp);
538 if (!at_spell || at_spell->clone.type != SPELL) 425 if (!at_spell || at_spell->type != SPELL)
539 { 426 {
540 strcpy (spell_name, cp); 427 assign (spell_name, cp);
541 fsp = strchr (spell_name, ' '); 428 fsp = strchr (spell_name, ' ');
542 if (fsp) 429 if (fsp)
543 { 430 {
544 *fsp = 0; 431 *fsp = 0;
545 fsp++; 432 fsp++;
546 at_spell = archetype::find (spell_name); 433 at_spell = archetype::find (spell_name);
547 434
548 /* Got a spell, update the first string pointer */ 435 /* Got a spell, update the first string pointer */
549 if (at_spell && at_spell->clone.type == SPELL) 436 if (at_spell && at_spell->type == SPELL)
550 bp2 = cp + strlen (spell_name) + 1; 437 bp2 = cp + strlen (spell_name) + 1;
551 else 438 else
552 at_spell = NULL; 439 at_spell = NULL;
553 } 440 }
554 } 441 }
556 /* OK - we didn't find a spell - presume the 'of' 443 /* OK - we didn't find a spell - presume the 'of'
557 * in this case means its an artifact. 444 * in this case means its an artifact.
558 */ 445 */
559 if (!at_spell) 446 if (!at_spell)
560 { 447 {
561 if (find_artifactlist (at->clone.type) == NULL) 448 if (find_artifactlist (at->type) == NULL)
562 new_draw_info_format (NDI_UNIQUE, 0, op, "No artifact list for type %d\n", at->clone.type); 449 new_draw_info_format (NDI_UNIQUE, 0, op, "No artifact list for type %d\n", at->type);
563 else 450 else
564 { 451 {
565 art = find_artifactlist (at->clone.type)->items; 452 art = find_artifactlist (at->type)->items;
566 453
567 do 454 while (art)
568 { 455 {
569 if (!strcmp (art->item->name, cp)) 456 if (!strcmp (art->item->name, cp))
570 break; 457 break;
458
571 art = art->next; 459 art = art->next;
572 } 460 }
573 while (art != NULL);
574 461
575 if (!art) 462 if (!art)
576 new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->clone.type, cp); 463 new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->type, cp);
577 } 464 }
578 465
579 LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp); 466 LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp);
580 } 467 }
581 } /* if cp */ 468 } /* if cp */
582 469
583 if ((at->clone.type == ROD || at->clone.type == WAND || at->clone.type == SCROLL || 470 if ((at->type == ROD || at->type == WAND || at->type == SCROLL ||
584 at->clone.type == HORN || at->clone.type == SPELLBOOK) && !at_spell) 471 at->type == HORN || at->type == SPELLBOOK) && !at_spell)
585 { 472 {
586 new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find spell %s for object that needs it, or it is of wrong type", cp); 473 new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find spell %s for object that needs it, or it is of wrong type", cp);
587 return 1; 474 return 1;
588 } 475 }
589 476
591 * Rather than have two different blocks with a lot of similar code, 478 * Rather than have two different blocks with a lot of similar code,
592 * just create one object, do all the processing, and then determine 479 * just create one object, do all the processing, and then determine
593 * if that one object should be inserted or if we need to make copies. 480 * if that one object should be inserted or if we need to make copies.
594 */ 481 */
595 tmp = arch_to_object (at); 482 tmp = arch_to_object (at);
596
597 if (settings.real_wiz == FALSE)
598 SET_FLAG (tmp, FLAG_WAS_WIZ);
599 483
600 if (set_magic) 484 if (set_magic)
601 set_abs_magic (tmp, magic); 485 set_abs_magic (tmp, magic);
602 486
603 if (art) 487 if (art)
683 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2); 567 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2);
684 568
685 bp2 = bp3 + 1; 569 bp2 = bp3 + 1;
686 } 570 }
687 571
688 if (at->clone.nrof) 572 if (at->nrof)
689 { 573 {
690 if (at_spell) 574 if (at_spell)
691 insert_ob_in_ob (arch_to_object (at_spell), tmp); 575 tmp->insert (arch_to_object (at_spell));
692 576
693 tmp->x = op->x; 577 tmp->x = op->x;
694 tmp->y = op->y; 578 tmp->y = op->y;
579 tmp->map = op->map;
695 580
696 if (set_nrof) 581 if (set_nrof)
697 tmp->nrof = nrof; 582 tmp->nrof = nrof;
698 583
699 tmp->map = op->map; 584 op->insert (tmp);
700
701 tmp = insert_ob_in_ob (tmp, op);
702 esrv_send_item (op, tmp);
703 585
704 /* Let's put this created item on stack so dm can access it easily. */ 586 /* Let's put this created item on stack so dm can access it easily. */
705 dm_stack_push (op->contr, tmp->count); 587 dm_stack_push (op->contr, tmp->count);
706 588
707 return 1; 589 return 1;
708 } 590 }
709 else 591 else
710 { 592 {
711 for (i = 0; i < (set_nrof ? nrof : 1); i++) 593 for (i = 0; i < (set_nrof ? nrof : 1); i++)
712 { 594 {
713 archetype *atmp;
714 object *prev = 0, *head = 0; 595 object *prev = 0, *head = 0;
715 596
716 for (atmp = at; atmp; atmp = atmp->more) 597 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
717 { 598 {
718 object *dup = arch_to_object (atmp); 599 object *dup = arch_to_object (atmp);
719 600
720 if (at_spell) 601 if (at_spell)
721 insert_ob_in_ob (arch_to_object (at_spell), dup); 602 insert_ob_in_ob (arch_to_object (at_spell), dup);
728 { 609 {
729 head = dup; 610 head = dup;
730 tmp->copy_to (dup); 611 tmp->copy_to (dup);
731 } 612 }
732 613
733 if (settings.real_wiz == FALSE)
734 SET_FLAG (dup, FLAG_WAS_WIZ);
735
736 dup->x = op->x + dup->arch->clone.x; 614 dup->x = op->x + dup->arch->x;
737 dup->y = op->y + dup->arch->clone.y; 615 dup->y = op->y + dup->arch->y;
738 dup->map = op->map; 616 dup->map = op->map;
739 617
740 if (head != dup) 618 if (head != dup)
741 { 619 {
742 dup->head = head; 620 dup->head = head;
752 int size_x = 0; 630 int size_x = 0;
753 int size_y = 0; 631 int size_y = 0;
754 632
755 while (check) 633 while (check)
756 { 634 {
757 size_x = MAX (size_x, check->arch->clone.x); 635 size_x = MAX (size_x, check->arch->x);
758 size_y = MAX (size_y, check->arch->clone.y); 636 size_y = MAX (size_y, check->arch->y);
759 check = check->more; 637 check = check->more;
760 } 638 }
761 639
762 if (out_of_map (op->map, head->x + size_x, head->y + size_y)) 640 if (out_of_map (op->map, head->x + size_x, head->y + size_y))
763 { 641 {
789 /* Wonder if we really want to push all of these, but since 667 /* Wonder if we really want to push all of these, but since
790 * things like rods have nrof 0, we want to cover those. 668 * things like rods have nrof 0, we want to cover those.
791 */ 669 */
792 dm_stack_push (op->contr, head->count); 670 dm_stack_push (op->contr, head->count);
793 671
794 if (at->clone.randomitems != NULL && !at_spell) 672 if (at->randomitems && !at_spell)
795 create_treasure (at->clone.randomitems, head, GT_APPLY, op->map->difficulty, 0); 673 create_treasure (at->randomitems, head, GT_APPLY, op->map->difficulty, 0);
796
797 esrv_send_item (op, head);
798 } 674 }
799 675
800 /* free the one we used to copy */ 676 /* free the one we used to copy */
801 tmp->destroy (); 677 tmp->destroy ();
802 } 678 }
809 */ 685 */
810 686
811int 687int
812command_inventory (object *op, char *params) 688command_inventory (object *op, char *params)
813{ 689{
690 int i;
814 object *tmp; 691 object *tmp;
815 int i;
816 692
817 if (!params) 693 if (!params || !sscanf (params, "%d", &i) || !(tmp = find_object (i)))
818 { 694 {
819 inventory (op, NULL); 695 op->contr->failmsg ("Inventory of what object (nr)?");
820 return 0; 696 return 1;
821 }
822
823 if (!sscanf (params, "%d", &i) || (tmp = find_object (i)) == NULL)
824 { 697 }
825 new_draw_info (NDI_UNIQUE, 0, op, "Inventory of what object (nr)?");
826 return 1;
827 }
828 698
829 inventory (op, tmp); 699 op->contr->infobox (MSG_CHANNEL ("examine"), tmp->query_inventory (op));
700
830 return 1; 701 return 1;
831} 702}
832 703
833/* just show player's their skills for now. Dm's can 704/* just show player's their skills for now. Dm's can
834 * already see skills w/ inventory command - b.t. 705 * already see skills w/ inventory command - b.t.
855 free (dump); 726 free (dump);
856 727
857 if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL)) 728 if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL))
858 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); 729 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original");
859 730
860 return 1;
861}
862
863/**
864 * When DM is possessing a monster, flip aggression on and off, to allow
865 * better motion.
866 */
867int
868command_mon_aggr (object *op, char *params)
869{
870 if (op->enemy || !QUERY_FLAG (op, FLAG_UNAGGRESSIVE))
871 {
872 op->enemy = NULL;
873 SET_FLAG (op, FLAG_UNAGGRESSIVE);
874 new_draw_info (NDI_UNIQUE, 0, op, "Aggression turned OFF");
875 }
876 else
877 {
878 CLEAR_FLAG (op, FLAG_FRIENDLY);
879 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE);
880 new_draw_info (NDI_UNIQUE, 0, op, "Aggression turned ON");
881 }
882
883 return 1;
884}
885
886/** DM can possess a monster. Basically, this tricks the client into thinking
887 * a given monster, is actually the player it controls. This allows a DM
888 * to inhabit a monster's body, and run around the game with it.
889 * This function is severely broken - it has tons of hardcoded values,
890 */
891int
892command_possess (object *op, char *params)
893{
894 object *victim, *curinv, *nextinv;
895 player *pl;
896 int i;
897 char buf[MAX_BUF];
898
899 victim = NULL;
900 if (params != NULL)
901 {
902 if (sscanf (params, "%d", &i))
903 victim = find_object (i);
904 else if (sscanf (params, "%s", buf))
905 victim = find_object_name (buf);
906 }
907 if (victim == NULL)
908 {
909 new_draw_info (NDI_UNIQUE, 0, op, "Patch what object (nr)?");
910 return 1;
911 }
912
913 if (victim == op)
914 {
915 new_draw_info (NDI_UNIQUE, 0, op, "As insane as you are, I cannot " "allow you to possess yourself.");
916 return 1;
917 }
918
919 /* clear out the old inventory */
920 curinv = op->inv;
921 while (curinv != NULL)
922 {
923 nextinv = curinv->below;
924 esrv_del_item (op->contr, curinv->count);
925 curinv = nextinv;
926 }
927
928 /* make the switch */
929 pl = op->contr;
930 victim->contr = pl;
931 pl->ob = victim;
932 victim->type = PLAYER;
933 SET_FLAG (victim, FLAG_WIZ);
934
935 /* send the inventory to the client */
936 curinv = victim->inv;
937 while (curinv != NULL)
938 {
939 nextinv = curinv->below;
940 esrv_send_item (victim, curinv);
941 curinv = nextinv;
942 }
943 /* basic patchup */
944 /* The use of hard coded values is terrible. Note
945 * that really, to be fair, this shouldn't get changed at
946 * all - if you are possessing a kobold, you should have the
947 * same limitations. As it is, as more body locations are added,
948 * this will give this player more locations than perhaps
949 * they should be allowed.
950 */
951 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
952 if (i == 1 || i == 6 || i == 8 || i == 9)
953 victim->body_info[i] = 2;
954 else
955 victim->body_info[i] = 1;
956
957 esrv_new_player (pl, 80); /* just pick a wieght, we don't care */
958 esrv_send_inventory (victim, victim);
959
960 victim->update_stats ();
961
962 do_some_living (victim);
963 return 1; 731 return 1;
964} 732}
965 733
966int 734int
967command_patch (object *op, char *params) 735command_patch (object *op, char *params)
982 return 1; 750 return 1;
983 } 751 }
984 752
985 if ((arg2 = strchr (arg, ' '))) 753 if ((arg2 = strchr (arg, ' ')))
986 arg2++; 754 arg2++;
987 if (settings.real_wiz == FALSE) 755
988 SET_FLAG (tmp, FLAG_WAS_WIZ); /* To avoid cheating */
989 if (set_variable (tmp, arg) == -1) 756 if (set_variable (tmp, arg) == -1)
990 new_draw_info_format (NDI_UNIQUE, 0, op, "Unknown variable %s", arg); 757 new_draw_info_format (NDI_UNIQUE, 0, op, "Unknown variable %s", arg);
991 else 758 else
992 {
993 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s=%s", &tmp->name, tmp->count, arg, arg2); 759 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s=%s", &tmp->name, tmp->count, arg, arg2);
994 }
995 760
996 return 1; 761 return 1;
997} 762}
998 763
999int 764int
1048 813
1049 if (from != STACK_FROM_STACK) 814 if (from != STACK_FROM_STACK)
1050 /* Item is either stack top, or is a number thus is now stack top, let's remove it */ 815 /* Item is either stack top, or is a number thus is now stack top, let's remove it */
1051 dm_stack_pop (op->contr); 816 dm_stack_pop (op->contr);
1052 817
1053 if (!QUERY_FLAG (tmp, FLAG_REMOVED))
1054 {
1055 new_draw_info (NDI_UNIQUE, 0, op, "Warning, item wasn't removed.");
1056 tmp->remove ();
1057 }
1058
1059 if (tmp->head) 818 if (tmp->head)
1060 tmp = tmp->head; 819 tmp = tmp->head;
1061 820
1062 tmp->destroy (); 821 tmp->destroy ();
1063 return 1; 822 return 1;
1068 */ 827 */
1069int 828int
1070command_addexp (object *op, char *params) 829command_addexp (object *op, char *params)
1071{ 830{
1072 char buf[MAX_BUF], skill[MAX_BUF]; 831 char buf[MAX_BUF], skill[MAX_BUF];
1073 int i, q; 832 int q;
833 long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure
1074 object *skillob = NULL; 834 object *skillob = NULL;
1075 835
1076 skill[0] = '\0'; 836 skill[0] = '\0';
1077 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %d %s", buf, &i, skill)) < 2)) 837 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %s", buf, &i, skill)) < 2))
1078 { 838 {
1079 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); 839 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>].");
1080 return 1; 840 return 1;
1081 } 841 }
1082 842
1099 } 859 }
1100 860
1101 pl->ob->stats.exp += i; 861 pl->ob->stats.exp += i;
1102 calc_perm_exp (pl->ob); 862 calc_perm_exp (pl->ob);
1103 player_lvl_adj (pl->ob, NULL); 863 player_lvl_adj (pl->ob, NULL);
1104
1105 if (settings.real_wiz == FALSE)
1106 SET_FLAG (pl->ob, FLAG_WAS_WIZ);
1107 864
1108 return 1; 865 return 1;
1109 } 866 }
1110 867
1111 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 868 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1160int 917int
1161command_abil (object *op, char *params) 918command_abil (object *op, char *params)
1162{ 919{
1163 char thing[20], thing2[20]; 920 char thing[20], thing2[20];
1164 int iii; 921 int iii;
1165 player *pl;
1166 char buf[MAX_BUF]; 922 char buf[MAX_BUF];
1167 923
1168 iii = 0; 924 iii = 0;
1169 thing[0] = '\0'; 925 thing[0] = '\0';
1170 thing2[0] = '\0'; 926 thing2[0] = '\0';
1188 944
1189 for_all_players (pl) 945 for_all_players (pl)
1190 { 946 {
1191 if (!strcmp (pl->ob->name, thing)) 947 if (!strcmp (pl->ob->name, thing))
1192 { 948 {
1193 if (settings.real_wiz == FALSE)
1194 SET_FLAG (pl->ob, FLAG_WAS_WIZ);
1195 if (!strcmp ("str", thing2))
1196 pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; 949 if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii;
1197 if (!strcmp ("dex", thing2))
1198 pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii; 950 if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii;
1199 if (!strcmp ("con", thing2))
1200 pl->ob->stats.Con = iii, pl->orig_stats.Con = iii; 951 if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii;
1201 if (!strcmp ("wis", thing2))
1202 pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii; 952 if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii;
1203 if (!strcmp ("cha", thing2))
1204 pl->ob->stats.Cha = iii, pl->orig_stats.Cha = iii; 953 if (!strcmp ("cha", thing2)) pl->ob->stats.Cha = iii, pl->orig_stats.Cha = iii;
1205 if (!strcmp ("int", thing2))
1206 pl->ob->stats.Int = iii, pl->orig_stats.Int = iii; 954 if (!strcmp ("int", thing2)) pl->ob->stats.Int = iii, pl->orig_stats.Int = iii;
1207 if (!strcmp ("pow", thing2))
1208 pl->ob->stats.Pow = iii, pl->orig_stats.Pow = iii; 955 if (!strcmp ("pow", thing2)) pl->ob->stats.Pow = iii, pl->orig_stats.Pow = iii;
956
1209 sprintf (buf, "%s has been altered.", &pl->ob->name); 957 sprintf (buf, "%s has been altered.", &pl->ob->name);
1210 new_draw_info (NDI_UNIQUE, 0, op, buf); 958 new_draw_info (NDI_UNIQUE, 0, op, buf);
1211 pl->ob->update_stats (); 959 pl->ob->update_stats ();
1212 return 1; 960 return 1;
1213 } 961 }
1217 return 1; 965 return 1;
1218} 966}
1219 967
1220int 968int
1221command_nowiz (object *op, char *params) 969command_nowiz (object *op, char *params)
1222{ /* 'noadm' is alias */ 970{ /* 'nodm' is alias */
1223 CLEAR_FLAG (op, FLAG_WIZ); 971 CLEAR_FLAG (op, FLAG_WIZ);
1224 CLEAR_FLAG (op, FLAG_WIZPASS); 972 CLEAR_FLAG (op, FLAG_WIZPASS);
1225 CLEAR_FLAG (op, FLAG_WIZCAST); 973 CLEAR_FLAG (op, FLAG_WIZCAST);
1226 974
1227 if (settings.real_wiz == TRUE)
1228 CLEAR_FLAG (op, FLAG_WAS_WIZ);
1229 if (op->contr->hidden) 975 if (op->contr->hidden)
1230 { 976 {
1231 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); 977 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
1232 op->map->players++; 978 op->map->players++;
1233 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name); 979 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
1295 } 1041 }
1296 1042
1297 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host)) 1043 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host))
1298 { 1044 {
1299 SET_FLAG (op, FLAG_WIZ); 1045 SET_FLAG (op, FLAG_WIZ);
1300 SET_FLAG (op, FLAG_WAS_WIZ);
1301 SET_FLAG (op, FLAG_WIZPASS); 1046 SET_FLAG (op, FLAG_WIZPASS);
1302 SET_FLAG (op, FLAG_WIZCAST); 1047 SET_FLAG (op, FLAG_WIZCAST);
1048
1303 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!"); 1049 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!");
1304 /* 1050 /*
1305 * Remove setting flying here - that won't work, because next 1051 * Remove setting flying here - that won't work, because next
1306 * fix_player() is called that will get cleared - proper solution 1052 * fix_player() is called that will get cleared - proper solution
1307 * is probably something like a wiz_force which gives that and any 1053 * is probably something like a wiz_force which gives that and any
1308 * other desired abilities. 1054 * other desired abilities.
1309 */ 1055 */
1310 clear_los (op); 1056 op->contr->clear_los (0);
1311 op->contr->write_buf[0] = '\0'; 1057 op->contr->write_buf[0] = '\0';
1312 1058
1313 if (!silent) 1059 if (!silent)
1314 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!"); 1060 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
1315 1061
1342command_invisible (object *op, char *params) 1088command_invisible (object *op, char *params)
1343{ 1089{
1344 if (op) 1090 if (op)
1345 { 1091 {
1346 op->invisible += 100; 1092 op->invisible += 100;
1347 update_object (op, UP_OBJ_FACE); 1093 update_object (op, UP_OBJ_CHANGE);
1348 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible."); 1094 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible.");
1349 } 1095 }
1350 1096
1351 return 0; 1097 return 0;
1352} 1098}
1364 * name than other "spell_xxx" archetypes and would always conflict. 1110 * name than other "spell_xxx" archetypes and would always conflict.
1365 */ 1111 */
1366static object * 1112static object *
1367get_spell_by_name (object *op, const char *spell_name) 1113get_spell_by_name (object *op, const char *spell_name)
1368{ 1114{
1369 archetype *ar; 1115 archetype *at;
1370 archetype *found; 1116 archetype *found;
1371 int conflict_found; 1117 int conflict_found;
1372 size_t spell_name_length; 1118 size_t spell_name_length;
1373 1119
1374 /* First check for full name matches. */ 1120 /* First check for full name matches. */
1375 conflict_found = 0; 1121 conflict_found = 0;
1376 found = NULL; 1122 found = NULL;
1377 for (ar = first_archetype; ar != NULL; ar = ar->next) 1123 for_all_archetypes (at)
1378 { 1124 {
1379 if (ar->clone.type != SPELL) 1125 if (at->type != SPELL)
1380 continue; 1126 continue;
1381 1127
1382 if (strncmp (ar->name, "spelldirect_", 12) == 0) 1128 if (strncmp (at->archname, "spelldirect_", 12) == 0)
1383 continue; 1129 continue;
1384 1130
1385 if (strcmp (ar->clone.name, spell_name) != 0) 1131 if (strcmp (at->object::name, spell_name) != 0)
1386 continue; 1132 continue;
1387 1133
1388 if (found != NULL) 1134 if (found != NULL)
1389 { 1135 {
1390 if (!conflict_found) 1136 if (!conflict_found)
1391 { 1137 {
1392 conflict_found = 1; 1138 conflict_found = 1;
1393 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", spell_name); 1139 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", spell_name);
1394 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->name); 1140 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname);
1395 } 1141 }
1142
1396 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &ar->name); 1143 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname);
1397 continue; 1144 continue;
1398 } 1145 }
1399 1146
1400 found = ar; 1147 found = at;
1401 } 1148 }
1402 1149
1403 /* No match if more more than one archetype matches. */ 1150 /* No match if more more than one archetype matches. */
1404 if (conflict_found) 1151 if (conflict_found)
1405 return NULL; 1152 return NULL;
1410 1157
1411 /* No full match found: now check for partial matches. */ 1158 /* No full match found: now check for partial matches. */
1412 spell_name_length = strlen (spell_name); 1159 spell_name_length = strlen (spell_name);
1413 conflict_found = 0; 1160 conflict_found = 0;
1414 found = NULL; 1161 found = NULL;
1415 for (ar = first_archetype; ar != NULL; ar = ar->next) 1162 for_all_archetypes (at)
1416 { 1163 {
1417 if (ar->clone.type != SPELL) 1164 if (at->type != SPELL)
1418 continue; 1165 continue;
1419 1166
1420 if (strncmp (ar->name, "spelldirect_", 12) == 0) 1167 if (strncmp (at->archname, "spelldirect_", 12) == 0)
1421 continue; 1168 continue;
1422 1169
1423 if (strncmp (ar->clone.name, spell_name, spell_name_length) != 0) 1170 if (strncmp (at->object::name, spell_name, spell_name_length) != 0)
1424 continue; 1171 continue;
1425 1172
1426 if (found != NULL) 1173 if (found != NULL)
1427 { 1174 {
1428 if (!conflict_found) 1175 if (!conflict_found)
1429 { 1176 {
1430 conflict_found = 1; 1177 conflict_found = 1;
1431 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one spell matches %s:", spell_name); 1178 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one spell matches %s:", spell_name);
1432 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->clone.name); 1179 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->object::name);
1433 } 1180 }
1434 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &ar->clone.name); 1181 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->object::name);
1435 continue; 1182 continue;
1436 } 1183 }
1437 1184
1438 found = ar; 1185 found = at;
1439 } 1186 }
1440 1187
1441 /* No match if more more than one archetype matches. */ 1188 /* No match if more more than one archetype matches. */
1442 if (conflict_found) 1189 if (conflict_found)
1443 return NULL; 1190 return NULL;
1508 new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); 1255 new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params);
1509 return 0; 1256 return 0;
1510 } 1257 }
1511 1258
1512 do_forget_spell (op, spell->name); 1259 do_forget_spell (op, spell->name);
1513 return 1;
1514}
1515
1516/**
1517 * Lists all plugins currently loaded with their IDs and full names.
1518 */
1519int
1520command_listplugins (object *op, char *params)
1521{
1522 plugins_display_list (op);
1523 return 1;
1524}
1525
1526/**
1527 * Loads the given plugin. The DM specifies the name of the library to load (no
1528 * pathname is needed). Do not ever attempt to load the same plugin more than
1529 * once at a time, or bad things could happen.
1530 */
1531int
1532command_loadplugin (object *op, char *params)
1533{
1534 char buf[MAX_BUF];
1535
1536 if (params == NULL)
1537 {
1538 new_draw_info (NDI_UNIQUE, 0, op, "Load which plugin?");
1539 return 1;
1540 }
1541
1542 strcpy (buf, LIBDIR);
1543 strcat (buf, "/plugins/");
1544 strcat (buf, params);
1545 LOG (llevDebug, "Requested plugin file is %s\n", buf);
1546 if (plugins_init_plugin (buf) == 0)
1547 new_draw_info (NDI_UNIQUE, 0, op, "Plugin successfully loaded.");
1548 else
1549 new_draw_info (NDI_UNIQUE, 0, op, "Could not load plugin.");
1550 return 1;
1551}
1552
1553/**
1554 * Unloads the given plugin. The DM specified the ID of the library to unload.
1555 * Note that some things may behave strangely if the correct plugins are not
1556 * loaded.
1557 */
1558int
1559command_unloadplugin (object *op, char *params)
1560{
1561 if (params == NULL)
1562 {
1563 new_draw_info (NDI_UNIQUE, 0, op, "Remove which plugin?");
1564 return 1;
1565 }
1566
1567 if (plugins_remove_plugin (params) == 0)
1568 new_draw_info (NDI_UNIQUE, 0, op, "Plugin successfully removed.");
1569 else
1570 new_draw_info (NDI_UNIQUE, 0, op, "Could not remove plugin.");
1571 return 1; 1260 return 1;
1572} 1261}
1573 1262
1574/** 1263/**
1575 * A players wants to become DM and hide. 1264 * A players wants to become DM and hide.
1896 return 0; 1585 return 0;
1897 } 1586 }
1898 1587
1899 if (!QUERY_FLAG (right, FLAG_REMOVED)) 1588 if (!QUERY_FLAG (right, FLAG_REMOVED))
1900 right->remove (); 1589 right->remove ();
1590
1901 inserted = insert_ob_in_ob (right, left); 1591 insert_ob_in_ob (right, left);
1902 if (left->type == PLAYER)
1903 if (inserted == right)
1904 esrv_send_item (left, right);
1905 else
1906 esrv_update_item (UPD_WEIGHT | UPD_NAME | UPD_NROF, left, inserted);
1907 1592
1908 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); 1593 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left));
1909 1594
1910 return 0; 1595 return 0;
1911 1596

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines