summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/modules.h9
-rw-r--r--src/mode.cpp9
-rw-r--r--src/modules.cpp2
-rw-r--r--src/modules/m_timedbans.cpp17
4 files changed, 35 insertions, 2 deletions
diff --git a/include/modules.h b/include/modules.h
index 9efb47670..120f17153 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -641,6 +641,15 @@ class Module : public classbase
*/
virtual void OnGlobalConnect(userrec* user);
+ /** Called whenever a ban is added to a channel's list.
+ * Return a non-zero value to 'eat' the mode change and prevent the ban from being added.
+ */
+ virtual int OnAddBan(userrec* source, chanrec* channel,std::string banmask);
+
+ /** Called whenever a ban is removed from a channel's list.
+ * Return a non-zero value to 'eat' the mode change and prevent the ban from being removed.
+ */
+ virtual int OnDelBan(userrec* source, chanrec* channel,std::string banmask);
};
diff --git a/src/mode.cpp b/src/mode.cpp
index e2eda1c82..65e42e875 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -470,6 +470,11 @@ char* add_ban(userrec *user,char *dest,chanrec *chan,int status)
log(DEBUG,"add_ban: %s %s",chan->name,user->nick);
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(OnAddBan(user,chan,dest));
+ if (MOD_RESULT)
+ return NULL;
+
TidyBan(dest);
for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
{
@@ -499,6 +504,10 @@ char* take_ban(userrec *user,char *dest,chanrec *chan,int status)
{
if (!strcasecmp(i->data,dest))
{
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(OnDelBan(user,chan,dest));
+ if (MOD_RESULT)
+ return NULL;
chan->bans.erase(i);
return dest;
}
diff --git a/src/modules.cpp b/src/modules.cpp
index 1ba2dbc8e..180830aa2 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -405,6 +405,8 @@ char* Module::OnRequest(Request* request) { return NULL; };
int Module::OnOperCompare(std::string password, std::string input) { return 0; };
void Module::OnGlobalOper(userrec* user) { };
void Module::OnGlobalConnect(userrec* user) { };
+int Module::OnAddBan(userrec* source, chanrec* channel,std::string banmask) { return 0; };
+int Module::OnDelBan(userrec* source, chanrec* channel,std::string banmask) { return 0; };
// server is a wrapper class that provides methods to all of the C-style
// exports in the core
diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp
index f75791b2c..8082831f0 100644
--- a/src/modules/m_timedbans.cpp
+++ b/src/modules/m_timedbans.cpp
@@ -108,6 +108,19 @@ class ModuleTimedBans : public Module
TimedBanList.clear();
}
+ virtual int OnDelBan(userrec* source, chanrec* chan, std::string banmask)
+ {
+ for (timedbans::iterator i = TimedBanList.begin(); i < TimedBanList.end(); i++)
+ {
+ if (!strcasecmp(banmask.c_str(),i->mask.c_str()))
+ {
+ TimedBanList.erase(i);
+ break;
+ }
+ }
+ return 0;
+ }
+
virtual void OnBackgroundTimer(time_t curtime)
{
bool again = true;
@@ -122,6 +135,7 @@ class ModuleTimedBans : public Module
again = true;
if (cr)
{
+ Srv->SendChannelServerNotice(Srv->GetServerName(),cr,"NOTICE "+std::string(cr->name)+" :Timed ban on "+i->mask+" expired.");
char *setban[3];
setban[0] = (char*)i->channel.c_str();
setban[1] = "-b";
@@ -135,9 +149,8 @@ class ModuleTimedBans : public Module
temp->fd = FD_MAGIC_NUMBER;
Srv->SendMode(setban,3,temp);
delete temp;
- Srv->SendChannelServerNotice(Srv->GetServerName(),cr,"NOTICE "+std::string(cr->name)+" :Timed ban on "+i->mask+" expired.");
}
- TimedBanList.erase(i);
+ // we used to delete the item here, but we dont need to as the servermode above does it for us,
break;
}
}