00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015
00016
00017
00018 class NoCTCP : public ModeHandler
00019 {
00020 public:
00021 NoCTCP(InspIRCd* Instance) : ModeHandler(Instance, 'C', 0, 0, false, MODETYPE_CHANNEL, false) { }
00022
00023 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
00024 {
00025 if (adding)
00026 {
00027 if (!channel->IsModeSet('C'))
00028 {
00029 channel->SetMode('C',true);
00030 return MODEACTION_ALLOW;
00031 }
00032 }
00033 else
00034 {
00035 if (channel->IsModeSet('C'))
00036 {
00037 channel->SetMode('C',false);
00038 return MODEACTION_ALLOW;
00039 }
00040 }
00041
00042 return MODEACTION_DENY;
00043 }
00044 };
00045
00046 class ModuleNoCTCP : public Module
00047 {
00048
00049 NoCTCP* nc;
00050
00051 public:
00052
00053 ModuleNoCTCP(InspIRCd* Me)
00054 : Module(Me)
00055 {
00056
00057 nc = new NoCTCP(ServerInstance);
00058 if (!ServerInstance->Modes->AddMode(nc))
00059 throw ModuleException("Could not add new modes!");
00060 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
00061 ServerInstance->Modules->Attach(eventlist, this, 2);
00062 }
00063
00064 virtual ~ModuleNoCTCP()
00065 {
00066 ServerInstance->Modes->DelMode(nc);
00067 delete nc;
00068 }
00069
00070 virtual Version GetVersion()
00071 {
00072 return Version("$Id: m_noctcp.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_COMMON | VF_VENDOR, API_VERSION);
00073 }
00074
00075 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
00076 {
00077 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
00078 }
00079
00080 virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
00081 {
00082 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
00083 {
00084 Channel* c = (Channel*)dest;
00085
00086 if (CHANOPS_EXEMPT(ServerInstance, 'C') && c->GetStatus(user) == STATUS_OP)
00087 {
00088 return 0;
00089 }
00090
00091 if (c->IsModeSet('C') || c->IsExtBanned(user, 'C'))
00092 {
00093 if ((text.length()) && (text[0] == '\1'))
00094 {
00095 if (strncmp(text.c_str(),"\1ACTION ",8))
00096 {
00097 user->WriteNumeric(ERR_NOCTCPALLOWED, "%s %s :Can't send CTCP to channel (+C set)",user->nick.c_str(), c->name.c_str());
00098 return 1;
00099 }
00100 }
00101 }
00102 }
00103 return 0;
00104 }
00105
00106 virtual void On005Numeric(std::string &output)
00107 {
00108 ServerInstance->AddExtBanChar('C');
00109 }
00110 };
00111
00112 MODULE_INIT(ModuleNoCTCP)