Jump to content

Simple chat log system


Guest BThallid

Recommended Posts

There was a patch for a chatlog/lexicscutter system that made me decide to put in just a simple chatlog system without the lexics cutter system. I know that there is a lot of controversial/stazi/spying issues that people may come up with, but do you think official doesn't log stuff like this? This patch is using the same log functions that were already there rather than recreating the wheel. It uses familiar log settings in the config file. It could use a little more sprucing up, but it does the job as is. The config option is default to be off. It has undergone basic testing. No load increase checking, but shouldn't be much more.

Where to get it?

With git at git://github.com/BThallid/mangos.git chatlog or browse

Link to comment
Share on other sites

IMO you should use the default config system in MaNGOS instead of saving it in your own variabled.

I'm not sure of what you mean. I thought I was using almost the same as what I was seeing used for the way the gmlog was made. If there is a better way, by all means have at it. I was thinking about using the shared defines header, but as I am still learning about the various part of C, I didn't want to add the header for just one thing if it would be degrading more. I had finished the update a few days ago and intended on researching it further to find out the best method, but I had got busy with that whole real life stuff that's around. :)

Link to comment
Share on other sites

I forgot to add. Official used something very similar. I say this because of the following:

One time i had a problem with a player of offi who was very rude to me. I told some offensive words back to the player and called for a GM to intervene. When i called the GM and told him about my situation he/she said that i too had said some offensive words back which were and he wrote the same words i had said to the other player. So they DO have a similar system that logs everything a player says in EVERY chat including whisper since at that time both, the player and me offended each other via whisper messages. So with this i like to say that this type or enhancement does exist on official server.

Link to comment
Share on other sites

  • 2 weeks later...
look on insider42 repo hes has added a updated version for 333.

He has the chatlog/lexicscutter version. Mine is only a chatlog. I meant for it to be simple, but I think code starts to grow over time.

Can someone please update this, one of the strings or something give a error and stops compile. =[

Updated with rev 9748. Don't know what changed; I just rebased it and it didn't give me any errors. I compiled it with rev 9745 with no problems a little while back. I don't see any changes in the most recent commits that would effect it, so it should still compile just fine.

Link to comment
Share on other sites

This is having merge conflicts with the latest revision of the master MaNGOS branch, at least for me. I'm no C++ whizz, so if there's anything I need to link to help fix this, let me know.

I have no conflicts with applying my patch to fresh rev 9763. Are you talking about the branch that Thyros mentioned in insider42 repo? Do you have other patches? More details help problem solving.

Link to comment
Share on other sites

I'm trying it out on a clean core, from mangos/mangos, not Insider42/mangos.

Give me a mo and I'll edit in what is showing on the git bash console. I assume I'm just doing it wrong.

EDIT: Here you go. Clean MaNGOS core using latest revision as of this post.

ChatLog.patch:9: trailing whitespace.

{

ChatLog.patch:10: trailing whitespace.

sLog.outChat(type, "[%s] says: %s", GetPlayer()->GetName(), msg.

c_str());

ChatLog.patch:12: trailing whitespace.

}

ChatLog.patch:14: trailing whitespace.

{

ChatLog.patch:15: trailing whitespace.

sLog.outChat(type, "[%s] %s", GetPlayer()->GetName(), msg.c_str(

));

fatal: corrupt patch at line 477

Link to comment
Share on other sites

I'm trying it out on a clean core, from mangos/mangos, not Insider42/mangos.

Give me a mo and I'll edit in what is showing on the git bash console. I assume I'm just doing it wrong.

EDIT: Here you go. Clean MaNGOS core using latest revision as of this post.

Apparently, when copy and pasting the code to a file using something like notepad will give whitespace errors which can be ignored or rather fixed with the option --whitespace=fix when using git apply. The fatal part is caused by the need for a new line ending. Just enter/return down one line at the end.

Link to comment
Share on other sites

  • 4 months later...

diff --git a/src/game/ChatHandler.cpp b/src/game/ChatHandler.cpp
index a568d41..3449e2f 100644
--- a/src/game/ChatHandler.cpp
+++ b/src/game/ChatHandler.cpp
@@ -179,11 +179,20 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )
break;

if(type == CHAT_MSG_SAY)
+ {
+ sLog.outChat(type, "[%s] says: %s", GetPlayer()->GetName(), msg.c_str());
GetPlayer()->Say(msg, lang);
+ }
else if(type == CHAT_MSG_EMOTE)
+ {
+ sLog.outChat(type, "[%s] %s", GetPlayer()->GetName(), msg.c_str());
GetPlayer()->TextEmote(msg);
+ }
else if(type == CHAT_MSG_YELL)
+ {
+ sLog.outChat(type, "[%s] yells: %s", GetPlayer()->GetName(), msg.c_str());
GetPlayer()->Yell(msg, lang);
+ }
} break;

case CHAT_MSG_WHISPER:
@@ -224,6 +233,7 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )
}
}

+ sLog.outChat(type, "[%s] whispers to [%s]: %s", GetPlayer()->GetName(), to.c_str(), msg.c_str());
GetPlayer()->Whisper(msg, lang, player->GetGUID());
} break;

@@ -257,6 +267,11 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )
if((type == CHAT_MSG_PARTY_LEADER) && !group->IsLeader(_player->GetGUID()))
return;

+ if(type == CHAT_MSG_PARTY_LEADER)
+ sLog.outChat(type, "[%s][Party - Leader]: %s", GetPlayer()->GetName(), msg.c_str());
+ else
+ sLog.outChat(type, "[%s][%s's Party]: %s", GetPlayer()->GetName(), group->GetLeaderName(), msg.c_str());
+
WorldPacket data;
ChatHandler::FillMessageData(&data, this, type, lang, NULL, 0, msg.c_str(), NULL);
group->BroadcastPacket(&data, false, group->GetMemberGroup(GetPlayer()->GetGUID()));
@@ -281,7 +296,10 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )

if (GetPlayer()->GetGuildId())
if (Guild *guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId()))
+ {
guild->BroadcastToGuild(this, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL);
+ sLog.outChat(type, "[%s][Guild]<%s>: %s", GetPlayer()->GetName(), guild->GetName().c_str(), msg.c_str());
+ }
} break;

case CHAT_MSG_OFFICER:
@@ -303,7 +321,10 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )

if (GetPlayer()->GetGuildId())
if (Guild *guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId()))
+ {
guild->BroadcastToOfficers(this, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL);
+ sLog.outChat(type, "[%s][Guild][Officer]<%s>: %s", GetPlayer()->GetName(), guild->GetName().c_str(), msg.c_str());
+ }
} break;

case CHAT_MSG_RAID:
@@ -332,6 +353,8 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )
return;
}

+ sLog.outChat(type, "[%s][%s's Raid]: %s", GetPlayer()->GetName(), group->GetLeaderName(), msg.c_str());
+
WorldPacket data;
ChatHandler::FillMessageData(&data, this, CHAT_MSG_RAID, lang, "", 0, msg.c_str(), NULL);
group->BroadcastPacket(&data, false);
@@ -362,6 +385,8 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )
return;
}

+ sLog.outChat(type, "[%s][Raid - Leader]: %s", GetPlayer()->GetName(), msg.c_str());
+
WorldPacket data;
ChatHandler::FillMessageData(&data, this, CHAT_MSG_RAID_LEADER, lang, "", 0, msg.c_str(), NULL);
group->BroadcastPacket(&data, false);
@@ -382,6 +407,8 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )
if(!group || !group->isRaidGroup() || !(group->IsLeader(GetPlayer()->GetGUID()) || group->IsAssistant(GetPlayer()->GetGUID())))
return;

+ sLog.outChat(type, "[%s][%s's Raid]: %s", GetPlayer()->GetName(), group->GetLeaderName(), msg.c_str());
+
WorldPacket data;
//in battleground, raid warning is sent only to players in battleground - code is ok
ChatHandler::FillMessageData(&data, this, CHAT_MSG_RAID_WARNING, lang, "", 0, msg.c_str(), NULL);
@@ -404,6 +431,8 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )
if(!group || !group->isBGGroup())
return;

+ sLog.outChat(type, "[%s][%s's BG]: %s", GetPlayer()->GetName(), group->GetLeaderName(), msg.c_str());
+
WorldPacket data;
ChatHandler::FillMessageData(&data, this, CHAT_MSG_BATTLEGROUND, lang, "", 0, msg.c_str(), NULL);
group->BroadcastPacket(&data, false);
@@ -425,6 +454,8 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )
if(!group || !group->isBGGroup() || !group->IsLeader(GetPlayer()->GetGUID()))
return;

+ sLog.outChat(type, "[%s][bG - Leader]: %s", GetPlayer()->GetName(), msg.c_str());
+
WorldPacket data;
ChatHandler::FillMessageData(&data, this, CHAT_MSG_BATTLEGROUND_LEADER, lang, "", 0, msg.c_str(), NULL);
group->BroadcastPacket(&data, false);
@@ -444,7 +475,10 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )

if(ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
if(Channel *chn = cMgr->GetChannel(channel, _player))
+ {
chn->Say(_player->GetGUID(), msg.c_str(), lang);
+ sLog.outChat(type , "[%s][%s]: %s", GetPlayer()->GetName(), channel.c_str(), msg.c_str());
+ }
} break;

case CHAT_MSG_AFK:
diff --git a/src/mangosd/mangosd.conf.dist.in b/src/mangosd/mangosd.conf.dist.in
index 5d4053f..ec3c170 100644
--- a/src/mangosd/mangosd.conf.dist.in
+++ b/src/mangosd/mangosd.conf.dist.in
@@ -290,6 +290,35 @@ AddonChannel = 1
# in form Logname_#ID_YYYY-MM-DD_HH-MM-SS.Ext
# or form Logname_#ID.Ext
#
+# ChatLogFile
+# Chat Log file of chat text
+# Default: "" (Disable)
+#
+# ChatLogTimestamp
+# Chat Logfile with timestamp of server start in name
+# Default: 0 - no timestamp in name
+# 1 - add timestamp in name in form Logname_YYYY-MM-DD_HH-MM-SS.Ext for Logname.Ext
+#
+# ChatLogPerType
+# Chat Logfiles with chat type (Note: logs not created if ChatLogFile not set)
+# Default: 0 - add chat log data to single log file
+# 1 - add chat log data to chat type specific log files with name
+# in form Logname_TYPE_YYYY-MM-DD_HH-MM-SS.Ext
+# or form Logname_TYPE.Ext
+#
+# ChatLogSay
+# ChatLogEmote
+# ChatLogYell
+# ChatLogWhisper
+# ChatLogParty
+# ChatLogGuild
+# ChatLogRaid
+# ChatLogBG
+# ChatLogChannel
+# Chat of type is logged
+# Default: 0 - log disabled for chat type
+# 1 - log enabled for chat type
+#
# RaLogFile
# Log file of RA commands
# Default: "Ra.log"
@@ -324,6 +353,18 @@ CharLogDump = 0
GmLogFile = ""
GmLogTimestamp = 0
GmLogPerAccount = 0
+ChatLogFile = ""
+ChatLogTimestamp = 0
+ChatLogPerType = 0
+ChatLogSay = 0
+ChatLogEmote = 0
+ChatLogYell = 0
+ChatLogWhisper = 0
+ChatLogParty = 0
+ChatLogGuild = 0
+ChatLogRaid = 0
+ChatLogBG = 0
+ChatLogChannel = 0
RaLogFile = ""
LogColors = ""

diff --git a/src/shared/Log.cpp b/src/shared/Log.cpp
index 9d9988d..08ce05d 100644
--- a/src/shared/Log.cpp
+++ b/src/shared/Log.cpp
@@ -38,8 +38,11 @@ enum LogType
const int LogType_count = int(LogError) +1;

Log::Log() :
- raLogfile(NULL), logfile(NULL), gmLogfile(NULL), charLogfile(NULL),
- dberLogfile(NULL), m_colored(false), m_includeTime(false), m_gmlog_per_account(false)
+ raLogfile(NULL), logfile(NULL), gmLogfile(NULL), charLogfile(NULL), chatLogfile(NULL),
+ dberLogfile(NULL), m_colored(false), m_includeTime(false), m_gmlog_per_account(false),
+ m_chatlog_per_type(false), m_chatlog_logsay(false), m_chatlog_logemote(false),
+ m_chatlog_logyell(false), m_chatlog_logwhisper(false), m_chatlog_logparty(false),
+ m_chatlog_logguild(false), m_chatlog_lograid(false), m_chatlog_logbg(false)
{
Initialize();
}
@@ -225,6 +228,46 @@ void Log::Initialize()
}
}

+ m_chatlog_per_type = sConfig.GetBoolDefault("ChatLogPerType", false);
+ if(!m_chatlog_per_type)
+ chatLogfile = openLogFile("ChatLogFile", "ChatLogTimestamp", "a");
+ else
+ {
+ // Chat log settings for per type case
+ m_chatlog_filename_format = sConfig.GetStringDefault("ChatLogFile", "");
+ if(!m_chatlog_filename_format.empty())
+ {
+ bool m_chatlog_timestamp = sConfig.GetBoolDefault("ChatLogTimestamp", false);
+
+ size_t dot_pos = m_chatlog_filename_format.find_last_of(".");
+ if(dot_pos != m_chatlog_filename_format.npos)
+ {
+ if(m_chatlog_timestamp)
+ m_chatlog_filename_format.insert(dot_pos, m_logsTimestamp);
+
+ m_chatlog_filename_format.insert(dot_pos, "_%s");
+ }
+ else
+ {
+ m_chatlog_filename_format += "_%s";
+
+ if(m_chatlog_timestamp)
+ m_chatlog_filename_format += m_logsTimestamp;
+ }
+
+ m_chatlog_filename_format = m_logsDir + m_chatlog_filename_format;
+ }
+ }
+ m_chatlog_logsay = sConfig.GetBoolDefault("ChatLogSay", false);
+ m_chatlog_logemote = sConfig.GetBoolDefault("ChatLogEmote", false);
+ m_chatlog_logyell = sConfig.GetBoolDefault("ChatLogYell", false);
+ m_chatlog_logwhisper = sConfig.GetBoolDefault("ChatLogWhisper", false);
+ m_chatlog_logparty = sConfig.GetBoolDefault("ChatLogParty", false);
+ m_chatlog_logguild = sConfig.GetBoolDefault("ChatLogGuild", false);
+ m_chatlog_lograid = sConfig.GetBoolDefault("ChatLogRaid", false);
+ m_chatlog_logbg = sConfig.GetBoolDefault("ChatLogBG", false);
+ m_chatlog_logchannel = sConfig.GetBoolDefault("ChatLogChannel", false);
+
charLogfile = openLogFile("CharLogFile","CharLogTimestamp","a");
dberLogfile = openLogFile("DBErrorLogFile",NULL,"a");
raLogfile = openLogFile("RaLogFile",NULL,"a");
@@ -279,6 +322,56 @@ FILE* Log::openGmlogPerAccount(uint32 account)
return fopen(namebuf, "a");
}

+FILE* Log::openChatLogPerType(uint32 chattype)
+{
+ if(m_chatlog_filename_format.empty())
+ return NULL;
+
+ std::string chatstr = "";
+
+ switch(chattype)
+ {
+ case 1: // CHAT_MSG_SAY
+ chatstr = "SAY";
+ break;
+ case 10: // CHAT_MSG_EMOTE
+ chatstr = "EMOTE";
+ break;
+ case 6: // CHAT_MSG_YELL
+ chatstr = "YELL";
+ break;
+ case 7: // CHAT_MSG_WHISPER
+ chatstr = "WHISPER";
+ break;
+ case 2: // CHAT_MSG_PARTY
+ case 51: // CHAT_MSG_PARTY_LEADER
+ chatstr = "PARTY";
+ break;
+ case 4: // CHAT_MSG_GUILD
+ case 5: // CHAT_MSG_OFFICER
+ chatstr = "GUILD";
+ break;
+ case 3: // CHAT_MSG_RAID
+ case 39: // CHAT_MSG_RAID_LEADER
+ case 40: // CHAT_MSG_RAID_WARNING
+ chatstr = "RAID";
+ break;
+ case 44: // CHAT_MSG_BATTLEGROUND
+ case 45: // CHAT_MSG_BATTLEGROUND_LEADER
+ chatstr = "BG";
+ break;
+ case 17: // CHAT_MSG_CHANNEL
+ chatstr = "CHANNEL";
+ break;
+ default:
+ break;
+ }
+
+ char namebuf[MANGOS_PATH_MAX];
+ snprintf(namebuf, MANGOS_PATH_MAX, m_chatlog_filename_format.c_str(), chatstr.c_str());
+ return fopen(namebuf, "a");
+}
+
void Log::outTimestamp(FILE* file)
{
time_t t = time(NULL);
@@ -681,6 +774,114 @@ void Log::outCommand( uint32 account, const char * str, ... )
fflush(stdout);
}

+void Log::outChat( uint32 chattype, const char * str, ... )
+{
+ if( !str )
+ return;
+
+ switch(chattype)
+ {
+ case 1: // CHAT_MSG_SAY
+ if(!m_chatlog_logsay)
+ return;
+ break;
+ case 10: // CHAT_MSG_EMOTE
+ if(!m_chatlog_logemote)
+ return;
+ break;
+ case 6: // CHAT_MSG_YELL
+ if(!m_chatlog_logyell)
+ return;
+ break;
+ case 7: // CHAT_MSG_WHISPER
+ if(!m_chatlog_logwhisper)
+ return;
+ break;
+ case 2: // CHAT_MSG_PARTY
+ case 51: // CHAT_MSG_PARTY_LEADER
+ if(!m_chatlog_logparty)
+ return;
+ break;
+ case 4: // CHAT_MSG_GUILD
+ case 5: // CHAT_MSG_OFFICER
+ if(!m_chatlog_logguild)
+ return;
+ break;
+ case 3: // CHAT_MSG_RAID
+ case 39: // CHAT_MSG_RAID_LEADER
+ case 40: // CHAT_MSG_RAID_WARNING
+ if(!m_chatlog_lograid)
+ return;
+ break;
+ case 44: // CHAT_MSG_BATTLEGROUND
+ case 45: // CHAT_MSG_BATTLEGROUND_LEADER
+ if(!m_chatlog_logbg)
+ return;
+ break;
+ case 17: // CHAT_MSG_CHANNEL
+ if(!m_chatlog_logchannel)
+ return;
+ break;
+ default:
+ break;
+ }
+
+ if( m_logLevel > 1 )
+ {
+ if(m_colored)
+ SetColor(true,m_colors[LogDetails]);
+
+ 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(logfile && m_logFileLevel > 1)
+ {
+ va_list ap;
+ outTimestamp(logfile);
+ va_start(ap, str);
+ vfprintf(logfile, str, ap);
+ fprintf(logfile, "\\n" );
+ va_end(ap);
+ fflush(logfile);
+ }
+
+ if (m_chatlog_per_type)
+ {
+ if (FILE* per_file = openChatLogPerType (chattype))
+ {
+ va_list ap;
+ outTimestamp(per_file);
+ va_start(ap, str);
+ vfprintf(per_file, str, ap);
+ fprintf(per_file, "\\n" );
+ va_end(ap);
+ fclose(per_file);
+ }
+ }
+ else if (chatLogfile)
+ {
+ va_list ap;
+ outTimestamp(chatLogfile);
+ va_start(ap, str);
+ vfprintf(chatLogfile, str, ap);
+ fprintf(chatLogfile, "\\n" );
+ va_end(ap);
+ fflush(chatLogfile);
+ }
+
+ fflush(stdout);
+}
+
void Log::outChar(const char * str, ... )
{

diff --git a/src/shared/Log.h b/src/shared/Log.h
index 9d08d66..11ec7bb 100644
--- a/src/shared/Log.h
+++ b/src/shared/Log.h
@@ -74,6 +74,10 @@ class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ACE_Th
fclose(charLogfile);
charLogfile = NULL;

+ if (chatLogfile != NULL)
+ fclose(chatLogfile);
+ chatLogfile = NULL;
+
if( dberLogfile != NULL )
fclose(dberLogfile);
dberLogfile = NULL;
@@ -109,6 +113,8 @@ class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ACE_Th
// any log level
void outErrorDb( const char * str, ... ) ATTR_PRINTF(2,3);
// any log level
+ void outChat( uint32 chattype, const char * str, ... ) ATTR_PRINTF(2,3);
+ // any log level
void outChar( const char * str, ... ) ATTR_PRINTF(2,3);
// any log level
void outWorldPacketDump( uint32 socket, uint32 opcode, char const* opcodeName, ByteBuffer const* packet, bool incoming );
@@ -129,11 +135,13 @@ class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ACE_Th
private:
FILE* openLogFile(char const* configFileName,char const* configTimeStampFlag, char const* mode);
FILE* openGmlogPerAccount(uint32 account);
+ FILE* openChatLogPerType(uint32 chattype);

FILE* raLogfile;
FILE* logfile;
FILE* gmLogfile;
FILE* charLogfile;
+ FILE* chatLogfile;
FILE* dberLogfile;
FILE* worldLogfile;

@@ -152,6 +160,19 @@ class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ACE_Th
// char log control
bool m_charLog_Dump;

+ // chat log control
+ bool m_chatlog_per_type;
+ bool m_chatlog_logsay;
+ bool m_chatlog_logemote;
+ bool m_chatlog_logyell;
+ bool m_chatlog_logwhisper;
+ bool m_chatlog_logparty;
+ bool m_chatlog_logguild;
+ bool m_chatlog_lograid;
+ bool m_chatlog_logbg;
+ bool m_chatlog_logchannel;
+ std::string m_chatlog_filename_format;
+
// gm log control
bool m_gmlog_per_account;
std::string m_gmlog_filename_format;

new version or update?

.ps i use double-byte character, so console is broken. but log file is fine.

anyone can fix this problem?

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use