summaryrefslogtreecommitdiff
path: root/src/modules/m_filter.h
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-11-10 17:54:14 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-11-10 17:54:14 +0000
commit9f477a1083574d01c78f12d95772ed122607a4ad (patch)
tree8294c89e61fe99079e31bfa55fe276c792b36eaf /src/modules/m_filter.h
parent6692d15462003157768a15c86192399b5b73e3c2 (diff)
Implement the /filter command. Note that this is currently untested, and propogation of filters between servers on burst isnt implemented yet (This is next on my todo)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5667 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_filter.h')
-rw-r--r--src/modules/m_filter.h200
1 files changed, 148 insertions, 52 deletions
diff --git a/src/modules/m_filter.h b/src/modules/m_filter.h
index b2c3816a8..bd6320e3f 100644
--- a/src/modules/m_filter.h
+++ b/src/modules/m_filter.h
@@ -36,79 +36,175 @@ class FilterResult : public classbase
}
};
+class cmd_filter;
+
class FilterBase : public Module
-{
+{
+ cmd_filter* filtcommand;
public:
- FilterBase(InspIRCd* Me)
- : Module::Module(Me)
- {
- }
-
- virtual ~FilterBase()
- {
- }
-
- virtual void Implements(char* List)
- {
- List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnRehash] = 1;
- }
+ FilterBase(InspIRCd* Me);
+ virtual ~FilterBase();
+ virtual void Implements(char* List);
+ virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status);
+ virtual FilterResult* FilterMatch(const std::string &text) = 0;
+ virtual bool DeleteFilter(const std::string &freeform) = 0;
+ virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration) = 0;
+ virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status);
+ virtual void OnRehash(const std::string &parameter);
+ virtual Version GetVersion();
+};
- virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
+class cmd_filter : public command_t
+{
+ FilterBase* Base;
+ public:
+ cmd_filter(FilterBase* f, InspIRCd* Me) : command_t(Me, "FILTER", 'o', 1), Base(f)
{
- return OnUserPreNotice(user,dest,target_type,text,status);
}
- /* This must be implemented by the module which uses the header */
- virtual FilterResult* FilterMatch(const std::string &text) = 0;
-
- virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
+ CmdResult Handle(const char** parameters, int pcnt, userrec *user)
{
- FilterResult* f = this->FilterMatch(text);
- if (f)
+ if (pcnt == 1)
{
- std::string target = "";
- if (target_type == TYPE_USER)
+ /* Deleting a filter */
+ if (Base->DeleteFilter(parameters[0]))
{
- userrec* t = (userrec*)dest;
- target = std::string(t->nick);
+ user->WriteServ("NOTICE %s :*** Deleted filter '%s'", user->nick, parameters[0]);
+ return CMD_SUCCESS;
}
- else if (target_type == TYPE_CHANNEL)
+ else
{
- chanrec* t = (chanrec*)dest;
- target = std::string(t->name);
+ user->WriteServ("NOTICE %s :*** Filter '%s' not found on list.", user->nick, parameters[0]);
+ return CMD_FAILURE;
}
- if (f->action == "block")
- {
- ServerInstance->WriteOpers(std::string("FILTER: ")+user->nick+" had their notice filtered, target was "+target+": "+f->reason);
- user->WriteServ("NOTICE "+std::string(user->nick)+" :Your notice has been filtered and opers notified: "+f->reason);
- }
- ServerInstance->Log(DEFAULT,"FILTER: "+std::string(user->nick)+std::string(" had their notice filtered, target was ")+target+": "+f->reason+" Action: "+f->action);
-
- if (f->action == "kill")
+ }
+ else
+ {
+ /* Adding a filter */
+ if (pcnt >= 3)
{
- userrec::QuitUser(ServerInstance,user,f->reason);
- }
+ std::string freeform = parameters[0];
+ std::string type = parameters[1];
+ std::string reason;
+ long duration = 0;
- if (f->action == "gline")
- {
- if (ServerInstance->XLines->add_gline(f->gline_time, ServerInstance->Config->ServerName, f->reason.c_str(), user->MakeHostIP()))
+ if ((type != "gline") && (type != "none") && (type != "block") && (type != "kill"))
+ {
+ user->WriteServ("NOTICE %s :*** Invalid filter type '%s'. Supported types are 'gline', 'none', 'block', and 'kill'.", user->nick, freeform.c_str());
+ return CMD_FAILURE;
+ }
+
+ if (type == "gline")
+ {
+ if (pcnt >= 4)
+ {
+ duration = ServerInstance->Duration(parameters[2]);
+ reason = parameters[3];
+ }
+ else
+ {
+ this->TooFewParams(user, " When setting a gline type filter, a gline duration must be specified as the third parameter.");
+ return CMD_FAILURE;
+ }
+ }
+ else
+ {
+ reason = parameters[2];
+ }
+ std::pair<bool, std::string> result = Base->AddFilter(freeform, type, reason, duration);
+ if (result.first)
+ {
+ user->WriteServ("NOTICE %s :*** Added filter '%s', type '%s%s%s', reason: '%s'", user->nick, freeform.c_str(),
+ (duration ? " duration: " : ""), (duration ? ConvToStr(duration).c_str() : ""),
+ reason.c_str());
+ return CMD_SUCCESS;
+ }
+ else
{
- ServerInstance->XLines->apply_lines(APPLY_GLINES);
- FOREACH_MOD(I_OnAddGLine,OnAddGLine(f->gline_time, NULL, f->reason, user->MakeHostIP()));
+ user->WriteServ("NOTICE %s :*** Filter '%s' could not be added: %s", user->nick, freeform.c_str(), result.second.c_str());
+ return CMD_FAILURE;
}
}
- return 1;
+ else
+ {
+ this->TooFewParams(user, ".");
+ return CMD_FAILURE;
+ }
+
}
- return 0;
}
- virtual void OnRehash(const std::string &parameter)
+ void TooFewParams(userrec* user, const std::string &extra_text)
{
+ user->WriteServ("NOTICE %s :*** Not enough parameters%s", user->nick, extra_text.c_str());
}
-
- virtual Version GetVersion()
+};
+
+FilterBase::FilterBase(InspIRCd* Me) : Module::Module(Me)
+{
+ filtcommand = new cmd_filter(this, Me);
+ ServerInstance->AddCommand(filtcommand);
+}
+
+FilterBase::~FilterBase()
+{
+}
+
+void FilterBase::Implements(char* List)
+{
+ List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnRehash] = 1;
+}
+
+int FilterBase::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
+{
+ return OnUserPreNotice(user,dest,target_type,text,status);
+}
+
+int FilterBase::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
+{
+ FilterResult* f = this->FilterMatch(text);
+ if (f)
{
- // This is version 2 because version 1.x is the unreleased unrealircd module
- return Version(1,1,0,2,VF_VENDOR,API_VERSION);
+ std::string target = "";
+ if (target_type == TYPE_USER)
+ {
+ userrec* t = (userrec*)dest;
+ target = std::string(t->nick);
+ }
+ else if (target_type == TYPE_CHANNEL)
+ {
+ chanrec* t = (chanrec*)dest;
+ target = std::string(t->name);
+ }
+ if (f->action == "block")
+ {
+ ServerInstance->WriteOpers(std::string("FILTER: ")+user->nick+" had their notice filtered, target was "+target+": "+f->reason);
+ user->WriteServ("NOTICE "+std::string(user->nick)+" :Your notice has been filtered and opers notified: "+f->reason);
+ }
+ ServerInstance->Log(DEFAULT,"FILTER: "+std::string(user->nick)+std::string(" had their notice filtered, target was ")+target+": "+f->reason+" Action: "+f->action);
+ if (f->action == "kill")
+ {
+ userrec::QuitUser(ServerInstance,user,f->reason);
+ }
+ if (f->action == "gline")
+ {
+ if (ServerInstance->XLines->add_gline(f->gline_time, ServerInstance->Config->ServerName, f->reason.c_str(), user->MakeHostIP()))
+ {
+ ServerInstance->XLines->apply_lines(APPLY_GLINES);
+ FOREACH_MOD(I_OnAddGLine,OnAddGLine(f->gline_time, NULL, f->reason, user->MakeHostIP()));
+ }
+ }
+ return 1;
}
-};
+ return 0;
+}
+
+void FilterBase::OnRehash(const std::string &parameter)
+{
+}
+
+Version FilterBase::GetVersion()
+{
+ return Version(1,1,0,2,VF_VENDOR,API_VERSION);
+}
+