From b4b66ad9600ff64b62bbfeabc8dc2579918b77b3 Mon Sep 17 00:00:00 2001 From: danieldg Date: Fri, 12 Feb 2010 23:41:22 +0000 Subject: 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 --- src/modules/m_permchannels.cpp | 31 ++++++++++++++++++------------- 1 file 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 ¶m, 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() -- cgit v1.2.3