- 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
283 lines
9.1 KiB
C++
Executable File
283 lines
9.1 KiB
C++
Executable File
/*
|
|
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
*
|
|
* 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 "MapInstanced.h"
|
|
#include "ObjectMgr.h"
|
|
#include "MapManager.h"
|
|
#include "Battleground.h"
|
|
#include "VMapFactory.h"
|
|
#include "InstanceSaveMgr.h"
|
|
#include "World.h"
|
|
#include "Group.h"
|
|
|
|
MapInstanced::MapInstanced(uint32 id, time_t expiry) : Map(id, expiry, 0, DUNGEON_DIFFICULTY_NORMAL)
|
|
{
|
|
// initialize instanced maps list
|
|
m_InstancedMaps.clear();
|
|
// fill with zero
|
|
memset(&GridMapReference, 0, MAX_NUMBER_OF_GRIDS*MAX_NUMBER_OF_GRIDS*sizeof(uint16));
|
|
}
|
|
|
|
void MapInstanced::InitVisibilityDistance()
|
|
{
|
|
if (m_InstancedMaps.empty())
|
|
return;
|
|
//initialize visibility distances for all instance copies
|
|
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
|
|
{
|
|
(*i).second->InitVisibilityDistance();
|
|
}
|
|
}
|
|
|
|
void MapInstanced::Update(const uint32 t)
|
|
{
|
|
// take care of loaded GridMaps (when unused, unload it!)
|
|
Map::Update(t);
|
|
|
|
// update the instanced maps
|
|
InstancedMaps::iterator i = m_InstancedMaps.begin();
|
|
|
|
while (i != m_InstancedMaps.end())
|
|
{
|
|
if (i->second->CanUnload(t))
|
|
{
|
|
if (!DestroyInstance(i)) // iterator incremented
|
|
{
|
|
//m_unloadTimer
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// update only here, because it may schedule some bad things before delete
|
|
if (sMapMgr->GetMapUpdater()->activated())
|
|
sMapMgr->GetMapUpdater()->schedule_update(*i->second, t);
|
|
else
|
|
i->second->Update(t);
|
|
++i;
|
|
}
|
|
}
|
|
}
|
|
|
|
void MapInstanced::DelayedUpdate(const uint32 diff)
|
|
{
|
|
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
|
|
i->second->DelayedUpdate(diff);
|
|
|
|
Map::DelayedUpdate(diff); // this may be removed
|
|
}
|
|
|
|
/*
|
|
void MapInstanced::RelocationNotify()
|
|
{
|
|
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
|
|
i->second->RelocationNotify();
|
|
}
|
|
*/
|
|
|
|
void MapInstanced::UnloadAll()
|
|
{
|
|
// Unload instanced maps
|
|
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
|
|
i->second->UnloadAll();
|
|
|
|
// Delete the maps only after everything is unloaded to prevent crashes
|
|
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
|
|
delete i->second;
|
|
|
|
m_InstancedMaps.clear();
|
|
|
|
// Unload own grids (just dummy(placeholder) grids, neccesary to unload GridMaps!)
|
|
Map::UnloadAll();
|
|
}
|
|
|
|
/*
|
|
- return the right instance for the object, based on its InstanceId
|
|
- create the instance if it's not created already
|
|
- the player is not actually added to the instance (only in InstanceMap::Add)
|
|
*/
|
|
Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player)
|
|
{
|
|
if (GetId() != mapId || !player)
|
|
return NULL;
|
|
|
|
Map* map = NULL;
|
|
uint32 newInstanceId = 0; // instanceId of the resulting map
|
|
|
|
if (IsBattlegroundOrArena())
|
|
{
|
|
// instantiate or find existing bg map for player
|
|
// the instance id is set in battlegroundid
|
|
newInstanceId = player->GetBattlegroundId();
|
|
if (!newInstanceId)
|
|
return NULL;
|
|
|
|
map = sMapMgr->FindMap(mapId, newInstanceId);
|
|
if (!map)
|
|
{
|
|
if (Battleground* bg = player->GetBattleground())
|
|
map = CreateBattleground(newInstanceId, bg);
|
|
else
|
|
{
|
|
player->TeleportToBGEntryPoint();
|
|
return NULL;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
InstancePlayerBind* pBind = player->GetBoundInstance(GetId(), player->GetDifficulty(IsRaid()));
|
|
InstanceSave* pSave = pBind ? pBind->save : NULL;
|
|
|
|
// the player's permanent player bind is taken into consideration first
|
|
// then the player's group bind and finally the solo bind.
|
|
if (!pBind || !pBind->perm)
|
|
{
|
|
InstanceGroupBind* groupBind = NULL;
|
|
Group* group = player->GetGroup();
|
|
// use the player's difficulty setting (it may not be the same as the group's)
|
|
if (group)
|
|
{
|
|
groupBind = group->GetBoundInstance(this);
|
|
if (groupBind)
|
|
pSave = groupBind->save;
|
|
}
|
|
}
|
|
if (pSave)
|
|
{
|
|
// solo/perm/group
|
|
newInstanceId = pSave->GetInstanceId();
|
|
map = FindInstanceMap(newInstanceId);
|
|
// it is possible that the save exists but the map doesn't
|
|
if (!map)
|
|
map = CreateInstance(newInstanceId, pSave, pSave->GetDifficulty());
|
|
}
|
|
else
|
|
{
|
|
// if no instanceId via group members or instance saves is found
|
|
// the instance will be created for the first time
|
|
newInstanceId = sMapMgr->GenerateInstanceId();
|
|
|
|
Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid());
|
|
//Seems it is now possible, but I do not know if it should be allowed
|
|
//ASSERT(!FindInstanceMap(NewInstanceId));
|
|
map = FindInstanceMap(newInstanceId);
|
|
if (!map)
|
|
map = CreateInstance(newInstanceId, NULL, diff);
|
|
}
|
|
}
|
|
|
|
return map;
|
|
}
|
|
|
|
InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save, Difficulty difficulty)
|
|
{
|
|
// load/create a map
|
|
TRINITY_GUARD(ACE_Thread_Mutex, Lock);
|
|
|
|
// make sure we have a valid map id
|
|
const MapEntry* entry = sMapStore.LookupEntry(GetId());
|
|
if (!entry)
|
|
{
|
|
sLog->outError(LOG_FILTER_MAPS, "CreateInstance: no entry for map %d", GetId());
|
|
ASSERT(false);
|
|
}
|
|
const InstanceTemplate* iTemplate = sObjectMgr->GetInstanceTemplate(GetId());
|
|
if (!iTemplate)
|
|
{
|
|
sLog->outError(LOG_FILTER_MAPS, "CreateInstance: no instance template for map %d", GetId());
|
|
ASSERT(false);
|
|
}
|
|
|
|
// some instances only have one difficulty
|
|
GetDownscaledMapDifficultyData(GetId(), difficulty);
|
|
|
|
sLog->outDebug(LOG_FILTER_MAPS, "MapInstanced::CreateInstance: %s map instance %d for %d created with difficulty %s", save?"":"new ", InstanceId, GetId(), difficulty?"heroic":"normal");
|
|
|
|
InstanceMap* map = new InstanceMap(GetId(), GetGridExpiry(), InstanceId, difficulty, this);
|
|
ASSERT(map->IsDungeon());
|
|
|
|
map->LoadRespawnTimes();
|
|
|
|
bool load_data = save != NULL;
|
|
map->CreateInstanceData(load_data);
|
|
|
|
m_InstancedMaps[InstanceId] = map;
|
|
return map;
|
|
}
|
|
|
|
BattlegroundMap* MapInstanced::CreateBattleground(uint32 InstanceId, Battleground* bg)
|
|
{
|
|
// load/create a map
|
|
TRINITY_GUARD(ACE_Thread_Mutex, Lock);
|
|
|
|
sLog->outDebug(LOG_FILTER_MAPS, "MapInstanced::CreateBattleground: map bg %d for %d created.", InstanceId, GetId());
|
|
|
|
PvPDifficultyEntry const* bracketEntry = GetBattlegroundBracketByLevel(bg->GetMapId(), bg->GetMinLevel());
|
|
|
|
uint8 spawnMode;
|
|
|
|
if (bracketEntry)
|
|
spawnMode = bracketEntry->difficulty;
|
|
else
|
|
spawnMode = REGULAR_DIFFICULTY;
|
|
|
|
BattlegroundMap* map = new BattlegroundMap(GetId(), GetGridExpiry(), InstanceId, this, spawnMode);
|
|
ASSERT(map->IsBattlegroundOrArena());
|
|
map->SetBG(bg);
|
|
bg->SetBgMap(map);
|
|
|
|
m_InstancedMaps[InstanceId] = map;
|
|
return map;
|
|
}
|
|
|
|
// increments the iterator after erase
|
|
bool MapInstanced::DestroyInstance(InstancedMaps::iterator &itr)
|
|
{
|
|
itr->second->RemoveAllPlayers();
|
|
if (itr->second->HavePlayers())
|
|
{
|
|
++itr;
|
|
return false;
|
|
}
|
|
|
|
itr->second->UnloadAll();
|
|
// should only unload VMaps if this is the last instance and grid unloading is enabled
|
|
if (m_InstancedMaps.size() <= 1 && sWorld->getBoolConfig(CONFIG_GRID_UNLOAD))
|
|
{
|
|
VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(itr->second->GetId());
|
|
// in that case, unload grids of the base map, too
|
|
// so in the next map creation, (EnsureGridCreated actually) VMaps will be reloaded
|
|
Map::UnloadAll();
|
|
}
|
|
|
|
// Free up the instance id and allow it to be reused for bgs and arenas (other instances are handled in the InstanceSaveMgr)
|
|
if (itr->second->IsBattlegroundOrArena())
|
|
sMapMgr->FreeInstanceId(itr->second->GetInstanceId());
|
|
|
|
// erase map
|
|
delete itr->second;
|
|
m_InstancedMaps.erase(itr++);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool MapInstanced::CanEnter(Player* /*player*/)
|
|
{
|
|
//ASSERT(false);
|
|
return true;
|
|
} |