AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
GroupMgr Class Reference

#include "GroupMgr.h"

Public Types

typedef std::map< uint32, Group * > GroupContainer
 

Public Member Functions

GroupGetGroupByGUID (ObjectGuid::LowType guid) const
 
void InitGroupIds ()
 
void RegisterGroupId (ObjectGuid::LowType groupId)
 
ObjectGuid::LowType GenerateGroupId ()
 
void LoadGroups ()
 
void AddGroup (Group *group)
 
void RemoveGroup (Group *group)
 

Static Public Member Functions

static GroupMgrinstance ()
 

Protected Types

typedef std::vector< bool > GroupIds
 

Protected Attributes

GroupIds _groupIds
 
ObjectGuid::LowType _nextGroupId
 
GroupContainer GroupStore
 

Private Member Functions

 GroupMgr ()
 
 ~GroupMgr ()
 

Detailed Description

Member Typedef Documentation

◆ GroupContainer

typedef std::map<uint32, Group*> GroupMgr::GroupContainer

◆ GroupIds

typedef std::vector<bool> GroupMgr::GroupIds
protected

Constructor & Destructor Documentation

◆ GroupMgr()

GroupMgr::GroupMgr ( )
private
26{
27 _nextGroupId = 0;
28}
ObjectGuid::LowType _nextGroupId
Definition: GroupMgr.h:47

References _nextGroupId.

◆ ~GroupMgr()

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:48

References GroupStore.

Member Function Documentation

◆ AddGroup()

void GroupMgr::AddGroup ( Group group)
91{
92 GroupStore[group->GetGUID().GetCounter()] = group;
93}
LowType GetCounter() const
Definition: ObjectGuid.h:145
ObjectGuid GetGUID() const
Definition: Group.cpp:2302

References ObjectGuid::GetCounter(), Group::GetGUID(), and GroupStore.

Referenced by LoadGroups().

◆ GenerateGroupId()

ObjectGuid::LowType GroupMgr::GenerateGroupId ( )
66{
68
69 // find the lowest available id starting from the current _nextGroupId
70 while (_nextGroupId < 0xFFFFFFFF && ++_nextGroupId < _groupIds.size() && _groupIds[_nextGroupId]);
71
72 if (_nextGroupId == 0xFFFFFFFF)
73 {
74 LOG_ERROR("server.worldserver", "Group ID overflow!! Can't continue, shutting down server.");
76 }
77
78 return newGroupId;
79}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
@ ERROR_EXIT_CODE
Definition: World.h:54
uint32 LowType
Definition: ObjectGuid.h:122
GroupIds _groupIds
Definition: GroupMgr.h:46
static void StopNow(uint8 exitcode)
Definition: World.h:253

References _groupIds, _nextGroupId, ERROR_EXIT_CODE, LOG_ERROR, and World::StopNow().

◆ GetGroupByGUID()

Group * GroupMgr::GetGroupByGUID ( ObjectGuid::LowType  guid) const
82{
83 GroupContainer::const_iterator itr = GroupStore.find(groupId);
84 if (itr != GroupStore.end())
85 return itr->second;
86
87 return nullptr;
88}

References GroupStore.

Referenced by LoadGroups().

◆ InitGroupIds()

void GroupMgr::InitGroupIds ( )
43{
44 _nextGroupId = 1;
45
46 QueryResult result = CharacterDatabase.Query("SELECT MAX(guid) FROM `groups`");
47 if (result)
48 {
49 uint32 maxId = (*result)[0].Get<uint32>();
50 _groupIds.resize(maxId + 1);
51 }
52}
std::uint32_t uint32
Definition: Define.h:107
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21

References _groupIds, _nextGroupId, and CharacterDatabase.

Referenced by LoadGroups().

◆ instance()

GroupMgr * GroupMgr::instance ( )
static
37{
38 static GroupMgr instance;
39 return &instance;
40}
Definition: GroupMgr.h:24
static GroupMgr * instance()
Definition: GroupMgr.cpp:36

References instance().

Referenced by instance().

◆ LoadGroups()

void GroupMgr::LoadGroups ( )
101{
102 {
103 uint32 oldMSTime = getMSTime();
104
105 // Delete all groups whose leader does not exist
106 CharacterDatabase.DirectExecute("DELETE FROM `groups` WHERE leaderGuid NOT IN (SELECT guid FROM characters)");
107
108 // Delete all groups with less than 2 members
109 CharacterDatabase.DirectExecute("DELETE FROM `groups` WHERE guid NOT IN (SELECT guid FROM group_member GROUP BY guid HAVING COUNT(guid) > 1)");
110
111 // Delete invalid lfg_data
112 CharacterDatabase.DirectExecute("DELETE lfg_data FROM lfg_data LEFT JOIN `groups` ON lfg_data.guid = groups.guid WHERE groups.guid IS NULL OR groups.groupType <> 12");
113 // CharacterDatabase.DirectExecute("DELETE `groups` FROM `groups` LEFT JOIN lfg_data ON groups.guid = lfg_data.guid WHERE groups.groupType=12 AND lfg_data.guid IS NULL"); // group should be left so binds are cleared when disbanded
114
115 InitGroupIds();
116
117 // 0 1 2 3 4 5 6 7 8 9
118 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"
119 // 10 11 12 13 14 15 16 17 18
120 ", g.icon7, g.icon8, g.groupType, g.difficulty, g.raidDifficulty, 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");
121
122 if (!result)
123 {
124 LOG_WARN("server.loading", ">> Loaded 0 group definitions. DB table `groups` is empty!");
125 LOG_INFO("server.loading", " ");
126 }
127 else
128 {
129 uint32 count = 0;
130 do
131 {
132 Field* fields = result->Fetch();
133 Group* group = new Group;
134 if (!group->LoadGroupFromDB(fields))
135 {
136 delete group;
137 continue;
138 }
139 AddGroup(group);
140
142
143 ++count;
144 } while (result->NextRow());
145
146 LOG_INFO("server.loading", ">> Loaded {} group definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
147 LOG_INFO("server.loading", " ");
148 }
149 }
150
151 LOG_INFO("server.loading", "Loading Group Members...");
152 {
153 uint32 oldMSTime = getMSTime();
154
155 // Delete all rows from group_member with no group
156 CharacterDatabase.DirectExecute("DELETE FROM group_member WHERE guid NOT IN (SELECT guid FROM `groups`)");
157 // Delete all members that does not exist
158 CharacterDatabase.DirectExecute("DELETE FROM group_member WHERE memberGuid NOT IN (SELECT guid FROM characters)");
159
160 // 0 1 2 3 4
161 QueryResult result = CharacterDatabase.Query("SELECT guid, memberGuid, memberFlags, subgroup, roles FROM group_member ORDER BY guid");
162 if (!result)
163 {
164 LOG_WARN("server.loading", ">> Loaded 0 group members. DB table `group_member` is empty!");
165 LOG_INFO("server.loading", " ");
166 }
167 else
168 {
169 uint32 count = 0;
170 do
171 {
172 Field* fields = result->Fetch();
173 Group* group = GetGroupByGUID(fields[0].Get<uint32>());
174
175 if (group)
176 group->LoadMemberFromDB(fields[1].Get<uint32>(), fields[2].Get<uint8>(), fields[3].Get<uint8>(), fields[4].Get<uint8>());
177
178 ++count;
179 } while (result->NextRow());
180
181 LOG_INFO("server.loading", ">> Loaded {} group members in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
182 LOG_INFO("server.loading", " ");
183 }
184 }
185}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_WARN(filterType__,...)
Definition: Log.h:161
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
Class used to access individual fields of database query result.
Definition: Field.h:98
Definition: Group.h:169
void LoadMemberFromDB(ObjectGuid::LowType guidLow, uint8 memberFlags, uint8 subgroup, uint8 roles)
Definition: Group.cpp:227
bool LoadGroupFromDB(Field *field)
Definition: Group.cpp:172
Group * GetGroupByGUID(ObjectGuid::LowType guid) const
Definition: GroupMgr.cpp:81
void InitGroupIds()
Definition: GroupMgr.cpp:42
void RegisterGroupId(ObjectGuid::LowType groupId)
Definition: GroupMgr.cpp:54
void AddGroup(Group *group)
Definition: GroupMgr.cpp:90

References AddGroup(), CharacterDatabase, ObjectGuid::GetCounter(), GetGroupByGUID(), Group::GetGUID(), getMSTime(), GetMSTimeDiffToNow(), InitGroupIds(), Group::LoadGroupFromDB(), Group::LoadMemberFromDB(), LOG_INFO, LOG_WARN, and RegisterGroupId().

◆ RegisterGroupId()

void GroupMgr::RegisterGroupId ( ObjectGuid::LowType  groupId)
55{
56 // Allocation was done in InitGroupIds()
57 _groupIds[groupId] = true;
58
59 // Groups are pulled in ascending order from db and _nextGroupId is initialized with 1,
60 // so if the instance id is used, increment
61 if (_nextGroupId == groupId)
63}

References _groupIds, and _nextGroupId.

Referenced by LoadGroups().

◆ RemoveGroup()

void GroupMgr::RemoveGroup ( Group group)
96{
97 GroupStore.erase(group->GetGUID().GetCounter());
98}

References ObjectGuid::GetCounter(), Group::GetGUID(), and GroupStore.

Member Data Documentation

◆ _groupIds

GroupIds GroupMgr::_groupIds
protected

◆ _nextGroupId

ObjectGuid::LowType GroupMgr::_nextGroupId
protected

◆ GroupStore

GroupContainer GroupMgr::GroupStore
protected