diff options
author | Rogier Polak <rogier.l.a.polak@gmail.com> | 2007-03-14 17:47:44 +0000 |
---|---|---|
committer | Rogier Polak <rogier.l.a.polak@gmail.com> | 2007-03-14 17:47:44 +0000 |
commit | 7ee29dd31113ea6419801e42de0e4b4a122b7aca (patch) | |
tree | d72ab243f5f378d7254d4765b3df0b46b63f5aa3 /src/account-server | |
parent | d69f5bc43d0d08f9b47465598d6b53552a252dfc (diff) | |
download | manaserv-7ee29dd31113ea6419801e42de0e4b4a122b7aca.tar.gz manaserv-7ee29dd31113ea6419801e42de0e4b4a122b7aca.tar.bz2 manaserv-7ee29dd31113ea6419801e42de0e4b4a122b7aca.tar.xz manaserv-7ee29dd31113ea6419801e42de0e4b4a122b7aca.zip |
Modified the game-server to use AbstractCharacterData, some renaming
Diffstat (limited to 'src/account-server')
-rw-r--r-- | src/account-server/accounthandler.cpp | 24 | ||||
-rw-r--r-- | src/account-server/characterdata.cpp | 8 | ||||
-rw-r--r-- | src/account-server/characterdata.hpp | 24 | ||||
-rw-r--r-- | src/account-server/dalstorage.cpp | 165 | ||||
-rw-r--r-- | src/account-server/serverhandler.cpp | 4 |
5 files changed, 117 insertions, 108 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 2b1f2ff0..fe3c64d8 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -351,8 +351,8 @@ AccountHandler::handleLoginMessage(AccountClient &computer, MessageIn &msg) charInfo.writeByte(chars[i]->getHairColor()); charInfo.writeByte(chars[i]->getLevel()); charInfo.writeShort(chars[i]->getMoney()); - for (int j = 0; j < NB_ATTRIBUTES; ++j) - charInfo.writeShort(chars[i]->getAttribute(j)); + for (int j = 0; j < NB_BASE_ATTRIBUTES; ++j) + charInfo.writeShort(chars[i]->getBaseAttribute(j)); computer.send(charInfo); } return; @@ -620,8 +620,8 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, // LATER_ON: Add race, face and maybe special attributes. // Customization of character's attributes... - unsigned short attributes[NB_ATTRIBUTES]; - for (int i = 0; i < NB_ATTRIBUTES; ++i) + unsigned short attributes[NB_BASE_ATTRIBUTES]; + for (int i = 0; i < NB_BASE_ATTRIBUTES; ++i) attributes[i] = msg.readShort(); // We see if the difference between the lowest stat and the highest @@ -630,7 +630,7 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, unsigned short highestAttribute = 0; // start value unsigned int totalAttributes = 0; bool validNonZeroAttributes = true; - for (int i = 0; i < NB_ATTRIBUTES; ++i) + for (int i = 0; i < NB_BASE_ATTRIBUTES; ++i) { // For good total attributes check. totalAttributes += attributes[i]; @@ -663,8 +663,8 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, else { CharacterPtr newCharacter(new CharacterData(name)); - for (int i = 0; i < NB_ATTRIBUTES; ++i) - newCharacter->setAttribute(i, attributes[i]); + for (int i = 0; i < NB_BASE_ATTRIBUTES; ++i) + newCharacter->setBaseAttribute(i, attributes[i]); newCharacter->setMoney(0); newCharacter->setLevel(1); newCharacter->setGender(gender); @@ -673,7 +673,7 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, newCharacter->setMapId((int) config.getValue("defaultMap", 1)); Point startingPos((int) config.getValue("startX", 0), (int) config.getValue("startY", 0)); - newCharacter->setPos(startingPos); + newCharacter->setPosition(startingPos); computer.getAccount()->addCharacter(newCharacter); LOG_INFO("Character " << name << " was created for " @@ -693,8 +693,8 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, charInfo.writeByte(chars[slot]->getHairColor()); charInfo.writeByte(chars[slot]->getLevel()); charInfo.writeShort(chars[slot]->getMoney()); - for (int j = 0; j < NB_ATTRIBUTES; ++j) - charInfo.writeShort(chars[slot]->getAttribute(j)); + for (int j = 0; j < NB_BASE_ATTRIBUTES; ++j) + charInfo.writeShort(chars[slot]->getBaseAttribute(j)); computer.send(charInfo); return; } @@ -749,9 +749,9 @@ handleReconnectedAccount(AccountClient &computer, int accountID) charInfo.writeByte(chars[i]->getLevel()); charInfo.writeShort(chars[i]->getMoney()); - for (int j = 0; j < NB_ATTRIBUTES; ++j) + for (int j = 0; j < NB_BASE_ATTRIBUTES; ++j) { - charInfo.writeShort(chars[i]->getAttribute(j)); + charInfo.writeShort(chars[i]->getBaseAttribute(j)); } computer.send(charInfo); } diff --git a/src/account-server/characterdata.cpp b/src/account-server/characterdata.cpp index 50d1562e..95b5e75a 100644 --- a/src/account-server/characterdata.cpp +++ b/src/account-server/characterdata.cpp @@ -28,9 +28,9 @@ CharacterData::CharacterData(std::string const &name, int id): mDatabaseID(id), mAccountID(-1), mName(name), mGender(0), mHairStyle(0), mHairColor(0), mLevel(0), mMoney(0), mMapId(0), mPos(0,0) { - for (int i = 0; i < NB_ATTRIBUTES; ++i) + for (int i = 0; i < NB_BASE_ATTRIBUTES; ++i) { - mAttributes[i] = 0; + mBaseAttributes[i] = 0; } } @@ -38,9 +38,9 @@ CharacterData::CharacterData(MessageIn & msg): mDatabaseID(-1), mAccountID(-1), mName(""), mGender(0), mHairStyle(0), mHairColor(0), mLevel(0), mMoney(0), mMapId(0), mPos(0,0) { - for (int i = 0; i < NB_ATTRIBUTES; ++i) + for (int i = 0; i < NB_BASE_ATTRIBUTES; ++i) { - mAttributes[i] = 0; + mBaseAttributes[i] = 0; } deserialize(msg); } diff --git a/src/account-server/characterdata.hpp b/src/account-server/characterdata.hpp index 8911cb21..4122bdbe 100644 --- a/src/account-server/characterdata.hpp +++ b/src/account-server/characterdata.hpp @@ -17,14 +17,14 @@ * with The Mana World; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id$ + * $Id$ */ #ifndef _TMWSERV_CHARACTERDATA #define _TMWSERV_CHARACTERDATA #include "abstractcharacterdata.hpp" - +#include "defines.h" #include <string> #include <vector> @@ -43,7 +43,7 @@ class CharacterData: public AbstractCharacterData /** * Constructor used for creating a character from a serialised message. */ - CharacterData(MessageIn &); + CharacterData(MessageIn & msg); /** * Get and set methods @@ -113,15 +113,15 @@ class CharacterData: public AbstractCharacterData void setMoney(int amount) { mMoney = amount; } - /** Gets the value of an attribute of the character. */ + /** Gets the value of a base attribute of the character. */ unsigned short - getAttribute(int attributeNumber) const - { return mAttributes[attributeNumber]; } + getBaseAttribute(int attributeNumber) const + { return mBaseAttributes[attributeNumber]; } - /** Sets the value of an attribute of the character. */ + /** Sets the value of a base attribute of the character. */ void - setAttribute(int attributeNumber, int value) - { mAttributes[attributeNumber] = value; } + setBaseAttribute(int attributeNumber, int value) + { mBaseAttributes[attributeNumber] = value; } /** Gets the Id of the map that the character is on. */ int @@ -133,11 +133,11 @@ class CharacterData: public AbstractCharacterData /** Gets the position of the character on the map. */ Point const & - getPos() const { return mPos; } + getPosition() const { return mPos; } /** Sets the position of the character on the map. */ void - setPos(const Point &p) { mPos = p; } + setPosition(const Point &p) { mPos = p; } /** Returns the number of inventory items. */ int @@ -169,7 +169,7 @@ class CharacterData: public AbstractCharacterData unsigned char mHairColor; //!< Hair Color of the being. unsigned char mLevel; //!< Level of the being. unsigned int mMoney; //!< Wealth of the being. - unsigned short mAttributes[NB_ATTRIBUTES]; //!< The attributes of the + unsigned short mBaseAttributes[NB_BASE_ATTRIBUTES]; //!< The attributes of the //!< character. unsigned short mMapId; //!< Map the being is on. Point mPos; //!< Position the being is at. diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp index cd63473c..0df47d86 100644 --- a/src/account-server/dalstorage.cpp +++ b/src/account-server/dalstorage.cpp @@ -170,10 +170,11 @@ DALStorage::open(void) createTable(CHANNELS_TBL_NAME, SQL_CHANNELS_TABLE); } catch (const DbConnectionFailure& e) { - LOG_ERROR("Unable to connect to the database: " << e.what()); + LOG_ERROR("(DALStorage::open #1) Unable to connect to the database: " + << e.what()); } catch (const DbSqlQueryExecFailure& e) { - LOG_ERROR("SQL query failure: " << e.what()); + LOG_ERROR("(DALStorage::open #2) SQL query failure: " << e.what()); } mIsOpen = mDb->isConnected(); @@ -391,7 +392,8 @@ CharacterPtr DALStorage::getCharacter(int id) // a string to an unsigned short. string_to< unsigned short > toUshort; - CharacterData *character = new CharacterData(charInfo(0, 2), toUint(charInfo(0, 0))); + CharacterData *character = new CharacterData(charInfo(0, 2), + toUint(charInfo(0, 0))); character->setAccountID(toUint(charInfo(0, 1))); character->setGender(toUshort(charInfo(0, 3))); character->setHairStyle(toUshort(charInfo(0, 4))); @@ -399,10 +401,10 @@ CharacterPtr DALStorage::getCharacter(int id) character->setLevel(toUshort(charInfo(0, 6))); character->setMoney(toUint(charInfo(0, 7))); Point pos(toUshort(charInfo(0, 8)), toUshort(charInfo(0, 9))); - character->setPos(pos); - for (int i = 0; i < NB_ATTRIBUTES; ++i) + character->setPosition(pos); + for (int i = 0; i < NB_BASE_ATTRIBUTES; ++i) { - character->setAttribute(i, toUshort(charInfo(0, 11 + i))); + character->setBaseAttribute(i, toUshort(charInfo(0, 11 + i))); } int mapId = toUint(charInfo(0, 10)); @@ -458,7 +460,7 @@ DALStorage::getEmailList() } catch (const dal::DbSqlQueryExecFailure& e) { // TODO: throw an exception. - LOG_ERROR("SQL query failure: " << e.what()); + LOG_ERROR("(DALStorage::getEmailList) SQL query failure: " << e.what()); } return emailList; @@ -485,7 +487,7 @@ bool DALStorage::doesEmailAddressExist(std::string const &email) return iReturn != 0; } catch (std::exception const &e) { // TODO: throw an exception. - LOG_ERROR("SQL query failure: " << e.what()); + LOG_ERROR("(DALStorage::doesEmailAddressExist) SQL query failure: " << e.what()); } return true; @@ -512,7 +514,8 @@ bool DALStorage::doesCharacterNameExist(const std::string& name) return iReturn != 0; } catch (std::exception const &e) { // TODO: throw an exception. - LOG_ERROR("SQL query failure: " << e.what()); + LOG_ERROR("(DALStorage::doesCharacterNameExist) SQL query failure: " + << e.what()); } return true; @@ -524,54 +527,55 @@ DALStorage::updateCharacter(CharacterPtr character) // If not opened already open(); - //Character data (see CharacterData for details) + // Update the database Character data (see CharacterData for details) try { std::ostringstream sqlUpdateCharacterInfo; sqlUpdateCharacterInfo << "update " << CHARACTERS_TBL_NAME << " " - << "set" - << "gender = " << character->getGender() - << ", " - << "hair_style = " << (int)character->getHairStyle() - << ", " - << "hair_color = " << (int)character->getHairColor() - << ", " - << "level = " << (int)character->getLevel() - << ", " - << "money = " << character->getMoney() - << ", " - << "x = " << character->getPos().x - << ", " - << "y = " << character->getPos().y - << ", " - << "map_id = " << character->getMapId() - << ", " - << "str = " << character->getAttribute(ATT_STRENGTH) - << ", " - << "agi = " << character->getAttribute(ATT_AGILITY) - << ", " - << "vit = " << character->getAttribute(ATT_VITALITY) - << ", " + << "set " + << "gender = '" << character->getGender() + << "', " + << "hair_style = '" << (int)character->getHairStyle() + << "', " + << "hair_color = '" << (int)character->getHairColor() + << "', " + << "level = '" << (int)character->getLevel() + << "', " + << "money = '" << character->getMoney() + << "', " + << "x = '" << character->getPosition().x + << "', " + << "y = '" << character->getPosition().y + << "', " + << "map_id = '" << character->getMapId() + << "', " + << "str = '" << character->getBaseAttribute(ATT_STRENGTH) + << "', " + << "agi = '" << character->getBaseAttribute(ATT_AGILITY) + << "', " + << "vit = '" << character->getBaseAttribute(ATT_VITALITY) + << "', " #if defined(MYSQL_SUPPORT) || defined(POSTGRESQL_SUPPORT) - << "`int` = " + << "`int` = '" #else - << "int = " + << "int = '" #endif - << character->getAttribute(ATT_INTELLIGENCE) - << ", " - << "dex = " << character->getAttribute(ATT_DEXTERITY) - << ", " - << "luck = " << character->getAttribute(ATT_LUCK) - << "where id = " << character->getDatabaseID() - << ";"; + << character->getBaseAttribute(ATT_INTELLIGENCE) + << "', " + << "dex = '" << character->getBaseAttribute(ATT_DEXTERITY) + << "', " + << "luck = '" << character->getBaseAttribute(ATT_LUCK) + << "' " + << "where id = '" << character->getDatabaseID() + << "';"; mDb->execSql(sqlUpdateCharacterInfo.str()); } catch (const dal::DbSqlQueryExecFailure& e) { // TODO: throw an exception. - LOG_ERROR("SQL query failure: " << e.what()); + LOG_ERROR("(DALStorage::updateCharacter #1) SQL query failure: " << e.what()); return false; } @@ -584,30 +588,30 @@ DALStorage::updateCharacter(CharacterPtr character) { std::ostringstream sqlDeleteCharacterInventory; sqlDeleteCharacterInventory - << "delete * from " << INVENTORIES_TBL_NAME - << "where owner_id = " << character->getDatabaseID() << ";"; - + << "delete from " << INVENTORIES_TBL_NAME + << " where owner_id = '" << character->getDatabaseID() << "';"; mDb->execSql(sqlDeleteCharacterInventory.str()); } catch (const dal::DbSqlQueryExecFailure& e) { // TODO: throw an exception. - LOG_ERROR("SQL query failure: " << e.what()); + LOG_ERROR("(DALStorage::updateCharacter #2) SQL query failure: " << e.what()); return false; } // Insert the new inventory data - try + if (character->getNumberOfInventoryItems()) { - if (character->getNumberOfInventoryItems()) + try { std::ostringstream sqlInsertCharacterInventory; + sqlInsertCharacterInventory << "insert into " << INVENTORIES_TBL_NAME - << "(owner_id, class_id, amount, equipped) " + << " (owner_id, class_id, amount, equipped) " << "values "; - for (int j = 0; ; ) + for (int j = 0; j < character->getNumberOfInventoryItems(); j++) { sqlInsertCharacterInventory << "(" << character->getDatabaseID() << ", " @@ -615,21 +619,23 @@ DALStorage::updateCharacter(CharacterPtr character) << character->getInventoryItem(j).numberOfItemsInSlot << ", " << (unsigned short) - character->getInventoryItem(j).isEquiped + character->getInventoryItem(j).isEquiped << ")"; + // Adding the comma only if it's needed - if (++j < character->getNumberOfInventoryItems()) - sqlInsertCharacterInventory << ", "; + if (j < (character->getNumberOfInventoryItems() - 1)) + sqlInsertCharacterInventory << ", "; } + sqlInsertCharacterInventory << ";"; mDb->execSql(sqlInsertCharacterInventory.str()); } - } - catch (const dal::DbSqlQueryExecFailure& e) - { - // TODO: throw an exception. - LOG_ERROR("SQL query failure: " << e.what()); - return false; + catch (const dal::DbSqlQueryExecFailure& e) + { + // TODO: throw an exception. + LOG_ERROR("(DALStorage::updateCharacter #3) SQL query failure: " << e.what()); + return false; + } } return true; } @@ -677,7 +683,7 @@ DALStorage::getChannelList() } catch (const dal::DbSqlQueryExecFailure& e) { // TODO: throw an exception. - LOG_ERROR("SQL query failure: " << e.what()); + LOG_ERROR("(DALStorage::getChannelList) SQL query failure: " << e.what()); } return channels; @@ -734,7 +740,7 @@ DALStorage::updateChannels(std::map<short, ChatChannel>& channelList) } catch (const dal::DbSqlQueryExecFailure& e) { // TODO: throw an exception. - LOG_ERROR("SQL query failure: " << e.what()); + LOG_ERROR("(DALStorage::updateChannels) SQL query failure: " << e.what()); } } @@ -865,15 +871,15 @@ void DALStorage::flush(AccountPtr const &account) << (int)(*it)->getHairColor() << ", " << (int)(*it)->getLevel() << ", " << (*it)->getMoney() << ", " - << (*it)->getPos().x << ", " - << (*it)->getPos().y << ", " + << (*it)->getPosition().x << ", " + << (*it)->getPosition().y << ", " << (*it)->getMapId() << ", " - << (*it)->getAttribute(ATT_STRENGTH) << ", " - << (*it)->getAttribute(ATT_AGILITY) << ", " - << (*it)->getAttribute(ATT_VITALITY) << ", " - << (*it)->getAttribute(ATT_INTELLIGENCE) << ", " - << (*it)->getAttribute(ATT_DEXTERITY) << ", " - << (*it)->getAttribute(ATT_LUCK) << ");"; + << (*it)->getBaseAttribute(ATT_STRENGTH) << ", " + << (*it)->getBaseAttribute(ATT_AGILITY) << ", " + << (*it)->getBaseAttribute(ATT_VITALITY) << ", " + << (*it)->getBaseAttribute(ATT_INTELLIGENCE) << ", " + << (*it)->getBaseAttribute(ATT_DEXTERITY) << ", " + << (*it)->getBaseAttribute(ATT_LUCK) << ");"; mDb->execSql(sqlInsertCharactersTable.str()); } else { @@ -886,19 +892,20 @@ void DALStorage::flush(AccountPtr const &account) << " hair_color = " << (int)(*it)->getHairColor() << ", " << " level = " << (int)(*it)->getLevel() << ", " << " money = " << (*it)->getMoney() << ", " - << " x = " << (*it)->getPos().x << ", " - << " y = " << (*it)->getPos().y << ", " + << " x = " << (*it)->getPosition().x << ", " + << " y = " << (*it)->getPosition().y << ", " << " map_id = " << (*it)->getMapId() << ", " - << " str = " << (*it)->getAttribute(ATT_STRENGTH) << ", " - << " agi = " << (*it)->getAttribute(ATT_AGILITY) << ", " - << " vit = " << (*it)->getAttribute(ATT_VITALITY) << ", " + << " str = " << (*it)->getBaseAttribute(ATT_STRENGTH) << ", " + << " agi = " << (*it)->getBaseAttribute(ATT_AGILITY) << ", " + << " vit = " << (*it)->getBaseAttribute(ATT_VITALITY) << ", " #if defined(MYSQL_SUPPORT) || defined(POSTGRESQL_SUPPORT) - << " `int` = " << (*it)->getAttribute(ATT_INTELLIGENCE) << ", " + << " `int` = " #else - << " int = " << (*it)->getAttribute(ATT_INTELLIGENCE) << ", " + << " int = " #endif - << " dex = " << (*it)->getAttribute(ATT_DEXTERITY) << ", " - << " luck = " << (*it)->getAttribute(ATT_LUCK) + << (*it)->getBaseAttribute(ATT_INTELLIGENCE) << ", " + << " dex = " << (*it)->getBaseAttribute(ATT_DEXTERITY) << ", " + << " luck = " << (*it)->getBaseAttribute(ATT_LUCK) << " where id = " << (*it)->getDatabaseID() << ";"; mDb->execSql(sqlUpdateCharactersTable.str()); diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index d2159d44..53cc53f5 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -125,7 +125,9 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) case GAMSG_PLAYER_DATA: { LOG_DEBUG("GAMSG_PLAYER_DATA"); - + // TODO: Store it in memory, only update the database when needed. + // That should get rid of the + // no_update_on_switch_character_bug as well. Storage &store = Storage::instance("tmw"); CharacterPtr ptr(new CharacterData(msg)); |