Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,8 @@ bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item*
}

if (g_config.getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) {
if (HouseTile* houseTile = dynamic_cast<HouseTile*>(item->getTile())) {
House* house = houseTile->getHouse();
if (house && !house->isInvited(player)) {
if (const HouseTile* const houseTile = dynamic_cast<const HouseTile*>(item->getTile())) {
if (!item->getTopParent()->getCreature() && !houseTile->getHouse()->isInvited(player)) {
player->sendCancelMessage(RETURNVALUE_PLAYERISNOTINVITED);
return false;
}
Expand Down Expand Up @@ -477,6 +476,15 @@ bool Actions::useItemEx(Player* player, const Position& fromPos, const Position&
showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), subType != item->getItemCount() ? subType : -1));
}

if (g_config.getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) {
if (const HouseTile* const houseTile = dynamic_cast<const HouseTile*>(item->getTile())) {
if (!item->getTopParent()->getCreature() && !houseTile->getHouse()->isInvited(player)) {
player->sendCancelMessage(RETURNVALUE_PLAYERISNOTINVITED);
return false;
}
}
}

if (action->executeUse(player, item, fromPos, action->getTarget(player, creature, toPos, toStackPos), toPos, isHotkey)) {
return true;
}
Expand Down
20 changes: 16 additions & 4 deletions src/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,15 @@ ReturnValue Container::queryAdd(int32_t index, const Thing& thing, uint32_t coun
}
}

const Cylinder* topParent = getTopParent();
const Cylinder* const topParent = getTopParent();
if (actor && g_config.getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) {
if (const HouseTile* const houseTile = dynamic_cast<const HouseTile*>(topParent->getTile())) {
if (!topParent->getCreature() && !houseTile->getHouse()->isInvited(actor->getPlayer())) {
return RETURNVALUE_PLAYERISNOTINVITED;
}
}
}

if (topParent != this) {
return topParent->queryAdd(INDEX_WHEREEVER, *item, count, flags | FLAG_CHILDISOWNER, actor);
}
Expand Down Expand Up @@ -381,9 +389,13 @@ ReturnValue Container::queryRemove(const Thing& thing, uint32_t count, uint32_t
return RETURNVALUE_NOTMOVEABLE;
}

const HouseTile* houseTile = dynamic_cast<const HouseTile*>(getTopParent());
if (houseTile) {
return houseTile->queryRemove(thing, count, flags, actor);
if (actor && g_config.getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) {
const Cylinder* const topParent = getTopParent();
if (const HouseTile* const houseTile = dynamic_cast<const HouseTile*>(topParent->getTile())) {
if (!topParent->getCreature() && !houseTile->getHouse()->isInvited(actor->getPlayer())) {
return RETURNVALUE_PLAYERISNOTINVITED;
}
}
}

return RETURNVALUE_NOERROR;
Expand Down
7 changes: 3 additions & 4 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2628,10 +2628,9 @@ void Game::playerRequestTrade(uint32_t playerId, const Position& pos, uint8_t st
}

if (g_config.getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) {
if (HouseTile* houseTile = dynamic_cast<HouseTile*>(tradeItem->getTile())) {
House* house = houseTile->getHouse();
if (house && !house->isInvited(player)) {
player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE);
if (const HouseTile* const houseTile = dynamic_cast<const HouseTile*>(tradeItem->getTile())) {
if (!tradeItem->getTopParent()->getCreature() && !houseTile->getHouse()->isInvited(player)) {
player->sendCancelMessage(RETURNVALUE_PLAYERISNOTINVITED);
return;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void House::updateDoorDescription() const
}
}

AccessHouseLevel_t House::getHouseAccessLevel(const Player* player)
AccessHouseLevel_t House::getHouseAccessLevel(const Player* player) const
{
if (!player) {
return HOUSE_OWNER;
Expand Down Expand Up @@ -277,7 +277,7 @@ bool House::getAccessList(uint32_t listId, std::string& list) const
return door->getAccessList(list);
}

bool House::isInvited(const Player* player)
bool House::isInvited(const Player* player) const
{
return getHouseAccessLevel(player) != HOUSE_NOT_INVITED;
}
Expand Down Expand Up @@ -499,7 +499,7 @@ void AccessList::addGuildRank(const std::string& name, const std::string& rankNa
}
}

bool AccessList::isInList(const Player* player)
bool AccessList::isInList(const Player* player) const
{
if (allowEveryone) {
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/house.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AccessList
void addGuild(const std::string& name);
void addGuildRank(const std::string& name, const std::string& rankName);

bool isInList(const Player* player);
bool isInList(const Player* player) const;

void getList(std::string& list) const;

Expand Down Expand Up @@ -142,9 +142,9 @@ class House
void setAccessList(uint32_t listId, const std::string& textlist);
bool getAccessList(uint32_t listId, std::string& list) const;

bool isInvited(const Player* player);
bool isInvited(const Player* player) const;

AccessHouseLevel_t getHouseAccessLevel(const Player* player);
AccessHouseLevel_t getHouseAccessLevel(const Player* player) const;
bool kickPlayer(Player* player, Player* target);

void setEntryPos(Position pos) {
Expand Down
12 changes: 5 additions & 7 deletions src/housetile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ ReturnValue HouseTile::queryAdd(int32_t index, const Thing& thing, uint32_t coun
return RETURNVALUE_ITEMCANNOTBEMOVEDTHERE;
}

if (actor) {
Player* actorPlayer = actor->getPlayer();
if (!house->isInvited(actorPlayer)) {
return RETURNVALUE_CANNOTTHROW;
if (actor && g_config.getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) {
if (!house->isInvited(actor->getPlayer())) {
return RETURNVALUE_PLAYERISNOTINVITED;
}
}
}
Expand Down Expand Up @@ -137,9 +136,8 @@ ReturnValue HouseTile::queryRemove(const Thing& thing, uint32_t count, uint32_t
}

if (actor && g_config.getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) {
Player* actorPlayer = actor->getPlayer();
if (!house->isInvited(actorPlayer)) {
return RETURNVALUE_NOTPOSSIBLE;
if (!house->isInvited(actor->getPlayer())) {
return RETURNVALUE_PLAYERISNOTINVITED;
}
}
return Tile::queryRemove(thing, count, flags);
Expand Down
2 changes: 1 addition & 1 deletion src/housetile.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class HouseTile final : public DynamicTile
void addThing(int32_t index, Thing* thing) override;
void internalAddThing(uint32_t index, Thing* thing) override;

House* getHouse() {
House* getHouse() const {
return house;
}

Expand Down