/** Check to see if an object has a good zone lock set. * If it doesn't have a lock at all, set one of '=Zone'. * \param player The object responsible for having the lock checked. * \param zone the object whose lock needs to be checked. * \param noisy if 1, notify player of automatic locking */ void check_zone_lock(dbref player, dbref zone, int noisy) { boolexp key = getlock(zone, Zone_Lock); if (key == TRUE_BOOLEXP) { add_lock(GOD, zone, Zone_Lock, parse_boolexp(zone, "=me", Zone_Lock), -1); if (noisy) notify_format(player, T ("Unlocked zone %s - automatically zone-locking to itself"), unparse_object(player, zone)); } else if (eval_lock(Location(player), zone, Zone_Lock)) { /* Does #0 and #2 pass it? If so, probably trivial elock */ if (eval_lock(PLAYER_START, zone, Zone_Lock) && eval_lock(MASTER_ROOM, zone, Zone_Lock)) { if (noisy) notify_format(player, T("Zone %s really should have a more secure zone-lock."), unparse_object(player, zone)); } else /* Probably inexact zone lock */ notify_format(player, T ("Warning: Zone %s may have loose zone lock. Lock zones to =player, not player"), unparse_object(player, zone)); } }
/** Can a player control a thing? * The control rules are, in order: * Only God controls God. * Wizards control everything else. * Nothing else controls a wizard, and only royalty control royalty. * Mistrusted objects control only themselves. * Objects with the same owner control each other, unless the * target object is TRUST and the would-be controller isn't. * If ZMOs allow control, and you pass the ZMO, you control. * If the owner is a Zone Master, and you pass the ZM, you control. * If you pass the control lock, you control. * Otherwise, no dice. * \param who object attempting to control. * \param what object to be controlled. * \retval 1 who controls what. * \retval 0 who doesn't control what. */ int controls(dbref who, dbref what) { boolexp c; if (!GoodObject(what)) return 0; if (Guest(who)) return 0; if (what == who) return 1; if (God(what)) return 0; if (Wizard(who)) return 1; if (Wizard(what) || (Hasprivs(what) && !Hasprivs(who))) return 0; if (Mistrust(who)) return 0; if (Owns(who, what) && (!Inheritable(what) || Inheritable(who))) return 1; if (Inheritable(what) || IsPlayer(what)) return 0; if (!ZONE_CONTROL_ZMP && (Zone(what) != NOTHING) && eval_lock(who, Zone(what), Zone_Lock)) return 1; if (ZMaster(Owner(what)) && !IsPlayer(what) && eval_lock(who, Owner(what), Zone_Lock)) return 1; c = getlock_noparent(what, Control_Lock); if (c != TRUE_BOOLEXP) { if (eval_boolexp(who, c, what, NULL)) return 1; } return 0; }
// Call this function to see if a given object can // pass a type of lock on a target object. HS_BOOL8 CHSInterface::PassesLock(int obj, int target, HS_LOCKTYPE locktype) { int retval = 0; #ifdef PENNMUSH switch (locktype) { case LOCK_ZONE: retval = eval_lock(obj, target, Zone_Lock); break; case LOCK_USE: retval = eval_lock(obj, target, Use_Lock); break; case LOCK_NORMAL: default: retval = eval_lock(obj, target, Basic_Lock); break; } #endif #if defined(TM3) || defined(MUX) switch (locktype) { case LOCK_ZONE: retval = could_doit(obj, target, A_LCONTROL); break; case LOCK_USE: retval = could_doit(obj, target, A_LUSE); break; default: retval = could_doit(obj, target, A_LOCK); break; } #endif return retval ? true : false; }
/** Link an exit, room, player, or thing. * \verbatim * This is the top-level function for @link, which is used to link an * exit to a destination, set a player or thing's home, or set a * drop-to on a room. * * Linking an exit usually seizes ownership of the exit and costs 1 penny. * 1 penny is also transferred to the former owner. * \endverbatim * \param player the enactor. * \param name the name of the object to link. * \param room_name the name of the link destination. * \param preserve if 1, preserve ownership and zone data on exit relink. */ void do_link(dbref player, const char *name, const char *room_name, int preserve) { /* Use this to link to a room that you own. * It usually seizes ownership of the exit and costs 1 penny, * plus a penny transferred to the exit owner if they aren't you. * You must own the linked-to room AND specify it by room number. */ dbref thing; dbref room; if (!room_name || !*room_name) { do_unlink(player, name); return; } if (!IsRoom(player) && GoodObject(Location(player)) && IsExit(Location(player))) { notify(player, T("You somehow wound up in a exit. No biscuit.")); return; } if ((thing = noisy_match_result(player, name, TYPE_EXIT, MAT_EVERYTHING)) != NOTHING) { switch (Typeof(thing)) { case TYPE_EXIT: if ((room = check_var_link(room_name)) == NOTHING) room = parse_linkable_room(player, room_name); if (room == NOTHING) return; if (GoodObject(room) && !can_link_to(player, room)) { notify(player, T("Permission denied.")); break; } /* We may link an exit if it's unlinked and we pass the link-lock * or if we control it. */ if (!(controls(player, thing) || ((Location(thing) == NOTHING) && eval_lock(player, thing, Link_Lock)))) { notify(player, T("Permission denied.")); return; } if (preserve && !Wizard(player)) { notify(player, T("Permission denied.")); return; } /* handle costs */ if (Owner(thing) == Owner(player)) { if (!payfor(player, LINK_COST)) { notify_format(player, T("It costs %d %s to link this exit."), LINK_COST, ((LINK_COST == 1) ? MONEY : MONIES)); return; } } else { if (!payfor(player, LINK_COST + EXIT_COST)) { int a = LINK_COST + EXIT_COST; notify_format(player, T("It costs %d %s to link this exit."), a, ((a == 1) ? MONEY : MONIES)); return; } else if (!preserve) { /* pay the owner for his loss */ giveto(Owner(thing), EXIT_COST); chown_object(player, thing, player, 0); } } /* link has been validated and paid for; do it */ if (!preserve) { Owner(thing) = Owner(player); Zone(thing) = Zone(player); } Location(thing) = room; /* notify the player */ notify_format(player, T("Linked exit #%d to %s"), thing, unparse_object(player, room)); break; case TYPE_PLAYER: case TYPE_THING: if ((room = noisy_match_result(player, room_name, NOTYPE, MAT_EVERYTHING)) == NOTHING) { notify(player, T("No match.")); return; } if (IsExit(room)) { notify(player, T("That is an exit.")); return; } if (thing == room) { notify(player, T("You may not link something to itself.")); return; } /* abode */ if (!controls(player, room) && !Abode(room)) { notify(player, T("Permission denied.")); break; } if (!controls(player, thing)) { notify(player, T("Permission denied.")); } else if (room == HOME) { notify(player, T("Can't set home to home.")); } else { /* do the link */ Home(thing) = room; /* home */ if (!Quiet(player) && !(Quiet(thing) && (Owner(thing) == player))) notify(player, T("Home set.")); } break; case TYPE_ROOM: if ((room = parse_linkable_room(player, room_name)) == NOTHING) return; if ((room != HOME) && (!IsRoom(room))) { notify(player, T("That is not a room!")); return; } if (!controls(player, thing)) { notify(player, T("Permission denied.")); } else { /* do the link, in location */ Location(thing) = room; /* dropto */ notify(player, T("Dropto set.")); } break; default: notify(player, T("Internal error: weird object type.")); do_log(LT_ERR, NOTHING, NOTHING, "Weird object! Type of #%d is %d", thing, Typeof(thing)); break; } } }