// Add group or player into queue. If player has group and he's a leader then whole party will be added to queue. void LFGQueue::AddToQueue(Player* leader, uint32 queAreaID) { if(!leader) return; if (AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(queAreaID)) { if (DisableMgr::IsDisabledFor(DISABLE_TYPE_MAP, areaEntry->mapid)) { ChatHandler(leader->GetSession()).SendSysMessage(LANG_MAP_IS_DISABLED); return; } } Group* grp = leader->GetGroup(); //add players from group to queue list & group to group list // Calculate what roles group need and add it to the GroupQueueList, (DONT'ADD PLAYERS!) if (grp && grp->IsLeader(leader->GetObjectGuid())) { // Add group to queued groups list LFGGroupQueueInfo& i_Group = m_QueuedGroups[grp->GetId()]; grp->CalculateLFGRoles(i_Group); i_Group.team = leader->GetTeam(); i_Group.areaId = queAreaID; i_Group.groupTimer = 5 * MINUTE * IN_MILLISECONDS; // Minute timer for SMSG_MEETINGSTONE_IN_PROGRESS grp->SetLFGAreaId(queAreaID); WorldPacket data; BuildSetQueuePacket(data, queAreaID, MEETINGSTONE_STATUS_JOINED_QUEUE); grp->BroadcastPacket(&data, true); } else if(!grp) { // Add player to queued players list LFGPlayerQueueInfo& i_Player = m_QueuedPlayers[leader->GetObjectGuid()]; i_Player.roleMask = CalculateRoles((Classes)leader->getClass()); i_Player.team = leader->GetTeam(); i_Player.areaId = queAreaID; i_Player.hasQueuePriority = false; leader->GetSession()->SendMeetingstoneSetqueue(queAreaID, MEETINGSTONE_STATUS_JOINED_QUEUE); } else // Player is in group, but it's not leader MANGOS_ASSERT(false && "LFGQueue::AddToQueue called while player is not leader and in group."); }
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()); } }