core/ConCmdManager.cpp
changeset 1584 8158e9eafff5
parent 1544 feff70182207
child 1902 ce912ad912a5
     1.1 --- a/core/ConCmdManager.cpp	Tue Oct 16 01:29:28 2007 +0000
     1.2 +++ b/core/ConCmdManager.cpp	Tue Oct 16 05:30:41 2007 +0000
     1.3 @@ -85,6 +85,60 @@
     1.4  	g_RootMenu.RemoveRootConsoleCommand("cmds", this);
     1.5  }
     1.6  
     1.7 +void ConCmdManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe)
     1.8 +{
     1.9 +	/* Whoa, first get its information struct */
    1.10 +	ConCmdInfo *pInfo;
    1.11 +
    1.12 +	if (!sm_trie_retrieve(m_pCmds, name, (void **)&pInfo))
    1.13 +	{
    1.14 +		return;
    1.15 +	}
    1.16 +
    1.17 +	RemoveConCmds(pInfo->srvhooks);
    1.18 +	RemoveConCmds(pInfo->conhooks);
    1.19 +
    1.20 +	RemoveConCmd(pInfo, name, is_read_safe, false);
    1.21 +}
    1.22 +
    1.23 +void ConCmdManager::RemoveConCmds(List<CmdHook *> &cmdlist)
    1.24 +{
    1.25 +	List<CmdHook *>::iterator iter = cmdlist.begin();
    1.26 +
    1.27 +	while (iter != cmdlist.end())
    1.28 +	{
    1.29 +		CmdHook *pHook = (*iter);
    1.30 +		IPluginContext *pContext = pHook->pf->GetParentContext();
    1.31 +		IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext());
    1.32 +		CmdList *pList = NULL;
    1.33 +		
    1.34 +		//gaben
    1.35 +		if (!pPlugin->GetProperty("CommandList", (void **)&pList, false) || !pList)
    1.36 +		{
    1.37 +			continue;
    1.38 +		}
    1.39 +
    1.40 +		CmdList::iterator p_iter = pList->begin();
    1.41 +		while (p_iter != pList->end())
    1.42 +		{
    1.43 +			PlCmdInfo &cmd = (*p_iter);
    1.44 +			if (cmd.pHook == pHook)
    1.45 +			{
    1.46 +				p_iter = pList->erase(p_iter);
    1.47 +			}
    1.48 +			else
    1.49 +			{
    1.50 +				p_iter++;
    1.51 +			}
    1.52 +		}
    1.53 +
    1.54 +		delete pHook->pAdmin;
    1.55 +		delete pHook;
    1.56 +		
    1.57 +		iter = cmdlist.erase(iter);
    1.58 +	}
    1.59 +}
    1.60 +
    1.61  void ConCmdManager::RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext)
    1.62  {
    1.63  	List<CmdHook *>::iterator iter = cmdlist.begin();
    1.64 @@ -98,7 +152,9 @@
    1.65  			delete pHook->pAdmin;
    1.66  			delete pHook;
    1.67  			iter = cmdlist.erase(iter);
    1.68 -		} else {
    1.69 +		}
    1.70 +		else
    1.71 +		{
    1.72  			iter++;
    1.73  		}
    1.74  	}
    1.75 @@ -143,7 +199,7 @@
    1.76  			}
    1.77  
    1.78  			/* Remove the command, it should be safe now */
    1.79 -			RemoveConCmd(pInfo);
    1.80 +			RemoveConCmd(pInfo, pInfo->pCmd->GetName(), true, true);
    1.81  			removed.push_back(pInfo);
    1.82  		}
    1.83  		delete pList;
    1.84 @@ -516,7 +572,9 @@
    1.85  	{
    1.86  		grpid = m_Strings.AddString(group);
    1.87  		sm_trie_insert(m_pCmdGrps, group, (void *)grpid);
    1.88 -	} else {
    1.89 +	}
    1.90 +	else
    1.91 +	{
    1.92  		grpid = (int)object;
    1.93  	}
    1.94  
    1.95 @@ -691,7 +749,9 @@
    1.96  			}
    1.97  		}
    1.98  		pInfo->is_admin_set = true;
    1.99 -	} else if (type == Override_CommandGroup) {
   1.100 +	}
   1.101 +	else if (type == Override_CommandGroup)
   1.102 +	{
   1.103  		void *object;
   1.104  		if (!sm_trie_retrieve(m_pCmdGrps, cmd, &object))
   1.105  		{
   1.106 @@ -726,16 +786,16 @@
   1.107  	}
   1.108  }
   1.109  
   1.110 -void ConCmdManager::RemoveConCmd(ConCmdInfo *info)
   1.111 +void ConCmdManager::RemoveConCmd(ConCmdInfo *info, const char *name, bool is_read_safe, bool untrack)
   1.112  {
   1.113 +	/* Remove from the trie */
   1.114 +	sm_trie_delete(m_pCmds, name);
   1.115 +
   1.116  	/* Remove console-specific information
   1.117  	 * This should always be true as of right now
   1.118  	 */
   1.119  	if (info->pCmd)
   1.120  	{
   1.121 -		/* Remove from the trie */
   1.122 -		sm_trie_delete(m_pCmds, info->pCmd->GetName());
   1.123 -
   1.124  		if (info->sourceMod)
   1.125  		{
   1.126  			/* Unlink from SourceMM */
   1.127 @@ -746,9 +806,18 @@
   1.128  			delete [] new_help;
   1.129  			delete [] new_name;
   1.130  			delete info->pCmd;
   1.131 -		} else {
   1.132 -			/* Remove the external hook */
   1.133 -			SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, info->pCmd, CommandCallback, false);
   1.134 +		}
   1.135 +		else
   1.136 +		{
   1.137 +			if (is_read_safe)
   1.138 +			{
   1.139 +				/* Remove the external hook */
   1.140 +				SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, info->pCmd, CommandCallback, false);
   1.141 +			}
   1.142 +			if (untrack)
   1.143 +			{
   1.144 +				UntrackConCommandBase(info->pCmd, this);
   1.145 +			}
   1.146  		}
   1.147  	}
   1.148  	
   1.149 @@ -822,7 +891,10 @@
   1.150  			char *new_help = sm_strdup(description);
   1.151  			pCmd = new ConCommand(new_name, CommandCallback, new_help, flags);
   1.152  			pInfo->sourceMod = true;
   1.153 -		} else {
   1.154 +		}
   1.155 +		else
   1.156 +		{
   1.157 +			TrackConCommandBase(pCmd, this);
   1.158  			SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pCmd, CommandCallback, false);
   1.159  		}
   1.160  
   1.161 @@ -880,16 +952,22 @@
   1.162  			if (cmd.type == Cmd_Server)
   1.163  			{
   1.164  				type = "server";
   1.165 -			} else if (cmd.type == Cmd_Console) {
   1.166 +			}
   1.167 +			else if (cmd.type == Cmd_Console)
   1.168 +			{
   1.169  				type = "console";
   1.170 -			} else if (cmd.type == Cmd_Admin) {
   1.171 +			}
   1.172 +			else if (cmd.type == Cmd_Admin)
   1.173 +			{
   1.174  				type = "admin";
   1.175  			}
   1.176  			name = cmd.pInfo->pCmd->GetName();
   1.177  			if (cmd.pHook->helptext.size())
   1.178  			{
   1.179  				help = cmd.pHook->helptext.c_str();
   1.180 -			} else {
   1.181 +			}
   1.182 +			else
   1.183 +			{
   1.184  				help = cmd.pInfo->pCmd->GetHelpText();
   1.185  			}
   1.186  			g_RootMenu.ConsolePrint("  %-17.16s %-12.11s %s", name, type, help);