TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GroupMgr Class Reference

#include <GroupMgr.h>

Public Types

typedef std::map
< ObjectGuid::LowType, Group * > 
GroupContainer
 
typedef std::vector< Group * > GroupDbContainer
 

Public Member Functions

GroupGetGroupByGUID (ObjectGuid const &guid) const
 
uint32 GenerateNewGroupDbStoreId ()
 
void RegisterGroupDbStoreId (uint32 storageId, Group *group)
 
void FreeGroupDbStoreId (Group *group)
 
void SetNextGroupDbStoreId (uint32 storageId)
 
GroupGetGroupByDbStoreId (uint32 storageId) const
 
void SetGroupDbStoreSize (uint32 newSize)
 
void LoadGroups ()
 
ObjectGuid::LowType GenerateGroupId ()
 
void AddGroup (Group *group)
 
void RemoveGroup (Group *group)
 
void Update (uint32 diff)
 

Static Public Member Functions

static GroupMgrinstance ()
 

Protected Attributes

ObjectGuid::LowType NextGroupId
 
uint32 NextGroupDbStoreId
 
GroupContainer GroupStore
 
GroupDbContainer GroupDbStore
 

Private Member Functions

 GroupMgr ()
 
 ~GroupMgr ()
 

Member Typedef Documentation

typedef std::vector<Group*> GroupMgr::GroupDbContainer

Constructor & Destructor Documentation

GroupMgr::GroupMgr ( )
private
25 {
27  NextGroupId = UI64LIT(1);
28 }
#define UI64LIT(N)
Definition: Define.h:138
uint32 NextGroupDbStoreId
Definition: GroupMgr.h:54
ObjectGuid::LowType NextGroupId
Definition: GroupMgr.h:53
GroupMgr::~GroupMgr ( )
private
31 {
32  for (GroupContainer::iterator itr = GroupStore.begin(); itr != GroupStore.end(); ++itr)
33  delete itr->second;
34 }
GroupContainer GroupStore
Definition: GroupMgr.h:55

Member Function Documentation

void GroupMgr::AddGroup ( Group group)
111 {
112  GroupStore[group->GetGUID().GetCounter()] = group;
113 }
ObjectGuid GetGUID() const
Definition: Group.cpp:2534
GroupContainer GroupStore
Definition: GroupMgr.h:55
LowType GetCounter() const
Definition: ObjectGuid.h:221

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void GroupMgr::FreeGroupDbStoreId ( Group group)
68 {
69  uint32 storageId = group->GetDbStoreId();
70 
71  if (storageId < NextGroupDbStoreId)
72  NextGroupDbStoreId = storageId;
73 
74  GroupDbStore[storageId] = NULL;
75 }
arena_t NULL
Definition: jemalloc_internal.h:624
GroupDbContainer GroupDbStore
Definition: GroupMgr.h:56
uint32 NextGroupDbStoreId
Definition: GroupMgr.h:54
uint32_t uint32
Definition: Define.h:150
uint32 GetDbStoreId() const
Definition: Group.h:278

+ Here is the call graph for this function:

ObjectGuid::LowType GroupMgr::GenerateGroupId ( )
86 {
87  if (NextGroupId >= 0xFFFFFFFE)
88  {
89  TC_LOG_ERROR("misc", "Group guid overflow!! Can't continue, shutting down server. ");
91  }
92  return NextGroupId++;
93 }
ObjectGuid::LowType NextGroupId
Definition: GroupMgr.h:53
Definition: World.h:74
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
static void StopNow(uint8 exitcode)
Definition: World.h:662

+ Here is the call graph for this function:

uint32 GroupMgr::GenerateNewGroupDbStoreId ( )
37 {
38  uint32 newStorageId = NextGroupDbStoreId;
39 
40  for (uint32 i = ++NextGroupDbStoreId; i < 0xFFFFFFFF; ++i)
41  {
42  if ((i < GroupDbStore.size() && GroupDbStore[i] == NULL) || i >= GroupDbStore.size())
43  {
45  break;
46  }
47  }
48 
49  if (newStorageId == NextGroupDbStoreId)
50  {
51  TC_LOG_ERROR("misc", "Group storage ID overflow!! Can't continue, shutting down server. ");
53  }
54 
55  return newStorageId;
56 }
arena_t NULL
Definition: jemalloc_internal.h:624
GroupDbContainer GroupDbStore
Definition: GroupMgr.h:56
uint32 NextGroupDbStoreId
Definition: GroupMgr.h:54
Definition: World.h:74
uint32_t uint32
Definition: Define.h:150
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
static void StopNow(uint8 exitcode)
Definition: World.h:662

+ Here is the call graph for this function:

Group * GroupMgr::GetGroupByDbStoreId ( uint32  storageId) const
78 {
79  if (storageId < GroupDbStore.size())
80  return GroupDbStore[storageId];
81 
82  return NULL;
83 }
arena_t NULL
Definition: jemalloc_internal.h:624
GroupDbContainer GroupDbStore
Definition: GroupMgr.h:56

+ Here is the caller graph for this function:

Group * GroupMgr::GetGroupByGUID ( ObjectGuid const guid) const
102 {
103  GroupContainer::const_iterator itr = GroupStore.find(groupId.GetCounter());
104  if (itr != GroupStore.end())
105  return itr->second;
106 
107  return NULL;
108 }
arena_t NULL
Definition: jemalloc_internal.h:624
GroupContainer GroupStore
Definition: GroupMgr.h:55

+ Here is the call graph for this function:

GroupMgr * GroupMgr::instance ( )
static
96 {
97  static GroupMgr instance;
98  return &instance;
99 }
Definition: GroupMgr.h:23
static GroupMgr * instance()
Definition: GroupMgr.cpp:95
void GroupMgr::LoadGroups ( )
121 {
122  {
123  uint32 oldMSTime = getMSTime();
124 
125  // Delete all groups whose leader does not exist
126  CharacterDatabase.DirectExecute("DELETE FROM groups WHERE leaderGuid NOT IN (SELECT guid FROM characters)");
127  // Delete all groups with less than 2 members
128  CharacterDatabase.DirectExecute("DELETE FROM groups WHERE guid NOT IN (SELECT guid FROM group_member GROUP BY guid HAVING COUNT(guid) > 1)");
129 
130  // 0 1 2 3 4 5 6 7 8 9
131  QueryResult result = CharacterDatabase.Query("SELECT g.leaderGuid, g.lootMethod, g.looterGuid, g.lootThreshold, g.icon1, g.icon2, g.icon3, g.icon4, g.icon5, g.icon6"
132  // 10 11 12 13 14 15 16 17 18 19
133  ", g.icon7, g.icon8, g.groupType, g.difficulty, g.raiddifficulty, g.legacyRaidDifficulty, g.masterLooterGuid, g.guid, lfg.dungeon, lfg.state FROM groups g LEFT JOIN lfg_data lfg ON lfg.guid = g.guid ORDER BY g.guid ASC");
134  if (!result)
135  {
136  TC_LOG_INFO("server.loading", ">> Loaded 0 group definitions. DB table `groups` is empty!");
137  return;
138  }
139 
140  uint32 count = 0;
141  do
142  {
143  Field* fields = result->Fetch();
144  Group* group = new Group;
145  group->LoadGroupFromDB(fields);
146  AddGroup(group);
147 
148  // Get the ID used for storing the group in the database and register it in the pool.
149  uint32 storageId = group->GetDbStoreId();
150 
151  RegisterGroupDbStoreId(storageId, group);
152 
153  // Increase the next available storage ID
154  if (storageId == NextGroupDbStoreId)
156 
157  ++count;
158  }
159  while (result->NextRow());
160 
161  TC_LOG_INFO("server.loading", ">> Loaded %u group definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
162  }
163 
164  TC_LOG_INFO("server.loading", "Loading Group members...");
165  {
166  uint32 oldMSTime = getMSTime();
167 
168  // Delete all rows from group_member or group_instance with no group
169  CharacterDatabase.DirectExecute("DELETE FROM group_member WHERE guid NOT IN (SELECT guid FROM groups)");
170  CharacterDatabase.DirectExecute("DELETE FROM group_instance WHERE guid NOT IN (SELECT guid FROM groups)");
171  // Delete all members that does not exist
172  CharacterDatabase.DirectExecute("DELETE FROM group_member WHERE memberGuid NOT IN (SELECT guid FROM characters)");
173 
174  // 0 1 2 3 4
175  QueryResult result = CharacterDatabase.Query("SELECT guid, memberGuid, memberFlags, subgroup, roles FROM group_member ORDER BY guid");
176  if (!result)
177  {
178  TC_LOG_INFO("server.loading", ">> Loaded 0 group members. DB table `group_member` is empty!");
179  return;
180  }
181 
182  uint32 count = 0;
183 
184  do
185  {
186  Field* fields = result->Fetch();
187  Group* group = GetGroupByDbStoreId(fields[0].GetUInt32());
188 
189  if (group)
190  group->LoadMemberFromDB(fields[1].GetUInt64(), fields[2].GetUInt8(), fields[3].GetUInt8(), fields[4].GetUInt8());
191  else
192  TC_LOG_ERROR("misc", "GroupMgr::LoadGroups: Consistency failed, can't find group (storage id: %u)", fields[0].GetUInt32());
193 
194  ++count;
195  }
196  while (result->NextRow());
197 
198  TC_LOG_INFO("server.loading", ">> Loaded %u group members in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
199  }
200 
201  TC_LOG_INFO("server.loading", "Loading Group instance saves...");
202  {
203  uint32 oldMSTime = getMSTime();
204  // 0 1 2 3 4 5 6
205  QueryResult result = CharacterDatabase.Query("SELECT gi.guid, i.map, gi.instance, gi.permanent, i.difficulty, i.resettime, COUNT(g.guid) "
206  "FROM group_instance gi INNER JOIN instance i ON gi.instance = i.id "
207  "LEFT JOIN character_instance ci LEFT JOIN groups g ON g.leaderGuid = ci.guid ON ci.instance = gi.instance AND ci.permanent = 1 GROUP BY gi.instance ORDER BY gi.guid");
208  if (!result)
209  {
210  TC_LOG_INFO("server.loading", ">> Loaded 0 group-instance saves. DB table `group_instance` is empty!");
211  return;
212  }
213 
214  uint32 count = 0;
215  do
216  {
217  Field* fields = result->Fetch();
218  Group* group = GetGroupByDbStoreId(fields[0].GetUInt32());
219  // group will never be NULL (we have run consistency sql's before loading)
220 
221  MapEntry const* mapEntry = sMapStore.LookupEntry(fields[1].GetUInt16());
222  if (!mapEntry || !mapEntry->IsDungeon())
223  {
224  TC_LOG_ERROR("sql.sql", "Incorrect entry in group_instance table : no dungeon map %d", fields[1].GetUInt16());
225  continue;
226  }
227 
228  uint32 diff = fields[4].GetUInt8();
229  DifficultyEntry const* difficultyEntry = sDifficultyStore.LookupEntry(diff);
230  if (!difficultyEntry || difficultyEntry->InstanceType != mapEntry->InstanceType)
231  continue;
232 
233  InstanceSave* save = sInstanceSaveMgr->AddInstanceSave(mapEntry->ID, fields[2].GetUInt32(), Difficulty(diff), time_t(fields[5].GetUInt32()), fields[6].GetUInt64() != 0, true);
234  group->BindToInstance(save, fields[3].GetBool(), true);
235  ++count;
236  }
237  while (result->NextRow());
238 
239  TC_LOG_INFO("server.loading", ">> Loaded %u group-instance saves in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
240  }
241 }
Difficulty
Definition: DBCEnums.h:402
uint64 GetUInt64() const
Definition: Field.h:184
InstanceGroupBind * BindToInstance(InstanceSave *save, bool permanent, bool load=false)
Definition: Group.cpp:2224
void AddGroup(Group *group)
Definition: GroupMgr.cpp:110
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32 getMSTime()
Definition: Timer.h:24
Definition: DBCStructure.h:830
void LoadMemberFromDB(ObjectGuid::LowType guidLow, uint8 memberFlags, uint8 subgroup, uint8 roles)
Definition: Group.cpp:201
uint8 GetUInt8() const
Definition: Field.h:70
uint32 InstanceType
Definition: DBCStructure.h:834
uint32 NextGroupDbStoreId
Definition: GroupMgr.h:54
Group * GetGroupByDbStoreId(uint32 storageId) const
Definition: GroupMgr.cpp:77
uint32_t uint32
Definition: Define.h:150
uint32 InstanceType
Definition: DBCStructure.h:342
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
static Summons Group[]
Definition: boss_urom.cpp:77
bool IsDungeon() const
Definition: DBCStructure.h:857
uint32 ID
Definition: DBCStructure.h:832
uint32 GetDbStoreId() const
Definition: Group.h:278
Definition: InstanceSaveMgr.h:44
#define sInstanceSaveMgr
Definition: InstanceSaveMgr.h:243
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
DBCStorage< MapEntry > sMapStore(Mapfmt)
uint32 GetUInt32() const
Definition: Field.h:146
void RegisterGroupDbStoreId(uint32 storageId, Group *group)
Definition: GroupMgr.cpp:58
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
void DirectExecute(const char *sql)
Definition: DatabaseWorkerPool.h:121
DBCStorage< DifficultyEntry > sDifficultyStore(DifficultyFmt)
void LoadGroupFromDB(Field *field)
Definition: Group.cpp:170
Definition: Group.h:191
Definition: DBCStructure.h:338

+ Here is the call graph for this function:

void GroupMgr::RegisterGroupDbStoreId ( uint32  storageId,
Group group 
)
59 {
60  // Allocate space if necessary.
61  if (storageId >= uint32(GroupDbStore.size()))
62  GroupDbStore.resize(storageId + 1);
63 
64  GroupDbStore[storageId] = group;
65 }
GroupDbContainer GroupDbStore
Definition: GroupMgr.h:56
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the caller graph for this function:

void GroupMgr::RemoveGroup ( Group group)
116 {
117  GroupStore.erase(group->GetGUID().GetCounter());
118 }
ObjectGuid GetGUID() const
Definition: Group.cpp:2534
GroupContainer GroupStore
Definition: GroupMgr.h:55
LowType GetCounter() const
Definition: ObjectGuid.h:221

+ Here is the call graph for this function:

void GroupMgr::SetGroupDbStoreSize ( uint32  newSize)
inline
42 { GroupDbStore.resize(newSize); }
GroupDbContainer GroupDbStore
Definition: GroupMgr.h:56
void GroupMgr::SetNextGroupDbStoreId ( uint32  storageId)
inline
40 { NextGroupDbStoreId = storageId; };
uint32 NextGroupDbStoreId
Definition: GroupMgr.h:54
void GroupMgr::Update ( uint32  diff)
244 {
245  for (GroupContainer::iterator itr = GroupStore.begin(); itr != GroupStore.end(); itr++)
246  if (itr->second)
247  itr->second->Update(diff);
248 }
GroupContainer GroupStore
Definition: GroupMgr.h:55

Member Data Documentation

GroupDbContainer GroupMgr::GroupDbStore
protected
GroupContainer GroupMgr::GroupStore
protected
uint32 GroupMgr::NextGroupDbStoreId
protected
ObjectGuid::LowType GroupMgr::NextGroupId
protected

The documentation for this class was generated from the following files: