bool IOLoginData::preloadPlayer(Player* player, const std::string& name) { Database* db = Database::getInstance(); std::ostringstream query; query << "SELECT `id`, `account_id`, `group_id`, `deletion`, (SELECT `type` FROM `accounts` WHERE `accounts`.`id` = `account_id`) AS `account_type`"; if (!g_config.getBoolean(ConfigManager::FREE_PREMIUM)) { query << ", (SELECT `premdays` FROM `accounts` WHERE `accounts`.`id` = `account_id`) AS `premium_days`"; } query << " FROM `players` WHERE `name` = " << db->escapeString(name); DBResult_ptr result = db->storeQuery(query.str()); if (!result) { return false; } if (result->getDataInt("deletion") != 0) { return false; } player->setGUID(result->getDataInt("id")); Group* group = g_game.getGroup(result->getDataInt("group_id")); if (!group) { std::cout << "[Error - IOLoginData::preloadPlayer] " << player->name << " has Group ID " << result->getDataInt("group_id") << " which doesn't exist." << std::endl; return false; } player->setGroup(group); player->accountNumber = result->getNumber<uint32_t>("account_id"); player->accountType = static_cast<AccountType_t>(result->getDataInt("account_type")); if (!g_config.getBoolean(ConfigManager::FREE_PREMIUM)) { player->premiumDays = result->getDataInt("premium_days"); } else { player->premiumDays = std::numeric_limits<uint16_t>::max(); } return true; }
bool IOLoginData::getGuidByNameEx(uint32_t& guid, bool& specialVip, std::string& name) { Database* db = Database::getInstance(); std::ostringstream query; query << "SELECT `name`, `id`, `group_id`, `account_id` FROM `players` WHERE `name` = " << db->escapeString(name); DBResult_ptr result = db->storeQuery(query.str()); if (!result) { return false; } name = result->getDataString("name"); guid = result->getDataInt("id"); Group* group = g_game.getGroup(result->getDataInt("group_id")); uint64_t flags; if (group) { flags = group->flags; } else { flags = 0; } specialVip = (flags & PlayerFlag_SpecialVIP) != 0; return true; }
bool IOLoginData::loginserverAuthentication(const std::string& name, const std::string& password, Account& account) { Database* db = Database::getInstance(); std::ostringstream query; query << "SELECT `id`, `name`, `password`, `type`, `premdays`, `lastday` FROM `accounts` WHERE `name` = " << db->escapeString(name); DBResult_ptr result = db->storeQuery(query.str()); if (!result) { return false; } if (transformToSHA1(password) != result->getDataString("password")) { return false; } account.id = result->getDataInt("id"); account.name = result->getDataString("name"); account.accountType = static_cast<AccountType_t>(result->getDataInt("type")); account.premiumDays = result->getDataInt("premdays"); account.lastDay = result->getDataInt("lastday"); query.str(""); query << "SELECT `name`, `deletion` FROM `players` WHERE `account_id` = " << account.id; result = db->storeQuery(query.str()); if (result) { do { if (result->getDataInt("deletion") == 0) { account.charList.push_back(result->getDataString("name")); } } while (result->next()); account.charList.sort(); } return true; }
void IOLoginData::loadItems(ItemMap& itemMap, DBResult_ptr result) { do { int32_t sid = result->getDataInt("sid"); int32_t pid = result->getDataInt("pid"); int32_t type = result->getDataInt("itemtype"); int32_t count = result->getDataInt("count"); unsigned long attrSize; const char* attr = result->getDataStream("attributes", attrSize); PropStream propStream; propStream.init(attr, attrSize); Item* item = Item::CreateItem(type, count); if (item) { if (!item->unserializeAttr(propStream)) { std::cout << "WARNING: Serialize error in IOLoginData::loadItems" << std::endl; } std::pair<Item*, int32_t> pair(item, pid); itemMap[sid] = pair; } } while (result->next()); }
uint32_t IOLoginData::gameworldAuthentication(const std::string& accountName, const std::string& password, std::string& characterName) { Database* db = Database::getInstance(); std::ostringstream query; query << "SELECT `id`, `password` FROM `accounts` WHERE `name` = " << db->escapeString(accountName); DBResult_ptr result = db->storeQuery(query.str()); if (!result) { return 0; } if (transformToSHA1(password) != result->getDataString("password")) { return 0; } int32_t accountId = result->getDataInt("id"); query.str(""); query << "SELECT `account_id`, `name`, `deletion` FROM `players` WHERE `name` = " << db->escapeString(characterName); result = db->storeQuery(query.str()); if (!result) { return 0; } if (result->getDataInt("account_id") != accountId || result->getDataInt("deletion") != 0) { return 0; } characterName = result->getDataString("name"); return accountId; }
Account IOAccount::loadAccount(const std::string& accountName, bool preLoad /* = false*/) { Account acc; acc.name = accountName; if(g_game.onAccountLogin( acc.name, acc.number, acc.password, acc.premiumEnd, acc.warnings, acc.charList)){ //handled by script return acc; } DatabaseDriver* db = DatabaseDriver::instance(); DBQuery query; DBResult_ptr result; query << "SELECT `id`, `name`, `password`, `premend`, `warnings` FROM `accounts` WHERE `name` = " << db->escapeString(accountName); if(!(result = db->storeQuery(query))){ return acc; } acc.number = result->getDataInt("id"); acc.password = result->getDataString("password"); acc.premiumEnd = result->getDataInt("premend"); acc.name = result->getDataString("name"); acc.warnings = result->getDataInt("warnings"); if(preLoad) return acc; query.reset(); query << "SELECT " << "`players`.`name` AS `name`, `worlds`.`name` AS `world`, " << "`worlds`.`port` AS `port`, `worlds`.`ip` AS `ip`, `worlds`.`id` AS `world_id`" << "FROM `players` " << "LEFT JOIN `worlds` ON `worlds`.`id` = `players`.`world_id` " << "WHERE `account_id` = " << acc.number; for(result = db->storeQuery(query); result; result = result->advance()) { AccountCharacter c; c.name = result->getDataString("name"); c.world_name = result->getDataString("world"); c.world_id = (uint16_t)result->getDataInt("world_id"); c.port = (uint16_t)result->getDataInt("port"); c.ip = (uint32_t)result->getDataLong("ip"); acc.charList.push_back(c); } acc.charList.sort(predicateAccountCharactersByName); return acc; }
bool IOPlayer::getGuidByName(uint32_t &guid, std::string& name) { GuidCacheMap::iterator it = guidCacheMap.find(name); if(it != guidCacheMap.end()){ name = it->first; guid = it->second; return true; } DatabaseDriver* db = DatabaseDriver::instance(); DBResult_ptr result; DBQuery query; query << "SELECT `name`, `id` " "FROM `players` " "WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `name` = " << db->escapeString(name); if(!(result = db->storeQuery(query))) return false; name = result->getDataString("name"); guid = result->getDataInt("id"); guidCacheMap[name] = guid; return true; }
Account IOLoginData::loadAccount(uint32_t accno) { Account account; std::ostringstream query; query << "SELECT `id`, `name`, `password`, `type`, `premdays`, `lastday` FROM `accounts` WHERE `id` = " << accno; DBResult_ptr result = Database::getInstance()->storeQuery(query.str()); if (!result) { return account; } account.id = result->getDataInt("id"); account.name = result->getDataString("name"); account.accountType = static_cast<AccountType_t>(result->getDataInt("type")); account.premiumDays = result->getDataInt("premdays"); account.lastDay = result->getDataInt("lastday"); return account; }
void IOGuild::getWarList(uint32_t guildId, GuildWarList& guildWarList) { std::ostringstream query; query << "SELECT `guild1`, `guild2` FROM `guild_wars` WHERE (`guild1` = " << guildId << " OR `guild2` = " << guildId << ") AND `ended` = 0 AND `status` = 1"; DBResult_ptr result = Database::getInstance()->storeQuery(query.str()); if (!result) { return; } do { uint32_t guild1 = result->getDataInt("guild1"); if (guildId != guild1) { guildWarList.push_back(guild1); } else { guildWarList.push_back(result->getDataInt("guild2")); } } while (result->next()); }
AccountType_t IOLoginData::getAccountType(uint32_t accountId) { std::ostringstream query; query << "SELECT `type` FROM `accounts` WHERE `id` = " << accountId; DBResult_ptr result = Database::getInstance()->storeQuery(query.str()); if (!result) { return ACCOUNT_TYPE_NORMAL; } return static_cast<AccountType_t>(result->getDataInt("type")); }
std::forward_list<VIPEntry> IOLoginData::getVIPEntries(uint32_t accountId) { std::forward_list<VIPEntry> entries; std::ostringstream query; query << "SELECT `player_id`, (SELECT `name` FROM `players` WHERE `id` = `player_id`) AS `name`, `description`, `icon`, `notify` FROM `account_viplist` WHERE `account_id` = " << accountId; DBResult_ptr result = Database::getInstance()->storeQuery(query.str()); if (result) { do { entries.emplace_front( result->getDataInt("player_id"), result->getDataString("name"), result->getDataString("description"), result->getDataInt("icon"), result->getDataInt("notify") != 0 ); } while (result->next()); } return entries; }
bool IOLoginData::getGuidByName(uint32_t& guid, std::string& name) { Database* db = Database::getInstance(); std::ostringstream query; query << "SELECT `id`, `name` FROM `players` WHERE `name` = " << db->escapeString(name); DBResult_ptr result = db->storeQuery(query.str()); if (!result) { return false; } name = result->getDataString("name"); guid = result->getDataInt("id"); return true; }
bool IOGuild::getGuildIdByName(uint32_t& guildId, const std::string& guildName) { Database* db = Database::getInstance(); std::ostringstream query; query << "SELECT `id` FROM `guilds` WHERE `name` = " << db->escapeString(guildName); DBResult_ptr result = db->storeQuery(query.str()); if (!result) { return false; } guildId = result->getDataInt("id"); return true; }
bool IOPlayer::getDefaultTown(std::string& name, uint32_t& depotId) { DatabaseDriver* db = DatabaseDriver::instance(); DBResult_ptr result; DBQuery query; query << "SELECT `town_id` " "FROM `players` " "WHERE `players`.`world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `name`= " << db->escapeString(name); if(!(result = db->storeQuery(query))) return false; depotId = result->getDataInt("town_id"); return true; }
bool IOPlayer::getAccountByName(uint32_t& account, const std::string& name) { DatabaseDriver* db = DatabaseDriver::instance(); DBResult_ptr result; DBQuery query; query << "SELECT `account_id` " "FROM `players` " "WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `name` = " << db->escapeString(name); if(!(result = db->storeQuery(query))) return false; account = result->getDataInt("account_id"); return true; }
bool IOPlayer::getLastIP(uint32_t& ip, uint32_t guid) { DatabaseDriver* db = DatabaseDriver::instance(); DBResult_ptr result; DBQuery query; query << "SELECT `lastip` " "FROM `players` " "WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `id` = " << guid << ";"; if(!(result = db->storeQuery(query))) return false; ip = result->getDataInt("lastip"); return true; }
bool IOPlayer::getGuildIdByName(uint32_t& guildId, const std::string& guildName) { DatabaseDriver* db = DatabaseDriver::instance(); DBResult_ptr result; DBQuery query; query << "SELECT `guilds`.`id` " "FROM `guilds` " "LEFT JOIN `players` ON `players`.`id` = `guilds`.`owner_id` " "WHERE `players`.`world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `guilds`.`name` = " << db->escapeString(guildName); if(!(result = db->storeQuery(query))) return false; guildId = result->getDataInt("id"); return true; }
bool IOPlayer::getGuidByNameEx(uint32_t& guid, bool& specialVip, const std::string& player_name) { DatabaseDriver* db = DatabaseDriver::instance(); DBResult_ptr result; DBQuery query; query << "SELECT `players`.`name`, `players`.`id`, `groups`.`flags` AS `flags` " "FROM `players` LEFT JOIN `groups` ON `groups`.`id` = `players`.`group_id` " "WHERE `players`.`world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `players`.`name`= " << db->escapeString(player_name); if(!(result = db->storeQuery(query.str()))) return false; guid = result->getDataInt("id"); specialVip = (result->getDataLong("flags") & (1ull << PlayerFlag_SpecialVIP)) != 0; return true; }
DatabaseMySQL::DatabaseMySQL() { m_connected = false; // connection handle initialization if(!mysql_init(&m_handle)){ std::cout << std::endl << "Failed to initialize MySQL connection handle." << std::endl; return; } // automatic reconnect my_bool reconnect = true; mysql_options(&m_handle, MYSQL_OPT_RECONNECT, &reconnect); // connects to database if(!mysql_real_connect(&m_handle, g_config.getString(ConfigManager::SQL_HOST).c_str(), g_config.getString(ConfigManager::SQL_USER).c_str(), g_config.getString(ConfigManager::SQL_PASS).c_str(), g_config.getString(ConfigManager::SQL_DB).c_str(), g_config.getNumber(ConfigManager::SQL_PORT), NULL, 0)){ std::cout << "Failed to connect to database. MYSQL ERROR: " << mysql_error(&m_handle) << std::endl; return; } if(MYSQL_VERSION_ID < 50019){ //mySQL servers < 5.0.19 has a bug where MYSQL_OPT_RECONNECT is (incorrectly) reset by mysql_real_connect calls //See http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html for more information. mysql_options(&m_handle, MYSQL_OPT_RECONNECT, &reconnect); std::cout << std::endl << "[Warning] Outdated mySQL server detected. Consider upgrading to a newer version." << std::endl; } m_connected = true; if(g_config.getString(ConfigManager::MAP_STORAGE_TYPE) == "binary"){ DBQuery query; query << "SHOW variables LIKE 'max_allowed_packet';"; DBResult_ptr result; if((result = storeQuery(query.str()))){ int32_t max_query = result->getDataInt("Value"); if(max_query < 16777216){ std::cout << std::endl << "[Warning] max_allowed_packet might be set too low for binary map storage." << std::endl; std::cout << "Use the following query to raise max_allow_packet: " << std::endl; std::cout << "\tSET GLOBAL max_allowed_packet = 16777216;" << std::endl; } } } }
bool IOPlayer::isPlayerOnlineByAccount(uint32_t acc) { DatabaseDriver* db = DatabaseDriver::instance(); DBResult_ptr result; DBQuery query; query << "SELECT COUNT(*) AS `co` " "FROM `players` " "WHERE `players`.`online` = 1 AND `players`.`account_id` = " << acc; if(!(result = db->storeQuery(query))) return false; if(result->getDataInt("co") > 0) return true; return false; }
bool IOBan::isAccountBanned(uint32_t accountId, BanInfo& banInfo) { Database* db = Database::getInstance(); std::ostringstream query; query << "SELECT `reason`, `expires_at`, `banned_at`, `banned_by`, (SELECT `name` FROM `players` WHERE `id` = `banned_by`) AS `name` FROM `account_bans` WHERE `account_id` = " << accountId; DBResult_ptr result = db->storeQuery(query.str()); if (!result) { return false; } int64_t expiresAt = result->getNumber<int64_t>("expires_at"); if (expiresAt != 0 && time(nullptr) > expiresAt) { // Move the ban to history if it has expired query.str(""); query << "INSERT INTO `account_ban_history` (`account_id`, `reason`, `banned_at`, `expired_at`, `banned_by`) VALUES (" << accountId << ',' << db->escapeString(result->getDataString("reason")) << ',' << result->getDataInt("banned_at") << ',' << expiresAt << ',' << result->getDataInt("banned_by") << ')'; db->executeQuery(query.str()); query.str(""); query << "DELETE FROM `account_bans` WHERE `account_id` = " << accountId; db->executeQuery(query.str()); return false; } banInfo.expiresAt = expiresAt; banInfo.reason = result->getDataString("reason"); banInfo.bannedBy = result->getDataString("name"); return true; }
bool IOPlayer::loadPlayer(Player* player, const std::string& name, bool preload /*= false*/) { DatabaseDriver* db = DatabaseDriver::instance(); DBQuery query; DBResult_ptr result; query << "SELECT `players`.`id` AS `id`, `players`.`name` AS `name`, `accounts`.`name` AS `accname`, \ `account_id`, `sex`, `vocation`, `town_id`, `experience`, `level`, `maglevel`, `health`, \ `groups`.`name` AS `groupname`, `groups`.`flags` AS `groupflags`, `groups`.`access` AS `access`, \ `groups`.`maxviplist` AS `maxviplist`, `groups`.`maxdepotitems` AS `maxdepotitems`, `groups`.`violation` AS `violationaccess`, \ `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `direction`, `lookbody`, \ `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `posx`, `posy`, `posz`, `cap`, \ `lastlogin`, `lastlogout`, `lastip`, `conditions`, `skull_time`, `skull_type`, `stamina`, \ `loss_experience`, `loss_mana`, `loss_skills`, `loss_items`, `loss_containers` \ FROM `players` \ LEFT JOIN `accounts` ON `account_id` = `accounts`.`id`\ LEFT JOIN `groups` ON `groups`.`id` = `players`.`group_id` \ WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `players`.`name` = " + db->escapeString(name); if(!(result = db->storeQuery(query))){ return false; } player->setGUID(result->getDataInt("id")); player->accountId = result->getDataInt("account_id"); player->accountName = result->getDataString("accname"); player->groupName = result->getDataString("groupname"); player->accessLevel = result->getDataInt("access"); player->violationLevel = result->getDataInt("violationaccess"); player->maxDepotLimit = result->getDataInt("maxdepotitems"); player->maxVipLimit = result->getDataInt("maxviplist"); player->setFlags(result->getDataLong("groupflags")); if(preload){ //only loading basic info return true; } // Getting all player properties player->setSex((PlayerSex)result->getDataInt("sex")); player->setDirection((Direction)result->getDataInt("direction")); player->level = std::max((uint32_t)1, (uint32_t)result->getDataInt("level")); player->town = result->getDataInt("town_id"); Town* town = Towns::getInstance()->getTown(player->town); if(town){ player->masterPos = town->getTemplePosition(); } uint64_t currExpCount = Player::getExpForLevel(player->level); uint64_t nextExpCount = Player::getExpForLevel(player->level + 1); uint64_t experience = (uint64_t)result->getDataLong("experience"); if(experience < currExpCount || experience > nextExpCount){ experience = currExpCount; } player->experience = experience; player->levelPercent = Player::getPercentLevel(player->experience - currExpCount, nextExpCount - currExpCount); player->soul = result->getDataInt("soul"); player->capacity = result->getDataInt("cap"); player->stamina = result->getDataInt("stamina"); player->lastLoginSaved = result->getDataInt("lastlogin"); player->lastLogout = result->getDataInt("lastlogout"); player->health = result->getDataInt("health"); player->healthMax = result->getDataInt("healthmax"); player->defaultOutfit.lookType = result->getDataInt("looktype"); player->defaultOutfit.lookHead = result->getDataInt("lookhead"); player->defaultOutfit.lookBody = result->getDataInt("lookbody"); player->defaultOutfit.lookLegs = result->getDataInt("looklegs"); player->defaultOutfit.lookFeet = result->getDataInt("lookfeet"); player->defaultOutfit.lookAddons = result->getDataInt("lookaddons"); player->currentOutfit = player->defaultOutfit; #ifdef __SKULLSYSTEM__ SkullType skullType = SkullType(result->getDataInt("skull_type")); int64_t lastSkullTime = result->getDataLong("skull_time"); if((skullType == SKULL_RED && std::time(NULL) < lastSkullTime + g_config.getNumber(ConfigManager::RED_SKULL_DURATION)) || (skullType == SKULL_BLACK && std::time(NULL) < lastSkullTime + g_config.getNumber(ConfigManager::BLACK_SKULL_DURATION))){ player->lastSkullTime = lastSkullTime; player->skullType = skullType; } #endif unsigned long conditionsSize = 0; const char* conditions = result->getDataStream("conditions", conditionsSize); PropStream propStream; propStream.init(conditions, conditionsSize); Condition* condition; while((condition = Condition::createCondition(propStream))){ if(condition->unserialize(propStream)){ player->storedConditionList.push_back(condition); } else{ delete condition; } } // you need to set the vocation after conditions in order to ensure the proper regeneration rates for the vocation player->setVocation(result->getDataInt("vocation")); // this stuff has to go after the vocation is set player->mana = result->getDataInt("mana"); player->manaMax = result->getDataInt("manamax"); player->magLevel = result->getDataInt("maglevel"); uint32_t nextManaCount = (uint32_t)player->vocation->getReqMana(player->magLevel + 1); uint32_t manaSpent = (uint32_t)result->getDataInt("manaspent"); if(manaSpent > nextManaCount){ //make sure its not out of bound manaSpent = 0; } player->manaSpent = manaSpent; player->magLevelPercent = Player::getPercentLevel(player->manaSpent, nextManaCount); player->setLossPercent(LOSS_EXPERIENCE, result->getDataInt("loss_experience")); player->setLossPercent(LOSS_MANASPENT, result->getDataInt("loss_mana")); player->setLossPercent(LOSS_SKILLTRIES, result->getDataInt("loss_skills")); player->setLossPercent(LOSS_ITEMS, result->getDataInt("loss_items")); player->setLossPercent(LOSS_CONTAINERS, result->getDataInt("loss_containers")); player->loginPosition.x = result->getDataInt("posx"); player->loginPosition.y = result->getDataInt("posy"); player->loginPosition.z = result->getDataInt("posz"); // login position is temple position Position loginPos = player->loginPosition; if(loginPos.x == 0 && loginPos.y == 0 && loginPos.z == 0){ player->loginPosition = player->masterPos; } query.reset(); query << "SELECT " " `guild_ranks`.`name` as `rank`, `guild_ranks`.`guild_id` as `guildid`, " " `guild_ranks`.`level` as `level`, `guilds`.`name` as `guildname`, " " `guild_members`.`nick` AS `nick` " "FROM `guild_members` " "LEFT JOIN `guild_ranks` ON `guild_ranks`.`id` = `guild_members`.`rank_id` " "LEFT JOIN `guilds` ON `guilds`.`id` = `guild_ranks`.`guild_id` " "WHERE `guild_members`.`player_id` = " << player->getGUID(); if((result = db->storeQuery(query))){ player->guildName = result->getDataString("guildname"); player->guildLevel = result->getDataInt("level"); player->guildId = result->getDataInt("guildid"); player->guildRank = result->getDataString("rank"); player->guildNick = result->getDataString("nick"); } //get password query.reset(); query << "SELECT `password`, `premend` FROM `accounts` WHERE `id` = " << player->accountId; if(!(result = db->storeQuery(query))){ return false; } player->password = result->getDataString("password"); player->premiumDays = IOAccount::getPremiumDaysLeft(result->getDataInt("premend")); // we need to find out our skills // so we query the skill table query.reset(); query << "SELECT `skill_id`, `value`, `count` FROM `player_skills` WHERE `player_id` = " << player->getGUID(); for(result = db->storeQuery(query); result; result = result->advance()){ //now iterate over the skills try { SkillType skillid = SkillType::fromInteger(result->getDataInt("skill_id")); uint32_t skillLevel = result->getDataInt("value"); uint32_t skillCount = result->getDataInt("count"); uint32_t nextSkillCount = player->vocation->getReqSkillTries(skillid, skillLevel + 1); if(skillCount > nextSkillCount){ //make sure its not out of bound skillCount = 0; } player->skills[skillid.value()][SKILL_LEVEL] = skillLevel; player->skills[skillid.value()][SKILL_TRIES] = skillCount; player->skills[skillid.value()][SKILL_PERCENT] = Player::getPercentLevel(skillCount, nextSkillCount); } catch(enum_conversion_error&) { std::cout << "Unknown skill ID when loading player " << result->getDataInt("skillid") << std::endl; } } //load inventory items ItemMap itemMap; /* query.reset(); query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_items` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC"; if((result = db->storeQuery(query.str()))){ loadItems(itemMap, result); ItemMap::reverse_iterator it; ItemMap::iterator it2; for(it = itemMap.rbegin(); it != itemMap.rend(); ++it){ Item* item = it->second.first; int pid = it->second.second; if(pid >= 1 && pid <= 10){ player->__internalAddThing(pid, item); } else{ it2 = itemMap.find(pid); if(it2 != itemMap.end()) if(Container* container = it2->second.first->getContainer()){ container->__internalAddThing(item); } } } db->freeResult(result); } //load depot items itemMap.clear(); query.str(""); query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_depotitems` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC"; if((result = db->storeQuery(query.str()))){ loadItems(itemMap, result); ItemMap::reverse_iterator it; ItemMap::iterator it2; for(it = itemMap.rbegin(); it != itemMap.rend(); ++it){ Item* item = it->second.first; int pid = it->second.second; if(pid >= 0 && pid < 100){ if(Container* c = item->getContainer()){ if(Depot* depot = c->getDepot()) player->addDepot(depot, pid); else std::cout << "Error loading depot "<< pid << " for player " << player->getGUID() << std::endl; } else{ std::cout << "Error loading depot "<< pid << " for player " << player->getGUID() << std::endl; } } else{ it2 = itemMap.find(pid); if(it2 != itemMap.end()) if(Container* container = it2->second.first->getContainer()){ container->__internalAddThing(item); } } } db->freeResult(result); } */ //load storage map query.str(""); query << "SELECT `id`, `value` FROM `player_storage` WHERE `player_id` = " << player->getGUID(); for(result = db->storeQuery(query); result; result = result->advance()){ std::string key = result->getDataString("id"); std::string value = result->getDataString("value"); player->setCustomValue(key, value); } //load vips query.str(""); query << "SELECT `vip_id` FROM `player_viplist` WHERE `player_id` = " << player->getGUID(); for(result = db->storeQuery(query); result; result = result->advance()){ uint32_t vip_id = result->getDataInt("vip_id"); std::string dummy_str; if(storeNameByGuid(*db, vip_id)) player->addVIP(vip_id, dummy_str, false, true); } player->updateBaseSpeed(); player->updateInventoryWeight(); player->updateItemsLight(true); return true; }
bool IOLoginData::savePlayer(Player* player) { if (player->getHealth() <= 0) { player->changeHealth(1); } Database* db = Database::getInstance(); std::ostringstream query; query << "SELECT `save` FROM `players` WHERE `id` = " << player->getGUID(); DBResult_ptr result = db->storeQuery(query.str()); if (!result) { return false; } if (result->getDataInt("save") == 0) { query.str(""); query << "UPDATE `players` SET `lastlogin` = " << player->lastLoginSaved << ", `lastip` = " << player->lastIP << " WHERE `id` = " << player->getGUID(); return db->executeQuery(query.str()); } //serialize conditions PropWriteStream propWriteStream; for (Condition* condition : player->conditions) { if (condition->isPersistent()) { condition->serialize(propWriteStream); propWriteStream.write<uint8_t>(CONDITIONATTR_END); } } size_t conditionsSize; const char* conditions = propWriteStream.getStream(conditionsSize); //First, an UPDATE query to write the player itself query.str(""); query << "UPDATE `players` SET "; query << "`level` = " << player->level << ','; query << "`group_id` = " << player->group->id << ','; query << "`vocation` = " << player->getVocationId() << ','; query << "`health` = " << player->health << ','; query << "`healthmax` = " << player->healthMax << ','; query << "`experience` = " << player->experience << ','; query << "`lookbody` = " << static_cast<uint32_t>(player->defaultOutfit.lookBody) << ','; query << "`lookfeet` = " << static_cast<uint32_t>(player->defaultOutfit.lookFeet) << ','; query << "`lookhead` = " << static_cast<uint32_t>(player->defaultOutfit.lookHead) << ','; query << "`looklegs` = " << static_cast<uint32_t>(player->defaultOutfit.lookLegs) << ','; query << "`looktype` = " << player->defaultOutfit.lookType << ','; query << "`lookaddons` = " << static_cast<uint32_t>(player->defaultOutfit.lookAddons) << ','; query << "`maglevel` = " << player->magLevel << ','; query << "`mana` = " << player->mana << ','; query << "`manamax` = " << player->manaMax << ','; query << "`manaspent` = " << player->manaSpent << ','; query << "`soul` = " << player->soul << ','; query << "`town_id` = " << player->town->getID() << ','; const Position& loginPosition = player->getLoginPosition(); query << "`posx` = " << loginPosition.getX() << ','; query << "`posy` = " << loginPosition.getY() << ','; query << "`posz` = " << loginPosition.getZ() << ','; query << "`cap` = " << (player->capacity / 100) << ','; query << "`sex` = " << player->sex << ','; if (player->lastLoginSaved != 0) { query << "`lastlogin` = " << player->lastLoginSaved << ','; } if (player->lastIP != 0) { query << "`lastip` = " << player->lastIP << ','; } query << "`conditions` = " << db->escapeBlob(conditions, conditionsSize) << ','; if (g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED) { int32_t skullTime = 0; if (player->skullTicks > 0) { skullTime = time(nullptr) + player->skullTicks / 1000; } query << "`skulltime` = " << skullTime << ','; Skulls_t skull = SKULL_NONE; if (player->skull == SKULL_RED) { skull = SKULL_RED; } else if (player->skull == SKULL_BLACK) { skull = SKULL_BLACK; } query << "`skull` = " << static_cast<uint32_t>(skull) << ','; } query << "`lastlogout` = " << player->getLastLogout() << ','; query << "`balance` = " << player->bankBalance << ','; query << "`offlinetraining_time` = " << player->getOfflineTrainingTime() / 1000 << ','; query << "`offlinetraining_skill` = " << player->getOfflineTrainingSkill() << ','; query << "`stamina` = " << player->getStaminaMinutes() << ','; query << "`skill_fist` = " << player->skills[SKILL_FIST].level << ','; query << "`skill_fist_tries` = " << player->skills[SKILL_FIST].tries << ','; query << "`skill_club` = " << player->skills[SKILL_CLUB].level << ','; query << "`skill_club_tries` = " << player->skills[SKILL_CLUB].tries << ','; query << "`skill_sword` = " << player->skills[SKILL_SWORD].level << ','; query << "`skill_sword_tries` = " << player->skills[SKILL_SWORD].tries << ','; query << "`skill_axe` = " << player->skills[SKILL_AXE].level << ','; query << "`skill_axe_tries` = " << player->skills[SKILL_AXE].tries << ','; query << "`skill_dist` = " << player->skills[SKILL_DISTANCE].level << ','; query << "`skill_dist_tries` = " << player->skills[SKILL_DISTANCE].tries << ','; query << "`skill_shielding` = " << player->skills[SKILL_SHIELD].level << ','; query << "`skill_shielding_tries` = " << player->skills[SKILL_SHIELD].tries << ','; query << "`skill_fishing` = " << player->skills[SKILL_FISHING].level << ','; query << "`skill_fishing_tries` = " << player->skills[SKILL_FISHING].tries << ','; if (!player->isOffline()) { query << "`onlinetime` = `onlinetime` + " << (time(nullptr) - player->lastLoginSaved) << ','; } query << "`blessings` = " << static_cast<uint32_t>(player->blessings); query << " WHERE `id` = " << player->getGUID(); DBTransaction transaction; if (!transaction.begin()) { return false; } if (!db->executeQuery(query.str())) { return false; } // learned spells query.str(""); query << "DELETE FROM `player_spells` WHERE `player_id` = " << player->getGUID(); if (!db->executeQuery(query.str())) { return false; } query.str(""); DBInsert spellsQuery("INSERT INTO `player_spells` (`player_id`, `name` ) VALUES "); for (const std::string& spellName : player->learnedInstantSpellList) { query << player->getGUID() << ',' << db->escapeString(spellName); if (!spellsQuery.addRow(query)) { return false; } } if (!spellsQuery.execute()) { return false; } //item saving query << "DELETE FROM `player_items` WHERE `player_id` = " << player->getGUID(); if (!db->executeQuery(query.str())) { return false; } DBInsert itemsQuery("INSERT INTO `player_items` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES "); ItemBlockList itemList; for (int32_t slotId = 1; slotId <= 10; ++slotId) { Item* item = player->inventory[slotId]; if (item) { itemList.emplace_back(slotId, item); } } if (!saveItems(player, itemList, itemsQuery, propWriteStream)) { return false; } if (player->lastDepotId != -1) { //save depot items query.str(""); query << "DELETE FROM `player_depotitems` WHERE `player_id` = " << player->getGUID(); if (!db->executeQuery(query.str())) { return false; } DBInsert depotQuery("INSERT INTO `player_depotitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES "); itemList.clear(); for (const auto& it : player->depotChests) { DepotChest* depotChest = it.second; for (Item* item : depotChest->getItemList()) { itemList.emplace_back(it.first, item); } } if (!saveItems(player, itemList, depotQuery, propWriteStream)) { return false; } } //save inbox items query.str(""); query << "DELETE FROM `player_inboxitems` WHERE `player_id` = " << player->getGUID(); if (!db->executeQuery(query.str())) { return false; } DBInsert inboxQuery("INSERT INTO `player_inboxitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES "); itemList.clear(); for (Item* item : player->getInbox()->getItemList()) { itemList.emplace_back(0, item); } if (!saveItems(player, itemList, inboxQuery, propWriteStream)) { return false; } query.str(""); query << "DELETE FROM `player_storage` WHERE `player_id` = " << player->getGUID(); if (!db->executeQuery(query.str())) { return false; } query.str(""); DBInsert storageQuery("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES "); player->genReservedStorageRange(); for (const auto& it : player->storageMap) { query << player->getGUID() << ',' << it.first << ',' << it.second; if (!storageQuery.addRow(query)) { return false; } } if (!storageQuery.execute()) { return false; } //End the transaction return transaction.commit(); }
bool IOPlayer::savePlayer(Player* player, bool shallow) { player->preSave(); DatabaseDriver* db = DatabaseDriver::instance(); DBQuery query; DBResult_ptr result; //check if the player has to be saved or not query << "SELECT `save` FROM `players` WHERE `id` = " << player->getGUID(); if(!(result = db->storeQuery(query))){ return false; } const uint32_t save = result->getDataInt("save"); if(save == 0) return true; //serialize conditions PropWriteStream propWriteStream; for(ConditionList::const_iterator it = player->conditions.begin(); it != player->conditions.end(); ++it){ if((*it)->isPersistent()){ if(!(*it)->serialize(propWriteStream)){ return false; } propWriteStream.ADD_UCHAR(*CONDITIONATTR_END); } } uint32_t conditionsSize; const char* conditions = propWriteStream.getStream(conditionsSize); //First, an UPDATE query to write the player itself query.reset(); query << "UPDATE `players` SET `level` = " << player->level << ", `vocation` = " << (int32_t)player->getVocationId() << ", `health` = " << player->health << ", `healthmax` = " << player->healthMax << ", `direction` = " << player->getDirection().value() << ", `experience` = " << player->experience << ", `lookbody` = " << (int32_t)player->defaultOutfit.lookBody << ", `lookfeet` = " << (int32_t)player->defaultOutfit.lookFeet << ", `lookhead` = " << (int32_t)player->defaultOutfit.lookHead << ", `looklegs` = " << (int32_t)player->defaultOutfit.lookLegs << ", `looktype` = " << (int32_t)player->defaultOutfit.lookType << ", `lookaddons` = " << (int32_t)player->defaultOutfit.lookAddons << ", `maglevel` = " << player->magLevel << ", `mana` = " << player->mana << ", `manamax` = " << player->manaMax << ", `manaspent` = " << player->manaSpent << ", `soul` = " << player->soul << ", `town_id` = " << player->town << ", `posx` = " << player->getLoginPosition().x << ", `posy` = " << player->getLoginPosition().y << ", `posz` = " << player->getLoginPosition().z << ", `cap` = " << player->getCapacity() << ", `sex` = " << player->sex.value() << ", `conditions` = " << db->escapeBlob(conditions, conditionsSize) << ", `loss_experience` = " << (int32_t)player->getLossPercent(LOSS_EXPERIENCE) << ", `loss_mana` = " << (int32_t)player->getLossPercent(LOSS_MANASPENT) << ", `loss_skills` = " << (int32_t)player->getLossPercent(LOSS_SKILLTRIES) << ", `loss_items` = " << (int32_t)player->getLossPercent(LOSS_ITEMS) << ", `loss_containers` = " << (int32_t)player->getLossPercent(LOSS_CONTAINERS) << ", `stamina` = " << player->stamina; #ifdef __SKULLSYSTEM__ query << ", `skull_type` = " << (player->getSkull() == SKULL_RED || player->getSkull() == SKULL_BLACK ? player->getSkull().value() : 0); query << ", `skull_time` = " << player->lastSkullTime; #endif query << " WHERE `id` = " << player->getGUID(); DBTransaction transaction(db); if(!transaction.begin()) return false; if(!db->executeQuery(query)){ return false; } //skills for(int32_t i = 0; i <= 6; i++){ query.reset(); query << "UPDATE `player_skills` SET `value` = " << player->skills[i][SKILL_LEVEL] << ", `count` = " << player->skills[i][SKILL_TRIES] << " WHERE `player_id` = " << player->getGUID() << " AND `skill_id` = " << i; if(!db->executeQuery(query)){ return false; } } if(shallow) return transaction.commit(); // deletes all player-related stuff /* query << "DELETE FROM `player_items` WHERE `player_id` = " << player->getGUID(); if(!db->executeQuery(query.str())){ return false; } query.str(""); query << "DELETE FROM `player_depotitems` WHERE `player_id` = " << player->getGUID(); if(!db->executeQuery(query.str())){ return false; } query.str(""); */ query.reset(); query << "DELETE FROM `player_storage` WHERE `player_id` = " << player->getGUID(); if(!db->executeQuery(query)){ return false; } query.reset(); query << "DELETE FROM `player_viplist` WHERE `player_id` = " << player->getGUID(); if(!db->executeQuery(query.str())){ return false; } // Starti inserting DBInsert insert(db); /* ItemBlockList itemList; Item* item; for(int32_t slotId = 1; slotId <= 10; ++slotId){ if((item = player->inventory[slotId])){ itemList.push_back(itemBlock(slotId, item)); } } //item saving stmt.setQuery("INSERT INTO `player_items` (`player_id` , `pid` , `sid` , `itemtype` , `count` , `attributes` ) VALUES "); if(!(saveItems(player, itemList, stmt) && stmt.execute())){ return false; } itemList.clear(); for(DepotMap::iterator it = player->depots.begin(); it != player->depots.end(); ++it){ itemList.push_back(itemBlock(it->first, it->second)); } //save depot items stmt.setQuery("INSERT INTO `player_depotitems` (`player_id` , `pid` , `sid` , `itemtype` , `count` , `attributes` ) VALUES "); if(!(saveItems(player, itemList, stmt) && stmt.execute())){ return false; } */ insert.setQuery("INSERT INTO `player_storage` (`player_id` , `id` , `value` ) VALUES "); for(StorageMap::const_iterator cit = player->getCustomValueIteratorBegin(); cit != player->getCustomValueIteratorEnd();cit++){ query.reset(); query << player->getGUID() << ", " << db->escapeString(cit->first) << ", " << db->escapeString(cit->second); if(!insert.addRow(query.str())){ return false; } } if(!insert.execute()){ return false; } //save vip list if(!player->VIPList.empty()){ query.reset(); query << "INSERT INTO `player_viplist` (`player_id`, `vip_id`) SELECT " << player->getGUID() << ", `id` FROM `players` WHERE `id` IN ("; for(VIPListSet::iterator it = player->VIPList.begin(); it != player->VIPList.end(); ){ query << (*it); ++it; if(it != player->VIPList.end()){ query << ","; } else{ query << ")"; } } if(!db->executeQuery(query)){ return false; } } //End the transaction return transaction.commit(); }
bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result) { if (!result) { return false; } Database* db = Database::getInstance(); uint32_t accno = result->getDataInt("account_id"); Account acc = loadAccount(accno); player->setGUID(result->getDataInt("id")); player->name = result->getDataString("name"); player->accountNumber = accno; player->accountType = acc.accountType; if (g_config.getBoolean(ConfigManager::FREE_PREMIUM)) { player->premiumDays = std::numeric_limits<uint16_t>::max(); } else { player->premiumDays = acc.premiumDays; } Group* group = g_game.getGroup(result->getDataInt("group_id")); if (!group) { std::cout << "[Error - IOLoginData::loadPlayer] " << player->name << " has Group ID " << result->getDataInt("group_id") << " which doesn't exist." << std::endl; return false; } player->setGroup(group); player->bankBalance = result->getNumber<uint64_t>("balance"); player->setSex(static_cast<PlayerSex_t>(result->getDataInt("sex"))); player->level = std::max<uint32_t>(1, result->getDataInt("level")); uint64_t experience = result->getNumber<uint64_t>("experience"); uint64_t currExpCount = Player::getExpForLevel(player->level); uint64_t nextExpCount = Player::getExpForLevel(player->level + 1); if (experience < currExpCount || experience > nextExpCount) { experience = currExpCount; } player->experience = experience; if (currExpCount < nextExpCount) { player->levelPercent = Player::getPercentLevel(player->experience - currExpCount, nextExpCount - currExpCount); } else { player->levelPercent = 0; } player->soul = result->getDataInt("soul"); player->capacity = result->getDataInt("cap") * 100; player->blessings = result->getDataInt("blessings"); unsigned long conditionsSize; const char* conditions = result->getDataStream("conditions", conditionsSize); PropStream propStream; propStream.init(conditions, conditionsSize); Condition* condition = Condition::createCondition(propStream); while (condition) { if (condition->unserialize(propStream)) { player->storedConditionList.push_front(condition); } else { delete condition; } condition = Condition::createCondition(propStream); } if (!player->setVocation(result->getDataInt("vocation"))) { std::cout << "[Error - IOLoginData::loadPlayer] " << player->name << " has Vocation ID " << result->getDataInt("vocation") << " which doesn't exist." << std::endl; return false; } player->mana = result->getDataInt("mana"); player->manaMax = result->getDataInt("manamax"); player->magLevel = result->getDataInt("maglevel"); uint64_t nextManaCount = player->vocation->getReqMana(player->magLevel + 1); uint64_t manaSpent = result->getNumber<uint64_t>("manaspent"); if (manaSpent > nextManaCount) { manaSpent = 0; } player->manaSpent = manaSpent; player->magLevelPercent = Player::getPercentLevel(player->manaSpent, nextManaCount); player->health = result->getDataInt("health"); player->healthMax = result->getDataInt("healthmax"); player->defaultOutfit.lookType = result->getDataInt("looktype"); player->defaultOutfit.lookHead = result->getDataInt("lookhead"); player->defaultOutfit.lookBody = result->getDataInt("lookbody"); player->defaultOutfit.lookLegs = result->getDataInt("looklegs"); player->defaultOutfit.lookFeet = result->getDataInt("lookfeet"); player->defaultOutfit.lookAddons = result->getDataInt("lookaddons"); player->currentOutfit = player->defaultOutfit; if (g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED) { const int32_t skullSeconds = result->getDataInt("skulltime") - time(nullptr); if (skullSeconds > 0) { //ensure that we round up the number of ticks player->skullTicks = (skullSeconds + 2) * 1000; int32_t skull = result->getDataInt("skull"); if (skull == SKULL_RED) { player->skull = SKULL_RED; } else if (skull == SKULL_BLACK) { player->skull = SKULL_BLACK; } } } player->loginPosition.x = result->getDataInt("posx"); player->loginPosition.y = result->getDataInt("posy"); player->loginPosition.z = result->getDataInt("posz"); player->lastLoginSaved = result->getNumber<uint64_t>("lastlogin"); player->lastLogout = result->getNumber<uint64_t>("lastlogout"); player->offlineTrainingTime = result->getDataInt("offlinetraining_time") * 1000; player->offlineTrainingSkill = result->getDataInt("offlinetraining_skill"); Town* town = Towns::getInstance().getTown(result->getDataInt("town_id")); if (!town) { std::cout << "[Error - IOLoginData::loadPlayer] " << player->name << " has Town ID " << result->getDataInt("town_id") << " which doesn't exist." << std::endl; return false; } player->town = town; const Position& loginPos = player->loginPosition; if (loginPos.x == 0 && loginPos.y == 0 && loginPos.z == 0) { player->loginPosition = player->getTemplePosition(); } player->staminaMinutes = result->getDataInt("stamina"); static const std::string skillNames[] = {"skill_fist", "skill_club", "skill_sword", "skill_axe", "skill_dist", "skill_shielding", "skill_fishing"}; static const std::string skillNameTries[] = {"skill_fist_tries", "skill_club_tries", "skill_sword_tries", "skill_axe_tries", "skill_dist_tries", "skill_shielding_tries", "skill_fishing_tries"}; static const size_t size = sizeof(skillNames) / sizeof(std::string); for (uint8_t i = 0; i < size; ++i) { uint16_t skillLevel = result->getNumber<uint16_t>(skillNames[i]); uint64_t skillTries = result->getNumber<uint64_t>(skillNameTries[i]); uint64_t nextSkillTries = player->vocation->getReqSkillTries(i, skillLevel + 1); if (skillTries > nextSkillTries) { skillTries = 0; } player->skills[i].level = skillLevel; player->skills[i].tries = skillTries; player->skills[i].percent = Player::getPercentLevel(skillTries, nextSkillTries); } std::ostringstream query; query << "SELECT `guild_id`, `rank_id`, `nick` FROM `guild_membership` WHERE `player_id` = " << player->getGUID(); if ((result = db->storeQuery(query.str()))) { uint32_t guildId = result->getDataInt("guild_id"); uint32_t playerRankId = result->getDataInt("rank_id"); player->guildNick = result->getDataString("nick"); Guild* guild = g_game.getGuild(guildId); if (!guild) { query.str(""); query << "SELECT `name` FROM `guilds` WHERE `id` = " << guildId; if ((result = db->storeQuery(query.str()))) { guild = new Guild(guildId, result->getDataString("name")); g_game.addGuild(guild); query.str(""); query << "SELECT `id`, `name`, `level` FROM `guild_ranks` WHERE `guild_id` = " << guildId << " LIMIT 3"; if ((result = db->storeQuery(query.str()))) { do { guild->addRank(result->getDataInt("id"), result->getDataString("name"), result->getDataInt("level")); } while (result->next()); } } } if (guild) { player->guild = guild; GuildRank* rank = guild->getRankById(playerRankId); if (rank) { player->guildLevel = rank->level; } else { player->guildLevel = 1; } IOGuild::getWarList(guildId, player->guildWarList); query.str(""); query << "SELECT COUNT(*) AS `members` FROM `guild_membership` WHERE `guild_id` = " << guildId; if ((result = db->storeQuery(query.str()))) { guild->setMemberCount(result->getDataInt("members")); } } } query.str(""); query << "SELECT `player_id`, `name` FROM `player_spells` WHERE `player_id` = " << player->getGUID(); if ((result = db->storeQuery(query.str()))) { do { player->learnedInstantSpellList.emplace_front(result->getDataString("name")); } while (result->next()); } //load inventory items ItemMap itemMap; query.str(""); query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_items` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC"; if ((result = db->storeQuery(query.str()))) { loadItems(itemMap, result); for (ItemMap::reverse_iterator it = itemMap.rbegin(); it != itemMap.rend(); ++it) { const std::pair<Item*, int32_t>& pair = it->second; Item* item = pair.first; int32_t pid = pair.second; if (pid >= 1 && pid <= 10) { player->__internalAddThing(pid, item); } else { ItemMap::const_iterator it2 = itemMap.find(pid); if (it2 == itemMap.end()) { continue; } Container* container = it2->second.first->getContainer(); if (container) { container->__internalAddThing(item); } } } } //load depot items itemMap.clear(); query.str(""); query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_depotitems` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC"; if ((result = db->storeQuery(query.str()))) { loadItems(itemMap, result); for (ItemMap::reverse_iterator it = itemMap.rbegin(); it != itemMap.rend(); ++it) { const std::pair<Item*, int32_t>& pair = it->second; Item* item = pair.first; int32_t pid = pair.second; if (pid >= 0 && pid < 100) { if (pid == 98) { DepotChest* depotChest = player->getPokeStorage(pid, true); if (depotChest) { depotChest->__internalAddThing(item); } } else { DepotChest* depotChest = player->getDepotChest(pid, true); if (depotChest) { depotChest->__internalAddThing(item); } } } else { ItemMap::const_iterator it2 = itemMap.find(pid); if (it2 == itemMap.end()) { continue; } Container* container = it2->second.first->getContainer(); if (container) { container->__internalAddThing(item); } } } } //load inbox items itemMap.clear(); query.str(""); query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_inboxitems` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC"; if ((result = db->storeQuery(query.str()))) { loadItems(itemMap, result); for (ItemMap::reverse_iterator it = itemMap.rbegin(); it != itemMap.rend(); ++it) { const std::pair<Item*, int32_t>& pair = it->second; Item* item = pair.first; int32_t pid = pair.second; if (pid >= 0 && pid < 100) { player->getInbox()->__internalAddThing(item); } else { ItemMap::const_iterator it2 = itemMap.find(pid); if (it2 == itemMap.end()) { continue; } Container* container = it2->second.first->getContainer(); if (container) { container->__internalAddThing(item); } } } } //load storage map query.str(""); query << "SELECT `key`, `value` FROM `player_storage` WHERE `player_id` = " << player->getGUID(); if ((result = db->storeQuery(query.str()))) { do { player->addStorageValue(result->getDataInt("key"), result->getDataInt("value"), true); } while (result->next()); } //load vip query.str(""); query << "SELECT `player_id` FROM `account_viplist` WHERE `account_id` = " << player->getAccount(); if ((result = db->storeQuery(query.str()))) { do { player->addVIPInternal(result->getDataInt("player_id")); } while (result->next()); } player->updateBaseSpeed(); player->updateInventoryWeight(); player->updateItemsLight(true); return true; }