[Warden]Fix server crash on shutdown

This commit is contained in:
H0zen 2016-03-31 00:09:16 +03:00
parent 19abc84cc9
commit c474651775
4 changed files with 42 additions and 34 deletions

View File

@ -41,6 +41,9 @@ WardenCheckMgr::~WardenCheckMgr()
for (CheckResultMap::iterator it = CheckResultStore.begin(); it != CheckResultStore.end(); ++it) for (CheckResultMap::iterator it = CheckResultStore.begin(); it != CheckResultStore.end(); ++it)
delete it->second; delete it->second;
CheckStore.clear();
CheckResultStore.clear();
} }
void WardenCheckMgr::LoadWardenChecks() void WardenCheckMgr::LoadWardenChecks()
@ -48,10 +51,9 @@ void WardenCheckMgr::LoadWardenChecks()
// Check if Warden is enabled by config before loading anything // Check if Warden is enabled by config before loading anything
if (!sWorld.getConfig(CONFIG_BOOL_WARDEN_WIN_ENABLED) && !sWorld.getConfig(CONFIG_BOOL_WARDEN_OSX_ENABLED)) if (!sWorld.getConfig(CONFIG_BOOL_WARDEN_WIN_ENABLED) && !sWorld.getConfig(CONFIG_BOOL_WARDEN_OSX_ENABLED))
{ {
sLog.outWarden(">> Warden disabled, loading checks skipped."); sLog.outString(">> Warden disabled, loading checks skipped.");
return; return;
} }
// 0 1 2 3 4 5 6 7 8 // 0 1 2 3 4 5 6 7 8
QueryResult *result = WorldDatabase.Query("SELECT id, build, type, data, result, address, length, str, comment FROM warden ORDER BY build ASC, id ASC"); QueryResult *result = WorldDatabase.Query("SELECT id, build, type, data, result, address, length, str, comment FROM warden ORDER BY build ASC, id ASC");
@ -138,7 +140,7 @@ void WardenCheckMgr::LoadWardenChecks()
++count; ++count;
} while (result->NextRow()); } while (result->NextRow());
sLog.outWarden(">> Loaded %u warden checks.", count); sLog.outString(">> Loaded %u warden checks.", count);
delete result; delete result;
} }
@ -148,22 +150,22 @@ void WardenCheckMgr::LoadWardenOverrides()
// Check if Warden is enabled by config before loading anything // Check if Warden is enabled by config before loading anything
if (!sWorld.getConfig(CONFIG_BOOL_WARDEN_WIN_ENABLED) && !sWorld.getConfig(CONFIG_BOOL_WARDEN_OSX_ENABLED)) if (!sWorld.getConfig(CONFIG_BOOL_WARDEN_WIN_ENABLED) && !sWorld.getConfig(CONFIG_BOOL_WARDEN_OSX_ENABLED))
{ {
sLog.outWarden(">> Warden disabled, loading check overrides skipped."); sLog.outString(">> Warden disabled, loading check overrides skipped.");
return; return;
} }
// 0 1 // 0 1
QueryResult* result = CharacterDatabase.Query("SELECT wardenId, action FROM warden_action"); QueryResult* result = CharacterDatabase.Query("SELECT wardenId, action FROM warden_action");
if (!result) if (!result)
{ {
sLog.outWarden(">> Loaded 0 Warden action overrides. DB table `warden_action` is empty!"); sLog.outString(">> Loaded 0 Warden action overrides. DB table `warden_action` is empty!");
return; return;
} }
uint32 count = 0; uint32 count = 0;
ACE_WRITE_GUARD(ACE_RW_Mutex, g, m_lock); ACE_WRITE_GUARD(LOCK, g, m_lock)
do do
{ {
@ -193,14 +195,14 @@ void WardenCheckMgr::LoadWardenOverrides()
} }
while (result->NextRow()); while (result->NextRow());
sLog.outWarden(">> Loaded %u warden action overrides.", count); sLog.outString(">> Loaded %u warden action overrides.", count);
} }
WardenCheck* WardenCheckMgr::GetWardenDataById(uint16 build, uint16 id) WardenCheck* WardenCheckMgr::GetWardenDataById(uint16 build, uint16 id)
{ {
WardenCheck* result = NULL; WardenCheck* result = NULL;
ACE_READ_GUARD_RETURN(ACE_RW_Mutex, g, m_lock, result) ACE_READ_GUARD_RETURN(LOCK, g, m_lock, result)
for (CheckMap::iterator it = CheckStore.lower_bound(build); it != CheckStore.upper_bound(build); ++it) for (CheckMap::iterator it = CheckStore.lower_bound(build); it != CheckStore.upper_bound(build); ++it)
{ {
if (it->second->CheckId == id) if (it->second->CheckId == id)
@ -214,7 +216,7 @@ WardenCheckResult* WardenCheckMgr::GetWardenResultById(uint16 build, uint16 id)
{ {
WardenCheckResult* result = NULL; WardenCheckResult* result = NULL;
ACE_READ_GUARD_RETURN(ACE_RW_Mutex, g, m_lock, result) ACE_READ_GUARD_RETURN(LOCK, g, m_lock, result)
for (CheckResultMap::iterator it = CheckResultStore.lower_bound(build); it != CheckResultStore.upper_bound(build); ++it) for (CheckResultMap::iterator it = CheckResultStore.lower_bound(build); it != CheckResultStore.upper_bound(build); ++it)
{ {
if (it->second->Id == id) if (it->second->Id == id)
@ -228,7 +230,7 @@ void WardenCheckMgr::GetWardenCheckIds(bool isMemCheck, uint16 build, std::list<
{ {
idl.clear(); //just to be sure idl.clear(); //just to be sure
ACE_READ_GUARD(ACE_RW_Mutex, g, m_lock); ACE_READ_GUARD(LOCK, g, m_lock)
for (CheckMap::iterator it = CheckStore.lower_bound(build); it != CheckStore.upper_bound(build); ++it) for (CheckMap::iterator it = CheckStore.lower_bound(build); it != CheckStore.upper_bound(build); ++it)
{ {
if (isMemCheck) if (isMemCheck)

View File

@ -75,10 +75,11 @@ class WardenCheckMgr
void LoadWardenOverrides(); void LoadWardenOverrides();
private: private:
ACE_RW_Mutex m_lock; typedef ACE_RW_Thread_Mutex LOCK;
typedef std::multimap< uint16, WardenCheck* > CheckMap; typedef std::multimap< uint16, WardenCheck* > CheckMap;
typedef std::multimap< uint16, WardenCheckResult* > CheckResultMap; typedef std::multimap< uint16, WardenCheckResult* > CheckResultMap;
LOCK m_lock;
CheckMap CheckStore; CheckMap CheckStore;
CheckResultMap CheckResultStore; CheckResultMap CheckResultStore;

View File

@ -351,8 +351,9 @@ void WardenWin::HandleData(ByteBuffer &buff)
uint32 ticksNow = WorldTimer::getMSTime(); uint32 ticksNow = WorldTimer::getMSTime();
uint32 ourTicks = newClientTicks + (ticksNow - _serverTicks); uint32 ourTicks = newClientTicks + (ticksNow - _serverTicks);
sLog.outWarden("ServerTicks %u, RequestTicks %u, CLientTicks %u", ticksNow, _serverTicks, newClientTicks); // Now, At request, At response sLog.outWarden("ServerTicks %u, RequestTicks %u, ClientTicks %u", ticksNow, _serverTicks, newClientTicks); // Now, At request, At response
sLog.outWarden("Waittime %u", ourTicks - newClientTicks); sLog.outWarden("Waittime %u", ourTicks - newClientTicks);
} }
WardenCheckResult* rs; WardenCheckResult* rs;

View File

@ -893,32 +893,36 @@ void Log::outWarden(const char* str, ...)
{ {
return; return;
} }
if (m_logLevel >= LOG_LVL_DETAIL)
if (m_colored)
{ {
SetColor(true, m_colors[LogNormal]); if (m_colored)
{
SetColor(true, m_colors[LogNormal]);
}
if (m_includeTime)
{
outTime();
}
va_list ap;
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
if (m_colored)
{
ResetColor(true);
}
printf("\n");
} }
if (m_includeTime) if (wardenLogfile && m_logFileLevel >= LOG_LVL_DETAIL)
{ {
outTime(); va_list ap;
}
va_list ap;
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
if (m_colored)
{
ResetColor(true);
}
printf("\n");
if (wardenLogfile)
{
outTimestamp(wardenLogfile); outTimestamp(wardenLogfile);
fprintf(wardenLogfile, "[Warden]: "); fprintf(wardenLogfile, "[Warden]: ");