summaryrefslogtreecommitdiff
path: root/src/account-server
diff options
context:
space:
mode:
authorChuck Miller <shadowmil@gmail.com>2009-10-01 00:26:38 -0400
committerChuck Miller <shadowmil@gmail.com>2009-10-01 09:22:40 -0400
commitf5fdb19e7aac292cca31ec23250587e0d97d0ff6 (patch)
treec0b9aa0ad1040fce1e3ab601aee7bcb489a3d343 /src/account-server
parent54217640c85a97341df7395a9acc39a0b819692d (diff)
downloadmanaserv-f5fdb19e7aac292cca31ec23250587e0d97d0ff6.tar.gz
manaserv-f5fdb19e7aac292cca31ec23250587e0d97d0ff6.tar.bz2
manaserv-f5fdb19e7aac292cca31ec23250587e0d97d0ff6.tar.xz
manaserv-f5fdb19e7aac292cca31ec23250587e0d97d0ff6.zip
Adds code for saving and getting status effects from the database
Diffstat (limited to 'src/account-server')
-rw-r--r--src/account-server/character.hpp16
-rw-r--r--src/account-server/dalstorage.cpp77
-rw-r--r--src/account-server/dalstorage.hpp8
3 files changed, 101 insertions, 0 deletions
diff --git a/src/account-server/character.hpp b/src/account-server/character.hpp
index d38d0211..32d8a8a6 100644
--- a/src/account-server/character.hpp
+++ b/src/account-server/character.hpp
@@ -125,6 +125,21 @@ class Character
{ mExperience[skill] += value; }
/**
+ * Get / Set a status effects
+ */
+ void applyStatusEffect(int id, int time)
+ { mStatusEffects[id] = time; }
+
+ int getStatusEffectSize() const
+ { return mStatusEffects.size(); }
+
+ const std::map<int, int>::const_iterator getStatusEffectBegin() const
+ { return mStatusEffects.begin(); }
+
+ const std::map<int, int>::const_iterator getStatusEffectEnd() const
+ { return mStatusEffects.end(); }
+
+ /**
* Gets the Id of the map that the character is on.
*/
int getMapId() const { return mMapId; }
@@ -180,6 +195,7 @@ class Character
Point mPos; //!< Position the being is at.
unsigned short mAttributes[CHAR_ATTR_NB]; //!< Attributes.
std::map<int, int> mExperience; //!< Skill Experience.
+ std::map<int, int> mStatusEffects; //!< Status Effects
unsigned short mMapId; //!< Map the being is on.
unsigned char mGender; //!< Gender of the being.
unsigned char mHairStyle; //!< Hair style of the being.
diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp
index 4628eca5..1f71d40c 100644
--- a/src/account-server/dalstorage.cpp
+++ b/src/account-server/dalstorage.cpp
@@ -314,6 +314,22 @@ Character *DALStorage::getCharacterBySQL(Account *owner)
toUint(skillInfo(row, 1))); // experience
}
}
+ s.clear();
+ s.str("");
+ // Load the status effect
+ s << "select status_id, status_time FROM " << CHAR_STATUS_EFFECTS_TBL_NAME
+ << " WHERE char_id = " << character->getDatabaseID();
+ const dal::RecordSet &statusInfo = mDb->execSql(s.str());
+ if (!statusInfo.isEmpty())
+ {
+ const unsigned int nRows = statusInfo.rows();
+ for (unsigned int row = 0; row < nRows; row++)
+ {
+ character->applyStatusEffect(
+ toUint(statusInfo(row, 0)), // Statusid
+ toUint(statusInfo(row, 1))); // Time
+ }
+ }
}
catch (const dal::DbSqlQueryExecFailure &e)
{
@@ -670,6 +686,48 @@ bool DALStorage::updateCharacter(Character *character,
return false;
}
+ /**
+ * Update char status effects
+ */
+ try
+ {
+ // Delete the old status effects first
+ std::ostringstream sql;
+
+ sql << "delete from " << CHAR_STATUS_EFFECTS_TBL_NAME
+ << " where char_id = '" << character->getDatabaseID() << "';";
+
+ mDb->execSql(sql.str());
+ }
+ catch (const dal::DbSqlQueryExecFailure& e)
+ {
+ // TODO: throw an exception.
+ if (startTransaction)
+ {
+ mDb->rollbackTransaction();
+ }
+ LOG_ERROR("(DALStorage::updateCharacter #5) SQL query failure: " << e.what());
+ return false;
+ }
+ try
+ {
+ std::map<int, int>::const_iterator status_it;
+ for (status_it = character->getStatusEffectBegin();
+ status_it != character->getStatusEffectEnd(); status_it++)
+ {
+ insertStatusEffect(character->getDatabaseID(), status_it->first, status_it->second);
+ }
+ }
+ catch (const dal::DbSqlQueryExecFailure& e)
+ {
+ // TODO: throw an exception
+ if (startTransaction)
+ {
+ mDb->rollbackTransaction();
+ }
+ LOG_ERROR("(DALStorage::updateCharacter #6) SQL query failure: " << e.what());
+ return false;
+ }
if (startTransaction)
{
mDb->commitTransaction();
@@ -972,6 +1030,25 @@ void DALStorage::updateExperience(const int CharId, const int SkillId,
}
}
+void DALStorage::insertStatusEffect(const int charId, const int statusId, const int time)
+{
+ try
+ {
+ std::ostringstream sql;
+
+ sql << "insert into " << CHAR_STATUS_EFFECTS_TBL_NAME
+ << " (char_id, status_id, status_time) VALUES ( "
+ << charId << ", "
+ << statusId << ", "
+ << time << ")";
+ mDb->execSql(sql.str());
+ }
+ catch (const dal::DbSqlQueryExecFailure &e)
+ {
+ LOG_ERROR("DALStorage::insertStatusEffect: " << e.what());
+ throw;
+ }
+}
/**
diff --git a/src/account-server/dalstorage.hpp b/src/account-server/dalstorage.hpp
index 77222377..36bb1e39 100644
--- a/src/account-server/dalstorage.hpp
+++ b/src/account-server/dalstorage.hpp
@@ -147,6 +147,14 @@ class DALStorage
const int SkillValue);
/**
+ * Inserts a record about a status effect into the database
+ * @param charId ID of the character in the database
+ * @param statusId ID of the status effect
+ * @param time Time left on the status effect
+ */
+ void insertStatusEffect(const int charId, const int statusId, const int time);
+
+ /**
* Sets a ban on an account (hence on all its characters).
*
* @param id character identifier.