Added the ability to override RegConsoleCommand-created commands (bug 5199, r=psychonic).
authorAsher Baker <asherkin@gmail.com>
Thu Nov 15 17:53:11 2012 +0000 (2012-11-15)
changeset 3687d0b1262dbc03
parent 3686 d7954e074526
child 3689 514c846f5573
Added the ability to override RegConsoleCommand-created commands (bug 5199, r=psychonic).
core/ConCmdManager.cpp
core/ConCmdManager.h
core/smn_console.cpp
     1.1 --- a/core/ConCmdManager.cpp	Thu Nov 15 17:50:11 2012 +0000
     1.2 +++ b/core/ConCmdManager.cpp	Thu Nov 15 17:53:11 2012 +0000
     1.3 @@ -559,44 +559,6 @@
     1.4  	return false;
     1.5  }
     1.6  
     1.7 -bool ConCmdManager::AddConsoleCommand(IPluginFunction *pFunction, 
     1.8 -									   const char *name, 
     1.9 -									   const char *description, 
    1.10 -									   int flags)
    1.11 -{
    1.12 -	ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags);
    1.13 -
    1.14 -	if (!pInfo)
    1.15 -	{
    1.16 -		return false;
    1.17 -	}
    1.18 -
    1.19 -	CmdHook *pHook = new CmdHook();
    1.20 -
    1.21 -	pHook->pf = pFunction;
    1.22 -	if (description && description[0])
    1.23 -	{
    1.24 -		pHook->helptext.assign(description);
    1.25 -	}
    1.26 -	pInfo->conhooks.push_back(pHook);
    1.27 -
    1.28 -	/* Add to the plugin */
    1.29 -	CmdList *pList;
    1.30 -	IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext());
    1.31 -	if (!pPlugin->GetProperty("CommandList", (void **)&pList))
    1.32 -	{
    1.33 -		pList = new CmdList();
    1.34 -		pPlugin->SetProperty("CommandList", pList);
    1.35 -	}
    1.36 -	PlCmdInfo info;
    1.37 -	info.pInfo = pInfo;
    1.38 -	info.type = Cmd_Console;
    1.39 -	info.pHook = pHook;
    1.40 -	AddToPlCmdList(pList, info);
    1.41 -
    1.42 -	return true;
    1.43 -}
    1.44 -
    1.45  bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction, 
    1.46  									 const char *name, 
    1.47  									 const char *group,
    1.48 @@ -658,7 +620,6 @@
    1.49  	/* Finally, add the hook */
    1.50  	pInfo->conhooks.push_back(pHook);
    1.51  	pInfo->admin = *(pHook->pAdmin);
    1.52 -	pInfo->is_admin_set = true;
    1.53  
    1.54  	/* Now add to the plugin */
    1.55  	CmdList *pList;
    1.56 @@ -803,7 +764,6 @@
    1.57  				pInfo->admin = *(pHook->pAdmin);
    1.58  			}
    1.59  		}
    1.60 -		pInfo->is_admin_set = true;
    1.61  	}
    1.62  	else if (type == Override_CommandGroup)
    1.63  	{
    1.64 @@ -837,7 +797,6 @@
    1.65  				}
    1.66  			}
    1.67  		}
    1.68 -		pInfo->is_admin_set = true;
    1.69  	}
    1.70  }
    1.71  
    1.72 @@ -905,7 +864,7 @@
    1.73  
    1.74  	*pFlags = pInfo->admin.eflags;
    1.75  
    1.76 -	return pInfo->is_admin_set;
    1.77 +	return true;
    1.78  }
    1.79  
    1.80  ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *description, int flags)
    1.81 @@ -942,7 +901,6 @@
    1.82  		}
    1.83  
    1.84  		pInfo->pCmd = pCmd;
    1.85 -		pInfo->is_admin_set = false;
    1.86  
    1.87  		sm_trie_insert(m_pCmds, name, pInfo);
    1.88  		AddToCmdList(pInfo);
    1.89 @@ -995,13 +953,9 @@
    1.90  			{
    1.91  				type = "server";
    1.92  			}
    1.93 -			else if (cmd.type == Cmd_Console)
    1.94 -			{
    1.95 -				type = "console";
    1.96 -			}
    1.97  			else if (cmd.type == Cmd_Admin)
    1.98  			{
    1.99 -				type = "admin";
   1.100 +				type = (cmd.pInfo->admin.eflags == 0)?"console":"admin";
   1.101  			}
   1.102  			name = cmd.pInfo->pCmd->GetName();
   1.103  			if (cmd.pHook->helptext.size())
     2.1 --- a/core/ConCmdManager.h	Thu Nov 15 17:50:11 2012 +0000
     2.2 +++ b/core/ConCmdManager.h	Thu Nov 15 17:53:11 2012 +0000
     2.3 @@ -48,7 +48,6 @@
     2.4  enum CmdType
     2.5  {
     2.6  	Cmd_Server,
     2.7 -	Cmd_Console,
     2.8  	Cmd_Admin,
     2.9  };
    2.10  
    2.11 @@ -89,7 +88,6 @@
    2.12  	List<CmdHook *> srvhooks;		/**< Hooks as a server command */
    2.13  	List<CmdHook *> conhooks;		/**< Hooks as a console command */
    2.14  	AdminCmdInfo admin;				/**< Admin info, if any */
    2.15 -	bool is_admin_set;				/**< Whether or not admin info is set */
    2.16  };
    2.17  
    2.18  typedef List<ConCmdInfo *> ConCmdList;
    2.19 @@ -119,7 +117,6 @@
    2.20  	void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe);
    2.21  public:
    2.22  	bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
    2.23 -	bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
    2.24  	bool AddAdminCommand(IPluginFunction *pFunction, 
    2.25  						 const char *name, 
    2.26  						 const char *group,
     3.1 --- a/core/smn_console.cpp	Thu Nov 15 17:50:11 2012 +0000
     3.2 +++ b/core/smn_console.cpp	Thu Nov 15 17:53:11 2012 +0000
     3.3 @@ -722,7 +722,9 @@
     3.4  		return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
     3.5  	}
     3.6  
     3.7 -	if (!g_ConCmds.AddConsoleCommand(pFunction, name, help, params[4]))
     3.8 +	CPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext());
     3.9 +	const char *group = pPlugin->GetFilename();
    3.10 +	if (!g_ConCmds.AddAdminCommand(pFunction, name, group, 0, help, params[4]))
    3.11  	{
    3.12  		return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
    3.13  	}