The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

m_chanfilter.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #define _CRT_SECURE_NO_DEPRECATE
00015 #define _SCL_SECURE_NO_DEPRECATE
00016 
00017 #include "inspircd.h"
00018 #include "u_listmode.h"
00019 
00020 /* $ModDesc: Provides channel-specific censor lists (like mode +G but varies from channel to channel) */
00021 /* $ModDep: ../../include/u_listmode.h */
00022 
00025 class ChanFilter : public ListModeBase
00026 {
00027  public:
00028         ChanFilter(InspIRCd* Instance) : ListModeBase(Instance, 'g', "End of channel spamfilter list", 941, 940, false, "chanfilter") { }
00029 
00030         virtual bool ValidateParam(User* user, Channel* chan, std::string &word)
00031         {
00032                 if ((word.length() > 35) || (word.empty()))
00033                 {
00034                         user->WriteNumeric(935, "%s %s %s :word is too %s for censor list",user->nick.c_str(), chan->name.c_str(), word.c_str(), (word.empty() ? "short" : "long"));
00035                         return false;
00036                 }
00037 
00038                 return true;
00039         }
00040 
00041         virtual bool TellListTooLong(User* user, Channel* chan, std::string &word)
00042         {
00043                 user->WriteNumeric(939, "%s %s %s :Channel spamfilter list is full", user->nick.c_str(), chan->name.c_str(), word.c_str());
00044                 return true;
00045         }
00046 
00047         virtual void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
00048         {
00049                 user->WriteNumeric(937, "%s %s :The word %s is already on the spamfilter list",user->nick.c_str(), chan->name.c_str(), word.c_str());
00050         }
00051 
00052         virtual void TellNotSet(User* user, Channel* chan, std::string &word)
00053         {
00054                 user->WriteNumeric(938, "%s %s :No such spamfilter word is set",user->nick.c_str(), chan->name.c_str());
00055         }
00056 };
00057 
00058 class ModuleChanFilter : public Module
00059 {
00060 
00061         ChanFilter* cf;
00062 
00063  public:
00064 
00065         ModuleChanFilter(InspIRCd* Me)
00066                 : Module(Me)
00067         {
00068                 cf = new ChanFilter(ServerInstance);
00069                 if (!ServerInstance->Modes->AddMode(cf))
00070                         throw ModuleException("Could not add new modes!");
00071 
00072                 cf->DoImplements(this);
00073                 Implementation eventlist[] = { I_OnCleanup, I_OnChannelDelete, I_OnRehash, I_OnUserPreMessage, I_OnUserPreNotice, I_OnSyncChannel };
00074                 ServerInstance->Modules->Attach(eventlist, this, 6);
00075 
00076                 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
00077         }
00078 
00079         virtual void OnChannelDelete(Channel* chan)
00080         {
00081                 cf->DoChannelDelete(chan);
00082         }
00083 
00084         virtual void OnRehash(User* user, const std::string &parameter)
00085         {
00086                 cf->DoRehash();
00087         }
00088 
00089         virtual int ProcessMessages(User* user,Channel* chan,std::string &text)
00090         {
00091                 if (!IS_LOCAL(user) || (CHANOPS_EXEMPT(ServerInstance, 'g') && chan->GetStatus(user) == STATUS_OP))
00092                         return 0;
00093 
00094                 modelist* list;
00095                 chan->GetExt(cf->GetInfoKey(), list);
00096 
00097                 if (list)
00098                 {
00099                         for (modelist::iterator i = list->begin(); i != list->end(); i++)
00100                         {
00101                                 if (InspIRCd::Match(text, i->mask))
00102                                 {
00103                                         user->WriteNumeric(936, "%s %s %s :Your message contained a censored word, and was blocked",user->nick.c_str(), chan->name.c_str(), i->mask.c_str());
00104                                         return 1;
00105                                 }
00106                         }
00107                 }
00108 
00109                 return 0;
00110         }
00111 
00112         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
00113         {
00114                 if (target_type == TYPE_CHANNEL)
00115                 {
00116                         return ProcessMessages(user,(Channel*)dest,text);
00117                 }
00118                 return 0;
00119         }
00120 
00121         virtual void OnCleanup(int target_type, void* item)
00122         {
00123                 cf->DoCleanup(target_type, item);
00124         }
00125 
00126         virtual const char* OnRequest(Request* request)
00127         {
00128                 return cf->DoOnRequest(request);
00129         }
00130 
00131         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
00132         {
00133                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
00134         }
00135 
00136         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
00137         {
00138                 cf->DoSyncChannel(chan, proto, opaque);
00139         }
00140 
00141         virtual Version GetVersion()
00142         {
00143                 return Version("$Id: m_chanfilter.cpp 10408 2008-09-06 13:05:28Z brain $", VF_COMMON | VF_VENDOR, API_VERSION);
00144         }
00145 
00146         virtual ~ModuleChanFilter()
00147         {
00148                 ServerInstance->Modes->DelMode(cf);
00149                 delete cf;
00150                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
00151         }
00152 };
00153 
00154 MODULE_INIT(ModuleChanFilter)