diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-09-23 22:37:15 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-09-26 18:09:32 +0200 |
commit | 73f1933f94bcadb8c3b3f9763e6afad5f02891f4 (patch) | |
tree | 6cd028fcfe3d4a8675f00d5a4a6566d62f3f679a /src/account-server/storage.cpp | |
parent | 825bc65e0328367c26bebbf68066de3800372f84 (diff) | |
download | manaserv-73f1933f94bcadb8c3b3f9763e6afad5f02891f4.tar.gz manaserv-73f1933f94bcadb8c3b3f9763e6afad5f02891f4.tar.bz2 manaserv-73f1933f94bcadb8c3b3f9763e6afad5f02891f4.tar.xz manaserv-73f1933f94bcadb8c3b3f9763e6afad5f02891f4.zip |
Store questlog values in the database
Diffstat (limited to 'src/account-server/storage.cpp')
-rw-r--r-- | src/account-server/storage.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index 91ceec94..b6268179 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -78,6 +78,7 @@ static const char *CHAR_ATTR_TBL_NAME = "mana_char_attr"; static const char *CHAR_STATUS_EFFECTS_TBL_NAME = "mana_char_status_effects"; static const char *CHAR_KILL_COUNT_TBL_NAME = "mana_char_kill_stats"; static const char *CHAR_ABILITIES_TBL_NAME = "mana_char_abilities"; +static const char *QUESTLOG_TBL_NAME = "mana_questlog"; static const char *INVENTORIES_TBL_NAME = "mana_inventories"; static const char *ITEMS_TBL_NAME = "mana_items"; static const char *GUILDS_TBL_NAME = "mana_guilds"; @@ -467,6 +468,27 @@ CharacterData *Storage::getCharacterBySQL(Account *owner) character->giveAbility(toUint(abilitiesInfo(row, 0))); } } + + // Load the questlog + s.clear(); + s.str(""); + s << "SELECT quest_id, quest_state, quest_title, quest_description " + << "FROM " << QUESTLOG_TBL_NAME + << " WHERE char_id = " << character->getDatabaseID(); + const dal::RecordSet &quests = mDb->execSql(s.str()); + if (!quests.isEmpty()) + { + const unsigned nRows = quests.rows(); + for (unsigned row = 0; row < nRows; row++) + { + QuestInfo quest; + quest.id = toUint(quests(row, 0)); + quest.state = toUint(quests(row, 1)); + quest.title = quests(row, 2); + quest.description = quests(row, 3); + character->mQuests.push_back(quest); + } + } } catch (const dal::DbSqlQueryExecFailure &e) { @@ -760,6 +782,45 @@ bool Storage::updateCharacter(CharacterData *character) "SQL query failure: ", e);; } + // Character's questlog + try + { + // Out with the old + std::ostringstream deleteSql(""); + std::ostringstream insertSql; + deleteSql << "DELETE FROM " << QUESTLOG_TBL_NAME + << " WHERE char_id='" + << character->getDatabaseID() << "';"; + mDb->execSql(deleteSql.str()); + // In with the new + for (QuestInfo &quest : character->mQuests) + { + insertSql.str(""); + insertSql << "INSERT INTO " << QUESTLOG_TBL_NAME + << " (char_id, quest_id, quest_state, " + << "quest_title, quest_description)" + << " VALUES (" + << character->getDatabaseID() << "," + << " " << quest.id << "," + << " " << quest.state << "," + << " ?," + << " ?" + << ")"; + if (mDb->prepareSql(insertSql.str())) + { + mDb->bindValue(1, quest.title); + mDb->bindValue(2, quest.description); + + mDb->processSql(); + } + } + } + catch (const dal::DbSqlQueryExecFailure& e) + { + utils::throwError("(DALStorage::updateCharacter #5) " + "SQL query failure: ", e);; + } + // Character's inventory // Delete the old inventory and equipment table first try |