/*
* Copyright (C) 2008-2015 TrinityCore
*
* 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 MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the 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, see .
*/
#include "LFGMgr.h"
#include "ObjectMgr.h"
#include "Group.h"
#include "Player.h"
#include "Opcodes.h"
#include "WorldPacket.h"
#include "WorldSession.h"
void BuildPlayerLockDungeonBlock(WorldPacket& data, lfg::LfgLockMap const& lock)
{
data << uint32(lock.size()); // Size of lock dungeons
for (lfg::LfgLockMap::const_iterator it = lock.begin(); it != lock.end(); ++it)
{
TC_LOG_TRACE("lfg", "BuildPlayerLockDungeonBlock:: DungeonID: %u Lock status: %u Required itemLevel: %u Current itemLevel: %f",
(it->first & 0x00FFFFFF), it->second.lockStatus, it->second.requiredItemLevel, it->second.currentItemLevel);
data << uint32(it->first); // Dungeon entry (id + type)
data << uint32(it->second.lockStatus); // Lock status
data << uint32(it->second.requiredItemLevel); // Required itemLevel
data << uint32(it->second.currentItemLevel); // Current itemLevel
}
}
void BuildPartyLockDungeonBlock(WorldPacket& data, lfg::LfgLockPartyMap const& lockMap)
{
data << uint8(lockMap.size());
for (lfg::LfgLockPartyMap::const_iterator it = lockMap.begin(); it != lockMap.end(); ++it)
{
data << it->first; // Player guid
BuildPlayerLockDungeonBlock(data, it->second);
}
}
void BuildQuestReward(WorldPacket& data, Quest const* quest, Player* player)
{
uint8 rewCount = quest->GetRewItemsCount() + quest->GetRewCurrencyCount();
data << uint32(quest->GetRewMoney());
data << uint32(player->GetQuestXPReward(quest));
data << uint8(rewCount);
if (rewCount)
{
for (uint8 i = 0; i < QUEST_REWARD_CURRENCY_COUNT; ++i)
{
if (uint32 currencyId = quest->RewardCurrencyId[i])
{
data << uint32(currencyId);
data << uint32(0);
data << uint32(quest->RewardCurrencyCount[i]);
data << uint8(1); // Is currency
}
}
for (uint8 i = 0; i < QUEST_REWARD_ITEM_COUNT; ++i)
{
if (uint32 itemId = quest->RewardItemId[i])
{
ItemTemplate const* item = sObjectMgr->GetItemTemplate(itemId);
data << uint32(itemId);
data << uint32(/*item ? item->DisplayInfoID :*/ 0);
data << uint32(quest->RewardItemCount[i]);
data << uint8(0); // Is currency
}
}
}
}
void WorldSession::HandleLfgJoinOpcode(WorldPacket& recvData)
{
if (!sLFGMgr->isOptionEnabled(lfg::LFG_OPTION_ENABLE_DUNGEON_FINDER | lfg::LFG_OPTION_ENABLE_RAID_BROWSER) ||
(GetPlayer()->GetGroup() && GetPlayer()->GetGroup()->GetLeaderGUID() != GetPlayer()->GetGUID() &&
(GetPlayer()->GetGroup()->GetMembersCount() == MAXGROUPSIZE || !GetPlayer()->GetGroup()->isLFGGroup())))
{
recvData.rfinish();
return;
}
uint32 roles;
recvData >> roles;
for (int32 i = 0; i < 3; ++i)
recvData.read_skip();
uint32 commentLen = recvData.ReadBits(9);
uint32 numDungeons = recvData.ReadBits(24);
if (!numDungeons)
{
TC_LOG_DEBUG("lfg", "CMSG_DF_JOIN %s no dungeons selected", GetPlayerInfo().c_str());
recvData.rfinish();
return;
}
std::string comment = recvData.ReadString(commentLen);
lfg::LfgDungeonSet newDungeons;
for (uint32 i = 0; i < numDungeons; ++i)
{
uint32 dungeon;
recvData >> dungeon;
dungeon &= 0x00FFFFFF; // remove the type from the dungeon entry
if (dungeon)
newDungeons.insert(dungeon);
}
TC_LOG_DEBUG("lfg", "CMSG_DF_JOIN %s roles: %u, Dungeons: %u, Comment: %s",
GetPlayerInfo().c_str(), roles, uint8(newDungeons.size()), comment.c_str());
sLFGMgr->JoinLfg(GetPlayer(), uint8(roles), newDungeons, comment);
}
void WorldSession::HandleLfgLeaveOpcode(WorldPacket& recvData)
{
ObjectGuid leaveGuid;
Group* group = GetPlayer()->GetGroup();
ObjectGuid guid = GetPlayer()->GetGUID();
ObjectGuid gguid = group ? group->GetGUID() : guid;
recvData.read_skip(); // Always 8
recvData.read_skip(); // Join date
recvData.read_skip(); // Always 3
recvData.read_skip(); // Queue Id
leaveGuid[4] = recvData.ReadBit();
leaveGuid[5] = recvData.ReadBit();
leaveGuid[0] = recvData.ReadBit();
leaveGuid[6] = recvData.ReadBit();
leaveGuid[2] = recvData.ReadBit();
leaveGuid[7] = recvData.ReadBit();
leaveGuid[1] = recvData.ReadBit();
leaveGuid[3] = recvData.ReadBit();
recvData.ReadByteSeq(leaveGuid[7]);
recvData.ReadByteSeq(leaveGuid[4]);
recvData.ReadByteSeq(leaveGuid[3]);
recvData.ReadByteSeq(leaveGuid[2]);
recvData.ReadByteSeq(leaveGuid[6]);
recvData.ReadByteSeq(leaveGuid[0]);
recvData.ReadByteSeq(leaveGuid[1]);
recvData.ReadByteSeq(leaveGuid[5]);
TC_LOG_DEBUG("lfg", "CMSG_DF_LEAVE %s in group: %u sent guid %s.",
GetPlayerInfo().c_str(), group ? 1 : 0, leaveGuid.ToString().c_str());
// Check cheating - only leader can leave the queue
if (!group || group->GetLeaderGUID() == guid)
sLFGMgr->LeaveLfg(gguid);
}
void WorldSession::HandleLfgProposalResultOpcode(WorldPacket& recvData)
{
uint32 proposalID; // Proposal ID
bool accept;
ObjectGuid guid1;
ObjectGuid guid2;
recvData >> proposalID;
recvData.read_skip();
recvData.read_skip();
recvData.read_skip();
guid2[4] = recvData.ReadBit();
guid2[5] = recvData.ReadBit();
guid2[0] = recvData.ReadBit();
guid2[6] = recvData.ReadBit();
guid2[2] = recvData.ReadBit();
guid2[7] = recvData.ReadBit();
guid2[1] = recvData.ReadBit();
guid2[3] = recvData.ReadBit();
recvData.ReadByteSeq(guid2[7]);
recvData.ReadByteSeq(guid2[4]);
recvData.ReadByteSeq(guid2[3]);
recvData.ReadByteSeq(guid2[2]);
recvData.ReadByteSeq(guid2[6]);
recvData.ReadByteSeq(guid2[0]);
recvData.ReadByteSeq(guid2[1]);
recvData.ReadByteSeq(guid2[5]);
guid1[7] = recvData.ReadBit();
accept = recvData.ReadBit();
guid1[1] = recvData.ReadBit();
guid1[3] = recvData.ReadBit();
guid1[0] = recvData.ReadBit();
guid1[5] = recvData.ReadBit();
guid1[4] = recvData.ReadBit();
guid1[6] = recvData.ReadBit();
guid1[2] = recvData.ReadBit();
recvData.ReadByteSeq(guid1[7]);
recvData.ReadByteSeq(guid1[1]);
recvData.ReadByteSeq(guid1[5]);
recvData.ReadByteSeq(guid1[6]);
recvData.ReadByteSeq(guid1[3]);
recvData.ReadByteSeq(guid1[4]);
recvData.ReadByteSeq(guid1[0]);
recvData.ReadByteSeq(guid1[2]);
TC_LOG_DEBUG("lfg", "CMSG_LFG_PROPOSAL_RESULT %s proposal: %u accept: %u",
GetPlayerInfo().c_str(), proposalID, accept ? 1 : 0);
sLFGMgr->UpdateProposal(proposalID, GetPlayer()->GetGUID(), accept);
}
void WorldSession::HandleLfgSetRolesOpcode(WorldPacket& recvData)
{
uint8 roles;
recvData >> roles; // Player Group Roles
ObjectGuid guid = GetPlayer()->GetGUID();
Group* group = GetPlayer()->GetGroup();
if (!group)
{
TC_LOG_DEBUG("lfg", "CMSG_DF_SET_ROLES %s Not in group",
GetPlayerInfo().c_str());
return;
}
ObjectGuid gguid = group->GetGUID();
TC_LOG_DEBUG("lfg", "CMSG_DF_SET_ROLES: Group %s, Player %s, Roles: %u",
gguid.ToString().c_str(), GetPlayerInfo().c_str(), roles);
sLFGMgr->UpdateRoleCheck(gguid, guid, roles);
}
void WorldSession::HandleLfgSetCommentOpcode(WorldPacket& recvData)
{
uint32 length = recvData.ReadBits(9);
std::string comment = recvData.ReadString(length);
TC_LOG_DEBUG("lfg", "CMSG_LFG_SET_COMMENT %s comment: %s",
GetPlayerInfo().c_str(), comment.c_str());
sLFGMgr->SetComment(GetPlayer()->GetGUID(), comment);
}
void WorldSession::HandleLfgSetBootVoteOpcode(WorldPacket& recvData)
{
bool agree; // Agree to kick player
recvData >> agree;
ObjectGuid guid = GetPlayer()->GetGUID();
TC_LOG_DEBUG("lfg", "CMSG_LFG_SET_BOOT_VOTE %s agree: %u",
GetPlayerInfo().c_str(), agree ? 1 : 0);
sLFGMgr->UpdateBoot(guid, agree);
}
void WorldSession::HandleLfgTeleportOpcode(WorldPacket& recvData)
{
bool out;
recvData >> out;
TC_LOG_DEBUG("lfg", "CMSG_DF_TELEPORT %s out: %u",
GetPlayerInfo().c_str(), out ? 1 : 0);
sLFGMgr->TeleportPlayer(GetPlayer(), out, true);
}
void WorldSession::HandleLfgGetLockInfoOpcode(WorldPacket& recvData)
{
bool forPlayer = recvData.ReadBit();
TC_LOG_DEBUG("lfg", "CMSG_LFG_LOCK_INFO_REQUEST %s for %s", GetPlayerInfo().c_str(), (forPlayer ? "player" : "party"));
if (forPlayer)
SendLfgPlayerLockInfo();
else
SendLfgPartyLockInfo();
}
void WorldSession::SendLfgPlayerLockInfo()
{
ObjectGuid guid = GetPlayer()->GetGUID();
// Get Random dungeons that can be done at a certain level and expansion
uint8 level = GetPlayer()->getLevel();
lfg::LfgDungeonSet const& randomDungeons =
sLFGMgr->GetRandomAndSeasonalDungeons(level, GetExpansion());
// Get player locked Dungeons
lfg::LfgLockMap const& lock = sLFGMgr->GetLockedDungeons(guid);
uint32 rsize = uint32(randomDungeons.size());
uint32 lsize = uint32(lock.size());
TC_LOG_DEBUG("lfg", "SMSG_LFG_PLAYER_INFO %s", GetPlayerInfo().c_str());
WorldPacket data(SMSG_LFG_PLAYER_INFO, 1 + rsize * (4 + 1 + 4 + 4 + 4 + 4 + 1 + 4 + 4 + 4) + 4 + lsize * (1 + 4 + 4 + 4 + 4 + 1 + 4 + 4 + 4));
data << uint8(randomDungeons.size()); // Random Dungeon count
for (lfg::LfgDungeonSet::const_iterator it = randomDungeons.begin(); it != randomDungeons.end(); ++it)
{
data << uint32(*it); // Dungeon Entry (id + type)
lfg::LfgReward const* reward = sLFGMgr->GetRandomDungeonReward(*it, level);
Quest const* quest = NULL;
bool done = false;
if (reward)
{
quest = sObjectMgr->GetQuestTemplate(reward->firstQuest);
if (quest)
{
done = !GetPlayer()->CanRewardQuest(quest, false);
if (done)
quest = sObjectMgr->GetQuestTemplate(reward->otherQuest);
}
}
data << uint8(done);
data << uint32(0); // currencyQuantity
data << uint32(0); // some sort of overall cap/weekly cap
data << uint32(0); // currencyID
data << uint32(0); // tier1Quantity
data << uint32(0); // tier1Limit
data << uint32(0); // overallQuantity
data << uint32(0); // overallLimit
data << uint32(0); // periodPurseQuantity
data << uint32(0); // periodPurseLimit
data << uint32(0); // purseQuantity
data << uint32(0); // purseLimit
data << uint32(0); // some sort of reward for completion
data << uint32(0); // completedEncounters
data << uint8(0); // Call to Arms eligible
for (uint32 i = 0; i < 3; ++i)
{
data << uint32(0); // Call to Arms Role
//if (role)
// BuildQuestReward(data, ctaRoleQuest, GetPlayer());
}
if (quest)
BuildQuestReward(data, quest, GetPlayer());
else
{
data << uint32(0); // Money
data << uint32(0); // XP
data << uint8(0); // Reward count
}
}
BuildPlayerLockDungeonBlock(data, lock);
SendPacket(&data);
}
void WorldSession::SendLfgPartyLockInfo()
{
ObjectGuid guid = GetPlayer()->GetGUID();
Group* group = GetPlayer()->GetGroup();
if (!group)
return;
// Get the locked dungeons of the other party members
lfg::LfgLockPartyMap lockMap;
for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
{
Player* plrg = itr->GetSource();
if (!plrg)
continue;
ObjectGuid pguid = plrg->GetGUID();
if (pguid == guid)
continue;
lockMap[pguid] = sLFGMgr->GetLockedDungeons(pguid);
}
uint32 size = 0;
for (lfg::LfgLockPartyMap::const_iterator it = lockMap.begin(); it != lockMap.end(); ++it)
size += 8 + 4 + uint32(it->second.size()) * (4 + 4 + 4 + 4);
TC_LOG_DEBUG("lfg", "SMSG_LFG_PARTY_INFO %s", GetPlayerInfo().c_str());
WorldPacket data(SMSG_LFG_PARTY_INFO, 1 + size);
BuildPartyLockDungeonBlock(data, lockMap);
SendPacket(&data);
}
void WorldSession::HandleLfrJoinOpcode(WorldPacket& recvData)
{
uint32 entry; // Raid id to search
recvData >> entry;
TC_LOG_DEBUG("lfg", "CMSG_LFG_LFR_JOIN %s dungeon entry: %u",
GetPlayerInfo().c_str(), entry);
//SendLfrUpdateListOpcode(entry);
}
void WorldSession::HandleLfrLeaveOpcode(WorldPacket& recvData)
{
uint32 dungeonId; // Raid id queue to leave
recvData >> dungeonId;
TC_LOG_DEBUG("lfg", "CMSG_LFG_LFR_LEAVE %s dungeonId: %u",
GetPlayerInfo().c_str(), dungeonId);
//sLFGMgr->LeaveLfr(GetPlayer(), dungeonId);
}
void WorldSession::HandleLfgGetStatus(WorldPacket& /*recvData*/)
{
TC_LOG_DEBUG("lfg", "CMSG_LFG_GET_STATUS %s", GetPlayerInfo().c_str());
if (!GetPlayer()->isUsingLfg())
return;
ObjectGuid guid = GetPlayer()->GetGUID();
lfg::LfgUpdateData updateData = sLFGMgr->GetLfgStatus(guid);
if (GetPlayer()->GetGroup())
{
SendLfgUpdateStatus(updateData, true);
updateData.dungeons.clear();
SendLfgUpdateStatus(updateData, false);
}
else
{
SendLfgUpdateStatus(updateData, false);
updateData.dungeons.clear();
SendLfgUpdateStatus(updateData, true);
}
}
void WorldSession::SendLfgUpdateStatus(lfg::LfgUpdateData const& updateData, bool party)
{
bool join = false;
bool queued = false;
uint8 size = uint8(updateData.dungeons.size());
ObjectGuid guid = _player->GetGUID();
time_t joinTime = sLFGMgr->GetQueueJoinTime(_player->GetGUID());
uint32 queueId = sLFGMgr->GetQueueId(_player->GetGUID());
switch (updateData.updateType)
{
case lfg::LFG_UPDATETYPE_JOIN_QUEUE_INITIAL: // Joined queue outside the dungeon
join = true;
break;
case lfg::LFG_UPDATETYPE_JOIN_QUEUE:
case lfg::LFG_UPDATETYPE_ADDED_TO_QUEUE: // Rolecheck Success
join = true;
queued = true;
break;
case lfg::LFG_UPDATETYPE_PROPOSAL_BEGIN:
join = true;
break;
case lfg::LFG_UPDATETYPE_UPDATE_STATUS:
join = updateData.state != lfg::LFG_STATE_ROLECHECK && updateData.state != lfg::LFG_STATE_NONE;
queued = updateData.state == lfg::LFG_STATE_QUEUED;
break;
default:
break;
}
TC_LOG_DEBUG("lfg", "SMSG_LFG_UPDATE_STATUS %s updatetype: %u, party %s",
GetPlayerInfo().c_str(), updateData.updateType, party ? "true" : "false");
WorldPacket data(SMSG_LFG_UPDATE_STATUS, 1 + 8 + 3 + 2 + 1 + updateData.comment.length() + 4 + 4 + 1 + 1 + 1 + 4 + size);
data.WriteBit(guid[1]);
data.WriteBit(party);
data.WriteBits(size, 24);
data.WriteBit(guid[6]);
data.WriteBit(size > 0); // Extra info
data.WriteBits(updateData.comment.length(), 9);
data.WriteBit(guid[4]);
data.WriteBit(guid[7]);
data.WriteBit(guid[2]);
data.WriteBit(join); // LFG Join
data.WriteBit(guid[0]);
data.WriteBit(guid[3]);
data.WriteBit(guid[5]);
data.WriteBit(queued); // Join the queue
data << uint8(updateData.updateType); // Lfg Update type
data.WriteString(updateData.comment);
data << uint32(queueId); // Queue Id
data << uint32(joinTime); // Join date
data.WriteByteSeq(guid[6]);
for (uint8 i = 0; i < 3; ++i)
data << uint8(0); // unk - Always 0
data.WriteByteSeq(guid[1]);
data.WriteByteSeq(guid[2]);
data.WriteByteSeq(guid[4]);
data.WriteByteSeq(guid[3]);
data.WriteByteSeq(guid[5]);
data.WriteByteSeq(guid[0]);
data << uint32(3);
data.WriteByteSeq(guid[7]);
for (lfg::LfgDungeonSet::const_iterator it = updateData.dungeons.begin(); it != updateData.dungeons.end(); ++it)
data << uint32(*it);
SendPacket(&data);
}
void WorldSession::SendLfgRoleChosen(ObjectGuid guid, uint8 roles)
{
TC_LOG_DEBUG("lfg", "SMSG_LFG_ROLE_CHOSEN %s guid: %s roles: %u",
GetPlayerInfo().c_str(), guid.ToString().c_str(), roles);
WorldPacket data(SMSG_LFG_ROLE_CHOSEN, 8 + 1 + 4);
data << guid; // Guid
data << uint8(roles > 0); // Ready
data << uint32(roles); // Roles
SendPacket(&data);
}
void WorldSession::SendLfgRoleCheckUpdate(lfg::LfgRoleCheck const& roleCheck)
{
lfg::LfgDungeonSet dungeons;
if (roleCheck.rDungeonId)
dungeons.insert(roleCheck.rDungeonId);
else
dungeons = roleCheck.dungeons;
TC_LOG_DEBUG("lfg", "SMSG_LFG_ROLE_CHECK_UPDATE %s", GetPlayerInfo().c_str());
WorldPacket data(SMSG_LFG_ROLE_CHECK_UPDATE, 4 + 1 + 1 + dungeons.size() * 4 + 1 + roleCheck.roles.size() * (8 + 1 + 4 + 1));
data << uint32(roleCheck.state); // Check result
data << uint8(roleCheck.state == lfg::LFG_ROLECHECK_INITIALITING);
data << uint8(dungeons.size()); // Number of dungeons
if (!dungeons.empty())
for (lfg::LfgDungeonSet::iterator it = dungeons.begin(); it != dungeons.end(); ++it)
data << uint32(sLFGMgr->GetLFGDungeonEntry(*it)); // Dungeon
data << uint8(roleCheck.roles.size()); // Players in group
if (!roleCheck.roles.empty())
{
// Leader info MUST be sent 1st :S
ObjectGuid guid = roleCheck.leader;
uint8 roles = roleCheck.roles.find(guid)->second;
Player* player = ObjectAccessor::FindConnectedPlayer(guid);
data << guid; // Guid
data << uint8(roles > 0); // Ready
data << uint32(roles); // Roles
data << uint8(player ? player->getLevel() : 0); // Level
for (lfg::LfgRolesMap::const_iterator it = roleCheck.roles.begin(); it != roleCheck.roles.end(); ++it)
{
if (it->first == roleCheck.leader)
continue;
guid = it->first;
roles = it->second;
player = ObjectAccessor::FindConnectedPlayer(guid);
data << guid; // Guid
data << uint8(roles > 0); // Ready
data << uint32(roles); // Roles
data << uint8(player ? player->getLevel() : 0);// Level
}
}
SendPacket(&data);
}
void WorldSession::SendLfgJoinResult(lfg::LfgJoinResultData const& joinData)
{
uint32 size = 0;
ObjectGuid guid = GetPlayer()->GetGUID();
uint32 queueId = sLFGMgr->GetQueueId(_player->GetGUID());
for (lfg::LfgLockPartyMap::const_iterator it = joinData.lockmap.begin(); it != joinData.lockmap.end(); ++it)
size += 8 + 4 + uint32(it->second.size()) * (4 + 4 + 4 + 4);
TC_LOG_DEBUG("lfg", "SMSG_LFG_JOIN_RESULT %s checkResult: %u checkValue: %u",
GetPlayerInfo().c_str(), joinData.result, joinData.state);
WorldPacket data(SMSG_LFG_JOIN_RESULT, 4 + 4 + size);
data << uint32(3);
data << uint8(joinData.result); // Check Result
data << uint32(queueId); // Queue Id
data << uint8(joinData.state); // Check Value
data << uint32(time(NULL)); // Join date
data.WriteBit(guid[2]);
data.WriteBit(guid[7]);
data.WriteBit(guid[3]);
data.WriteBit(guid[0]);
data.WriteBits(joinData.lockmap.size(), 24);
for (lfg::LfgLockPartyMap::const_iterator it = joinData.lockmap.begin(); it != joinData.lockmap.end(); ++it)
{
ObjectGuid playerGuid = it->first;
data.WriteBit(playerGuid[7]);
data.WriteBit(playerGuid[5]);
data.WriteBit(playerGuid[3]);
data.WriteBit(playerGuid[6]);
data.WriteBit(playerGuid[0]);
data.WriteBit(playerGuid[2]);
data.WriteBit(playerGuid[4]);
data.WriteBit(playerGuid[1]);
data.WriteBits(it->second.size(), 22);
}
data.WriteBit(guid[4]);
data.WriteBit(guid[5]);
data.WriteBit(guid[1]);
data.WriteBit(guid[6]);
for (lfg::LfgLockPartyMap::const_iterator it = joinData.lockmap.begin(); it != joinData.lockmap.end(); ++it)
{
ObjectGuid playerGuid = it->first;
for (lfg::LfgLockMap::const_iterator itr = it->second.begin(); itr != it->second.end(); ++itr)
{
TC_LOG_TRACE("lfg", "SendLfgJoinResult:: %s DungeonID: %u Lock status: %u Required itemLevel: %u Current itemLevel: %f",
playerGuid.ToString().c_str(), (itr->first & 0x00FFFFFF), itr->second.lockStatus, itr->second.requiredItemLevel, itr->second.currentItemLevel);
data << uint32(itr->second.lockStatus); // Lock status
data << uint32(itr->second.currentItemLevel); // Current itemLevel
data << uint32(itr->second.requiredItemLevel); // Required itemLevel
data << uint32(itr->first); // Dungeon entry (id + type)
}
data.WriteByteSeq(playerGuid[2]);
data.WriteByteSeq(playerGuid[5]);
data.WriteByteSeq(playerGuid[1]);
data.WriteByteSeq(playerGuid[0]);
data.WriteByteSeq(playerGuid[4]);
data.WriteByteSeq(playerGuid[3]);
data.WriteByteSeq(playerGuid[6]);
data.WriteByteSeq(playerGuid[7]);
}
data.WriteByteSeq(guid[1]);
data.WriteByteSeq(guid[4]);
data.WriteByteSeq(guid[3]);
data.WriteByteSeq(guid[5]);
data.WriteByteSeq(guid[0]);
data.WriteByteSeq(guid[7]);
data.WriteByteSeq(guid[2]);
data.WriteByteSeq(guid[6]);
SendPacket(&data);
}
void WorldSession::SendLfgQueueStatus(lfg::LfgQueueStatusData const& queueData)
{
TC_LOG_DEBUG("lfg", "SMSG_LFG_QUEUE_STATUS %s dungeon: %u, waitTime: %d, "
"avgWaitTime: %d, waitTimeTanks: %d, waitTimeHealer: %d, waitTimeDps: %d, "
"queuedTime: %u, tanks: %u, healers: %u, dps: %u",
GetPlayerInfo().c_str(), queueData.dungeonId, queueData.waitTime, queueData.waitTimeAvg,
queueData.waitTimeTank, queueData.waitTimeHealer, queueData.waitTimeDps,
queueData.queuedTime, queueData.tanks, queueData.healers, queueData.dps);
ObjectGuid guid = _player->GetGUID();
WorldPacket data(SMSG_LFG_QUEUE_STATUS, 4 + 4 + 4 + 4 + 4 + 4 + 1 + 1 + 1 + 4 + 4 + 4 + 4 + 8);
data.WriteBit(guid[3]);
data.WriteBit(guid[0]);
data.WriteBit(guid[2]);
data.WriteBit(guid[6]);
data.WriteBit(guid[5]);
data.WriteBit(guid[7]);
data.WriteBit(guid[1]);
data.WriteBit(guid[4]);
data.WriteByteSeq(guid[0]);
data << uint8(queueData.tanks); // Tanks needed
data << int32(queueData.waitTimeTank); // Wait Tanks
data << uint8(queueData.healers); // Healers needed
data << int32(queueData.waitTimeHealer); // Wait Healers
data << uint8(queueData.dps); // Dps needed
data << int32(queueData.waitTimeDps); // Wait Dps
data.WriteByteSeq(guid[4]);
data.WriteByteSeq(guid[6]);
data << int32(queueData.waitTime); // Wait Time
data << uint32(queueData.joinTime); // Join time
data << uint32(queueData.dungeonId); // Dungeon
data << uint32(queueData.queuedTime); // Player wait time in queue
data.WriteByteSeq(guid[5]);
data.WriteByteSeq(guid[7]);
data.WriteByteSeq(guid[3]);
data << uint32(queueData.queueId); // Queue Id
data.WriteByteSeq(guid[1]);
data.WriteByteSeq(guid[2]);
data << int32(queueData.waitTimeAvg); // Average Wait time
data << uint32(3);
SendPacket(&data);
}
void WorldSession::SendLfgPlayerReward(lfg::LfgPlayerRewardData const& rewardData)
{
if (!rewardData.rdungeonEntry || !rewardData.sdungeonEntry || !rewardData.quest)
return;
TC_LOG_DEBUG("lfg", "SMSG_LFG_PLAYER_REWARD %s rdungeonEntry: %u, sdungeonEntry: %u, done: %u",
GetPlayerInfo().c_str(), rewardData.rdungeonEntry, rewardData.sdungeonEntry, rewardData.done);
uint8 itemNum = rewardData.quest->GetRewItemsCount() + rewardData.quest->GetRewCurrencyCount();
WorldPacket data(SMSG_LFG_PLAYER_REWARD, 4 + 4 + 1 + 4 + 4 + 4 + 4 + 4 + 1 + itemNum * (4 + 4 + 4));
data << uint32(rewardData.rdungeonEntry); // Random Dungeon Finished
data << uint32(rewardData.sdungeonEntry); // Dungeon Finished
BuildQuestReward(data, rewardData.quest, GetPlayer());
SendPacket(&data);
}
void WorldSession::SendLfgBootProposalUpdate(lfg::LfgPlayerBoot const& boot)
{
ObjectGuid guid = GetPlayer()->GetGUID();
lfg::LfgAnswer playerVote = boot.votes.find(guid)->second;
uint8 votesNum = 0;
uint8 agreeNum = 0;
uint32 secsleft = uint8((boot.cancelTime - time(NULL)) / 1000);
for (lfg::LfgAnswerContainer::const_iterator it = boot.votes.begin(); it != boot.votes.end(); ++it)
{
if (it->second != lfg::LFG_ANSWER_PENDING)
{
++votesNum;
if (it->second == lfg::LFG_ANSWER_AGREE)
++agreeNum;
}
}
TC_LOG_DEBUG("lfg", "SMSG_LFG_BOOT_PROPOSAL_UPDATE %s inProgress: %u - "
"didVote: %u - agree: %u - victim: %s votes: %u - agrees: %u - left: %u - "
"needed: %u - reason %s",
GetPlayerInfo().c_str(), uint8(boot.inProgress), uint8(playerVote != lfg::LFG_ANSWER_PENDING),
uint8(playerVote == lfg::LFG_ANSWER_AGREE), boot.victim.ToString().c_str(), votesNum, agreeNum,
secsleft, lfg::LFG_GROUP_KICK_VOTES_NEEDED, boot.reason.c_str());
WorldPacket data(SMSG_LFG_BOOT_PROPOSAL_UPDATE, 1 + 1 + 1 + 1 + 8 + 4 + 4 + 4 + 4 + boot.reason.length());
data << uint8(boot.inProgress); // Vote in progress
data << uint8(agreeNum >= lfg::LFG_GROUP_KICK_VOTES_NEEDED); // Did succeed
data << uint8(playerVote != lfg::LFG_ANSWER_PENDING); // Did Vote
data << uint8(playerVote == lfg::LFG_ANSWER_AGREE); // Agree
data << boot.victim; // Victim GUID
data << uint32(votesNum); // Total Votes
data << uint32(agreeNum); // Agree Count
data << uint32(secsleft); // Time Left
data << uint32(lfg::LFG_GROUP_KICK_VOTES_NEEDED); // Needed Votes
data << boot.reason.c_str(); // Kick reason
SendPacket(&data);
}
void WorldSession::SendLfgUpdateProposal(lfg::LfgProposal const& proposal)
{
ObjectGuid guid = GetPlayer()->GetGUID();
ObjectGuid gguid = proposal.players.find(guid)->second.group;
bool silent = !proposal.isNew && gguid == proposal.group;
uint32 dungeonEntry = proposal.dungeonId;
uint32 queueId = sLFGMgr->GetQueueId(_player->GetGUID());
time_t joinTime = sLFGMgr->GetQueueJoinTime(_player->GetGUID());
TC_LOG_DEBUG("lfg", "SMSG_LFG_PROPOSAL_UPDATE %s state: %u",
GetPlayerInfo().c_str(), proposal.state);
// show random dungeon if player selected random dungeon and it's not lfg group
if (!silent)
{
lfg::LfgDungeonSet const& playerDungeons = sLFGMgr->GetSelectedDungeons(guid);
if (playerDungeons.find(proposal.dungeonId) == playerDungeons.end())
dungeonEntry = (*playerDungeons.begin());
}
dungeonEntry = sLFGMgr->GetLFGDungeonEntry(dungeonEntry);
WorldPacket data(SMSG_LFG_PROPOSAL_UPDATE, 4 + 1 + 4 + 4 + 1 + 1 + proposal.players.size() * (4 + 1 + 1 + 1 + 1 +1));
data << uint32(joinTime);
data << uint32(proposal.encounters); // Encounters done
data << uint32(queueId); // Queue Id
data << uint32(3); // Always 3
data << uint32(dungeonEntry); // Dungeon
data << uint32(proposal.id); // Proposal Id
data << uint8(proposal.state); // State
ObjectGuid guid1 = guid;
ObjectGuid guid2 = gguid;
data.WriteBit(guid2[4]);
data.WriteBit(guid1[3]);
data.WriteBit(guid1[7]);
data.WriteBit(guid1[0]);
data.WriteBit(guid2[1]);
data.WriteBit(silent);
data.WriteBit(guid1[4]);
data.WriteBit(guid1[5]);
data.WriteBit(guid2[3]);
data.WriteBits(proposal.players.size(), 23);
data.WriteBit(guid2[7]);
for (lfg::LfgProposalPlayerContainer::const_iterator it = proposal.players.begin(); it != proposal.players.end(); ++it)
{
lfg::LfgProposalPlayer const& player = it->second;
if (!player.group)
{
data.WriteBit(0);
data.WriteBit(0);
}
else
{
data.WriteBit(player.group == proposal.group); // Is group in dungeon
data.WriteBit(player.group == gguid); // Same group as the player
}
data.WriteBit(player.accept == lfg::LFG_ANSWER_AGREE);
data.WriteBit(player.accept != lfg::LFG_ANSWER_PENDING);
data.WriteBit(it->first == guid);
}
data.WriteBit(guid2[5]);
data.WriteBit(guid1[6]);
data.WriteBit(guid2[2]);
data.WriteBit(guid2[6]);
data.WriteBit(guid1[2]);
data.WriteBit(guid1[1]);
data.WriteBit(guid2[0]);
data.WriteByteSeq(guid1[5]);
data.WriteByteSeq(guid2[3]);
data.WriteByteSeq(guid2[6]);
data.WriteByteSeq(guid1[6]);
data.WriteByteSeq(guid1[0]);
data.WriteByteSeq(guid2[5]);
data.WriteByteSeq(guid1[1]);
for (lfg::LfgProposalPlayerContainer::const_iterator it = proposal.players.begin(); it != proposal.players.end(); ++it)
{
lfg::LfgProposalPlayer const& player = it->second;
data << uint32(player.role);
}
data.WriteByteSeq(guid2[7]);
data.WriteByteSeq(guid1[4]);
data.WriteByteSeq(guid2[0]);
data.WriteByteSeq(guid2[1]);
data.WriteByteSeq(guid1[2]);
data.WriteByteSeq(guid1[7]);
data.WriteByteSeq(guid2[2]);
data.WriteByteSeq(guid1[3]);
data.WriteByteSeq(guid2[4]);
SendPacket(&data);
}
void WorldSession::SendLfgLfrList(bool update)
{
TC_LOG_DEBUG("lfg", "SMSG_LFG_LFR_LIST %s update: %u",
GetPlayerInfo().c_str(), update ? 1 : 0);
WorldPacket data(SMSG_LFG_UPDATE_SEARCH, 1);
data << uint8(update); // In Lfg Queue?
SendPacket(&data);
}
void WorldSession::SendLfgDisabled()
{
TC_LOG_DEBUG("lfg", "SMSG_LFG_DISABLED %s", GetPlayerInfo().c_str());
WorldPacket data(SMSG_LFG_DISABLED, 0);
SendPacket(&data);
}
void WorldSession::SendLfgOfferContinue(uint32 dungeonEntry)
{
TC_LOG_DEBUG("lfg", "SMSG_LFG_OFFER_CONTINUE %s dungeon entry: %u",
GetPlayerInfo().c_str(), dungeonEntry);
WorldPacket data(SMSG_LFG_OFFER_CONTINUE, 4);
data << uint32(dungeonEntry);
SendPacket(&data);
}
void WorldSession::SendLfgTeleportError(uint8 err)
{
TC_LOG_DEBUG("lfg", "SMSG_LFG_TELEPORT_DENIED %s reason: %u",
GetPlayerInfo().c_str(), err);
WorldPacket data(SMSG_LFG_TELEPORT_DENIED, 4);
data << uint32(err); // Error
SendPacket(&data);
}
/*
void WorldSession::SendLfrUpdateListOpcode(uint32 dungeonEntry)
{
TC_LOG_DEBUG("network", "SMSG_LFG_UPDATE_LIST %s dungeon entry: %u",
GetPlayerInfo().c_str(), dungeonEntry);
WorldPacket data(SMSG_LFG_UPDATE_LIST);
SendPacket(&data);
}
*/