- Logging System is asyncronous to improve performance.
- Each msg and Logger has a Log Type and Log Level assigned. Each msg is assigned the Logger of same Log Type or "root" Logger is selected if there is no Logger configured for the given Log Type
- Loggers have a list of Appenders to send the msg to. The Msg in the Logger is not sent to Appenders if the msg LogLevel is lower than Logger LogLevel.
- There are three (at the moment) types of Appenders: Console, File or DB (this is WIP, not working ATM). Msg is not written to the resource if msg LogLevel is lower than Appender LogLevel.
- Appender and Console Log levels can be changed while server is active with command '.set loglevel (a/l) name level'
Explanation of use with Sample config:
Appender.Console.Type=1 (1 = Console)
Appender.Console.Level=2 (2 = Debug)
Appender.Server.Type=2 (2 = File)
Appender.Server.Level=3 (3 = Info)
Appender.Server.File=Server.log
Appender.SQL.Type=2 (2 = File)
Appender.SQL.Level=1 (1 = Trace)
Appender.SQL.File=sql.log
Appenders=Console Server (NOTE: SQL has not been included here... that will make core ignore the config for "SQL" as it's not in this list)
Logger.root.Type=0 (0 = Default - if it's not created by config, server will create it with LogLevel = DISABLED)
Logger.root.Level=5 (5 = Error)
Logger.root.Appenders=Console
Logger.SQL.Type=26 (26 = SQL)
Logger.SQL.Level=3 (2 = Debug)
Logger.SQL.Appenders=Console Server SQL
Logger.SomeRandomName.Type=24 (24 = Guild)
Logger.SomeRandomName.Level=5 (5 = Error)
Loggers=root SQL SomeRandomName
* At loading Appender SQL will be ignored, as it's not present on "Appenders"
* sLog->outDebug(LOG_FILTER_GUILD, "Some log msg related to Guilds")
- Msg is sent to Logger of Type LOG_FILTER_GUILD (24). Logger with name SomeRandomName is found but it's LogLevel = 5 and Msg LogLevel=2... Msg is not logged
* sLog->outError(LOG_FILTER_GUILD, "Some error log msg related to Guilds")
- Msg is sent to Logger of Type LOG_FILTER_GUILD (24). Logger with name SomeRandomeName is found with proper LogLevel but Logger does not have any Appenders assigned to that logger... Msg is not logged
* sLog->outDebug(LOG_FILTER_SQL, "Some msg related to SQLs")
- Msg is sent to Logger SQL (matches type), as it matches LogLevel the msg is sent to Appenders Console, Server and SQL
- Appender Console has lower Log Level: Msg is logged to Console
- Appender Server has higher Log Level: Msg is not logged to file
- Appender SQL has lower Log Level: Msg is logged to file sql.log
* sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Some msg related to Battelgrounds")
- Msg is sent to Logger root (Type 0) as no Logger was found with Type LOG_FILTER_BATTLEGROUND (13). As Logger has higher LogLevel msg is not sent to any appender
* sLog->outError(LOG_FILTER_BATTLEGROUND, "Some error msg related to Battelgrounds")
- Msg is sent to Logger root (Type 0) as no Logger was found with Type LOG_FILTER_BATTLEGROUND (13). Msg has lower LogLevel and is sent to Appender Console
- Appender Console has lower LogLevel: Msg is logged to Console
242 lines
8.7 KiB
C++
242 lines
8.7 KiB
C++
/*
|
|
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
|
|
*
|
|
* 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 "Common.h"
|
|
#include "GroupMgr.h"
|
|
#include "InstanceSaveMgr.h"
|
|
|
|
GroupMgr::GroupMgr()
|
|
{
|
|
NextGroupDbStoreId = 1;
|
|
NextGroupId = 1;
|
|
}
|
|
|
|
GroupMgr::~GroupMgr()
|
|
{
|
|
for (GroupContainer::iterator itr = GroupStore.begin(); itr != GroupStore.end(); ++itr)
|
|
delete itr->second;
|
|
}
|
|
|
|
uint32 GroupMgr::GenerateNewGroupDbStoreId()
|
|
{
|
|
uint32 newStorageId = NextGroupDbStoreId;
|
|
|
|
for (uint32 i = ++NextGroupDbStoreId; i < 0xFFFFFFFF; ++i)
|
|
{
|
|
if ((i < GroupDbStore.size() && GroupDbStore[i] == NULL) || i >= GroupDbStore.size())
|
|
{
|
|
NextGroupDbStoreId = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (newStorageId == NextGroupDbStoreId)
|
|
{
|
|
sLog->outError(LOG_FILTER_GENERAL, "Group storage ID overflow!! Can't continue, shutting down server. ");
|
|
World::StopNow(ERROR_EXIT_CODE);
|
|
}
|
|
|
|
return newStorageId;
|
|
}
|
|
|
|
void GroupMgr::RegisterGroupDbStoreId(uint32 storageId, Group* group)
|
|
{
|
|
// Allocate space if necessary.
|
|
if (storageId >= uint32(GroupDbStore.size()))
|
|
GroupDbStore.resize(storageId + 1);
|
|
|
|
GroupDbStore[storageId] = group;
|
|
}
|
|
|
|
void GroupMgr::FreeGroupDbStoreId(Group* group)
|
|
{
|
|
uint32 storageId = group->GetDbStoreId();
|
|
|
|
if (storageId < NextGroupDbStoreId)
|
|
NextGroupDbStoreId = storageId;
|
|
|
|
GroupDbStore[storageId] = NULL;
|
|
}
|
|
|
|
Group* GroupMgr::GetGroupByDbStoreId(uint32 storageId) const
|
|
{
|
|
if (storageId < GroupDbStore.size())
|
|
return GroupDbStore[storageId];
|
|
|
|
return NULL;
|
|
}
|
|
|
|
uint32 GroupMgr::GenerateGroupId()
|
|
{
|
|
if (NextGroupId >= 0xFFFFFFFE)
|
|
{
|
|
sLog->outError(LOG_FILTER_GENERAL, "Group guid overflow!! Can't continue, shutting down server. ");
|
|
World::StopNow(ERROR_EXIT_CODE);
|
|
}
|
|
return NextGroupId++;
|
|
}
|
|
|
|
Group* GroupMgr::GetGroupByGUID(uint32 groupId) const
|
|
{
|
|
GroupContainer::const_iterator itr = GroupStore.find(groupId);
|
|
if (itr != GroupStore.end())
|
|
return itr->second;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void GroupMgr::AddGroup(Group* group)
|
|
{
|
|
GroupStore[group->GetLowGUID()] = group;
|
|
}
|
|
|
|
void GroupMgr::RemoveGroup(Group* group)
|
|
{
|
|
GroupStore.erase(group->GetLowGUID());
|
|
}
|
|
|
|
void GroupMgr::LoadGroups()
|
|
{
|
|
{
|
|
uint32 oldMSTime = getMSTime();
|
|
|
|
// Delete all groups whose leader does not exist
|
|
CharacterDatabase.DirectExecute("DELETE FROM groups WHERE leaderGuid NOT IN (SELECT guid FROM characters)");
|
|
// Delete all groups with less than 2 members
|
|
CharacterDatabase.DirectExecute("DELETE FROM groups WHERE guid NOT IN (SELECT guid FROM group_member GROUP BY guid HAVING COUNT(guid) > 1)");
|
|
|
|
// 0 1 2 3 4 5 6 7 8 9
|
|
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"
|
|
// 10 11 12 13 14 15 16 17
|
|
", g.icon7, g.icon8, g.groupType, g.difficulty, g.raiddifficulty, g.guid, lfg.dungeon, lfg.state FROM groups g LEFT JOIN lfg_data lfg ON lfg.guid = g.guid ORDER BY g.guid ASC");
|
|
if (!result)
|
|
{
|
|
sLog->outInfo(LOG_FILTER_GENERAL, ">> Loaded 0 group definitions. DB table `groups` is empty!");
|
|
|
|
return;
|
|
}
|
|
|
|
uint32 count = 0;
|
|
do
|
|
{
|
|
Field* fields = result->Fetch();
|
|
Group* group = new Group;
|
|
group->LoadGroupFromDB(fields);
|
|
AddGroup(group);
|
|
|
|
// Get the ID used for storing the group in the database and register it in the pool.
|
|
uint32 storageId = group->GetDbStoreId();
|
|
|
|
RegisterGroupDbStoreId(storageId, group);
|
|
|
|
// Increase the next available storage ID
|
|
if (storageId == NextGroupDbStoreId)
|
|
NextGroupDbStoreId++;
|
|
|
|
++count;
|
|
}
|
|
while (result->NextRow());
|
|
|
|
sLog->outInfo(LOG_FILTER_GENERAL, ">> Loaded %u group definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
|
|
|
}
|
|
|
|
sLog->outInfo(LOG_FILTER_GENERAL, "Loading Group members...");
|
|
{
|
|
uint32 oldMSTime = getMSTime();
|
|
|
|
// Delete all rows from group_member or group_instance with no group
|
|
CharacterDatabase.DirectExecute("DELETE FROM group_member WHERE guid NOT IN (SELECT guid FROM groups)");
|
|
CharacterDatabase.DirectExecute("DELETE FROM group_instance WHERE guid NOT IN (SELECT guid FROM groups)");
|
|
// Delete all members that does not exist
|
|
CharacterDatabase.DirectExecute("DELETE FROM group_member WHERE memberGuid NOT IN (SELECT guid FROM characters)");
|
|
|
|
// 0 1 2 3 4
|
|
QueryResult result = CharacterDatabase.Query("SELECT guid, memberGuid, memberFlags, subgroup, roles FROM group_member ORDER BY guid");
|
|
if (!result)
|
|
{
|
|
sLog->outInfo(LOG_FILTER_GENERAL, ">> Loaded 0 group members. DB table `group_member` is empty!");
|
|
|
|
return;
|
|
}
|
|
|
|
uint32 count = 0;
|
|
|
|
do
|
|
{
|
|
Field* fields = result->Fetch();
|
|
Group* group = GetGroupByDbStoreId(fields[0].GetUInt32());
|
|
|
|
if (group)
|
|
group->LoadMemberFromDB(fields[1].GetUInt32(), fields[2].GetUInt8(), fields[3].GetUInt8(), fields[4].GetUInt8());
|
|
else
|
|
sLog->outError(LOG_FILTER_GENERAL, "GroupMgr::LoadGroups: Consistency failed, can't find group (storage id: %u)", fields[0].GetUInt32());
|
|
|
|
++count;
|
|
}
|
|
while (result->NextRow());
|
|
|
|
sLog->outInfo(LOG_FILTER_GENERAL, ">> Loaded %u group members in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
|
|
|
}
|
|
|
|
sLog->outInfo(LOG_FILTER_GENERAL, "Loading Group instance saves...");
|
|
{
|
|
uint32 oldMSTime = getMSTime();
|
|
// 0 1 2 3 4 5 6
|
|
QueryResult result = CharacterDatabase.Query("SELECT gi.guid, i.map, gi.instance, gi.permanent, i.difficulty, i.resettime, COUNT(g.guid) "
|
|
"FROM group_instance gi INNER JOIN instance i ON gi.instance = i.id "
|
|
"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");
|
|
if (!result)
|
|
{
|
|
sLog->outInfo(LOG_FILTER_GENERAL, ">> Loaded 0 group-instance saves. DB table `group_instance` is empty!");
|
|
|
|
return;
|
|
}
|
|
|
|
uint32 count = 0;
|
|
do
|
|
{
|
|
Field* fields = result->Fetch();
|
|
Group* group = GetGroupByDbStoreId(fields[0].GetUInt32());
|
|
// group will never be NULL (we have run consistency sql's before loading)
|
|
|
|
MapEntry const* mapEntry = sMapStore.LookupEntry(fields[1].GetUInt16());
|
|
if (!mapEntry || !mapEntry->IsDungeon())
|
|
{
|
|
sLog->outError(LOG_FILTER_SQL, "Incorrect entry in group_instance table : no dungeon map %d", fields[1].GetUInt16());
|
|
continue;
|
|
}
|
|
|
|
uint32 diff = fields[4].GetUInt8();
|
|
if (diff >= uint32(mapEntry->IsRaid() ? MAX_RAID_DIFFICULTY : MAX_DUNGEON_DIFFICULTY))
|
|
{
|
|
sLog->outError(LOG_FILTER_SQL, "Wrong dungeon difficulty use in group_instance table: %d", diff + 1);
|
|
diff = 0; // default for both difficaly types
|
|
}
|
|
|
|
InstanceSave* save = sInstanceSaveMgr->AddInstanceSave(mapEntry->MapID, fields[2].GetUInt32(), Difficulty(diff), time_t(fields[5].GetUInt32()), (bool)fields[6].GetUInt64(), true);
|
|
group->BindToInstance(save, fields[3].GetBool(), true);
|
|
++count;
|
|
}
|
|
while (result->NextRow());
|
|
|
|
sLog->outInfo(LOG_FILTER_GENERAL, ">> Loaded %u group-instance saves in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
|
|
|
}
|
|
}
|