diff options
author | Philipp Sehmisch <mana@crushnet.org> | 2010-07-09 15:21:50 +0200 |
---|---|---|
committer | Philipp Sehmisch <mana@crushnet.org> | 2010-07-09 15:22:11 +0200 |
commit | 26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2 (patch) | |
tree | 6d7ea0ebe8be228a61315f72122eed3f2f995a0b /src/account-server/storage.cpp | |
parent | 2627acefebc688d9d9733abe23ba5aae79f66ea0 (diff) | |
download | manaserv-26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2.tar.gz manaserv-26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2.tar.bz2 manaserv-26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2.tar.xz manaserv-26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2.zip |
Added LUA script bindings for manipulating the specials available to a character.
Added script call for getting the cost of a special (recharge only for now)
Deleting specials works server-sided but the client isn't informed about it properly. Specials without recharge cost don't appear for the player. Both of these features require an additional netcode message.
Reviewed-by: Freeyorp
Diffstat (limited to 'src/account-server/storage.cpp')
-rw-r--r-- | src/account-server/storage.cpp | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index 4828e055..c104b4f7 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -40,7 +40,7 @@ static const char *DEFAULT_ITEM_FILE = "items.xml"; // defines the supported db version static const char *DB_VERSION_PARAMETER = "database_version"; -static const char *SUPPORTED_DB_VERSION = "8"; +static const char *SUPPORTED_DB_VERSION = "9"; /* * MySQL specificities: @@ -72,6 +72,7 @@ static const char *CHARACTERS_TBL_NAME = "mana_characters"; static const char *CHAR_SKILLS_TBL_NAME = "mana_char_skills"; 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_SPECIALS_TBL_NAME = "mana_char_specials"; static const char *INVENTORIES_TBL_NAME = "mana_inventories"; static const char *ITEMS_TBL_NAME = "mana_items"; static const char *GUILDS_TBL_NAME = "mana_guilds"; @@ -433,11 +434,10 @@ Character *Storage::getCharacterBySQL(Account *owner) // Load the kill stats s.clear(); s.str(""); - // Load the status effect s << "select monster_id, kills FROM " << CHAR_KILL_COUNT_TBL_NAME << " WHERE char_id = " << character->getDatabaseID(); const dal::RecordSet &killsInfo = mDb->execSql(s.str()); - if (!statusInfo.isEmpty()) + if (!killsInfo.isEmpty()) { const unsigned int nRows = killsInfo.rows(); for (unsigned int row = 0; row < nRows; row++) @@ -447,6 +447,20 @@ Character *Storage::getCharacterBySQL(Account *owner) toUint(killsInfo(row, 1))); // Kills } } + // load the special status + s.clear(); + s.str(""); + s << "select special_id FROM " << CHAR_SPECIALS_TBL_NAME + << " WHERE char_id = " << character->getDatabaseID(); + const dal::RecordSet &specialsInfo = mDb->execSql(s.str()); + if (!specialsInfo.isEmpty()) + { + const unsigned int nRows = specialsInfo.rows(); + for (unsigned int row = 0; row < nRows; row++) + { + character->giveSpecial(toUint(specialsInfo(row, 0))); + } + } } catch (const dal::DbSqlQueryExecFailure &e) { @@ -729,9 +743,44 @@ bool Storage::updateCharacter(Character *character, { mDb->rollbackTransaction(); } - LOG_ERROR("(DALStorage::updateCharacter #2) SQL query failure: " << e.what()); + LOG_ERROR("(DALStorage::updateCharacter #3) SQL query failure: " << e.what()); + return false; + } + /** + * Character's special actions + */ + try + { + // out with the old + std::ostringstream deleteSql(""); + std::ostringstream insertSql; + deleteSql << "DELETE FROM " << CHAR_SPECIALS_TBL_NAME + << " WHERE char_id='" << character->getDatabaseID() << "';"; + mDb->execSql(deleteSql.str()); + // in with the new + std::map<int, Special*>::const_iterator special_it; + for (special_it = character->getSpecialBegin(); + special_it != character->getSpecialEnd(); special_it++) + { + insertSql.str(""); + insertSql << "INSERT INTO " << CHAR_SPECIALS_TBL_NAME + << " (char_id, special_id) VALUES (" + << " '" << character->getDatabaseID() << "'," + << " '" << special_it->first << "');"; + mDb->execSql(insertSql.str()); + } + } + catch (const dal::DbSqlQueryExecFailure& e) + { + // TODO: throw an exception. + if (startTransaction) + { + mDb->rollbackTransaction(); + } + LOG_ERROR("(DALStorage::updateCharacter #4) SQL query failure: " << e.what()); return false; } + /** * Character's inventory */ @@ -752,7 +801,7 @@ bool Storage::updateCharacter(Character *character, { mDb->rollbackTransaction(); } - LOG_ERROR("(DALStorage::updateCharacter #3) SQL query failure: " << e.what()); + LOG_ERROR("(DALStorage::updateCharacter #5) SQL query failure: " << e.what()); return false; } |