diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-09-09 02:35:25 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-09-09 02:36:30 +0200 |
commit | 6ae2001e91eaaeb8b72031e96f88820711bb1ca0 (patch) | |
tree | 8ab01e1d9e59860837560e6cd8bbd7eabaa428de /src/account-server/storage.cpp | |
parent | 40a31c52aebc19221cc9da8a0f764d21e672937b (diff) | |
download | manaserv-6ae2001e91eaaeb8b72031e96f88820711bb1ca0.tar.gz manaserv-6ae2001e91eaaeb8b72031e96f88820711bb1ca0.tar.bz2 manaserv-6ae2001e91eaaeb8b72031e96f88820711bb1ca0.tar.xz manaserv-6ae2001e91eaaeb8b72031e96f88820711bb1ca0.zip |
Add persistent items support based on seeseekey's work.
Also made some random changes where useful, including:
- Code formatting fixes,
- Design fix about the fact that only the game config option
should be checked.
- Fixed the size of the values sent and receive to follow
the rest of the development.
- Fixed variables names to make them show what they are,
and not why they are used.
Resolves: Mana-Mantis #142.
Diffstat (limited to 'src/account-server/storage.cpp')
-rw-r--r-- | src/account-server/storage.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index 4f22964b..a1d1694b 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -24,6 +24,7 @@ #include "account-server/storage.h" #include "account-server/account.h" +#include "account-server/flooritem.h" #include "chat-server/chatchannel.h" #include "chat-server/guild.h" #include "chat-server/post.h" @@ -90,6 +91,7 @@ static const char *AUCTION_TBL_NAME = "mana_auctions"; static const char *AUCTION_BIDS_TBL_NAME = "mana_auction_bids"; static const char *ONLINE_USERS_TBL_NAME = "mana_online_list"; static const char *TRANSACTION_TBL_NAME = "mana_transactions"; +static const char *FLOOR_ITEMS_TBL_NAME = "mana_floor_items"; Storage::Storage() : mDb(dal::DataProviderFactory::createDataProvider()), @@ -138,6 +140,15 @@ void Storage::open() std::ostringstream sql; sql << "DELETE FROM " << ONLINE_USERS_TBL_NAME; mDb->execSql(sql.str()); + + // In case where the server shouldn't keep floor item in database, + // we remove remnants at startup + if (Configuration::getValue("game_floorItemDecayTime", 0) > 0) + { + sql.clear(); + sql << "DELETE FROM " << FLOOR_ITEMS_TBL_NAME; + mDb->execSql(sql.str()); + } } catch (const DbConnectionFailure& e) { @@ -1376,6 +1387,82 @@ void Storage::removeGuildMember(int guildId, int memberId) } } +void Storage::addFloorItem(int mapId, int itemId, int amount, + int posX, int posY) +{ + try + { + std::ostringstream sql; + sql << "INSERT INTO " << FLOOR_ITEMS_TBL_NAME + << " (map_id, item_id, amount, pos_x, pos_y)" + << " VALUES (" + << mapId << ", " + << itemId << ", " + << amount << ", " + << posX << ", " + << posY << ");"; + mDb->execSql(sql.str()); + } + catch (const dal::DbSqlQueryExecFailure& e) + { + utils::throwError("(DALStorage::addFloorItem) SQL query failure: ", e); + } +} + +void Storage::removeFloorItem(int mapId, int itemId, int amount, + int posX, int posY) +{ + try + { + std::ostringstream sql; + sql << "DELETE FROM " << FLOOR_ITEMS_TBL_NAME + << " WHERE map_id = " + << mapId << " AND item_id = " + << itemId << " AND amount = " + << amount << " AND pos_x = " + << posX << " AND pos_y = " + << posY << ";"; + mDb->execSql(sql.str()); + } + catch (const dal::DbSqlQueryExecFailure& e) + { + utils::throwError("(DALStorage::removeFloorItem) SQL query failure: ", + e); + } +} + +std::list<FloorItem> Storage::getFloorItemsFromMap(int mapId) +{ + std::list<FloorItem> floorItems; + + try + { + std::ostringstream sql; + sql << "SELECT * FROM " << FLOOR_ITEMS_TBL_NAME + << " WHERE map_id = " << mapId; + + string_to< unsigned > toUint; + const dal::RecordSet &itemInfo = mDb->execSql(sql.str()); + if (!itemInfo.isEmpty()) + { + for (int k = 0, size = itemInfo.rows(); k < size; ++k) + { + floorItems.push_back(FloorItem(toUint(itemInfo(k, 2)), + toUint(itemInfo(k, 3)), + toUint(itemInfo(k, 4)), + toUint(itemInfo(k, 5)))); + } + } + } + catch (const dal::DbSqlQueryExecFailure &e) + { + utils::throwError("DALStorage::getFloorItemsFromMap " + "SQL query failure: ", e); + } + + return floorItems; +} + void Storage::setMemberRights(int guildId, int memberId, int rights) { try |