m_banexception.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015 #include "u_listmode.h"
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00031 class BanException : public ListModeBase
00032 {
00033 public:
00034 BanException(InspIRCd* Instance) : ListModeBase(Instance, 'e', "End of Channel Exception List", 348, 349, true) { }
00035 };
00036
00037
00038 class ModuleBanException : public Module
00039 {
00040 BanException* be;
00041
00042
00043 public:
00044 ModuleBanException(InspIRCd* Me) : Module(Me)
00045 {
00046 be = new BanException(ServerInstance);
00047 if (!ServerInstance->Modes->AddMode(be))
00048 throw ModuleException("Could not add new modes!");
00049 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
00050
00051 be->DoImplements(this);
00052 Implementation list[] = { I_OnRehash, I_OnRequest, I_On005Numeric, I_OnCheckBan, I_OnCheckExtBan, I_OnCheckStringExtBan };
00053 Me->Modules->Attach(list, this, 6);
00054
00055 }
00056
00057 virtual void On005Numeric(std::string &output)
00058 {
00059 output.append(" EXCEPTS=e");
00060 }
00061
00062 virtual int OnCheckExtBan(User *user, Channel *chan, char type)
00063 {
00064 if (chan != NULL)
00065 {
00066 modelist *list;
00067 chan->GetExt(be->GetInfoKey(), list);
00068
00069 if (!list)
00070 return 0;
00071
00072 std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
00073 for (modelist::iterator it = list->begin(); it != list->end(); it++)
00074 {
00075 if (it->mask[0] != type || it->mask[1] != ':')
00076 continue;
00077
00078 std::string maskptr = it->mask.substr(2);
00079
00080 if (InspIRCd::Match(user->GetFullRealHost(), maskptr) || InspIRCd::Match(user->GetFullHost(), maskptr) || (InspIRCd::MatchCIDR(mask, maskptr)))
00081 {
00082
00083 return 1;
00084 }
00085 }
00086 }
00087
00088 return 0;
00089 }
00090
00091 virtual int OnCheckStringExtBan(const std::string &str, Channel *chan, char type)
00092 {
00093 if (chan != NULL)
00094 {
00095 modelist *list;
00096 chan->GetExt(be->GetInfoKey(), list);
00097
00098 if (!list)
00099 return 0;
00100 for (modelist::iterator it = list->begin(); it != list->end(); it++)
00101 {
00102 if (it->mask[0] != type || it->mask[1] != ':')
00103 continue;
00104
00105 std::string maskptr = it->mask.substr(2);
00106 if (InspIRCd::Match(str, maskptr))
00107 return 1;
00108 }
00109 }
00110
00111 return 0;
00112 }
00113
00114 virtual int OnCheckBan(User* user, Channel* chan)
00115 {
00116 if (chan != NULL)
00117 {
00118 modelist* list;
00119 chan->GetExt(be->GetInfoKey(), list);
00120
00121 if (!list)
00122 {
00123
00124 return 0;
00125 }
00126
00127 std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
00128 for (modelist::iterator it = list->begin(); it != list->end(); it++)
00129 {
00130 if (InspIRCd::Match(user->GetFullRealHost(), it->mask) || InspIRCd::Match(user->GetFullHost(), it->mask) || (InspIRCd::MatchCIDR(mask, it->mask)))
00131 {
00132
00133 return 1;
00134 }
00135 }
00136 }
00137 return 0;
00138 }
00139
00140 virtual void OnCleanup(int target_type, void* item)
00141 {
00142 be->DoCleanup(target_type, item);
00143 }
00144
00145 virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
00146 {
00147 be->DoSyncChannel(chan, proto, opaque);
00148 }
00149
00150 virtual void OnChannelDelete(Channel* chan)
00151 {
00152 be->DoChannelDelete(chan);
00153 }
00154
00155 virtual void OnRehash(User* user, const std::string ¶m)
00156 {
00157 be->DoRehash();
00158 }
00159
00160 virtual const char* OnRequest(Request* request)
00161 {
00162 return be->DoOnRequest(request);
00163 }
00164
00165 virtual Version GetVersion()
00166 {
00167 return Version("$Id: m_banexception.cpp 10407 2008-09-06 13:04:26Z brain $", VF_COMMON | VF_VENDOR, API_VERSION);
00168 }
00169
00170 virtual ~ModuleBanException()
00171 {
00172 ServerInstance->Modes->DelMode(be);
00173 delete be;
00174 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
00175 }
00176 };
00177
00178 MODULE_INIT(ModuleBanException)