diff --git a/common/eq_constants.h b/common/eq_constants.h index 1868d6c3e..426d4a9e5 100644 --- a/common/eq_constants.h +++ b/common/eq_constants.h @@ -968,4 +968,6 @@ namespace legacy { } InventorySlot; } +static const uint32 MAX_SPELL_DB_ID_VAL = 65535; + #endif diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 7a1d36a4e..75605a486 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -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; diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index afa43f6e8..e18a208ae 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -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;