mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-25 03:12:09 +01:00
*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "WorldSession.h"
|
||||
#include "Log.h"
|
||||
#include "Database/DatabaseEnv.h"
|
||||
@@ -25,35 +24,28 @@
|
||||
#include "WorldPacket.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "World.h"
|
||||
|
||||
static void AttemptJoin(Player* _player)
|
||||
{
|
||||
// skip not can autojoin cases and player group case
|
||||
if(!_player->m_lookingForGroup.canAutoJoin() || _player->GetGroup())
|
||||
return;
|
||||
|
||||
//TODO: Guard Player Map
|
||||
HashMapHolder<Player>::MapType const& players = ObjectAccessor::Instance().GetPlayers();
|
||||
for(HashMapHolder<Player>::MapType::const_iterator iter = players.begin(); iter != players.end(); ++iter)
|
||||
{
|
||||
Player *plr = iter->second;
|
||||
|
||||
// skip enemies and self
|
||||
if(!plr || plr==_player || plr->GetTeam() != _player->GetTeam())
|
||||
continue;
|
||||
|
||||
//skip players not in world
|
||||
if(!plr->IsInWorld())
|
||||
continue;
|
||||
|
||||
// skip not auto add, not group leader cases
|
||||
if(!plr->GetSession()->LookingForGroup_auto_add || plr->GetGroup() && plr->GetGroup()->GetLeaderGUID()!=plr->GetGUID())
|
||||
continue;
|
||||
|
||||
// skip non auto-join or empty slots, or non compatible slots
|
||||
if(!plr->m_lookingForGroup.more.canAutoJoin() || !_player->m_lookingForGroup.HaveInSlot(plr->m_lookingForGroup.more))
|
||||
continue;
|
||||
|
||||
// attempt create group, or skip
|
||||
if(!plr->GetGroup())
|
||||
{
|
||||
@@ -63,10 +55,8 @@ static void AttemptJoin(Player* _player)
|
||||
delete group;
|
||||
continue;
|
||||
}
|
||||
|
||||
objmgr.AddGroup(group);
|
||||
}
|
||||
|
||||
// stop at success join
|
||||
if(plr->GetGroup()->AddMember(_player->GetGUID(), _player->GetName()))
|
||||
{
|
||||
@@ -82,36 +72,28 @@ static void AttemptJoin(Player* _player)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void AttemptAddMore(Player* _player)
|
||||
{
|
||||
// skip not group leader case
|
||||
if(_player->GetGroup() && _player->GetGroup()->GetLeaderGUID()!=_player->GetGUID())
|
||||
return;
|
||||
|
||||
if(!_player->m_lookingForGroup.more.canAutoJoin())
|
||||
return;
|
||||
|
||||
//TODO: Guard Player map
|
||||
HashMapHolder<Player>::MapType const& players = ObjectAccessor::Instance().GetPlayers();
|
||||
for(HashMapHolder<Player>::MapType::const_iterator iter = players.begin(); iter != players.end(); ++iter)
|
||||
{
|
||||
Player *plr = iter->second;
|
||||
|
||||
// skip enemies and self
|
||||
if(!plr || plr==_player || plr->GetTeam() != _player->GetTeam())
|
||||
continue;
|
||||
|
||||
if(!plr->IsInWorld())
|
||||
continue;
|
||||
|
||||
// skip not auto join or in group
|
||||
if(!plr->GetSession()->LookingForGroup_auto_join || plr->GetGroup() )
|
||||
continue;
|
||||
|
||||
if(!plr->m_lookingForGroup.HaveInSlot(_player->m_lookingForGroup.more))
|
||||
continue;
|
||||
|
||||
// attempt create group if need, or stop attempts
|
||||
if(!_player->GetGroup())
|
||||
{
|
||||
@@ -121,90 +103,69 @@ static void AttemptAddMore(Player* _player)
|
||||
delete group;
|
||||
return; // can't create group (??)
|
||||
}
|
||||
|
||||
objmgr.AddGroup(group);
|
||||
}
|
||||
|
||||
// stop at join fail (full)
|
||||
if(!_player->GetGroup()->AddMember(plr->GetGUID(), plr->GetName()) )
|
||||
{
|
||||
if( sWorld.getConfig(CONFIG_RESTRICTED_LFG_CHANNEL) && _player->GetSession()->GetSecurity() == SEC_PLAYER )
|
||||
_player->LeaveLFGChannel();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// joined
|
||||
if( sWorld.getConfig(CONFIG_RESTRICTED_LFG_CHANNEL) && plr->GetSession()->GetSecurity() == SEC_PLAYER )
|
||||
plr->LeaveLFGChannel();
|
||||
|
||||
// and group full
|
||||
if(_player->GetGroup()->IsFull() )
|
||||
{
|
||||
if( sWorld.getConfig(CONFIG_RESTRICTED_LFG_CHANNEL) && _player->GetSession()->GetSecurity() == SEC_PLAYER )
|
||||
_player->LeaveLFGChannel();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WorldSession::HandleLfgSetAutoJoinOpcode( WorldPacket & /*recv_data*/ )
|
||||
{
|
||||
sLog.outDebug("CMSG_LFG_SET_AUTOJOIN");
|
||||
LookingForGroup_auto_join = true;
|
||||
|
||||
if(!_player) // needed because STATUS_AUTHED
|
||||
return;
|
||||
|
||||
AttemptJoin(_player);
|
||||
}
|
||||
|
||||
void WorldSession::HandleLfgClearAutoJoinOpcode( WorldPacket & /*recv_data*/ )
|
||||
{
|
||||
sLog.outDebug("CMSG_LFG_CLEAR_AUTOJOIN");
|
||||
LookingForGroup_auto_join = false;
|
||||
}
|
||||
|
||||
void WorldSession::HandleLfmSetAutoFillOpcode( WorldPacket & /*recv_data*/ )
|
||||
{
|
||||
sLog.outDebug("CMSG_LFM_SET_AUTOFILL");
|
||||
LookingForGroup_auto_add = true;
|
||||
|
||||
if(!_player) // needed because STATUS_AUTHED
|
||||
return;
|
||||
|
||||
AttemptAddMore(_player);
|
||||
}
|
||||
|
||||
void WorldSession::HandleLfmClearAutoFillOpcode( WorldPacket & /*recv_data*/ )
|
||||
{
|
||||
sLog.outDebug("CMSG_LFM_CLEAR_AUTOFILL");
|
||||
LookingForGroup_auto_add = false;
|
||||
}
|
||||
|
||||
void WorldSession::HandleLfgClearOpcode( WorldPacket & /*recv_data */ )
|
||||
{
|
||||
// empty packet
|
||||
sLog.outDebug("CMSG_CLEAR_LOOKING_FOR_GROUP");
|
||||
|
||||
for(int i = 0; i < MAX_LOOKING_FOR_GROUP_SLOT; ++i)
|
||||
_player->m_lookingForGroup.slots[i].Clear();
|
||||
|
||||
if( sWorld.getConfig(CONFIG_RESTRICTED_LFG_CHANNEL) && _player->GetSession()->GetSecurity() == SEC_PLAYER )
|
||||
_player->LeaveLFGChannel();
|
||||
|
||||
SendLfgUpdate(0, 0, 0);
|
||||
}
|
||||
|
||||
void WorldSession::HandleLfmClearOpcode( WorldPacket & /*recv_data */)
|
||||
{
|
||||
// empty packet
|
||||
sLog.outDebug("CMSG_CLEAR_LOOKING_FOR_MORE");
|
||||
|
||||
_player->m_lookingForGroup.more.Clear();
|
||||
}
|
||||
|
||||
void WorldSession::HandleSetLfmOpcode( WorldPacket & recv_data )
|
||||
{
|
||||
sLog.outDebug("CMSG_SET_LOOKING_FOR_MORE");
|
||||
@@ -212,60 +173,44 @@ void WorldSession::HandleSetLfmOpcode( WorldPacket & recv_data )
|
||||
uint32 temp, entry, type;
|
||||
uint8 unk1;
|
||||
uint8 unk2[3];
|
||||
|
||||
recv_data >> temp >> unk1 >> unk2[0] >> unk2[1] >> unk2[2];
|
||||
|
||||
entry = ( temp & 0x00FFFFFF);
|
||||
type = ( (temp >> 24) & 0x000000FF);
|
||||
|
||||
_player->m_lookingForGroup.more.Set(entry,type);
|
||||
sLog.outDebug("LFM set: temp %u, zone %u, type %u", temp, entry, type);
|
||||
|
||||
if(LookingForGroup_auto_add)
|
||||
AttemptAddMore(_player);
|
||||
|
||||
SendLfgResult(type, entry, 1);
|
||||
}
|
||||
|
||||
void WorldSession::HandleSetLfgCommentOpcode( WorldPacket & recv_data )
|
||||
{
|
||||
sLog.outDebug("CMSG_SET_LFG_COMMENT");
|
||||
//recv_data.hexlike();
|
||||
|
||||
std::string comment;
|
||||
recv_data >> comment;
|
||||
sLog.outDebug("LFG comment %s", comment.c_str());
|
||||
|
||||
_player->m_lookingForGroup.comment = comment;
|
||||
}
|
||||
|
||||
void WorldSession::HandleLookingForGroup(WorldPacket& recv_data)
|
||||
{
|
||||
sLog.outDebug("MSG_LOOKING_FOR_GROUP");
|
||||
//recv_data.hexlike();
|
||||
uint32 type, entry, unk;
|
||||
|
||||
recv_data >> type >> entry >> unk;
|
||||
sLog.outDebug("MSG_LOOKING_FOR_GROUP: type %u, entry %u, unk %u", type, entry, unk);
|
||||
|
||||
if(LookingForGroup_auto_add)
|
||||
AttemptAddMore(_player);
|
||||
|
||||
if(LookingForGroup_auto_join)
|
||||
AttemptJoin(_player);
|
||||
|
||||
SendLfgResult(type, entry, 0);
|
||||
SendLfgUpdate(0, 1, 0);
|
||||
}
|
||||
|
||||
void WorldSession::SendLfgResult(uint32 type, uint32 entry, uint8 lfg_type)
|
||||
{
|
||||
uint32 number = 0;
|
||||
|
||||
WorldPacket data(MSG_LOOKING_FOR_GROUP);
|
||||
data << uint32(type); // type
|
||||
data << uint32(entry); // entry from LFGDungeons.dbc
|
||||
|
||||
data << uint8(0);
|
||||
/*if(uint8)
|
||||
{
|
||||
@@ -275,7 +220,6 @@ void WorldSession::SendLfgResult(uint32 type, uint32 entry, uint8 lfg_type)
|
||||
uint64; // player guid
|
||||
}
|
||||
}*/
|
||||
|
||||
data << uint32(0); // count2
|
||||
data << uint32(0);
|
||||
/*for(count2)
|
||||
@@ -298,42 +242,31 @@ void WorldSession::SendLfgResult(uint32 type, uint32 entry, uint8 lfg_type)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
size_t count3_pos = data.wpos();
|
||||
data << uint32(0); // count3
|
||||
data << uint32(0); // unk
|
||||
|
||||
//TODO: Guard Player map
|
||||
HashMapHolder<Player>::MapType const& players = ObjectAccessor::Instance().GetPlayers();
|
||||
for(HashMapHolder<Player>::MapType::const_iterator iter = players.begin(); iter != players.end(); ++iter)
|
||||
{
|
||||
Player *plr = iter->second;
|
||||
|
||||
if(!plr || plr->GetTeam() != _player->GetTeam())
|
||||
continue;
|
||||
|
||||
if(!plr->IsInWorld())
|
||||
continue;
|
||||
|
||||
if(!plr->m_lookingForGroup.HaveInSlot(entry, type))
|
||||
continue;
|
||||
|
||||
++number;
|
||||
|
||||
data << uint64(plr->GetGUID()); // guid
|
||||
|
||||
uint32 flags = 0x1FF;
|
||||
data << uint32(flags); // flags
|
||||
|
||||
if(flags & 0x1)
|
||||
{
|
||||
data << uint8(plr->getLevel());
|
||||
data << uint8(plr->getClass());
|
||||
data << uint8(plr->getRace());
|
||||
|
||||
for(int i = 0; i < 3; ++i)
|
||||
data << uint8(0); // spent talents count in specific tab
|
||||
|
||||
data << uint32(0); // resistances1
|
||||
data << uint32(0); // spd/heal
|
||||
data << uint32(0); // spd/heal
|
||||
@@ -355,28 +288,20 @@ void WorldSession::SendLfgResult(uint32 type, uint32 entry, uint8 lfg_type)
|
||||
data << uint32(0); // combat_rating20
|
||||
data << uint32(0); // unk
|
||||
}
|
||||
|
||||
if(flags & 0x2)
|
||||
data << plr->m_lookingForGroup.comment; // comment
|
||||
|
||||
if(flags & 0x4)
|
||||
data << uint8(0); // unk
|
||||
|
||||
if(flags & 0x8)
|
||||
data << uint64(0); // guid from count2 block, not player guid
|
||||
|
||||
if(flags & 0x10)
|
||||
data << uint8(0); // unk
|
||||
|
||||
if(flags & 0x20)
|
||||
data << uint8(plr->m_lookingForGroup.roles); // roles
|
||||
|
||||
if(flags & 0x40)
|
||||
data << uint32(plr->GetZoneId()); // areaid
|
||||
|
||||
if(flags & 0x100)
|
||||
data << uint8(0); // LFG/LFM flag?
|
||||
|
||||
if(flags & 0x80)
|
||||
{
|
||||
for(uint8 j = 0; j < MAX_LOOKING_FOR_GROUP_SLOT; ++j)
|
||||
@@ -385,48 +310,35 @@ void WorldSession::SendLfgResult(uint32 type, uint32 entry, uint8 lfg_type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.put<uint32>(count3_pos, number); // fill count placeholder
|
||||
|
||||
SendPacket(&data);
|
||||
}
|
||||
|
||||
void WorldSession::HandleSetLfgOpcode( WorldPacket & recv_data )
|
||||
{
|
||||
sLog.outDebug("CMSG_SET_LOOKING_FOR_GROUP");
|
||||
recv_data.hexlike();
|
||||
uint32 slot, temp, entry, type;
|
||||
uint8 roles, unk1;
|
||||
|
||||
recv_data >> slot >> temp >> roles >> unk1;
|
||||
|
||||
entry = ( temp & 0x00FFFFFF);
|
||||
type = ( (temp >> 24) & 0x000000FF);
|
||||
|
||||
if(slot >= MAX_LOOKING_FOR_GROUP_SLOT)
|
||||
return;
|
||||
|
||||
_player->m_lookingForGroup.slots[slot].Set(entry, type);
|
||||
_player->m_lookingForGroup.roles = roles;
|
||||
sLog.outDebug("LFG set: looknumber %u, temp %X, type %u, entry %u", slot, temp, type, entry);
|
||||
|
||||
if(LookingForGroup_auto_join)
|
||||
AttemptJoin(_player);
|
||||
|
||||
//SendLfgResult(type, entry, 0);
|
||||
SendLfgUpdate(0, 1, 0);
|
||||
}
|
||||
|
||||
void WorldSession::HandleLfgSetRoles(WorldPacket &recv_data)
|
||||
{
|
||||
sLog.outDebug("CMSG_LFG_SET_ROLES");
|
||||
|
||||
uint8 roles;
|
||||
recv_data >> roles;
|
||||
|
||||
_player->m_lookingForGroup.roles = roles;
|
||||
}
|
||||
|
||||
void WorldSession::SendLfgUpdate(uint8 unk1, uint8 unk2, uint8 unk3)
|
||||
{
|
||||
WorldPacket data(SMSG_LFG_UPDATE, 3);
|
||||
|
||||
Reference in New Issue
Block a user