Debian Codegraph @

server/c_wiz.c

raw symbols SCIP
1 /*
2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
3 *
4 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
6 *
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
10 *
11 * The authors can be reached via e-mail at <[email protected]>.
12 */
13
14 /**
15 * @file
16 * Those functions are used by DMs.
17 * @todo explain item stack, item specifier for commands.
18 */
19
20 #include "global.h"
21
22 #include <ctype.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/stat.h>
26
27 #include "sproto.h"
28 #include "spells.h"
29 #include "treasure.h"
30 #include "skills.h"
31
32 /* Defines for DM item stack **/
33 #define STACK_SIZE 50 /**< Stack size, static */
34 /** Values for 'from' field of get_dm_object() */
35 enum {
36 STACK_FROM_NONE = 0, /**< Item was not found */
37 STACK_FROM_TOP = 1, /**< Item is stack top */
38 STACK_FROM_STACK = 2, /**< Item is somewhere in stack */
39 STACK_FROM_NUMBER = 3 /**< Item is a number (may be top) */
40 };
41
42 /** Time, in seconds from epoch, of server shutdown. */
43 int cmd_shutdown_time = 0;
44
45 /**
46 * Enough of the DM functions seem to need this that I broke
47 * it out to a seperate function. name is the person
48 * being saught, op is who is looking for them. This
49 * prints diagnostics messages, and returns the
50 * other player, or NULL otherwise.
51 *
52 * @param op
53 * player searching someone.
54 * @param name
55 * name to search for.
56 * @return
57 * player, or NULL if player can't be found.
58 */
59 static player *get_other_player_from_name(object *op, const char *name) {
60 player *pl;
61
62 if (!name)
63 return NULL;
64
65 for (pl = first_player; pl != NULL; pl = pl->next)
66 if (!strncmp(pl->ob->name, name, MAX_NAME))
67 break;
68
69 if (pl == NULL) {
70 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
71 "No such player.");
72 return NULL;
73 }
74
75 if (pl->ob == op) {
76 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
77 "You can't do that to yourself.");
78 return NULL;
79 }
80 if (pl->state != ST_PLAYING) {
81 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
82 "That player is in no state for that right now.");
83 return NULL;
84 }
85 return pl;
86 }
87
88 /**
89 * Remove an item from the wizard's item stack.
90 *
91 * @param pl
92 * wizard.
93 */
94 static void dm_stack_pop(player *pl) {
95 if (!pl->stack_items || !pl->stack_position) {
96 draw_ext_info(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
97 "Empty stack!");
98 return;
99 }
100
101 pl->stack_position--;
102 draw_ext_info_format(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
103 "Popped item from stack, %d left.",
104 pl->stack_position);
105 }
106
107 /**
108 * Get current stack top item for player.
109 * Returns NULL if no stacked item.
110 * If stacked item disappeared (freed), remove it.
111 *
112 * Ryo, august 2004
113 *
114 * @param pl
115 * wizard.
116 * @return
117 * item on top of stack, or NULL if deleted/stack empty.
118 */
119 static object *dm_stack_peek(player *pl) {
120 object *ob;
121
122 if (!pl->stack_position) {
123 draw_ext_info(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
124 "Empty stack!");
125 return NULL;
126 }
127
128 ob = object_find_by_tag_global(pl->stack_items[pl->stack_position-1]);
129 if (!ob) {
130 draw_ext_info(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
131 "Stacked item was removed!");
132 dm_stack_pop(pl);
133 return NULL;
134 }
135
136 return ob;
137 }
138
139 /**
140 * Push specified item on player stack.
141 * Inform player of position.
142 * Initializes variables if needed.
143 *
144 * @param pl
145 * wizard.
146 * @param item
147 * item to put on stack.
148 */
149 static void dm_stack_push(player *pl, tag_t item) {
150 if (!pl->stack_items) {
151 pl->stack_items = (tag_t *)malloc(sizeof(tag_t)*STACK_SIZE);
152 memset(pl->stack_items, 0, sizeof(tag_t)*STACK_SIZE);
153 }
154
155 if (pl->stack_position == STACK_SIZE) {
156 draw_ext_info(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
157 "Item stack full!");
158 return;
159 }
160
161 pl->stack_items[pl->stack_position] = item;
162 draw_ext_info_format(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
163 "Item stacked as %d.",
164 pl->stack_position);
165 pl->stack_position++;
166 }
167
168 /**
169 * Checks 'params' for object code.
170 *
171 * Can be:
172 * - empty => get current object stack top for player
173 * - number => get item with that tag, stack it for future use
174 * - $number => get specified stack item
175 * - "me" => player himself
176 *
177 * At function exit, params points to first non-object char
178 *
179 * 'from', if not NULL, contains at exit:
180 * - ::STACK_FROM_NONE => object not found
181 * - ::STACK_FROM_TOP => top item stack, may be NULL if stack was empty
182 * - ::STACK_FROM_STACK => item from somewhere in the stack
183 * - ::STACK_FROM_NUMBER => item by number, pushed on stack
184 *
185 * Ryo, august 2004
186 *
187 * @param pl
188 * wizard.
189 * @param params
190 * object specified.
191 * @param from
192 * @return
193 * pointed object, or NULL if nothing suitable was found.
194 */
195 static object *get_dm_object(player *pl, const char **params, int *from) {
196 int item_tag, item_position;
197 object *ob;
198
199 if (!pl)
200 return NULL;
201
202 if (**params == '\0') {
203 if (from)
204 *from = STACK_FROM_TOP;
205 /* No parameter => get stack item */
206 return dm_stack_peek(pl);
207 }
208
209 /* Let's clean white spaces */
210 while (**params == ' ')
211 (*params)++;
212
213 /* Next case: number => item tag */
214 if (sscanf(*params, "%d", &item_tag)) {
215 /* Move parameter to next item */
216 while (isdigit(**params))
217 (*params)++;
218
219 /* And skip blanks, too */
220 while (**params == ' ')
221 (*params)++;
222
223 /* Get item */
224 ob = object_find_by_tag_global(item_tag);
225 if (!ob) {
226 if (from)
227 *from = STACK_FROM_NONE;
228 draw_ext_info_format(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
229 "No such item %d!",
230 item_tag);
231 return NULL;
232 }
233
234 /* Got one, let's push it on stack */
235 dm_stack_push(pl, item_tag);
236 if (from)
237 *from = STACK_FROM_NUMBER;
238 return ob;
239 }
240
241 /* Next case: $number => stack item */
242 if (sscanf(*params, "$%d", &item_position)) {
243 /* Move parameter to next item */
244 (*params)++;
245
246 while (isdigit(**params))
247 (*params)++;
248 while (**params == ' ')
249 (*params)++;
250
251 if (item_position >= pl->stack_position) {
252 if (from)
253 *from = STACK_FROM_NONE;
254 draw_ext_info_format(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
255 "No such stack item %d!",
256 item_position);
257 return NULL;
258 }
259
260 ob = object_find_by_tag_global(pl->stack_items[item_position]);
261 if (!ob) {
262 if (from)
263 *from = STACK_FROM_NONE;
264 draw_ext_info_format(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
265 "Stack item %d was removed.",
266 item_position);
267 return NULL;
268 }
269
270 if (from)
271 *from = item_position < pl->stack_position-1 ? STACK_FROM_STACK : STACK_FROM_TOP;
272 return ob;
273 }
274
275 /* Next case: 'me' => return pl->ob */
276 if (!strncmp(*params, "me", 2)) {
277 if (from)
278 *from = STACK_FROM_NUMBER;
279 dm_stack_push(pl, pl->ob->count);
280
281 /* Skip to next token */
282 (*params) += 2;
283 while (**params == ' ')
284 (*params)++;
285
286 return pl->ob;
287 }
288
289 /* Last case: get stack top */
290 if (from)
291 *from = STACK_FROM_TOP;
292 return dm_stack_peek(pl);
293 }
294
295 /**
296 * This command will stress server.
297 *
298 * It will basically load all world maps (so 900 maps).
299 *
300 * @param op
301 * DM wanting to test the server.
302 * @param params
303 * option, must be "TRUE" for the test to happen.
304 */
305 void command_loadtest(object *op, const char *params) {
306 uint32_t x, y;
307 char buf[1024];
308
309 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DEBUG,
310 "loadtest will stress server through teleporting at different map places. "
311 "Use at your own risk. Very long loop used so server may have to be reset. "
312 "type loadtest TRUE to run");
313 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DEBUG,
314 "{%s}",
315 params);
316 if (*params == '\0')
317 return;
318 if (strncmp(params, "TRUE", 4))
319 return;
320
321 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DEBUG,
322 "gogogo");
323
324 for (x = 0; x < settings.worldmaptilesx; x++) {
325 for (y = 0; y < settings.worldmaptilesy; y++) {
326 snprintf(buf, sizeof(buf), "/world/world_%u_%u", x+settings.worldmapstartx, y+settings.worldmapstarty);
327 command_goto(op, buf);
328 }
329 }
330 }
331
332 static void unhide(object* op) {
333 op->contr->hidden = 0;
334 op->invisible = 1;
335 op->map->players++;
336 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
337 "You are no longer hidden from other players");
338 draw_ext_info_format(NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL,
339 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_PLAYER,
340 "%s has entered the game.", op->name);
341 }
342
343 /**
344 * Actually hides or unhides specified player (obviously a DM).
345 *
346 * @param op
347 * DM hiding.
348 * @param silent_dm
349 * if non zero, other players are informed of DM entering/leaving, else they just think someone left/entered.
350 */
351 static void do_wizard_hide(object *op, int silent_dm) {
352 if (op->contr->hidden) {
353 unhide(op);
354 if (!silent_dm) {
355 draw_ext_info(NDI_UNIQUE|NDI_ALL|NDI_LT_GREEN, 1, NULL,
356 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM,
357 "The Dungeon Master has arrived!");
358 }
359 } else {
360 op->contr->hidden = 1;
361 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
362 "Other players will no longer see you.");
363 op->map->players--;
364 if (!silent_dm) {
365 draw_ext_info(NDI_UNIQUE|NDI_ALL|NDI_LT_GREEN, 1, NULL,
366 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM,
367 "The Dungeon Master is gone..");
368 }
369 draw_ext_info_format(NDI_UNIQUE|NDI_ALL|NDI_DK_ORANGE, 5, NULL,
370 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_PLAYER,
371 "%s leaves the game.",
372 op->name);
373 draw_ext_info_format(NDI_UNIQUE|NDI_ALL|NDI_DK_ORANGE, 5, NULL,
374 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_PLAYER,
375 "%s left the game.",
376 op->name);
377 }
378 }
379
380 /**
381 * Wizard 'hide' command.
382 *
383 * @param op
384 * DM wanting to hide.
385 * @param params
386 * ignored.
387 */
388 void command_hide(object *op, const char *params) {
389 do_wizard_hide(op, 0);
390 }
391
392 /**
393 * This finds and returns the object which matches the name or
394 * object number (specified via num \#whatever).
395 *
396 * @param params
397 * object to find.
398 * @return
399 * suitable object, or NULL if none found.
400 */
401 static object *find_object_both(const char *params) {
402 if (params[0] == '#')
403 return object_find_by_tag_global(atol(params+1));
404 else
405 return object_find_by_name_global(params);
406 }
407
408 /**
409 * Sets the god for some objects.
410 *
411 * @param op
412 * DM wanting to change an object.
413 * @param params
414 * command options. Should contain two values, first the object to change, followed by the god to change it to.
415 */
416 void command_setgod(object *op, const char *params) {
417 object *ob;
418 const object *god;
419 char *str;
420
421 if (*params == '\0' || !(str = strchr(params, ' '))) {
422 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
423 "Usage: set_god player god");
424 return;
425 }
426
427 /* kill the space, and set string to the next param */
428 *str++ = '\0';
429 if (!(ob = find_object_both(params))) {
430 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
431 "Set whose god - can not find object %s?",
432 params);
433 return;
434 }
435
436 /*
437 * Perhaps this is overly restrictive? Should we perhaps be able
438 * to rebless altars and the like?
439 */
440 if (ob->type != PLAYER) {
441 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
442 "%s is not a player - can not change its god",
443 ob->name);
444 return;
445 }
446
447 god = find_god(str);
448 if (god == NULL) {
449 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
450 "No such god %s.",
451 str);
452 return;
453 }
454
455 become_follower(ob, god);
456 }
457
458 /**
459 * Kicks a player from the server.
460 *
461 * @param op
462 * DM kicking.
463 * @param params
464 * player to kick. Must be a full name match.
465 */
466 static void command_kick2(object *op, const char *params) {
467 struct pl *pl;
468
469 for (pl = first_player; pl != NULL; pl = pl->next) {
470 if ((*params == '\0' || !strcmp(pl->ob->name, params)) && pl->ob != op) {
471 object *op;
472 int removed = 0;
473
474 op = pl->ob;
475 if (!QUERY_FLAG(op, FLAG_REMOVED)) {
476 /* Avion : Here we handle the KICK global event */
477 execute_global_event(EVENT_KICK, op, *params == '\0' ? NULL : params);
478 object_remove(op);
479 removed = 1;
480 }
481 op->direction = 0;
482 draw_ext_info_format(NDI_UNIQUE|NDI_ALL|NDI_RED, 5, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM,
483 "%s is kicked out of the game.",
484 op->name);
485 strcpy(op->contr->killer, "left");
486 hiscore_check(op, 0); /* Always check score */
487
488 /*
489 * not sure how the player would be freed, but did see
490 * a crash here - if that is the case, don't save the
491 * the player.
492 */
493 if (!removed && !QUERY_FLAG(op, FLAG_FREED)) {
494 (void)save_player(op, 0);
495 if (op->map)
496 op->map->players--;
497 }
498 #if MAP_MAXTIMEOUT
499 if (op->map)
500 op->map->timeout = MAP_TIMEOUT(op->map);
501 #endif
502 pl->socket.status = Ns_Dead;
503 }
504 }
505 }
506
507 /**
508 * Add player's IP to ban_file and kick them off the server.
509 *
510 * I know most people have dynamic IPs but this is more of a short term
511 * solution if they have to get a new IP to play maybe they'll calm down.
512 * This uses the banish_file in the local directory *not *the ban_file
513 * The action is logged with a ! for easy searching. -tm
514 *
515 * @param op
516 * DM banishing.
517 * @param params
518 * player to banish. Must be a complete name match.
519 * @return
520 * 1.
521 */
522 void command_banish(object *op, const char *params) {
523 player *pl;
524 FILE *banishfile;
525 char buf[MAX_BUF];
526 time_t now;
527
528 if (*params == '\0') {
529 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
530 "Usage: banish <player>.");
531 return;
532 }
533
534 pl = get_other_player_from_name(op, params);
535 if (!pl)
536 return;
537
538 snprintf(buf, sizeof(buf), "%s/%s", settings.localdir, BANISHFILE);
539
540 if ((banishfile = fopen(buf, "a")) == NULL) {
541 LOG(llevDebug, "Could not find file banish_file.\n");
542 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
543 "Could not find banish_file.");
544 return;
545 }
546
547 now = time(NULL);
548 /*
549 * Record this as a comment - then we don't have to worry about changing
550 * the parsing code.
551 */
552 fprintf(banishfile, "# %s (%s) banned by %s at %s\n", pl->ob->name, pl->socket.host, op->name, ctime(&now));
553 fprintf(banishfile, "*@%s\n", pl->socket.host);
554 fclose(banishfile);
555
556 LOG(llevDebug, "! %s banned %s from IP: %s.\n", op->name, pl->ob->name, pl->socket.host);
557
558 draw_ext_info_format(NDI_UNIQUE|NDI_RED, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
559 "You banish %s",
560 pl->ob->name);
561
562 draw_ext_info_format(NDI_UNIQUE|NDI_ALL|NDI_RED, 5, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM,
563 "%s banishes %s from the land!",
564 op->name, pl->ob->name);
565 command_kick2(op, pl->ob->name);
566 }
567
568 /**
569 * Kicks a player from the server.
570 *
571 * @param op
572 * DM kicking.
573 * @param params
574 * player to kick. Must be a full name match.
575 */
576 void command_kick(object *op, const char *params) {
577 command_kick2(op, params);
578 }
579
580 /**
581 * Saves the op's map as an overlay - objects are persisted.
582 *
583 * @param op
584 * DM wanting to save.
585 * @param params
586 * ignored.
587 */
588 void command_overlay_save(object *op, const char *params) {
589 if (!op)
590 return;
591
592 if (save_map(op->map, SAVE_MODE_OVERLAY) < 0)
593 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
594 "Overlay save error!");
595 else
596 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
597 "Current map has been saved as an overlay.");
598 }
599
600 /**
601 * Removes the overlay for op's current map.
602 *
603 * @param op
604 * DM acting.
605 * @param params
606 * ignored.
607 */
608 void command_overlay_reset(object *op, const char *params) {
609 char filename[MAX_BUF];
610 struct stat stats;
611
612 create_overlay_pathname(op->map->path, filename, MAX_BUF);
613 if (!stat(filename, &stats))
614 if (!unlink(filename))
615 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
616 "Overlay successfully removed.");
617 else
618 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
619 "Overlay couldn't be removed.");
620 else
621 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
622 "No overlay for current map.");
623 }
624
625 /**
626 * A simple toggle for the no_shout field. AKA the MUZZLE command.
627 *
628 * @param op
629 * wizard toggling.
630 * @param params
631 * player to mute/unmute.
632 */
633 void command_toggle_shout(object *op, const char *params) {
634 player *pl;
635
636 if (*params == '\0') {
637 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
638 "Usage: toggle_shout <player>.");
639 return;
640 }
641
642 pl = get_other_player_from_name(op, params);
643 if (!pl)
644 return;
645
646 if (pl->ob->contr->no_shout == 0) {
647 pl->ob->contr->no_shout = 1;
648
649 draw_ext_info(NDI_UNIQUE|NDI_RED, 0, pl->ob, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM,
650 "You have been muzzled by the DM!");
651 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
652 "You muzzle %s.",
653 pl->ob->name);
654
655 /* Avion : Here we handle the MUZZLE global event */
656 execute_global_event(EVENT_MUZZLE, pl->ob, params);
657
658 return;
659 }
660
661 pl->ob->contr->no_shout = 0;
662 draw_ext_info(NDI_UNIQUE|NDI_ORANGE, 0, pl->ob, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM,
663 "You are allowed to shout and chat again.");
664 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
665 "You remove %s's muzzle.",
666 pl->ob->name);
667 }
668
669 /**
670 * Totally shutdowns the server.
671 *
672 * @param op
673 * wizard shutting down the server.
674 * @param params
675 * When to shut down the server.
676 */
677 void command_shutdown(object *op, const char *params) {
678 if (strlen(params) == 0) {
679 /* Give DM command help and display current shutdown status. */
680 command_help(op, "shutdown");
681
682 if (cmd_shutdown_time != 0) {
683 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
684 MSG_TYPE_COMMAND_DM, "Server is shutting down soon.");
685 }
686 } else if (strcmp(params, "cancel") == 0) {
687 /* Tell everyone that the server is no longer shutting down. */
688 if (cmd_shutdown_time != 0) {
689 draw_ext_info(NDI_UNIQUE | NDI_ALL, 0, op, MSG_TYPE_ADMIN,
690 MSG_TYPE_ADMIN_DM, "Server shutdown cancelled.");
691 cmd_shutdown_time = 0;
692 LOG(llevInfo, "Server shutdown cancelled by %s.\n", op->name);
693 } else {
694 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
695 MSG_TYPE_COMMAND_ERROR, "No shutdown is pending.");
696 }
697 } else if (strncmp(params, "now", 3) == 0) {
698 /* Announce and shut down immediately. */
699 draw_ext_info(NDI_UNIQUE | NDI_ALL, 0, op, MSG_TYPE_ADMIN,
700 MSG_TYPE_ADMIN_DM, "Server is shutting down now!");
701 cmd_shutdown_time = time(NULL);
702 LOG(llevInfo, "Server shutdown initiated by %s.\n", op->name);
703 } else {
704 /* Schedule (but don't announce) a shutdown. */
705 int minutes = atoi(params);
706
707 if (minutes > 0 && minutes <= 720) {
708 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
709 MSG_TYPE_COMMAND_SUCCESS,
710 "Server will shut down in %d minutes.", minutes);
711 cmd_shutdown_time = time(NULL) + minutes * 60;
712 LOG(llevInfo, "Server shutdown initiated by %s in %d minutes.\n", op->name, minutes);
713 } else {
714 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
715 MSG_TYPE_COMMAND_ERROR,
716 "Please specify a reasonable time in minutes.");
717 }
718 }
719 }
720
721 /**
722 * Wizard teleports to a map.
723 *
724 * @param op
725 * wizard teleporting.
726 * @param params
727 * map to teleport to. Can be absolute or relative path.
728 */
729 void command_goto(object *op, const char *params) {
730 if (!op)
731 return ;
732
733 if (*params == '\0') {
734 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
735 "Go to what level?");
736 return;
737 }
738
739 do_goto(op, params, -1, -1);
740 }
741
742 /**
743 * Freezes a player for a specified tick count, 100 by default.
744 *
745 * @param op
746 * wizard freezing the player.
747 * @param params
748 * optional tick count, followed by player name.
749 */
750 void command_freeze(object *op, const char *params) {
751 int ticks;
752 player *pl;
753
754 if (*params == '\0') {
755 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
756 "Usage: freeze [ticks] <player>.");
757 return;
758 }
759
760 ticks = atoi(params);
761 if (ticks) {
762 while ((isdigit(*params) || isspace(*params)) && *params != 0)
763 params++;
764 if (*params == 0) {
765 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
766 "Usage: freeze [ticks] <player>.");
767 return;
768 }
769 } else
770 ticks = 100;
771
772 pl = get_other_player_from_name(op, params);
773 if (!pl)
774 return;
775
776 draw_ext_info(NDI_UNIQUE|NDI_RED, 0, pl->ob, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM,
777 "You have been frozen by the DM!");
778
779 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
780 "You freeze %s for %d ticks",
781 pl->ob->name, ticks);
782
783 pl->ob->speed_left = -(pl->ob->speed*ticks);
784 }
785
786 /**
787 * Put a player into jail, taking into account cursed exits and player's region.
788 * @param who player to put in jail
789 * @retval 0 player was moved to jail.
790 * @retval -1 no jail found.
791 * @retval -2 couldn't move to jail (map loading error, or already at jail's position).
792 * @retval -3 op isn't a player.
793 */
794 int player_arrest(object *who) {
795 object *dummy;
796 mapstruct *cur;
797 int x, y;
798
799 if (who->type != PLAYER)
800 return -3;
801
802 dummy = get_jail_exit(who);
803 if (!dummy) {
804 return -1;
805 }
806 cur = who->map;
807 x = who->x;
808 y = who->y;
809 enter_exit(who, dummy);
810 object_free(dummy, FREE_OBJ_NO_DESTROY_CALLBACK);
811
812 if (cur == who->map && x == who->x && y == who->y)
813 return -2;
814
815 return 0;
816 }
817
818 /**
819 * Wizard jails player.
820 *
821 * @param op
822 * wizard.
823 * @param params
824 * player to jail.
825 */
826 void command_arrest(object *op, const char *params) {
827 player *pl;
828 int ret;
829
830 if (!op)
831 return;
832 if (*params == '\0') {
833 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
834 "Usage: arrest <player>.");
835 return;
836 }
837 pl = get_other_player_from_name(op, params);
838 if (!pl)
839 return;
840
841 ret = player_arrest(pl->ob);
842 if (ret == -1) {
843 /* we have nowhere to send the prisoner....*/
844 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
845 "Can't jail player, there is no map to hold them");
846 return;
847 }
848 if (ret == -2) {
849 /* something prevented jailing the player */
850 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
851 "Can't jail player, map loading issue or already in jail's position");
852 return;
853
854 }
855
856 draw_ext_info(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM,
857 "You have been arrested.");
858 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
859 "Jailed %s",
860 pl->ob->name);
861 LOG(llevInfo, "Player %s arrested by %s\n", pl->ob->name, op->name);
862 }
863
864 /**
865 * Summons player near DM.
866 * @param op
867 * DM.
868 * @param params
869 * player to summon.
870 */
871 void command_summon(object *op, const char *params) {
872 int i;
873 object *dummy;
874 player *pl;
875
876 if (!op)
877 return;
878
879 if (*params == '\0') {
880 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
881 "Usage: summon <player>.");
882 return;
883 }
884
885 pl = get_other_player_from_name(op, params);
886 if (!pl)
887 return;
888
889 i = object_find_free_spot(op, op->map, op->x, op->y, 1, 9);
890 if (i == -1) {
891 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
892 "Can not find a free spot to place summoned player.");
893 return;
894 }
895
896 dummy = object_new();
897 EXIT_PATH(dummy) = add_string(op->map->path);
898 EXIT_X(dummy) = op->x+freearr_x[i];
899 EXIT_Y(dummy) = op->y+freearr_y[i];
900 enter_exit(pl->ob, dummy);
901 object_free(dummy, FREE_OBJ_NO_DESTROY_CALLBACK);
902 draw_ext_info(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM,
903 "You are summoned.");
904 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
905 "You summon %s",
906 pl->ob->name);
907 }
908
909 /**
910 * Teleport next to target player.
911 *
912 * @param op
913 * DM teleporting.
914 * @param params
915 * options sent by player.
916 */
917 /* mids 01/16/2002 */
918 void command_teleport(object *op, const char *params) {
919 int i;
920 object *dummy;
921 player *pl;
922
923 if (!op)
924 return;
925
926 if (*params == '\0') {
927 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
928 "Usage: teleport <player>.");
929 return;
930 }
931
932 pl = find_player_partial_name(params);
933 if (!pl) {
934 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
935 "No such player or ambiguous name.");
936 return;
937 }
938
939 i = object_find_free_spot(pl->ob, pl->ob->map, pl->ob->x, pl->ob->y, 1, 9);
940 if (i == -1) {
941 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
942 "Can not find a free spot to teleport to.");
943 return;
944 }
945
946 dummy = object_new();
947 EXIT_PATH(dummy) = add_string(pl->ob->map->path);
948 EXIT_X(dummy) = pl->ob->x+freearr_x[i];
949 EXIT_Y(dummy) = pl->ob->y+freearr_y[i];
950 enter_exit(op, dummy);
951 object_free(dummy, FREE_OBJ_NO_DESTROY_CALLBACK);
952 if (!op->contr->hidden)
953 draw_ext_info(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM,
954 "You see a portal open.");
955 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
956 "You teleport to %s",
957 pl->ob->name);
958 }
959
960 /**
961 * Wizard wants to create an object.
962 *
963 * This function is a real mess, because we're stucking getting
964 * the entire item description in one block of text, so we just
965 * can't simply parse it - we need to look for double quotes
966 * for example. This could actually get much simpler with just a
967 * little help from the client - if we could get line breaks, it
968 * makes parsing much easier, eg, something like:
969 * - arch dragon
970 * - name big nasty creature
971 * - hp 5
972 * - sp 30
973 *
974 * which is much easier to parse than
975 * dragon name "big nasty creature" hp 5 sp 30
976 * for example.
977 *
978 * @param op
979 * wizard.
980 * @param params
981 * object description.
982 * @todo enable line breaks in command.
983 */
984 void command_create(object *op, const char *params) {
985 object *tmp = NULL;
986 uint32_t i;
987 int magic, set_magic = 0, set_nrof = 0, gotquote, gotspace;
988 uint32_t nrof;
989 char *cp, *bp, *bp2, *bp3, *endline, cpy[MAX_BUF];
990 archetype *at, *at_spell = NULL;
991 const artifact *art = NULL;
992
993 if (!op)
994 return;
995
996 if (*params == '\0') {
997 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
998 "Usage: create [nr] [magic] <archetype> [ of <artifact>] [variable_to_patch setting]");
999 return;
1000 }
1001 safe_strncpy(cpy, params, sizeof(cpy));
1002 bp = cpy;
1003
1004 /* We need to know where the line ends */
1005 endline = bp+strlen(bp);
1006
1007 if (sscanf(bp, "%u ", &nrof)) {
1008 if ((bp = strchr(cpy, ' ')) == NULL) {
1009 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1010 "Usage: create [nr] [magic] <archetype> [ of <artifact>] [variable_to_patch setting]");
1011 return;
1012 }
1013 bp++;
1014 set_nrof = 1;
1015 LOG(llevDebug, "%s creates: (%u) %s\n", op->name, nrof, bp);
1016 }
1017 if (sscanf(bp, "%d ", &magic)) {
1018 if ((bp = strchr(bp, ' ')) == NULL) {
1019 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1020 "Usage: create [nr] [magic] <archetype> [ of <artifact>] [variable_to_patch setting]");
1021 return;
1022 }
1023 bp++;
1024 set_magic = 1;
1025 LOG(llevDebug, "%s creates: (%d) (%d) %s\n", op->name, nrof, magic, bp);
1026 }
1027 if ((cp = strstr(bp, " of ")) != NULL) {
1028 *cp = '\0';
1029 cp += 4;
1030 }
1031 for (bp2 = bp; *bp2; bp2++) {
1032 if (*bp2 == ' ') {
1033 *bp2 = '\0';
1034 bp2++;
1035 break;
1036 }
1037 }
1038
1039 if ((at = try_find_archetype(bp)) == NULL) {
1040 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1041 "No such archetype.");
1042 return;
1043 }
1044
1045 if (cp) {
1046 char spell_name[MAX_BUF], *fsp = NULL;
1047
1048 /*
1049 * Try to find a spell object for this. Note that
1050 * we also set up spell_name which is only
1051 * the first word.
1052 */
1053
1054 at_spell = try_find_archetype(cp);
1055 if (!at_spell || at_spell->clone.type != SPELL)
1056 at_spell = find_archetype_by_object_name(cp);
1057 if (!at_spell || at_spell->clone.type != SPELL) {
1058 safe_strncpy(spell_name, cp, sizeof(spell_name));
1059 fsp = strchr(spell_name, ' ');
1060 if (fsp) {
1061 *fsp = 0;
1062 fsp++;
1063 at_spell = try_find_archetype(spell_name);
1064
1065 /* Got a spell, update the first string pointer */
1066 if (at_spell && at_spell->clone.type == SPELL)
1067 bp2 = cp+strlen(spell_name)+1;
1068 else
1069 at_spell = NULL;
1070 } else
1071 at_spell = NULL;
1072 }
1073
1074 /* OK - we didn't find a spell - presume the 'of'
1075 * in this case means its an artifact.
1076 */
1077 if (!at_spell) {
1078 if (find_artifactlist(at->clone.type) == NULL) {
1079 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1080 "No artifact list for type %d\n",
1081 at->clone.type);
1082 } else {
1083 art = find_artifactlist(at->clone.type)->items;
1084
1085 do {
1086 if (!strcmp(art->item->name, cp) && legal_artifact_combination(&at->clone, art))
1087 break;
1088 art = art->next;
1089 } while (art != NULL);
1090 if (!art) {
1091 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1092 "No such artifact ([%d] of %s)",
1093 at->clone.type, cp);
1094 }
1095 }
1096 LOG(llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp);
1097 }
1098 } /* if cp */
1099
1100 /* rods and potions can get their spell from the artifact */
1101 if ((at->clone.type == ROD || at->clone.type == POTION) && !at_spell && (!art || !art->item->other_arch)) {
1102 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1103 "Unable to find spell %s for object that needs it, or it is of wrong type",
1104 cp);
1105 return;
1106 }
1107 if ((at->clone.type == WAND || at->clone.type == SCROLL || at->clone.type == SPELLBOOK)
1108 && !at_spell) {
1109 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1110 "Unable to find spell %s for object that needs it, or it is of wrong type",
1111 cp);
1112 return;
1113 }
1114
1115 /*
1116 * Rather than have two different blocks with a lot of similar code,
1117 * just create one object, do all the processing, and then determine
1118 * if that one object should be inserted or if we need to make copies.
1119 */
1120 tmp = object_create_arch(at);
1121 if (settings.real_wiz == FALSE)
1122 SET_FLAG(tmp, FLAG_WAS_WIZ);
1123 if (set_magic)
1124 set_abs_magic(tmp, magic);
1125 if (art)
1126 give_artifact_abilities(tmp, art->item);
1127 if (!is_identifiable_type(tmp)) {
1128 SET_FLAG(tmp, FLAG_IDENTIFIED);
1129 CLEAR_FLAG(tmp, FLAG_KNOWN_MAGICAL);
1130 object_give_identified_properties(tmp);
1131 }
1132
1133 /*
1134 * This entire block here tries to find variable pairings,
1135 * eg, 'hp 4' or the like. The mess here is that values
1136 * can be quoted (eg "my cool sword"); So the basic logic
1137 * is we want to find two spaces, but if we got a quote,
1138 * any spaces there don't count.
1139 */
1140 while (*bp2 && bp2 <= endline) {
1141 gotspace = 0;
1142 gotquote = 0;
1143 /* find the first quote */
1144 for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) {
1145 /* Found a quote - now lets find the second one */
1146 if (*bp3 == '"') {
1147 *bp3 = ' ';
1148 bp2 = bp3+1; /* Update start of string */
1149 bp3++;
1150 gotquote++;
1151 while (*bp3) {
1152 if (*bp3 == '"') {
1153 *bp3 = '\0';
1154 gotquote++;
1155 } else
1156 bp3++;
1157 }
1158 } else if (*bp3 == ' ') {
1159 gotspace++;
1160 }
1161 }
1162
1163 /*
1164 * If we got two spaces, send the second one to null.
1165 * if we've reached the end of the line, increase gotspace -
1166 * this is perfectly valid for the list entry listed.
1167 */
1168 if (gotspace == 2 || gotquote == 2) {
1169 bp3--; /* Undo the extra increment */
1170 *bp3 = '\0';
1171 } else if (*bp3 == '\0')
1172 gotspace++;
1173
1174 if ((gotquote && gotquote != 2)
1175 || (gotspace != 2 && gotquote != 2)) {
1176 /*
1177 * Unfortunately, we've clobbered lots of values, so printing
1178 * out what we have probably isn't useful. Break out, because
1179 * trying to recover is probably won't get anything useful
1180 * anyways, and we'd be confused about end of line pointers
1181 * anyways.
1182 */
1183 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1184 "Malformed create line: %s",
1185 bp2);
1186 break;
1187 }
1188 /* bp2 should still point to the start of this line,
1189 * with bp3 pointing to the end
1190 */
1191 if (set_variable(tmp, bp2) == -1)
1192 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1193 "Unknown variable %s",
1194 bp2);
1195 else
1196 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1197 "(%s#%d)->%s",
1198 tmp->name, tmp->count, bp2);
1199 bp2 = bp3+1;
1200 }
1201
1202 if (at->clone.nrof) {
1203 if (at_spell)
1204 object_insert_in_ob(arch_to_object(at_spell), tmp);
1205
1206 if (set_nrof)
1207 tmp->nrof = nrof;
1208
1209 if (at->clone.randomitems != NULL && !at_spell) {
1210 create_treasure(at->clone.randomitems, tmp, 0, op->map->difficulty, 0);
1211 if (QUERY_FLAG(tmp, FLAG_MONSTER)) {
1212 monster_check_apply_all(tmp);
1213 }
1214 }
1215
1216 /* Multipart objects can't be in inventory, put'em on floor. */
1217 if (!tmp->more) {
1218 tmp = object_insert_in_ob(tmp, op);
1219 } else {
1220 object_insert_in_map_at(tmp, op->map, op, 0, op->x, op->y);
1221 }
1222
1223 /* Let's put this created item on stack so dm can access it easily. */
1224 dm_stack_push(op->contr, tmp->count);
1225
1226 return;
1227 }
1228
1229 for (i = 0; i < (set_nrof ? nrof : 1); i++) {
1230 archetype *atmp;
1231 object *prev = NULL, *head = NULL, *dup;
1232
1233 for (atmp = at; atmp != NULL; atmp = atmp->more) {
1234 dup = arch_to_object(atmp);
1235
1236 if (at_spell)
1237 object_insert_in_ob(arch_to_object(at_spell), dup);
1238
1239 /*
1240 * The head is what contains all the important bits,
1241 * so just copying it over should be fine.
1242 */
1243 if (head == NULL) {
1244 head = dup;
1245 object_copy(tmp, dup);
1246 }
1247 if (settings.real_wiz == FALSE)
1248 SET_FLAG(dup, FLAG_WAS_WIZ);
1249 dup->x = op->x+dup->arch->clone.x;
1250 dup->y = op->y+dup->arch->clone.y;
1251 dup->map = op->map;
1252
1253 if (head != dup) {
1254 dup->head = head;
1255 prev->more = dup;
1256 }
1257 prev = dup;
1258 }
1259
1260 if (QUERY_FLAG(head, FLAG_ALIVE)) {
1261 object *check = head;
1262 int size_x = 0;
1263 int size_y = 0;
1264
1265 while (check) {
1266 size_x = MAX(size_x, check->arch->clone.x);
1267 size_y = MAX(size_y, check->arch->clone.y);
1268 check = check->more;
1269 }
1270
1271 if (out_of_map(op->map, head->x+size_x, head->y+size_y)) {
1272 if (head->x < size_x || head->y < size_y) {
1273 dm_stack_pop(op->contr);
1274 object_free(head, FREE_OBJ_NO_DESTROY_CALLBACK);
1275 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1276 "Object too big to insert in map, or wrong position.");
1277 object_free(tmp, FREE_OBJ_NO_DESTROY_CALLBACK);
1278 return;
1279 }
1280
1281 check = head;
1282 while (check) {
1283 check->x -= size_x;
1284 check->y -= size_y;
1285 check = check->more;
1286 }
1287 }
1288
1289 object_insert_in_map_at(head, op->map, op, 0, head->x, head->y);
1290 } else
1291 head = object_insert_in_ob(head, op);
1292
1293 /* Let's put this created item on stack so dm can access it easily. */
1294 /* Wonder if we really want to push all of these, but since
1295 * things like rods have nrof 0, we want to cover those.
1296 */
1297 dm_stack_push(op->contr, head->count);
1298
1299 if (at->clone.randomitems != NULL && !at_spell) {
1300 create_treasure(at->clone.randomitems, head, 0, op->map->difficulty, 0);
1301 if (QUERY_FLAG(head, FLAG_MONSTER)) {
1302 monster_check_apply_all(head);
1303 }
1304 }
1305 }
1306
1307 /* free the one we used to copy */
1308 object_free(tmp, FREE_OBJ_NO_DESTROY_CALLBACK);
1309 }
1310
1311 /*
1312 * Now follows dm-commands which are also acceptable from sockets
1313 */
1314
1315 /**
1316 * Shows the inventory or some item.
1317 *
1318 * @param op
1319 * player.
1320 * @param params
1321 * object count to get the inventory of. If NULL then defaults to op.
1322 */
1323 void command_inventory(object *op, const char *params) {
1324 object *tmp;
1325 int i;
1326
1327 if (*params == '\0') {
1328 inventory(op, NULL);
1329 return;
1330 }
1331
1332 if (!sscanf(params, "%d", &i) || (tmp = object_find_by_tag_global(i)) == NULL) {
1333 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1334 "Inventory of what object (nr)?");
1335 return;
1336 }
1337
1338 inventory(op, tmp);
1339 }
1340
1341 /**
1342 * Player is asking for her skills.
1343 *
1344 * Just show player's their skills for now. Dm's can
1345 * already see skills w/ inventory command - b.t.
1346 *
1347 * @param op
1348 * player.
1349 * @param params
1350 * optional skill restriction.
1351 * @todo move out of this file as it is used by all players.
1352 */
1353 void command_skills(object *op, const char *params) {
1354 show_skills(op, *params == '\0' ? NULL : params);
1355 }
1356
1357 /**
1358 * Dumps the difference between an object and its archetype.
1359 *
1360 * @param op
1361 * wiard.
1362 * @param params
1363 * object to dump.
1364 */
1365 void command_dump(object *op, const char *params) {
1366 object *tmp;
1367 StringBuffer *sb;
1368 char *diff;
1369
1370 tmp = get_dm_object(op->contr, &params, NULL);
1371 if (!tmp)
1372 return;
1373
1374 sb = stringbuffer_new();
1375 object_dump(tmp, sb);
1376 diff = stringbuffer_finish(sb);
1377 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM, diff);
1378 free(diff);
1379 if (QUERY_FLAG(tmp, FLAG_OBJ_ORIGINAL))
1380 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1381 "Object is marked original");
1382 }
1383
1384 /**
1385 * When DM is possessing a monster, flip aggression on and off, to allow
1386 * better motion.
1387 *
1388 * @param op
1389 * wiard.
1390 * @param params
1391 * ignored.
1392 */
1393 void command_mon_aggr(object *op, const char *params) {
1394 if (op->enemy || !QUERY_FLAG(op, FLAG_UNAGGRESSIVE)) {
1395 object_set_enemy(op, NULL);
1396 SET_FLAG(op, FLAG_UNAGGRESSIVE);
1397 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1398 "Aggression turned OFF");
1399 } else {
1400 CLEAR_FLAG(op, FLAG_FRIENDLY);
1401 CLEAR_FLAG(op, FLAG_UNAGGRESSIVE);
1402 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1403 "Aggression turned ON");
1404 }
1405 }
1406
1407 /**
1408 * DM can possess a monster. Basically, this tricks the client into thinking
1409 * a given monster, is actually the player it controls. This allows a DM
1410 * to inhabit a monster's body, and run around the game with it.
1411 * This function is severely broken - it has tons of hardcoded values,
1412 *
1413 * @param op
1414 * wizard wanting to possess something.
1415 * @param params
1416 * monster to possess.
1417 * @todo fix and reactivate the function, or totally trash.
1418 */
1419 void command_possess(object *op, const char *params) {
1420 object *victim;
1421 player *pl;
1422 int i;
1423 char buf[MAX_BUF];
1424
1425 victim = NULL;
1426 if (*params != '\0') {
1427 if (sscanf(params, "%d", &i))
1428 victim = object_find_by_tag_global(i);
1429 else if (sscanf(params, "%s", buf))
1430 victim = object_find_by_name_global(buf);
1431 }
1432 if (victim == NULL) {
1433 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1434 "Patch what object (nr)?");
1435 return;
1436 }
1437
1438 if (victim == op) {
1439 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1440 "As insane as you are, I cannot allow you to possess yourself.");
1441 return;
1442 }
1443
1444 /* make the switch */
1445 pl = op->contr;
1446 victim->contr = pl;
1447 pl->ob = victim;
1448 victim->type = PLAYER;
1449 SET_FLAG(victim, FLAG_WIZ);
1450
1451 /* basic patchup */
1452 /* The use of hard coded values is terrible. Note
1453 * that really, to be fair, this shouldn't get changed at
1454 * all - if you are possessing a kobold, you should have the
1455 * same limitations. As it is, as more body locations are added,
1456 * this will give this player more locations than perhaps
1457 * they should be allowed.
1458 */
1459 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
1460 if (i == 1 || i == 6 || i == 8 || i == 9)
1461 victim->body_info[i] = 2;
1462 else
1463 victim->body_info[i] = 1;
1464
1465 esrv_new_player(pl, 80); /* just pick a weight, we don't care */
1466 esrv_send_inventory(victim, victim);
1467
1468 fix_object(victim);
1469
1470 do_some_living(victim);
1471 }
1472
1473 /**
1474 * Wizard wants to altar an object.
1475 * @param op
1476 * wizard.
1477 * @param params
1478 * object and what to patch.
1479 */
1480 void command_patch(object *op, const char *params) {
1481 const char *arg, *arg2;
1482 object *tmp;
1483
1484 tmp = get_dm_object(op->contr, &params, NULL);
1485 if (!tmp)
1486 /* Player already informed of failure */
1487 return;
1488
1489 /* params set to first value by get_dm_default */
1490 arg = params;
1491 if (*arg == '\0') {
1492 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1493 "Patch what values?");
1494 return;
1495 }
1496
1497 if ((arg2 = strchr(arg, ' ')))
1498 arg2++;
1499 if (settings.real_wiz == FALSE)
1500 SET_FLAG(tmp, FLAG_WAS_WIZ); /* To avoid cheating */
1501 if (set_variable(tmp, arg) == -1)
1502 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1503 "Unknown variable %s",
1504 arg);
1505 else {
1506 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1507 "(%s#%d)->%s=%s",
1508 tmp->name, tmp->count, arg, arg2);
1509 }
1510 }
1511
1512 /**
1513 * Remove an object from its position.
1514 *
1515 * @param op
1516 * wizard.
1517 * @param params
1518 * object to remove.
1519 */
1520 void command_remove(object *op, const char *params) {
1521 object *tmp;
1522 int from;
1523
1524 tmp = get_dm_object(op->contr, &params, &from);
1525 if (!tmp) {
1526 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1527 "Remove what object (nr)?");
1528 return;
1529 }
1530
1531 if (tmp->type == PLAYER) {
1532 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1533 "Unable to remove a player!");
1534 return;
1535 }
1536
1537 if (QUERY_FLAG(tmp, FLAG_REMOVED)) {
1538 char name[MAX_BUF];
1539
1540 query_name(tmp, name, MAX_BUF);
1541 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1542 "%s is already removed!",
1543 name);
1544 return;
1545 }
1546
1547 if (from != STACK_FROM_STACK)
1548 /* Item is either stack top, or is a number thus is now stack top, let's remove it */
1549 dm_stack_pop(op->contr);
1550
1551 /* Always work on the head - otherwise object will get in odd state */
1552 tmp = HEAD(tmp);
1553 if (tmp->speed != 0) {
1554 tmp->speed = 0;
1555 object_update_speed(tmp);
1556 }
1557 object_remove(tmp);
1558 }
1559
1560 /**
1561 * Totally free an object.
1562 * @param op
1563 * wizard.
1564 * @param params
1565 * object to free.
1566 */
1567 void command_free(object *op, const char *params) {
1568 object *tmp;
1569 int from;
1570
1571 tmp = get_dm_object(op->contr, &params, &from);
1572
1573 if (!tmp) {
1574 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1575 "Free what object (nr)?");
1576 return;
1577 }
1578
1579 if (from != STACK_FROM_STACK)
1580 /* Item is either stack top, or is a number thus is now stack top, let's remove it */
1581 dm_stack_pop(op->contr);
1582
1583 tmp = HEAD(tmp);
1584 if (!QUERY_FLAG(tmp, FLAG_REMOVED)) {
1585 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1586 "Warning: item was not removed, will do so now.");
1587 object_remove(tmp);
1588 }
1589
1590 object_free_drop_inventory(tmp);
1591 }
1592
1593 /**
1594 * This adds exp to a player. We now allow adding to a specific skill.
1595 *
1596 * @param op
1597 * wizard.
1598 * @param params
1599 * should be "player quantity [skill]".
1600 */
1601 void command_addexp(object *op, const char *params) {
1602 char buf[MAX_BUF], skill[MAX_BUF];
1603 int i, q;
1604 object *skillob = NULL;
1605 player *pl;
1606
1607 skill[0] = '\0';
1608 if ((*params == '\0')
1609 || (strlen(params) > MAX_BUF)
1610 || ((q = sscanf(params, "%s %d %[^\r\n]", buf, &i, skill)) < 2)) {
1611 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1612 "Usage: addexp player quantity [skill].");
1613 return;
1614 }
1615
1616 for (pl = first_player; pl != NULL; pl = pl->next)
1617 if (!strncmp(pl->ob->name, buf, MAX_NAME))
1618 break;
1619
1620 if (pl == NULL) {
1621 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1622 "No such player.");
1623 return;
1624 }
1625
1626 if (q >= 3) {
1627 skillob = find_skill_by_name(pl->ob, skill);
1628 if (!skillob) {
1629 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1630 "Unable to find skill %s in %s",
1631 skill, buf);
1632 return;
1633 }
1634
1635 i = check_exp_adjust(skillob, i);
1636 skillob->stats.exp += i;
1637 calc_perm_exp(skillob);
1638 player_lvl_adj(pl->ob, skillob);
1639 }
1640
1641 pl->ob->stats.exp += i;
1642 calc_perm_exp(pl->ob);
1643 player_lvl_adj(pl->ob, NULL);
1644
1645 if (settings.real_wiz == FALSE)
1646 SET_FLAG(pl->ob, FLAG_WAS_WIZ);
1647 }
1648
1649 /**
1650 * Changes the server speed.
1651 *
1652 * @param op
1653 * wizard.
1654 * @param params
1655 * new speed, or NULL to see the speed.
1656 */
1657 void command_speed(object *op, const char *params) {
1658 int i;
1659
1660 if (*params == '\0' || !sscanf(params, "%d", &i)) {
1661 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1662 "Current speed is %d",
1663 max_time);
1664 return;
1665 }
1666
1667 set_max_time(i);
1668 reset_sleep();
1669 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1670 "The speed is changed to %d.",
1671 i);
1672 }
1673
1674 /**************************************************************************/
1675 /* Mods made by Tyler Van Gorder, May 10-13, 1992. */
1676 /* CSUChico : [email protected] */
1677 /**************************************************************************/
1678
1679 /**
1680 * Displays the statistics of a player.
1681 *
1682 * @param op
1683 * wizard.
1684 * @param params
1685 * player's name.
1686 */
1687 void command_stats(object *op, const char *params) {
1688 player *pl;
1689
1690 if (*params == '\0') {
1691 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1692 "Who?");
1693 return;
1694 }
1695
1696 pl = find_player_partial_name(params);
1697 if (pl == NULL) {
1698 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1699 "No such player.");
1700 return;
1701 }
1702
1703 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1704 "[Fixed]Statistics for %s:", pl->ob->name);
1705
1706 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1707 "[fixed]Str : %-2d H.P. : %-4d MAX : %d",
1708 pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp);
1709
1710 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1711 "[fixed]Dex : %-2d S.P. : %-4d MAX : %d",
1712 pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp);
1713
1714 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1715 "[fixed]Con : %-2d AC : %-4d WC : %d",
1716 pl->ob->stats.Con, pl->ob->stats.ac, pl->ob->stats.wc);
1717
1718 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1719 "[fixed]Int : %-2d Damage : %d",
1720 pl->ob->stats.Int, pl->ob->stats.dam);
1721
1722 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1723 "[fixed]Wis : %-2d EXP : %"FMT64,
1724 pl->ob->stats.Wis, pl->ob->stats.exp);
1725
1726 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1727 "[fixed]Pow : %-2d Grace : %d",
1728 pl->ob->stats.Pow, pl->ob->stats.grace);
1729
1730 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1731 "[fixed]Cha : %-2d Food : %d",
1732 pl->ob->stats.Cha, pl->ob->stats.food);
1733 }
1734
1735 /**
1736 * Changes an object's statistics.
1737 *
1738 * @param op
1739 * wizard.
1740 * @param params
1741 * parameters, should be "player statistic new_value".
1742 * @todo use get_other_player_from_name(). Isn't this useless with the command_patch()?
1743 */
1744 void command_abil(object *op, const char *params) {
1745 char thing[20], thing2[20];
1746 int iii;
1747 player *pl;
1748
1749 iii = 0;
1750 thing[0] = '\0';
1751 thing2[0] = '\0';
1752 if (*params == '\0'
1753 || sscanf(params, "%s %s %d", thing, thing2, &iii) != 3
1754 || thing[0] == '\0') {
1755 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1756 "Who?");
1757 return;
1758 }
1759
1760 if (thing2[0] == '\0') {
1761 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1762 "You can't change that.");
1763 return;
1764 }
1765
1766 if (iii < MIN_STAT || iii > settings.max_stat) {
1767 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1768 "Illegal range of stat.\n");
1769 return;
1770 }
1771
1772 for (pl = first_player; pl != NULL; pl = pl->next) {
1773 if (!strcmp(pl->ob->name, thing)) {
1774 if (settings.real_wiz == FALSE)
1775 SET_FLAG(pl->ob, FLAG_WAS_WIZ);
1776 if (!strcmp("str", thing2))
1777 pl->ob->stats.Str = iii, pl->orig_stats.Str = iii;
1778 if (!strcmp("dex", thing2))
1779 pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii;
1780 if (!strcmp("con", thing2))
1781 pl->ob->stats.Con = iii, pl->orig_stats.Con = iii;
1782 if (!strcmp("wis", thing2))
1783 pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii;
1784 if (!strcmp("cha", thing2))
1785 pl->ob->stats.Cha = iii, pl->orig_stats.Cha = iii;
1786 if (!strcmp("int", thing2))
1787 pl->ob->stats.Int = iii, pl->orig_stats.Int = iii;
1788 if (!strcmp("pow", thing2))
1789 pl->ob->stats.Pow = iii, pl->orig_stats.Pow = iii;
1790 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
1791 "%s has been altered.",
1792 pl->ob->name);
1793 fix_object(pl->ob);
1794 return;
1795 }
1796 }
1797
1798 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1799 "No such player.");
1800 }
1801
1802 /**
1803 * Resets a map.
1804 *
1805 * @param op
1806 * wizard.
1807 * @param params
1808 * map to reset. Can be "." for current op's map, or a map path.
1809 */
1810 void command_reset(object *op, const char *params) {
1811 mapstruct *m;
1812 object *dummy = NULL, *tmp = NULL;
1813 char path[HUGE_BUF];
1814 const char *space, *confirmation = NULL;
1815 int res = 0;
1816
1817 if (*params == '\0') {
1818 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
1819 MSG_TYPE_COMMAND_ERROR, "Which map should be reset?");
1820 return;
1821 }
1822
1823 space = strchr(params, ' ');
1824 if (space != NULL) {
1825 confirmation = params;
1826 params = space + 1;
1827 }
1828
1829 /* Use the DM's map if the current map was given. */
1830 if (strcmp(params, ".") == 0) {
1831 strlcpy(path, op->map->path, sizeof(path));
1832 } else {
1833 path_combine_and_normalize(op->map->path, params, path, sizeof(path));
1834 }
1835
1836 m = has_been_loaded(path);
1837 if (m == NULL) {
1838 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
1839 MSG_TYPE_COMMAND_ERROR, "No such map.");
1840 return;
1841 }
1842
1843 if (confirmation) {
1844 if (m->unique && (op->map == m)) {
1845 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
1846 MSG_TYPE_COMMAND_ERROR,
1847 "Cannot reset a unique player map while on it. Use "
1848 "'reset full-reset %s' while standing somewhere else.",
1849 m->path);
1850 return;
1851 }
1852
1853 if (strncmp("full-reset", confirmation, strlen("full-reset"))) {
1854 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
1855 MSG_TYPE_COMMAND_ERROR, "Confirm using 'full-reset'.");
1856 return;
1857 }
1858 }
1859
1860 /* Forbid using reset on our own map when we're in a transport, as
1861 * it has the displeasant effect of crashing the server.
1862 * - gros, July 25th 2006 */
1863 if ((op->contr && op->contr->transport) && (op->map == m)) {
1864 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1865 "You need to disembark first.");
1866 return;
1867 }
1868
1869 strlcpy(path, m->path, sizeof(path));
1870
1871 if (m->in_memory != MAP_SWAPPED) {
1872 if (m->in_memory != MAP_IN_MEMORY) {
1873 LOG(llevError, "Tried to swap out map which was not in memory.\n");
1874 return;
1875 }
1876
1877 /*
1878 * Only attempt to remove the player that is doing the reset, and not other
1879 * players or wiz's.
1880 */
1881 if (op->map == m) {
1882 if (strncmp(m->path, "/random/", 8) == 0) {
1883 /* This is not a very satisfying solution - it would be much better
1884 * to recreate a random map with the same seed value as the old one.
1885 * Unfortunately, I think recreating the map would require some
1886 * knowledge about its 'parent', which appears very non-trivial to
1887 * me.
1888 * On the other hand, this should prevent the freeze that this
1889 * situation caused. - gros, 26th July 2006.
1890 */
1891 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1892 "You cannot reset a random map when inside it.");
1893 return;
1894 }
1895
1896 dummy = object_new();
1897 dummy->map = NULL;
1898 EXIT_X(dummy) = op->x;
1899 EXIT_Y(dummy) = op->y;
1900 EXIT_PATH(dummy) = add_string(op->map->path);
1901 object_remove(op);
1902 op->map = NULL;
1903 tmp = op;
1904 }
1905 res = swap_map(m);
1906 }
1907
1908 if (res < 0 || m->in_memory != MAP_SWAPPED) {
1909 player *pl;
1910 int playercount = 0;
1911
1912 /* Need to re-insert player if swap failed for some reason */
1913 if (tmp) {
1914 object_insert_in_map_at(op, m, NULL, 0, op->x, op->y);
1915 object_free(dummy, FREE_OBJ_NO_DESTROY_CALLBACK);
1916 }
1917
1918 if (res < 0 && res != SAVE_ERROR_PLAYER)
1919 /* no need to warn if player on map, code below checks that. */
1920 draw_ext_info_format(NDI_UNIQUE|NDI_RED, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1921 "Reset failed, error code: %d.", res);
1922 else {
1923 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1924 "Reset failed, couldn't swap map, the following players are on it:");
1925 for (pl = first_player; pl != NULL; pl = pl->next) {
1926 if (pl->ob->map == m && pl->ob != op) {
1927 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1928 pl->ob->name);
1929 playercount++;
1930 }
1931 }
1932 if (!playercount)
1933 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1934 "hmm, I don't see any other players on this map, something else is the problem.");
1935 return;
1936 }
1937 }
1938
1939 /* Here, map reset succeeded. */
1940
1941 if (m && m->in_memory == MAP_SWAPPED) {
1942 if (confirmation) {
1943 map_remove_unique_files(m);
1944 LOG(llevDebug, "DM %s fully resetting map %s.\n", op->name, m->path);
1945 } else
1946 LOG(llevDebug, "DM %s resetting map %s.\n", op->name, m->path);
1947
1948 /* setting this effectively causes an immediate reload */
1949 m->reset_time = 1;
1950 flush_old_maps();
1951 }
1952
1953 /* Display the appropriate success message. */
1954 if (confirmation) {
1955 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
1956 MSG_TYPE_COMMAND_DM, "Fully resetting map %s.", path);
1957 } else {
1958 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
1959 MSG_TYPE_COMMAND_DM, "Resetting map %s.", path);
1960 }
1961
1962 if (tmp) {
1963 enter_exit(tmp, dummy);
1964 object_free(dummy, FREE_OBJ_NO_DESTROY_CALLBACK);
1965 }
1966
1967 /* Remind the DM how to fully reset the map. */
1968 if (confirmation == NULL) {
1969 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
1970 MSG_TYPE_COMMAND_DM,
1971 "Use 'reset full-reset %s' to fully reset the map.", params);
1972 }
1973 }
1974
1975 /**
1976 * Steps down from wizard mode.
1977 *
1978 * @param op
1979 * wizard.
1980 * @param params
1981 * ignored.
1982 */
1983 void command_nowiz(object *op, const char *params) { /* 'noadm' is alias */
1984 CLEAR_FLAG(op, FLAG_WIZ);
1985 CLEAR_FLAG(op, FLAG_WIZPASS);
1986 CLEAR_FLAG(op, FLAG_WIZCAST);
1987 if (op->contr->followed_player)
1988 FREE_AND_CLEAR_STR(op->contr->followed_player);
1989
1990 if (settings.real_wiz == TRUE)
1991 CLEAR_FLAG(op, FLAG_WAS_WIZ);
1992 if (op->contr->hidden) {
1993 unhide(op);
1994 } else
1995 draw_ext_info(NDI_UNIQUE|NDI_ALL|NDI_LT_GREEN, 1, NULL, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM,
1996 "The Dungeon Master is gone..");
1997
1998 update_los(op);
1999 }
2000
2001 /**
2002 * object *op is trying to become dm.
2003 * pl_name is name supplied by player. Restrictive DM will make it harder
2004 * for socket users to become DM - in that case, it will check for the players
2005 * character name.
2006 *
2007 * @param op
2008 * player wishing to become DM.
2009 * @param pl_name
2010 * player's name.
2011 * @param pl_passwd
2012 * entered password.
2013 * @param pl_host
2014 * player's host.
2015 * @retval 0
2016 * invalid credentials.
2017 * @retval 1
2018 * op can become DM.
2019 * @todo can't name/host be found from op? What is RESTRICTIVE_DM?
2020 */
2021 static int checkdm(object *op, const char *pl_name, const char *pl_passwd, const char *pl_host) {
2022 FILE *dmfile;
2023 char buf[MAX_BUF];
2024 char line_buf[160], name[160], passwd[160], host[160];
2025
2026 #ifdef RESTRICTIVE_DM
2027 *pl_name = op->name ? op->name : "*";
2028 #endif
2029
2030 snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, DMFILE);
2031 if ((dmfile = fopen(buf, "r")) == NULL) {
2032 LOG(llevDebug, "Could not find DM file.\n");
2033 return 0;
2034 }
2035
2036 while (fgets(line_buf, 160, dmfile) != NULL) {
2037 // Skip empty lines as well as commented ones.
2038 if (line_buf[0] == '#' || line_buf[0] == '\n')
2039 continue;
2040 if (sscanf(line_buf, "%[^:]:%[^:]:%s\n", name, passwd, host) != 3) {
2041 LOG(llevError, "Warning - malformed dm file entry: %s\n", line_buf);
2042 } else if ((!strcmp(name, "*") || (pl_name && !strcmp(pl_name, name)))
2043 && (!strcmp(passwd, "*") || !strcmp(passwd, pl_passwd))
2044 && (!strcmp(host, "*") || !strcmp(host, pl_host))) {
2045 fclose(dmfile);
2046 return (1);
2047 }
2048 }
2049 fclose(dmfile);
2050 return (0);
2051 }
2052
2053 /**
2054 * Actually changes a player to wizard.
2055 *
2056 * @param op
2057 * player.
2058 * @param params
2059 * password.
2060 * @param silent
2061 * if zero, don't inform players of the mode change.
2062 * @retval 0
2063 * no mode change.
2064 * @retval 1
2065 * op is now a wizard.
2066 */
2067 static int do_wizard_dm(object *op, const char *params, int silent) {
2068 if (!op->contr)
2069 return 0;
2070
2071 if (QUERY_FLAG(op, FLAG_WIZ)) {
2072 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2073 "You are already the Dungeon Master!");
2074 return 0;
2075 }
2076
2077 if (checkdm(op, op->name, (*params != '\0' ? params : "*"), op->contr->socket.host)) {
2078 SET_FLAG(op, FLAG_WIZ);
2079 SET_FLAG(op, FLAG_WAS_WIZ);
2080 SET_FLAG(op, FLAG_WIZPASS);
2081 SET_FLAG(op, FLAG_WIZCAST);
2082 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
2083 "Ok, you are the Dungeon Master!");
2084 /*
2085 * Remove setting flying here - that won't work, because next
2086 * fix_object() is called that will get cleared - proper solution
2087 * is probably something like a wiz_force which gives that and any
2088 * other desired abilities.
2089 */
2090 clear_los(op->contr);
2091 op->contr->write_buf[0] = '\0';
2092
2093 if (!silent)
2094 draw_ext_info(NDI_UNIQUE|NDI_ALL|NDI_LT_GREEN, 1, NULL,
2095 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM,
2096 "The Dungeon Master has arrived!");
2097
2098 return 1;
2099 }
2100
2101 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2102 "Sorry Pal, I don't think so.");
2103 op->contr->write_buf[0] = '\0';
2104 return 0;
2105 }
2106
2107 /**
2108 * Actual command to perhaps become dm. Changed around a bit in version 0.92.2
2109 * to allow people on sockets to become dm, and allow better dm file
2110 *
2111 * @param op
2112 * player wishing to become wizard.
2113 * @param params
2114 * password.
2115 * @return
2116 * 0 unless op isn't a player.
2117 */
2118 void command_dm(object *op, const char *params) {
2119 do_wizard_dm(op, params, 0);
2120 }
2121
2122 /**
2123 * Wizard wants to become invisible.
2124 *
2125 * @param op
2126 * wizard.
2127 * @param params
2128 * ignored.
2129 */
2130 void command_invisible(object *op, const char *params) {
2131 if (op) {
2132 op->invisible += 100;
2133 object_update(op, UP_OBJ_FACE);
2134 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
2135 "You turn invisible.");
2136 }
2137 }
2138
2139 /**
2140 * Returns spell object (from archetypes) by name.
2141 * Used for wizard's learn spell/prayer.
2142 *
2143 * Ignores archetypes "spelldirect_xxx" since these archetypes are not used
2144 * anymore (but may still be present in some player's inventories and thus
2145 * cannot be removed). We have to ignore them here since they have the same
2146 * name than other "spell_xxx" archetypes and would always conflict.
2147 **
2148 * @param op
2149 * player issuing the command.
2150 * @param spell_name
2151 * spell to find.
2152 * @return
2153 * NULL if 0 or more than one spell matches, spell object else.
2154 * @todo remove the spelldirect_xxx test?
2155 */
2156 static object *get_spell_by_name(object *op, const char *spell_name) {
2157 archetype *ar;
2158 archetype *found;
2159 int conflict_found;
2160 size_t spell_name_length;
2161
2162 /* First check for full name matches. */
2163 conflict_found = 0;
2164 found = NULL;
2165 for (ar = first_archetype; ar != NULL; ar = ar->next) {
2166 if (ar->clone.type != SPELL)
2167 continue;
2168
2169 if (strncmp(ar->name, "spelldirect_", 12) == 0)
2170 continue;
2171
2172 if (strcmp(ar->clone.name, spell_name) != 0)
2173 continue;
2174
2175 if (found != NULL) {
2176 if (!conflict_found) {
2177 conflict_found = 1;
2178 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2179 "More than one archetype matches the spell name %s:",
2180 spell_name);
2181 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2182 "- %s",
2183 found->name);
2184 }
2185 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2186 "- %s",
2187 ar->name);
2188 continue;
2189 }
2190
2191 found = ar;
2192 }
2193
2194 /* No match if more more than one archetype matches. */
2195 if (conflict_found)
2196 return NULL;
2197
2198 /* Return if exactly one archetype matches. */
2199 if (found != NULL)
2200 return arch_to_object(found);
2201
2202 /* No full match found: now check for partial matches. */
2203 spell_name_length = strlen(spell_name);
2204 conflict_found = 0;
2205 found = NULL;
2206 for (ar = first_archetype; ar != NULL; ar = ar->next) {
2207 if (ar->clone.type != SPELL)
2208 continue;
2209
2210 if (strncmp(ar->name, "spelldirect_", 12) == 0)
2211 continue;
2212
2213 if (strncmp(ar->clone.name, spell_name, spell_name_length) != 0)
2214 continue;
2215
2216 if (found != NULL) {
2217 if (!conflict_found) {
2218 conflict_found = 1;
2219 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2220 "More than one spell matches %s:",
2221 spell_name);
2222 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2223 "- %s",
2224 found->clone.name);
2225 }
2226 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2227 "- %s",
2228 ar->clone.name);
2229 continue;
2230 }
2231
2232 found = ar;
2233 }
2234
2235 /* No match if more more than one archetype matches. */
2236 if (conflict_found)
2237 return NULL;
2238
2239 /* Return if exactly one archetype matches. */
2240 if (found != NULL)
2241 return arch_to_object(found);
2242
2243 /* No spell found: just print an error message. */
2244 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2245 "The spell %s does not exist.",
2246 spell_name);
2247 return NULL;
2248 }
2249
2250 /**
2251 * Wizards wants to learn a spell.
2252 *
2253 * @param op
2254 * wizard.
2255 * @param params
2256 * spell name to learn.
2257 * @param special_prayer
2258 * if set, special (god-given) prayer.
2259 */
2260 static void command_learn_spell_or_prayer(object *op, const char *params, int special_prayer) {
2261 object *tmp;
2262
2263 if (op->contr == NULL || *params == '\0') {
2264 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2265 "Which spell do you want to learn?");
2266 return;
2267 }
2268
2269 tmp = get_spell_by_name(op, params);
2270 if (tmp == NULL) {
2271 return;
2272 }
2273
2274 if (check_spell_known(op, tmp->name)) {
2275 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2276 "You already know the spell %s.",
2277 tmp->name);
2278 return;
2279 }
2280
2281 do_learn_spell(op, tmp, special_prayer);
2282 object_free(tmp, FREE_OBJ_NO_DESTROY_CALLBACK);
2283 }
2284
2285 /**
2286 * Wizard wants to learn a regular spell.
2287 *
2288 * @param op
2289 * wizard.
2290 * @param params
2291 * spell name.
2292 */
2293 void command_learn_spell(object *op, const char *params) {
2294 command_learn_spell_or_prayer(op, params, 0);
2295 }
2296
2297 /**
2298 * Wizard wants to learn a god-given spell.
2299 *
2300 * @param op
2301 * wizard.
2302 * @param params
2303 * spell name.
2304 */
2305 void command_learn_special_prayer(object *op, const char *params) {
2306 command_learn_spell_or_prayer(op, params, 1);
2307 }
2308
2309 /**
2310 * Command for players to forget a spell. This command used to be available
2311 * only to DMs.
2312 *
2313 * @param op
2314 * player
2315 * @param params
2316 * spell name to forget.
2317 */
2318 void command_forget_spell(object *op, const char *params) {
2319 object *spell;
2320
2321 if (op->contr == NULL || *params == '\0') {
2322 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2323 "Which spell do you want to forget?");
2324 return;
2325 }
2326
2327 spell = lookup_spell_by_name(op, params);
2328 if (spell == NULL) {
2329 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2330 "You do not know the spell %s.",
2331 params);
2332 return;
2333 }
2334
2335 do_forget_spell(op, spell->name);
2336 }
2337
2338 /**
2339 * Lists all plugins currently loaded with their IDs and full names.
2340 *
2341 * @param op
2342 * wizard.
2343 * @param params
2344 * ignored.
2345 */
2346 void command_listplugins(object *op, const char *params) {
2347 plugins_display_list(op);
2348 }
2349
2350 /**
2351 * Loads the given plugin. The DM specifies the name of the library to load (no
2352 * pathname is needed). Do not ever attempt to load the same plugin more than
2353 * once at a time, or bad things could happen.
2354 *
2355 * @param op
2356 * DM loading a plugin.
2357 * @param params
2358 * should be the plugin's name, eg cfpython.so
2359 */
2360 void command_loadplugin(object *op, const char *params) {
2361 char buf[MAX_BUF];
2362
2363 if (*params == '\0') {
2364 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2365 "Load which plugin?");
2366 return;
2367 }
2368
2369 snprintf(buf, sizeof(buf), LIBDIR"/plugins/%s", params);
2370 LOG(llevDebug, "Requested plugin file is %s\n", buf);
2371 if (plugins_init_plugin(buf) == 0) {
2372 LOG(llevInfo, "DM %s loaded plugin %s\n", op->name, params);
2373 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
2374 "Plugin %s successfully loaded.",
2375 params);
2376 } else
2377 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2378 "Could not load plugin %s.",
2379 params);
2380 }
2381
2382 /**
2383 * Unloads the given plugin. The DM specified the ID of the library to unload.
2384 * Note that some things may behave strangely if the correct plugins are not
2385 * loaded.
2386 *
2387 * @param op
2388 * DM unloading a plugin.
2389 * @param params
2390 * should be the plugin's internal name, eg Python
2391 */
2392 void command_unloadplugin(object *op, const char *params) {
2393 if (*params == '\0') {
2394 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2395 "Remove which plugin?");
2396 return;
2397 }
2398
2399 if (plugins_remove_plugin(params) == 0) {
2400 LOG(llevInfo, "DM %s unloaded plugin %s\n", op->name, params);
2401 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
2402 "Plugin %s successfully removed.",
2403 params);
2404 } else
2405 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2406 "Could not remove plugin %s.",
2407 params);
2408 }
2409
2410 /**
2411 * A players wants to become DM and hide.
2412 * Let's see if that's authorized.
2413 * Make sure to not tell anything to anyone.
2414 *
2415 * @param op
2416 * wizard.
2417 * @param params
2418 * password.
2419 */
2420 void command_dmhide(object *op, const char *params) {
2421 if (!do_wizard_dm(op, params, 1))
2422 return;
2423
2424 do_wizard_hide(op, 1);
2425 }
2426
2427 /**
2428 * Pop the stack top.
2429 *
2430 * @param op
2431 * wizard.
2432 * @param params
2433 * ignored.
2434 */
2435 void command_stack_pop(object *op, const char *params) {
2436 dm_stack_pop(op->contr);
2437 }
2438
2439 /**
2440 * Push specified item on stack.
2441 *
2442 * @param op
2443 * wizard.
2444 * @param params
2445 * object specifier.
2446 */
2447 void command_stack_push(object *op, const char *params) {
2448 object *ob;
2449 int from;
2450 ob = get_dm_object(op->contr, &params, &from);
2451
2452 if (ob && from != STACK_FROM_NUMBER)
2453 /* Object was from stack, need to push it again */
2454 dm_stack_push(op->contr, ob->count);
2455 }
2456
2457 /**
2458 * Displays stack contents.
2459 *
2460 * @param op
2461 * wizard.
2462 * @param params
2463 * ignored.
2464 */
2465 void command_stack_list(object *op, const char *params) {
2466 int item;
2467 object *display;
2468 player *pl = op->contr;
2469
2470 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
2471 "Item stack contents:");
2472
2473 for (item = 0; item < pl->stack_position; item++) {
2474 display = object_find_by_tag_global(pl->stack_items[item]);
2475 if (display)
2476 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
2477 " %d : %s [%d]",
2478 item, display->name, display->count);
2479 else
2480 /* Item was freed */
2481 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
2482 " %d : (lost item: %d)",
2483 item, pl->stack_items[item]);
2484 }
2485 }
2486
2487 /**
2488 * Empty DM item stack.
2489 *
2490 * @param op
2491 * wizard.
2492 * @param params
2493 * ignored.
2494 */
2495 void command_stack_clear(object *op, const char *params) {
2496 op->contr->stack_position = 0;
2497 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
2498 "Item stack cleared.");
2499 }
2500
2501 /**
2502 * Get a diff of specified items.
2503 * Second item is compared to first, and differences displayed.
2504 *
2505 * @note
2506 * get_ob_diff() works the opposite way (first compared to 2nd),
2507 * but it's easier with stack functions to do it this way, so you can do:
2508 * - stack_push \<base\>
2509 * - stack_push \<object to be compared\>
2510 * - diff
2511 * - patch xxx <---- applies to object compared to base, easier :)
2512 *
2513 * Ryo, august 2004
2514 *
2515 * @param op
2516 * wizard.
2517 * @param params
2518 * object specifier.
2519 */
2520 void command_diff(object *op, const char *params) {
2521 object *left, *right;
2522 char *diff;
2523 StringBuffer *sb;
2524 int left_from, right_from;
2525
2526 left = get_dm_object(op->contr, &params, &left_from);
2527 if (!left) {
2528 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2529 "Compare to what item?");
2530 return;
2531 }
2532
2533 if (left_from == STACK_FROM_NUMBER)
2534 /* Item was stacked, remove it else right will be the same... */
2535 dm_stack_pop(op->contr);
2536
2537 right = get_dm_object(op->contr, &params, &right_from);
2538
2539 if (!right) {
2540 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2541 "Compare what item?");
2542 return;
2543 }
2544
2545 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
2546 "Item difference:");
2547
2548 if (left_from == STACK_FROM_TOP && right_from == STACK_FROM_TOP) {
2549 /*
2550 * Special case: both items were taken from stack top.
2551 * Override the behaviour, taking left as item just below top, if exists.
2552 * See function description for why.
2553 * Besides, if we don't do anything, compare an item to itself, not really useful.
2554 */
2555 if (op->contr->stack_position > 1) {
2556 left = object_find_by_tag_global(op->contr->stack_items[op->contr->stack_position-2]);
2557 if (left)
2558 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
2559 "(Note: first item taken from undertop)");
2560 else
2561 /* Stupid case: item under top was freed, fallback to stack top */
2562 left = right;
2563 }
2564 }
2565
2566 sb = stringbuffer_new();
2567 get_ob_diff(sb, left, right);
2568 diff = stringbuffer_finish(sb);
2569 if (*diff == '\0') {
2570 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM, "Objects are the same.");
2571 } else {
2572 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM, diff);
2573 }
2574 free(diff);
2575 }
2576
2577 /**
2578 * Puts an object into another.
2579 * @param op
2580 * wizard.
2581 * @param params
2582 * object specifier.
2583 */
2584 void command_insert_into(object *op, const char *params) {
2585 object *left, *right, *inserted;
2586 int left_from, right_from;
2587 char what[MAX_BUF], where[MAX_BUF];
2588
2589 left = get_dm_object(op->contr, &params, &left_from);
2590 if (!left) {
2591 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2592 "Insert into what object?");
2593 return;
2594 }
2595
2596 if (left_from == STACK_FROM_NUMBER)
2597 /* Item was stacked, remove it else right will be the same... */
2598 dm_stack_pop(op->contr);
2599
2600 right = get_dm_object(op->contr, &params, &right_from);
2601
2602 if (!right) {
2603 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2604 "Insert what item?");
2605 return;
2606 }
2607
2608 if (left_from == STACK_FROM_TOP && right_from == STACK_FROM_TOP) {
2609 /*
2610 * Special case: both items were taken from stack top.
2611 * Override the behaviour, taking left as item just below top, if exists.
2612 * See function description for why.
2613 * Besides, can't insert an item into itself.
2614 */
2615 if (op->contr->stack_position > 1) {
2616 left = object_find_by_tag_global(op->contr->stack_items[op->contr->stack_position-2]);
2617 if (left)
2618 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
2619 "(Note: item to insert into taken from undertop)");
2620 else
2621 /* Stupid case: item under top was freed, fallback to stack top */
2622 left = right;
2623 }
2624 }
2625
2626 if (left == right) {
2627 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2628 "Can't insert an object into itself!");
2629 return;
2630 }
2631
2632 if (right->type == PLAYER) {
2633 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2634 "Can't insert a player into something!");
2635 return;
2636 }
2637
2638 if (!QUERY_FLAG(right, FLAG_REMOVED))
2639 object_remove(right);
2640 inserted = object_insert_in_ob(right, left);
2641 if (left->type == PLAYER) {
2642 if (inserted != right)
2643 /* item was merged, so updating name and such. */
2644 esrv_update_item(UPD_WEIGHT|UPD_NAME|UPD_NROF, left, inserted);
2645 }
2646 query_name(inserted, what, MAX_BUF);
2647 query_name(left, where, MAX_BUF);
2648 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DM,
2649 "Inserted %s in %s",
2650 what, where);
2651 }
2652
2653 /**
2654 * Displays information about styles loaded for random maps.
2655 *
2656 * @param op
2657 * wizard.
2658 * @param params
2659 * ignored.
2660 */
2661 void command_style_map_info(object *op, const char *params) {
2662 extern mapstruct *styles;
2663 mapstruct *mp;
2664 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
2665
2666 for (mp = styles; mp != NULL; mp = mp->next) {
2667 maps_used++;
2668 mapmem += map_size(mp) * (sizeof(object *)+sizeof(MapSpace))+sizeof(mapstruct);
2669 for (x = 0; x < MAP_WIDTH(mp); x++) {
2670 for (y = 0; y < MAP_HEIGHT(mp); y++) {
2671 FOR_MAP_PREPARE(mp, x, y, tmp)
2672 objects_used++;
2673 FOR_MAP_FINISH();
2674 }
2675 }
2676 }
2677 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_MAPS,
2678 "[fixed]Style maps loaded: %d",
2679 maps_used);
2680 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_MAPS,
2681 "[fixed]Memory used, not");
2682 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_MAPS,
2683 "[fixed]including objects: %d",
2684 mapmem);
2685 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_MAPS,
2686 "[fixed]Style objects: %d",
2687 objects_used);
2688 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_MAPS,
2689 "[fixed]Mem for objects: %lu",
2690 (unsigned long)(objects_used*sizeof(object)));
2691 }
2692
2693 /**
2694 * DM wants to follow a player, or stop following a player.
2695 *
2696 * @param op
2697 * wizard.
2698 * @param params
2699 * player to follow. If NULL, stop following player.
2700 */
2701 void command_follow(object *op, const char *params) {
2702 player *other;
2703
2704 if (*params == '\0') {
2705 if (op->contr->followed_player != NULL) {
2706 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, "You stop following %s.", op->contr->followed_player);
2707 FREE_AND_CLEAR_STR(op->contr->followed_player);
2708 }
2709 return;
2710 }
2711
2712 other = find_player_partial_name(params);
2713 if (!other) {
2714 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, "No such player or ambiguous name.");
2715 return;
2716 }
2717 if (other == op->contr) {
2718 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, "You can't follow yourself.");
2719 return;
2720 }
2721
2722 if (op->contr->followed_player)
2723 FREE_AND_CLEAR_STR(op->contr->followed_player);
2724
2725 op->contr->followed_player = add_string(other->ob->name);
2726 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, "Following %s.", op->contr->followed_player);
2727 }
2728
2729 void command_purge_quest(object *op, const char * param) {
2730 free_quest();
2731 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, "Purged quest state.");
2732 }
2733
2734 void command_purge_quest_definitions(object *op, const char * param) {
2735 free_quest_definitions();
2736 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, "Purged quests definitions.");
2737 }
2738
2739 static void do_dump(object *who, object *what) {
2740 StringBuffer *sb;
2741 char *diff;
2742
2743 sb = stringbuffer_new();
2744 object_dump(what, sb);
2745 diff = stringbuffer_finish(sb);
2746 draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_COMMAND, MSG_SUBTYPE_NONE, diff);
2747 free(diff);
2748
2749 /* Let's push that item on the dm's stack */
2750 dm_stack_push(who->contr, what->count);
2751 }
2752
2753 /**
2754 * Player wants to dump object below her.
2755 *
2756 * @param op
2757 * player asking for information.
2758 * @param params
2759 * unused.
2760 */
2761 void command_dumpbelow(object *op, const char *params) {
2762 if (op && op->below) {
2763 do_dump(op, op->below);
2764 }
2765 }
2766
2767 /**
2768 * Player wants to dump object above her.
2769 *
2770 * @param op
2771 * player asking for information.
2772 * @param params
2773 * unused.
2774 */
2775 void command_dumpabove(object *op, const char *params) {
2776 if (op && op->above) {
2777 do_dump(op, op->above);
2778 }
2779 }
2780
2781 /**
2782 * Wizard wants to know some server settings, so display.
2783 * @param op wizard asking for settings.
2784 * @param ignored ignored additional text.
2785 */
2786 void command_settings(object *op, const char *ignored) {
2787 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, "Server settings:"));
2788
2789 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * item power factor: %2f"), settings.item_power_factor);
2790
2791 if (settings.not_permadeth) {
2792 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * death is not permanent"));
2793 } else if (settings.resurrection) {
2794 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * permanent death, resurrection is enabled"));
2795 } else {
2796 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * permanent death, resurrection is NOT enabled"));
2797 }
2798
2799 if (settings.set_title) {
2800 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * players can set their title"));
2801 } else {
2802 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * players can't set their title"));
2803 }
2804
2805 if (settings.spell_encumbrance) {
2806 if (settings.spell_failure_effects) {
2807 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * too much equipment can lead to spell failure and ill effects"));
2808 } else {
2809 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * too much equipment can lead to spell failure but no ill effects"));
2810 }
2811 } else {
2812 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * too much equipment can't lead to spell failure"));
2813 }
2814
2815 if (settings.casting_time) {
2816 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * casting takes time"));
2817 } else {
2818 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * casting is immediate"));
2819 }
2820
2821 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * permanent experience: %d%%"), settings.permanent_exp_ratio);
2822 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * death penalty %d%% or %d levels"), settings.death_penalty_ratio, settings.death_penalty_level);
2823
2824 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * friendly fire: %d%%"), settings.set_friendly_fire);
2825
2826 if (settings.no_player_stealing) {
2827 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * players can't steal from other players"));
2828 } else {
2829 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * players can steal from other players"));
2830 }
2831
2832 if (settings.create_home_portals) {
2833 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * players can create portals from their apartments"));
2834 } else {
2835 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * players can't create portals from their apartments"));
2836 }
2837
2838 if (settings.allow_denied_spells_writing) {
2839 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * players can write spells they are denied"));
2840 } else {
2841 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, i18n(op, " * players can't write spells they are denied"));
2842 }
2843 }