diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-09-08 18:00:22 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-09-08 18:00:22 +0200 |
commit | a48e3a4d5c96555f5a8df8b25c9796ae9314ad1e (patch) | |
tree | 40b291c322ab824819272c663aa6800f7f21d218 /src | |
parent | ba7431b4fd6c62dd04d252e769e825769accb2a9 (diff) |
Change allocation of a few services to make use of auto registration
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_dccallow.cpp | 40 | ||||
-rw-r--r-- | src/modules/m_showwhois.cpp | 25 |
2 files changed, 28 insertions, 37 deletions
diff --git a/src/modules/m_dccallow.cpp b/src/modules/m_dccallow.cpp index c6cb09645..99952342b 100644 --- a/src/modules/m_dccallow.cpp +++ b/src/modules/m_dccallow.cpp @@ -51,12 +51,16 @@ typedef std::vector<DCCAllow> dccallowlist; dccallowlist* dl; typedef std::vector<BannedFileList> bannedfilelist; bannedfilelist bfl; -SimpleExtItem<dccallowlist>* ext; +typedef SimpleExtItem<dccallowlist> DCCAllowExt; class CommandDccallow : public Command { + DCCAllowExt& ext; + public: - CommandDccallow(Module* parent) : Command(parent, "DCCALLOW", 0) + CommandDccallow(Module* parent, DCCAllowExt& Ext) + : Command(parent, "DCCALLOW", 0) + , ext(Ext) { syntax = "{[+|-]<nick> <time>|HELP|LIST}"; /* XXX we need to fix this so it can work with translation stuff (i.e. move +- into a seperate param */ @@ -106,7 +110,7 @@ class CommandDccallow : public Command if (action == '-') { // check if it contains any entries - dl = ext->get(user); + dl = ext.get(user); if (dl) { for (dccallowlist::iterator i = dl->begin(); i != dl->end(); ++i) @@ -129,11 +133,11 @@ class CommandDccallow : public Command return CMD_FAILURE; } - dl = ext->get(user); + dl = ext.get(user); if (!dl) { dl = new dccallowlist; - ext->set(user, dl); + ext.set(user, dl); // add this user to the userlist ul.push_back(user); } @@ -228,7 +232,7 @@ class CommandDccallow : public Command // display current DCCALLOW list user->WriteNumeric(990, "%s :Users on your DCCALLOW list:", user->nick.c_str()); - dl = ext->get(user); + dl = ext.get(user); if (dl) { for (dccallowlist::const_iterator c = dl->begin(); c != dl->end(); ++c) @@ -244,24 +248,19 @@ class CommandDccallow : public Command class ModuleDCCAllow : public Module { + DCCAllowExt ext; CommandDccallow cmd; public: ModuleDCCAllow() - : cmd(this) - { - ext = NULL; - } - - void init() CXX11_OVERRIDE + : ext("dccallow", this) + , cmd(this, ext) { - ext = new SimpleExtItem<dccallowlist>("dccallow", this); - ServerInstance->Modules->AddService(*ext); } void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message) CXX11_OVERRIDE { - dccallowlist* udl = ext->get(user); + dccallowlist* udl = ext.get(user); // remove their DCCALLOW list if they have one if (udl) @@ -303,7 +302,7 @@ class ModuleDCCAllow : public Module if (strncmp(text.c_str(), "\1DCC ", 5) == 0) { - dl = ext->get(u); + dl = ext.get(u); if (dl && dl->size()) { for (dccallowlist::const_iterator iter = dl->begin(); iter != dl->end(); ++iter) @@ -372,7 +371,7 @@ class ModuleDCCAllow : public Module for (userlist::iterator iter = ul.begin(); iter != ul.end();) { User* u = (User*)(*iter); - dl = ext->get(u); + dl = ext.get(u); if (dl) { if (dl->size()) @@ -406,7 +405,7 @@ class ModuleDCCAllow : public Module for (userlist::iterator iter = ul.begin(); iter != ul.end();) { User *u = (User*)(*iter); - dl = ext->get(u); + dl = ext.get(u); if (dl) { if (dl->size()) @@ -459,11 +458,6 @@ class ModuleDCCAllow : public Module } } - ~ModuleDCCAllow() - { - delete ext; - } - Version GetVersion() CXX11_OVERRIDE { return Version("Provides support for the /DCCALLOW command", VF_COMMON | VF_VENDOR); diff --git a/src/modules/m_showwhois.cpp b/src/modules/m_showwhois.cpp index bedaf6236..96d8d90cf 100644 --- a/src/modules/m_showwhois.cpp +++ b/src/modules/m_showwhois.cpp @@ -28,9 +28,14 @@ class SeeWhois : public SimpleUserModeHandler { public: - SeeWhois(Module* Creator, bool IsOpersOnly) : SimpleUserModeHandler(Creator, "showwhois", 'W') + SeeWhois(Module* Creator) + : SimpleUserModeHandler(Creator, "showwhois", 'W') { - oper = IsOpersOnly; + } + + void SetOperOnly(bool operonly) + { + oper = operonly; } }; @@ -67,13 +72,13 @@ class WhoisNoticeCmd : public Command class ModuleShowwhois : public Module { bool ShowWhoisFromOpers; - SeeWhois* sw; + SeeWhois sw; WhoisNoticeCmd cmd; public: ModuleShowwhois() - : sw(NULL), cmd(this) + : sw(this), cmd(this) { } @@ -81,16 +86,8 @@ class ModuleShowwhois : public Module { ConfigTag* tag = ServerInstance->Config->ConfValue("showwhois"); - bool OpersOnly = tag->getBool("opersonly", true); + sw.SetOperOnly(tag->getBool("opersonly", true)); ShowWhoisFromOpers = tag->getBool("showfromopers", true); - - sw = new SeeWhois(this, OpersOnly); - ServerInstance->Modules->AddService(*sw); - } - - ~ModuleShowwhois() - { - delete sw; } Version GetVersion() CXX11_OVERRIDE @@ -100,7 +97,7 @@ class ModuleShowwhois : public Module void OnWhois(User* source, User* dest) CXX11_OVERRIDE { - if (!dest->IsModeSet(*sw) || source == dest) + if (!dest->IsModeSet(sw) || source == dest) return; if (!ShowWhoisFromOpers && source->IsOper()) |