[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
+12 -5
View File
@@ -3072,21 +3072,28 @@ void Aura::HandleAuraModScale(bool apply, bool Real)
m_target->StopMoving(); m_target->StopMoving();
m_target->GetMotionMaster()->Clear(); m_target->GetMotionMaster()->Clear();
m_target->GetMotionMaster()->MoveIdle(); m_target->GetMotionMaster()->MoveIdle();
CharmInfo *charmInfo = ((Creature*)m_target)->InitCharmInfo(m_target); }
charmInfo->InitPossessCreateSpells(); else if(m_target->GetTypeId() == TYPEID_PLAYER)
{
((Player*)m_target)->SetClientControl(m_target, 0);
} }
if(CharmInfo *charmInfo = m_target->InitCharmInfo(m_target))
charmInfo->InitPossessCreateSpells();
if(caster->GetTypeId() == TYPEID_PLAYER) if(caster->GetTypeId() == TYPEID_PLAYER)
{
((Player*)caster)->PossessSpellInitialize(); ((Player*)caster)->PossessSpellInitialize();
}
} }
else else
{ {
m_target->SetCharmerGUID(0); m_target->SetCharmerGUID(0);
caster->InterruptSpell(CURRENT_CHANNELED_SPELL); // the spell is not automatically canceled when interrupted, do it now
if(m_target->GetTypeId() == TYPEID_PLAYER) if(m_target->GetTypeId() == TYPEID_PLAYER)
{
((Player*)m_target)->setFactionForRace(m_target->getRace()); ((Player*)m_target)->setFactionForRace(m_target->getRace());
((Player*)m_target)->SetClientControl(m_target, 1);
}
else if(m_target->GetTypeId() == TYPEID_UNIT) else if(m_target->GetTypeId() == TYPEID_UNIT)
{ {
CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo(); CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
@@ -3193,7 +3200,7 @@ void Aura::HandleAuraModPetTalentsPoints(bool Apply, bool Real)
if(m_target->GetTypeId() == TYPEID_UNIT) if(m_target->GetTypeId() == TYPEID_UNIT)
{ {
((Creature*)m_target)->AIM_Initialize(); ((Creature*)m_target)->AIM_Initialize();
CharmInfo *charmInfo = ((Creature*)m_target)->InitCharmInfo(m_target); CharmInfo *charmInfo = m_target->InitCharmInfo(m_target);
charmInfo->InitCharmCreateSpells(); charmInfo->InitCharmCreateSpells();
charmInfo->SetReactState( REACT_DEFENSIVE ); charmInfo->SetReactState( REACT_DEFENSIVE );
+62 -9
View File
@@ -38,6 +38,11 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
CHECK_PACKET_SIZE(recvPacket,1+1+1+4+8+4+1); CHECK_PACKET_SIZE(recvPacket,1+1+1+4+8+4+1);
Player* pUser = _player; Player* pUser = _player;
// ignore for remote control state
if(pUser->m_mover != pUser)
return;
uint8 bagIndex, slot; uint8 bagIndex, slot;
uint8 unk_flags; // flags (if 0x02 - some additional data are received) uint8 unk_flags; // flags (if 0x02 - some additional data are received)
uint8 cast_count; // next cast if exists (single or not) 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()); sLog.outDetail("WORLD: CMSG_OPEN_ITEM packet, data length = %i",(uint32)recvPacket.size());
Player* pUser = _player; Player* pUser = _player;
// ignore for remote control state
if(pUser->m_mover != pUser)
return;
uint8 bagIndex, slot; uint8 bagIndex, slot;
recvPacket >> bagIndex >> slot; recvPacket >> bagIndex >> slot;
@@ -219,6 +229,11 @@ void WorldSession::HandleGameObjectUseOpcode( WorldPacket & recv_data )
recv_data >> guid; recv_data >> guid;
sLog.outDebug( "WORLD: Recvd CMSG_GAMEOBJ_USE Message [guid=%u]", GUID_LOPART(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); GameObject *obj = ObjectAccessor::GetGameObject(*_player, guid);
if(!obj) 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)); 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); GameObject* go = ObjectAccessor::GetGameObject(*_player,guid);
if(!go) if(!go)
return; return;
@@ -259,6 +278,11 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
recvPacket >> spellId; recvPacket >> spellId;
recvPacket >> unk_flags; // flags (if 0x02 - some additional data are received) 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", 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()); spellId, cast_count, unk_flags, (uint32)recvPacket.size());
@@ -270,11 +294,23 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
return; return;
} }
// not have spell in spellbook or spell passive and not casted by client if(mover->GetTypeId()==TYPEID_PLAYER)
if ( !_player->HasActiveSpell (spellId) || IsPassiveSpell(spellId) )
{ {
//cheater? kick? ban? // not have spell in spellbook or spell passive and not casted by client
return; 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, // 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 // client provided targets
SpellCastTargets targets; SpellCastTargets targets;
if(!targets.read(&recvPacket,_player)) if(!targets.read(&recvPacket,mover))
return; return;
// auto-selection buff level base at target level (in spellInfo) // auto-selection buff level base at target level (in spellInfo)
@@ -296,7 +332,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
spellInfo = actualSpellInfo; 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->m_cast_count = cast_count; // set count of casts
spell->prepare(&targets); spell->prepare(&targets);
} }
@@ -305,6 +341,11 @@ void WorldSession::HandleCancelCastOpcode(WorldPacket& recvPacket)
{ {
CHECK_PACKET_SIZE(recvPacket,5); 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 // increments with every CANCEL packet, don't use for now
uint8 counter; uint8 counter;
uint32 spellId; uint32 spellId;
@@ -315,14 +356,18 @@ void WorldSession::HandleCancelCastOpcode(WorldPacket& recvPacket)
if(spellId==26679) if(spellId==26679)
return; return;
if(_player->IsNonMeleeSpellCasted(false)) if(mover->IsNonMeleeSpellCasted(false))
_player->InterruptNonMeleeSpells(false,spellId); mover->InterruptNonMeleeSpells(false,spellId);
} }
void WorldSession::HandleCancelAuraOpcode( WorldPacket& recvPacket) void WorldSession::HandleCancelAuraOpcode( WorldPacket& recvPacket)
{ {
CHECK_PACKET_SIZE(recvPacket,4); CHECK_PACKET_SIZE(recvPacket,4);
// ignore for remote control state
if(_player->m_mover != _player)
return;
uint32 spellId; uint32 spellId;
recvPacket >> spellId; recvPacket >> spellId;
@@ -357,6 +402,10 @@ void WorldSession::HandlePetCancelAuraOpcode( WorldPacket& recvPacket)
{ {
CHECK_PACKET_SIZE(recvPacket, 8+4); CHECK_PACKET_SIZE(recvPacket, 8+4);
// ignore for remote control state
if(_player->m_mover != _player)
return;
uint64 guid; uint64 guid;
uint32 spellId; uint32 spellId;
@@ -404,7 +453,7 @@ void WorldSession::HandleCancelAutoRepeatSpellOpcode( WorldPacket& /*recvPacket*
{ {
// may be better send SMSG_CANCEL_AUTO_REPEAT? // may be better send SMSG_CANCEL_AUTO_REPEAT?
// cancel and prepare for deleting // cancel and prepare for deleting
_player->InterruptSpell(CURRENT_AUTOREPEAT_SPELL); _player->m_mover->InterruptSpell(CURRENT_AUTOREPEAT_SPELL);
} }
/// \todo Complete HandleCancelChanneling function /// \todo Complete HandleCancelChanneling function
@@ -422,6 +471,10 @@ void WorldSession::HandleTotemDestroy( WorldPacket& recvPacket)
{ {
CHECK_PACKET_SIZE(recvPacket, 1); CHECK_PACKET_SIZE(recvPacket, 1);
// ignore for remote control state
if(_player->m_mover != _player)
return;
uint8 slotId; uint8 slotId;
recvPacket >> slotId; recvPacket >> slotId;