summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-12 23:41:22 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-12 23:41:22 +0000
commitb4b66ad9600ff64b62bbfeabc8dc2579918b77b3 (patch)
tree1ec04b8db9ab237862ed73aacf72e13c43dc1a3d
parent69e28c67dddd8b74ee4c321667d286111e09e5da (diff)
Write out the permchannels database on a timer, not on every mode change
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12446 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/modules/m_permchannels.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/modules/m_permchannels.cpp b/src/modules/m_permchannels.cpp
index a3d023ffe..e81ac3a7c 100644
--- a/src/modules/m_permchannels.cpp
+++ b/src/modules/m_permchannels.cpp
@@ -119,9 +119,6 @@ class PermChannel : public ModeHandler
if (!channel->IsModeSet('P'))
{
channel->SetMode('P',true);
-
- // Save permchannels db if needed.
- WriteDatabase();
return MODEACTION_ALLOW;
}
}
@@ -153,9 +150,6 @@ class PermChannel : public ModeHandler
/* for servers, remove +P (to avoid desyncs) but don't bother trying to delete. */
channel->SetMode('P',false);
-
- // Save permchannels db if needed.
- WriteDatabase();
return MODEACTION_ALLOW;
}
}
@@ -167,14 +161,18 @@ class PermChannel : public ModeHandler
class ModulePermanentChannels : public Module
{
PermChannel p;
+ bool dirty;
public:
- ModulePermanentChannels() : p(this)
+ ModulePermanentChannels() : p(this), dirty(false)
+ {
+ }
+
+ void init()
{
- if (!ServerInstance->Modes->AddMode(&p))
- throw ModuleException("Could not add new modes!");
- Implementation eventlist[] = { I_OnChannelPreDelete, I_OnPostTopicChange, I_OnRawMode, I_OnRehash };
- ServerInstance->Modules->Attach(eventlist, this, 4);
+ ServerInstance->Modes->AddService(p);
+ Implementation eventlist[] = { I_OnChannelPreDelete, I_OnPostTopicChange, I_OnRawMode, I_OnRehash, I_OnBackgroundTimer };
+ ServerInstance->Modules->Attach(eventlist, this, 5);
OnRehash(NULL);
}
@@ -276,8 +274,8 @@ public:
virtual ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string &param, bool adding, int pcnt)
{
- if (chan && chan->IsModeSet('P'))
- WriteDatabase();
+ if (chan && (chan->IsModeSet('P') || mode == 'P'))
+ dirty = true;
return MOD_RES_PASSTHRU;
}
@@ -285,7 +283,14 @@ public:
virtual void OnPostTopicChange(User*, Channel *c, const std::string&)
{
if (c->IsModeSet('P'))
+ dirty = true;
+ }
+
+ void OnBackgroundTimer(time_t)
+ {
+ if (dirty)
WriteDatabase();
+ dirty = false;
}
virtual Version GetVersion()