//////////////////////////////////////////////////////////////// ///This function handles CMSG_GROUP_ACCEPT: //////////////////////////////////////////////////////////////// void WorldSession::HandleGroupAcceptOpcode( WorldPacket & recv_data ) { if(!_player->IsInWorld()) return; Player *player = objmgr.GetPlayer(_player->GetInviter()); if ( !player ) return; player->SetInviter(0); _player->SetInviter(0); Group *grp = player->GetGroup(); if(grp) { grp->AddMember(_player); _player->iInstanceType = grp->GetLeader()->iInstanceType; _player->GetSession()->OutPacket(CMSG_DUNGEON_DIFFICULTY, 4, &grp->GetLeader()->iInstanceType); sInstanceSavingManager.ResetSavedInstancesForPlayer(_player); return; } // If we're this far, it means we have no existing group, and have to make one. grp = new Group; grp->AddMember(player); // add the inviter first, therefore he is the leader grp->AddMember(_player); // add us. _player->iInstanceType = player->iInstanceType; _player->GetSession()->OutPacket(CMSG_DUNGEON_DIFFICULTY, 4, &player->iInstanceType); sInstanceSavingManager.ResetSavedInstancesForPlayer(_player); // Currentgroup and all that shit are set by addmember. }
//////////////////////////////////////////////////////////////// ///This function handles CMSG_GROUP_ACCEPT: //////////////////////////////////////////////////////////////// void WorldSession::HandleGroupAcceptOpcode( WorldPacket & recv_data ) { if(!_player->IsInWorld()) return; Player *player = objmgr.GetPlayer(_player->GetInviter()); if ( !player ) return; player->SetInviter(0); _player->SetInviter(0); Group *grp = player->GetGroup(); if(grp) { grp->AddMember(_player->m_playerInfo); if(grp->GetLeader()->m_loggedInPlayer) _player->iInstanceType = grp->GetLeader()->m_loggedInPlayer->iInstanceType; _player->GetSession()->OutPacket(MSG_SET_DUNGEON_DIFFICULTY, 4, &_player->iInstanceType); return; } // If we're this far, it means we have no existing group, and have to make one. grp = new Group(true); grp->AddMember(player->m_playerInfo); // add the inviter first, therefore he is the leader grp->AddMember(_player->m_playerInfo); // add us. _player->iInstanceType = player->iInstanceType; _player->GetSession()->OutPacket(MSG_SET_DUNGEON_DIFFICULTY, 4, &player->iInstanceType); }
void WorldSession::HandleGroupAcceptOpcode( WorldPacket & /*recv_data*/ ) { Group *group = GetPlayer()->GetGroupInvite(); if (!group) return; // remove in from ivites in any case group->RemoveInvite(GetPlayer()); /** error handling **/ /********************/ // not have place if(group->IsFull()) { SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_PARTY_FULL); return; } // everything's fine, do it if(!group->AddMember(GetPlayer()->GetGUID(), GetPlayer()->GetName())) return; uint8 subgroup = group->GetMemberGroup(GetPlayer()->GetGUID()); GetPlayer()->SetGroup(group, subgroup); }
bool Battlefield::AddOrSetPlayerToCorrectBfGroup(Player* player) { if (!player->IsInWorld()) return false; if (Group* group = player->GetGroup()) group->RemoveMember(player->GetGUID()); Group* group = GetFreeBfRaid(player->GetTeamId()); if (!group) { group = new Group; group->SetBattlefieldGroup(this); group->Create(player); sGroupMgr->AddGroup(group); m_Groups[player->GetTeamId()].insert(group->GetGUID()); } else if (group->IsMember(player->GetGUID())) { uint8 subgroup = group->GetMemberGroup(player->GetGUID()); player->SetBattlegroundOrBattlefieldRaid(group, subgroup); } else group->AddMember(player); return true; }
bool Battlefield::AddOrSetPlayerToCorrectBfGroup(Player* player) { if (!player->IsInWorld()) return false; if (player->GetGroup() && (player->GetGroup()->isBGGroup() || player->GetGroup()->isBFGroup())) { sLog->outMisc("Battlefield::AddOrSetPlayerToCorrectBfGroup - player is already in %s group!", (player->GetGroup()->isBGGroup() ? "BG" : "BF")); return false; } Group* group = GetFreeBfRaid(player->GetTeamId()); if (!group) { group = new Group; group->SetBattlefieldGroup(this); group->Create(player); sGroupMgr->AddGroup(group); m_Groups[player->GetTeamId()].insert(group->GetGUID()); } else if (group->IsMember(player->GetGUID())) { uint8 subgroup = group->GetMemberGroup(player->GetGUID()); player->SetBattlegroundOrBattlefieldRaid(group, subgroup); } else group->AddMember(player); return true; }
//////////////////////////////////////////////////////////////// ///This function handles CMSG_GROUP_ACCEPT: //////////////////////////////////////////////////////////////// void WorldSession::HandleGroupAcceptOpcode(WorldPacket & recv_data) { CHECK_INWORLD_RETURN; // we are in group already if(_player->GetGroup() != NULL) return; Player* player = objmgr.GetPlayer(_player->GetInviter()); if(!player) return; player->SetInviter(0); _player->SetInviter(0); Group* grp = player->GetGroup(); if(grp != NULL) { grp->AddMember(_player->m_playerInfo); _player->iInstanceType = grp->m_difficulty; _player->SendDungeonDifficulty(); //sInstanceSavingManager.ResetSavedInstancesForPlayer(_player); return; } // If we're this far, it means we have no existing group, and have to make one. grp = new Group(true); grp->m_difficulty = static_cast<uint8>(player->iInstanceType); grp->AddMember(player->m_playerInfo); // add the inviter first, therefore he is the leader grp->AddMember(_player->m_playerInfo); // add us. _player->iInstanceType = grp->m_difficulty; _player->SendDungeonDifficulty(); Instance* instance = sInstanceMgr.GetInstanceByIds(player->GetMapId(), player->GetInstanceID()); if(instance != NULL && instance->m_creatorGuid == player->GetLowGUID()) { grp->m_instanceIds[instance->m_mapId][instance->m_difficulty] = instance->m_instanceId; instance->m_creatorGroup = grp->GetID(); instance->m_creatorGuid = 0; instance->SaveToDB(); } //sInstanceSavingManager.ResetSavedInstancesForPlayer(_player); // Currentgroup and all that shit are set by addmember. }
void WorldSession::HandleGroupAcceptOpcode(WorldPacket& recvData) { #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_GROUP_ACCEPT"); #endif recvData.read_skip<uint32>(); Group* group = GetPlayer()->GetGroupInvite(); if (!group) return; // Remove player from invitees in any case group->RemoveInvite(GetPlayer()); if (GetPlayer()->IsSpectator()) { SendPartyResult(PARTY_OP_INVITE, "", ERR_INVITE_RESTRICTED); return; } if (group->GetLeaderGUID() == GetPlayer()->GetGUID()) { sLog->outError("HandleGroupAcceptOpcode: player %s(%d) tried to accept an invite to his own group", GetPlayer()->GetName().c_str(), GetPlayer()->GetGUIDLow()); return; } // Group is full if (group->IsFull()) { SendPartyResult(PARTY_OP_INVITE, "", ERR_GROUP_FULL); return; } Player* leader = ObjectAccessor::FindPlayerInOrOutOfWorld(group->GetLeaderGUID()); // Forming a new group, create it if (!group->IsCreated()) { // This can happen if the leader is zoning. To be removed once delayed actions for zoning are implemented if (!leader || leader->IsSpectator()) { group->RemoveAllInvites(); return; } // If we're about to create a group there really should be a leader present ASSERT(leader); group->RemoveInvite(leader); group->Create(leader); sGroupMgr->AddGroup(group); } // Everything is fine, do it, PLAYER'S GROUP IS SET IN ADDMEMBER!!! if (!group->AddMember(GetPlayer())) return; group->BroadcastGroupUpdate(); }
//////////////////////////////////////////////////////////////// ///This function handles CMSG_GROUP_ACCEPT: //////////////////////////////////////////////////////////////// void WorldSession::HandleGroupAcceptOpcode( WorldPacket & recv_data ) { WorldPacket data; Player * player; player = objmgr.GetObject<Player>( GetPlayer()->GetGroupLeader() ); if ( !player ) return; if ( !GetPlayer()->IsInvited() ) return; GetPlayer()->UnSetInvited(); if ( player->IsInGroup() && (player->GetGroupLeader() == player->GetGUID()) ) { GetPlayer()->SetInGroup(); Group *group = objmgr.GetGroupByLeader( GetPlayer()->GetGroupLeader() ); ASSERT(group); group->AddMember( GetPlayer()->GetGUID(), GetPlayer()->GetName() ); group->SendUpdate(); return; } else if ( !player->IsInGroup() ) { player->SetInGroup(); player->SetLeader( player->GetGUID() ); GetPlayer()->SetInGroup(); GetPlayer()->SetLeader( player->GetGUID() ); // creating group Group * group = new Group; ASSERT(group); group->Create(player->GetGUID(), player->GetName()); // adding our client group->AddMember(GetPlayer()->GetGUID(), GetPlayer()->GetName()); objmgr.AddGroup(group); group->SendUpdate(); } }
void WorldSession::HandleLfgInviteAccept(WorldPacket & recvPacket) { CHECK_INWORLD_RETURN; _player->PartLFGChannel(); if(_player->m_lfgMatch == NULL && _player->m_lfgInviterGuid == 0) { if(_player->m_lfgMatch == NULL) OutPacket(SMSG_LFG_AUTOJOIN_FAILED_NO_PLAYER); // Matched Player(s) have gone offline. else OutPacket(SMSG_LFG_AUTOJOIN_FAILED); // Group no longer available. return; } if( _player->m_lfgMatch != NULL ) { // move into accepted players _player->m_lfgMatch->lock.Acquire(); _player->m_lfgMatch->PendingPlayers.erase(_player); if( !_player->GetGroup() ) { _player->m_lfgMatch->AcceptedPlayers.insert(_player); if(!_player->m_lfgMatch->PendingPlayers.size()) { // all players have accepted Group * pGroup = new Group(true); for(set<Player*>::iterator itr = _player->m_lfgMatch->AcceptedPlayers.begin(); itr != _player->m_lfgMatch->AcceptedPlayers.end(); ++itr) pGroup->AddMember((*itr)->m_playerInfo); _player->m_lfgMatch->pGroup = pGroup; } } _player->m_lfgMatch->lock.Release(); } else { Player * pPlayer = objmgr.GetPlayer(_player->m_lfgInviterGuid); if( pPlayer == NULL ) { OutPacket(SMSG_LFG_AUTOJOIN_FAILED_NO_PLAYER); // Matched Player(s) have gone offline. return; } if( pPlayer->GetGroup() == NULL || pPlayer->GetGroup()->IsFull() || pPlayer->GetGroup()->GetLeader() != pPlayer->m_playerInfo ) { OutPacket(SMSG_LFG_AUTOJOIN_FAILED); return; } pPlayer->GetGroup()->AddMember(_player->m_playerInfo); } _player->m_lfgInviterGuid = 0; _player->m_lfgMatch = NULL; }
/** Function that checks if the player can be added to a raid group @param player to be added to raid */ bool Battlefield::CanAddPlayerToRaid(Player* player) { if (!player->IsInWorld()) return false; DEBUG_LOG("Battlefield: Adding player %s to raid", player->GetGuidStr().c_str()); if (Group* group = player->GetGroup()) { DEBUG_LOG("Battlefield: Player %s already has group %s, uninviting", player->GetGuidStr().c_str(), group->GetGuidStr().c_str()); group->RemoveMember(player->GetObjectGuid(), 0); } PvpTeamIndex teamIdx = GetTeamIndexByTeamId(player->GetTeam()); Group* group = GetFreeRaid(teamIdx); if (!group) { DEBUG_LOG("Battlefield: No free raid for %s!", player->GetGuidStr().c_str()); if (IsTeamFull(teamIdx)) { DEBUG_LOG("Battlefield: Battlefield is full! Can't add player %s!", player->GetGuidStr().c_str()); return false; } DEBUG_LOG("Battlefield: Trying to create new group for %s!", player->GetGuidStr().c_str()); group = new Group; group->SetBattlefieldGroup(this); if (group->Create(player->GetObjectGuid(), player->GetName())) DEBUG_LOG("Battlefield: Successfully created new group %s", group->GetGuidStr().c_str()); else sLog.outError("Battlefield: Failed to create group for player %s.", player->GetGuidStr().c_str()); m_battlefieldRaids[teamIdx].insert(group); } else if (group->IsMember(player->GetObjectGuid())) { DEBUG_LOG("Battlefield: Raid already has players %s, making some shit", player->GetGuidStr().c_str()); uint8 subgroup = group->GetMemberGroup(player->GetObjectGuid()); player->SetBattleRaid(group, subgroup); } else { if (IsTeamFull(teamIdx)) { DEBUG_LOG("Battlefield: Group %s found, but battlefield is full! Can't add player %s!", group->GetGuidStr().c_str(), player->GetGuidStr().c_str()); return false; } return group->AddMember(player->GetObjectGuid(), player->GetName()); } return true; }
void WorldSession::HandleGroupAcceptOpcode(WorldPacket& recvData) { TC_LOG_DEBUG("network", "WORLD: Received CMSG_GROUP_ACCEPT"); recvData.read_skip<uint32>(); Group* group = GetPlayer()->GetGroupInvite(); if (!group) return; // Remove player from invitees in any case group->RemoveInvite(GetPlayer()); if (group->GetLeaderGUID() == GetPlayer()->GetGUID()) { TC_LOG_ERROR("network", "HandleGroupAcceptOpcode: player %s(%d) tried to accept an invite to his own group", GetPlayer()->GetName().c_str(), GetPlayer()->GetGUID().GetCounter()); return; } // Group is full if (group->IsFull()) { SendPartyResult(PARTY_OP_INVITE, "", ERR_GROUP_FULL); return; } Player* leader = ObjectAccessor::FindPlayer(group->GetLeaderGUID()); // Forming a new group, create it if (!group->IsCreated()) { // This can happen if the leader is zoning. To be removed once delayed actions for zoning are implemented if (!leader) { group->RemoveAllInvites(); return; } // If we're about to create a group there really should be a leader present ASSERT(leader); group->RemoveInvite(leader); group->Create(leader); sGroupMgr->AddGroup(group); } // Everything is fine, do it, PLAYER'S GROUP IS SET IN ADDMEMBER!!! if (!group->AddMember(GetPlayer())) return; group->BroadcastGroupUpdate(); }
void WorldSession::HandleGroupAcceptOpcode( WorldPacket & recv_data ) { if (!GetPlayer()->GetPlayerbotAI()) recv_data.read_skip<uint32>(); // roles mask? Group *group = GetPlayer()->GetGroupInvite(); if (!group) return; if (group->GetLeaderGuid() == GetPlayer()->GetObjectGuid()) { sLog.outError("HandleGroupAcceptOpcode: %s tried to accept an invite to his own group", GetPlayer()->GetGuidStr().c_str()); return; } // remove in from invites in any case group->RemoveInvite(GetPlayer()); /** error handling **/ /********************/ // not have place if(group->IsFull()) { SendPartyResult(PARTY_OP_INVITE, "", ERR_GROUP_FULL); return; } Player* leader = sObjectMgr.GetPlayer(group->GetLeaderGuid()); // forming a new group, create it if (!group->IsCreated()) { if (leader) group->RemoveInvite(leader); if (group->Create(group->GetLeaderGuid(), group->GetLeaderName())) sObjectMgr.AddGroup(group); else return; } // everything is fine, do it, PLAYER'S GROUP IS SET IN ADDMEMBER!!! if(!group->AddMember(GetPlayer()->GetObjectGuid(), GetPlayer()->GetName())) return; // Frozen Mod group->BroadcastGroupUpdate(); // Frozen Mod }
bool Battlefield::AddPlayerToGroup(Player * player) { Group* grp; if(player->GetTeam() == ALLIANCE) grp = m_raidGroup[TEAM_ALLIANCE]; else grp = m_raidGroup[TEAM_HORDE]; if(!grp->IsCreated()) { grp->Create(player->GetObjectGuid(),player->GetName()); grp->ConvertToRaid(); grp->AddMember(player->GetObjectGuid(),player->GetName()); } else if(!grp->IsFull()) { grp->AddMember(player->GetObjectGuid(),player->GetName()); } else return false; return true; }
void WorldSession::HandleGroupAcceptOpcode(WorldPacket & /*recv_data*/) { Group *group = GetPlayer()->GetGroupInvite(); if (!group) return; if (group->GetLeaderGUID() == GetPlayer()->GetGUID()) { sLog.outError("HandleGroupAcceptOpcode: player %s(%d) tried to accept an invite to his own group", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow()); return; } // remove in from ivites in any case group->RemoveInvite(GetPlayer()); /** error handling **/ /********************/ // not have place if (group->IsFull()) { SendPartyResult(PARTY_OP_INVITE, "", ERR_GROUP_FULL); return; } Player* leader = objmgr.GetPlayer(group->GetLeaderGUID()); // forming a new group, create it if (!group->IsCreated()) { if (leader) group->RemoveInvite(leader); group->Create(group->GetLeaderGUID(), group->GetLeaderName()); objmgr.AddGroup(group); } // everything's fine, do it, PLAYER'S GROUP IS SET IN ADDMEMBER!!! if (!group->AddMember(GetPlayer()->GetGUID(), GetPlayer()->GetName())) return; SendLfgUpdatePlayer(LFG_UPDATETYPE_REMOVED_FROM_QUEUE); for (GroupReference *itr = group->GetFirstMember(); itr != NULL; itr = itr->next()) if (Player *plrg = itr->getSource()) { plrg->GetSession()->SendLfgUpdatePlayer(LFG_UPDATETYPE_CLEAR_LOCK_LIST); plrg->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_CLEAR_LOCK_LIST); } group->BroadcastGroupUpdate(); }
void WorldSession::HandleGroupAcceptOpcode( WorldPacket & /*recv_data*/ ) { Group *group = GetPlayer()->GetGroupInvite(); if (!group) return; if(group->GetLeaderGUID() == GetPlayer()->GetGUID()) { sLog.outError("HandleGroupAcceptOpcode: player %s(%d) tried to accept an invite to his own group", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow()); return; } // remove in from ivites in any case group->RemoveInvite(GetPlayer()); /** error handling **/ /********************/ // not have place if(group->IsFull()) { SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_PARTY_FULL); return; } Player* leader = objmgr.GetPlayer(group->GetLeaderGUID()); if(leader && leader->InBattleGround()) { SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_INVITE_RESTRICTED); return; } // forming a new group, create it if(!group->IsCreated()) { if(leader) group->RemoveInvite(leader); group->Create(group->GetLeaderGUID(), group->GetLeaderName()); objmgr.AddGroup(group); } // everything's fine, do it if(!group->AddMember(GetPlayer()->GetGUID(), GetPlayer()->GetName())) return; uint8 subgroup = group->GetMemberGroup(GetPlayer()->GetGUID()); GetPlayer()->SetGroup(group, subgroup); }
void WorldSession::HandleGroupAcceptOpcode( WorldPacket & /*recv_data*/ ) { Group *group = GetPlayer()->GetGroupInvite(); if (!group) return; if(group->GetLeaderGUID() == GetPlayer()->GetGUID()) { sLog.outError("HandleGroupAcceptOpcode: player %s(%d) tried to accept an invite to his own group", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow()); return; } // remove in from invites in any case group->RemoveInvite(GetPlayer()); /** error handling **/ /********************/ // not have place if(group->IsFull()) { SendPartyResult(PARTY_OP_INVITE, "", ERR_GROUP_FULL); return; } Player* leader = sObjectMgr.GetPlayer(group->GetLeaderGUID()); if(leader && leader->InBattleGround()) { SendPartyResult(PARTY_OP_INVITE, "", ERR_INVITE_RESTRICTED); return; } // forming a new group, create it if(!group->IsCreated()) { if (leader) group->RemoveInvite(leader); if (group->Create(group->GetLeaderGUID(), group->GetLeaderName())) sObjectMgr.AddGroup(group); else return; } // everything is fine, do it, PLAYER'S GROUP IS SET IN ADDMEMBER!!! if(!group->AddMember(GetPlayer()->GetGUID(), GetPlayer()->GetName())) return; }
static bool HandleGroupJoinCommand(ChatHandler* handler, char const* args) { if (!*args) return false; Player* playerSource = NULL; Player* playerTarget = NULL; Group* groupSource = NULL; Group* groupTarget = NULL; uint64 guidSource = 0; uint64 guidTarget = 0; char* nameplgrStr = strtok((char*)args, " "); char* nameplStr = strtok(NULL, " "); if (!handler->GetPlayerGroupAndGUIDByName(nameplgrStr, playerSource, groupSource, guidSource, true)) return false; if (!groupSource) { handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, playerSource->GetName().c_str()); handler->SetSentErrorMessage(true); return false; } if (!handler->GetPlayerGroupAndGUIDByName(nameplStr, playerTarget, groupTarget, guidTarget, true)) return false; if (groupTarget || playerTarget->GetGroup() == groupSource) { handler->PSendSysMessage(LANG_GROUP_ALREADY_IN_GROUP, playerTarget->GetName().c_str()); handler->SetSentErrorMessage(true); return false; } if (!groupSource->IsFull()) { handler->PSendSysMessage(LANG_GROUP_FULL); handler->SetSentErrorMessage(true); return false; } groupSource->AddMember(playerTarget); groupSource->BroadcastGroupUpdate(); handler->PSendSysMessage(LANG_GROUP_PLAYER_JOINED, playerTarget->GetName().c_str(), playerSource->GetName().c_str()); return true; }
void WorldSession::HandleGroupAcceptOpcode( WorldPacket & recv_data ) { recv_data.read_skip<uint32>(); // value received in WorldSession::HandleGroupInviteOpcode and also skipeed currently? Group *group = GetPlayer()->GetGroupInvite(); if (!group) return; if(group->GetLeaderGUID() == GetPlayer()->GetGUID()) { sLog.outError("HandleGroupAcceptOpcode: player %s(%d) tried to accept an invite to his own group", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow()); return; } // remove in from ivites in any case group->RemoveInvite(GetPlayer()); /** error handling **/ /********************/ // not have place if(group->IsFull()) { SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_PARTY_FULL); return; } Player* leader = sObjectMgr.GetPlayer(group->GetLeaderGUID()); // forming a new group, create it if(!group->IsCreated()) { if( leader ) group->RemoveInvite(leader); group->Create(group->GetLeaderGUID(), group->GetLeaderName()); sObjectMgr.AddGroup(group); } // everything's fine, do it, PLAYER'S GROUP IS SET IN ADDMEMBER!!! if(!group->AddMember(GetPlayer()->GetGUID(), GetPlayer()->GetName())) return; }
void WorldSession::HandleGroupInviteResponseOpcode(WorldPacket& recvData) { TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_GROUP_INVITE_RESPONSE"); recvData.ReadBit(); // unk always 0 bool accept = recvData.ReadBit(); // Never actually received? /*if (accept) recvData.read_skip<uint32>(); // unk*/ Group* group = GetPlayer()->GetGroupInvite(); if (!group) return; if (accept) { // Remove player from invitees in any case group->RemoveInvite(GetPlayer()); if (group->GetLeaderGUID() == GetPlayer()->GetGUID()) { TC_LOG_ERROR(LOG_FILTER_NETWORKIO, "HandleGroupAcceptOpcode: player %s(%d) tried to accept an invite to his own group", GetPlayer()->GetName().c_str(), GetPlayer()->GetGUIDLow()); return; } // Group is full if (group->IsFull()) { SendPartyResult(PARTY_OP_INVITE, "", ERR_GROUP_FULL); return; } Player* leader = ObjectAccessor::FindPlayer(group->GetLeaderGUID()); // Forming a new group, create it if (!group->IsCreated()) { // This can happen if the leader is zoning. To be removed once delayed actions for zoning are implemented if (!leader) { group->RemoveAllInvites(); return; } // If we're about to create a group there really should be a leader present ASSERT(leader); group->RemoveInvite(leader); group->Create(leader); sGroupMgr->AddGroup(group); } // Everything is fine, do it, PLAYER'S GROUP IS SET IN ADDMEMBER!!! if (!group->AddMember(GetPlayer())) return; group->BroadcastGroupUpdate(); } else { // Remember leader if online (group pointer will be invalid if group gets disbanded) Player* leader = ObjectAccessor::FindPlayer(group->GetLeaderGUID()); // uninvite, group can be deleted GetPlayer()->UninviteFromGroup(); if (!leader || !leader->GetSession()) return; // report WorldPacket data(SMSG_GROUP_DECLINE, GetPlayer()->GetName().size()); data << GetPlayer()->GetName(); leader->GetSession()->SendPacket(&data); } }
void WorldSession::LFGLoop() { QueryResult *result = WorldDatabase.Query("SELECT guid,zoneid,is_group FROM lfg_queue"); if (result) { do { Field* fields = result->Fetch(); //is this entry a group? if(fields[2].GetUInt32() == 1) { //is there anyone in the queue looking for a group for this groups instance? QueryResult *resultLFG = WorldDatabase.PQuery("SELECT guid,zoneid,is_group,player_name FROM lfg_queue WHERE zoneid = '%u' AND is_group = 0", fields[1].GetUInt32()); if (resultLFG) { do { Field* fieldsLFG = resultLFG->Fetch(); Player *plr = sObjectAccessor.FindPlayerByName(fieldsLFG[3].GetString()); Group *grp = sObjectMgr.GetGroupById(fields[0].GetUInt32()); if(!grp->IsFull()) { //check for roles if(GroupHasRole(ROLE_TANK, grp) && GroupHasRole(ROLE_HEALER, grp)) { //group has both dps & tank, add anyone. grp->AddMember(plr->GetGUID(), plr->GetName()); RemovePlayerFromQueue(plr->GetGUIDLow()); if(grp->IsFull()) { SendMeetingStoneCompleteToParty(grp); } } else if(GroupHasRole(ROLE_TANK, grp) && !GroupHasRole(ROLE_HEALER, grp)) { //tank but healers missing //is player healer? if(isPlayerHealer(plr)) { grp->AddMember(plr->GetGUID(), plr->GetName()); RemovePlayerFromQueue(plr->GetGUIDLow()); if(grp->IsFull()) { SendMeetingStoneCompleteToParty(grp); } } //player is not healer but group can take one more random.. else if(!isPlayerHealer(plr) && grp->GetMembersCount() < 4) { grp->AddMember(plr->GetGUID(), plr->GetName()); RemovePlayerFromQueue(plr->GetGUIDLow()); if(grp->IsFull()) { SendMeetingStoneCompleteToParty(grp); } } } else if(!GroupHasRole(ROLE_TANK, grp) && !GroupHasRole(ROLE_HEALER, grp)) { //group has neither tank or healer if(isPlayerHealer(plr) || isPlayerTank(plr)) { grp->AddMember(plr->GetGUID(), plr->GetName()); RemovePlayerFromQueue(plr->GetGUIDLow()); if(grp->IsFull()) { SendMeetingStoneCompleteToParty(grp); } } else { if(grp->GetMembersCount() < 3) { //theres room for 1 more random, let the player join. grp->AddMember(plr->GetGUID(), plr->GetName()); RemovePlayerFromQueue(plr->GetGUIDLow()); if(grp->IsFull()) { SendMeetingStoneCompleteToParty(grp); } } } } } } while (resultLFG->NextRow()); } } else { //its a player, is there any other non-grouped players thats looking for the same instance? QueryResult *result_mp = WorldDatabase.PQuery("SELECT guid,zoneid,is_group,player_name FROM lfg_queue WHERE zoneid = '%u' AND is_group = 0", fields[1].GetUInt32()); if(result_mp->GetRowCount() > 1) { int i = 1; Group* grp; grp = new Group; do { Field* fields_mp = result_mp->Fetch(); Player *plr = sObjectAccessor.FindPlayerByName(fields_mp[3].GetString()); if(!grp->IsCreated()) { if (grp->Create(plr->GetGUID(), plr->GetName())) { sObjectMgr.AddGroup(grp); RemovePlayerFromQueue(plr->GetGUIDLow()); } } else { grp->AddMember(plr->GetGUID(), plr->GetName()); RemovePlayerFromQueue(plr->GetGUIDLow()); } plr = NULL; } while (result_mp->NextRow()); //if this group did not fill up, add it into LFM queue if(!grp->IsFull()) { AddGroupToQueue(grp->GetId(), fields[1].GetUInt32()); } } } } while (result->NextRow()); } }
void WorldSession::HandleMoveWorldportAckOpcode( WorldPacket & /*recv_data*/ ) { sLog.outDebug( "WORLD: got MSG_MOVE_WORLDPORT_ACK." ); MapEntry const* mEntry = sMapStore.LookupEntry(GetPlayer()->GetMapId()); if(!mEntry || !MaNGOS::IsValidMapCoord(GetPlayer()->GetPositionX(),GetPlayer()->GetPositionY())) { LogoutPlayer(false); return; } // reset instance validity GetPlayer()->m_InstanceValid = true; GetPlayer()->SetSemaphoreTeleport(false); GetPlayer()->SendInitialPacketsBeforeAddToMap(); MapManager::Instance().GetMap(GetPlayer()->GetMapId(), GetPlayer())->Add(GetPlayer()); GetPlayer()->SendInitialPacketsAfterAddToMap(); // flight fast teleport case if(GetPlayer()->GetMotionMaster()->top()->GetMovementGeneratorType()==FLIGHT_MOTION_TYPE) { if(!_player->InBattleGround()) { // short preparations to continue flight FlightPathMovementGenerator* flight = (FlightPathMovementGenerator*)(GetPlayer()->GetMotionMaster()->top()); flight->Initialize(*GetPlayer()); SendPath(flight->GetPath(),flight->GetCurrentNode(),flight->GetPathAtMapEnd()); GetPlayer()->SetDontMove(false); return; } // battleground state prepre, stop flight GetPlayer()->GetMotionMaster()->MovementExpired(); GetPlayer()->FlightComplete(); GetPlayer()->ClearTaxiDestinations(); GetPlayer()->StopMoving(); } // resurrect character at enter into instance where his corpse exist after add to map Corpse *corpse = GetPlayer()->GetCorpse(); if (corpse && corpse->GetType() == CORPSE_RESURRECTABLE && corpse->GetMapId() == GetPlayer()->GetMapId()) { if( mEntry && (mEntry->map_type == MAP_INSTANCE || mEntry->map_type == MAP_RAID) ) { GetPlayer()->ResurrectPlayer(0.5f,false); GetPlayer()->SpawnCorpseBones(); GetPlayer()->SaveToDB(); } } // mount allow check if(!_player->GetBaseMap()->IsMountAllowed()) _player->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED); // battleground state preper if(_player->InBattleGround()) { BattleGround *bg = _player->GetBattleGround(); if(bg) { if(bg->GetMapId() == _player->GetMapId()) // we teleported to bg { if(!bg->GetBgRaid(_player->GetTeam())) // first player joined { Group *group = new Group; bg->SetBgRaid(_player->GetTeam(), group); group->ConvertToRaid(); group->AddMember(_player->GetGUID(), _player->GetName()); group->ChangeLeader(_player->GetGUID()); } else // raid already exist { bg->GetBgRaid(_player->GetTeam())->AddMember(_player->GetGUID(), _player->GetName()); } } } } // honorless target if(GetPlayer()->pvpInfo.inHostileArea) GetPlayer()->CastSpell(GetPlayer(), 2479, true); // resummon pet if(GetPlayer()->m_oldpetnumber) { Pet* NewPet = new Pet(GetPlayer()); if(!NewPet->LoadPetFromDB(GetPlayer(), 0, GetPlayer()->m_oldpetnumber, true)) delete NewPet; GetPlayer()->m_oldpetnumber = 0; } GetPlayer()->SetDontMove(false); }
void WorldSession::HandleGroupInviteResponseOpcode(WorldPacket& recv_data) { bool unk = recv_data.ReadBit(); bool accepted = recv_data.ReadBit(); if (unk) recv_data.read_skip<uint32>(); Group* group = GetPlayer()->GetGroupInvite(); if (!group) return; if (accepted) { // remove in from invites in any case group->RemoveInvite(GetPlayer()); if (group->GetLeaderGuid() == GetPlayer()->GetObjectGuid()) { sLog.outError("HandleGroupInviteResponseOpcode: %s tried to accept an invite to his own group", GetPlayer()->GetGuidStr().c_str()); return; } /** error handling **/ /********************/ // not have place if (group->IsFull()) { SendPartyResult(PARTY_OP_INVITE, "", ERR_GROUP_FULL); return; } Player* leader = sObjectMgr.GetPlayer(group->GetLeaderGuid()); // forming a new group, create it if (!group->IsCreated()) { if (leader) group->RemoveInvite(leader); if (group->Create(group->GetLeaderGuid(), group->GetLeaderName())) sObjectMgr.AddGroup(group); else return; } // everything is fine, do it, PLAYER'S GROUP IS SET IN ADDMEMBER!!! if (!group->AddMember(GetPlayer()->GetObjectGuid(), GetPlayer()->GetName())) return; } else { // uninvite, group can be deleted GetPlayer()->UninviteFromGroup(); // remember leader if online Player* leader = sObjectMgr.GetPlayer(group->GetLeaderGuid()); if (!leader || !leader->GetSession()) return; // report WorldPacket data(SMSG_GROUP_DECLINE, 10); // guess size data << GetPlayer()->GetName(); leader->GetSession()->SendPacket(&data); } }
void LFGQueue::Update(uint32 diff) { if(m_QueuedGroups.empty() && m_QueuedPlayers.empty()) return; // Iterate over QueuedPlayersMap to update players timers and remove offline/disconnected players. for(QueuedPlayersMap::iterator qPlayer = m_QueuedPlayers.begin(); qPlayer != m_QueuedPlayers.end(); ++qPlayer) { Player* plr = sObjectMgr.GetPlayer(qPlayer->first); // Player could have been disconnected if(!plr ||!plr->IsInWorld()) { m_OfflinePlayers[qPlayer->first] = qPlayer->second; m_QueuedPlayers.erase(qPlayer); break; } qPlayer->second.timeInLFG += diff; // Update player timer and give him queue priority. if(qPlayer->second.timeInLFG >= (30 * MINUTE * IN_MILLISECONDS)) { qPlayer->second.hasQueuePriority = true; } } if(!m_QueuedGroups.empty()) { // Iterate over QueuedGroupsMap to fill groups with roles they're missing. for(QueuedGroupsMap::iterator qGroup = m_QueuedGroups.begin(); qGroup != m_QueuedGroups.end(); ++qGroup) { Group* grp = sObjectMgr.GetGroupById(qGroup->first); // Safe check if(!grp) return; // Remove group from Queue if it's full if(grp->IsFull()) { RemoveGroupFromQueue(qGroup->first, GROUP_SYSTEM_LEAVE); break; } // Iterate over QueuedPlayersMap to find suitable player to join group for(QueuedPlayersMap::iterator qPlayer = m_QueuedPlayers.begin(); qPlayer != m_QueuedPlayers.end(); ++qPlayer) { Player* plr = sObjectMgr.GetPlayer(qPlayer->first); // Check here that players team and areaId they're in queue are same if(qPlayer->second.team == qGroup->second.team && qPlayer->second.areaId == qGroup->second.areaId) { // Check if player can perform tank role if((canPerformRole(qPlayer->second.roleMask, LFG_ROLE_TANK) & qGroup->second.availableRoles) == LFG_ROLE_TANK) { if(FindRoleToGroup(plr, grp, LFG_ROLE_TANK)) { break; } else { continue; } } // Check if player can perform healer role if((canPerformRole(qPlayer->second.roleMask, LFG_ROLE_HEALER) & qGroup->second.availableRoles) == LFG_ROLE_HEALER) { if(FindRoleToGroup(plr, grp, LFG_ROLE_HEALER)) { break; } else { continue; } } // Check if player can perform dps role if((canPerformRole(qPlayer->second.roleMask, LFG_ROLE_DPS) & qGroup->second.availableRoles) == LFG_ROLE_DPS) { if(FindRoleToGroup(plr, grp, LFG_ROLE_DPS)) { break; } else { continue; } } // Check if group is full, no need to try to iterate same group if it's already full. if(grp->IsFull()) { RemoveGroupFromQueue(qGroup->first, GROUP_SYSTEM_LEAVE); break; } } } // Update group timer. After each 5 minutes group will be broadcasted they're still waiting more members. if (qGroup->second.groupTimer <= diff) { WorldPacket data; BuildInProgressPacket(data); grp->BroadcastPacket(&data, true); qGroup->second.groupTimer = 5 * MINUTE * IN_MILLISECONDS; } else { qGroup->second.groupTimer -= diff; } } } // Pick first 2 players and form group out of them also inserting them into queue as group. if(m_QueuedPlayers.size() > 5) { // Pick Leader as first target. QueuedPlayersMap::iterator nPlayer1 = m_QueuedPlayers.begin(); if(findInArea(nPlayer1->second.areaId) > 5) { Group* newQueueGroup = new Group; // Iterate of QueuedPlayersMap and pick first member to accompany leader. for(QueuedPlayersMap::iterator nPlayer2 = m_QueuedPlayers.begin(); nPlayer2 != m_QueuedPlayers.end(); ++nPlayer2) { if(nPlayer1->first == nPlayer2->first) continue; if(nPlayer1->second.team == nPlayer2->second.team && nPlayer1->second.areaId == nPlayer2->second.areaId) { Player* leader = sObjectMgr.GetPlayer(nPlayer1->first); Player* member = sObjectMgr.GetPlayer(nPlayer2->first); uint32 areaId = nPlayer1->second.areaId; if(!newQueueGroup->IsCreated()) { if(newQueueGroup->Create(leader->GetObjectGuid(), leader->GetName())) sObjectMgr.AddGroup(newQueueGroup); else return; } WorldPacket data; BuildMemberAddedPacket(data, member->GetGUID()); leader->GetSession()->SendPacket(&data); // Add member to the group. Leader is already added upon creation of group. newQueueGroup->AddMember(member->GetObjectGuid(), member->GetName(), GROUP_LFG); // Add this new group to GroupQueue now and remove players from PlayerQueue RemovePlayerFromQueue(nPlayer1->first, PLAYER_SYSTEM_LEAVE); RemovePlayerFromQueue(nPlayer2->first, PLAYER_SYSTEM_LEAVE); AddToQueue(leader, areaId); break; } } } } }
void WorldSession::HandlePartyInviteResponseOpcode(WorldPackets::Party::PartyInviteResponse& packet) { Group* group = GetPlayer()->GetGroupInvite(); if (!group) return; if (packet.Accept) { // Remove player from invitees in any case group->RemoveInvite(GetPlayer()); if (group->GetLeaderGUID() == GetPlayer()->GetGUID()) { TC_LOG_ERROR("network", "HandleGroupAcceptOpcode: player %s (%s) tried to accept an invite to his own group", GetPlayer()->GetName().c_str(), GetPlayer()->GetGUID().ToString().c_str()); return; } // Group is full if (group->IsFull()) { SendPartyResult(PARTY_OP_INVITE, "", ERR_GROUP_FULL); return; } Player* leader = ObjectAccessor::FindPlayer(group->GetLeaderGUID()); // Forming a new group, create it if (!group->IsCreated()) { // This can happen if the leader is zoning. To be removed once delayed actions for zoning are implemented if (!leader) { group->RemoveAllInvites(); return; } // If we're about to create a group there really should be a leader present ASSERT(leader); group->RemoveInvite(leader); group->Create(leader); sGroupMgr->AddGroup(group); } // Everything is fine, do it, PLAYER'S GROUP IS SET IN ADDMEMBER!!! if (!group->AddMember(GetPlayer())) return; group->BroadcastGroupUpdate(); } else { // Remember leader if online (group pointer will be invalid if group gets disbanded) Player* leader = ObjectAccessor::FindConnectedPlayer(group->GetLeaderGUID()); // uninvite, group can be deleted GetPlayer()->UninviteFromGroup(); if (!leader || !leader->GetSession()) return; // report WorldPackets::Party::GroupDecline decline(GetPlayer()->GetName()); leader->GetSession()->SendPacket(decline.Write()); } }
void LfgMgr::UpdateLfgQueue(uint32 LfgDungeonId) { if (LfgDungeonId >= MAX_DUNGEONS) return; LfgPlayerList possibleGroupLeaders; LfgPlayerList possibleMembers; LfgPlayerList::iterator itr; LfgPlayerList::iterator it2; LfgPlayerList::iterator it3; Player * plr = 0; uint32 i; //LfgMatch * pMatch; // only update on autojoinable dungeons if (LfgDungeonTypes[LfgDungeonId] != LFG_INSTANCE && LfgDungeonTypes[LfgDungeonId] != LFG_HEROIC_DUNGEON) return; m_lock.Acquire(); for (itr = m_lookingForGroup[LfgDungeonId].begin(); itr != m_lookingForGroup[LfgDungeonId].end(); ++itr) { plr = *itr; if (plr->m_lfgInviterGuid || plr->m_lfgMatch != NULL) continue; // possible member? if (plr->m_Autojoin) possibleMembers.push_back(plr); } for (itr = m_lookingForMore[LfgDungeonId].begin(); itr != m_lookingForMore[LfgDungeonId].end(); ++itr) { if (plr->GetGroup()) { // check if this is a suitable candidate for a group for others to join if (plr->m_AutoAddMem && plr->IsGroupLeader() && !plr->GetGroup()->IsFull() && plr->GetGroup()->GetGroupType() == GROUP_TYPE_PARTY) { possibleGroupLeaders.push_back(plr); continue; } if (plr->m_lfgInviterGuid || plr->m_lfgMatch != NULL) continue; // just a guy in a group continue; } } // look through our members, as well as our groups and see if we can add anyone to any groups // if not, if we have enough members, create a new group for them. if (possibleMembers.size() > 0) { for (itr = possibleGroupLeaders.begin(); itr != possibleGroupLeaders.end(); ++itr) { for (it2 = possibleMembers.begin(); it2 != possibleMembers.end();) { if ((*itr)->GetGroup()->IsFull()) { ++it2; continue; } // found a group for him, lets insert him. if ((*itr)->GetGroup()->AddMember((*it2)->m_playerInfo)) { (*it2)->m_lfgInviterGuid = (*itr)->GetLowGUID(); it3 = it2; ++it2; possibleMembers.erase(it2); } else ++it2; } } } // do we still have any members left over (enough to form a group) while (possibleMembers.size() > 1) { /*pMatch = new LfgMatch(LfgDungeonId); pMatch->lock.Acquire(); for(i = 0; i < 5, possibleMembers.size() > 0; ++i) { pMatch->PendingPlayers.insert(possibleMembers.front()); possibleMembers.front()->SendMeetingStoneQueue(LfgDungeonId, 0); possibleMembers.front()->GetSession()->OutPacket(SMSG_LFG_INVITE, 4, &LfgDungeonId); possibleMembers.front()->m_lfgMatch = pMatch; possibleMembers.pop_front(); } pMatch->lock.Release();*/ Group * pGroup = new Group(true); for (i = 0; i < 5 && possibleMembers.size() > 0; ++i) { pGroup->AddMember(possibleMembers.front()->m_playerInfo); possibleMembers.front()->SendMeetingStoneQueue(LfgDungeonId, 0); m_lookingForGroup[LfgDungeonId].remove(possibleMembers.front()); possibleMembers.pop_front(); } } m_lock.Release(); }
//////////////////////////////////////////////////////////////// ///This function handles CMSG_GROUP_ACCEPT and deny: //////////////////////////////////////////////////////////////// void WorldSession::HandleGroupAcceptOpcode( WorldPacket & recv_data ) { if(!_player->IsInWorld()) { return; } uint8 packet_type; recv_data >> packet_type; if( packet_type == 0 ) //0x80 for group accept and 0 is for decline { HandleGroupDeclineOpcode( recv_data ); return; } Player *player = objmgr.GetPlayer(_player->GetInviter()); if ( !player ) { return; } //check if this invite is still valid if( player->GetInviter() != _player->GetLowGUID() || _player->GetInviter() != player->GetLowGUID() ) { _player->BroadcastMessage( "Group invite from player %s expired", player->GetName() ); player->BroadcastMessage( "Group invite from player %s expired", _player->GetName() ); return; } player->SetInviter(0); _player->SetInviter(0); Group *grp = player->GetGroup(); if(grp) { grp->AddMember(_player->m_playerInfo); _player->dungeon_difficulty = grp->dungeon_difficulty; _player->raid_difficulty = grp->raid_difficulty; _player->SendDungeonDifficulty(); _player->SendRaidDifficulty(); //sInstanceSavingManager.ResetSavedInstancesForPlayer(_player); return; } // If we're this far, it means we have no existing group, and have to make one. grp = new Group(true); grp->dungeon_difficulty = player->dungeon_difficulty; grp->raid_difficulty = player->raid_difficulty; grp->AddMember(player->m_playerInfo); // add the inviter first, therefore he is the leader grp->AddMember(_player->m_playerInfo); // add us. _player->dungeon_difficulty = grp->dungeon_difficulty; _player->raid_difficulty = grp->raid_difficulty; _player->SendDungeonDifficulty(); _player->SendRaidDifficulty(); Instance *instance = sInstanceMgr.GetInstanceByIds(player->GetMapId(), player->GetInstanceID()); if(instance != NULL && instance->m_creatorGuid == player->GetLowGUID()) { grp->AddSavedInstance(instance->m_mapId,instance->instance_difficulty,instance->m_instanceId); instance->m_creatorGroup = grp->GetID(); instance->m_creatorGuid = 0; instance->SaveToDB(); } //sInstanceSavingManager.ResetSavedInstancesForPlayer(_player); // Currentgroup and all that shit are set by addmember. }