Remove memtables from ConCmdManager (bug 5899 part 3, r=fyren).
This commit is contained in:
parent
ba927964c8
commit
67ce8aff61
@ -38,6 +38,8 @@
|
||||
#include "ChatTriggers.h"
|
||||
#include "logic_bridge.h"
|
||||
|
||||
using namespace ke;
|
||||
|
||||
ConCmdManager g_ConCmds;
|
||||
|
||||
#if SOURCE_ENGINE == SE_DOTA
|
||||
@ -53,7 +55,7 @@ SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, false, int
|
||||
typedef ke::LinkedList<CmdHook *> PluginHookList;
|
||||
void RegisterInPlugin(CmdHook *hook);
|
||||
|
||||
ConCmdManager::ConCmdManager() : m_Strings(1024)
|
||||
ConCmdManager::ConCmdManager()
|
||||
{
|
||||
m_CmdClient = 0;
|
||||
}
|
||||
@ -105,6 +107,9 @@ void ConCmdManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *na
|
||||
}
|
||||
}
|
||||
|
||||
if (hook->admin)
|
||||
hook->admin->group->hooks.remove(hook);
|
||||
|
||||
iter = pInfo->hooks.erase(iter);
|
||||
delete hook;
|
||||
}
|
||||
@ -124,6 +129,8 @@ void ConCmdManager::OnPluginDestroyed(IPlugin *plugin)
|
||||
CmdHook *hook = *iter;
|
||||
|
||||
hook->info->hooks.remove(hook);
|
||||
if (hook->admin)
|
||||
hook->admin->group->hooks.remove(hook);
|
||||
|
||||
if (hook->info->hooks.empty())
|
||||
RemoveConCmd(hook->info, hook->info->pCmd->GetName(), true, true);
|
||||
@ -450,19 +457,17 @@ bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
|
||||
if (!pInfo)
|
||||
return false;
|
||||
|
||||
CmdHook *pHook = new CmdHook(CmdHook::Client, pInfo, pFunction, description);
|
||||
|
||||
pHook->admin = new AdminCmdInfo();
|
||||
|
||||
int grpid;
|
||||
if (!m_CmdGrps.retrieve(group, &grpid))
|
||||
GroupMap::Insert i = m_CmdGrps.findForAdd(group);
|
||||
if (!i.found())
|
||||
{
|
||||
grpid = m_Strings.AddString(group);
|
||||
m_CmdGrps.insert(group, grpid);
|
||||
if (!m_CmdGrps.add(i, group))
|
||||
return false;
|
||||
i->value = NoAddRef(new CommandGroup());
|
||||
}
|
||||
Ref<CommandGroup> cmdgroup = i->value;
|
||||
|
||||
pHook->admin->cmdGrpId = grpid;
|
||||
pHook->admin->flags = adminflags;
|
||||
CmdHook *pHook = new CmdHook(CmdHook::Client, pInfo, pFunction, description);
|
||||
pHook->admin = new AdminCmdInfo(cmdgroup, adminflags);
|
||||
|
||||
/* First get the command group override, if any */
|
||||
bool override = g_Admins.GetCommandOverride(group,
|
||||
@ -482,6 +487,7 @@ bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
|
||||
pHook->admin->eflags = pHook->admin->flags;
|
||||
pInfo->eflags = pHook->admin->eflags;
|
||||
|
||||
cmdgroup->hooks.append(pHook);
|
||||
pInfo->hooks.append(pHook);
|
||||
RegisterInPlugin(pHook);
|
||||
return true;
|
||||
@ -586,27 +592,20 @@ void ConCmdManager::UpdateAdminCmdFlags(const char *cmd, OverrideType type, Flag
|
||||
}
|
||||
else if (type == Override_CommandGroup)
|
||||
{
|
||||
int grpid;
|
||||
if (!m_CmdGrps.retrieve(cmd, &grpid))
|
||||
GroupMap::Result r = m_CmdGrps.find(cmd);
|
||||
if (!r.found())
|
||||
return;
|
||||
|
||||
/* This is bad :( loop through all commands */
|
||||
List<ConCmdInfo *>::iterator iter;
|
||||
for (iter=m_CmdList.begin(); iter!=m_CmdList.end(); iter++)
|
||||
{
|
||||
ConCmdInfo *pInfo = *iter;
|
||||
for (CmdHookList::iterator citer = pInfo->hooks.begin(); citer != pInfo->hooks.end(); citer++)
|
||||
{
|
||||
CmdHook *hook = (*citer);
|
||||
if (!hook->admin || hook->admin->cmdGrpId != grpid)
|
||||
continue;
|
||||
Ref<CommandGroup> group(r->value);
|
||||
|
||||
if (remove)
|
||||
hook->admin->eflags = bits;
|
||||
else
|
||||
hook->admin->eflags = hook->admin->flags;
|
||||
pInfo->eflags = hook->admin->eflags;
|
||||
}
|
||||
for (PluginHookList::iterator iter = group->hooks.begin(); iter != group->hooks.end(); iter++)
|
||||
{
|
||||
CmdHook *hook = *iter;
|
||||
if (remove)
|
||||
hook->admin->eflags = bits;
|
||||
else
|
||||
hook->admin->eflags = hook->admin->flags;
|
||||
hook->info->eflags = hook->admin->eflags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include "sm_globals.h"
|
||||
#include "sourcemm_api.h"
|
||||
#include "ForwardSys.h"
|
||||
#include "sm_memtable.h"
|
||||
#include <sh_list.h>
|
||||
#include <sh_string.h>
|
||||
#include <IRootConsoleMenu.h>
|
||||
@ -45,24 +44,31 @@
|
||||
#include <am-utility.h>
|
||||
#include <am-inlinelist.h>
|
||||
#include <am-linkedlist.h>
|
||||
#include <am-refcounting.h>
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
struct CmdHook;
|
||||
struct ConCmdInfo;
|
||||
|
||||
struct CommandGroup : public ke::Refcounted<CommandGroup>
|
||||
{
|
||||
ke::LinkedList<CmdHook *> hooks;
|
||||
};
|
||||
|
||||
struct AdminCmdInfo
|
||||
{
|
||||
AdminCmdInfo()
|
||||
AdminCmdInfo(const ke::Ref<CommandGroup> &group, FlagBits flags)
|
||||
: group(group),
|
||||
flags(flags),
|
||||
eflags(0)
|
||||
{
|
||||
cmdGrpId = -1;
|
||||
flags = 0;
|
||||
eflags = 0;
|
||||
}
|
||||
int cmdGrpId; /* index into cmdgroup string table */
|
||||
ke::Ref<CommandGroup> group;
|
||||
FlagBits flags; /* default flags */
|
||||
FlagBits eflags; /* effective flags */
|
||||
};
|
||||
|
||||
struct ConCmdInfo;
|
||||
|
||||
struct CmdHook : public ke::InlineListNode<CmdHook>
|
||||
{
|
||||
enum Type {
|
||||
@ -166,11 +172,12 @@ public:
|
||||
return m_CmdList;
|
||||
}
|
||||
private:
|
||||
typedef StringHashMap<ke::Ref<CommandGroup> > GroupMap;
|
||||
|
||||
StringHashMap<ConCmdInfo *> m_Cmds; /* command lookup */
|
||||
StringHashMap<int> m_CmdGrps; /* command group lookup */
|
||||
GroupMap m_CmdGrps; /* command group map */
|
||||
ConCmdList m_CmdList; /* command list */
|
||||
int m_CmdClient; /* current client */
|
||||
BaseStringTable m_Strings; /* string table */
|
||||
};
|
||||
|
||||
extern ConCmdManager g_ConCmds;
|
||||
|
@ -58,6 +58,13 @@ class Newborn
|
||||
mutable T *thing_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static inline Newborn<T>
|
||||
NoAddRef(T *t)
|
||||
{
|
||||
return Newborn<T>(t);
|
||||
}
|
||||
|
||||
// When returning a value, we'd rather not be needlessly changing the refcount,
|
||||
// so we have a special type to use for returns.
|
||||
template <typename T>
|
||||
|
Loading…
Reference in New Issue
Block a user