From 3cf9cf5bd74b5ac78cc78817dab02d27b4a2e802 Mon Sep 17 00:00:00 2001 From: GRMrGecko Date: Mon, 13 Feb 2012 21:43:03 -0600 Subject: [PATCH] Added a new feature to ignore channels/nicks which you do not want to have logged and replayed. Ignores are wildcard based and nick ignores includes the mask which allows you to block an entire ip address/hostname and or nick name. --- MySQL Database Defaults.sql | 11 ++ logmysql.cpp | 318 +++++++++++++++++++++++++++++++++--- logsqlite.cpp | 292 ++++++++++++++++++++++++++++++--- 3 files changed, 577 insertions(+), 44 deletions(-) diff --git a/MySQL Database Defaults.sql b/MySQL Database Defaults.sql index aad230a..9d1ddc5 100644 --- a/MySQL Database Defaults.sql +++ b/MySQL Database Defaults.sql @@ -31,4 +31,15 @@ BEGIN; INSERT INTO `settings` VALUES ('replayAll', '0'), ('logLimit', '1'), ('logLevel', '1'); COMMIT; +-- ---------------------------- +-- Table structure for `ignorelist` +-- ---------------------------- +DROP TABLE IF EXISTS `ignorelist`; +CREATE TABLE `ignorelist` ( + `rowid` int(10) unsigned NOT NULL AUTO_INCREMENT, + `type` text, + `target` text, + PRIMARY KEY (`rowid`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + SET FOREIGN_KEY_CHECKS = 1; diff --git a/logmysql.cpp b/logmysql.cpp index 922377b..e308151 100755 --- a/logmysql.cpp +++ b/logmysql.cpp @@ -40,6 +40,9 @@ public: AddCommand("ReplayAll", static_cast(&CLogMySQL::ReplayAllCommand), "[1|0]", "Replay all messages stored."); AddCommand("LogLimit", static_cast(&CLogMySQL::LogLimitCommand), "[0-9]+", "Limit the amount of items to store into the log."); AddCommand("LogLevel", static_cast(&CLogMySQL::LogLevelCommand), "[0-4]", "Log level."); + AddCommand("AddIgnore", static_cast(&CLogMySQL::AddIgnoreCommand), "Type[nick|chan] Target", "Add to ignore list."); + AddCommand("RemoveIgnore", static_cast(&CLogMySQL::RemoveIgnoreCommand), "Type[nick|chan] Target", "Remove from ignore list."); + AddCommand("IgnoreList", static_cast(&CLogMySQL::IgnoreListCommand), "", "View what is currently ignored."); } void HostCommand(const CString &sLine) { @@ -196,6 +199,88 @@ public: PutModule("LogLevel is "+now+"set to: "+setting); } + void AddIgnoreCommand(const CString &sLine) { + CString type = sLine.Token(1); + CString target = sLine.Token(2); + bool help = sLine.Equals("HELP"); + + if (help) { + PutModule("Inorder to add an ignore, you must choose what type of ignore it is which can ether be a nick or a chan."); + PutModule("Nicks are matched with wildcards against the full mask."); + PutModule("Channels are matched by #channel which can contain wildcards."); + } else if (!type.empty() && !target.empty()) { + if (type.Equals("nick")) + type = "nick"; + else if (type.Equals("chan") || type.Equals("channel")) + type = "chan"; + else + type = ""; + + if (type.empty()) { + PutModule("Unknown type. If you need help, type \"AddIgnore help\"."); + return; + } + + if (AddIgnore(type, target)) + PutModule("Successfully added \""+target+"\" to the ignore list."); + else + PutModule("Failed, maybe it already existed?"); + } else { + PutModule("If you need help, type \"AddIgnore help\"."); + } + } + + void RemoveIgnoreCommand(const CString &sLine) { + CString type = sLine.Token(1); + CString target = sLine.Token(2); + bool help = sLine.Equals("HELP"); + + if (help) { + PutModule("Inorder to remove an ignore, you must specify the type and the exact pattren used to add it. If you need to find what currently exists, type \"IgnoreList\"."); + } else if (!type.empty() && !target.empty()) { + if (type.Equals("nick")) + type = "nick"; + else if (type.Equals("chan") || type.Equals("channel")) + type = "chan"; + else + type = ""; + + if (type.empty()) { + PutModule("Unknown type. If you need help, type \"RemoveIgnore help\"."); + return; + } + + if (RemoveIgnore(type, target)) + PutModule("Successfully removed \""+target+"\" from the ignore list."); + else + PutModule("Failed, maybe it does not exist?"); + } else { + PutModule("If you need help, type \"RemoveIgnore help\"."); + } + } + + void IgnoreListCommand(const CString &sLine) { + if (nickIgnoreList.size()==0) { + PutModule("The nick ignore list is currently empty."); + } else { + PutModule("Nick ignore list contains:"); + + for (vector::iterator it=nickIgnoreList.begin(); it::iterator it=chanIgnoreList.begin(); it::iterator it=nickIgnoreList.begin(); it::iterator it=chanIgnoreList.begin(); it::iterator it=nickIgnoreList.begin(); it::iterator it=chanIgnoreList.begin(); it nickIgnoreList; + vector chanIgnoreList; }; template<> void TModInfo(CModInfo& Info) { diff --git a/logsqlite.cpp b/logsqlite.cpp index 8c4b8af..aa5e614 100755 --- a/logsqlite.cpp +++ b/logsqlite.cpp @@ -33,6 +33,9 @@ public: AddCommand("ReplayAll", static_cast(&CLogSQLite::ReplayAllCommand), "[1|0]", "Replay all messages stored."); AddCommand("LogLimit", static_cast(&CLogSQLite::LogLimitCommand), "[0-9]+", "Limit the amount of items to store into the log."); AddCommand("LogLevel", static_cast(&CLogSQLite::LogLevelCommand), "[0-4]", "Log level."); + AddCommand("AddIgnore", static_cast(&CLogSQLite::AddIgnoreCommand), "Type[nick|chan] Target", "Add to ignore list."); + AddCommand("RemoveIgnore", static_cast(&CLogSQLite::RemoveIgnoreCommand), "Type[nick|chan] Target", "Remove from ignore list."); + AddCommand("IgnoreList", static_cast(&CLogSQLite::IgnoreListCommand), "", "View what is currently ignored."); } void ReplayCommand(const CString &sLine) { @@ -109,41 +112,157 @@ public: PutModule("LogLevel is "+now+"set to: "+setting); } + void AddIgnoreCommand(const CString &sLine) { + CString type = sLine.Token(1); + CString target = sLine.Token(2); + bool help = sLine.Equals("HELP"); + + if (help) { + PutModule("Inorder to add an ignore, you must choose what type of ignore it is which can ether be a nick or a chan."); + PutModule("Nicks are matched with wildcards against the full mask."); + PutModule("Channels are matched by #channel which can contain wildcards."); + } else if (!type.empty() && !target.empty()) { + if (type.Equals("nick")) + type = "nick"; + else if (type.Equals("chan") || type.Equals("channel")) + type = "chan"; + else + type = ""; + + if (type.empty()) { + PutModule("Unknown type. If you need help, type \"AddIgnore help\"."); + return; + } + + if (AddIgnore(type, target)) + PutModule("Successfully added \""+target+"\" to the ignore list."); + else + PutModule("Failed, maybe it already existed?"); + } else { + PutModule("If you need help, type \"AddIgnore help\"."); + } + } + + void RemoveIgnoreCommand(const CString &sLine) { + CString type = sLine.Token(1); + CString target = sLine.Token(2); + bool help = sLine.Equals("HELP"); + + if (help) { + PutModule("Inorder to remove an ignore, you must specify the type and the exact pattren used to add it. If you need to find what currently exists, type \"IgnoreList\"."); + } else if (!type.empty() && !target.empty()) { + if (type.Equals("nick")) + type = "nick"; + else if (type.Equals("chan") || type.Equals("channel")) + type = "chan"; + else + type = ""; + + if (type.empty()) { + PutModule("Unknown type. If you need help, type \"RemoveIgnore help\"."); + return; + } + + if (RemoveIgnore(type, target)) + PutModule("Successfully removed \""+target+"\" from the ignore list."); + else + PutModule("Failed, maybe it does not exist?"); + } else { + PutModule("If you need help, type \"RemoveIgnore help\"."); + } + } + + void IgnoreListCommand(const CString &sLine) { + if (nickIgnoreList.size()==0) { + PutModule("The nick ignore list is currently empty."); + } else { + PutModule("Nick ignore list contains:"); + + for (vector::iterator it=nickIgnoreList.begin(); it::iterator it=chanIgnoreList.begin(); it::iterator it=nickIgnoreList.begin(); it::iterator it=chanIgnoreList.begin(); it::iterator it=nickIgnoreList.begin(); it::iterator it=chanIgnoreList.begin(); it nickIgnoreList; + vector chanIgnoreList; }; template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("logsqlite"); } -NETWORKMODULEDEFS(CLogSQLite, "Add logging to SQLite") +NETWORKMODULEDEFS(CLogSQLite, "Add logging to SQLite") \ No newline at end of file