Skip to content

Commit

Permalink
config: houseOwnedByAccount (#2935)
Browse files Browse the repository at this point in the history
This enables or disables the possibility that characters from the same account automatically become "owners" and have full access to the house.
  • Loading branch information
MillhioreBT committed Apr 29, 2020
1 parent d6dd42d commit 20f50a0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.lua.dist
Expand Up @@ -42,6 +42,7 @@ deathLosePercent = -1
-- NOTE: set housePriceEachSQM to -1 to disable the ingame buy house functionality
housePriceEachSQM = 1000
houseRentPeriod = "never"
houseOwnedByAccount = false

-- Item Usage
timeBetweenActions = 200
Expand Down
1 change: 1 addition & 0 deletions src/configmanager.cpp
Expand Up @@ -150,6 +150,7 @@ bool ConfigManager::load()
boolean[ONLINE_OFFLINE_CHARLIST] = getGlobalBoolean(L, "showOnlineStatusInCharlist", false);
boolean[YELL_ALLOW_PREMIUM] = getGlobalBoolean(L, "yellAlwaysAllowPremium", false);
boolean[FORCE_MONSTERTYPE_LOAD] = getGlobalBoolean(L, "forceMonsterTypesOnLoad", true);
boolean[HOUSE_OWNED_BY_ACCOUNT] = getGlobalBoolean(L, "houseOwnedByAccount", false);

string[DEFAULT_PRIORITY] = getGlobalString(L, "defaultPriority", "high");
string[SERVER_NAME] = getGlobalString(L, "serverName", "");
Expand Down
1 change: 1 addition & 0 deletions src/configmanager.h
Expand Up @@ -52,6 +52,7 @@ class ConfigManager
ONLINE_OFFLINE_CHARLIST,
YELL_ALLOW_PREMIUM,
FORCE_MONSTERTYPE_LOAD,
HOUSE_OWNED_BY_ACCOUNT,

LAST_BOOLEAN_CONFIG /* this must be the last one */
};
Expand Down
8 changes: 8 additions & 0 deletions src/house.cpp
Expand Up @@ -79,6 +79,7 @@ void House::setOwner(uint32_t guid, bool updateDatabase/* = true*/, Player* play

//clean access lists
owner = 0;
ownerAccountId = 0;
setAccessList(SUBOWNER_LIST, "");
setAccessList(GUEST_LIST, "");

Expand Down Expand Up @@ -110,6 +111,7 @@ void House::setOwner(uint32_t guid, bool updateDatabase/* = true*/, Player* play
if (!name.empty()) {
owner = guid;
ownerName = name;
ownerAccountId = IOLoginData::getAccountIdByPlayerName(name);
}
}

Expand Down Expand Up @@ -141,6 +143,12 @@ AccessHouseLevel_t House::getHouseAccessLevel(const Player* player)
return HOUSE_OWNER;
}

if (g_config.getBoolean(ConfigManager::HOUSE_OWNED_BY_ACCOUNT)) {
if (ownerAccountId == player->getAccount()) {
return HOUSE_OWNER;
}
}

if (player->hasFlag(PlayerFlag_CanEditHouses)) {
return HOUSE_OWNER;
}
Expand Down
1 change: 1 addition & 0 deletions src/house.h
Expand Up @@ -245,6 +245,7 @@ class House

uint32_t id;
uint32_t owner = 0;
uint32_t ownerAccountId = 0;
uint32_t rentWarnings = 0;
uint32_t rent = 0;
uint32_t townId = 0;
Expand Down
13 changes: 13 additions & 0 deletions src/iologindata.cpp
Expand Up @@ -160,6 +160,19 @@ uint32_t IOLoginData::gameworldAuthentication(const std::string& accountName, co
return accountId;
}

uint32_t IOLoginData::getAccountIdByPlayerName(const std::string& playerName)
{
Database& db = Database::getInstance();

std::ostringstream query;
query << "SELECT `account_id` FROM `players` WHERE `name` = " << db.escapeString(playerName);
DBResult_ptr result = db.storeQuery(query.str());
if (!result) {
return 0;
}
return result->getNumber<uint32_t>("account_id");
}

AccountType_t IOLoginData::getAccountType(uint32_t accountId)
{
std::ostringstream query;
Expand Down
1 change: 1 addition & 0 deletions src/iologindata.h
Expand Up @@ -34,6 +34,7 @@ class IOLoginData

static bool loginserverAuthentication(const std::string& name, const std::string& password, Account& account);
static uint32_t gameworldAuthentication(const std::string& accountName, const std::string& password, std::string& characterName, std::string& token, uint32_t tokenTime);
static uint32_t getAccountIdByPlayerName(const std::string& playerName);

static AccountType_t getAccountType(uint32_t accountId);
static void setAccountType(uint32_t accountId, AccountType_t accountType);
Expand Down

0 comments on commit 20f50a0

Please sign in to comment.