Files
TCPlayerbotCore/src/game/LFGHandler.cpp
T

435 lines
13 KiB
C++
Raw Normal View History

2008-10-02 16:23:55 -05:00
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
2010-01-16 20:19:18 +03:00
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "WorldSession.h"
#include "Log.h"
#include "Database/DatabaseEnv.h"
#include "Player.h"
#include "WorldPacket.h"
#include "ObjectMgr.h"
#include "World.h"
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
static void AttemptJoin(Player* _player)
{
// skip not can autojoin cases and player group case
if(!_player->m_lookingForGroup.canAutoJoin() || _player->GetGroup())
return;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//TODO: Guard Player Map
HashMapHolder<Player>::MapType const& players = ObjectAccessor::Instance().GetPlayers();
2009-10-17 16:20:24 -07:00
for (HashMapHolder<Player>::MapType::const_iterator iter = players.begin(); iter != players.end(); ++iter)
2008-10-02 16:23:55 -05:00
{
Player *plr = iter->second;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// skip enemies and self
if(!plr || plr==_player || plr->GetTeam() != _player->GetTeam())
continue;
2009-10-17 15:51:44 -07:00
//skip players not in world
if(!plr->IsInWorld())
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// skip not auto add, not group leader cases
if(!plr->GetSession()->LookingForGroup_auto_add || plr->GetGroup() && plr->GetGroup()->GetLeaderGUID()!=plr->GetGUID())
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// 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;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// attempt create group, or skip
if(!plr->GetGroup())
{
Group* group = new Group;
if(!group->Create(plr->GetGUID(), plr->GetName()))
{
delete group;
continue;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
objmgr.AddGroup(group);
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// stop at success join
if(plr->GetGroup()->AddMember(_player->GetGUID(), _player->GetName()))
{
if( sWorld.getConfig(CONFIG_RESTRICTED_LFG_CHANNEL) && _player->GetSession()->GetSecurity() == SEC_PLAYER )
_player->LeaveLFGChannel();
break;
}
// full
else
{
if( sWorld.getConfig(CONFIG_RESTRICTED_LFG_CHANNEL) && plr->GetSession()->GetSecurity() == SEC_PLAYER )
plr->LeaveLFGChannel();
}
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
static void AttemptAddMore(Player* _player)
{
// skip not group leader case
if(_player->GetGroup() && _player->GetGroup()->GetLeaderGUID()!=_player->GetGUID())
return;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(!_player->m_lookingForGroup.more.canAutoJoin())
return;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//TODO: Guard Player map
HashMapHolder<Player>::MapType const& players = ObjectAccessor::Instance().GetPlayers();
2009-10-17 16:20:24 -07:00
for (HashMapHolder<Player>::MapType::const_iterator iter = players.begin(); iter != players.end(); ++iter)
2008-10-02 16:23:55 -05:00
{
Player *plr = iter->second;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// skip enemies and self
if(!plr || plr==_player || plr->GetTeam() != _player->GetTeam())
continue;
2009-10-17 15:51:44 -07:00
if(!plr->IsInWorld())
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// skip not auto join or in group
if(!plr->GetSession()->LookingForGroup_auto_join || plr->GetGroup() )
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(!plr->m_lookingForGroup.HaveInSlot(_player->m_lookingForGroup.more))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// attempt create group if need, or stop attempts
if(!_player->GetGroup())
{
Group* group = new Group;
if(!group->Create(_player->GetGUID(), _player->GetName()))
{
delete group;
2008-11-14 16:28:45 -06:00
return; // can't create group (??)
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
objmgr.AddGroup(group);
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// 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();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
break;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// joined
if( sWorld.getConfig(CONFIG_RESTRICTED_LFG_CHANNEL) && plr->GetSession()->GetSecurity() == SEC_PLAYER )
plr->LeaveLFGChannel();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// and group full
if(_player->GetGroup()->IsFull() )
{
if( sWorld.getConfig(CONFIG_RESTRICTED_LFG_CHANNEL) && _player->GetSession()->GetSecurity() == SEC_PLAYER )
_player->LeaveLFGChannel();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
break;
}
}
}
2009-10-17 15:51:44 -07:00
2009-05-31 15:56:51 -05:00
void WorldSession::HandleLfgSetAutoJoinOpcode( WorldPacket & /*recv_data*/ )
2008-10-02 16:23:55 -05:00
{
2009-05-31 15:56:51 -05:00
sLog.outDebug("CMSG_LFG_SET_AUTOJOIN");
2008-10-02 16:23:55 -05:00
LookingForGroup_auto_join = true;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(!_player) // needed because STATUS_AUTHED
return;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
AttemptJoin(_player);
}
2009-10-17 15:51:44 -07:00
2009-05-31 15:56:51 -05:00
void WorldSession::HandleLfgClearAutoJoinOpcode( WorldPacket & /*recv_data*/ )
2008-10-02 16:23:55 -05:00
{
2009-05-31 15:56:51 -05:00
sLog.outDebug("CMSG_LFG_CLEAR_AUTOJOIN");
2008-10-02 16:23:55 -05:00
LookingForGroup_auto_join = false;
}
2009-10-17 15:51:44 -07:00
2009-05-31 15:56:51 -05:00
void WorldSession::HandleLfmSetAutoFillOpcode( WorldPacket & /*recv_data*/ )
2008-10-02 16:23:55 -05:00
{
2009-05-31 15:56:51 -05:00
sLog.outDebug("CMSG_LFM_SET_AUTOFILL");
2008-10-02 16:23:55 -05:00
LookingForGroup_auto_add = true;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(!_player) // needed because STATUS_AUTHED
return;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
AttemptAddMore(_player);
}
2009-10-17 15:51:44 -07:00
2009-05-31 15:56:51 -05:00
void WorldSession::HandleLfmClearAutoFillOpcode( WorldPacket & /*recv_data*/ )
2008-10-02 16:23:55 -05:00
{
2009-05-31 15:56:51 -05:00
sLog.outDebug("CMSG_LFM_CLEAR_AUTOFILL");
2008-10-02 16:23:55 -05:00
LookingForGroup_auto_add = false;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleLfgClearOpcode( WorldPacket & /*recv_data */ )
{
2009-05-31 15:56:51 -05:00
// empty packet
sLog.outDebug("CMSG_CLEAR_LOOKING_FOR_GROUP");
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (int i = 0; i < MAX_LOOKING_FOR_GROUP_SLOT; ++i)
2008-10-02 16:23:55 -05:00
_player->m_lookingForGroup.slots[i].Clear();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if( sWorld.getConfig(CONFIG_RESTRICTED_LFG_CHANNEL) && _player->GetSession()->GetSecurity() == SEC_PLAYER )
_player->LeaveLFGChannel();
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
SendLfgUpdate(0, 0, 0);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2009-05-31 15:56:51 -05:00
void WorldSession::HandleLfmClearOpcode( WorldPacket & /*recv_data */)
2008-10-02 16:23:55 -05:00
{
2009-05-31 15:56:51 -05:00
// empty packet
sLog.outDebug("CMSG_CLEAR_LOOKING_FOR_MORE");
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
_player->m_lookingForGroup.more.Clear();
}
2009-10-17 15:51:44 -07:00
2009-05-31 15:56:51 -05:00
void WorldSession::HandleSetLfmOpcode( WorldPacket & recv_data )
2008-10-02 16:23:55 -05:00
{
sLog.outDebug("CMSG_SET_LOOKING_FOR_MORE");
//recv_data.hexlike();
uint32 temp, entry, type;
2009-06-11 00:45:59 -05:00
uint8 unk1;
uint8 unk2[3];
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
recv_data >> temp >> unk1 >> unk2[0] >> unk2[1] >> unk2[2];
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
entry = ( temp & 0x00FFFFFF);
type = ( (temp >> 24) & 0x000000FF);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
_player->m_lookingForGroup.more.Set(entry,type);
sLog.outDebug("LFM set: temp %u, zone %u, type %u", temp, entry, type);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(LookingForGroup_auto_add)
AttemptAddMore(_player);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
SendLfgResult(type, entry, 1);
}
2009-10-17 15:51:44 -07:00
2009-05-31 15:56:51 -05:00
void WorldSession::HandleSetLfgCommentOpcode( WorldPacket & recv_data )
2008-10-02 16:23:55 -05:00
{
2009-05-31 15:56:51 -05:00
sLog.outDebug("CMSG_SET_LFG_COMMENT");
2008-10-02 16:23:55 -05:00
//recv_data.hexlike();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::string comment;
recv_data >> comment;
sLog.outDebug("LFG comment %s", comment.c_str());
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
_player->m_lookingForGroup.comment = comment;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleLookingForGroup(WorldPacket& recv_data)
{
sLog.outDebug("MSG_LOOKING_FOR_GROUP");
//recv_data.hexlike();
uint32 type, entry, unk;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
recv_data >> type >> entry >> unk;
sLog.outDebug("MSG_LOOKING_FOR_GROUP: type %u, entry %u, unk %u", type, entry, unk);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(LookingForGroup_auto_add)
AttemptAddMore(_player);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(LookingForGroup_auto_join)
AttemptJoin(_player);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
SendLfgResult(type, entry, 0);
2009-06-11 00:45:59 -05:00
SendLfgUpdate(0, 1, 0);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::SendLfgResult(uint32 type, uint32 entry, uint8 lfg_type)
2010-02-14 19:13:14 -07:00
{/*
2008-10-02 16:23:55 -05:00
uint32 number = 0;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
WorldPacket data(MSG_LOOKING_FOR_GROUP);
data << uint32(type); // type
data << uint32(entry); // entry from LFGDungeons.dbc
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
data << uint8(0);
2010-02-14 19:13:14 -07:00
if(uint8)
2009-06-11 00:45:59 -05:00
{
uint32 count1;
for(count1)
{
uint64; // player guid
}
2010-02-14 19:13:14 -07:00
}
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
data << uint32(0); // count2
data << uint32(0);
2010-02-14 19:13:14 -07:00
for(count2)
2009-06-11 00:45:59 -05:00
{
uint64 // not player guid
uint32 flags;
if(flags & 0x2)
{
string
}
if(flags & 0x10)
{
uint8
}
if(flags & 0x20)
{
for(3)
{
uint8
}
}
2010-02-14 19:13:14 -07:00
}
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
size_t count3_pos = data.wpos();
data << uint32(0); // count3
data << uint32(0); // unk
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//TODO: Guard Player map
HashMapHolder<Player>::MapType const& players = ObjectAccessor::Instance().GetPlayers();
2009-10-17 16:20:24 -07:00
for (HashMapHolder<Player>::MapType::const_iterator iter = players.begin(); iter != players.end(); ++iter)
2008-10-02 16:23:55 -05:00
{
Player *plr = iter->second;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(!plr || plr->GetTeam() != _player->GetTeam())
continue;
2009-10-17 15:51:44 -07:00
if(!plr->IsInWorld())
continue;
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
if(!plr->m_lookingForGroup.HaveInSlot(entry, type))
2008-10-02 16:23:55 -05:00
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
++number;
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
data << uint64(plr->GetGUID()); // guid
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
uint32 flags = 0x1FF;
data << uint32(flags); // flags
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
if(flags & 0x1)
2008-10-02 16:23:55 -05:00
{
2009-06-11 00:45:59 -05:00
data << uint8(plr->getLevel());
data << uint8(plr->getClass());
data << uint8(plr->getRace());
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (int i = 0; i < 3; ++i)
2009-06-11 00:45:59 -05:00
data << uint8(0); // spent talents count in specific tab
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
data << uint32(0); // resistances1
data << uint32(0); // spd/heal
data << uint32(0); // spd/heal
data << uint32(0); // combat_rating9
data << uint32(0); // combat_rating10
data << uint32(0); // combat_rating11
data << float(0); // mp5
data << float(0); // unk
data << uint32(0); // attack power
data << uint32(0); // stat1
data << uint32(0); // maxhealth
data << uint32(0); // maxpower1
data << uint32(0); // unk
data << float(0); // unk
data << uint32(0); // unk
data << uint32(0); // unk
data << uint32(0); // unk
data << uint32(0); // unk
data << uint32(0); // combat_rating20
data << uint32(0); // unk
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
if(flags & 0x2)
data << plr->m_lookingForGroup.comment; // comment
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
if(flags & 0x4)
data << uint8(0); // unk
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
if(flags & 0x8)
data << uint64(0); // guid from count2 block, not player guid
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
if(flags & 0x10)
data << uint8(0); // unk
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
if(flags & 0x20)
data << uint8(plr->m_lookingForGroup.roles); // roles
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
if(flags & 0x40)
data << uint32(plr->GetZoneId()); // areaid
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
if(flags & 0x100)
data << uint8(0); // LFG/LFM flag?
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
if(flags & 0x80)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (uint8 j = 0; j < MAX_LOOKING_FOR_GROUP_SLOT; ++j)
2008-10-02 16:23:55 -05:00
{
2009-06-11 00:45:59 -05:00
data << uint32(plr->m_lookingForGroup.slots[j].entry | (plr->m_lookingForGroup.slots[j].type << 24));
2008-10-02 16:23:55 -05:00
}
}
}
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
data.put<uint32>(count3_pos, number); // fill count placeholder
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
SendPacket(&data);
2010-02-14 19:13:14 -07:00
*/
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleSetLfgOpcode( WorldPacket & recv_data )
{
sLog.outDebug("CMSG_SET_LOOKING_FOR_GROUP");
2009-06-11 00:45:59 -05:00
recv_data.hexlike();
2008-10-02 16:23:55 -05:00
uint32 slot, temp, entry, type;
2009-06-11 00:45:59 -05:00
uint8 roles, unk1;
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
recv_data >> slot >> temp >> roles >> unk1;
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
entry = ( temp & 0x00FFFFFF);
type = ( (temp >> 24) & 0x000000FF);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(slot >= MAX_LOOKING_FOR_GROUP_SLOT)
return;
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
_player->m_lookingForGroup.slots[slot].Set(entry, type);
_player->m_lookingForGroup.roles = roles;
2008-10-02 16:23:55 -05:00
sLog.outDebug("LFG set: looknumber %u, temp %X, type %u, entry %u", slot, temp, type, entry);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(LookingForGroup_auto_join)
AttemptJoin(_player);
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
//SendLfgResult(type, entry, 0);
SendLfgUpdate(0, 1, 0);
}
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
void WorldSession::HandleLfgSetRoles(WorldPacket &recv_data)
{
sLog.outDebug("CMSG_LFG_SET_ROLES");
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
uint8 roles;
recv_data >> roles;
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
_player->m_lookingForGroup.roles = roles;
}
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
void WorldSession::SendLfgUpdate(uint8 unk1, uint8 unk2, uint8 unk3)
{
2009-02-17 20:07:49 -06:00
2010-02-14 19:13:14 -07:00
}