2012-10-19 14:00:40 +02:00
/*
2017-01-01 16:21:30 +01:00
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
2012-10-19 14:00:40 +02: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 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 <http://www.gnu.org/licenses/>.
*/
#include "ObjectDefines.h"
#include "Containers.h"
#include "Group.h"
#include "LFGQueue.h"
#include "LFGMgr.h"
#include "Log.h"
2013-02-04 04:43:18 +01:00
namespace lfg
{
2012-10-19 14:00:40 +02:00
/**
Given a list of guids returns the concatenation using | as delimiter
@param[in] check list of guids
@returns Concatenated string
*/
2014-09-14 16:14:12 +02:00
std :: string ConcatenateGuids ( GuidList const & check )
2012-10-19 14:00:40 +02:00
{
if ( check . empty ())
return "" ;
// need the guids in order to avoid duplicates
2014-09-14 16:14:12 +02:00
GuidSet guids ( check . begin (), check . end ());
2012-10-19 14:00:40 +02:00
std :: ostringstream o ;
2014-09-14 16:14:12 +02:00
GuidSet :: const_iterator it = guids . begin ();
2014-10-23 17:01:26 +02:00
o << * it ;
2012-10-19 14:00:40 +02:00
for ( ++ it ; it != guids . end (); ++ it )
2014-10-23 17:01:26 +02:00
o << '|' << * it ;
2012-10-19 14:00:40 +02:00
return o . str ();
}
2012-10-29 20:13:42 +01:00
char const * GetCompatibleString ( LfgCompatibility compatibles )
2012-10-19 14:00:40 +02:00
{
switch ( compatibles )
{
case LFG_COMPATIBILITY_PENDING :
return "Pending" ;
case LFG_COMPATIBLES_BAD_STATES :
return "Compatibles (Bad States)" ;
case LFG_COMPATIBLES_MATCH :
return "Match" ;
case LFG_COMPATIBLES_WITH_LESS_PLAYERS :
return "Compatibles (Not enough players)" ;
case LFG_INCOMPATIBLES_HAS_IGNORES :
return "Has ignores" ;
case LFG_INCOMPATIBLES_MULTIPLE_LFG_GROUPS :
return "Multiple Lfg Groups" ;
case LFG_INCOMPATIBLES_NO_DUNGEONS :
return "Incompatible dungeons" ;
case LFG_INCOMPATIBLES_NO_ROLES :
return "Incompatible roles" ;
case LFG_INCOMPATIBLES_TOO_MUCH_PLAYERS :
2015-09-05 17:08:37 +02:00
return "Too many players" ;
2012-10-19 14:00:40 +02:00
case LFG_INCOMPATIBLES_WRONG_GROUP_SIZE :
return "Wrong group size" ;
default :
return "Unknown" ;
}
}
2015-09-05 21:18:52 +02:00
std :: string LFGQueue :: GetDetailedMatchRoles ( GuidList const & check ) const
2015-08-31 22:45:45 +02:00
{
if ( check . empty ())
return "" ;
// need the guids in order to avoid duplicates
GuidSet guids ( check . begin (), check . end ());
std :: ostringstream o ;
GuidSet :: const_iterator it = guids . begin ();
o << it -> ToString ();
2015-09-05 21:18:52 +02:00
LfgQueueDataContainer :: const_iterator itQueue = QueueDataStore . find ( * it );
2015-09-05 17:08:37 +02:00
if ( itQueue != QueueDataStore . end ())
2015-08-31 22:45:45 +02:00
{
// skip leader flag, log only dps/tank/healer
2015-09-05 21:18:52 +02:00
auto role = itQueue -> second . roles . find ( * it );
if ( role != itQueue -> second . roles . end ())
o << ' ' << GetRolesString ( itQueue -> second . roles . at ( * it ) & uint8 ( ~ PLAYER_ROLE_LEADER ));
2015-08-31 22:45:45 +02:00
}
for ( ++ it ; it != guids . end (); ++ it )
{
o << '|' << it -> ToString ();
itQueue = QueueDataStore . find ( * it );
2015-09-05 17:08:37 +02:00
if ( itQueue != QueueDataStore . end ())
2015-08-31 22:45:45 +02:00
{
// skip leader flag, log only dps/tank/healer
2015-09-05 21:18:52 +02:00
auto role = itQueue -> second . roles . find ( * it );
if ( role != itQueue -> second . roles . end ())
o << ' ' << GetRolesString ( itQueue -> second . roles . at ( * it ) & uint8 ( ~ PLAYER_ROLE_LEADER ));
2015-08-31 22:45:45 +02:00
}
}
return o . str ();
}
2016-04-11 12:33:25 -04:00
void LFGQueue :: AddToQueue ( ObjectGuid guid , bool reAdd )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
LfgQueueDataContainer :: iterator itQueue = QueueDataStore . find ( guid );
if ( itQueue == QueueDataStore . end ())
2012-10-19 14:00:40 +02:00
{
2014-09-16 20:47:08 +02:00
TC_LOG_ERROR ( "lfg.queue.add" , "Queue data not found for [%s]" , guid . ToString (). c_str ());
2012-10-19 14:00:40 +02:00
return ;
}
2016-04-11 12:33:25 -04:00
if ( reAdd )
AddToFrontCurrentQueue ( guid );
else
AddToNewQueue ( guid );
2012-10-19 14:00:40 +02:00
}
2014-09-14 16:14:12 +02:00
void LFGQueue :: RemoveFromQueue ( ObjectGuid guid )
2012-10-19 14:00:40 +02:00
{
RemoveFromNewQueue ( guid );
RemoveFromCurrentQueue ( guid );
RemoveFromCompatibles ( guid );
2012-10-29 20:13:42 +01:00
std :: ostringstream o ;
2014-10-23 17:01:26 +02:00
o << guid ;
2012-10-29 20:13:42 +01:00
std :: string sguid = o . str ();
2012-10-29 20:56:37 +01:00
LfgQueueDataContainer :: iterator itDelete = QueueDataStore . end ();
for ( LfgQueueDataContainer :: iterator itr = QueueDataStore . begin (); itr != QueueDataStore . end (); ++ itr )
2012-10-29 20:13:42 +01:00
if ( itr -> first != guid )
{
if ( std :: string :: npos != itr -> second . bestCompatible . find ( sguid ))
{
itr -> second . bestCompatible . clear ();
FindBestCompatibleInQueue ( itr );
}
}
else
itDelete = itr ;
2012-10-29 20:56:37 +01:00
if ( itDelete != QueueDataStore . end ())
QueueDataStore . erase ( itDelete );
2012-10-19 14:00:40 +02:00
}
2014-09-14 16:14:12 +02:00
void LFGQueue :: AddToNewQueue ( ObjectGuid guid )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
newToQueueStore . push_back ( guid );
2012-10-19 14:00:40 +02:00
}
2014-09-14 16:14:12 +02:00
void LFGQueue :: RemoveFromNewQueue ( ObjectGuid guid )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
newToQueueStore . remove ( guid );
2012-10-19 14:00:40 +02:00
}
2014-09-14 16:14:12 +02:00
void LFGQueue :: AddToCurrentQueue ( ObjectGuid guid )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
currentQueueStore . push_back ( guid );
2012-10-19 14:00:40 +02:00
}
2016-04-11 12:33:25 -04:00
void LFGQueue :: AddToFrontCurrentQueue ( ObjectGuid guid )
{
currentQueueStore . push_front ( guid );
}
2014-09-14 16:14:12 +02:00
void LFGQueue :: RemoveFromCurrentQueue ( ObjectGuid guid )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
currentQueueStore . remove ( guid );
2012-10-19 14:00:40 +02:00
}
2014-09-14 16:14:12 +02:00
void LFGQueue :: AddQueueData ( ObjectGuid guid , time_t joinTime , LfgDungeonSet const & dungeons , LfgRolesMap const & rolesMap )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
QueueDataStore [ guid ] = LfgQueueData ( joinTime , dungeons , rolesMap );
2012-10-19 14:00:40 +02:00
AddToQueue ( guid );
}
2014-09-14 16:14:12 +02:00
void LFGQueue :: RemoveQueueData ( ObjectGuid guid )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
LfgQueueDataContainer :: iterator it = QueueDataStore . find ( guid );
if ( it != QueueDataStore . end ())
QueueDataStore . erase ( it );
2012-10-19 14:00:40 +02:00
}
2012-10-29 20:13:42 +01:00
void LFGQueue :: UpdateWaitTimeAvg ( int32 waitTime , uint32 dungeonId )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
LfgWaitTime & wt = waitTimesAvgStore [ dungeonId ];
2012-10-19 14:00:40 +02:00
uint32 old_number = wt . number ++ ;
wt . time = int32 (( wt . time * old_number + waitTime ) / wt . number );
}
2012-10-29 20:13:42 +01:00
void LFGQueue :: UpdateWaitTimeTank ( int32 waitTime , uint32 dungeonId )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
LfgWaitTime & wt = waitTimesTankStore [ dungeonId ];
2012-10-19 14:00:40 +02:00
uint32 old_number = wt . number ++ ;
wt . time = int32 (( wt . time * old_number + waitTime ) / wt . number );
}
2012-10-29 20:13:42 +01:00
void LFGQueue :: UpdateWaitTimeHealer ( int32 waitTime , uint32 dungeonId )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
LfgWaitTime & wt = waitTimesHealerStore [ dungeonId ];
2012-10-19 14:00:40 +02:00
uint32 old_number = wt . number ++ ;
wt . time = int32 (( wt . time * old_number + waitTime ) / wt . number );
}
2012-10-29 20:13:42 +01:00
void LFGQueue :: UpdateWaitTimeDps ( int32 waitTime , uint32 dungeonId )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
LfgWaitTime & wt = waitTimesDpsStore [ dungeonId ];
2012-10-19 14:00:40 +02:00
uint32 old_number = wt . number ++ ;
wt . time = int32 (( wt . time * old_number + waitTime ) / wt . number );
}
/**
Remove from cached compatible dungeons any entry that contains the given guid
@param[in] guid Guid to remove from compatible cache
*/
2014-09-14 16:14:12 +02:00
void LFGQueue :: RemoveFromCompatibles ( ObjectGuid guid )
2012-10-19 14:00:40 +02:00
{
std :: stringstream out ;
2014-10-23 17:01:26 +02:00
out << guid ;
2012-10-19 14:00:40 +02:00
std :: string strGuid = out . str ();
2014-09-14 16:14:12 +02:00
TC_LOG_DEBUG ( "lfg.queue.data.compatibles.remove" , "Removing %s" , guid . ToString (). c_str ());
2012-10-29 20:56:37 +01:00
for ( LfgCompatibleContainer :: iterator itNext = CompatibleMapStore . begin (); itNext != CompatibleMapStore . end ();)
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
LfgCompatibleContainer :: iterator it = itNext ++ ;
2012-10-29 20:13:42 +01:00
if ( std :: string :: npos != it -> first . find ( strGuid ))
2012-10-29 20:56:37 +01:00
CompatibleMapStore . erase ( it );
2012-10-19 14:00:40 +02:00
}
}
/**
Stores the compatibility of a list of guids
@param[in] key String concatenation of guids (| used as separator)
@param[in] compatibles type of compatibility
*/
2012-10-29 20:13:42 +01:00
void LFGQueue :: SetCompatibles ( std :: string const & key , LfgCompatibility compatibles )
{
2012-10-29 20:56:37 +01:00
LfgCompatibilityData & data = CompatibleMapStore [ key ];
2012-10-29 20:13:42 +01:00
data . compatibility = compatibles ;
}
void LFGQueue :: SetCompatibilityData ( std :: string const & key , LfgCompatibilityData const & data )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
CompatibleMapStore [ key ] = data ;
2012-10-19 14:00:40 +02:00
}
/**
Get the compatibility of a group of guids
@param[in] key String concatenation of guids (| used as separator)
@return LfgCompatibility type of compatibility
*/
2012-10-29 20:13:42 +01:00
LfgCompatibility LFGQueue :: GetCompatibles ( std :: string const & key )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:56:37 +01:00
LfgCompatibleContainer :: iterator itr = CompatibleMapStore . find ( key );
if ( itr != CompatibleMapStore . end ())
2012-10-29 20:13:42 +01:00
return itr -> second . compatibility ;
2012-10-19 14:00:40 +02:00
return LFG_COMPATIBILITY_PENDING ;
}
2012-10-29 20:13:42 +01:00
LfgCompatibilityData * LFGQueue :: GetCompatibilityData ( std :: string const & key )
{
2012-10-29 20:56:37 +01:00
LfgCompatibleContainer :: iterator itr = CompatibleMapStore . find ( key );
if ( itr != CompatibleMapStore . end ())
2012-10-29 20:13:42 +01:00
return & ( itr -> second );
return NULL ;
}
uint8 LFGQueue :: FindGroups ()
2012-10-19 14:00:40 +02:00
{
uint8 proposals = 0 ;
2014-09-14 16:14:12 +02:00
GuidList firstNew ;
2012-10-29 20:56:37 +01:00
while ( ! newToQueueStore . empty ())
2012-10-19 14:00:40 +02:00
{
2014-09-14 16:14:12 +02:00
ObjectGuid frontguid = newToQueueStore . front ();
TC_LOG_DEBUG ( "lfg.queue.match.check.new" , "Checking [%s] newToQueue(%u), currentQueue(%u)" , frontguid . ToString (). c_str (),
uint32 ( newToQueueStore . size ()), uint32 ( currentQueueStore . size ()));
2012-10-19 14:00:40 +02:00
firstNew . clear ();
firstNew . push_back ( frontguid );
RemoveFromNewQueue ( frontguid );
2014-09-14 16:14:12 +02:00
GuidList temporalList = currentQueueStore ;
2012-10-19 14:00:40 +02:00
LfgCompatibility compatibles = FindNewGroups ( firstNew , temporalList );
if ( compatibles == LFG_COMPATIBLES_MATCH )
++ proposals ;
else
AddToCurrentQueue ( frontguid ); // Lfg group not found, add this group to the queue.
}
return proposals ;
}
/**
Checks que main queue to try to form a Lfg group. Returns first match found (if any)
@param[in] check List of guids trying to match with other groups
@param[in] all List of all other guids in main queue to match against
@return LfgCompatibility type of compatibility between groups
*/
2014-09-14 16:14:12 +02:00
LfgCompatibility LFGQueue :: FindNewGroups ( GuidList & check , GuidList & all )
2012-10-19 14:00:40 +02:00
{
std :: string strGuids = ConcatenateGuids ( check );
LfgCompatibility compatibles = GetCompatibles ( strGuids );
2015-08-31 22:45:45 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.check" , "Guids: (%s): %s - all(%s)" , GetDetailedMatchRoles ( check ). c_str (), GetCompatibleString ( compatibles ), GetDetailedMatchRoles ( all ). c_str ());
2012-10-29 13:58:48 +01:00
if ( compatibles == LFG_COMPATIBILITY_PENDING ) // Not previously cached, calculate
2012-10-19 14:00:40 +02:00
compatibles = CheckCompatibility ( check );
2012-10-29 13:58:48 +01:00
if ( compatibles == LFG_COMPATIBLES_BAD_STATES && sLFGMgr -> AllQueued ( check ))
{
2015-08-31 22:45:45 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.check" , "Guids: (%s) compatibles (cached) changed from bad states to match" , GetDetailedMatchRoles ( check ). c_str ());
2012-10-29 13:58:48 +01:00
SetCompatibles ( strGuids , LFG_COMPATIBLES_MATCH );
return LFG_COMPATIBLES_MATCH ;
}
2012-10-19 14:00:40 +02:00
if ( compatibles != LFG_COMPATIBLES_WITH_LESS_PLAYERS )
return compatibles ;
// Try to match with queued groups
while ( ! all . empty ())
{
check . push_back ( all . front ());
all . pop_front ();
LfgCompatibility subcompatibility = FindNewGroups ( check , all );
if ( subcompatibility == LFG_COMPATIBLES_MATCH )
return LFG_COMPATIBLES_MATCH ;
check . pop_back ();
}
return compatibles ;
}
/**
Check compatibilities between groups. If group is Matched proposal will be created
@param[in] check List of guids to check compatibilities
@return LfgCompatibility type of compatibility
*/
2014-09-14 16:14:12 +02:00
LfgCompatibility LFGQueue :: CheckCompatibility ( GuidList check )
2012-10-19 14:00:40 +02:00
{
std :: string strGuids = ConcatenateGuids ( check );
LfgProposal proposal ;
LfgDungeonSet proposalDungeons ;
LfgGroupsMap proposalGroups ;
LfgRolesMap proposalRoles ;
// Check for correct size
2015-05-19 02:55:53 +01:00
if ( check . size () > MAX_GROUP_SIZE || check . empty ())
2012-10-19 14:00:40 +02:00
{
2015-08-31 22:45:45 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.compatibility.check" , "Guids: (%s): Size wrong - Not compatibles" , GetDetailedMatchRoles ( check ). c_str ());
2012-10-19 14:00:40 +02:00
return LFG_INCOMPATIBLES_WRONG_GROUP_SIZE ;
}
// Check all-but-new compatiblitity
if ( check . size () > 2 )
{
2014-09-14 16:14:12 +02:00
ObjectGuid frontGuid = check . front ();
2012-10-19 14:00:40 +02:00
check . pop_front ();
// Check all-but-new compatibilities (New, A, B, C, D) --> check(A, B, C, D)
LfgCompatibility child_compatibles = CheckCompatibility ( check );
if ( child_compatibles < LFG_COMPATIBLES_WITH_LESS_PLAYERS ) // Group not compatible
{
2015-08-31 22:45:45 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.compatibility.check" , "Guids: (%s) child %s not compatibles" , strGuids . c_str (), GetDetailedMatchRoles ( check ). c_str ());
2012-10-19 14:00:40 +02:00
SetCompatibles ( strGuids , child_compatibles );
return child_compatibles ;
}
check . push_front ( frontGuid );
}
// Check if more than one LFG group and number of players joining
uint8 numPlayers = 0 ;
uint8 numLfgGroups = 0 ;
2015-05-19 02:55:53 +01:00
for ( GuidList :: const_iterator it = check . begin (); it != check . end () && numLfgGroups < 2 && numPlayers <= MAX_GROUP_SIZE ; ++ it )
2012-10-19 14:00:40 +02:00
{
2014-09-14 16:14:12 +02:00
ObjectGuid guid = * it ;
2012-10-29 20:56:37 +01:00
LfgQueueDataContainer :: iterator itQueue = QueueDataStore . find ( guid );
if ( itQueue == QueueDataStore . end ())
2012-10-19 14:00:40 +02:00
{
2014-09-14 16:14:12 +02:00
TC_LOG_ERROR ( "lfg.queue.match.compatibility.check" , "Guid: [%s] is not queued but listed as queued!" , guid . ToString (). c_str ());
2012-10-19 14:00:40 +02:00
RemoveFromQueue ( guid );
return LFG_COMPATIBILITY_PENDING ;
}
// Store group so we don't need to call Mgr to get it later (if it's player group will be 0 otherwise would have joined as group)
for ( LfgRolesMap :: const_iterator it2 = itQueue -> second . roles . begin (); it2 != itQueue -> second . roles . end (); ++ it2 )
2014-10-27 12:03:35 +01:00
proposalGroups [ it2 -> first ] = itQueue -> first . IsParty () ? itQueue -> first : ObjectGuid :: Empty ;
2012-10-19 14:00:40 +02:00
numPlayers += itQueue -> second . roles . size ();
if ( sLFGMgr -> IsLfgGroup ( guid ))
{
if ( ! numLfgGroups )
proposal . group = guid ;
++ numLfgGroups ;
}
}
2015-05-19 02:55:53 +01:00
// Group with less that MAX_GROUP_SIZE members always compatible
if ( check . size () == 1 && numPlayers != MAX_GROUP_SIZE )
2012-10-19 14:00:40 +02:00
{
2015-08-31 22:45:45 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.compatibility.check" , "Guids: (%s) single group. Compatibles" , GetDetailedMatchRoles ( check ). c_str ());
2012-10-29 20:56:37 +01:00
LfgQueueDataContainer :: iterator itQueue = QueueDataStore . find ( check . front ());
2012-10-29 20:13:42 +01:00
LfgCompatibilityData data ( LFG_COMPATIBLES_WITH_LESS_PLAYERS );
data . roles = itQueue -> second . roles ;
LFGMgr :: CheckGroupRoles ( data . roles );
UpdateBestCompatibleInQueue ( itQueue , strGuids , data . roles );
SetCompatibilityData ( strGuids , data );
2012-10-19 14:00:40 +02:00
return LFG_COMPATIBLES_WITH_LESS_PLAYERS ;
}
if ( numLfgGroups > 1 )
{
2015-08-31 22:45:45 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.compatibility.check" , "Guids: (%s) More than one Lfggroup (%u)" , GetDetailedMatchRoles ( check ). c_str (), numLfgGroups );
2012-10-19 14:00:40 +02:00
SetCompatibles ( strGuids , LFG_INCOMPATIBLES_MULTIPLE_LFG_GROUPS );
return LFG_INCOMPATIBLES_MULTIPLE_LFG_GROUPS ;
}
2015-05-19 02:55:53 +01:00
if ( numPlayers > MAX_GROUP_SIZE )
2012-10-19 14:00:40 +02:00
{
2015-09-05 17:08:37 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.compatibility.check" , "Guids: (%s) Too many players (%u)" , GetDetailedMatchRoles ( check ). c_str (), numPlayers );
2012-10-19 14:00:40 +02:00
SetCompatibles ( strGuids , LFG_INCOMPATIBLES_TOO_MUCH_PLAYERS );
return LFG_INCOMPATIBLES_TOO_MUCH_PLAYERS ;
}
// If it's single group no need to check for duplicate players, ignores, bad roles or bad dungeons as it's been checked before joining
if ( check . size () > 1 )
{
2014-09-14 16:14:12 +02:00
for ( GuidList :: const_iterator it = check . begin (); it != check . end (); ++ it )
2012-10-19 14:00:40 +02:00
{
2014-09-14 16:14:12 +02:00
LfgRolesMap const & roles = QueueDataStore [( * it )]. roles ;
2012-10-19 14:00:40 +02:00
for ( LfgRolesMap :: const_iterator itRoles = roles . begin (); itRoles != roles . end (); ++ itRoles )
{
LfgRolesMap :: const_iterator itPlayer ;
for ( itPlayer = proposalRoles . begin (); itPlayer != proposalRoles . end (); ++ itPlayer )
{
if ( itRoles -> first == itPlayer -> first )
2014-09-16 20:47:08 +02:00
TC_LOG_ERROR ( "lfg.queue.match.compatibility.check" , "Guids: ERROR! Player multiple times in queue! [%s]" , itRoles -> first . ToString (). c_str ());
2012-10-19 14:00:40 +02:00
else if ( sLFGMgr -> HasIgnore ( itRoles -> first , itPlayer -> first ))
break ;
}
if ( itPlayer == proposalRoles . end ())
proposalRoles [ itRoles -> first ] = itRoles -> second ;
}
}
if ( uint8 playersize = numPlayers - proposalRoles . size ())
{
2015-08-31 22:45:45 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.compatibility.check" , "Guids: (%s) not compatible, %u players are ignoring each other" , GetDetailedMatchRoles ( check ). c_str (), playersize );
2012-10-19 14:00:40 +02:00
SetCompatibles ( strGuids , LFG_INCOMPATIBLES_HAS_IGNORES );
return LFG_INCOMPATIBLES_HAS_IGNORES ;
}
2012-10-29 20:13:42 +01:00
LfgRolesMap debugRoles = proposalRoles ;
2012-10-19 14:00:40 +02:00
if ( ! LFGMgr :: CheckGroupRoles ( proposalRoles ))
{
std :: ostringstream o ;
for ( LfgRolesMap :: const_iterator it = debugRoles . begin (); it != debugRoles . end (); ++ it )
2014-10-23 17:01:26 +02:00
o << ", " << it -> first << ": " << GetRolesString ( it -> second );
2012-10-19 14:00:40 +02:00
2015-08-31 22:45:45 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.compatibility.check" , "Guids: (%s) Roles not compatible%s" , GetDetailedMatchRoles ( check ). c_str (), o . str (). c_str ());
2012-10-19 14:00:40 +02:00
SetCompatibles ( strGuids , LFG_INCOMPATIBLES_NO_ROLES );
return LFG_INCOMPATIBLES_NO_ROLES ;
}
2014-09-14 16:14:12 +02:00
GuidList :: iterator itguid = check . begin ();
2012-10-29 20:56:37 +01:00
proposalDungeons = QueueDataStore [ * itguid ]. dungeons ;
2012-10-19 14:00:40 +02:00
std :: ostringstream o ;
2014-10-23 17:01:26 +02:00
o << ", " << * itguid << ": (" << ConcatenateDungeons ( proposalDungeons ) << ")" ;
2012-10-19 14:00:40 +02:00
for ( ++ itguid ; itguid != check . end (); ++ itguid )
{
LfgDungeonSet temporal ;
2014-09-14 16:14:12 +02:00
LfgDungeonSet & dungeons = QueueDataStore [ * itguid ]. dungeons ;
2014-10-23 17:01:26 +02:00
o << ", " << * itguid << ": (" << ConcatenateDungeons ( dungeons ) << ")" ;
2012-10-19 14:00:40 +02:00
std :: set_intersection ( proposalDungeons . begin (), proposalDungeons . end (), dungeons . begin (), dungeons . end (), std :: inserter ( temporal , temporal . begin ()));
proposalDungeons = temporal ;
}
if ( proposalDungeons . empty ())
{
2015-08-31 22:45:45 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.compatibility.check" , "Guids: (%s) No compatible dungeons%s" , GetDetailedMatchRoles ( check ). c_str (), o . str (). c_str ());
2012-10-19 14:00:40 +02:00
SetCompatibles ( strGuids , LFG_INCOMPATIBLES_NO_DUNGEONS );
return LFG_INCOMPATIBLES_NO_DUNGEONS ;
}
}
else
{
2014-09-14 16:14:12 +02:00
ObjectGuid gguid = * check . begin ();
2012-10-29 20:56:37 +01:00
const LfgQueueData & queue = QueueDataStore [ gguid ];
2012-10-19 14:00:40 +02:00
proposalDungeons = queue . dungeons ;
proposalRoles = queue . roles ;
LFGMgr :: CheckGroupRoles ( proposalRoles ); // assing new roles
}
// Enough players?
2015-05-19 02:55:53 +01:00
if ( numPlayers != MAX_GROUP_SIZE )
2012-10-19 14:00:40 +02:00
{
2015-08-31 22:45:45 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.compatibility.check" , "Guids: (%s) Compatibles but not enough players(%u)" , GetDetailedMatchRoles ( check ). c_str (), numPlayers );
2012-10-29 20:13:42 +01:00
LfgCompatibilityData data ( LFG_COMPATIBLES_WITH_LESS_PLAYERS );
data . roles = proposalRoles ;
2014-09-14 16:14:12 +02:00
for ( GuidList :: const_iterator itr = check . begin (); itr != check . end (); ++ itr )
2012-10-29 20:56:37 +01:00
UpdateBestCompatibleInQueue ( QueueDataStore . find ( * itr ), strGuids , data . roles );
2012-10-29 20:13:42 +01:00
SetCompatibilityData ( strGuids , data );
2012-10-19 14:00:40 +02:00
return LFG_COMPATIBLES_WITH_LESS_PLAYERS ;
}
2014-09-14 16:14:12 +02:00
ObjectGuid gguid = * check . begin ();
2012-10-19 14:00:40 +02:00
proposal . queues = check ;
2013-01-13 16:15:28 +01:00
proposal . isNew = numLfgGroups != 1 || sLFGMgr -> GetOldState ( gguid ) != LFG_STATE_DUNGEON ;
2012-10-19 14:00:40 +02:00
if ( ! sLFGMgr -> AllQueued ( check ))
{
2015-08-31 22:45:45 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.compatibility.check" , "Guids: (%s) Group MATCH but can't create proposal!" , GetDetailedMatchRoles ( check ). c_str ());
2012-10-19 14:00:40 +02:00
SetCompatibles ( strGuids , LFG_COMPATIBLES_BAD_STATES );
return LFG_COMPATIBLES_BAD_STATES ;
}
// Create a new proposal
proposal . cancelTime = time ( NULL ) + LFG_TIME_PROPOSAL ;
proposal . state = LFG_PROPOSAL_INITIATING ;
2014-09-14 16:14:12 +02:00
proposal . leader . Clear ();
2012-10-19 14:00:40 +02:00
proposal . dungeonId = Trinity :: Containers :: SelectRandomContainerElement ( proposalDungeons );
bool leader = false ;
for ( LfgRolesMap :: const_iterator itRoles = proposalRoles . begin (); itRoles != proposalRoles . end (); ++ itRoles )
{
// Assing new leader
if ( itRoles -> second & PLAYER_ROLE_LEADER )
{
if ( ! leader || ! proposal . leader || urand ( 0 , 1 ))
proposal . leader = itRoles -> first ;
leader = true ;
}
else if ( ! leader && ( ! proposal . leader || urand ( 0 , 1 )))
proposal . leader = itRoles -> first ;
// Assing player data and roles
LfgProposalPlayer & data = proposal . players [ itRoles -> first ];
data . role = itRoles -> second ;
data . group = proposalGroups . find ( itRoles -> first ) -> second ;
2014-10-21 19:23:32 +02:00
if ( ! proposal . isNew && ! data . group . IsEmpty () && data . group == proposal . group ) // Player from existing group, autoaccept
2012-10-19 14:00:40 +02:00
data . accept = LFG_ANSWER_AGREE ;
}
// Mark proposal members as not queued (but not remove queue data)
2014-09-14 16:14:12 +02:00
for ( GuidList :: const_iterator itQueue = proposal . queues . begin (); itQueue != proposal . queues . end (); ++ itQueue )
2012-10-19 14:00:40 +02:00
{
2014-09-14 16:14:12 +02:00
ObjectGuid guid = ( * itQueue );
2012-10-19 14:00:40 +02:00
RemoveFromNewQueue ( guid );
RemoveFromCurrentQueue ( guid );
}
sLFGMgr -> AddProposal ( proposal );
2015-08-31 22:45:45 +02:00
TC_LOG_DEBUG ( "lfg.queue.match.compatibility.check" , "Guids: (%s) MATCH! Group formed" , GetDetailedMatchRoles ( check ). c_str ());
2012-10-19 14:00:40 +02:00
SetCompatibles ( strGuids , LFG_COMPATIBLES_MATCH );
return LFG_COMPATIBLES_MATCH ;
}
2013-06-23 00:07:25 +02:00
void LFGQueue :: UpdateQueueTimers ( uint8 queueId , time_t currTime )
2012-10-19 14:00:40 +02:00
{
2013-12-19 09:39:00 +01:00
TC_LOG_TRACE ( "lfg.queue.timers.update" , "Updating queue timers..." );
2012-10-29 20:56:37 +01:00
for ( LfgQueueDataContainer :: iterator itQueue = QueueDataStore . begin (); itQueue != QueueDataStore . end (); ++ itQueue )
2012-10-19 14:00:40 +02:00
{
2012-10-29 20:13:42 +01:00
LfgQueueData & queueinfo = itQueue -> second ;
2012-10-19 14:00:40 +02:00
uint32 dungeonId = ( * queueinfo . dungeons . begin ());
uint32 queuedTime = uint32 ( currTime - queueinfo . joinTime );
uint8 role = PLAYER_ROLE_NONE ;
int32 waitTime = - 1 ;
2012-10-29 20:56:37 +01:00
int32 wtTank = waitTimesTankStore [ dungeonId ]. time ;
int32 wtHealer = waitTimesHealerStore [ dungeonId ]. time ;
int32 wtDps = waitTimesDpsStore [ dungeonId ]. time ;
int32 wtAvg = waitTimesAvgStore [ dungeonId ]. time ;
2012-10-19 14:00:40 +02:00
for ( LfgRolesMap :: const_iterator itPlayer = queueinfo . roles . begin (); itPlayer != queueinfo . roles . end (); ++ itPlayer )
role |= itPlayer -> second ;
role &= ~ PLAYER_ROLE_LEADER ;
switch ( role )
{
case PLAYER_ROLE_NONE : // Should not happen - just in case
waitTime = - 1 ;
break ;
case PLAYER_ROLE_TANK :
waitTime = wtTank ;
break ;
case PLAYER_ROLE_HEALER :
waitTime = wtHealer ;
break ;
case PLAYER_ROLE_DAMAGE :
waitTime = wtDps ;
break ;
default :
waitTime = wtAvg ;
break ;
}
2012-10-29 20:13:42 +01:00
if ( queueinfo . bestCompatible . empty ())
FindBestCompatibleInQueue ( itQueue );
2013-06-23 00:07:25 +02:00
LfgQueueStatusData queueData ( queueId , dungeonId , queueinfo . joinTime , waitTime , wtAvg , wtTank , wtHealer , wtDps , queuedTime , queueinfo . tanks , queueinfo . healers , queueinfo . dps );
2012-10-19 14:00:40 +02:00
for ( LfgRolesMap :: const_iterator itPlayer = queueinfo . roles . begin (); itPlayer != queueinfo . roles . end (); ++ itPlayer )
{
2014-09-14 16:14:12 +02:00
ObjectGuid pguid = itPlayer -> first ;
2012-10-19 14:00:40 +02:00
LFGMgr :: SendLfgQueueStatus ( pguid , queueData );
}
}
}
2014-09-20 11:05:30 +02:00
time_t LFGQueue :: GetJoinTime ( ObjectGuid guid ) const
2012-10-19 14:00:40 +02:00
{
2013-11-11 00:05:36 +01:00
LfgQueueDataContainer :: const_iterator itr = QueueDataStore . find ( guid );
if ( itr != QueueDataStore . end ())
return itr -> second . joinTime ;
return 0 ;
2012-10-23 11:44:02 +02:00
}
2012-10-29 20:13:42 +01:00
std :: string LFGQueue :: DumpQueueInfo () const
2012-10-23 11:44:02 +02:00
{
uint32 players = 0 ;
uint32 groups = 0 ;
uint32 playersInGroup = 0 ;
for ( uint8 i = 0 ; i < 2 ; ++ i )
{
2014-09-14 16:14:12 +02:00
GuidList const & queue = i ? newToQueueStore : currentQueueStore ;
for ( GuidList :: const_iterator it = queue . begin (); it != queue . end (); ++ it )
2012-10-23 11:44:02 +02:00
{
2014-09-14 16:14:12 +02:00
ObjectGuid guid = * it ;
2014-10-27 12:03:35 +01:00
if ( guid . IsParty ())
2012-10-23 11:44:02 +02:00
{
groups ++ ;
2012-10-29 13:58:48 +01:00
playersInGroup += sLFGMgr -> GetPlayerCount ( guid );
2012-10-23 11:44:02 +02:00
}
else
players ++ ;
}
}
std :: ostringstream o ;
2012-10-29 13:58:48 +01:00
o << "Queued Players: " << players << " (in group: " << playersInGroup << ") Groups: " << groups << " \n " ;
2012-10-23 11:44:02 +02:00
return o . str ();
}
2012-10-29 20:13:42 +01:00
std :: string LFGQueue :: DumpCompatibleInfo ( bool full /* = false */ ) const
2012-10-23 11:44:02 +02:00
{
std :: ostringstream o ;
2012-10-29 20:56:37 +01:00
o << "Compatible Map size: " << CompatibleMapStore . size () << " \n " ;
2012-10-29 13:58:48 +01:00
if ( full )
2012-10-29 20:56:37 +01:00
for ( LfgCompatibleContainer :: const_iterator itr = CompatibleMapStore . begin (); itr != CompatibleMapStore . end (); ++ itr )
2015-09-05 17:08:37 +02:00
{
o << "(" << itr -> first << "): " << GetCompatibleString ( itr -> second . compatibility );
if ( ! itr -> second . roles . empty ())
{
o << " (" ;
bool first = true ;
for ( const auto & role : itr -> second . roles )
{
if ( ! first )
o << "|" ;
2015-09-24 23:57:13 +02:00
o << role . first . ToString () << " " << GetRolesString ( role . second & uint8 ( ~ PLAYER_ROLE_LEADER ));
2015-09-05 17:08:37 +02:00
first = false ;
}
o << ")" ;
}
o << " \n " ;
}
2012-10-29 13:58:48 +01:00
2012-10-23 11:44:02 +02:00
return o . str ();
}
2012-10-29 20:13:42 +01:00
2012-10-29 20:56:37 +01:00
void LFGQueue :: FindBestCompatibleInQueue ( LfgQueueDataContainer :: iterator itrQueue )
2012-10-29 20:13:42 +01:00
{
2014-09-16 20:47:08 +02:00
TC_LOG_DEBUG ( "lfg.queue.compatibles.find" , "%s" , itrQueue -> first . ToString (). c_str ());
2012-10-29 20:13:42 +01:00
std :: ostringstream o ;
2014-10-23 17:01:26 +02:00
o << itrQueue -> first ;
2012-10-29 20:13:42 +01:00
std :: string sguid = o . str ();
2012-10-29 20:56:37 +01:00
for ( LfgCompatibleContainer :: const_iterator itr = CompatibleMapStore . begin (); itr != CompatibleMapStore . end (); ++ itr )
2012-11-08 11:13:46 +01:00
if ( itr -> second . compatibility == LFG_COMPATIBLES_WITH_LESS_PLAYERS &&
2012-10-29 20:13:42 +01:00
std :: string :: npos != itr -> first . find ( sguid ))
{
UpdateBestCompatibleInQueue ( itrQueue , itr -> first , itr -> second . roles );
}
}
2012-10-29 20:56:37 +01:00
void LFGQueue :: UpdateBestCompatibleInQueue ( LfgQueueDataContainer :: iterator itrQueue , std :: string const & key , LfgRolesMap const & roles )
2012-10-29 20:13:42 +01:00
{
LfgQueueData & queueData = itrQueue -> second ;
2012-11-08 11:13:46 +01:00
uint8 storedSize = queueData . bestCompatible . empty () ? 0 :
2012-10-29 20:13:42 +01:00
std :: count ( queueData . bestCompatible . begin (), queueData . bestCompatible . end (), '|' ) + 1 ;
uint8 size = std :: count ( key . begin (), key . end (), '|' ) + 1 ;
if ( size <= storedSize )
return ;
2014-09-16 20:47:08 +02:00
TC_LOG_DEBUG ( "lfg.queue.compatibles.update" , "Changed (%s) to (%s) as best compatible group for %s" ,
queueData . bestCompatible . c_str (), key . c_str (), itrQueue -> first . ToString (). c_str ());
2012-10-29 20:13:42 +01:00
queueData . bestCompatible = key ;
queueData . tanks = LFG_TANKS_NEEDED ;
queueData . healers = LFG_HEALERS_NEEDED ;
queueData . dps = LFG_DPS_NEEDED ;
for ( LfgRolesMap :: const_iterator it = roles . begin (); it != roles . end (); ++ it )
{
uint8 role = it -> second ;
if ( role & PLAYER_ROLE_TANK )
-- queueData . tanks ;
else if ( role & PLAYER_ROLE_HEALER )
-- queueData . healers ;
else
-- queueData . dps ;
}
2012-11-02 22:23:14 +01:00
}
2013-02-04 04:43:18 +01:00
} // namespace lfg