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.67 by root, Thu Jan 1 16:05:13 2009 UTC vs.
Revision 1.94 by root, Sat Sep 16 22:17:42 2017 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 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 (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <sproto.h> 26#include <sproto.h>
33/* Values for 'from' field of get_dm_object */ 34/* Values for 'from' field of get_dm_object */
34#define STACK_FROM_NONE 0 /* Item was not found */ 35#define STACK_FROM_NONE 0 /* Item was not found */
35#define STACK_FROM_TOP 1 /* Item is stack top */ 36#define STACK_FROM_TOP 1 /* Item is stack top */
36#define STACK_FROM_STACK 2 /* Item is somewhere in stack */ 37#define STACK_FROM_STACK 2 /* Item is somewhere in stack */
37#define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */ 38#define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */
38
39 39
40/** 40/**
41 * Enough of the DM functions seem to need this that I broke 41 * Enough of the DM functions seem to need this that I broke
42 * it out to a seperate function. name is the person 42 * it out to a seperate function. name is the person
43 * being saught, rq is who is looking for them. This 43 * being saught, rq is who is looking for them. This
70 70
71 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 71 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
72 return 0; 72 return 0;
73} 73}
74 74
75static void
76dm_stack_pop (player *pl)
77{
78 if (!pl->stack_items || !pl->stack_position)
79 {
80 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
81 return;
82 }
83
84 pl->stack_position--;
85 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position);
86}
87
75/** 88/**
76 * Actually hides specified player (obviously a DM). 89 * Get current stack top item for player.
77 * If 'silent_dm' is non zero, other players are informed of DM entering/leaving, 90 * Returns NULL if no stacked item.
78 * else they just think someone left/entered. 91 * If stacked item disappeared (freed), remove it.
92 *
93 * Ryo, august 2004
94 */
95static object *
96dm_stack_peek (player *pl)
97{
98 object *ob;
99
100 if (!pl->stack_position)
101 {
102 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
103 return NULL;
104 }
105
106 ob = find_object (pl->stack_items[pl->stack_position - 1]);
107 if (!ob)
108 {
109 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!");
110 dm_stack_pop (pl);
111 return NULL;
112 }
113
114 return ob;
115}
116
117/**
118 * Push specified item on player stack.
119 * Inform player of position.
120 * Initializes variables if needed.
79 */ 121 */
80void 122void
81do_wizard_hide (object *op, int silent_dm) 123dm_stack_push (player *pl, tag_t item)
82{ 124{
83 if (op->contr->hidden) 125 if (!pl->stack_items)
84 {
85 op->contr->hidden = 0;
86 op->invisible = 1;
87 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other 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);
90
91 if (!silent_dm)
92 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
93 } 126 {
94 else 127 pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE);
128 memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE);
95 { 129 }
96 op->contr->hidden = 1;
97 new_draw_info (NDI_UNIQUE, 0, op, "Other players will no longer see you.");
98 op->map->players--;
99 130
100 if (!silent_dm) 131 if (pl->stack_position == STACK_SIZE)
101 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
102
103 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s leaves the game.", &op->name);
104 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s left the game.", &op->name);
105 } 132 {
106} 133 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!");
107
108int
109command_hide (object *op, char *params)
110{
111 do_wizard_hide (op, 0);
112 return 1; 134 return;
135 }
136
137 pl->stack_items[pl->stack_position] = item;
138 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position);
139 pl->stack_position++;
140}
141
142/**
143 * Checks 'params' for object code.
144 *
145 * Can be:
146 * * empty => get current object stack top for player
147 * * number => get item with that tag, stack it for future use
148 * * $number => get specified stack item
149 * * "me" => player himself
150 *
151 * At function exit, params points to first non-object char
152 *
153 * 'from', if not NULL, contains at exit:
154 * * STACK_FROM_NONE => object not found
155 * * STACK_FROM_TOP => top item stack, may be NULL if stack was empty
156 * * STACK_FROM_STACK => item from somewhere in the stack
157 * * STACK_FROM_NUMBER => item by number, pushed on stack
158 *
159 * Ryo, august 2004
160 */
161static object *
162get_dm_object (player *pl, char **params, int *from)
163{
164 int item_tag, item_position;
165 object *ob;
166
167 if (!pl)
168 return NULL;
169
170 if (!params || !*params || **params == '\0')
171 {
172 if (from)
173 *from = STACK_FROM_TOP;
174 /* No parameter => get stack item */
175 return dm_stack_peek (pl);
176 }
177
178 /* Let's clean white spaces */
179 while (**params == ' ')
180 (*params)++;
181
182 /* Next case: number => item tag */
183 if (sscanf (*params, "%d", &item_tag))
184 {
185 /* Move parameter to next item */
186 while (isdigit (**params))
187 (*params)++;
188
189 /* And skip blanks, too */
190 while (**params == ' ')
191 (*params)++;
192
193 /* Get item */
194 ob = find_object (item_tag);
195 if (!ob)
196 {
197 if (from)
198 *from = STACK_FROM_NONE;
199 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag);
200 return NULL;
201 }
202
203 /* Got one, let's push it on stack */
204 dm_stack_push (pl, item_tag);
205 if (from)
206 *from = STACK_FROM_NUMBER;
207 return ob;
208 }
209
210 /* Next case: $number => stack item */
211 if (sscanf (*params, "$%d", &item_position))
212 {
213 /* Move parameter to next item */
214 (*params)++;
215
216 while (isdigit (**params))
217 (*params)++;
218 while (**params == ' ')
219 (*params)++;
220
221 if (item_position >= pl->stack_position)
222 {
223 if (from)
224 *from = STACK_FROM_NONE;
225 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position);
226 return NULL;
227 }
228
229 ob = find_object (pl->stack_items[item_position]);
230 if (!ob)
231 {
232 if (from)
233 *from = STACK_FROM_NONE;
234 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position);
235 return NULL;
236 }
237
238 if (from)
239 *from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP;
240 return ob;
241 }
242
243 /* Next case: 'me' => return pl->ob */
244 if (!strncmp (*params, "me", 2))
245 {
246 if (from)
247 *from = STACK_FROM_NUMBER;
248 dm_stack_push (pl, pl->ob->count);
249
250 /* Skip to next token */
251 (*params) += 2;
252 while (**params == ' ')
253 (*params)++;
254
255 return pl->ob;
256 }
257
258 /* Last case: get stack top */
259 if (from)
260 *from = STACK_FROM_TOP;
261 return dm_stack_peek (pl);
113} 262}
114 263
115/** 264/**
116 * This finds and returns the object which matches the name or 265 * This finds and returns the object which matches the name or
117 * object nubmer (specified via num #whatever). 266 * object nubmer (specified via num #whatever).
167 { 316 {
168 new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str); 317 new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str);
169 return 1; 318 return 1;
170 } 319 }
171 320
172 become_follower (ob, god); 321 ob->become_follower (god);
173 return 1; 322 return 1;
174} 323}
175
176// TODO: Rewrite banish in perl and get rid of the following two functions
177int
178command_kick (object *op, char *params)
179{
180 for_all_players (pl)
181 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params)))
182 {
183 object *plop = pl->ob;
184
185 if (!QUERY_FLAG (plop, FLAG_REMOVED) && !QUERY_FLAG (plop, FLAG_FREED))
186 {
187 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &plop->name);
188 plop->contr->killer = op;
189 }
190
191 pl->ns->destroy ();
192 }
193
194 return 1;
195}
196
197//TODO
198#if 0
199int
200command_save_overlay (object *op, char *params)
201{
202 if (!op)
203 return 0;
204
205 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
206 {
207 new_draw_info (NDI_UNIQUE, 0, op, "Sorry, you can't force an overlay save.");
208 return 1;
209 }
210
211 new_save_map (op->map, 2);
212 new_save_map (op->map, 0);
213 new_draw_info (NDI_UNIQUE, 0, op, "Current map has been saved as an" " overlay.");
214
215 ready_map_name (op->map->path, 0);
216
217 return 1;
218}
219#endif
220 324
221int 325int
222command_freeze (object *op, char *params) 326command_freeze (object *op, char *params)
223{ 327{
224 int ticks; 328 int ticks;
292 396
293int 397int
294command_summon (object *op, char *params) 398command_summon (object *op, char *params)
295{ 399{
296 int i; 400 int i;
297 object *dummy;
298 player *pl; 401 player *pl;
299 402
300 if (!op) 403 if (!op)
301 return 0; 404 return 0;
302 405
308 411
309 pl = get_other_player_from_name (op, params); 412 pl = get_other_player_from_name (op, params);
310 if (!pl) 413 if (!pl)
311 return 1; 414 return 1;
312 415
313 i = find_free_spot (op, op->map, op->x, op->y, 1, 9); 416 maptile *m = op->map;
417 sint16 nx = op->x;
418 sint16 ny = op->y;
419
420 i = find_free_spot (op, m, nx, ny, 1, SIZEOFFREE1+1);
314 if (i == -1) 421 if (i == -1)
315 { 422 {
316 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); 423 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player.");
317 return 1; 424 return 1;
318 } 425 }
319 426
320 pl->ob->player_goto (op->map->path, op->x + freearr_x[i], op->y + freearr_y[i]); 427 nx += DIRX (i);
428 ny += DIRY (i);
429
430 if (!xy_normalise (m, nx, ny))
431 {
432 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player.");
433 return 1;
434 }
435
436 pl->ob->player_goto (m->path, nx, ny);
321 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); 437 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned.");
322 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 438 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
323 439
324 return 1; 440 return 1;
325} 441}
342int 458int
343command_create (object *op, char *params) 459command_create (object *op, char *params)
344{ 460{
345 object *tmp = NULL; 461 object *tmp = NULL;
346 int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace; 462 int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace;
347 char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *bp4, *endline; 463 char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *endline;
348 archetype *at, *at_spell = NULL; 464 archetype *at, *at_spell = NULL;
349 artifact *art = NULL; 465 artifact *art = NULL;
350 466
351 if (!op) 467 if (!op)
352 return 0; 468 return 0;
477 /* 593 /*
478 * Rather than have two different blocks with a lot of similar code, 594 * Rather than have two different blocks with a lot of similar code,
479 * just create one object, do all the processing, and then determine 595 * just create one object, do all the processing, and then determine
480 * if that one object should be inserted or if we need to make copies. 596 * if that one object should be inserted or if we need to make copies.
481 */ 597 */
482 tmp = arch_to_object (at); 598 tmp = at->instance ();
483 599
484 if (set_magic) 600 if (set_magic)
485 set_abs_magic (tmp, magic); 601 set_abs_magic (tmp, magic);
486 602
487 if (art) 603 if (art)
488 give_artifact_abilities (tmp, art->item); 604 give_artifact_abilities (tmp, art->item);
489 605
490 if (need_identify (tmp)) 606 if (tmp->need_identify ())
491 { 607 {
492 SET_FLAG (tmp, FLAG_IDENTIFIED); 608 tmp->set_flag (FLAG_IDENTIFIED);
493 CLEAR_FLAG (tmp, FLAG_KNOWN_MAGICAL); 609 tmp->clr_flag (FLAG_KNOWN_MAGICAL);
494 } 610 }
495 611
496 /* 612 /*
497 * This entire block here tries to find variable pairings, 613 * This entire block here tries to find variable pairings,
498 * eg, 'hp 4' or the like. The mess here is that values 614 * eg, 'hp 4' or the like. The mess here is that values
500 * is we want to find two spaces, but if we got a quote, 616 * is we want to find two spaces, but if we got a quote,
501 * any spaces there don't count. 617 * any spaces there don't count.
502 */ 618 */
503 while (*bp2 && bp2 <= endline) 619 while (*bp2 && bp2 <= endline)
504 { 620 {
505 bp4 = NULL;
506 gotspace = 0; 621 gotspace = 0;
507 gotquote = 0; 622 gotquote = 0;
508 623
509 /* find the first quote */ 624 /* find the first quote */
510 for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) 625 for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++)
570 } 685 }
571 686
572 if (at->nrof) 687 if (at->nrof)
573 { 688 {
574 if (at_spell) 689 if (at_spell)
575 tmp->insert (arch_to_object (at_spell)); 690 tmp->insert (at_spell->instance ());
576 691
577 tmp->x = op->x; 692 tmp->x = op->x;
578 tmp->y = op->y; 693 tmp->y = op->y;
579 tmp->map = op->map; 694 tmp->map = op->map;
580 695
594 { 709 {
595 object *prev = 0, *head = 0; 710 object *prev = 0, *head = 0;
596 711
597 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) 712 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
598 { 713 {
599 object *dup = arch_to_object (atmp); 714 object *dup = atmp->instance ();
600 715
601 if (at_spell) 716 if (at_spell)
602 insert_ob_in_ob (arch_to_object (at_spell), dup); 717 insert_ob_in_ob (at_spell->instance (), dup);
603 718
604 /* 719 /*
605 * The head is what contains all the important bits, 720 * The head is what contains all the important bits,
606 * so just copying it over should be fine. 721 * so just copying it over should be fine.
607 */ 722 */
622 } 737 }
623 738
624 prev = dup; 739 prev = dup;
625 } 740 }
626 741
627 if (QUERY_FLAG (head, FLAG_ALIVE)) 742 if (head->flag [FLAG_ALIVE])
628 { 743 {
629 object *check = head; 744 object *check = head;
630 int size_x = 0; 745 int size_x = 0;
631 int size_y = 0; 746 int size_y = 0;
632 747
633 while (check) 748 while (check)
634 { 749 {
635 size_x = MAX (size_x, check->arch->x); 750 size_x = max (size_x, check->arch->x);
636 size_y = MAX (size_y, check->arch->y); 751 size_y = max (size_y, check->arch->y);
637 check = check->more; 752 check = check->more;
638 } 753 }
639 754
640 if (out_of_map (op->map, head->x + size_x, head->y + size_y)) 755 if (out_of_map (op->map, head->x + size_x, head->y + size_y))
641 { 756 {
723 838
724 char *dump = dump_object (tmp); 839 char *dump = dump_object (tmp);
725 new_draw_info (NDI_UNIQUE, 0, op, dump); 840 new_draw_info (NDI_UNIQUE, 0, op, dump);
726 free (dump); 841 free (dump);
727 842
728 if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL)) 843 if (tmp->flag [FLAG_OBJ_ORIGINAL])
729 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); 844 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original");
730 845
731 return 1; 846 return 1;
732} 847}
733 848
778 { 893 {
779 new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!"); 894 new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!");
780 return 1; 895 return 1;
781 } 896 }
782 897
783 if (QUERY_FLAG (tmp, FLAG_REMOVED)) 898 if (tmp->flag [FLAG_REMOVED])
784 { 899 {
785 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp)); 900 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp));
786 return 1; 901 return 1;
787 } 902 }
788 903
832 int q; 947 int q;
833 long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure 948 long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure
834 object *skillob = NULL; 949 object *skillob = NULL;
835 950
836 skill[0] = '\0'; 951 skill[0] = '\0';
837 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %s", buf, &i, skill)) < 2)) 952 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %[^\n]", buf, &i, skill)) < 2))
838 { 953 {
839 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); 954 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>].");
840 return 1; 955 return 1;
841 } 956 }
842 957
878/**************************************************************************/ 993/**************************************************************************/
879 994
880int 995int
881command_stats (object *op, char *params) 996command_stats (object *op, char *params)
882{ 997{
883 char thing[20];
884 char buf[MAX_BUF]; 998 char buf[MAX_BUF];
885 999
886 thing[0] = '\0'; 1000 if (params == NULL || params[0] == '\0')
887 if (params == NULL || !sscanf (params, "%s", thing) || thing == NULL)
888 { 1001 {
889 new_draw_info (NDI_UNIQUE, 0, op, "Who?"); 1002 new_draw_info (NDI_UNIQUE, 0, op, "Who?");
890 return 1; 1003 return 1;
891 } 1004 }
892 1005
893 for_all_players (pl) 1006 for_all_players (pl)
894 if (!strcmp (&pl->ob->name, thing)) 1007 if (!strcmp (&pl->ob->name, params))
895 { 1008 {
896 sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); 1009 sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp);
897 new_draw_info (NDI_UNIQUE, 0, op, buf); 1010 new_draw_info (NDI_UNIQUE, 0, op, buf);
898 sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); 1011 sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp);
899 new_draw_info (NDI_UNIQUE, 0, op, buf); 1012 new_draw_info (NDI_UNIQUE, 0, op, buf);
964 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 1077 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
965 return 1; 1078 return 1;
966} 1079}
967 1080
968int 1081int
969command_nowiz (object *op, char *params)
970{ /* 'nodm' is alias */
971 CLEAR_FLAG (op, FLAG_WIZ);
972 CLEAR_FLAG (op, FLAG_WIZPASS);
973 CLEAR_FLAG (op, FLAG_WIZCAST);
974 CLEAR_FLAG (op, FLAG_WIZLOOK);
975 op->contr->do_los = 1;
976
977 if (op->contr->hidden)
978 {
979 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
980 op->map->players++;
981 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
982 op->contr->hidden = 0;
983 op->invisible = 1;
984 }
985 else
986 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
987
988 return 1;
989}
990
991/**
992 * object *op is trying to become dm.
993 * pl_name is name supplied by player. Restrictive DM will make it harder
994 * for socket users to become DM - in that case, it will check for the players
995 * character name.
996 */
997static int
998checkdm (object *op, const char *pl_name, const char *pl_passwd, const char *pl_host)
999{
1000 FILE *dmfile;
1001 char buf[MAX_BUF];
1002 char line_buf[160], name[160], passwd[160], host[160];
1003
1004#ifdef RESTRICTIVE_DM
1005 *pl_name = op->name ? op->name : "*";
1006#endif
1007
1008 sprintf (buf, "%s/%s", settings.confdir, DMFILE);
1009 if ((dmfile = fopen (buf, "r")) == NULL)
1010 {
1011 LOG (llevDebug, "Could not find DM file.\n");
1012 return 0;
1013 }
1014
1015 while (fgets (line_buf, 160, dmfile) != NULL)
1016 {
1017 if (line_buf[0] == '#')
1018 continue;
1019 if (sscanf (line_buf, "%[^:]:%[^:]:%s\n", name, passwd, host) != 3)
1020 {
1021 LOG (llevError, "Warning - malformed dm file entry: %s\n", line_buf);
1022 }
1023 else if ((!strcmp (name, "*") || (pl_name && !strcmp (pl_name, name)))
1024 && (!strcmp (passwd, "*") || !strcmp (passwd, pl_passwd)) && (!strcmp (host, "*") || !strcmp (host, pl_host)))
1025 {
1026 fclose (dmfile);
1027 return (1);
1028 }
1029 }
1030 fclose (dmfile);
1031 return (0);
1032}
1033
1034int
1035do_wizard_dm (object *op, char *params, int silent)
1036{
1037 if (!op->contr)
1038 return 0;
1039
1040 if (QUERY_FLAG (op, FLAG_WIZ))
1041 {
1042 new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!");
1043 return 0;
1044 }
1045
1046 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host))
1047 {
1048 SET_FLAG (op, FLAG_WIZ);
1049 SET_FLAG (op, FLAG_WIZPASS);
1050 SET_FLAG (op, FLAG_WIZCAST);
1051 SET_FLAG (op, FLAG_WIZLOOK);
1052 op->contr->do_los = 1;
1053
1054 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!");
1055 op->contr->write_buf[0] = '\0';
1056
1057 if (!silent)
1058 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
1059
1060 return 1;
1061 }
1062 else
1063 {
1064 new_draw_info (NDI_UNIQUE, 0, op, "Sorry Pal, I don't think so.");
1065 op->contr->write_buf[0] = '\0';
1066 return 0;
1067 }
1068}
1069
1070/*
1071 * Actual command to perhaps become dm. Changed aroun a bit in version 0.92.2
1072 * - allow people on sockets to become dm, and allow better dm file
1073 */
1074int
1075command_dm (object *op, char *params)
1076{
1077 if (!op->contr)
1078 return 0;
1079
1080 do_wizard_dm (op, params, 0);
1081
1082 return 1;
1083}
1084
1085int
1086command_invisible (object *op, char *params) 1082command_invisible (object *op, char *params)
1087{ 1083{
1088 if (op) 1084 if (op)
1089 { 1085 {
1090 op->invisible += 100; 1086 op->invisible += TIME2TICK (60);
1091 update_object (op, UP_OBJ_CHANGE); 1087 update_object (op, UP_OBJ_CHANGE);
1092 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible."); 1088 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible.");
1093 } 1089 }
1094 1090
1095 return 0; 1091 return 0;
1103 * op is the player issuing the command. 1099 * op is the player issuing the command.
1104 */ 1100 */
1105static object * 1101static object *
1106get_spell_by_name (object *op, shstr_cmp spell_name) 1102get_spell_by_name (object *op, shstr_cmp spell_name)
1107{ 1103{
1108 archetype *at;
1109 archetype *found;
1110 int conflict_found;
1111 size_t spell_name_length;
1112
1113 /* First check for full name matches. */ 1104 /* First check for full name matches. */
1114 conflict_found = 0; 1105 int conflict_found = 0;
1115 found = NULL; 1106 archetype *found = 0;
1107
1116 for_all_archetypes (at) 1108 for_all_archetypes (at)
1117 { 1109 {
1118 if (at->type != SPELL) 1110 if (at->type != SPELL)
1119 continue; 1111 continue;
1120 1112
1129 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", &spell_name); 1121 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", &spell_name);
1130 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname); 1122 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname);
1131 } 1123 }
1132 1124
1133 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname); 1125 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname);
1134 continue; 1126 return 0;
1135 } 1127 }
1136 1128
1137 found = at; 1129 found = at;
1138 } 1130 }
1139 1131
1140 /* No match if more more than one archetype matches. */
1141 if (conflict_found)
1142 return NULL;
1143
1144 /* Return if exactly one archetype matches. */ 1132 /* Return if exactly one archetype matches. */
1145 if (found != NULL) 1133 if (found)
1146 return arch_to_object (found); 1134 return found->instance ();
1147
1148 /* No full match found: now check for partial matches. */
1149 spell_name_length = strlen (spell_name);
1150 conflict_found = 0;
1151 found = NULL;
1152 for_all_archetypes (at)
1153 {
1154 if (at->type != SPELL)
1155 continue;
1156
1157 if (strncmp (at->archname, "spelldirect_", 12) == 0)
1158 continue;
1159
1160 if (strncmp (at->object::name, spell_name, spell_name_length) != 0)
1161 continue;
1162
1163 if (found != NULL)
1164 {
1165 if (!conflict_found)
1166 {
1167 conflict_found = 1;
1168 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one spell matches %s:", &spell_name);
1169 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->object::name);
1170 }
1171 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->object::name);
1172 continue;
1173 }
1174
1175 found = at;
1176 }
1177
1178 /* No match if more more than one archetype matches. */
1179 if (conflict_found)
1180 return NULL;
1181
1182 /* Return if exactly one archetype matches. */
1183 if (found != NULL)
1184 return arch_to_object (found);
1185 1135
1186 /* No spell found: just print an error message. */ 1136 /* No spell found: just print an error message. */
1187 new_draw_info_format (NDI_UNIQUE, 0, op, "The spell %s does not exist.", &spell_name); 1137 new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist.");
1138
1188 return NULL; 1139 return 0;
1189} 1140}
1190 1141
1191static int 1142static int
1192command_learn_spell_or_prayer (object *op, char *params, int special_prayer) 1143command_learn_spell_or_prayer (object *op, char *params, int special_prayer)
1193{ 1144{
1237 { 1188 {
1238 new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to forget?"); 1189 new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to forget?");
1239 return 0; 1190 return 0;
1240 } 1191 }
1241 1192
1242 spell = lookup_spell_by_name (op, params); 1193 spell = op->find_spell (params);
1243 if (spell == NULL) 1194 if (spell == NULL)
1244 { 1195 {
1245 new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); 1196 new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params);
1246 return 0; 1197 return 0;
1247 } 1198 }
1248 1199
1249 do_forget_spell (op, spell->name); 1200 do_forget_spell (op, spell->name);
1250 return 1; 1201 return 1;
1251}
1252
1253/**
1254 * A players wants to become DM and hide.
1255 * Let's see if that's authorized.
1256 * Make sure to not tell anything to anyone.
1257 */
1258int
1259command_dmhide (object *op, char *params)
1260{
1261 if (!do_wizard_dm (op, params, 1))
1262 return 0;
1263
1264 do_wizard_hide (op, 1);
1265
1266 return 1;
1267}
1268
1269void
1270dm_stack_pop (player *pl)
1271{
1272 if (!pl->stack_items || !pl->stack_position)
1273 {
1274 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
1275 return;
1276 }
1277
1278 pl->stack_position--;
1279 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position);
1280}
1281
1282/**
1283 * Get current stack top item for player.
1284 * Returns NULL if no stacked item.
1285 * If stacked item disappeared (freed), remove it.
1286 *
1287 * Ryo, august 2004
1288 */
1289object *
1290dm_stack_peek (player *pl)
1291{
1292 object *ob;
1293
1294 if (!pl->stack_position)
1295 {
1296 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
1297 return NULL;
1298 }
1299
1300 ob = find_object (pl->stack_items[pl->stack_position - 1]);
1301 if (!ob)
1302 {
1303 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!");
1304 dm_stack_pop (pl);
1305 return NULL;
1306 }
1307
1308 return ob;
1309}
1310
1311/**
1312 * Push specified item on player stack.
1313 * Inform player of position.
1314 * Initializes variables if needed.
1315 */
1316void
1317dm_stack_push (player *pl, tag_t item)
1318{
1319 if (!pl->stack_items)
1320 {
1321 pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE);
1322 memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE);
1323 }
1324
1325 if (pl->stack_position == STACK_SIZE)
1326 {
1327 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!");
1328 return;
1329 }
1330
1331 pl->stack_items[pl->stack_position] = item;
1332 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position);
1333 pl->stack_position++;
1334}
1335
1336/**
1337 * Checks 'params' for object code.
1338 *
1339 * Can be:
1340 * * empty => get current object stack top for player
1341 * * number => get item with that tag, stack it for future use
1342 * * $number => get specified stack item
1343 * * "me" => player himself
1344 *
1345 * At function exit, params points to first non-object char
1346 *
1347 * 'from', if not NULL, contains at exit:
1348 * * STACK_FROM_NONE => object not found
1349 * * STACK_FROM_TOP => top item stack, may be NULL if stack was empty
1350 * * STACK_FROM_STACK => item from somewhere in the stack
1351 * * STACK_FROM_NUMBER => item by number, pushed on stack
1352 *
1353 * Ryo, august 2004
1354 */
1355object *
1356get_dm_object (player *pl, char **params, int *from)
1357{
1358 int item_tag, item_position;
1359 object *ob;
1360
1361 if (!pl)
1362 return NULL;
1363
1364 if (!params || !*params || **params == '\0')
1365 {
1366 if (from)
1367 *from = STACK_FROM_TOP;
1368 /* No parameter => get stack item */
1369 return dm_stack_peek (pl);
1370 }
1371
1372 /* Let's clean white spaces */
1373 while (**params == ' ')
1374 (*params)++;
1375
1376 /* Next case: number => item tag */
1377 if (sscanf (*params, "%d", &item_tag))
1378 {
1379 /* Move parameter to next item */
1380 while (isdigit (**params))
1381 (*params)++;
1382
1383 /* And skip blanks, too */
1384 while (**params == ' ')
1385 (*params)++;
1386
1387 /* Get item */
1388 ob = find_object (item_tag);
1389 if (!ob)
1390 {
1391 if (from)
1392 *from = STACK_FROM_NONE;
1393 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag);
1394 return NULL;
1395 }
1396
1397 /* Got one, let's push it on stack */
1398 dm_stack_push (pl, item_tag);
1399 if (from)
1400 *from = STACK_FROM_NUMBER;
1401 return ob;
1402 }
1403
1404 /* Next case: $number => stack item */
1405 if (sscanf (*params, "$%d", &item_position))
1406 {
1407 /* Move parameter to next item */
1408 (*params)++;
1409
1410 while (isdigit (**params))
1411 (*params)++;
1412 while (**params == ' ')
1413 (*params)++;
1414
1415 if (item_position >= pl->stack_position)
1416 {
1417 if (from)
1418 *from = STACK_FROM_NONE;
1419 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position);
1420 return NULL;
1421 }
1422
1423 ob = find_object (pl->stack_items[item_position]);
1424 if (!ob)
1425 {
1426 if (from)
1427 *from = STACK_FROM_NONE;
1428 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position);
1429 return NULL;
1430 }
1431
1432 if (from)
1433 *from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP;
1434 return ob;
1435 }
1436
1437 /* Next case: 'me' => return pl->ob */
1438 if (!strncmp (*params, "me", 2))
1439 {
1440 if (from)
1441 *from = STACK_FROM_NUMBER;
1442 dm_stack_push (pl, pl->ob->count);
1443
1444 /* Skip to next token */
1445 (*params) += 2;
1446 while (**params == ' ')
1447 (*params)++;
1448
1449 return pl->ob;
1450 }
1451
1452 /* Last case: get stack top */
1453 if (from)
1454 *from = STACK_FROM_TOP;
1455 return dm_stack_peek (pl);
1456} 1202}
1457 1203
1458/** 1204/**
1459 * Pop the stack top. 1205 * Pop the stack top.
1460 */ 1206 */
1520} 1266}
1521 1267
1522int 1268int
1523command_insert_into (object *op, char *params) 1269command_insert_into (object *op, char *params)
1524{ 1270{
1525 object *left, *right, *inserted; 1271 object *left, *right;
1526 int left_from, right_from; 1272 int left_from, right_from;
1527 1273
1528 left = get_dm_object (op->contr, &params, &left_from); 1274 left = get_dm_object (op->contr, &params, &left_from);
1529 if (!left) 1275 if (!left)
1530 { 1276 {
1573 { 1319 {
1574 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); 1320 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!");
1575 return 0; 1321 return 0;
1576 } 1322 }
1577 1323
1578 if (!QUERY_FLAG (right, FLAG_REMOVED)) 1324 if (!right->flag [FLAG_REMOVED])
1579 right->remove (); 1325 right->remove ();
1580 1326
1581 insert_ob_in_ob (right, left); 1327 object *inserted = insert_ob_in_ob (right, left);
1582 1328
1583 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); 1329 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left));
1584 1330
1585 return 0; 1331 return 0;
1586 1332

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines