[8797] Merge WorldLog class into Log class.

* Added AuthSocket::SendPacket() function.
 * Packet logging now also possible in realmd.
 * realmd.conf.dist.in updated (added "WorldLogFile" setting).
This commit is contained in:
XTZGZoReX 2009-11-09 02:24:12 +01:00
parent fc42125cfb
commit 07aa44992b
13 changed files with 117 additions and 183 deletions

View file

@ -283,8 +283,6 @@ libmangosgame_a_SOURCES = \
Weather.h \
World.cpp \
World.h \
WorldLog.cpp \
WorldLog.h \
WorldSession.cpp \
WorldSession.h \
WorldSocket.cpp \

View file

@ -1,47 +0,0 @@
/*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** \file
\ingroup u2w
*/
#include "WorldLog.h"
#include "Policies/SingletonImp.h"
#include "Config/ConfigEnv.h"
#define CLASS_LOCK MaNGOS::ClassLevelLockable<WorldLog, ACE_Thread_Mutex>
INSTANTIATE_SINGLETON_2(WorldLog, CLASS_LOCK);
INSTANTIATE_CLASS_MUTEX(WorldLog, ACE_Thread_Mutex);
/// Open the log file (if specified so in the configuration file)
void WorldLog::Initialize()
{
std::string logsDir = sConfig.GetStringDefault("LogsDir","");
if(!logsDir.empty())
{
if((logsDir.at(logsDir.length()-1)!='/') && (logsDir.at(logsDir.length()-1)!='\\'))
logsDir.append("/");
}
std::string logname = sConfig.GetStringDefault("WorldLogFile", "");
if(!logname.empty())
{
i_file = fopen((logsDir+logname).c_str(), "w");
}
}

View file

@ -1,76 +0,0 @@
/*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/// \addtogroup u2w
/// @{
/// \file
#ifndef MANGOS_WORLDLOG_H
#define MANGOS_WORLDLOG_H
#include "Common.h"
#include "Policies/Singleton.h"
#include "Errors.h"
#include <stdarg.h>
/// %Log packets to a file
class MANGOS_DLL_DECL WorldLog : public MaNGOS::Singleton<WorldLog, MaNGOS::ClassLevelLockable<WorldLog, ACE_Thread_Mutex> >
{
friend class MaNGOS::OperatorNew<WorldLog>;
WorldLog() : i_file(NULL) { Initialize(); }
WorldLog(const WorldLog &);
WorldLog& operator=(const WorldLog &);
typedef MaNGOS::ClassLevelLockable<WorldLog, ACE_Thread_Mutex>::Lock Guard;
/// Close the file in destructor
~WorldLog()
{
if( i_file != NULL )
fclose(i_file);
i_file = NULL;
}
public:
void Initialize();
/// Is the world logger active?
bool LogWorld(void) const { return (i_file != NULL); }
/// %Log to the file
void Log(char const *fmt, ...)
{
if( LogWorld() )
{
Guard guard(*this);
ASSERT(i_file);
va_list args;
va_start(args, fmt);
vfprintf(i_file, fmt, args);
va_end(args);
fflush(i_file);
}
}
private:
FILE *i_file;
};
#define sWorldLog WorldLog::Instance()
#endif
/// @}

View file

@ -42,7 +42,6 @@
#include "WorldSession.h"
#include "WorldSocketMgr.h"
#include "Log.h"
#include "WorldLog.h"
#if defined( __GNUC__ )
#pragma pack(1)
@ -166,24 +165,21 @@ int WorldSocket::SendPacket (const WorldPacket& pct)
return -1;
// Dump outgoing packet.
if (sWorldLog.LogWorld ())
if (sLog.IsLogWorld())
{
sWorldLog.Log ("SERVER:\nSOCKET: %u\nLENGTH: %u\nOPCODE: %s (0x%.4X)\nDATA:\n",
(uint32) get_handle (),
pct.size (),
LookupOpcodeName (pct.GetOpcode ()),
pct.GetOpcode ());
sLog.outWorld("S->C - SOCKET: %u LENGTH: %u OPCODE: %s (0x%.4X)\n",
uint32(get_handle()), pct.size (), LookupOpcodeName(pct.GetOpcode()), pct.GetOpcode());
uint32 p = 0;
while (p < pct.size ())
size_t p = 0;
while (p < pct.size())
{
for (uint32 j = 0; j < 16 && p < pct.size (); j++)
sWorldLog.Log ("%.2X ", const_cast<WorldPacket&>(pct)[p++]);
for (size_t j = 0; j < 16 && p < pct.size(); ++j)
sLog.outWorld("%.2X ", const_cast<WorldPacket&>(pct)[p++]);
sWorldLog.Log ("\n");
sLog.outWorld("\n");
}
sWorldLog.Log ("\n\n");
sLog.outWorld("\n\n");
}
ServerPktHeader header(pct.size()+2, pct.GetOpcode());
@ -682,25 +678,25 @@ int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
return -1;
// Dump received packet.
if (sWorldLog.LogWorld ())
if (sLog.IsLogWorld())
{
sWorldLog.Log ("CLIENT:\nSOCKET: %u\nLENGTH: %u\nOPCODE: %s (0x%.4X)\nDATA:\n",
(uint32) get_handle (),
new_pct->size (),
LookupOpcodeName (new_pct->GetOpcode ()),
new_pct->GetOpcode ());
sLog.outWorld("C->S - SOCKET: %u LENGTH: %u OPCODE: %s (0x%.4X)\n",
uint32(get_handle()), new_pct->size(), LookupOpcodeName(new_pct->GetOpcode()), new_pct->GetOpcode());
uint32 p = 0;
while (p < new_pct->size ())
size_t p = 0;
while (p < new_pct->size())
{
for (uint32 j = 0; j < 16 && p < new_pct->size (); j++)
sWorldLog.Log ("%.2X ", (*new_pct)[p++]);
sWorldLog.Log ("\n");
for (size_t j = 0; j < 16 && p < new_pct->size(); ++j)
sLog.outWorld("%.2X ", (*new_pct)[p++]);
sLog.outWorld("\n");
}
sWorldLog.Log ("\n\n");
sLog.outWorld("\n\n");
}
try {
try
{
switch(opcode)
{
case CMSG_PING:
@ -738,13 +734,13 @@ int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
}
}
}
catch(ByteBufferException &)
catch (ByteBufferException &)
{
sLog.outError("WorldSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i. Disconnected client.",
opcode, GetRemoteAddress().c_str(), m_Session?m_Session->GetAccountId():-1);
if(sLog.IsOutDebug())
{
sLog.outDebug("Dumping error causing packet:");
sLog.outDebug("Dumping error-causing packet:");
new_pct->hexlike();
}