Update IPlugin reference on cmd hook removal (#1439)
This commit is contained in:
parent
ae485c3115
commit
99c39b1d57
@ -121,8 +121,13 @@ void ConCmdManager::OnPluginDestroyed(IPlugin *plugin)
|
|||||||
if (hook->admin)
|
if (hook->admin)
|
||||||
hook->admin->group->hooks.remove(hook);
|
hook->admin->group->hooks.remove(hook);
|
||||||
|
|
||||||
if (hook->info->hooks.empty())
|
if (hook->info->hooks.empty()) {
|
||||||
RemoveConCmd(hook->info, hook->info->pCmd->GetName(), true);
|
RemoveConCmd(hook->info, hook->info->pCmd->GetName(), true);
|
||||||
|
}
|
||||||
|
else { // update plugin reference to next hook in line
|
||||||
|
auto next = *hook->info->hooks.begin();
|
||||||
|
next->info->pPlugin = next->plugin;
|
||||||
|
}
|
||||||
|
|
||||||
iter = pList->erase(iter);
|
iter = pList->erase(iter);
|
||||||
delete hook;
|
delete hook;
|
||||||
@ -360,7 +365,7 @@ bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
|
|||||||
}
|
}
|
||||||
RefPtr<CommandGroup> cmdgroup = i->value;
|
RefPtr<CommandGroup> cmdgroup = i->value;
|
||||||
|
|
||||||
CmdHook *pHook = new CmdHook(CmdHook::Client, pInfo, pFunction, description);
|
CmdHook *pHook = new CmdHook(CmdHook::Client, pInfo, pFunction, description, pPlugin);
|
||||||
pHook->admin = std::make_unique<AdminCmdInfo>(cmdgroup, adminflags);
|
pHook->admin = std::make_unique<AdminCmdInfo>(cmdgroup, adminflags);
|
||||||
|
|
||||||
/* First get the command group override, if any */
|
/* First get the command group override, if any */
|
||||||
@ -399,7 +404,7 @@ bool ConCmdManager::AddServerCommand(IPluginFunction *pFunction,
|
|||||||
if (!pInfo)
|
if (!pInfo)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CmdHook *pHook = new CmdHook(CmdHook::Server, pInfo, pFunction, description);
|
CmdHook *pHook = new CmdHook(CmdHook::Server, pInfo, pFunction, description, pPlugin);
|
||||||
|
|
||||||
pInfo->hooks.append(pHook);
|
pInfo->hooks.append(pHook);
|
||||||
RegisterInPlugin(pHook);
|
RegisterInPlugin(pHook);
|
||||||
|
@ -80,10 +80,11 @@ struct CmdHook : public ke::InlineListNode<CmdHook>
|
|||||||
Client
|
Client
|
||||||
};
|
};
|
||||||
|
|
||||||
CmdHook(Type type, ConCmdInfo *cmd, IPluginFunction *fun, const char *description)
|
CmdHook(Type type, ConCmdInfo *cmd, IPluginFunction *fun, const char *description, IPlugin *plugin)
|
||||||
: type(type),
|
: type(type),
|
||||||
info(cmd),
|
info(cmd),
|
||||||
pf(fun),
|
pf(fun),
|
||||||
|
plugin(plugin),
|
||||||
helptext(description)
|
helptext(description)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -91,6 +92,7 @@ struct CmdHook : public ke::InlineListNode<CmdHook>
|
|||||||
Type type;
|
Type type;
|
||||||
ConCmdInfo *info;
|
ConCmdInfo *info;
|
||||||
IPluginFunction *pf; /* function hook */
|
IPluginFunction *pf; /* function hook */
|
||||||
|
IPlugin *plugin; /* owning plugin */
|
||||||
std::string helptext; /* help text */
|
std::string helptext; /* help text */
|
||||||
std::unique_ptr<AdminCmdInfo> admin; /* admin requirements, if any */
|
std::unique_ptr<AdminCmdInfo> admin; /* admin requirements, if any */
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user