예제 #1
0
 /** Validate that the specified user is the room owner or the owner of the pet. */
 protected void validateRoomOrPetOwnership(MemberObject owner) throws InvocationException {
   // normally I always do the cheap compare first, but I'd rather not duplicate
   // the code from validateOwnership.
   PlaceManager plmgr = _placeReg.getPlaceManager(owner.getPlaceOid());
   if ((plmgr instanceof RoomManager) && ((RoomManager) plmgr).canManage(owner)) {
     return; // they check out, they're room owners
   }
   // otherwise...
   validateOwnership(owner);
 }
예제 #2
0
  /** Handles an order from the specified user on this pet. */
  public void orderPet(MemberObject owner, int order) throws InvocationException {
    // first validate the permissions
    if (order == Pet.ORDER_SLEEP) {
      validateRoomOrPetOwnership(owner);
    } else {
      validateOwnership(owner);
    }

    // then enact the order
    switch (order) {
      case Pet.ORDER_SLEEP:
        if (_petobj.pet.ownerId != owner.getMemberId()) {
          // a non-owner sent the pet to sleep, let's report that
          MemberObject realOwner = _locator.lookupMember(_petobj.pet.ownerId);
          if (realOwner != null) {
            SpeakUtil.sendInfo(
                realOwner,
                MsoyCodes.GENERAL_MSGS,
                MessageUtil.tcompose("m.pet_ordered4_room_mgr", owner.getVisibleName()));
          }
        }
        stopFollowing();
        updateUsage(Item.UsedAs.NOTHING, 0);
        shutdown(false);
        break;

      case Pet.ORDER_FOLLOW:
        startFollowing(owner);
        break;

      case Pet.ORDER_GO_HOME:
        stopFollowing();
        updateUsage(Item.UsedAs.PET, owner.homeSceneId);
        if (ScenePlace.getSceneId(_petobj) == owner.homeSceneId) {
          // we're already home, yay!
        } else if (_sceneReg.getSceneManager(owner.homeSceneId) != null) {
          enterRoom(owner.homeSceneId);
        } else {
          // TODO: if home room is resolved (on any server), instruct it to resolve pet
          shutdown(false);
        }
        break;

      case Pet.ORDER_STAY:
        // make sure the requester is in a room that they own
        PlaceManager plmgr = _placeReg.getPlaceManager(owner.getPlaceOid());
        if (!(plmgr instanceof RoomManager)) {
          log.info("Owner no longer in a room?", "who", owner.who(), "in", plmgr);
          throw new InvocationException(PetCodes.E_INTERNAL_ERROR);
        }
        ((RoomManager) plmgr).requireCanAddPet(owner);
        // potentially stop following our owner
        stopFollowing();
        // note that we want to autoload in this room
        updateUsage(Item.UsedAs.PET, ((RoomManager) plmgr).getScene().getId());
        break;

      default:
        log.warning("Received unknown pet order", "from", owner.who(), "order", order);
        throw new InvocationException(PetCodes.E_INTERNAL_ERROR);
    }
  }