From a09109f61286bcd50ec5b8aaf08b98dd9a3985c3 Mon Sep 17 00:00:00 2001 From: om Date: Sun, 9 Jul 2006 11:59:07 +0000 Subject: Okay..updates to u_listmode, general cleanups and add some virtual methods which subclasses can override to alter behaviour..all looking much nicer and more flexible now. Update m_chanfilter to use u_listmode, demonstrates most or all of the new features of it and looks a hell of a lot prettier :) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4201 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/u_listmode.h | 72 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/u_listmode.h b/include/u_listmode.h index f7d74a2c7..d30da1e5e 100644 --- a/include/u_listmode.h +++ b/include/u_listmode.h @@ -126,7 +126,7 @@ class ListModeBase : public ModeHandler { // Make one el = new modelist; - channel->Extend(infokey, (char*)el); + channel->Extend(infokey, el); } // Clean the mask up @@ -137,8 +137,10 @@ class ListModeBase : public ModeHandler { if(parameter == it->mask) { + /* Give a subclass a chance to error about this */ + TellAlreadyOnList(source, channel, parameter); + // it does, deny the change - parameter = ""; return MODEACTION_DENY; } } @@ -153,22 +155,44 @@ class ListModeBase : public ModeHandler maxsize = el->size(); if (maxsize < it->limit) { - // And now add the mask onto the list... - ListItem e; - e.mask = parameter; - e.nick = source->nick; - e.time = stringtime(); + /* Ok, it *could* be allowed, now give someone subclassing us + * a chance to validate the parameter. + * The param is passed by reference, so they can both modify it + * and tell us if we allow it or not. + * + * eg, the subclass could: + * 1) allow + * 2) 'fix' parameter and then allow + * 3) deny + */ + if(ValidateParam(source, channel, parameter)) + { + // And now add the mask onto the list... + ListItem e; + e.mask = parameter; + e.nick = source->nick; + e.time = stringtime(); - el->push_back(e); - return MODEACTION_ALLOW; + el->push_back(e); + return MODEACTION_ALLOW; + } + else + { + /* If they deny it they have the job of giving an error message */ + return MODEACTION_DENY; + } } } } - // List is full - WriteServ(source->fd, "478 %s %s %s :Channel ban/ignore list is full", source->nick, channel->name, parameter.c_str()); + /* List is full, give subclass a chance to send a custom message */ + if(!TellListTooLong(source, channel, parameter)) + { + WriteServ(source->fd, "478 %s %s %s :Channel ban/ignore list is full", source->nick, channel->name, parameter.c_str()); + } + parameter = ""; - return MODEACTION_DENY; + return MODEACTION_DENY; } else { @@ -187,6 +211,11 @@ class ListModeBase : public ModeHandler } return MODEACTION_ALLOW; } + else + { + /* Tried to remove something that wasn't set */ + TellNotSet(source, channel, parameter); + } } parameter = ""; return MODEACTION_DENY; @@ -244,6 +273,25 @@ class ListModeBase : public ModeHandler } } } + + virtual bool ValidateParam(userrec* source, chanrec* channel, std::string ¶meter) + { + return true; + } + + virtual bool TellListTooLong(userrec* source, chanrec* channel, std::string ¶meter) + { + return false; + } + + virtual void TellAlreadyOnList(userrec* source, chanrec* channel, std::string ¶meter) + { + } + + virtual void TellNotSet(userrec* source, chanrec* channel, std::string ¶meter) + { + + } }; #endif -- cgit v1.2.3