summaryrefslogtreecommitdiff
path: root/src/account-server/storage.cpp
diff options
context:
space:
mode:
authorFreeyorp <Freeyorp101@hotmail.com>2010-05-17 20:55:06 +1200
committerFreeyorp <Freeyorp101@hotmail.com>2010-07-10 21:51:07 +1200
commit98cdcb1de4f422255aa5ef924042ae7d00a5b968 (patch)
tree1746776580502fb007581f171fa89638ab6bc64f /src/account-server/storage.cpp
parent26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2 (diff)
downloadmanaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.tar.gz
manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.tar.bz2
manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.tar.xz
manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.zip
New attribute system and major changes to many low-level areas.
Attribute system: Structure is no longer completely hardcoded. Attributes and structure is defined by new xml file (defaulting to stats.xml) Structure defines non-base modifications to an attribute, to be used by modifiers from items, effects, etc. Calculating the base value for core attributes is still done in C++ (and for such fundamental elements the only reason I can think of to do it any other way is perhaps being able to quickly change scripts without a compile could be useful for testing, but such things are a low priority anyway) Item structure: Modifiers are now through triggers rather than single events. This also removes hardcoded types - an item could be both able to be equipped and be able to be activated. Item activation no longer consumes by default, this must be specified by the property <consumes /> inside the trigger. Currently only attribute modifications, autoattacks, and consumes are defined as effects, but stubs for others do exist. Autoattacks are currently non-functional, and this should be rectified with some urgency. Auto Attacks: AutoAttacks are now separate entities, though not fully complete, nor fully integrated with all beings yet. Integration with the Character class is urgent, integration with other Being children less so. When fully integrated this will allow for multiple autoattacks, through equipping multiple items with this as an equip effect or even through other means if needed. Equipment structure: As ItemClass types are no longer hardcoded, so too are equip types. An item have multiple ways to be equipped across multiple equipment slots with any number in each slot. Character maximums are global but configurable. Miscellaneous: Speed, money, and weight are now attributes. Some managers have been changed into classes such that their associated classes can have them as friends, to avoid (ab)use of public accessors. The serialise procedure should also be set as a friend of Character (both in the account- and game- server) as well; having public accessors returning iterators is simply ridiculous. Some start for such cleanups have been made, but this is not the primary focus here. Significant work will need to be done before this is resolved completely, but the start is there. BuySell::registerPlayerItems() has been completely disabled temporarily. The previous function iterated through equipment, yet in the context I think it is intended to fill items? I have been unable to update this function to fit the modifications made to the Inventory/Equipment/Possessions, as I am unsure what exactly what it should be doing. ItemClass::mSpriteId was previously unused, so had been removed, but I notice that it was used when transmitting equipment to nearby clients. Experimentation showed that this value was never set to anything other than 0, and so has been left out of the ItemManager rewrite. I am not entirely sure what is happening here, but it should be worth looking into at a later time, as I am not sure how equipment appearences would be sent otherwise.
Diffstat (limited to 'src/account-server/storage.cpp')
-rw-r--r--src/account-server/storage.cpp382
1 files changed, 222 insertions, 160 deletions
diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp
index c104b4f7..f427a2a7 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 = "9";
+static const char *SUPPORTED_DB_VERSION = "10";
/*
* MySQL specificities:
@@ -67,24 +67,26 @@ static const char *SUPPORTED_DB_VERSION = "9";
* TODO: Fix problem with PostgreSQL null primary key's.
*/
-static const char *ACCOUNTS_TBL_NAME = "mana_accounts";
-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";
-static const char *GUILD_MEMBERS_TBL_NAME = "mana_guild_members";
-static const char *QUESTS_TBL_NAME = "mana_quests";
-static const char *WORLD_STATES_TBL_NAME = "mana_world_states";
-static const char *POST_TBL_NAME = "mana_post";
-static const char *POST_ATTACHMENTS_TBL_NAME = "mana_post_attachments";
-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 *ACCOUNTS_TBL_NAME = "mana_accounts";
+static const char *CHARACTERS_TBL_NAME = "mana_characters";
+static const char *CHAR_ATTR_TBL_NAME = "mana_char_attr";
+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 *CHAR_EQUIPS_TBL_NAME = "mana_char_equips";
+static const char *INVENTORIES_TBL_NAME = "mana_inventories";
+static const char *ITEMS_TBL_NAME = "mana_items";
+static const char *GUILDS_TBL_NAME = "mana_guilds";
+static const char *GUILD_MEMBERS_TBL_NAME = "mana_guild_members";
+static const char *QUESTS_TBL_NAME = "mana_quests";
+static const char *WORLD_STATES_TBL_NAME = "mana_world_states";
+static const char *POST_TBL_NAME = "mana_post";
+static const char *POST_ATTACHMENTS_TBL_NAME = "mana_post_attachments";
+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";
/**
* Constructor.
@@ -217,7 +219,7 @@ Account *Storage::getAccountBySQL()
// we have no choice but to return nothing.
if (accountInfo.isEmpty())
{
- return NULL;
+ return 0;
}
// specialize the string_to functor to convert
@@ -237,7 +239,7 @@ Account *Storage::getAccountBySQL()
int level = toUint(accountInfo(0, 4));
// Check if the user is permanently banned, or temporarily banned.
if (level == AL_BANNED
- || time(NULL) <= (int) toUint(accountInfo(0, 5)))
+ || time(0) <= (int) toUint(accountInfo(0, 5)))
{
account->setLevel(AL_BANNED);
// It is, so skip character loading.
@@ -285,7 +287,7 @@ Account *Storage::getAccountBySQL()
catch (const dal::DbSqlQueryExecFailure &e)
{
LOG_ERROR("DALStorage::getAccountBySQL: " << e.what());
- return NULL; // TODO: Throw exception here
+ return 0; // TODO: Throw exception here
}
}
@@ -345,13 +347,12 @@ Character *Storage::getCharacterBySQL(Account *owner)
// if the character is not even in the database then
// we have no choice but to return nothing.
if (charInfo.isEmpty())
- {
- return NULL;
- }
+ return 0;
// specialize the string_to functor to convert
// a string to an unsigned short.
string_to< unsigned short > toUshort;
+ string_to< double > toDouble;
character = new Character(charInfo(0, 2), toUint(charInfo(0, 0)));
character->setGender(toUshort(charInfo(0, 3)));
@@ -360,16 +361,10 @@ Character *Storage::getCharacterBySQL(Account *owner)
character->setLevel(toUshort(charInfo(0, 6)));
character->setCharacterPoints(toUshort(charInfo(0, 7)));
character->setCorrectionPoints(toUshort(charInfo(0, 8)));
- character->getPossessions().money = toUint(charInfo(0, 9));
- Point pos(toUshort(charInfo(0, 10)), toUshort(charInfo(0, 11)));
+ Point pos(toUshort(charInfo(0, 9)), toUshort(charInfo(0, 10)));
character->setPosition(pos);
- for (int i = 0; i < CHAR_ATTR_NB; ++i)
- {
- character->setAttribute(CHAR_ATTR_BEGIN + i,
- toUshort(charInfo(0, 13 + i)));
- }
- int mapId = toUint(charInfo(0, 12));
+ int mapId = toUint(charInfo(0, 11));
if (mapId > 0)
{
character->setMapId(mapId);
@@ -398,12 +393,35 @@ Character *Storage::getCharacterBySQL(Account *owner)
character->setAccountLevel(toUint(levelInfo(0, 0)), true);
}
- // load the skills of the char from CHAR_SKILLS_TBL_NAME
std::ostringstream s;
- s << "SELECT skill_id, skill_exp "
- << "FROM " << CHAR_SKILLS_TBL_NAME << " "
+
+ /*
+ * Load attributes.
+ */
+ s << "SELECT attr_id, attr_base, attr_mod "
+ << "FROM " << CHAR_ATTR_TBL_NAME << " "
<< "WHERE char_id = " << character->getDatabaseID();
+ const dal::RecordSet &attrInfo = mDb->execSql(s.str());
+ if (!attrInfo.isEmpty())
+ {
+ const unsigned int nRows = attrInfo.rows();
+ for (unsigned int row = 0; row < nRows; ++row)
+ {
+ unsigned int id = toUint(attrInfo(row, 0));
+ character->setAttribute(id, toDouble(attrInfo(row, 1)));
+ character->setModAttribute(id, toDouble(attrInfo(row, 2)));
+ }
+ }
+
+ s.clear();
+ s.str("");
+
+ // load the skills of the char from CHAR_SKILLS_TBL_NAME
+
+ s << "select status_id, status_time FROM " << CHAR_STATUS_EFFECTS_TBL_NAME
+ << " WHERE char_id = " << character->getDatabaseID();
+
const dal::RecordSet &skillInfo = mDb->execSql(s.str());
if (!skillInfo.isEmpty())
{
@@ -465,7 +483,28 @@ Character *Storage::getCharacterBySQL(Account *owner)
catch (const dal::DbSqlQueryExecFailure &e)
{
LOG_ERROR("(DALStorage::getCharacter #1) SQL query failure: " << e.what());
- return NULL;
+ return 0;
+ }
+
+ Possessions &poss = character->getPossessions();
+
+ try
+ {
+ std::ostringstream sql;
+ sql << " select * from " << CHAR_EQUIPS_TBL_NAME << " where owner_id = '"
+ << character->getDatabaseID() << "' order by slot_type desc;";
+
+ const dal::RecordSet &equipInfo = mDb->execSql(sql.str());
+ if (!equipInfo.isEmpty())
+ for (int k = 0, size = equipInfo.rows(); k < size; ++k)
+ poss.equipSlots.insert(std::pair<unsigned int, unsigned int>(
+ toUint(equipInfo(k, 3)),
+ toUint(equipInfo(k, 2))));
+ }
+ catch (const dal::DbSqlQueryExecFailure &e)
+ {
+ LOG_ERROR("(DALStorage::getCharacter #1) SQL query failure: " << e.what());
+ return 0;
}
try
@@ -476,44 +515,19 @@ Character *Storage::getCharacterBySQL(Account *owner)
const dal::RecordSet &itemInfo = mDb->execSql(sql.str());
if (!itemInfo.isEmpty())
- {
- Possessions &poss = character->getPossessions();
- unsigned nextSlot = 0;
-
for (int k = 0, size = itemInfo.rows(); k < size; ++k)
{
- unsigned slot = toUint(itemInfo(k, 2));
- if (slot < EQUIPMENT_SLOTS)
- {
- poss.equipment[slot] = toUint(itemInfo(k, 3));
- }
- else
- {
- slot -= 32;
- if (slot >= INVENTORY_SLOTS || slot < nextSlot)
- {
- LOG_ERROR("(DALStorage::getCharacter #2) Corrupted inventory.");
- break;
- }
- InventoryItem item;
- if (slot != nextSlot)
- {
- item.itemId = 0;
- item.amount = slot - nextSlot;
- poss.inventory.push_back(item);
- }
- item.itemId = toUint(itemInfo(k, 3));
- item.amount = toUint(itemInfo(k, 4));
- poss.inventory.push_back(item);
- nextSlot = slot + 1;
- }
+ InventoryItem item;
+ unsigned short slot = toUint(itemInfo(k, 2));
+ item.itemId = toUint(itemInfo(k, 3));
+ item.amount = toUint(itemInfo(k, 4));
+ poss.inventory[slot] = item;
}
- }
}
catch (const dal::DbSqlQueryExecFailure &e)
{
LOG_ERROR("(DALStorage::getCharacter #2) SQL query failure: " << e.what());
- return NULL;
+ return 0;
}
return character;
@@ -553,7 +567,7 @@ Character *Storage::getCharacter(const std::string &name)
{
mDb->bindValue(1, name);
}
- return getCharacterBySQL(NULL);
+ return getCharacterBySQL(0);
}
/**
@@ -671,21 +685,9 @@ bool Storage::updateCharacter(Character *character,
<< "level = '" << character->getLevel() << "', "
<< "char_pts = '" << character->getCharacterPoints() << "', "
<< "correct_pts = '"<< character->getCorrectionPoints() << "', "
- << "money = '" << character->getPossessions().money << "', "
<< "x = '" << character->getPosition().x << "', "
<< "y = '" << character->getPosition().y << "', "
- << "map_id = '" << character->getMapId() << "', "
- << "str = '" << character->getAttribute(CHAR_ATTR_STRENGTH) << "', "
- << "agi = '" << character->getAttribute(CHAR_ATTR_AGILITY) << "', "
- << "dex = '" << character->getAttribute(CHAR_ATTR_DEXTERITY) << "', "
- << "vit = '" << character->getAttribute(CHAR_ATTR_VITALITY) << "', "
-#if defined(MYSQL_SUPPORT) || defined(POSTGRESQL_SUPPORT)
- << "`int` = '"
-#else
- << "int = '"
-#endif
- << character->getAttribute(CHAR_ATTR_INTELLIGENCE) << "', "
- << "will = '" << character->getAttribute(CHAR_ATTR_WILLPOWER) << "' "
+ << "map_id = '" << character->getMapId() << "' "
<< "where id = '" << character->getDatabaseID() << "';";
mDb->execSql(sqlUpdateCharacterInfo.str());
@@ -702,13 +704,34 @@ bool Storage::updateCharacter(Character *character,
}
/**
+ * Character attributes.
+ */
+ try
+ {
+ std::ostringstream sqlAttr;
+ for (AttributeMap::const_iterator
+ it = character->mAttributes.begin(),
+ it_end = character->mAttributes.end();
+ it != it_end;
+ ++it)
+ updateAttribute(character->getDatabaseID(), it->first,
+ it->second.first, it->second.second);
+ }
+ catch (const dal::DbSqlQueryExecFailure &e)
+ {
+ if (startTransaction)
+ mDb->rollbackTransaction();
+ LOG_ERROR("(DALStorage::updateCharacter #2) SQL query failure: " << e.what());
+ }
+
+ /**
* Character's skills
*/
try
{
std::map<int, int>::const_iterator skill_it;
- for (skill_it = character->getSkillBegin();
- skill_it != character->getSkillEnd(); skill_it++)
+ for (skill_it = character->mExperience.begin();
+ skill_it != character->mExperience.end(); skill_it++)
{
updateExperience(character->getDatabaseID(), skill_it->first, skill_it->second);
}
@@ -720,7 +743,7 @@ 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;
}
@@ -743,7 +766,7 @@ bool Storage::updateCharacter(Character *character,
{
mDb->rollbackTransaction();
}
- LOG_ERROR("(DALStorage::updateCharacter #3) SQL query failure: " << e.what());
+ LOG_ERROR("(DALStorage::updateCharacter #4) SQL query failure: " << e.what());
return false;
}
/**
@@ -777,7 +800,7 @@ bool Storage::updateCharacter(Character *character,
{
mDb->rollbackTransaction();
}
- LOG_ERROR("(DALStorage::updateCharacter #4) SQL query failure: " << e.what());
+ LOG_ERROR("(DALStorage::updateCharacter #5) SQL query failure: " << e.what());
return false;
}
@@ -810,36 +833,39 @@ bool Storage::updateCharacter(Character *character,
{
std::ostringstream sql;
- sql << "insert into " << INVENTORIES_TBL_NAME
- << " (owner_id, slot, class_id, amount) values ("
+ sql << "insert into " << CHAR_EQUIPS_TBL_NAME
+ << " (owner_id, slot_type, inventory_slot) values ("
<< character->getDatabaseID() << ", ";
std::string base = sql.str();
const Possessions &poss = character->getPossessions();
-
- for (int j = 0; j < EQUIPMENT_SLOTS; ++j)
+ for (EquipData::const_iterator it = poss.equipSlots.begin(),
+ it_end = poss.equipSlots.end();
+ it != it_end;
+ ++it)
{
- int v = poss.equipment[j];
- if (!v) continue;
- sql.str(std::string());
- sql << base << j << ", " << v << ", 1);";
- mDb->execSql(sql.str());
+ sql.str("");
+ sql << base << it->first << ", " << it->second << ");";
+ mDb->execSql(sql.str());
}
- int slot = 32;
- for (std::vector< InventoryItem >::const_iterator j = poss.inventory.begin(),
+ sql.str("");
+
+ sql << "insert into " << INVENTORIES_TBL_NAME
+ << " (owner_id, slot, class_id, amount) values ("
+ << character->getDatabaseID() << ", ";
+ base = sql.str();
+
+ for (InventoryData::const_iterator j = poss.inventory.begin(),
j_end = poss.inventory.end(); j != j_end; ++j)
{
- int v = j->itemId;
- if (!v)
- {
- slot += j->amount;
- continue;
- }
- sql.str(std::string());
- sql << base << slot << ", " << v << ", " << unsigned(j->amount) << ");";
+ sql.str("");
+ unsigned short slot = j->first;
+ unsigned int itemId = j->second.itemId;
+ unsigned int amount = j->second.amount;
+ assert(itemId);
+ sql << base << slot << ", " << itemId << ", " << amount << ");";
mDb->execSql(sql.str());
- ++slot;
}
}
@@ -850,7 +876,7 @@ bool Storage::updateCharacter(Character *character,
{
mDb->rollbackTransaction();
}
- LOG_ERROR("(DALStorage::updateCharacter #4) SQL query failure: " << e.what());
+ LOG_ERROR("(DALStorage::updateCharacter #6) SQL query failure: " << e.what());
return false;
}
@@ -874,7 +900,7 @@ bool Storage::updateCharacter(Character *character,
{
mDb->rollbackTransaction();
}
- LOG_ERROR("(DALStorage::updateCharacter #5) SQL query failure: " << e.what());
+ LOG_ERROR("(DALStorage::updateCharacter #7) SQL query failure: " << e.what());
return false;
}
try
@@ -893,7 +919,7 @@ bool Storage::updateCharacter(Character *character,
{
mDb->rollbackTransaction();
}
- LOG_ERROR("(DALStorage::updateCharacter #6) SQL query failure: " << e.what());
+ LOG_ERROR("(DALStorage::updateCharacter #8) SQL query failure: " << e.what());
return false;
}
if (startTransaction)
@@ -1005,14 +1031,8 @@ void Storage::flush(Account *account)
// uniqueness
sqlInsertCharactersTable
<< "insert into " << CHARACTERS_TBL_NAME
- << " (user_id, name, gender, hair_style, hair_color, level, char_pts, correct_pts, money,"
- << " x, y, map_id, str, agi, dex, vit, "
-#if defined(MYSQL_SUPPORT) || defined(POSTGRESQL_SUPPORT)
- << "`int`, "
-#else
- << "int, "
-#endif
- << "will ) values ("
+ << " (user_id, name, gender, hair_style, hair_color, level, char_pts, correct_pts,"
+ << " x, y, map_id) values ("
<< account->getID() << ", \""
<< (*it)->getName() << "\", "
<< (*it)->getGender() << ", "
@@ -1021,30 +1041,33 @@ void Storage::flush(Account *account)
<< (int)(*it)->getLevel() << ", "
<< (int)(*it)->getCharacterPoints() << ", "
<< (int)(*it)->getCorrectionPoints() << ", "
- << (*it)->getPossessions().money << ", "
<< (*it)->getPosition().x << ", "
<< (*it)->getPosition().y << ", "
- << (*it)->getMapId() << ", "
- << (*it)->getAttribute(CHAR_ATTR_STRENGTH) << ", "
- << (*it)->getAttribute(CHAR_ATTR_AGILITY) << ", "
- << (*it)->getAttribute(CHAR_ATTR_DEXTERITY) << ", "
- << (*it)->getAttribute(CHAR_ATTR_VITALITY) << ", "
- << (*it)->getAttribute(CHAR_ATTR_INTELLIGENCE) << ", "
- << (*it)->getAttribute(CHAR_ATTR_WILLPOWER) << " "
+ << (*it)->getMapId()
<< ");";
mDb->execSql(sqlInsertCharactersTable.str());
+ // Update all attributes.
+ std::map<unsigned int, std::pair<double, double> >::const_iterator
+ attr_it, attr_end;
+ for (attr_it = (*it)->mAttributes.begin(),
+ attr_end = (*it)->mAttributes.end();
+ attr_it != attr_end;
+ ++attr_it)
+ updateAttribute((*it)->getDatabaseID(), attr_it->first,
+ attr_it->second.first,
+ attr_it->second.second);
+
// Update the character ID.
(*it)->setDatabaseID(mDb->getLastId());
// update the characters skill
std::map<int, int>::const_iterator skill_it;
- for (skill_it = (*it)->getSkillBegin();
- skill_it != (*it)->getSkillEnd(); skill_it++)
- {
+ for (skill_it = (*it)->mExperience.begin();
+ skill_it != (*it)->mExperience.end();
+ skill_it++)
updateExperience((*it)->getDatabaseID(), skill_it->first, skill_it->second);
- }
}
} //
@@ -1135,31 +1158,26 @@ void Storage::updateLastLogin(const Account *account)
* @param CharId ID of the character
* @param CharPoints Number of character points left for the character
* @param CorrPoints Number of correction points left for the character
- * @param AttribId ID of the modified attribute
- * @param AttribValue New value of the modified attribute
*/
void Storage::updateCharacterPoints(int charId,
- int charPoints, int corrPoints,
- int attribId, int attribValue)
+ int charPoints, int corrPoints)
{
- std::ostringstream sql;
- sql << "UPDATE " << CHARACTERS_TBL_NAME
- << " SET char_pts = " << charPoints << ", "
- << " correct_pts = " << corrPoints << ", ";
+ try
+ {
+ std::ostringstream sql;
+ sql << "UPDATE " << CHARACTERS_TBL_NAME
+ << " SET char_pts = " << charPoints << ", "
+ << " correct_pts = " << corrPoints << ", "
+ << " WHERE id = " << charId;
- switch (attribId)
+ mDb->execSql(sql.str());
+ }
+ catch (dal::DbSqlQueryExecFailure &e)
{
- case CHAR_ATTR_STRENGTH: sql << "str = "; break;
- case CHAR_ATTR_AGILITY: sql << "agi = "; break;
- case CHAR_ATTR_DEXTERITY: sql << "dex = "; break;
- case CHAR_ATTR_VITALITY: sql << "vit = "; break;
- case CHAR_ATTR_INTELLIGENCE: sql << "int = "; break;
- case CHAR_ATTR_WILLPOWER: sql << "will = "; break;
+ LOG_ERROR("DALStorage::updateCharacterPoints: " << e.what());
+ throw;
}
- sql << attribValue
- << " WHERE id = " << charId;
- mDb->execSql(sql.str());
}
/**
@@ -1215,6 +1233,50 @@ void Storage::updateExperience(int charId, int skillId, int skillValue)
}
/**
+ * Write a modification message about character attributes to the database.
+ * @param charId The Id of the character
+ * @param attrId The Id of the attribute
+ * @param base The base value of the attribute for this character
+ * @param mod The cached modified value for this character.
+ */
+
+void Storage::updateAttribute(int charId, unsigned int attrId,
+ double base, double mod)
+{
+ try {
+ std::ostringstream sql;
+ sql << "UPDATE " << CHAR_ATTR_TBL_NAME << " "
+ << "SET "
+ << "attr_base = '" << base << "', "
+ << "attr_mod = '" << mod << "' "
+ << "WHERE "
+ << "char_id = '" << charId << "' "
+ << "AND "
+ << "attr_id = '" << attrId << "';";
+ mDb->execSql(sql.str());
+ // If this has modified a row, we're done, it updated sucessfully.
+ if (mDb->getModifiedRows() > 0)
+ return;
+ // If it did not change anything, then the record didn't previously exist.
+ // Create it.
+ sql.clear();
+ sql.str("");
+ sql << "INSERT INTO " << CHAR_ATTR_TBL_NAME << " "
+ << "(char_id, attr_id, attr_base, attr_mod) VALUES ( "
+ << charId << ", "
+ << attrId << ", "
+ << base << ", "
+ << mod << ")";
+ mDb->execSql(sql.str());
+ }
+ catch (const dal::DbSqlQueryExecFailure &e)
+ {
+ LOG_ERROR("DALStorage::updateAttribute: " << e.what());
+ throw;
+ }
+}
+
+/**
* Write a modification message about character skills to the database.
* @param CharId ID of the character
* @param monsterId ID of the monster type
@@ -1445,7 +1507,7 @@ std::list<Guild*> Storage::getGuildList()
i != members.end();
++i)
{
- Character *character = getCharacter((*i).first, NULL);
+ Character *character = getCharacter((*i).first, 0);
if (character)
{
character->addGuild((*itr)->getName());
@@ -1567,7 +1629,7 @@ void Storage::setWorldStateVar(const std::string &name,
std::ostringstream updateStateVar;
updateStateVar << "UPDATE " << WORLD_STATES_TBL_NAME
<< " SET value = '" << value << "', "
- << " moddate = '" << time(NULL) << "' "
+ << " moddate = '" << time(0) << "' "
<< " WHERE state_name = '" << name << "'";
if (mapId >= 0)
@@ -1594,10 +1656,10 @@ void Storage::setWorldStateVar(const std::string &name,
}
else
{
- insertStateVar << "NULL , ";
+ insertStateVar << "0 , ";
}
insertStateVar << "'" << value << "', "
- << "'" << time(NULL) << "');";
+ << "'" << time(0) << "');";
mDb->execSql(insertStateVar.str());
}
catch (const dal::DbSqlQueryExecFailure &e)
@@ -1657,7 +1719,7 @@ void Storage::banCharacter(int id, int duration)
std::ostringstream sql;
sql << "update " << ACCOUNTS_TBL_NAME
<< " set level = '" << AL_BANNED << "', banned = '"
- << time(NULL) + duration * 60
+ << time(0) + duration * 60
<< "' where id = '" << info(0, 0) << "';";
mDb->execSql(sql.str());
}
@@ -1766,7 +1828,7 @@ void Storage::checkBannedAccounts()
sql << "update " << ACCOUNTS_TBL_NAME
<< " set level = " << AL_PLAYER << ", banned = 0"
<< " where level = " << AL_BANNED
- << " AND banned <= " << time(NULL) << ";";
+ << " AND banned <= " << time(0) << ";";
mDb->execSql(sql.str());
}
catch (const dal::DbSqlQueryExecFailure &e)
@@ -1835,7 +1897,7 @@ void Storage::storeLetter(Letter *letter)
<< letter->getSender()->getDatabaseID() << ", "
<< letter->getReceiver()->getDatabaseID() << ", "
<< letter->getExpiry() << ", "
- << time(NULL) << ", "
+ << time(0) << ", "
<< "?)";
if (mDb->prepareSql(sql.str()))
{
@@ -1857,7 +1919,7 @@ void Storage::storeLetter(Letter *letter)
<< " receiver_id = '" << letter->getReceiver()->getDatabaseID() << "', "
<< " letter_type = '" << letter->getType() << "', "
<< " expiration_date = '" << letter->getExpiry() << "', "
- << " sending_date = '" << time(NULL) << "', "
+ << " sending_date = '" << time(0) << "', "
<< " letter_text = ? "
<< " WHERE letter_id = '" << letter->getId() << "'";
@@ -1905,8 +1967,8 @@ Post *Storage::getStoredPost(int playerId)
for (unsigned int i = 0; i < post.rows(); i++ )
{
// load sender and receiver
- Character *sender = getCharacter(toUint(post(i, 1)), NULL);
- Character *receiver = getCharacter(toUint(post(i, 2)), NULL);
+ Character *sender = getCharacter(toUint(post(i, 1)), 0);
+ Character *receiver = getCharacter(toUint(post(i, 2)), 0);
Letter *letter = new Letter(toUint( post(0,3) ), sender, receiver);
@@ -2089,7 +2151,7 @@ void Storage::setOnlineStatus(int charId, bool online)
sql.clear();
sql.str("");
sql << "INSERT INTO " << ONLINE_USERS_TBL_NAME
- << " VALUES (" << charId << ", " << time(NULL) << ")";
+ << " VALUES (" << charId << ", " << time(0) << ")";
mDb->execSql(sql.str());
}
else
@@ -2119,7 +2181,7 @@ void Storage::addTransaction(const Transaction &trans)
<< " VALUES (NULL, " << trans.mCharacterId << ", "
<< trans.mAction << ", "
<< "?, "
- << time(NULL) << ")";
+ << time(0) << ")";
if (mDb->prepareSql(sql.str()))
{
mDb->bindValue(1, trans.mMessage);