[7611] Prevent casting owner spell/use item or gameobject by mind controlled player or creature. Author: VladimirMangos

This also prevent some crashes in like wrong case.
[7610] skipped.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-04-03 16:42:19 -06:00
parent 3d1200f4ac
commit b922da4db1
2 changed files with 74 additions and 14 deletions

View File

@@ -38,6 +38,11 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
CHECK_PACKET_SIZE(recvPacket,1+1+1+4+8+4+1);
Player* pUser = _player;
// ignore for remote control state
if(pUser->m_mover != pUser)
return;
uint8 bagIndex, slot;
uint8 unk_flags; // flags (if 0x02 - some additional data are received)
uint8 cast_count; // next cast if exists (single or not)
@@ -142,6 +147,11 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket)
sLog.outDetail("WORLD: CMSG_OPEN_ITEM packet, data length = %i",(uint32)recvPacket.size());
Player* pUser = _player;
// ignore for remote control state
if(pUser->m_mover != pUser)
return;
uint8 bagIndex, slot;
recvPacket >> bagIndex >> slot;
@@ -219,6 +229,11 @@ void WorldSession::HandleGameObjectUseOpcode( WorldPacket & recv_data )
recv_data >> guid;
sLog.outDebug( "WORLD: Recvd CMSG_GAMEOBJ_USE Message [guid=%u]", GUID_LOPART(guid));
// ignore for remote control state
if(_player->m_mover != _player)
return;
GameObject *obj = ObjectAccessor::GetGameObject(*_player, guid);
if(!obj)
@@ -239,6 +254,10 @@ void WorldSession::HandleGameobjectReportUse(WorldPacket& recvPacket)
sLog.outDebug( "WORLD: Recvd CMSG_GAMEOBJ_REPORT_USE Message [in game guid: %u]", GUID_LOPART(guid));
// ignore for remote control state
if(_player->m_mover != _player)
return;
GameObject* go = ObjectAccessor::GetGameObject(*_player,guid);
if(!go)
return;
@@ -259,6 +278,11 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
recvPacket >> spellId;
recvPacket >> unk_flags; // flags (if 0x02 - some additional data are received)
// ignore for remote control state (for player case)
Unit* mover = _player->m_mover;
if(mover != _player && mover->GetTypeId()==TYPEID_PLAYER)
return;
sLog.outDebug("WORLD: got cast spell packet, spellId - %u, cast_count: %u, unk_flags %u, data length = %i",
spellId, cast_count, unk_flags, (uint32)recvPacket.size());
@@ -270,11 +294,23 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
return;
}
// not have spell in spellbook or spell passive and not casted by client
if ( !_player->HasActiveSpell (spellId) || IsPassiveSpell(spellId) )
if(mover->GetTypeId()==TYPEID_PLAYER)
{
//cheater? kick? ban?
return;
// not have spell in spellbook or spell passive and not casted by client
if (!((Player*)mover)->HasActiveSpell (spellId) || IsPassiveSpell(spellId) )
{
//cheater? kick? ban?
return;
}
}
else
{
// not have spell in spellbook or spell passive and not casted by client
if (!((Creature*)mover)->HasSpell(spellId) || IsPassiveSpell(spellId) )
{
//cheater? kick? ban?
return;
}
}
// can't use our own spells when we're in possession of another unit,
@@ -283,7 +319,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
// client provided targets
SpellCastTargets targets;
if(!targets.read(&recvPacket,_player))
if(!targets.read(&recvPacket,mover))
return;
// auto-selection buff level base at target level (in spellInfo)
@@ -296,7 +332,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
spellInfo = actualSpellInfo;
}
Spell *spell = new Spell(_player, spellInfo, false);
Spell *spell = new Spell(mover, spellInfo, false);
spell->m_cast_count = cast_count; // set count of casts
spell->prepare(&targets);
}
@@ -305,6 +341,11 @@ void WorldSession::HandleCancelCastOpcode(WorldPacket& recvPacket)
{
CHECK_PACKET_SIZE(recvPacket,5);
// ignore for remote control state (for player case)
Unit* mover = _player->m_mover;
if(mover != _player && mover->GetTypeId()==TYPEID_PLAYER)
return;
// increments with every CANCEL packet, don't use for now
uint8 counter;
uint32 spellId;
@@ -315,14 +356,18 @@ void WorldSession::HandleCancelCastOpcode(WorldPacket& recvPacket)
if(spellId==26679)
return;
if(_player->IsNonMeleeSpellCasted(false))
_player->InterruptNonMeleeSpells(false,spellId);
if(mover->IsNonMeleeSpellCasted(false))
mover->InterruptNonMeleeSpells(false,spellId);
}
void WorldSession::HandleCancelAuraOpcode( WorldPacket& recvPacket)
{
CHECK_PACKET_SIZE(recvPacket,4);
// ignore for remote control state
if(_player->m_mover != _player)
return;
uint32 spellId;
recvPacket >> spellId;
@@ -357,6 +402,10 @@ void WorldSession::HandlePetCancelAuraOpcode( WorldPacket& recvPacket)
{
CHECK_PACKET_SIZE(recvPacket, 8+4);
// ignore for remote control state
if(_player->m_mover != _player)
return;
uint64 guid;
uint32 spellId;
@@ -404,7 +453,7 @@ void WorldSession::HandleCancelAutoRepeatSpellOpcode( WorldPacket& /*recvPacket*
{
// may be better send SMSG_CANCEL_AUTO_REPEAT?
// cancel and prepare for deleting
_player->InterruptSpell(CURRENT_AUTOREPEAT_SPELL);
_player->m_mover->InterruptSpell(CURRENT_AUTOREPEAT_SPELL);
}
/// \todo Complete HandleCancelChanneling function
@@ -422,6 +471,10 @@ void WorldSession::HandleTotemDestroy( WorldPacket& recvPacket)
{
CHECK_PACKET_SIZE(recvPacket, 1);
// ignore for remote control state
if(_player->m_mover != _player)
return;
uint8 slotId;
recvPacket >> slotId;