From 8571c35e77458cfedda5ddd8f5ccb7ae8618f220 Mon Sep 17 00:00:00 2001 From: ukmeth0d Date: Fri, 7 Mar 2014 01:34:30 +0100 Subject: [PATCH 1/6] Fixed 2H Blunt Animation to match Live Melee bots (with no mana) will now sit when not full HP and out of combat. --- zone/attack.cpp | 4 ++-- zone/bot.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/zone/attack.cpp b/zone/attack.cpp index a291a709b..798c61b11 100644 --- a/zone/attack.cpp +++ b/zone/attack.cpp @@ -91,7 +91,7 @@ bool Mob::AttackAnimation(SkillUseTypes &skillinuse, int Hand, const ItemInst* w case ItemType2HBlunt: // 2H Blunt { skillinuse = Skill2HBlunt; - type = anim2HWeapon; + type = anim2HSlashing; //anim2HWeapon break; } case ItemType2HPiercing: // 2H Piercing @@ -140,7 +140,7 @@ bool Mob::AttackAnimation(SkillUseTypes &skillinuse, int Hand, const ItemInst* w } case Skill2HBlunt: // 2H Blunt { - type = anim2HWeapon; + type = anim2HSlashing; //anim2HWeapon break; } case 99: // 2H Piercing // change to Skill2HPiercing once activated diff --git a/zone/bot.cpp b/zone/bot.cpp index 1ec736ecf..425402b65 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -3151,9 +3151,9 @@ void Bot::SpellProcess() void Bot::BotMeditate(bool isSitting) { if(isSitting) { // If the bot is a caster has less than 99% mana while its not engaged, he needs to sit to meditate - if(GetManaRatio() < 99.0f) + if(GetManaRatio() < 99.0f || GetHPRatio() < 99.0f) { - if(!IsSitting()) + if (!IsEngaged() && !IsSitting()) Sit(); } else From 95176fc8137aa920f81625f1038e75dc86cc8af3 Mon Sep 17 00:00:00 2001 From: KayenEQ Date: Wed, 12 Mar 2014 05:14:19 -0400 Subject: [PATCH 2/6] Coverted melee and magic runes to use bonuses. Removed all the old rune flags now that none of them are used. Fixed issues where runes would not fade properly if damage = remaing rune amount Fixed issue where runes would stop absorbing damage if you had multiple runes. --- changelog.txt | 4 ++++ zone/attack.cpp | 31 +++++++++++------------------ zone/bonuses.cpp | 38 ++++++++++++++++++++++++++++++++++- zone/client.cpp | 4 ++-- zone/common.h | 4 ++-- zone/mob.cpp | 6 ------ zone/mob.h | 14 ------------- zone/pets.cpp | 1 - zone/spell_effects.cpp | 14 +++++-------- zone/spells.cpp | 45 ------------------------------------------ zone/zonedb.cpp | 6 ------ 11 files changed, 62 insertions(+), 105 deletions(-) diff --git a/changelog.txt b/changelog.txt index df6cc662d..e7973ed6d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,9 @@ EQEMu Changelog (Started on Sept 24, 2003 15:50) ------------------------------------------------------- + +== 03/12/2014 == +Kayen: Melee/Magic runes are now calculated as bonuses. Resolved issues with runes not working and not fading properly. + == 03/08/2014 == Kayen: Revision to lull/harmony/pacification code to be consistent with live based on extensive personal parsing. *Lulls on initial cast do not check regular resists (MR ect) but only apply a flat ~7.5 % resist chance + level modifier diff --git a/zone/attack.cpp b/zone/attack.cpp index 798c61b11..ccbc3a8f8 100644 --- a/zone/attack.cpp +++ b/zone/attack.cpp @@ -3188,7 +3188,6 @@ int32 Mob::ReduceDamage(int32 damage) damage -= damage_to_reduce; if(!TryFadeEffect(slot)) BuffFadeBySlot(slot); - //UpdateRuneFlags(); } else { @@ -3213,7 +3212,6 @@ int32 Mob::ReduceDamage(int32 damage) damage -= damage_to_reduce; if(!TryFadeEffect(slot)) BuffFadeBySlot(slot); - UpdateRuneFlags(); } else { @@ -3221,7 +3219,6 @@ int32 Mob::ReduceDamage(int32 damage) " damage remaining.", damage_to_reduce, buffs[slot].melee_rune); buffs[slot].melee_rune = (buffs[slot].melee_rune - damage_to_reduce); damage -= damage_to_reduce; - UpdateRuneFlags(); } } } @@ -3243,7 +3240,7 @@ int32 Mob::ReduceDamage(int32 damage) if(damage < 1) return -6; - if (HasRune()) + if (spellbonuses.MeleeRune[0] && spellbonuses.MeleeRune[1] >= 0) damage = RuneAbsorb(damage, SE_Rune); if(damage < 1) @@ -3317,7 +3314,6 @@ int32 Mob::AffectMagicalDamage(int32 damage, uint16 spell_id, const bool iBuffTi damage -= damage_to_reduce; if(!TryFadeEffect(slot)) BuffFadeBySlot(slot); - //UpdateRuneFlags(); } else { @@ -3341,7 +3337,6 @@ int32 Mob::AffectMagicalDamage(int32 damage, uint16 spell_id, const bool iBuffTi damage -= damage_to_reduce; if(!TryFadeEffect(slot)) BuffFadeBySlot(slot); - UpdateRuneFlags(); } else { @@ -3349,7 +3344,6 @@ int32 Mob::AffectMagicalDamage(int32 damage, uint16 spell_id, const bool iBuffTi " damage remaining.", damage_to_reduce, buffs[slot].magic_rune); buffs[slot].magic_rune = (buffs[slot].magic_rune - damage_to_reduce); damage -= damage_to_reduce; - UpdateRuneFlags(); } } } @@ -3372,7 +3366,7 @@ int32 Mob::AffectMagicalDamage(int32 damage, uint16 spell_id, const bool iBuffTi return 0; - if (HasSpellRune()) + if (spellbonuses.AbsorbMagicAtt[0] && spellbonuses.AbsorbMagicAtt[1] >= 0) damage = RuneAbsorb(damage, SE_AbsorbMagicAtt); if(damage < 1) @@ -4602,9 +4596,10 @@ int32 Mob::RuneAbsorb(int32 damage, uint16 type) uint32 buff_max = GetMaxTotalSlots(); if (type == SE_Rune){ for(uint32 slot = 0; slot < buff_max; slot++) { - if((buffs[slot].spellid != SPELL_UNKNOWN) && (buffs[slot].melee_rune) && IsEffectInSpell(buffs[slot].spellid, type)){ + if(slot == spellbonuses.MeleeRune[1] && spellbonuses.MeleeRune[0] && buffs[slot].melee_rune && IsValidSpell(buffs[slot].spellid)){ uint32 melee_rune_left = buffs[slot].melee_rune; - if(melee_rune_left >= damage) + + if(melee_rune_left > damage) { melee_rune_left -= damage; buffs[slot].melee_rune = melee_rune_left; @@ -4615,22 +4610,20 @@ int32 Mob::RuneAbsorb(int32 damage, uint16 type) { if(melee_rune_left > 0) damage -= melee_rune_left; + if(!TryFadeEffect(slot)) BuffFadeBySlot(slot); - UpdateRuneFlags(); - continue; } } } - return damage; } - + else{ for(uint32 slot = 0; slot < buff_max; slot++) { - if((buffs[slot].spellid != SPELL_UNKNOWN) && (buffs[slot].magic_rune) && IsEffectInSpell(buffs[slot].spellid, type)){ + if(slot == spellbonuses.AbsorbMagicAtt[1] && spellbonuses.AbsorbMagicAtt[0] && buffs[slot].magic_rune && IsValidSpell(buffs[slot].spellid)){ uint32 magic_rune_left = buffs[slot].magic_rune; - if(magic_rune_left >= damage) + if(magic_rune_left > damage) { magic_rune_left -= damage; buffs[slot].magic_rune = magic_rune_left; @@ -4641,14 +4634,14 @@ int32 Mob::RuneAbsorb(int32 damage, uint16 type) { if(magic_rune_left > 0) damage -= magic_rune_left; + if(!TryFadeEffect(slot)) BuffFadeBySlot(slot); - UpdateRuneFlags(); - continue; } } } - return damage; } + + return damage; } diff --git a/zone/bonuses.cpp b/zone/bonuses.cpp index 49cfe8a08..99941b893 100644 --- a/zone/bonuses.cpp +++ b/zone/bonuses.cpp @@ -2538,11 +2538,36 @@ void Mob::ApplySpellsBonuses(uint16 spell_id, uint8 casterlevel, StatBonuses* ne newbon->Root[0] = 1; newbon->Root[1] = buffslot; } - else { + else if (!newbon->Root[0]){ newbon->Root[0] = 1; newbon->Root[1] = buffslot; } break; + + case SE_Rune: + + if (newbon->MeleeRune[0] && (newbon->MeleeRune[1] > buffslot)){ + + newbon->MeleeRune[0] = effect_value; + newbon->MeleeRune[1] = buffslot; + } + else if (!newbon->MeleeRune[0]){ + newbon->MeleeRune[0] = effect_value; + newbon->MeleeRune[1] = buffslot; + } + + break; + + case SE_AbsorbMagicAtt: + if (newbon->AbsorbMagicAtt[0] && (newbon->AbsorbMagicAtt[1] > buffslot)){ + newbon->AbsorbMagicAtt[0] = effect_value; + newbon->AbsorbMagicAtt[1] = buffslot; + } + else if (!newbon->AbsorbMagicAtt[0]){ + newbon->AbsorbMagicAtt[0] = effect_value; + newbon->AbsorbMagicAtt[1] = buffslot; + } + break; } } } @@ -3896,7 +3921,18 @@ void Mob::NegateSpellsBonuses(uint16 spell_id) case SE_Root: spellbonuses.Root[0] = effect_value; spellbonuses.Root[1] = -1; + break; + case SE_Rune: + spellbonuses.MeleeRune[0] = effect_value; + spellbonuses.MeleeRune[1] = -1; + break; + + case SE_AbsorbMagicAtt: + spellbonuses.AbsorbMagicAtt[0] = effect_value; + spellbonuses.AbsorbMagicAtt[1] = -1; + break; + } } } diff --git a/zone/client.cpp b/zone/client.cpp index e8af229ae..ebf5d806c 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -6710,9 +6710,9 @@ void Client::SendStatsWindow(Client* client, bool use_window) uint32 buff_count = GetMaxTotalSlots(); for (int i=0; i < buff_count; i++) { if (buffs[i].spellid != SPELL_UNKNOWN) { - if ((HasRune() || HasPartialMeleeRune()) && buffs[i].melee_rune > 0) { rune_number += buffs[i].melee_rune; } + if (buffs[i].melee_rune > 0) { rune_number += buffs[i].melee_rune; } - if ((HasSpellRune() || HasPartialSpellRune()) && buffs[i].magic_rune > 0) { magic_rune_number += buffs[i].magic_rune; } + if (buffs[i].magic_rune > 0) { magic_rune_number += buffs[i].magic_rune; } } } diff --git a/zone/common.h b/zone/common.h index bd744316f..581d11430 100644 --- a/zone/common.h +++ b/zone/common.h @@ -342,8 +342,8 @@ struct StatBonuses { int16 ImprovedTaunt[3]; // 0 = Max Level 1 = Aggro modifier 2 = buffid int8 Root[2]; // The lowest buff slot a root can be found. [0] = Bool if has root [1] = buff slot int16 FrenziedDevastation; // base1= AArank(used) base2= chance increase spell criticals + all DD spells 2x mana. - //bool AbsorbMagicAtt; // Magic Rune *Need to be implemented for NegateEffect - //bool MeleeRune; // Melee Rune *Need to be implemented for NegateEffect + uint16 AbsorbMagicAtt[2]; // 0 = magic rune value 1 = buff slot + uint16 MeleeRune[2]; // 0 = rune value 1 = buff slot // AAs int8 Packrat; //weight reduction for items, 1 point = 10% diff --git a/zone/mob.cpp b/zone/mob.cpp index d7b37d996..3c1500d19 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -349,12 +349,6 @@ Mob::Mob(const char* in_name, nextinchpevent = -1; TempPets(false); - SetHasRune(false); - SetHasSpellRune(false); - SetHasPartialMeleeRune(false); - SetHasPartialSpellRune(false); - - m_hasDeathSaveChance = false; m_is_running = false; diff --git a/zone/mob.h b/zone/mob.h index a98c125c4..c771d57b7 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -248,14 +248,6 @@ public: virtual int GetMaxTotalSlots() const { return 0; } virtual void InitializeBuffSlots() { buffs = nullptr; current_buff_count = 0; } virtual void UninitializeBuffSlots() { } - inline bool HasRune() const { return m_hasRune; } - inline bool HasSpellRune() const { return m_hasSpellRune; } - inline bool HasPartialMeleeRune() const { return m_hasPartialMeleeRune; } - inline bool HasPartialSpellRune() const { return m_hasPartialSpellRune; } - inline void SetHasRune(bool hasRune) { m_hasRune = hasRune; } - inline void SetHasSpellRune(bool hasSpellRune) { m_hasSpellRune = hasSpellRune; } - inline void SetHasPartialMeleeRune(bool hasPartialMeleeRune) { m_hasPartialMeleeRune = hasPartialMeleeRune; } - inline void SetHasPartialSpellRune(bool hasPartialSpellRune) { m_hasPartialSpellRune = hasPartialSpellRune; } EQApplicationPacket *MakeBuffsPacket(bool for_target = true); void SendBuffsToClient(Client *c); inline Buffs_Struct* GetBuffs() { return buffs; } @@ -993,7 +985,6 @@ protected: float FindGroundZ(float new_x, float new_y, float z_offset=0.0); VERTEX UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &WaypointChange, bool &NodeReached); void PrintRoute(); - void UpdateRuneFlags(); virtual float GetSympatheticProcChances(float &ProcBonus, float &ProcChance, int32 cast_time, int16 ProcRateMod); @@ -1192,11 +1183,6 @@ protected: float tar_vz; float test_vector; - bool m_hasRune; - bool m_hasSpellRune; - bool m_hasPartialMeleeRune; - bool m_hasPartialSpellRune; - bool m_hasDeathSaveChance; uint32 m_spellHitsLeft[38]; // Used to track which spells will have their numhits incremented when spell finishes casting, 38 Buffslots int flymode; bool m_targetable; diff --git a/zone/pets.cpp b/zone/pets.cpp index 5e81c3f84..d5946ce58 100644 --- a/zone/pets.cpp +++ b/zone/pets.cpp @@ -627,7 +627,6 @@ void NPC::SetPetState(SpellBuff_Struct *pet_buffs, uint32 *items) { } } } - UpdateRuneFlags(); //restore their equipment... for(i = 0; i < MAX_WORN_INVENTORY; i++) { diff --git a/zone/spell_effects.cpp b/zone/spell_effects.cpp index 4361761de..cebd548dd 100644 --- a/zone/spell_effects.cpp +++ b/zone/spell_effects.cpp @@ -1242,7 +1242,6 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial) #endif effect_value = ApplySpellEffectiveness(caster, spell_id, effect_value); buffs[buffslot].melee_rune = effect_value; - SetHasRune(true); break; } @@ -1251,17 +1250,15 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial) #ifdef SPELL_EFFECT_SPAM snprintf(effect_desc, _EDLEN, "Spell Absorb Rune: %+i", effect_value); #endif - if(effect_value > 0) { - buffs[buffslot].magic_rune = effect_value; - SetHasSpellRune(true); - } + if(effect_value > 0) + buffs[buffslot].magic_rune = effect_value; + break; } case SE_MitigateMeleeDamage: { - buffs[buffslot].melee_rune = GetPartialMeleeRuneAmount(spell_id); - SetHasPartialMeleeRune(true); + buffs[buffslot].melee_rune = spells[spell_id].max[i]; break; } @@ -1279,8 +1276,7 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial) case SE_MitigateSpellDamage: { - buffs[buffslot].magic_rune = GetPartialMagicRuneAmount(spell_id); - SetHasPartialSpellRune(true); + buffs[buffslot].magic_rune = spells[spell_id].max[i]; break; } diff --git a/zone/spells.cpp b/zone/spells.cpp index 8769e16a2..332906883 100644 --- a/zone/spells.cpp +++ b/zone/spells.cpp @@ -5133,51 +5133,6 @@ void Mob::BuffModifyDurationBySpellID(uint16 spell_id, int32 newDuration) } } } -void Mob::UpdateRuneFlags() -{ - bool Has_SE_Rune = false, Has_SE_AbsorbMagicAtt = false, Has_SE_MitigateMeleeDamage = false, Has_SE_MitigateSpellDamage = false; - uint32 buff_count = GetMaxTotalSlots(); - for (unsigned int i = 0; i < buff_count; ++i) - { - if (buffs[i].spellid != SPELL_UNKNOWN) - { - for (int j = 0; j < EFFECT_COUNT; ++j) - { - switch(spells[buffs[i].spellid].effectid[j]) - { - case SE_Rune: - { - Has_SE_Rune = true; - break; - } - case SE_AbsorbMagicAtt: - { - Has_SE_AbsorbMagicAtt = true; - break; - } - case SE_MitigateMeleeDamage: - { - Has_SE_MitigateMeleeDamage = true; - break; - } - case SE_MitigateSpellDamage: - { - Has_SE_MitigateSpellDamage = true; - break; - } - - default: - break; - } - } - } - } - - SetHasRune(Has_SE_Rune); - SetHasSpellRune(Has_SE_AbsorbMagicAtt); - SetHasPartialMeleeRune(Has_SE_MitigateMeleeDamage); - SetHasPartialSpellRune(Has_SE_MitigateSpellDamage); -} int Client::GetCurrentBuffSlots() const { diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 9457a5f8d..6c3b8ce6e 100644 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -2656,12 +2656,6 @@ void ZoneDatabase::LoadBuffs(Client *c) { buffs[slot_id].ExtraDIChance = ExtraDIChance; buffs[slot_id].RootBreakChance = 0; buffs[slot_id].UpdateClient = false; - if(IsRuneSpell(spell_id)) { - c->SetHasRune(true); - } - else if(IsMagicRuneSpell(spell_id)) { - c->SetHasSpellRune(true); - } } mysql_free_result(result); From 02633d4b01e52564663b486e4a4c5a3043cd28a0 Mon Sep 17 00:00:00 2001 From: Uleat Date: Mon, 17 Mar 2014 04:53:47 -0400 Subject: [PATCH 3/6] ** Fix for RoF clients not displaying Augment Restrictions in the Item Info window. ** Change to Client::SummonItem() to enforce valid item/augment combinations. (Run the optional sql file first, before posting any SummonItem() failure issues in the forums.) --- changelog.txt | 10 + common/eq_constants.h | 77 +++ common/patches/RoF.cpp | 3 +- common/patches/RoF_structs.h | 5 +- common/ruletypes.h | 6 + .../2014_03_17_EnforceAugmentRules.sql | 3 + zone/client.h | 2 +- zone/inventory.cpp | 461 ++++++++++++++---- 8 files changed, 460 insertions(+), 107 deletions(-) create mode 100644 utils/sql/git/optional/2014_03_17_EnforceAugmentRules.sql diff --git a/changelog.txt b/changelog.txt index e7973ed6d..23374f83c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,15 @@ EQEMu Changelog (Started on Sept 24, 2003 15:50) ------------------------------------------------------- +== 03/17/2014 == +Uleat: Updated Client::SummonItem() to check for valid item combinations when augmentations are passed. +Uleat: Changed the return type of Client::SummonItem() from void to bool. Calling methods and APIs have not been update as yet. +Uleat: Fixed the RoF Item structure to properly pass the 'augrestrict' variable. RoF clients now show restrictions in the Item Information window. + +Optional SQL: 2014/03/17_EnforceAugmentRules.sql +Note: This adds the rules Inventory:EnforceAugmentRestriction, Inventory:EnforceAugmentUsability and Inventory:EnforceAugmentWear. + If you run into script/recipe issues, running this sql file will set the default enforcement rules to false. + If you still run into issues, you may want to check that your scripts are not trying to augment non-common items. + Please post any failures as bugs and be sure to include the base item ID, as well as any augment IDs that you are using. == 03/12/2014 == Kayen: Melee/Magic runes are now calculated as bonuses. Resolved issues with runes not working and not fading properly. diff --git a/common/eq_constants.h b/common/eq_constants.h index d612017ad..8b4db6fc3 100644 --- a/common/eq_constants.h +++ b/common/eq_constants.h @@ -137,6 +137,83 @@ enum ItemUseTypes : uint8 */ }; +/* +** Augmentation use types (in-work) +** +** (ref: dbstr_us.txt) +** +*/ +enum AugmentationUseTypes : uint32 { + AugTypeNone = 0, // not 100% sure on this... + AugTypeGeneralSingleStat, /*1^16^1 (General: Single Stat)^0*/ + AugTypeGeneralMultipleStat, /*2^16^2 (General: Multiple Stat)^0*/ + AugTypeGeneralSpellEffect, /*3^16^3 (General: Spell Effect)^0*/ + AugTypeWeaponGeneral, /*4^16^4 (Weapon: General)^0*/ + AugTypeWeaponElemDamage, /*5^16^5 (Weapon: Elem Damage)^0*/ + AugTypeWeaponBaseDamage, /*6^16^6 (Weapon: Base Damage)^0*/ + AugTypeGeneralGroup, /*7^16^7 (General: Group)^0*/ + AugTypeGeneralRaid, /*8^16^8 (General: Raid)^0*/ + AugTypeGeneralDragonsPoints, /*9^16^9 (General: Dragons Points)^0*/ + AugTypeCraftedCommon, /*10^16^10 (Crafted: Common)^0*/ + AugTypeCraftedGroup1, /*11^16^11 (Crafted: Group)^0*/ + AugTypeCraftedRaid1, /*12^16^12 (Crafted: Raid)^0*/ + AugTypeEnergeiacGroup, /*13^16^13 (Energeiac: Group)^0*/ + AugTypeEnergeiacRaid, /*14^16^14 (Energeiac: Raid)^0*/ + AugTypeEmblem, /*15^16^15 (Emblem)^0*/ + AugTypeCraftedGroup2, /*16^16^16 (Crafted: Group)^0*/ + AugTypeCraftedRaid2, /*17^16^17 (Crafted: Raid)^0*/ + AugTypeUnknown1, /*18^16^18^0*/ + AugTypeUnknown2, /*19^16^19^0*/ + AugTypeOrnamentation, /*20^16^20 (Ornamentation)^0*/ + AugTypeSpecialOrnamentation, /*21^16^21 (Special Ornamentation)^0*/ + AugTypeUnknown3, /*22^16^22^0*/ + AugTypeUnknown4, /*23^16^23^0*/ + AugTypeUnknown5, /*24^16^24^0*/ + AugTypeUnknown6, /*25^16^25^0*/ + AugTypeUnknown7, /*26^16^26^0*/ + AugTypeUnknown8, /*27^16^27^0*/ + AugTypeUnknown9, /*28^16^28^0*/ + AugTypeUnknown10, /*29^16^29^0*/ + AugTypeEpic25, /*30^16^30^0*/ + AugTypeTest, /*31^16^Test^0*/ // listed as 31^16^31^0 in 5-10 client + _AugTypeCount +}; + +/* +** Augmentation restriction types (in-work) +** +** (ref: eqstr_us.txt) +** +*/ +enum AugmentationRestrictionTypes : uint8 { +/*4690*/ AugRestrAny = 0, +/*9134*/ AugRestrArmor, +/*9135*/ AugRestrWeapons, +/*9136*/ AugRestr1HWeapons, +/*9137*/ AugRestr2HWeapons, +/*9138*/ AugRestr1HSlash, +/*9139*/ AugRestr1HBlunt, +/*9140*/ AugRestrPiercing, +/*9148*/ AugRestrHandToHand, +/*9141*/ AugRestr2HSlash, +/*9142*/ AugRestr2HBlunt, +/*9143*/ AugRestr2HPierce, +/*9144*/ AugRestrBows, +/*9145*/ AugRestrShields, +/*8052*/ AugRestr1HSlash1HBluntOrHandToHand, +/*9200*/ AugRestr1HBluntOrHandToHand, // no listed peq entries + +// these three appear to be post-RoF (12-10-2012) and can not be verified until RoF (05-10-2013) is supported +/*????*/ AugRestrUnknown1, +/*????*/ AugRestrUnknown2, +/*????*/ AugRestrUnknown3, // last value in peq entries + _AugRestrCount + +/*4687*/ //AugTypeAllItems, // ?? unknown atm +/*4688*/ //AugTypePrestige, // ?? unknown atm +/*4689*/ //AugTypeNonPrestige, // ?? unknown atm +}; + /* ** Container use types ** diff --git a/common/patches/RoF.cpp b/common/patches/RoF.cpp index 07cea6dfb..cbe228c92 100644 --- a/common/patches/RoF.cpp +++ b/common/patches/RoF.cpp @@ -5070,8 +5070,9 @@ char* SerializeItem(const ItemInst *inst, int16 slot_id_in, uint32 *length, uint memset(&isbs, 0, sizeof(RoF::structs::ItemSecondaryBodyStruct)); isbs.augtype = item->AugType; - isbs.augrestrict = item->AugRestrict; isbs.augdistiller = 0; + isbs.augrestrict = item->AugRestrict; + for(int x = 0; x < 5; ++x) { diff --git a/common/patches/RoF_structs.h b/common/patches/RoF_structs.h index a2635ceae..918bbe68d 100644 --- a/common/patches/RoF_structs.h +++ b/common/patches/RoF_structs.h @@ -4427,8 +4427,11 @@ struct AugSlotStruct struct ItemSecondaryBodyStruct { uint32 augtype; - uint32 augrestrict; + // swapped augrestrict and augdistiller positions + // (this swap does show the proper augment restrictions in Item Information window now) + // unsure what the purpose of augdistiller is at this time -U 3/17/2014 uint32 augdistiller; // New to December 10th 2012 client - NEW + uint32 augrestrict; AugSlotStruct augslots[6]; uint32 ldonpoint_type; diff --git a/common/ruletypes.h b/common/ruletypes.h index 83324d533..83db6c3f0 100644 --- a/common/ruletypes.h +++ b/common/ruletypes.h @@ -537,6 +537,12 @@ RULE_BOOL( QueryServ, MerchantLogTransactions, false) // Logs Merchant Transacti RULE_BOOL( QueryServ, PlayerLogPCCoordinates, false) // Logs Player Coordinates with certain events RULE_CATEGORY_END() +RULE_CATEGORY( Inventory ) +RULE_BOOL ( Inventory, EnforceAugmentRestriction, true) // Forces augment slot restrictions +RULE_BOOL ( Inventory, EnforceAugmentUsability, true) // Forces augmented item usability +RULE_BOOL ( Inventory, EnforceAugmentWear, true) // Forces augment wear slot validation +RULE_CATEGORY_END() + #undef RULE_CATEGORY #undef RULE_INT #undef RULE_REAL diff --git a/utils/sql/git/optional/2014_03_17_EnforceAugmentRules.sql b/utils/sql/git/optional/2014_03_17_EnforceAugmentRules.sql new file mode 100644 index 000000000..e89d4a437 --- /dev/null +++ b/utils/sql/git/optional/2014_03_17_EnforceAugmentRules.sql @@ -0,0 +1,3 @@ +INSERT INTO `rule_values` (`ruleset_id`, `rule_name`, `rule_value`, `notes`) VALUES (1, 'Inventory:EnforceAugmentRestriction', 'false', 'Forces augment slot restrictions.'); +INSERT INTO `rule_values` (`ruleset_id`, `rule_name`, `rule_value`, `notes`) VALUES (1, 'Inventory:EnforceAugmentUsability', 'false', 'Forces augmented item usability.'); +INSERT INTO `rule_values` (`ruleset_id`, `rule_name`, `rule_value`, `notes`) VALUES (1, 'Inventory:EnforceAugmentWear', 'false', 'Forces augment wear slot validation.'); \ No newline at end of file diff --git a/zone/client.h b/zone/client.h index 10465dbc6..97ee1b32f 100644 --- a/zone/client.h +++ b/zone/client.h @@ -794,7 +794,7 @@ public: void QSSwapItemAuditor(MoveItem_Struct* move_in, bool postaction_call = false); void PutLootInInventory(int16 slot_id, const ItemInst &inst, ServerLootItem_Struct** bag_item_data = 0); bool AutoPutLootInInventory(ItemInst& inst, bool try_worn = false, bool try_cursor = true, ServerLootItem_Struct** bag_item_data = 0); - void SummonItem(uint32 item_id, int16 charges = -1, uint32 aug1=0, uint32 aug2=0, uint32 aug3=0, uint32 aug4=0, uint32 aug5=0, bool attuned=false, uint16 to_slot=SLOT_CURSOR); + bool SummonItem(uint32 item_id, int16 charges = -1, uint32 aug1=0, uint32 aug2=0, uint32 aug3=0, uint32 aug4=0, uint32 aug5=0, bool attuned=false, uint16 to_slot=SLOT_CURSOR); void SetStats(uint8 type,int16 set_val); void IncStats(uint8 type,int16 increase_val); void DropItem(int16 slot_id); diff --git a/zone/inventory.cpp b/zone/inventory.cpp index 865eaa8e5..c6f1663da 100644 --- a/zone/inventory.cpp +++ b/zone/inventory.cpp @@ -200,124 +200,377 @@ bool Client::CheckLoreConflict(const Item_Struct* item) { return (m_inv.HasItemByLoreGroup(item->LoreGroup, ~invWhereSharedBank) != SLOT_INVALID); } -void Client::SummonItem(uint32 item_id, int16 charges, uint32 aug1, uint32 aug2, uint32 aug3, uint32 aug4, uint32 aug5, bool attuned, uint16 to_slot) { +bool Client::SummonItem(uint32 item_id, int16 charges, uint32 aug1, uint32 aug2, uint32 aug3, uint32 aug4, uint32 aug5, bool attuned, uint16 to_slot) { + // I have 'over-logged' failure messages to aid in any troubleshooting of issues that arise from this change. + // The 'LogFile' code may be taken out once after a period of time with no script/recipe issues. + // + // I have also incorporated a bool return type..but, have not updated any calling methods to process failures. + // Once the APIs are updated, scripts may also be updated. + const Item_Struct* item = database.GetItem(item_id); - if (item == nullptr) { - Message(0, "No such item: %i", item_id); - return; - } else { + if(item == nullptr) { + Message(13, "Item %u does not exist.", item_id); + LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to create an item with an invalid id.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + account_name, GetName(), item->ID, aug1, aug2, aug3, aug4, aug5); + + return false; + } + else { // if the item is stackable and the charge amount is -1 or 0 then set to 1 charge. // removed && item->MaxCharges == 0 if -1 or 0 was passed max charges is irrelevant - if (charges <= 0 && item->Stackable) { + if(charges <= 0 && item->Stackable) charges = 1; - // if the charges is -1, then no charge value was passed in set to max charges - } else if(charges == -1) { - charges = item->MaxCharges; - // in any other situation just use charges as passed - } - } - // Checking to see if the Item is lore or not. - bool foundlore = CheckLoreConflict(item); - //TODO: check for lore conflict on augments + // if the charges is -1, then no charge value was passed in set to max charges + else if(charges == -1) + charges = item->MaxCharges; + + // in any other situation just use charges as passed + } + + // Base item is lore..so, cancel summon + if(CheckLoreConflict(item)) { + // this is the 'you can not pickup another...' message. I don't feel this is appropriate + // for a summoning failure response + // DuplicateLoreMessage(item_id); + Message(13, "You already have a lore %s (%i) in your inventory.", item->Name, item_id); + + return false; + } // Checking to see if it is a GM only Item or not. - //bool foundgm = (item->gm && (this->Admin() < 100)); - bool foundgm = false; + /* + if(item->gm && (this->Admin() < 100)) + Message(0, "You are not a GM and can not summon this item!"); - if (!foundlore && !foundgm) { // Okay, It isn't LORE, or if it is, it is not in player's inventory. - ItemInst* inst = database.CreateItem(item, charges); - if (inst) { - // Corrected the augment references to reflect augment name/id instead of base item name/id - if (aug1) { - const Item_Struct* augitem1 = database.GetItem(aug1); - if (augitem1) { - if (!CheckLoreConflict(augitem1)) { - inst->PutAugment(&database, 0, aug1); - } - else { - Message(0, "You already have a %s (%u) in your inventory - Augment not added!", augitem1->Name, aug1); - } - } - } - if (aug2) { - const Item_Struct* augitem2 = database.GetItem(aug2); - if (augitem2) { - if (!CheckLoreConflict(augitem2)) { - inst->PutAugment(&database, 1, aug2); - } - else { - Message(0, "You already have a %s (%u) in your inventory - Augment not added!", augitem2->Name, aug2); - } - } - } - if (aug3) { - const Item_Struct* augitem3 = database.GetItem(aug3); - if (augitem3) { - if (!CheckLoreConflict(augitem3)) { - inst->PutAugment(&database, 2, aug3); - } - else { - Message(0, "You already have a %s (%u) in your inventory - Augment not added!", augitem3->Name, aug3); - } - } - } - if (aug4) { - const Item_Struct* augitem4 = database.GetItem(aug4); - if (augitem4) { - if (!CheckLoreConflict(augitem4)) { - inst->PutAugment(&database, 3, aug4); - } - else { - Message(0, "You already have a %s (%u) in your inventory - Augment not added!", augitem4->Name, aug4); - } - } - } - if (aug5) { - const Item_Struct* augitem5 = database.GetItem(aug5); - if (augitem5) { - if (!CheckLoreConflict(augitem5)) { - inst->PutAugment(&database, 4, aug5); - } - else { - Message(0, "You already have a %s (%u) in your inventory - Augment not added!", augitem5->Name, aug5); - } - } - } - if (attuned) { - if (inst->GetItem()->Attuneable) { - inst->SetInstNoDrop(true); - } - } - if (to_slot == SLOT_CURSOR) - { - //inst->SetCharges( - PushItemOnCursor(*inst); - // Send item packet to user - SendItemPacket(SLOT_CURSOR, inst, ItemPacketSummonItem); - } - else - { - PutItemInInventory(to_slot, *inst, true); - } - safe_delete(inst); + return false; + */ - if ((RuleB(Character, EnableDiscoveredItems))) - { - if(!GetGM() && !IsDiscovered(item_id)) - DiscoverItem(item_id); + if(((item->ItemClass != ItemClassCommon) || (item->AugType > 0)) && (aug1 | aug2 | aug3 | aug4 | aug5)) { + Message(13, "You can not augment an augment or a non-common class item."); + LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to augment an augment or a non-common class item.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + account_name, GetName(), item->ID, aug1, aug2, aug3, aug4, aug5); + + return false; + } + + uint32 augments[MAX_AUGMENT_SLOTS] = { aug1, aug2, aug3, aug4, aug5 }; + + for(int iter = 0; iter < MAX_AUGMENT_SLOTS; ++iter) { + if(augments[iter] && (database.GetItem(augments[iter]) == nullptr)) { + Message(13, "Augment %u (Aug%i) does not exist.", augments[iter], iter + 1); + LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to create an augment (Aug%i) with an invalid id.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + account_name, GetName(), iter + 1, item->ID, aug1, aug2, aug3, aug4, aug5); + + return false; + } + } + + uint32 classes = item->Classes; + uint32 races = item->Races; + uint32 slots = item->Slots; + + bool enforcewear = RuleB(Inventory, EnforceAugmentWear); + bool enforcerestr = RuleB(Inventory, EnforceAugmentRestriction); + bool enforceusable = RuleB(Inventory, EnforceAugmentUsability); + + for(int iter = 0; iter < MAX_AUGMENT_SLOTS; ++iter) { + const Item_Struct* augtest = database.GetItem(augments[iter]); + + if(augtest) { + if(CheckLoreConflict(augtest)) { + // ditto + // DuplicateLoreMessage(augtest->ID); + Message(13, "You already have a lore %s (%u) in your inventory.", augtest->Name, augtest->ID); + + return false; + } + + /* + if(augtest->gm && (this->Admin() < 100)) { + Message(0, "You are not a GM and can not summon this augment!"); + + return false; + } + */ + + if(augtest->AugType == 0) { + Message(13, "%s (%u) (Aug%i) is not an actual augment.", augtest->Name, augtest->ID, iter + 1); + LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to use a non-augment item (Aug%i) as an augment.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + account_name, GetName(), item->ID, iter + 1, aug1, aug2, aug3, aug4, aug5); + + return false; + } + + if(enforcewear) { + if((item->AugSlotType[iter] == AugTypeNone) || !(((uint32)1 << (item->AugSlotType[iter] - 1)) & augtest->AugType)) { + Message(13, "Augment %u (Aug%i) is not allowed wear on Item %u.", augments[iter], iter + 1, item->ID); + LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to augment an item with a disallowed augment type (Aug%i).\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + account_name, GetName(), iter + 1, item->ID, aug1, aug2, aug3, aug4, aug5); + + return false; + } + } + + if(enforcerestr) { + bool restrictfail = false; + uint8 it = item->ItemType; + + switch(augtest->AugRestrict) { + case AugRestrAny: + break; + case AugRestrArmor: + switch(it) { + case ItemTypeArmor: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestrWeapons: + switch(it) { + case ItemType1HSlash: + case ItemType1HBlunt: + case ItemType1HPiercing: + case ItemTypeMartial: + case ItemType2HSlash: + case ItemType2HBlunt: + case ItemType2HPiercing: + case ItemTypeBow: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestr1HWeapons: + switch(it) { + case ItemType1HSlash: + case ItemType1HBlunt: + case ItemType1HPiercing: + case ItemTypeMartial: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestr2HWeapons: + switch(it) { + case ItemType2HSlash: + case ItemType2HBlunt: + case ItemType2HPiercing: + case ItemTypeBow: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestr1HSlash: + switch(it) { + case ItemType1HSlash: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestr1HBlunt: + switch(it) { + case ItemType1HBlunt: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestrPiercing: + switch(it) { + case ItemType1HPiercing: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestrHandToHand: + switch(it) { + case ItemTypeMartial: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestr2HSlash: + switch(it) { + case ItemType2HSlash: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestr2HBlunt: + switch(it) { + case ItemType2HBlunt: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestr2HPierce: + switch(it) { + case ItemType2HPiercing: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestrBows: + switch(it) { + case ItemTypeBow: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestrShields: + switch(it) { + case ItemTypeShield: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestr1HSlash1HBluntOrHandToHand: + switch(it) { + case ItemType1HSlash: + case ItemType1HBlunt: + case ItemTypeMartial: + break; + default: + restrictfail = true; + break; + } + break; + case AugRestr1HBluntOrHandToHand: + switch(it) { + case ItemType1HBlunt: + case ItemTypeMartial: + break; + default: + restrictfail = true; + break; + } + break; + // These 3 are in-work + case AugRestrUnknown1: + case AugRestrUnknown2: + case AugRestrUnknown3: + default: + restrictfail = true; + break; + } + + if(restrictfail) { + Message(13, "Augment %u (Aug%i) is restricted from wear on Item %u.", augments[iter], iter + 1, item->ID); + LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to augment an item with a restricted augment (Aug%i).\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + account_name, GetName(), iter + 1, item->ID, aug1, aug2, aug3, aug4, aug5); + + return false; + } + } + + if(enforceusable) { + classes &= augtest->Classes; + + if(item->Classes && !classes) { + Message(13, "Augment %u (Aug%i) will result in an item not usable by any class.", augments[iter], iter + 1); + LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to create an item unusable by any class.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + account_name, GetName(), item->ID, aug1, aug2, aug3, aug4, aug5); + + return false; + } + + races &= augtest->Races; + + if(item->Races && !races) { + Message(13, "Augment %u (Aug%i) will result in an item not usable by any race.", augments[iter], iter + 1); + LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to create an item unusable by any race.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + account_name, GetName(), item->ID, aug1, aug2, aug3, aug4, aug5); + + return false; + } + + slots &= augtest->Slots; + + if(item->Slots && !slots) { + Message(13, "Augment %u (Aug%i) will result in an item not usable in any slot.", augments[iter], iter + 1); + LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to create an item unusable in any slot.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + account_name, GetName(), item->ID, aug1, aug2, aug3, aug4, aug5); + + return false; + } } } } - else { // Item was already in inventory & is a LORE item or was a GM only item. Give them a message about it. - if (foundlore){ - DuplicateLoreMessage(item_id); - //Message(0, "You already have a %s (%i) in your inventory!", item->Name, item_id); - } - else if (foundgm) - Message(0, "You are not a GM to summon this item"); + + // Item is not lore.. + // Item is not GM-Only.. + // Augments are valid and match allowed slots.. + // ..or Augments are valid and do not match allowed slots and.. + // ..EnforceAugmentWear=false and EnforceAugmentRestriction=false and EnforceAugmentUsability=false + + ItemInst* inst = database.CreateItem(item, charges); + + if(inst == nullptr) { + Message(13, "An unknown server error has occurred and your item was not created."); + LogFile->write(EQEMuLog::Error, "Player %s on account %s encountered an unknown item creation error.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + account_name, GetName(), item->ID, aug1, aug2, aug3, aug4, aug5); + + return false; } + + for(int iter = 0; iter < MAX_AUGMENT_SLOTS; ++iter) { + if(augments[iter]) + inst->PutAugment(&database, iter, augments[iter]); + } + + // This may need augment checks as well..left out for now + if(attuned && inst->GetItem()->Attuneable) + inst->SetInstNoDrop(true); + + if(to_slot == SLOT_CURSOR) { + //inst->SetCharges( + PushItemOnCursor(*inst); + // Send item packet to user + SendItemPacket(SLOT_CURSOR, inst, ItemPacketSummonItem); + } + else { + PutItemInInventory(to_slot, *inst, true); + } + + safe_delete(inst); + + if((RuleB(Character, EnableDiscoveredItems)) && !GetGM()) { + if(!IsDiscovered(item_id)) + DiscoverItem(item_id); + + for(int iter = 0; iter < MAX_AUGMENT_SLOTS; ++iter) { + if(augments[iter] && !IsDiscovered(augments[iter])) + DiscoverItem(augments[iter]); + } + } + + return true; } // Drop item from inventory to ground (generally only dropped from SLOT_CURSOR) From 02d6471c888e1bd726a8ab2685a1832c73fb3b1e Mon Sep 17 00:00:00 2001 From: Uleat Date: Tue, 18 Mar 2014 06:00:46 -0400 Subject: [PATCH 4/6] Fix for name/account discrepancy in \\zone\inventory.cpp. Rearranged/condensed code snippets in Client::SummonItem(). Added 'augslotvisible' check to augment validation in C::SI(). --- changelog.txt | 5 ++ zone/inventory.cpp | 199 ++++++++++++++++++++++++--------------------- 2 files changed, 111 insertions(+), 93 deletions(-) diff --git a/changelog.txt b/changelog.txt index 23374f83c..08fc5dd27 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,10 @@ EQEMu Changelog (Started on Sept 24, 2003 15:50) ------------------------------------------------------- +== 03/18/2014 == +Uleat: Fixed the name/account discrepancy in the Client::SummonItem() code as well as the origin of the mistake (thanks K_K!) +Uleat: Condensed and rearranged certain snippets of code in SummonItem(). Added a 'augslotvisible' check to validation check. +Note: If you are experiencing issues with SummonItem, please enable 'INVENTORY_ERROR' logging if it not active on your server. + == 03/17/2014 == Uleat: Updated Client::SummonItem() to check for valid item combinations when augmentations are passed. Uleat: Changed the return type of Client::SummonItem() from void to bool. Calling methods and APIs have not been update as yet. diff --git a/zone/inventory.cpp b/zone/inventory.cpp index c6f1663da..b18514056 100644 --- a/zone/inventory.cpp +++ b/zone/inventory.cpp @@ -201,72 +201,45 @@ bool Client::CheckLoreConflict(const Item_Struct* item) { } bool Client::SummonItem(uint32 item_id, int16 charges, uint32 aug1, uint32 aug2, uint32 aug3, uint32 aug4, uint32 aug5, bool attuned, uint16 to_slot) { - // I have 'over-logged' failure messages to aid in any troubleshooting of issues that arise from this change. - // The 'LogFile' code may be taken out once after a period of time with no script/recipe issues. - // - // I have also incorporated a bool return type..but, have not updated any calling methods to process failures. - // Once the APIs are updated, scripts may also be updated. + // TODO: update calling methods and script apis to handle a failure return const Item_Struct* item = database.GetItem(item_id); + // make sure the item exists if(item == nullptr) { Message(13, "Item %u does not exist.", item_id); - LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to create an item with an invalid id.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", - account_name, GetName(), item->ID, aug1, aug2, aug3, aug4, aug5); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to create an item with an invalid id.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, item->ID, aug1, aug2, aug3, aug4, aug5); return false; } - else { - // if the item is stackable and the charge amount is -1 or 0 then set to 1 charge. - // removed && item->MaxCharges == 0 if -1 or 0 was passed max charges is irrelevant - if(charges <= 0 && item->Stackable) - charges = 1; - - // if the charges is -1, then no charge value was passed in set to max charges - else if(charges == -1) - charges = item->MaxCharges; - - // in any other situation just use charges as passed - } - - // Base item is lore..so, cancel summon - if(CheckLoreConflict(item)) { - // this is the 'you can not pickup another...' message. I don't feel this is appropriate - // for a summoning failure response + // check that there is not a lore conflict between base item and existing inventory + else if(CheckLoreConflict(item)) { // DuplicateLoreMessage(item_id); Message(13, "You already have a lore %s (%i) in your inventory.", item->Name, item_id); return false; } + // check to make sure we are augmenting an augmentable item + else if(((item->ItemClass != ItemClassCommon) || (item->AugType > 0)) && (aug1 | aug2 | aug3 | aug4 | aug5)) { + Message(13, "You can not augment an augment or a non-common class item."); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to augment an augment or a non-common class item.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, item->ID, aug1, aug2, aug3, aug4, aug5); - // Checking to see if it is a GM only Item or not. + return false; + } + // check to make sure we are a GM if the item is GM-only /* - if(item->gm && (this->Admin() < 100)) - Message(0, "You are not a GM and can not summon this item!"); + else if(item->gm && (this->Admin() < 100)) + Message(13, "You are not a GM and can not summon this item."); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to create a GM-only item with a status of %i.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, this->Admin(), item->ID, aug1, aug2, aug3, aug4, aug5); return false; */ - if(((item->ItemClass != ItemClassCommon) || (item->AugType > 0)) && (aug1 | aug2 | aug3 | aug4 | aug5)) { - Message(13, "You can not augment an augment or a non-common class item."); - LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to augment an augment or a non-common class item.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", - account_name, GetName(), item->ID, aug1, aug2, aug3, aug4, aug5); - - return false; - } - uint32 augments[MAX_AUGMENT_SLOTS] = { aug1, aug2, aug3, aug4, aug5 }; - for(int iter = 0; iter < MAX_AUGMENT_SLOTS; ++iter) { - if(augments[iter] && (database.GetItem(augments[iter]) == nullptr)) { - Message(13, "Augment %u (Aug%i) does not exist.", augments[iter], iter + 1); - LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to create an augment (Aug%i) with an invalid id.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", - account_name, GetName(), iter + 1, item->ID, aug1, aug2, aug3, aug4, aug5); - - return false; - } - } - uint32 classes = item->Classes; uint32 races = item->Races; uint32 slots = item->Slots; @@ -278,41 +251,62 @@ bool Client::SummonItem(uint32 item_id, int16 charges, uint32 aug1, uint32 aug2, for(int iter = 0; iter < MAX_AUGMENT_SLOTS; ++iter) { const Item_Struct* augtest = database.GetItem(augments[iter]); - if(augtest) { + if(augtest == nullptr) { + if(augments[iter]) { + Message(13, "Augment %u (Aug%i) does not exist.", augments[iter], iter + 1); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to create an augment (Aug%i) with an invalid id.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, (iter + 1), item->ID, aug1, aug2, aug3, aug4, aug5); + + return false; + } + } + else { + // check that there is not a lore conflict between augment and existing inventory if(CheckLoreConflict(augtest)) { - // ditto // DuplicateLoreMessage(augtest->ID); Message(13, "You already have a lore %s (%u) in your inventory.", augtest->Name, augtest->ID); return false; } - + // check that augment is an actual augment + else if(augtest->AugType == 0) { + Message(13, "%s (%u) (Aug%i) is not an actual augment.", augtest->Name, augtest->ID, iter + 1); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to use a non-augment item (Aug%i) as an augment.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, item->ID, (iter + 1), aug1, aug2, aug3, aug4, aug5); + + return false; + } + // check to make sure we are a GM if the augment is GM-only /* - if(augtest->gm && (this->Admin() < 100)) { - Message(0, "You are not a GM and can not summon this augment!"); + else if(augtest->gm && (this->Admin() < 100)) { + Message(13, "You are not a GM and can not summon this augment."); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to create a GM-only augment (Aug%i) with a status of %i.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, (iter + 1), this->Admin(), item->ID, aug1, aug2, aug3, aug4, aug5); return false; } */ - if(augtest->AugType == 0) { - Message(13, "%s (%u) (Aug%i) is not an actual augment.", augtest->Name, augtest->ID, iter + 1); - LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to use a non-augment item (Aug%i) as an augment.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", - account_name, GetName(), item->ID, iter + 1, aug1, aug2, aug3, aug4, aug5); - - return false; - } - + // check for augment type allowance if(enforcewear) { if((item->AugSlotType[iter] == AugTypeNone) || !(((uint32)1 << (item->AugSlotType[iter] - 1)) & augtest->AugType)) { - Message(13, "Augment %u (Aug%i) is not allowed wear on Item %u.", augments[iter], iter + 1, item->ID); - LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to augment an item with a disallowed augment type (Aug%i).\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", - account_name, GetName(), iter + 1, item->ID, aug1, aug2, aug3, aug4, aug5); + Message(13, "Augment %u (Aug%i) is not acceptable wear on Item %u.", augments[iter], iter + 1, item->ID); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to augment an item with an unacceptable augment type (Aug%i).\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, (iter + 1), item->ID, aug1, aug2, aug3, aug4, aug5); + + return false; + } + + if(item->AugSlotVisible[iter] == 0) { + Message(13, "Item %u has not evolved enough to accept Augment %u (Aug%i).", item->ID, augments[iter], iter + 1); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to augment an unevolved item with augment type (Aug%i).\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, (iter + 1), item->ID, aug1, aug2, aug3, aug4, aug5); return false; } } + // check for augment to item restriction if(enforcerestr) { bool restrictfail = false; uint8 it = item->ItemType; @@ -481,41 +475,38 @@ bool Client::SummonItem(uint32 item_id, int16 charges, uint32 aug1, uint32 aug2, } if(restrictfail) { - Message(13, "Augment %u (Aug%i) is restricted from wear on Item %u.", augments[iter], iter + 1, item->ID); - LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to augment an item with a restricted augment (Aug%i).\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", - account_name, GetName(), iter + 1, item->ID, aug1, aug2, aug3, aug4, aug5); + Message(13, "Augment %u (Aug%i) is restricted from wear on Item %u.", augments[iter], (iter + 1), item->ID); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to augment an item with a restricted augment (Aug%i).\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, (iter + 1), item->ID, aug1, aug2, aug3, aug4, aug5); return false; } } if(enforceusable) { - classes &= augtest->Classes; - - if(item->Classes && !classes) { - Message(13, "Augment %u (Aug%i) will result in an item not usable by any class.", augments[iter], iter + 1); - LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to create an item unusable by any class.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", - account_name, GetName(), item->ID, aug1, aug2, aug3, aug4, aug5); + // check for class usability + if(item->Classes && !(classes &= augtest->Classes)) { + Message(13, "Augment %u (Aug%i) will result in an item not usable by any class.", augments[iter], (iter + 1)); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to create an item unusable by any class.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, item->ID, aug1, aug2, aug3, aug4, aug5); return false; } - races &= augtest->Races; - - if(item->Races && !races) { - Message(13, "Augment %u (Aug%i) will result in an item not usable by any race.", augments[iter], iter + 1); - LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to create an item unusable by any race.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", - account_name, GetName(), item->ID, aug1, aug2, aug3, aug4, aug5); + // check for race usability + if(item->Races && !(races &= augtest->Races)) { + Message(13, "Augment %u (Aug%i) will result in an item not usable by any race.", augments[iter], (iter + 1)); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to create an item unusable by any race.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, item->ID, aug1, aug2, aug3, aug4, aug5); return false; } - slots &= augtest->Slots; - - if(item->Slots && !slots) { - Message(13, "Augment %u (Aug%i) will result in an item not usable in any slot.", augments[iter], iter + 1); - LogFile->write(EQEMuLog::Error, "Player %s on account %s attempted to create an item unusable in any slot.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", - account_name, GetName(), item->ID, aug1, aug2, aug3, aug4, aug5); + // check for slot usability + if(item->Slots && !(slots &= augtest->Slots)) { + Message(13, "Augment %u (Aug%i) will result in an item not usable in any slot.", augments[iter], (iter + 1)); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to create an item unusable in any slot.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, item->ID, aug1, aug2, aug3, aug4, aug5); return false; } @@ -523,35 +514,56 @@ bool Client::SummonItem(uint32 item_id, int16 charges, uint32 aug1, uint32 aug2, } } - // Item is not lore.. - // Item is not GM-Only.. - // Augments are valid and match allowed slots.. - // ..or Augments are valid and do not match allowed slots and.. - // ..EnforceAugmentWear=false and EnforceAugmentRestriction=false and EnforceAugmentUsability=false + // validation passed..so, set the charges and create the actual item + + // if the item is stackable and the charge amount is -1 or 0 then set to 1 charge. + // removed && item->MaxCharges == 0 if -1 or 0 was passed max charges is irrelevant + if(charges <= 0 && item->Stackable) + charges = 1; + + // if the charges is -1, then no charge value was passed in set to max charges + else if(charges == -1) + charges = item->MaxCharges; + + // in any other situation just use charges as passed ItemInst* inst = database.CreateItem(item, charges); if(inst == nullptr) { Message(13, "An unknown server error has occurred and your item was not created."); + // this goes to logfile since this is a major error LogFile->write(EQEMuLog::Error, "Player %s on account %s encountered an unknown item creation error.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", - account_name, GetName(), item->ID, aug1, aug2, aug3, aug4, aug5); + GetName(), account_name, item->ID, aug1, aug2, aug3, aug4, aug5); return false; } + // add any validated augments for(int iter = 0; iter < MAX_AUGMENT_SLOTS; ++iter) { if(augments[iter]) inst->PutAugment(&database, iter, augments[iter]); } - // This may need augment checks as well..left out for now + // attune item if(attuned && inst->GetItem()->Attuneable) inst->SetInstNoDrop(true); + // check to see if item is usable in requested slot + if(enforceusable && (((to_slot >= 0) && (to_slot <= 21)) || (to_slot == 9999))) { + uint32 slottest = (to_slot == 9999) ? 22 : to_slot; + + if(!(slots & ((uint32)1 << slottest))) { + Message(0, "This item is not equipable at slot %u - moving to cursor.", to_slot); + mlog(INVENTORY__ERROR, "Player %s on account %s attempted to equip an item unusable in slot %u - moved to cursor.\n(Item: %u, Aug1: %u, Aug2: %u, Aug3: %u, Aug4: %u, Aug5: %u)\n", + GetName(), account_name, to_slot, item->ID, aug1, aug2, aug3, aug4, aug5); + + to_slot = SLOT_CURSOR; + } + } + + // put item into inventory if(to_slot == SLOT_CURSOR) { - //inst->SetCharges( PushItemOnCursor(*inst); - // Send item packet to user SendItemPacket(SLOT_CURSOR, inst, ItemPacketSummonItem); } else { @@ -560,6 +572,7 @@ bool Client::SummonItem(uint32 item_id, int16 charges, uint32 aug1, uint32 aug2, safe_delete(inst); + // discover item and any augments if((RuleB(Character, EnableDiscoveredItems)) && !GetGM()) { if(!IsDiscovered(item_id)) DiscoverItem(item_id); @@ -1373,7 +1386,7 @@ bool Client::SwapItem(MoveItem_Struct* move_in) { //verify shared bank transactions in the database if(src_inst && src_slot_id >= 2500 && src_slot_id <= 2550) { if(!database.VerifyInventory(account_id, src_slot_id, src_inst)) { - LogFile->write(EQEMuLog::Error, "Player %s on account %s was found exploiting the shared bank.\n", account_name, GetName()); + LogFile->write(EQEMuLog::Error, "Player %s on account %s was found exploiting the shared bank.\n", GetName(), account_name); DeleteItemInInventory(dst_slot_id,0,true); return(false); } @@ -1388,7 +1401,7 @@ bool Client::SwapItem(MoveItem_Struct* move_in) { } if(dst_inst && dst_slot_id >= 2500 && dst_slot_id <= 2550) { if(!database.VerifyInventory(account_id, dst_slot_id, dst_inst)) { - LogFile->write(EQEMuLog::Error, "Player %s on account %s was found exploting the shared bank.\n", account_name, GetName()); + LogFile->write(EQEMuLog::Error, "Player %s on account %s was found exploting the shared bank.\n", GetName(), account_name); DeleteItemInInventory(src_slot_id,0,true); return(false); } From 3054a4c307a110ddee17d359c23d61d1c0b96f35 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Wed, 18 Jun 2014 15:58:26 -0700 Subject: [PATCH 5/6] Database interface improvement with stl style iterators --- common/CMakeLists.txt | 4 ++ common/MySQLRequestResult.cpp | 103 ++++++++++++++++++++++++++++++++++ common/MySQLRequestResult.h | 54 ++++++++++++++++++ common/MySQLRequestRow.cpp | 54 ++++++++++++++++++ common/MySQLRequestRow.h | 37 ++++++++++++ common/dbcore.cpp | 79 +++++++++++++++++++++++++- common/dbcore.h | 4 +- 7 files changed, 333 insertions(+), 2 deletions(-) create mode 100644 common/MySQLRequestResult.cpp create mode 100644 common/MySQLRequestResult.h create mode 100644 common/MySQLRequestRow.cpp create mode 100644 common/MySQLRequestRow.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a63563983..35cb7eb7f 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -39,6 +39,8 @@ SET(common_sources MiscFunctions.cpp moremath.cpp Mutex.cpp + MySQLRequestResult.cpp + MySQLRequestRow.cpp opcode_map.cpp opcodemgr.cpp packet_dump.cpp @@ -149,6 +151,8 @@ SET(common_headers MiscFunctions.h moremath.h Mutex.h + MySQLRequestResult.h + MySQLRequestRow.h op_codes.h opcode_dispatch.h opcodemgr.h diff --git a/common/MySQLRequestResult.cpp b/common/MySQLRequestResult.cpp new file mode 100644 index 000000000..16d7fe9a0 --- /dev/null +++ b/common/MySQLRequestResult.cpp @@ -0,0 +1,103 @@ +#include "MySQLRequestResult.h" + + +MySQLRequestResult::MySQLRequestResult() + : m_CurrentRow(), m_OneBeyondRow() +{ + ZeroOut(); +} + +MySQLRequestResult::MySQLRequestResult(MYSQL_RES* result, uint32 rowsAffected, uint32 rowCount, uint32 columnCount, uint32 lastInsertedID, uint32 errorNumber, char *errorBuffer) + : m_CurrentRow(result), m_OneBeyondRow() +{ + if (errorBuffer != nullptr) + m_Success = false; + else if (errorBuffer == nullptr && result == nullptr) + { + m_Success = false; + +#ifdef _EQDEBUG + std::cout << "DB Query Error: No Result" << std::endl; +#endif + m_ErrorNumber = UINT_MAX; + m_ErrorBuffer = new char[MYSQL_ERRMSG_SIZE]; + + strcpy(m_ErrorBuffer, "DBcore::RunQuery: No Result"); + } + else + m_Success = true; + + m_Result = result; + m_ErrorBuffer = errorBuffer; + m_RowsAffected = rowsAffected; + m_RowCount = rowCount; + m_ColumnCount = columnCount; + m_LastInsertedID = lastInsertedID; + m_ErrorNumber = errorNumber; +} + +void MySQLRequestResult::FreeInternals() +{ + safe_delete_array(m_ErrorBuffer); + + if (m_Result != nullptr) + mysql_free_result(m_Result); + + ZeroOut(); +} + +void MySQLRequestResult::ZeroOut() +{ + m_Success = false; + m_Result = nullptr; + m_ErrorBuffer = nullptr; + m_RowCount = 0; + m_RowsAffected = 0; + m_LastInsertedID = 0; +} + +MySQLRequestResult::~MySQLRequestResult() +{ + FreeInternals(); +} + +MySQLRequestResult::MySQLRequestResult(MySQLRequestResult&& moveItem) + : m_CurrentRow(moveItem.m_CurrentRow), m_OneBeyondRow() +{ + m_Result = moveItem.m_Result; + m_ErrorBuffer = moveItem.m_ErrorBuffer; + m_Success = moveItem.m_Success; + m_RowCount = moveItem.m_RowCount; + m_RowsAffected = moveItem.m_RowsAffected; + m_LastInsertedID = moveItem.m_LastInsertedID; + + // Keeps deconstructor from double freeing + // pre move instance. + moveItem.ZeroOut(); +} + +MySQLRequestResult& MySQLRequestResult::operator=(MySQLRequestResult&& other) +{ + // Assigning something to itself? + // Silly! (but happens) + if (this == &other) + return *this; + + FreeInternals(); + + m_Success = other.m_Success; + + m_Result = other.m_Result; + m_ErrorBuffer = other.m_ErrorBuffer; + + m_RowCount = other.m_RowCount; + m_RowsAffected = other.m_RowsAffected; + m_LastInsertedID = other.m_LastInsertedID; + m_CurrentRow = other.m_CurrentRow; + m_OneBeyondRow = other.m_OneBeyondRow; + + // Keeps deconstructor from double freeing + // pre move instance. + other.ZeroOut(); + return *this; +} \ No newline at end of file diff --git a/common/MySQLRequestResult.h b/common/MySQLRequestResult.h new file mode 100644 index 000000000..807efdfc0 --- /dev/null +++ b/common/MySQLRequestResult.h @@ -0,0 +1,54 @@ +#ifndef MYSQL_REQUEST_RESULT_H +#define MYSQL_REQUEST_RESULT_H + +#ifdef _WINDOWS + #include + #include +#endif + +#include +#include <../common/types.h> +#include <../common/MySQLRequestRow.h> +#include + +class MySQLRequestResult { +private: + MYSQL_RES* m_Result; + char* m_ErrorBuffer; + MySQLRequestRow m_CurrentRow; + MySQLRequestRow m_OneBeyondRow; + + bool m_Success; + uint32 m_RowsAffected; + uint32 m_RowCount; + uint32 m_ColumnCount; + uint32 m_LastInsertedID; + uint32 m_ErrorNumber; + + +public: + + MySQLRequestResult(MYSQL_RES* result, uint32 rowsAffected = 0, uint32 rowCount = 0, uint32 columnCount = 0, uint32 lastInsertedID = 0, uint32 errorNumber = 0, char *errorBuffer = nullptr); + MySQLRequestResult(); + MySQLRequestResult(MySQLRequestResult&& moveItem); + ~MySQLRequestResult(); + + MySQLRequestResult& operator=(MySQLRequestResult&& other); + + bool Success() const { return m_Success;} + std::string ErrorMessage() const {return std::string(m_ErrorBuffer);} + uint32 ErrorNumber() const {return m_ErrorNumber;} + uint32 RowsAffected() const {return m_RowsAffected;} + uint32 RowCount() const {return m_RowCount;} + uint32 ColumnCount() const {return m_ColumnCount;} + + MySQLRequestRow& begin() { return m_CurrentRow; } + MySQLRequestRow& end() { return m_OneBeyondRow;} + +private: + void FreeInternals(); + void ZeroOut(); +}; + + +#endif \ No newline at end of file diff --git a/common/MySQLRequestRow.cpp b/common/MySQLRequestRow.cpp new file mode 100644 index 000000000..5fc4a40e8 --- /dev/null +++ b/common/MySQLRequestRow.cpp @@ -0,0 +1,54 @@ +#include "MySQLRequestRow.h" + +MySQLRequestRow::MySQLRequestRow(const MySQLRequestRow& row) + : m_Result(row.m_Result), m_MySQLRow(row.m_MySQLRow) +{ +} + +MySQLRequestRow::MySQLRequestRow() + : m_Result(nullptr), m_MySQLRow(nullptr) +{ +} + +MySQLRequestRow::MySQLRequestRow(MySQLRequestRow&& moveItem) +{ + m_Result = moveItem.m_Result; + m_MySQLRow = moveItem.m_MySQLRow; + + moveItem.m_Result = nullptr; + moveItem.m_MySQLRow = nullptr; +} + +MySQLRequestRow::MySQLRequestRow(MYSQL_RES *result) + : m_Result(result), m_MySQLRow(mysql_fetch_row(m_Result)) +{ +} + +MySQLRequestRow& MySQLRequestRow::operator++() +{ + m_MySQLRow = mysql_fetch_row(m_Result); + return *this; +} + +MySQLRequestRow MySQLRequestRow::operator++(int) +{ + MySQLRequestRow tmp(*this); + operator++(); + return tmp; +} + +bool MySQLRequestRow::operator==(const MySQLRequestRow& rhs) +{ + return m_MySQLRow == rhs.m_MySQLRow; +} + +bool MySQLRequestRow::operator!=(const MySQLRequestRow& rhs) +{ + return m_MySQLRow != rhs.m_MySQLRow; +} + +char* MySQLRequestRow::operator[](int index) +{ + + return m_MySQLRow[index]; +} \ No newline at end of file diff --git a/common/MySQLRequestRow.h b/common/MySQLRequestRow.h new file mode 100644 index 000000000..615a75371 --- /dev/null +++ b/common/MySQLRequestRow.h @@ -0,0 +1,37 @@ +#ifndef MYSQL_REQUEST_ROW_H +#define MYSQL_REQUEST_ROW_H + +#ifdef _WINDOWS + #include + #include +#endif + +#include +#include +#include <../common/types.h> + +class MySQLRequestRow : public std::iterator +{ + +private: + MYSQL_RES* m_Result; + MYSQL_ROW m_MySQLRow; + +public: + + MySQLRequestRow(); + MySQLRequestRow(MYSQL_RES *result); + MySQLRequestRow(const MySQLRequestRow& row); + MySQLRequestRow(MySQLRequestRow&& moveItem); + MySQLRequestRow& operator++(); + MySQLRequestRow operator++(int); + bool operator==(const MySQLRequestRow& rhs); + bool operator!=(const MySQLRequestRow& rhs); + + char* operator[](int index); + +}; + + + +#endif \ No newline at end of file diff --git a/common/dbcore.cpp b/common/dbcore.cpp index a2c6bc7f8..ce1b41bdc 100644 --- a/common/dbcore.cpp +++ b/common/dbcore.cpp @@ -58,6 +58,83 @@ void DBcore::ping() { MDatabase.unlock(); } +MySQLRequestResult DBcore::QueryDatabase(const char* query, uint32 querylen, bool retryOnFailureOnce) +{ + LockMutex lock(&MDatabase); + + // Reconnect if we are not connected before hand. + if (pStatus != Connected) + Open(); + + // request query. != 0 indicates some kind of error. + if (mysql_real_query(&mysql, query, querylen) != 0) + { + unsigned int errorNumber = mysql_errno(&mysql); + + if (errorNumber == CR_SERVER_GONE_ERROR) + pStatus = Error; + + // error appears to be a disconnect error, may need to try again. + if (errorNumber == CR_SERVER_LOST || errorNumber == CR_SERVER_GONE_ERROR) + { + + if (retryOnFailureOnce) + { + std::cout << "Database Error: Lost connection, attempting to recover...." << std::endl; + MySQLRequestResult requestResult = QueryDatabase(query, querylen, false); + + if (requestResult.Success()) + { + std::cout << "Reconnection to database successful." << std::endl; + return requestResult; + } + + } + + pStatus = Error; + + char *errorBuffer = new char[MYSQL_ERRMSG_SIZE]; + + snprintf(errorBuffer, MYSQL_ERRMSG_SIZE, "#%i: %s", mysql_errno(&mysql), mysql_error(&mysql)); + + std::cout << "DB Query Error #" << mysql_errno(&mysql) << ": " << mysql_error(&mysql) << std::endl; + + return MySQLRequestResult(nullptr, 0, 0, 0, 0, (uint32)mysql_errno(&mysql), errorBuffer); + } + + char *errorBuffer = new char[MYSQL_ERRMSG_SIZE]; + snprintf(errorBuffer, MYSQL_ERRMSG_SIZE, "#%i: %s", mysql_errno(&mysql), mysql_error(&mysql)); + +#ifdef _EQDEBUG + std::cout << "DB Query Error #" << mysql_errno(&mysql) << ": " << mysql_error(&mysql) << std::endl; +#endif + return MySQLRequestResult(nullptr, 0, 0, 0, 0, mysql_errno(&mysql),errorBuffer); + + } + + // successful query. get results. + MYSQL_RES* res = mysql_store_result(&mysql); + MySQLRequestResult requestResult(res, (uint32)mysql_affected_rows(&mysql), (uint32)mysql_num_rows(res), (uint32)mysql_field_count(&mysql), (uint32)mysql_insert_id(&mysql)); + + +#if DEBUG_MYSQL_QUERIES >= 1 + if (requestResult.Success()) + { + std::cout << "query successful"; + if (requestResult.Result()) + std::cout << ", " << (int) mysql_num_rows(requestResult.Result()) << " rows returned"; + + std::cout << ", " << requestResult.RowCount() << " rows affected"; + std::cout<< std::endl; + } + else { + std::cout << "QUERY: query FAILED" << std::endl; + } +#endif + + return requestResult; +} + bool DBcore::RunQuery(const char* query, uint32 querylen, char* errbuf, MYSQL_RES** result, uint32* affected_rows, uint32* last_insert_id, uint32* errnum, bool retry) { if (errnum) *errnum = 0; @@ -111,7 +188,7 @@ bool DBcore::RunQuery(const char* query, uint32 querylen, char* errbuf, MYSQL_RE if (affected_rows) *affected_rows = mysql_affected_rows(&mysql); if (last_insert_id) - *last_insert_id = mysql_insert_id(&mysql); + *last_insert_id = (uint32)mysql_insert_id(&mysql); if (result) { if (*result) { ret = true; diff --git a/common/dbcore.h b/common/dbcore.h index ed5e62133..13a395eac 100644 --- a/common/dbcore.h +++ b/common/dbcore.h @@ -4,8 +4,8 @@ #ifdef _WINDOWS #include #include - //#include #endif + #include #include "../common/types.h" #include "../common/Mutex.h" @@ -13,6 +13,7 @@ #include "../common/queue.h" #include "../common/timer.h" #include "../common/Condition.h" +#include "../common/MySQLRequestResult.h" class DBcore { public: @@ -22,6 +23,7 @@ public: ~DBcore(); eStatus GetStatus() { return pStatus; } bool RunQuery(const char* query, uint32 querylen, char* errbuf = 0, MYSQL_RES** result = 0, uint32* affected_rows = 0, uint32* last_insert_id = 0, uint32* errnum = 0, bool retry = true); + MySQLRequestResult QueryDatabase(const char* query, uint32 querylen, bool retryOnFailureOnce = true); uint32 DoEscapeString(char* tobuf, const char* frombuf, uint32 fromlen); void ping(); MYSQL* getMySQL(){ return &mysql; } From 2734307ba270424f17bd119c6c4a70da0cedc053 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 3 Jul 2014 15:48:17 -0700 Subject: [PATCH 6/6] Added LastInsertID() to MySQLRequestResult --- common/MySQLRequestResult.h | 1 + 1 file changed, 1 insertion(+) diff --git a/common/MySQLRequestResult.h b/common/MySQLRequestResult.h index 807efdfc0..ef2dcd104 100644 --- a/common/MySQLRequestResult.h +++ b/common/MySQLRequestResult.h @@ -41,6 +41,7 @@ public: uint32 RowsAffected() const {return m_RowsAffected;} uint32 RowCount() const {return m_RowCount;} uint32 ColumnCount() const {return m_ColumnCount;} + uint32 LastInsertedID() const {return m_LastInsertedID;} MySQLRequestRow& begin() { return m_CurrentRow; } MySQLRequestRow& end() { return m_OneBeyondRow;}