Cleaner way to handle out of range and swaps

This commit is contained in:
Akkadius 2014-11-02 22:30:29 -06:00
parent 771279128d
commit 51958b991c
3 changed files with 13 additions and 6 deletions

View File

@ -968,4 +968,6 @@ namespace legacy {
} InventorySlot;
}
static const uint32 MAX_SPELL_DB_ID_VAL = 65535;
#endif

View File

@ -12928,8 +12928,13 @@ void Client::Handle_OP_SwapSpell(const EQApplicationPacket *app)
m_pp.spell_book[swapspell->from_slot] = m_pp.spell_book[swapspell->to_slot];
m_pp.spell_book[swapspell->to_slot] = swapspelltemp;
database.SaveCharacterSpell(this->CharacterID(), m_pp.spell_book[swapspell->from_slot], swapspell->from_slot);
database.SaveCharacterSpell(this->CharacterID(), swapspelltemp, swapspell->to_slot);
/* Save Spell Swaps */
if (!database.SaveCharacterSpell(this->CharacterID(), m_pp.spell_book[swapspell->from_slot], swapspell->from_slot)){
database.DeleteCharacterSpell(this->CharacterID(), m_pp.spell_book[swapspell->from_slot], swapspell->from_slot);
}
if (!database.SaveCharacterSpell(this->CharacterID(), swapspelltemp, swapspell->to_slot)){
database.DeleteCharacterSpell(this->CharacterID(), swapspelltemp, swapspell->to_slot);
}
QueuePacket(app);
return;

View File

@ -966,7 +966,7 @@ bool ZoneDatabase::LoadCharacterMemmedSpells(uint32 character_id, PlayerProfile_
}
for (auto row = results.begin(); row != results.end(); ++row) {
i = atoi(row[0]);
if (i < MAX_PP_MEMSPELL){
if (i < MAX_PP_MEMSPELL && atoi(row[1]) <= SPDAT_RECORDS){
pp->mem_spells[i] = atoi(row[1]);
}
}
@ -989,7 +989,7 @@ bool ZoneDatabase::LoadCharacterSpellBook(uint32 character_id, PlayerProfile_Str
}
for (auto row = results.begin(); row != results.end(); ++row) {
i = atoi(row[0]);
if (i < MAX_PP_SPELLBOOK){
if (i < MAX_PP_SPELLBOOK && atoi(row[1]) <= SPDAT_RECORDS){
pp->spell_book[i] = atoi(row[1]);
}
}
@ -1655,14 +1655,14 @@ bool ZoneDatabase::SaveCharacterAA(uint32 character_id, uint32 aa_id, uint32 cur
}
bool ZoneDatabase::SaveCharacterMemorizedSpell(uint32 character_id, uint32 spell_id, uint32 slot_id){
if (spell_id == 65535 || spell_id == 4294967295){ return false; }
if (spell_id > SPDAT_RECORDS){ return false; }
std::string query = StringFormat("REPLACE INTO `character_memmed_spells` (id, slot_id, spell_id) VALUES (%u, %u, %u)", character_id, slot_id, spell_id);
QueryDatabase(query);
return true;
}
bool ZoneDatabase::SaveCharacterSpell(uint32 character_id, uint32 spell_id, uint32 slot_id){
if (spell_id == 65535 || spell_id == 4294967295){ return false; }
if (spell_id > SPDAT_RECORDS){ return false; }
std::string query = StringFormat("REPLACE INTO `character_spells` (id, slot_id, spell_id) VALUES (%u, %u, %u)", character_id, slot_id, spell_id);
QueryDatabase(query);
return true;