Diff
checker
テキスト
テキスト
画像
ドキュメント
Excel
フォルダ
Legal
Enterprise
デスクトップ
料金
ログイン
Diffchecker デスクトップのダウンロード
テキスト比較
2 つのテキスト ファイルの違いを見つける
ツール
履歴
ライブエディター
未変更行を折りたたむ
折り返しなし
レイアウト
分割
統合
比較精度
スマート
単語
文字
シンタックスハイライト
構文を選択
無視
テキスト変換
最初の差分へ移動
入力を編集
Diffchecker Desktop
Diffcheckerを実行する最も安全な方法。Diffchecker Desktopアプリを入手:あなたの差分はコンピューターから出ることはありません!
Desktopを入手
Untitled diff
作成日
9 年前
差分は期限切れになりません
クリア
エクスポート
共有
説明
0 削除
行
合計
削除
文字
合計
削除
この機能を引き続き使用するには、アップグレードしてください
Diff
checker
Pro
価格を見る
235 行
すべてコピー
1 追加
行
合計
追加
文字
合計
追加
この機能を引き続き使用するには、アップグレードしてください
Diff
checker
Pro
価格を見る
236 行
すべてコピー
bool IOLoginData::savePlayer(Player* player)
bool IOLoginData::savePlayer(Player* player)
{
{
if (player->getHealth() <= 0) {
if (player->getHealth() <= 0) {
player->changeHealth(1);
player->changeHealth(1);
}
}
Database& db = Database::getInstance();
Database& db = Database::getInstance();
std::ostringstream query;
std::ostringstream query;
query << "SELECT `save` FROM `players` WHERE `id` = " << player->getGUID();
query << "SELECT `save` FROM `players` WHERE `id` = " << player->getGUID();
DBResult_ptr result = db.storeQuery(query.str());
DBResult_ptr result = db.storeQuery(query.str());
if (!result) {
if (!result) {
return false;
return false;
}
}
if (result->getNumber<uint16_t>("save") == 0) {
if (result->getNumber<uint16_t>("save") == 0) {
query.str(std::string());
query.str(std::string());
query << "UPDATE `players` SET `lastlogin` = " << player->lastLoginSaved << ", `lastip` = " << player->lastIP << " WHERE `id` = " << player->getGUID();
query << "UPDATE `players` SET `lastlogin` = " << player->lastLoginSaved << ", `lastip` = " << player->lastIP << " WHERE `id` = " << player->getGUID();
return db.executeQuery(query.str());
return db.executeQuery(query.str());
}
}
//serialize conditions
//serialize conditions
PropWriteStream propWriteStream;
PropWriteStream propWriteStream;
for (Condition* condition : player->conditions) {
for (Condition* condition : player->conditions) {
if (condition->isPersistent()) {
if (condition->isPersistent()) {
condition->serialize(propWriteStream);
condition->serialize(propWriteStream);
propWriteStream.write<uint8_t>(CONDITIONATTR_END);
propWriteStream.write<uint8_t>(CONDITIONATTR_END);
}
}
}
}
size_t conditionsSize;
size_t conditionsSize;
const char* conditions = propWriteStream.getStream(conditionsSize);
const char* conditions = propWriteStream.getStream(conditionsSize);
//First, an UPDATE query to write the player itself
//First, an UPDATE query to write the player itself
query.str(std::string());
query.str(std::string());
query << "UPDATE `players` SET ";
query << "UPDATE `players` SET ";
query << "`level` = " << player->level << ',';
query << "`level` = " << player->level << ',';
コピー
コピー済み
コピー
コピー済み
query << "`passivedamagebonus` = " << player->passiveDamageBonus << ',';
query << "`group_id` = " << player->group->id << ',';
query << "`group_id` = " << player->group->id << ',';
query << "`vocation` = " << player->getVocationId() << ',';
query << "`vocation` = " << player->getVocationId() << ',';
query << "`health` = " << player->health << ',';
query << "`health` = " << player->health << ',';
query << "`healthmax` = " << player->healthMax << ',';
query << "`healthmax` = " << player->healthMax << ',';
query << "`experience` = " << player->experience << ',';
query << "`experience` = " << player->experience << ',';
query << "`lookbody` = " << static_cast<uint32_t>(player->defaultOutfit.lookBody) << ',';
query << "`lookbody` = " << static_cast<uint32_t>(player->defaultOutfit.lookBody) << ',';
query << "`lookfeet` = " << static_cast<uint32_t>(player->defaultOutfit.lookFeet) << ',';
query << "`lookfeet` = " << static_cast<uint32_t>(player->defaultOutfit.lookFeet) << ',';
query << "`lookhead` = " << static_cast<uint32_t>(player->defaultOutfit.lookHead) << ',';
query << "`lookhead` = " << static_cast<uint32_t>(player->defaultOutfit.lookHead) << ',';
query << "`looklegs` = " << static_cast<uint32_t>(player->defaultOutfit.lookLegs) << ',';
query << "`looklegs` = " << static_cast<uint32_t>(player->defaultOutfit.lookLegs) << ',';
query << "`looktype` = " << player->defaultOutfit.lookType << ',';
query << "`looktype` = " << player->defaultOutfit.lookType << ',';
query << "`lookaddons` = " << static_cast<uint32_t>(player->defaultOutfit.lookAddons) << ',';
query << "`lookaddons` = " << static_cast<uint32_t>(player->defaultOutfit.lookAddons) << ',';
query << "`maglevel` = " << player->magLevel << ',';
query << "`maglevel` = " << player->magLevel << ',';
query << "`mana` = " << player->mana << ',';
query << "`mana` = " << player->mana << ',';
query << "`manamax` = " << player->manaMax << ',';
query << "`manamax` = " << player->manaMax << ',';
query << "`manaspent` = " << player->manaSpent << ',';
query << "`manaspent` = " << player->manaSpent << ',';
query << "`soul` = " << static_cast<uint16_t>(player->soul) << ',';
query << "`soul` = " << static_cast<uint16_t>(player->soul) << ',';
query << "`town_id` = " << player->town->getID() << ',';
query << "`town_id` = " << player->town->getID() << ',';
const Position& loginPosition = player->getLoginPosition();
const Position& loginPosition = player->getLoginPosition();
query << "`posx` = " << loginPosition.getX() << ',';
query << "`posx` = " << loginPosition.getX() << ',';
query << "`posy` = " << loginPosition.getY() << ',';
query << "`posy` = " << loginPosition.getY() << ',';
query << "`posz` = " << loginPosition.getZ() << ',';
query << "`posz` = " << loginPosition.getZ() << ',';
query << "`cap` = " << (player->capacity / 100) << ',';
query << "`cap` = " << (player->capacity / 100) << ',';
query << "`sex` = " << player->sex << ',';
query << "`sex` = " << player->sex << ',';
if (player->lastLoginSaved != 0) {
if (player->lastLoginSaved != 0) {
query << "`lastlogin` = " << player->lastLoginSaved << ',';
query << "`lastlogin` = " << player->lastLoginSaved << ',';
}
}
if (player->lastIP != 0) {
if (player->lastIP != 0) {
query << "`lastip` = " << player->lastIP << ',';
query << "`lastip` = " << player->lastIP << ',';
}
}
query << "`conditions` = " << db.escapeBlob(conditions, conditionsSize) << ',';
query << "`conditions` = " << db.escapeBlob(conditions, conditionsSize) << ',';
if (g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED) {
if (g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED) {
int32_t skullTime = 0;
int32_t skullTime = 0;
if (player->skullTicks > 0) {
if (player->skullTicks > 0) {
skullTime = time(nullptr) + player->skullTicks / 1000;
skullTime = time(nullptr) + player->skullTicks / 1000;
}
}
query << "`skulltime` = " << skullTime << ',';
query << "`skulltime` = " << skullTime << ',';
Skulls_t skull = SKULL_NONE;
Skulls_t skull = SKULL_NONE;
if (player->skull == SKULL_RED) {
if (player->skull == SKULL_RED) {
skull = SKULL_RED;
skull = SKULL_RED;
} else if (player->skull == SKULL_BLACK) {
} else if (player->skull == SKULL_BLACK) {
skull = SKULL_BLACK;
skull = SKULL_BLACK;
}
}
query << "`skull` = " << static_cast<uint32_t>(skull) << ',';
query << "`skull` = " << static_cast<uint32_t>(skull) << ',';
}
}
query << "`lastlogout` = " << player->getLastLogout() << ',';
query << "`lastlogout` = " << player->getLastLogout() << ',';
query << "`balance` = " << player->bankBalance << ',';
query << "`balance` = " << player->bankBalance << ',';
query << "`offlinetraining_time` = " << player->getOfflineTrainingTime() / 1000 << ',';
query << "`offlinetraining_time` = " << player->getOfflineTrainingTime() / 1000 << ',';
query << "`offlinetraining_skill` = " << player->getOfflineTrainingSkill() << ',';
query << "`offlinetraining_skill` = " << player->getOfflineTrainingSkill() << ',';
query << "`stamina` = " << player->getStaminaMinutes() << ',';
query << "`stamina` = " << player->getStaminaMinutes() << ',';
query << "`skill_fist` = " << player->skills[SKILL_FIST].level << ',';
query << "`skill_fist` = " << player->skills[SKILL_FIST].level << ',';
query << "`skill_fist_tries` = " << player->skills[SKILL_FIST].tries << ',';
query << "`skill_fist_tries` = " << player->skills[SKILL_FIST].tries << ',';
query << "`skill_club` = " << player->skills[SKILL_CLUB].level << ',';
query << "`skill_club` = " << player->skills[SKILL_CLUB].level << ',';
query << "`skill_club_tries` = " << player->skills[SKILL_CLUB].tries << ',';
query << "`skill_club_tries` = " << player->skills[SKILL_CLUB].tries << ',';
query << "`skill_sword` = " << player->skills[SKILL_SWORD].level << ',';
query << "`skill_sword` = " << player->skills[SKILL_SWORD].level << ',';
query << "`skill_sword_tries` = " << player->skills[SKILL_SWORD].tries << ',';
query << "`skill_sword_tries` = " << player->skills[SKILL_SWORD].tries << ',';
query << "`skill_axe` = " << player->skills[SKILL_AXE].level << ',';
query << "`skill_axe` = " << player->skills[SKILL_AXE].level << ',';
query << "`skill_axe_tries` = " << player->skills[SKILL_AXE].tries << ',';
query << "`skill_axe_tries` = " << player->skills[SKILL_AXE].tries << ',';
query << "`skill_dist` = " << player->skills[SKILL_DISTANCE].level << ',';
query << "`skill_dist` = " << player->skills[SKILL_DISTANCE].level << ',';
query << "`skill_dist_tries` = " << player->skills[SKILL_DISTANCE].tries << ',';
query << "`skill_dist_tries` = " << player->skills[SKILL_DISTANCE].tries << ',';
query << "`skill_shielding` = " << player->skills[SKILL_SHIELD].level << ',';
query << "`skill_shielding` = " << player->skills[SKILL_SHIELD].level << ',';
query << "`skill_shielding_tries` = " << player->skills[SKILL_SHIELD].tries << ',';
query << "`skill_shielding_tries` = " << player->skills[SKILL_SHIELD].tries << ',';
query << "`skill_fishing` = " << player->skills[SKILL_FISHING].level << ',';
query << "`skill_fishing` = " << player->skills[SKILL_FISHING].level << ',';
query << "`skill_fishing_tries` = " << player->skills[SKILL_FISHING].tries << ',';
query << "`skill_fishing_tries` = " << player->skills[SKILL_FISHING].tries << ',';
if (!player->isOffline()) {
if (!player->isOffline()) {
query << "`onlinetime` = `onlinetime` + " << (time(nullptr) - player->lastLoginSaved) << ',';
query << "`onlinetime` = `onlinetime` + " << (time(nullptr) - player->lastLoginSaved) << ',';
}
}
query << "`blessings` = " << static_cast<uint32_t>(player->blessings);
query << "`blessings` = " << static_cast<uint32_t>(player->blessings);
query << " WHERE `id` = " << player->getGUID();
query << " WHERE `id` = " << player->getGUID();
DBTransaction transaction;
DBTransaction transaction;
if (!transaction.begin()) {
if (!transaction.begin()) {
return false;
return false;
}
}
if (!db.executeQuery(query.str())) {
if (!db.executeQuery(query.str())) {
return false;
return false;
}
}
// learned spells
// learned spells
query.str(std::string());
query.str(std::string());
query << "DELETE FROM `player_spells` WHERE `player_id` = " << player->getGUID();
query << "DELETE FROM `player_spells` WHERE `player_id` = " << player->getGUID();
if (!db.executeQuery(query.str())) {
if (!db.executeQuery(query.str())) {
return false;
return false;
}
}
query.str(std::string());
query.str(std::string());
DBInsert spellsQuery("INSERT INTO `player_spells` (`player_id`, `name` ) VALUES ");
DBInsert spellsQuery("INSERT INTO `player_spells` (`player_id`, `name` ) VALUES ");
for (const std::string& spellName : player->learnedInstantSpellList) {
for (const std::string& spellName : player->learnedInstantSpellList) {
query << player->getGUID() << ',' << db.escapeString(spellName);
query << player->getGUID() << ',' << db.escapeString(spellName);
if (!spellsQuery.addRow(query)) {
if (!spellsQuery.addRow(query)) {
return false;
return false;
}
}
}
}
if (!spellsQuery.execute()) {
if (!spellsQuery.execute()) {
return false;
return false;
}
}
//item saving
//item saving
query << "DELETE FROM `player_items` WHERE `player_id` = " << player->getGUID();
query << "DELETE FROM `player_items` WHERE `player_id` = " << player->getGUID();
if (!db.executeQuery(query.str())) {
if (!db.executeQuery(query.str())) {
return false;
return false;
}
}
DBInsert itemsQuery("INSERT INTO `player_items` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES ");
DBInsert itemsQuery("INSERT INTO `player_items` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES ");
ItemBlockList itemList;
ItemBlockList itemList;
for (int32_t slotId = 1; slotId <= 10; ++slotId) {
for (int32_t slotId = 1; slotId <= 10; ++slotId) {
Item* item = player->inventory[slotId];
Item* item = player->inventory[slotId];
if (item) {
if (item) {
itemList.emplace_back(slotId, item);
itemList.emplace_back(slotId, item);
}
}
}
}
if (!saveItems(player, itemList, itemsQuery, propWriteStream)) {
if (!saveItems(player, itemList, itemsQuery, propWriteStream)) {
return false;
return false;
}
}
if (player->lastDepotId != -1) {
if (player->lastDepotId != -1) {
//save depot items
//save depot items
query.str(std::string());
query.str(std::string());
query << "DELETE FROM `player_depotitems` WHERE `player_id` = " << player->getGUID();
query << "DELETE FROM `player_depotitems` WHERE `player_id` = " << player->getGUID();
if (!db.executeQuery(query.str())) {
if (!db.executeQuery(query.str())) {
return false;
return false;
}
}
DBInsert depotQuery("INSERT INTO `player_depotitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES ");
DBInsert depotQuery("INSERT INTO `player_depotitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES ");
itemList.clear();
itemList.clear();
for (const auto& it : player->depotChests) {
for (const auto& it : player->depotChests) {
DepotChest* depotChest = it.second;
DepotChest* depotChest = it.second;
for (Item* item : depotChest->getItemList()) {
for (Item* item : depotChest->getItemList()) {
itemList.emplace_back(it.first, item);
itemList.emplace_back(it.first, item);
}
}
}
}
if (!saveItems(player, itemList, depotQuery, propWriteStream)) {
if (!saveItems(player, itemList, depotQuery, propWriteStream)) {
return false;
return false;
}
}
}
}
//save inbox items
//save inbox items
query.str(std::string());
query.str(std::string());
query << "DELETE FROM `player_inboxitems` WHERE `player_id` = " << player->getGUID();
query << "DELETE FROM `player_inboxitems` WHERE `player_id` = " << player->getGUID();
if (!db.executeQuery(query.str())) {
if (!db.executeQuery(query.str())) {
return false;
return false;
}
}
DBInsert inboxQuery("INSERT INTO `player_inboxitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES ");
DBInsert inboxQuery("INSERT INTO `player_inboxitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES ");
itemList.clear();
itemList.clear();
for (Item* item : player->getInbox()->getItemList()) {
for (Item* item : player->getInbox()->getItemList()) {
itemList.emplace_back(0, item);
itemList.emplace_back(0, item);
}
}
if (!saveItems(player, itemList, inboxQuery, propWriteStream)) {
if (!saveItems(player, itemList, inboxQuery, propWriteStream)) {
return false;
return false;
}
}
query.str(std::string());
query.str(std::string());
query << "DELETE FROM `player_storage` WHERE `player_id` = " << player->getGUID();
query << "DELETE FROM `player_storage` WHERE `player_id` = " << player->getGUID();
if (!db.executeQuery(query.str())) {
if (!db.executeQuery(query.str())) {
return false;
return false;
}
}
query.str(std::string());
query.str(std::string());
DBInsert storageQuery("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES ");
DBInsert storageQuery("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES ");
player->genReservedStorageRange();
player->genReservedStorageRange();
for (const auto& it : player->storageMap) {
for (const auto& it : player->storageMap) {
query << player->getGUID() << ',' << it.first << ',' << it.second;
query << player->getGUID() << ',' << it.first << ',' << it.second;
if (!storageQuery.addRow(query)) {
if (!storageQuery.addRow(query)) {
return false;
return false;
}
}
}
}
if (!storageQuery.execute()) {
if (!storageQuery.execute()) {
return false;
return false;
}
}
//End the transaction
//End the transaction
return transaction.commit();
return transaction.commit();
}
}
保存された差分
原文
ファイルを開く
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->getNumber<uint16_t>("save") == 0) { query.str(std::string()); 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(std::string()); 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` = " << static_cast<uint16_t>(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(std::string()); query << "DELETE FROM `player_spells` WHERE `player_id` = " << player->getGUID(); if (!db.executeQuery(query.str())) { return false; } query.str(std::string()); 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(std::string()); 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(std::string()); 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(std::string()); query << "DELETE FROM `player_storage` WHERE `player_id` = " << player->getGUID(); if (!db.executeQuery(query.str())) { return false; } query.str(std::string()); 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 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->getNumber<uint16_t>("save") == 0) { query.str(std::string()); 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(std::string()); query << "UPDATE `players` SET "; query << "`level` = " << player->level << ','; query << "`passivedamagebonus` = " << player->passiveDamageBonus << ','; 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` = " << static_cast<uint16_t>(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(std::string()); query << "DELETE FROM `player_spells` WHERE `player_id` = " << player->getGUID(); if (!db.executeQuery(query.str())) { return false; } query.str(std::string()); 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(std::string()); 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(std::string()); 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(std::string()); query << "DELETE FROM `player_storage` WHERE `player_id` = " << player->getGUID(); if (!db.executeQuery(query.str())) { return false; } query.str(std::string()); 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(); }
違いを見つける