summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-09-02 15:50:29 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-09-02 15:50:29 +0000
commit7f9c5d0bb0aee8939a92c9003121c53c7a6d1057 (patch)
tree1d4619326f883fc94293b21f67cd8f540d92f35d /src
parent29fd51d6f76a639fbd909e7bf7489eb92e9f90db (diff)
Allow unloading of modules which implement modes!
The default implementation of the new system will remove simplemodes so any mode handler which is just a simple mode (no params and not a list mode) does not need to add much more than one line of code and remove its VF_STATIC flag. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5100 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/mode.cpp76
-rw-r--r--src/modules/m_operchans.cpp3
2 files changed, 78 insertions, 1 deletions
diff --git a/src/mode.cpp b/src/mode.cpp
index c1a39d625..5da96249f 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -588,6 +588,41 @@ bool ModeParser::AddMode(ModeHandler* mh, unsigned const char modeletter)
return true;
}
+bool ModeParser::DelMode(ModeHandler* mh)
+{
+ unsigned char mask = 0;
+ unsigned char pos = 0;
+
+ if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z'))
+ return false;
+
+ mh->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
+ pos = (mh->GetModeChar()-65) | mask;
+
+ if (!modehandlers[pos])
+ return false;
+
+ switch (mh->GetModeType())
+ {
+ case MODETYPE_USER:
+ for (user_hash::iterator i = ServerInstance->clientlist.begin(); i != ServerInstance->clientlist.end(); i++)
+ {
+ mh->RemoveMode(i->second);
+ }
+ break;
+ case MODETYPE_CHANNEL:
+ for (chan_hash::iterator i = ServerInstance->chanlist.begin(); i != ServerInstance->chanlist.end(); i++)
+ {
+ mh->RemoveMode(i->second);
+ }
+ break;
+ }
+
+ modehandlers[pos] = NULL;
+
+ return true;
+}
+
ModeHandler* ModeParser::FindMode(unsigned const char modeletter, ModeType mt)
{
unsigned char mask = 0;
@@ -816,6 +851,47 @@ bool ModeParser::DelModeWatcher(ModeWatcher* mw)
return true;
}
+/** This default implementation can remove simple user modes
+ */
+void ModeHandler::RemoveMode(userrec* user)
+{
+ char moderemove[MAXBUF];
+ const char* parameters[] = { user->nick, moderemove };
+
+ if (user->IsModeSet(this->GetModeChar()))
+ {
+ userrec* n = new userrec(ServerInstance);
+
+ sprintf(moderemove,"-%c",this->GetModeChar());
+ n->SetFd(FD_MAGIC_NUMBER);
+
+ ServerInstance->SendMode(parameters, 2, n);
+
+ delete n;
+ }
+}
+
+/** This default implementation can remove simple channel modes
+ * (no parameters)
+ */
+void ModeHandler::RemoveMode(chanrec* channel)
+{
+ char moderemove[MAXBUF];
+ const char* parameters[] = { channel->name, moderemove };
+
+ if (channel->IsModeSet(this->GetModeChar()))
+ {
+ userrec* n = new userrec(ServerInstance);
+
+ sprintf(moderemove,"-%c",this->GetModeChar());
+ n->SetFd(FD_MAGIC_NUMBER);
+
+ ServerInstance->SendMode(parameters, 2, n);
+
+ delete n;
+ }
+}
+
ModeParser::ModeParser(InspIRCd* Instance) : ServerInstance(Instance)
{
/* Clear mode list */
diff --git a/src/modules/m_operchans.cpp b/src/modules/m_operchans.cpp
index 7f3b989aa..03444ea1a 100644
--- a/src/modules/m_operchans.cpp
+++ b/src/modules/m_operchans.cpp
@@ -88,12 +88,13 @@ class ModuleOperChans : public Module
virtual ~ModuleOperChans()
{
+ ServerInstance->Modes->DelMode(oc);
DELETE(oc);
}
virtual Version GetVersion()
{
- return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
+ return Version(1,0,0,0,VF_VENDOR);
}
};