diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game/Channel.cpp | 124 | ||||
-rw-r--r-- | src/game/Channel.h | 4 | ||||
-rw-r--r-- | src/game/DBCStructure.h | 6 | ||||
-rw-r--r-- | src/game/DBCfmt.h | 2 | ||||
-rw-r--r-- | src/game/Item.cpp | 39 | ||||
-rw-r--r-- | src/game/Item.h | 3 | ||||
-rw-r--r-- | src/game/Player.cpp | 6 | ||||
-rw-r--r-- | src/game/Unit.cpp | 20 | ||||
-rw-r--r-- | src/game/World.cpp | 12 |
9 files changed, 119 insertions, 97 deletions
diff --git a/src/game/Channel.cpp b/src/game/Channel.cpp index c7155d7d2b1..768b8865eb0 100644 --- a/src/game/Channel.cpp +++ b/src/game/Channel.cpp @@ -24,9 +24,8 @@ #include "World.h" Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team) - : m_name(name), m_announce(true), m_moderate(false), m_channelId(channel_id), m_ownerGUID(0), m_password(""), m_flags(0) + : m_name(name), m_announce(true), m_moderate(false), m_channelId(channel_id), m_ownerGUID(0), m_password(""), m_flags(0), m_Team(Team) { - m_Team = Team; // set special flags if built-in channel ChatChannelsEntry const* ch = GetChannelEntryFor(channel_id); if(ch) // it's built-in channel @@ -52,7 +51,9 @@ Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team) { m_flags |= CHANNEL_FLAG_CUSTOM; //load not built in channel if saved - QueryResult *result = CharacterDatabase.PQuery("SELECT m_name, m_team, m_announce, m_moderate, m_password, BannedList FROM channels WHERE m_name = '%s' AND m_team = '%u'", name.c_str(), m_Team); + std::string _name(name); + CharacterDatabase.escape_string(_name); + QueryResult *result = CharacterDatabase.PQuery("SELECT m_name, m_team, m_announce, m_moderate, m_password, BannedList FROM channels WHERE m_name = '%s' AND m_team = '%u'", _name.c_str(), m_Team); if (result)//load { Field *fields = result->Fetch(); @@ -65,7 +66,7 @@ Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team) m_IsSaved = true; - if(db_BannedList) + if (db_BannedList) { Tokens tokens = StrSplit(db_BannedList, " "); Tokens::iterator iter; @@ -79,11 +80,12 @@ Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team) } } } - }else{//save - std::ostringstream ss; - ss << "INSERT INTO channels (m_name,m_team,m_announce,m_moderate,m_password) VALUES ('" - << name.c_str() << "','" << m_Team << "','1','0','')"; - if(CharacterDatabase.PExecute( ss.str( ).c_str( ) )) + } + else // save + { + // _name is already escaped at this point. + if (CharacterDatabase.PExecute("INSERT INTO channels (m_name, m_team, m_announce, m_moderate, m_password) " + "VALUES ('%s', '%u', '1', '0', '')", _name.c_str(), m_Team)) { sLog.outDebug("New Channel(%s) saved", name.c_str()); m_IsSaved = true; @@ -92,6 +94,41 @@ Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team) } } +bool Channel::_UpdateStringInDB(const std::string& colName, const std::string& colValue) const +{ + // Prevent SQL-injection + std::string _name(m_name); + std::string _colValue(colValue); + CharacterDatabase.escape_string(_colValue); + CharacterDatabase.escape_string(_name); + return CharacterDatabase.PExecute("UPDATE channels SET %s = '%s' WHERE m_name = '%s' AND m_team = '%u'", + colName.c_str(), _colValue.c_str(), _name.c_str(), m_Team); +} + +bool Channel::_UpdateIntInDB(const std::string& colName, int colValue) const +{ + // Prevent SQL-injection + std::string _name(m_name); + CharacterDatabase.escape_string(_name); + return CharacterDatabase.PExecute("UPDATE channels SET %s = '%u' WHERE m_name = '%s' AND m_team = '%u'", + colName.c_str(), colValue, _name.c_str(), m_Team); +} + +void Channel::_UpdateBanListInDB() const +{ + // save banlist + if (m_IsSaved) + { + std::ostringstream banlist; + BannedList::const_iterator iter; + for (iter = banned.begin(); iter != banned.end(); ++iter) + banlist << (*iter) << " "; + std::string banListStr = banlist.str(); + if (_UpdateStringInDB("BannedList", banListStr)) + sLog.outDebug("Channel(%s) BannedList saved", m_name.c_str()); + } +} + void Channel::Join(uint64 p, const char *pass) { WorldPacket data; @@ -260,23 +297,7 @@ void Channel::KickOrBan(uint64 good, const char *badname, bool ban) { banned.insert(bad->GetGUID()); MakePlayerBanned(&data, bad->GetGUID(), good); - //save banlist - if(m_IsSaved) - { - std::ostringstream banlist; - BannedList::iterator iter; - for (iter = banned.begin(); iter != banned.end(); ++iter) - { - banlist << (*iter) << " "; - } - std::ostringstream ss; - ss << "UPDATE channels SET BannedList = '" << banlist.str().c_str() << "' WHERE m_name = '"<<m_name.c_str()<<"' AND m_team = '"<<m_Team<<"'"; - if(CharacterDatabase.PExecute( ss.str( ).c_str( ) )) - { - sLog.outDebug("Channel(%s) BannedList saved", m_name.c_str()); - } - } - + _UpdateBanListInDB(); } else MakePlayerKicked(&data, bad->GetGUID(), good); @@ -330,22 +351,7 @@ void Channel::UnBan(uint64 good, const char *badname) WorldPacket data; MakePlayerUnbanned(&data, bad->GetGUID(), good); SendToAll(&data); - //save banlist - if(m_IsSaved) - { - std::ostringstream banlist; - BannedList::iterator iter; - for (iter = banned.begin(); iter != banned.end(); ++iter) - { - banlist << (*iter) << " "; - } - std::ostringstream ss; - ss << "UPDATE channels SET BannedList = '" << banlist.str().c_str() << "' WHERE m_name = '"<<m_name.c_str()<<"' AND m_team = '"<<m_Team<<"'"; - if(CharacterDatabase.PExecute( ss.str( ).c_str( ) )) - { - sLog.outDebug("Channel(%s) BannedList saved", m_name.c_str()); - } - } + _UpdateBanListInDB(); } } } @@ -376,15 +382,8 @@ void Channel::Password(uint64 p, const char *pass) WorldPacket data; MakePasswordChanged(&data, p); SendToAll(&data); - if(m_IsSaved) - { - std::ostringstream ss; - ss << "UPDATE channels SET m_password = '" << pass << "' WHERE m_name = '"<<m_name.c_str()<<"' AND m_team = '"<<m_Team<<"'"; - if(CharacterDatabase.PExecute( ss.str( ).c_str( ) )) - { - sLog.outDebug("Channel(%s) password saved", m_name.c_str()); - } - } + if (m_IsSaved && _UpdateStringInDB("m_password", m_password)) + sLog.outDebug("Channel(%s) password saved", m_name.c_str()); } } @@ -591,16 +590,8 @@ void Channel::Announce(uint64 p) else MakeAnnouncementsOff(&data, p); SendToAll(&data); - if(m_IsSaved) - { - std::ostringstream ss; - ss << "UPDATE channels SET m_announce = '" << m_announce << "' WHERE m_name = '"<<m_name.c_str()<<"' AND m_team = '"<<m_Team<<"'"; - if(CharacterDatabase.PExecute( ss.str( ).c_str( ) )) - { - sLog.outDebug("Channel(%s) announce saved", m_name.c_str()); - } - } - + if (m_IsSaved && _UpdateIntInDB("m_announce", m_announce ? 1 : 0)) + sLog.outDebug("Channel(%s) announce saved", m_name.c_str()); } } @@ -633,15 +624,8 @@ void Channel::Moderate(uint64 p) else MakeModerationOff(&data, p); SendToAll(&data); - if(m_IsSaved) - { - std::ostringstream ss; - ss << "UPDATE channels SET m_moderate = '" << m_moderate << "' WHERE m_name = '"<<m_name.c_str()<<"' AND m_team = '"<<m_Team<<"'"; - if(CharacterDatabase.PExecute( ss.str( ).c_str( ) )) - { - sLog.outDebug("Channel(%s) moderate saved", m_name.c_str()); - } - } + if (m_IsSaved && _UpdateIntInDB("m_moderate", m_moderate ? 1 : 0)) + sLog.outDebug("Channel(%s) moderate saved", m_name.c_str()); } } diff --git a/src/game/Channel.h b/src/game/Channel.h index 69a1e2f66f6..1e883d3810b 100644 --- a/src/game/Channel.h +++ b/src/game/Channel.h @@ -208,6 +208,10 @@ class Channel bool IsOn(uint64 who) const { return players.find(who) != players.end(); } bool IsBanned(uint64 guid) const { return banned.find(guid) != banned.end(); } + bool _UpdateStringInDB(const std::string& colName, const std::string& colValue) const; + bool _UpdateIntInDB(const std::string& colName, int colValue) const; + void _UpdateBanListInDB() const; + uint8 GetPlayerFlags(uint64 p) const { PlayerList::const_iterator p_itr = players.find(p); diff --git a/src/game/DBCStructure.h b/src/game/DBCStructure.h index 9e44687e867..8c60c28980e 100644 --- a/src/game/DBCStructure.h +++ b/src/game/DBCStructure.h @@ -1536,9 +1536,9 @@ struct SpellItemEnchantmentEntry uint32 slot; // 32 m_flags uint32 GemID; // 33 m_src_itemID uint32 EnchantmentCondition; // 34 m_condition_id - //uint32 requiredSkill; // 35 m_requiredSkillID - //uint32 requiredSkillValue; // 36 m_requiredSkillRank - // 37 new in 3.1 + uint32 requiredSkill; // 35 m_requiredSkillID + uint32 requiredSkillValue; // 36 m_requiredSkillRank + uint32 RequiredLevel; // 37 m_requiredLevel - new in 3.1 }; struct SpellItemEnchantmentConditionEntry diff --git a/src/game/DBCfmt.h b/src/game/DBCfmt.h index 7487ac116a2..0e5fb8b83cf 100644 --- a/src/game/DBCfmt.h +++ b/src/game/DBCfmt.h @@ -90,7 +90,7 @@ const char SpellEntryfmt[]="niiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiifxiiiiii const std::string CustomSpellEntryfmt="pappppppppaaapaaaaaaaaaaapaaapapppppppaaaaapaapaaaaaaaaaaaaaaaaaappppppppppppppppppppppppppppppppppppppppppaaaaaapppppppppaaapppppppppaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaappppppppapppaaaaappaaa"; const std::string CustomSpellEntryIndex = "Id"; const char SpellFocusObjectfmt[]="nxxxxxxxxxxxxxxxxx"; -const char SpellItemEnchantmentfmt[]="nxiiiiiixxxiiissssssssssssssssxiiiixxx"; +const char SpellItemEnchantmentfmt[]="nxiiiiiixxxiiissssssssssssssssxiiiiiii"; const char SpellItemEnchantmentConditionfmt[]="nbbbbbxxxxxbbbbbbbbbbiiiiiXXXXX"; const char SpellRadiusfmt[]="nfxf"; const char SpellRangefmt[]="nffffixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; diff --git a/src/game/Item.cpp b/src/game/Item.cpp index 8174fe7029b..f26106cb452 100644 --- a/src/game/Item.cpp +++ b/src/game/Item.cpp @@ -733,22 +733,37 @@ bool Item::CanBeTraded(bool mail) const return true; } -bool Item::IsBoundByEnchant() const +bool Item::HasEnchantRequiredSkill(const Player *pPlayer) const { - // Check all enchants for soulbound + // Check all enchants for required skill for (uint32 enchant_slot = PERM_ENCHANTMENT_SLOT; enchant_slot < MAX_ENCHANTMENT_SLOT; ++enchant_slot) - { - uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot)); - if(!enchant_id) - continue; + if (uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot))) + if (SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id)) + if (enchantEntry->requiredSkill && pPlayer->GetSkillValue(enchantEntry->requiredSkill) < enchantEntry->requiredSkillValue) + return false; + return true; +} - SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id); - if(!enchantEntry) - continue; +uint32 Item::GetEnchantRequiredLevel() const +{ + uint32 level = 0; + // Check all enchants for required level + for (uint32 enchant_slot = PERM_ENCHANTMENT_SLOT; enchant_slot < MAX_ENCHANTMENT_SLOT; ++enchant_slot) + if (uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot))) + if (SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id)) + if (enchantEntry->RequiredLevel > level) + level = enchantEntry->RequiredLevel; + return level; +} - if(enchantEntry->slot & ENCHANTMENT_CAN_SOULBOUND) - return true; - } +bool Item::IsBoundByEnchant() const +{ + // Check all enchants for soulbound + for (uint32 enchant_slot = PERM_ENCHANTMENT_SLOT; enchant_slot < MAX_ENCHANTMENT_SLOT; ++enchant_slot) + if (uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot))) + if (SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id)) + if (enchantEntry->slot & ENCHANTMENT_CAN_SOULBOUND) + return true; return false; } diff --git a/src/game/Item.h b/src/game/Item.h index 2988707a464..a26b9148f21 100644 --- a/src/game/Item.h +++ b/src/game/Item.h @@ -250,6 +250,9 @@ class TRINITY_DLL_SPEC Item : public Object void SetInTrade(bool b = true) { mb_in_trade = b; } bool IsInTrade() const { return mb_in_trade; } + bool HasEnchantRequiredSkill(const Player *pPlayer) const; + uint32 GetEnchantRequiredLevel() const; + bool IsFitToSpellRequirements(SpellEntry const* spellInfo) const; bool IsTargetValidForItemUse(Unit* pUnitTarget); bool IsLimitedToAnotherMapOrZone( uint32 cur_mapId, uint32 cur_zoneId) const; diff --git a/src/game/Player.cpp b/src/game/Player.cpp index bf9f1f63c62..c6e762d7950 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -10666,6 +10666,12 @@ uint8 Player::CanUseItem( Item *pItem, bool not_loading ) const if (getLevel() < pProto->RequiredLevel) return EQUIP_ERR_CANT_EQUIP_LEVEL_I; + if (getLevel() < pItem->GetEnchantRequiredLevel()) + return EQUIP_ERR_CANT_EQUIP_LEVEL_I; + + if (!pItem->HasEnchantRequiredSkill(this)) + return EQUIP_ERR_NO_REQUIRED_PROFICIENCY; + return EQUIP_ERR_OK; } } diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 6170f2a04fa..884588e0456 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -2066,13 +2066,18 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff else currentAbsorb = RemainingDamage; - float manaMultiplier = (*i)->GetSpellProto()->EffectMultipleValue[(*i)->GetEffIndex()]; - if (Player *modOwner = pVictim->GetSpellModOwner()) - modOwner->ApplySpellMod((*i)->GetId(), SPELLMOD_MULTIPLE_VALUE, manaMultiplier); + if (float manaMultiplier = (*i)->GetSpellProto()->EffectMultipleValue[(*i)->GetEffIndex()]) + { + if(Player *modOwner = pVictim->GetSpellModOwner()) + modOwner->ApplySpellMod((*i)->GetId(), SPELLMOD_MULTIPLE_VALUE, manaMultiplier); + + int32 maxAbsorb = int32(pVictim->GetPower(POWER_MANA) / manaMultiplier); + if (currentAbsorb > maxAbsorb) + currentAbsorb = maxAbsorb; - int32 maxAbsorb = int32(pVictim->GetPower(POWER_MANA) / manaMultiplier); - if (currentAbsorb > maxAbsorb) - currentAbsorb = maxAbsorb; + int32 manaReduction = int32(currentAbsorb * manaMultiplier); + pVictim->ApplyPowerMod(POWER_MANA, manaReduction, false); + } (*i)->SetAmount((*i)->GetAmount()-currentAbsorb); if ((*i)->GetAmount() <= 0) @@ -2081,9 +2086,6 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff next = vManaShield.begin(); } - int32 manaReduction = int32(currentAbsorb * manaMultiplier); - pVictim->ApplyPowerMod(POWER_MANA, manaReduction, false); - RemainingDamage -= currentAbsorb; } diff --git a/src/game/World.cpp b/src/game/World.cpp index ae692c3494a..b343798dbf7 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -250,7 +250,7 @@ World::AddSession_ (WorldSession* s) packet << uint32 (0); // BillingTimeRemaining packet << uint8 (0); // BillingPlanFlags packet << uint32 (0); // BillingTimeRested - packet << uint8 (s->Expansion()); // 0 - normal, 1 - TBC, must be set in database manually for each account + packet << uint8 (s->Expansion()); // 0 - normal, 1 - TBC, 2 - WOTLK, must be set in database manually for each account s->SendPacket (&packet); s->SendAddonsInfo(); @@ -317,7 +317,7 @@ void World::AddQueuedPlayer(WorldSession* sess) packet << uint32 (0); // BillingTimeRemaining packet << uint8 (0); // BillingPlanFlags packet << uint32 (0); // BillingTimeRested - packet << uint8 (sess->Expansion () ? 1 : 0); // 0 - normal, 1 - TBC, must be set in database manually for each account + packet << uint8 (sess->Expansion()); // 0 - normal, 1 - TBC, 2 - WOTLK, must be set in database manually for each account packet << uint32(GetQueuePos (sess)); sess->SendPacket (&packet); @@ -359,6 +359,14 @@ bool World::RemoveQueuedPlayer(WorldSession* sess) WorldSession* pop_sess = m_QueuedPlayer.front(); pop_sess->SetInQueue(false); pop_sess->SendAuthWaitQue(0); + pop_sess->SendAddonsInfo(); + + WorldPacket pkt(SMSG_CLIENTCACHE_VERSION, 4); + pkt << uint32(sWorld.getConfig(CONFIG_CLIENTCACHE_VERSION)); + pop_sess->SendPacket(&pkt); + + pop_sess->SendTutorialsData(); + m_QueuedPlayer.pop_front(); // update iter to point first queued socket or end() if queue is empty now |