summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2015-11-26 13:36:44 +0100
committerAttila Molnar <attilamolnar@hush.com>2015-11-26 13:36:44 +0100
commitc290d09c454324614a93039364fe62a7b7b75cbb (patch)
tree6c68b27d78629dfe5fa8c5aa41b760e2e9e44b40 /src
parentbbc6a0bbbe7475e5e1d0c4f2418c6fe6e0e952b7 (diff)
Handle module reloading in core_reloadmodule entirely
Diffstat (limited to 'src')
-rw-r--r--src/coremods/core_reloadmodule.cpp42
-rw-r--r--src/modules.cpp28
-rw-r--r--src/modules/m_globalload.cpp25
3 files changed, 31 insertions, 64 deletions
diff --git a/src/coremods/core_reloadmodule.cpp b/src/coremods/core_reloadmodule.cpp
index 7f0f15e77..7bf762e64 100644
--- a/src/coremods/core_reloadmodule.cpp
+++ b/src/coremods/core_reloadmodule.cpp
@@ -34,21 +34,34 @@ class CommandReloadmodule : public Command
CmdResult Handle(const std::vector<std::string>& parameters, User *user);
};
-class ReloadModuleWorker : public HandlerBase1<void, bool>
+class ReloadAction : public HandlerBase0<void>
{
+ Module* const mod;
+ const std::string uuid;
+ const std::string passedname;
+
public:
- const std::string name;
- const std::string uid;
- ReloadModuleWorker(const std::string& uuid, const std::string& modn)
- : name(modn), uid(uuid) {}
- void Call(bool result)
+ ReloadAction(Module* m, const std::string& uid, const std::string& passedmodname)
+ : mod(m)
+ , uuid(uid)
+ , passedname(passedmodname)
+ {
+ }
+
+ void Call()
{
- ServerInstance->SNO->WriteGlobalSno('a', "RELOAD MODULE: %s %ssuccessfully reloaded",
- name.c_str(), result ? "" : "un");
- User* user = ServerInstance->FindNick(uid);
+ DLLManager* dll = mod->ModuleDLLManager;
+ std::string name = mod->ModuleSourceFile;
+ ServerInstance->Modules->DoSafeUnload(mod);
+ ServerInstance->GlobalCulls.Apply();
+ delete dll;
+ bool result = ServerInstance->Modules->Load(name);
+
+ ServerInstance->SNO->WriteGlobalSno('a', "RELOAD MODULE: %s %ssuccessfully reloaded", passedname.c_str(), result ? "" : "un");
+ User* user = ServerInstance->FindUUID(uuid);
if (user)
- user->WriteNumeric(RPL_LOADEDMODULE, "%s :Module %ssuccessfully reloaded.",
- name.c_str(), result ? "" : "un");
+ user->WriteNumeric(RPL_LOADEDMODULE, "%s :Module %ssuccessfully reloaded.", passedname.c_str(), result ? "" : "un");
+
ServerInstance->GlobalCulls.AddItem(this);
}
};
@@ -63,9 +76,12 @@ CmdResult CommandReloadmodule::Handle (const std::vector<std::string>& parameter
return CMD_FAILURE;
}
- if (m)
+ if (creator->dying)
+ return CMD_FAILURE;
+
+ if ((m) && (ServerInstance->Modules.CanUnload(m)))
{
- ServerInstance->Modules->Reload(m, (creator->dying ? NULL : new ReloadModuleWorker(user->uuid, parameters[0])));
+ ServerInstance->AtomicActions.AddAction(new ReloadAction(m, user->uuid, parameters[0]));
return CMD_SUCCESS;
}
else
diff --git a/src/modules.cpp b/src/modules.cpp
index 9e653a4ab..79a71652c 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -451,26 +451,6 @@ namespace
ServerInstance->GlobalCulls.AddItem(this);
}
};
-
- struct ReloadAction : public HandlerBase0<void>
- {
- Module* const mod;
- HandlerBase1<void, bool>* const callback;
- ReloadAction(Module* m, HandlerBase1<void, bool>* c)
- : mod(m), callback(c) {}
- void Call()
- {
- DLLManager* dll = mod->ModuleDLLManager;
- std::string name = mod->ModuleSourceFile;
- ServerInstance->Modules->DoSafeUnload(mod);
- ServerInstance->GlobalCulls.Apply();
- delete dll;
- bool rv = ServerInstance->Modules->Load(name);
- if (callback)
- callback->Call(rv);
- ServerInstance->GlobalCulls.AddItem(this);
- }
- };
}
bool ModuleManager::Unload(Module* mod)
@@ -481,14 +461,6 @@ bool ModuleManager::Unload(Module* mod)
return true;
}
-void ModuleManager::Reload(Module* mod, HandlerBase1<void, bool>* callback)
-{
- if (CanUnload(mod))
- ServerInstance->AtomicActions.AddAction(new ReloadAction(mod, callback));
- else if (callback)
- callback->Call(false);
-}
-
void ModuleManager::LoadAll()
{
std::map<std::string, ServiceList> servicemap;
diff --git a/src/modules/m_globalload.cpp b/src/modules/m_globalload.cpp
index a3f3242f0..294187fa5 100644
--- a/src/modules/m_globalload.cpp
+++ b/src/modules/m_globalload.cpp
@@ -116,25 +116,6 @@ class CommandGunloadmodule : public Command
}
};
-class GReloadModuleWorker : public HandlerBase1<void, bool>
-{
- public:
- const std::string nick;
- const std::string name;
- const std::string uid;
- GReloadModuleWorker(const std::string& usernick, const std::string& uuid, const std::string& modn)
- : nick(usernick), name(modn), uid(uuid) {}
- void Call(bool result)
- {
- ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBALLY RELOADED BY '%s'%s", name.c_str(), nick.c_str(), result ? "" : " (failed here)");
- User* user = ServerInstance->FindNick(uid);
- if (user)
- user->WriteNumeric(RPL_LOADEDMODULE, "%s :Module %ssuccessfully reloaded.",
- name.c_str(), result ? "" : "un");
- ServerInstance->GlobalCulls.AddItem(this);
- }
-};
-
/** Handle /GRELOADMODULE
*/
class CommandGreloadmodule : public Command
@@ -154,10 +135,8 @@ class CommandGreloadmodule : public Command
Module* m = ServerInstance->Modules->Find(parameters[0]);
if (m)
{
- GReloadModuleWorker* worker = NULL;
- if ((m != creator) && (!creator->dying))
- worker = new GReloadModuleWorker(user->nick, user->uuid, parameters[0]);
- ServerInstance->Modules->Reload(m, worker);
+ ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBALLY RELOADED BY '%s'", parameters[0].c_str(), user->nick.c_str());
+ ServerInstance->Parser.CallHandler("RELOADMODULE", parameters, user);
}
else
{