home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / tinymud2.zip / WIZ.C < prev   
C/C++ Source or Header  |  1990-09-02  |  17KB  |  624 lines

  1. #include "copyright.h"
  2.  
  3. /* Wizard-only commands */
  4.  
  5.  
  6. #include "db.h"
  7. #include "config.h"
  8. #include "interface.h"
  9. #include "match.h"
  10. #include "externs.h"
  11.  
  12. void do_teleport(dbref player, const char *arg1, const char *arg2)
  13. {
  14.     dbref victim;
  15.     dbref destination;
  16.     const char *to;
  17.  
  18. #ifdef RESTRICTED_TELEPORT
  19.     if(!Wizard(player)) {
  20. #ifndef TINKER
  21.     notify(player, "Only a Wizard may teleport at will.");
  22. #else TINKER
  23.     notify(player, "Only a Tinker may teleport at will.");
  24. #endif TINKER
  25.     return;
  26.     }
  27. #endif /* RESTRICTED_TELEPORT */
  28.  
  29.     /* get victim, destination */
  30.     if(*arg2 == '\0') {
  31.     victim = player;
  32.     to = arg1;
  33.     } else {
  34.     init_match(player, arg1, NOTYPE);
  35.     match_neighbor();
  36.     match_possession();
  37.     match_me();
  38.     match_absolute();
  39.     match_player();
  40.  
  41.     if((victim = noisy_match_result()) == NOTHING) {
  42.         return;
  43.     }
  44.     to = arg2;
  45.     }
  46.  
  47.     /* get destination */
  48.     init_match(player, to, TYPE_PLAYER);
  49.     match_here();
  50.     match_absolute();
  51.     if(Wizard(player)) {
  52.     match_neighbor();
  53.     match_me();
  54.     match_player();
  55.     }
  56.  
  57.     switch(destination = match_result()) {
  58.       case NOTHING:
  59.     notify(player, "Send it where?");
  60.     break;
  61.       case AMBIGUOUS:
  62.     notify(player, "I don't know which destination you mean!");
  63.     break;
  64.       default:
  65.     /* check victim, destination types, teleport if ok */
  66.     if(Typeof(destination) == TYPE_EXIT
  67.        || Typeof(destination) == TYPE_THING
  68.        || Typeof(victim) == TYPE_EXIT
  69.        || Typeof(victim) == TYPE_ROOM
  70.        || (Typeof(victim) == TYPE_PLAYER
  71.            && Typeof(destination) != TYPE_ROOM)) {
  72.         notify(player, "Bad destination.");
  73. #ifndef RESTRICTED_TELEPORT
  74.     } else if(!Wizard(player)
  75.           && !(Typeof(victim) == TYPE_THING
  76.                && Typeof(destination) == TYPE_ROOM
  77.                && (controls(player, victim)
  78.                || (Typeof(db[victim].location) == TYPE_ROOM
  79.                    && controls(player, db[victim].location)))
  80.                && (can_link_to(player, TYPE_PLAYER, destination)))) {
  81.         notify(player, "Permission denied.");
  82. #endif /* RESTRICTED_TELEPORT */          
  83.     } else if(Typeof(victim) == TYPE_PLAYER) {
  84.         notify(victim, "You feel a wrenching sensation...");
  85.         enter_room(victim, destination);
  86.         notify(player, "Teleported.");
  87.     } else {
  88.         /* check for non-sticky dropto */
  89.         if(Typeof(destination) == TYPE_ROOM
  90.            && db[destination].location != NOTHING
  91.            && !(db[destination].flags & STICKY)) {
  92.         /* destination has immediate dropto */
  93.         destination = db[destination].location;
  94.         }
  95.  
  96.         /* do the move */
  97.         moveto(victim, destination);
  98.         notify(player, "Teleported.");
  99.     }
  100.     }
  101. }
  102.  
  103. void do_mass_teleport(dbref player, const char *arg1)
  104. {
  105.     dbref victim;
  106.     dbref destination;
  107.     char buf[BUFFER_LEN];
  108.     int moved = 0;
  109.  
  110.     if(!God(player)) {
  111. #ifndef TINKER
  112.     notify(player, "Only God can do a mass teleport.");
  113. #else TINKER
  114.     notify(player, "Only the Master Tinker can do a mass teleport.");
  115. #endif TINKER
  116.     return;
  117.     }
  118.  
  119.     /* get destination */
  120.     init_match(player, arg1, TYPE_ROOM);
  121.     match_here();
  122.     match_absolute();
  123.  
  124.     if ((destination = match_result()) == NOTHING) {
  125.     notify(player, "Please specify a destination to send everyone to.");
  126.     return;
  127.     }
  128.     
  129.     switch (Typeof(destination)) {
  130.       case NOTHING:
  131.     notify(player, "Send them where?");
  132.     break;
  133.  
  134.       case TYPE_ROOM:
  135.         for (victim = 0; victim < db_top; victim++) {
  136.         if (victim != player && Typeof(victim) == TYPE_PLAYER) {
  137.             notify(victim,
  138.          "You and everyone around you feels a wrenching sensation...");
  139.         moveto(victim, destination);
  140.         look_room(victim, destination);
  141.         moved++;
  142.         }
  143.     }
  144.     sprintf (buf, "Teleported %d players to %s.",
  145.          moved, unparse_object (player, destination));
  146.     notify(player, "Teleported.");
  147.         break;
  148.     
  149.       default:
  150.     notify(player, "Mass teleports are legal to rooms only.");
  151.     }
  152. }
  153.  
  154. void do_force(dbref player, const char *what, char *command)
  155. {
  156.     dbref victim;
  157.  
  158.     if(!Wizard(player)) {
  159.     writelog ("FORCE: failed, priv, player %s(%d), who '%s', what '%s'\n",
  160.           db[player].name, player, what, command);
  161. #ifndef TINKER
  162.     notify(player, "Only Wizards may use this command.");
  163. #else TINKER
  164.     notify(player, "Only Tinkers may use this command.");
  165. #endif TINKER
  166.     return;
  167.     }
  168.  
  169.     /* get victim */
  170.     if((victim = lookup_player(what)) == NOTHING) {
  171.     writelog ("FORCE: failed, victim, player %s(%d), who '%s', what '%s'\n",
  172.           db[player].name, player, what, command);
  173.     notify(player, "That player does not exist.");
  174.     return;
  175.     }
  176.  
  177. #ifdef GOD_PRIV
  178.     if(God(victim)) {
  179. #ifndef TINKER
  180.     writelog ("FORCE: failed, wizard, player %s(%d), who '%s', what '%s'\n",
  181. #else TINKER
  182.     writelog ("FORCE: failed, tinker, player %s(%d), who '%s', what '%s'\n",
  183. #endif TINKER
  184.           db[player].name, player, what, command);
  185. #ifndef TINKER
  186.     notify(player, "You can't force God.");
  187. #else TINKER
  188.     notify(player, "You can't force the Master Tinker.");
  189. #endif TINKER
  190.     return;
  191.     }
  192. #endif GOD_PRIV
  193.  
  194.     /* force victim to do command */
  195.     writelog ("FORCE: success, player %s(%d), who '%s', what '%s'\n",
  196.           db[player].name, player, what, command);
  197.  
  198.     process_command(victim, command);
  199. }
  200.  
  201. void do_stats(dbref player, const char *name)
  202. {
  203.     dbref rooms;
  204.     dbref exits;
  205.     dbref things;
  206.     dbref players;
  207.     dbref total;
  208.     dbref i;
  209.     dbref owner;
  210.     char buf[BUFFER_LEN];
  211.  
  212.     if(!Wizard(player)) {
  213.     sprintf(buf, "The universe contains %d objects.", db_top);
  214.     notify(player, buf);
  215.     } else {
  216.     owner = lookup_player(name);
  217.     total = rooms = exits = things = players = 0;
  218.     for(i = 0; i < db_top; i++) {
  219.         if(owner == NOTHING || owner == db[i].owner) {
  220.         total++;
  221.         switch(Typeof(i)) {
  222.           case TYPE_ROOM:
  223.             rooms++;
  224.             break;
  225.           case TYPE_EXIT:
  226.             exits++;
  227.             break;
  228.           case TYPE_THING:
  229.             things++;
  230.             break;
  231.           case TYPE_PLAYER:
  232.             players++;
  233.             break;
  234.           default:
  235.             abort();
  236.             break;
  237.         }
  238.         }
  239.     }
  240.     sprintf(buf,
  241.         "%d objects = %d rooms, %d exits, %d things, %d players.",
  242.         total, rooms, exits, things, players);
  243.     notify(player, buf);
  244. #ifdef TEST_MALLOC
  245.     sprintf(buf, "Malloc count = %d.", malloc_count);
  246.     notify(player, buf);
  247. #endif /* TEST_MALLOC */
  248.     }
  249. }
  250.         
  251. void do_bobble(dbref player, const char *name, const char *rname)
  252. {
  253.     dbref victim, recip, i;
  254.     char buf[BUFFER_LEN];
  255.     int newflags = 0;
  256.  
  257.     if(!Wizard(player)) {
  258. #ifndef TINKER
  259.         writelog("TOAD: failed, priv %s(%d) who '%s'\n",
  260.          db[player].name, player, name);
  261.     notify(player, "Only a Wizard can turn a person into a toad.");
  262. #else TINKER
  263.         writelog("BOBBLE: failed, priv %s(%d) who '%s'\n",
  264.          db[player].name, player, name);
  265.     notify(player, "Only a Tinker can bobble a person.");
  266. #endif TINKER
  267.     return;
  268.     }
  269.  
  270.     if (!name || !*name) {
  271. #ifndef TINKER
  272.         writelog("TOAD: failed, syntax %s(%d) who '%s'\n",
  273.          db[player].name, player, name);
  274. #else TINKER
  275.         writelog("BOBBLE: failed, syntax %s(%d) who '%s'\n",
  276.          db[player].name, player, name);
  277. #endif TINKER
  278.     notify(player, "You must specify a victim.");
  279.     return;
  280.     }
  281.     
  282.     init_match(player, name, TYPE_PLAYER);
  283.     match_neighbor();
  284.     match_absolute();
  285.     match_player();
  286.     if((victim = noisy_match_result()) == NOTHING) {
  287. #ifndef TINKER
  288.         writelog("TOAD: failed, victim %s(%d) who '%s'\n",
  289.          db[player].name, player, name);
  290. #else TINKER
  291.         writelog("BOBBLE: failed, victim %s(%d) who '%s'\n",
  292.          db[player].name, player, name);
  293. #endif TINKER
  294.     notify(player, "Please specify another victim.");
  295.     return;
  296.     }
  297.  
  298. #ifdef RECYCLE
  299.     /* Default the recipient to RECYCLER */
  300.     if (!rname || !*rname || string_compare (rname, RECYCLER) == 0) {
  301.     recip = lookup_player(RECYCLER);
  302.     newflags = UNWANTED;        /* Can be gotten by other players */
  303.     } else {
  304.     recip = lookup_player(rname);
  305.     }
  306. #else
  307.     recip = lookup_player(rname);
  308. #endif
  309.  
  310.     if(recip == NOTHING || recip == victim) {
  311. #ifndef TINKER
  312.         writelog("TOAD: failed, recip %s(%d) who '%s'\n",
  313.          db[player].name, player, name);
  314. #else TINKER
  315.         writelog("BOBBLE: failed, recip %s(%d) who '%s'\n",
  316.          db[player].name, player, name);
  317. #endif TINKER
  318.     notify(player, "Please specify another player to own the victim's effects.");
  319.     return;
  320.     }
  321.  
  322.     if(Typeof(victim) != TYPE_PLAYER) {
  323. #ifndef TINKER
  324.         writelog("TOAD: failed, type %s(%d) who '%s'\n",
  325.          db[player].name, player, name);
  326.     notify(player, "You can only turn players into toads!");
  327. #else TINKER
  328.         writelog("BOBBLE: failed, type %s(%d) who '%s'\n",
  329.          db[player].name, player, name);
  330.     notify(player, "You can only bobble players!");
  331. #endif TINKER
  332.     } else if(Wizard(victim)) {
  333. #ifndef TINKER
  334.         writelog("TOAD: failed, wizard %s(%d) who '%s'\n",
  335.          db[player].name, player, name);
  336.     notify(player, "You can't turn a Wizard into a toad.");
  337. #else TINKER
  338.         writelog("BOBBLE: failed, tinker %s(%d) who '%s'\n",
  339.          db[player].name, player, name);
  340.     notify(player, "You can't bobble a Tinker.");
  341. #endif TINKER
  342.     } else if(db[victim].contents != NOTHING) {
  343. #ifndef TINKER
  344.         writelog("TOAD: failed, contents %s(%d) who '%s'\n",
  345.          db[player].name, player, name);
  346. #else TINKER
  347.         writelog("BOBBLE: failed, contents %s(%d) who '%s'\n",
  348.          db[player].name, player, name);
  349. #endif TINKER
  350.  
  351.     notify(player, "What about what they are carrying?");
  352.     } else {
  353. #ifndef TINKER
  354.         writelog("TOAD: success %s(%d) who '%s'\n",
  355.          db[player].name, player, name);
  356. #else TINKER
  357.         writelog("BOBBLE: success %s(%d) who '%s'\n",
  358.          db[player].name, player, name);
  359. #endif TINKER
  360.  
  361.     /* we are ok */
  362.     /* do it */
  363.     if(db[victim].password) {
  364.         free((void *) db[victim].password);
  365.         db[victim].password = 0;
  366.     }
  367.     db[victim].flags = TYPE_THING;
  368.  
  369.     /* Give the sphere and all old belongings to recipient */
  370.     db[victim].owner = recip;
  371.     for (i=0; i<db_top; i++) {
  372.         if (db[i].owner == victim) {
  373.         db[i].owner = recip;
  374.         db[i].flags |= newflags;
  375.         }
  376.     }
  377.  
  378.     db[victim].pennies = 1;    /* dont let him keep his immense wealth */
  379.  
  380.     /* notify people */
  381. #ifndef TINKER
  382.     sprintf(buf, "You have been turned into a toad by %s.",
  383.         db[player].name);
  384. #else TINKER
  385.     sprintf(buf, "You have been encased in a stasis sphere by %s.",
  386.         db[player].name);
  387. #endif TINKER
  388.     notify(victim, buf);
  389. #ifndef TINKER
  390.     sprintf(buf, "You turned %s into a toad!", db[victim].name);
  391. #else TINKER
  392.     sprintf(buf, "You bobbled %s!", db[victim].name);
  393. #endif TINKER
  394.     notify(player, buf);
  395.  
  396.     /* reset name */
  397. #ifdef PLAYER_LIST
  398.     delete_player(victim);
  399. #endif PLAYER_LIST    
  400. #ifndef TINKER
  401.     sprintf(buf, "a slimy toad named %s", db[victim].name);
  402. #else TINKER
  403.     sprintf(buf, "a silvery sphere containing %s", db[victim].name);
  404. #endif TINKER
  405.     free((void *) db[victim].name);
  406.     db[victim].name = alloc_string(buf);
  407.     }
  408. }
  409.  
  410. void do_unbobble(dbref player, const char *name, const char *newname)
  411. {
  412.     dbref victim;
  413.     char buf[BUFFER_LEN];
  414.  
  415.     if(!Wizard(player)) {
  416. #ifndef TINKER
  417.         writelog("UNTOAD: failed, priv %s(%d) who '%s'\n",
  418.          db[player].name, player, name);
  419.     notify(player, "Only a Wizard can turn a toad into a person.");
  420. #else TINKER
  421.         writelog("UNBOBBLE: failed, priv %s(%d) who '%s'\n",
  422.          db[player].name, player, name);
  423.     notify(player, "Only a Tinker can unbobble a person.");
  424. #endif TINKER
  425.     return;
  426.     }
  427.  
  428.     if (!name || !*name) {
  429. #ifndef TINKER
  430.         writelog("UNTOAD: failed, syntax %s(%d) who '%s'\n",
  431.          db[player].name, player, name);
  432. #else TINKER
  433.         writelog("UNBOBBLE: failed, syntax %s(%d) who '%s'\n",
  434.          db[player].name, player, name);
  435. #endif TINKER
  436.     notify(player, "You must specify a thing.");
  437.     return;
  438.     }
  439.     
  440.     if (!newname || !*newname) {
  441. #ifndef TINKER
  442.         writelog("UNTOAD: failed, syntax %s(%d) who '%s'\n",
  443.          db[player].name, player, name);
  444.     notify(player,"You must specify a new name: @untoad <thing> = <name>");
  445. #else TINKER
  446.         writelog("UNBOBBLE: failed, syntax %s(%d) who '%s'\n",
  447.          db[player].name, player, name);
  448.     notify(player,
  449.            "You must specify a new name: @unbobble <thing> = <name>");
  450. #endif TINKER
  451.     return;
  452.     }
  453.     
  454.     init_match(player, name, TYPE_THING);
  455.     match_neighbor();
  456.     match_absolute();
  457.     match_player();
  458.     if((victim = noisy_match_result()) == NOTHING) {
  459. #ifndef TINKER
  460.         writelog("UNTOAD: failed, victim %s(%d) who '%s'\n",
  461.          db[player].name, player, name);
  462. #else TINKER
  463.         writelog("UNBOBBLE: failed, victim %s(%d) who '%s'\n",
  464.          db[player].name, player, name);
  465. #endif TINKER
  466.     notify(player, "Please specify another thing.");
  467.     return;
  468.     }
  469.  
  470.     if(Typeof(victim) != TYPE_THING) {
  471. #ifndef TINKER
  472.         writelog("UNTOAD: failed, type %s(%d) who '%s'\n",
  473.          db[player].name, player, name);
  474.     notify(player, "You can only turn players into toads!");
  475. #else TINKER
  476.         writelog("UNBOBBLE: failed, type %s(%d) who '%s'\n",
  477.          db[player].name, player, name);
  478.     notify(player, "You can only bobble players!");
  479. #endif TINKER
  480.     } else if (!ok_player_name(newname)) {
  481. #ifndef TINKER
  482.         writelog("UNTOAD: failed, name %s(%d) who '%s'\n",
  483.          db[player].name, player, name);
  484. #else TINKER
  485.         writelog("UNBOBBLE: failed, name %s(%d) who '%s'\n",
  486.          db[player].name, player, name);
  487. #endif TINKER
  488.     notify(player, "You can't give a player that name!");
  489.     } else {
  490. #ifndef TINKER
  491.         writelog("UNTOAD: success %s(%d) who '%s'\n",
  492.          db[player].name, player, name);
  493. #else TINKER
  494.         writelog("UNBOBBLE: success %s(%d) who '%s'\n",
  495.          db[player].name, player, name);
  496. #endif TINKER
  497.  
  498.     /* we are ok */
  499.     /* do it */
  500.     db[victim].flags = TYPE_PLAYER;
  501.     db[victim].owner = victim;
  502.     db[victim].pennies = KILL_BONUS;
  503.  
  504.     /* reset name */
  505.     free((void *) db[victim].name);
  506.     db[victim].name = alloc_string(newname);
  507.  
  508. #ifndef TINKER
  509.     sprintf(buf, "You turned the toad back into %s!", db[victim].name);
  510. #else TINKER
  511.     sprintf(buf, "You unbobbled %s!", db[victim].name);
  512. #endif TINKER
  513.     notify(player, buf);
  514.  
  515.     sprintf(buf, "Use @newpassword to give %s a password",
  516.         db[victim].name);
  517.     notify(player, buf);
  518.  
  519. #ifdef PLAYER_LIST
  520.     add_player(victim);
  521. #endif PLAYER_LIST    
  522.     }
  523. }
  524.  
  525. void do_newpassword(dbref player, const char *name, const char *password)
  526. {
  527.     dbref victim;
  528.     char buf[BUFFER_LEN];
  529.  
  530.     if(!Wizard(player)) {
  531.         writelog("PASSWORD: failed, priv %s(%d) who '%s'\n",
  532.          db[player].name, player, name);
  533.     notify(player, "Your delusions of grandeur have been duly noted.");
  534.     return;
  535.     } else if((victim = lookup_player(name)) == NOTHING) {
  536.         writelog("PASSWORD: failed, victim %s(%d) who '%s'\n",
  537.          db[player].name, player, name);
  538.     notify(player, "No such player.");
  539.     } else if(*password != '\0' && !ok_password(password)) {
  540.     /* Wiz can set null passwords, but not bad passwords */
  541.         writelog("PASSWORD: failed, password %s(%d) who '%s'\n",
  542.          db[player].name, player, name);
  543.     notify(player, "Bad password");
  544. #ifdef GOD_PRIV    
  545.     } else if (God(victim) && !God(player)) {
  546. #ifndef TINKER
  547.         writelog("PASSWORD: failed, wizard %s(%d) who '%s'\n",
  548. #else TINKER
  549.         writelog("PASSWORD: failed, tinker %s(%d) who '%s'\n",
  550. #endif TINKER
  551.          db[player].name, player, name);
  552.     notify(player, "You cannot change that player's password.");
  553. #endif GOD_PRIV    
  554.     } else {
  555.         writelog("PASSWORD: success %s(%d) who '%s'\n",
  556.          db[player].name, player, name);
  557.     /* it's ok, do it */
  558.     if(db[victim].password) free((void *) db[victim].password);
  559.     db[victim].password = alloc_string(password);
  560.     notify(player, "Password changed.");
  561.     sprintf(buf, "Your password has been changed by %s.", db[player].name);
  562.     notify(victim, buf);
  563.     }
  564. }
  565.  
  566. void do_boot(dbref player, const char *name)
  567. {
  568.     dbref victim;
  569.     char buf[BUFFER_LEN];
  570.  
  571.     if(!Wizard(player)) {
  572.     writelog ("BOOT: failed, priv player %s(%d), who '%s'\n",
  573.           db[player].name, player, name);
  574.  
  575. #ifndef TINKER
  576.     notify(player, "Only a Wizard can boot another player off!");
  577. #else TINKER
  578.     notify(player, "Only a Tinker can boot another player off!");
  579. #endif TINKER
  580.     return;
  581.     }
  582.  
  583.     init_match(player, name, TYPE_PLAYER);
  584.     match_neighbor();
  585.     match_absolute();
  586.     match_player();
  587.     if((victim = noisy_match_result()) == NOTHING) return;
  588.  
  589. #ifdef GOD_PRIV
  590.     if(God(victim)) {
  591. #ifndef TINKER
  592.     writelog ("BOOT: failed, wizard, player %s(%d), who '%s'\n",
  593. #else TINKER
  594.     writelog ("BOOT: failed, tinker, player %s(%d), who '%s'\n",
  595. #endif TINKER
  596.           db[player].name, player, name);
  597.  
  598.     notify(player, "You can't boot that player!");
  599.     return;
  600.     }
  601. #endif GOD_PRIV
  602.  
  603.     if(Typeof(victim) != TYPE_PLAYER) {
  604.     writelog ("BOOT: failed, victim, player %s(%d), who '%s'\n",
  605.           db[player].name, player, name);
  606.  
  607.     notify(player, "You can only boot off other players!");
  608.     } else {
  609.     writelog ("BOOT: success, player %s(%d), who '%s'\n",
  610.           db[player].name, player, name);
  611.  
  612.     /* we are ok */
  613.     /* do it */
  614.     /* notify people */
  615.     sprintf(buf, "You have been booted off the game by %s.",
  616.         db[player].name);
  617.     notify(victim, buf);
  618.     sprintf(buf, "You booted %s off!", db[victim].name);
  619.     notify(player, buf);
  620.     boot_off(victim);
  621.     /* reset name */
  622.     }
  623. }
  624.