diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-07-08 21:52:56 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-07-08 21:52:56 +0000 |
commit | 53ebf157c53f6808cb042c5a6cc6edd06d394c98 (patch) | |
tree | 483e31dd8e96e00a11fc3a04225688533d32da61 /src/modules | |
parent | db07867e945deb72ce103f796e20104a27c5f68a (diff) |
Convert m_censor to new api
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4196 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/m_censor.cpp | 86 |
1 files changed, 67 insertions, 19 deletions
diff --git a/src/modules/m_censor.cpp b/src/modules/m_censor.cpp index 8c8bfc001..246079c10 100644 --- a/src/modules/m_censor.cpp +++ b/src/modules/m_censor.cpp @@ -36,11 +36,69 @@ class CensorException : public ModuleException } }; +class CensorUser : public ModeHandler +{ + public: + CensorUser() : ModeHandler('G', 0, 0, false, MODETYPE_USER, false) { } + + ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) + { + if (adding) + { + if (!dest->IsModeSet('G')) + { + dest->SetMode('G',true); + return MODEACTION_ALLOW; + } + } + else + { + if (dest->IsModeSet('G')) + { + dest->SetMode('G',false); + return MODEACTION_ALLOW; + } + } + + return MODEACTION_DENY; + } +}; + +class CensorChannel : public ModeHandler +{ + public: + CensorChannel() : ModeHandler('G', 0, 0, false, MODETYPE_CHANNEL, false) { } + + ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) + { + if (adding) + { + if (!channel->IsModeSet('G')) + { + channel->SetMode('G',false); + return MODEACTION_ALLOW; + } + } + else + { + if (channel->IsModeSet('G')) + { + channel->SetMode('G',false); + return MODEACTION_ALLOW; + } + } + + return MODEACTION_ALLOW; + } +}; + class ModuleCensor : public Module { Server *Srv; censor_t censors; + CensorUser *cu; + CensorChannel *cc; public: ModuleCensor(Server* Me) @@ -60,13 +118,15 @@ class ModuleCensor : public Module */ Srv = Me; OnRehash(""); - Srv->AddExtendedMode('G',MT_CHANNEL,false,0,0); - Srv->AddExtendedMode('G',MT_CLIENT,false,0,0); + cu = new CensorUser; + cc = new CensorChannel; + Srv->AddMode(cu, 'G'); + Srv->AddMode(cc, 'G'); } void Implements(char* List) { - List[I_OnRehash] = List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnExtendedMode] = 1; + List[I_OnRehash] = List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1; } @@ -74,23 +134,11 @@ class ModuleCensor : public Module { InsertMode(output,"G",4); } - - - virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) - { - // check if this is our mode character... - if (modechar == 'G') - { - return 1; - } - else - { - return 0; - } - } - + virtual ~ModuleCensor() { + delete cu; + delete cc; } virtual void ReplaceLine(irc::string &text, irc::string pattern, irc::string replace) @@ -119,7 +167,7 @@ class ModuleCensor : public Module if (target_type == TYPE_USER) { userrec* t = (userrec*)dest; - active = t->modes['G'-65]; + active = t->IsModeSet('G'); } else if (target_type == TYPE_CHANNEL) { |