fixed bug amb571 (FakeClientCommand having weird side effects)
authorDavid Anderson <dvander@alliedmods.net>
Wed Aug 15 17:14:48 2007 +0000 (2007-08-15)
changeset 13352047dc42d800
parent 1334 9db842b7a9fe
child 1336 a75b25f7cd9a
fixed bug amb571 (FakeClientCommand having weird side effects)
core/ConCmdManager.cpp
core/ConCmdManager.h
core/MenuStyle_Radio.cpp
core/MenuStyle_Radio.h
core/MenuStyle_Valve.cpp
core/MenuStyle_Valve.h
core/PlayerManager.cpp
     1.1 --- a/core/ConCmdManager.cpp	Wed Aug 15 16:21:28 2007 +0000
     1.2 +++ b/core/ConCmdManager.cpp	Wed Aug 15 17:14:48 2007 +0000
     1.3 @@ -155,11 +155,8 @@
     1.4  	m_CmdClient = client + 1;
     1.5  }
     1.6  
     1.7 -ResultType ConCmdManager::DispatchClientCommand(int client, ResultType type)
     1.8 +ResultType ConCmdManager::DispatchClientCommand(int client, const char *cmd, int args, ResultType type)
     1.9  {
    1.10 -	const char *cmd = engine->Cmd_Argv(0);
    1.11 -	int args = engine->Cmd_Argc() - 1;
    1.12 -
    1.13  	ConCmdInfo *pInfo;
    1.14  	if (sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))
    1.15  	{
     2.1 --- a/core/ConCmdManager.h	Wed Aug 15 16:21:28 2007 +0000
     2.2 +++ b/core/ConCmdManager.h	Wed Aug 15 17:14:48 2007 +0000
     2.3 @@ -115,7 +115,7 @@
     2.4  						 int adminflags,
     2.5  						 const char *description, 
     2.6  						 int flags);
     2.7 -	ResultType DispatchClientCommand(int client, ResultType type);
     2.8 +	ResultType DispatchClientCommand(int client, const char *cmd, int args, ResultType type);
     2.9  	void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits);
    2.10  	bool LookForSourceModCommand(const char *cmd);
    2.11  	bool CheckCommandAccess(int client, const char *cmd, FlagBits flags);
     3.1 --- a/core/MenuStyle_Radio.cpp	Wed Aug 15 16:21:28 2007 +0000
     3.2 +++ b/core/MenuStyle_Radio.cpp	Wed Aug 15 17:14:48 2007 +0000
     3.3 @@ -96,10 +96,8 @@
     3.4  	return (g_ShowMenuId != -1);
     3.5  }
     3.6  
     3.7 -bool CRadioStyle::OnClientCommand(int client)
     3.8 +bool CRadioStyle::OnClientCommand(int client, const char *cmd)
     3.9  {
    3.10 -	const char *cmd = engine->Cmd_Argv(0);
    3.11 -
    3.12  	if (strcmp(cmd, "menuselect") == 0)
    3.13  	{
    3.14  		if (!m_players[client].bInMenu)
     4.1 --- a/core/MenuStyle_Radio.h	Wed Aug 15 16:21:28 2007 +0000
     4.2 +++ b/core/MenuStyle_Radio.h	Wed Aug 15 17:14:48 2007 +0000
     4.3 @@ -70,7 +70,7 @@
     4.4  	void OnUserMessageSent(int msg_id);
     4.5  public:
     4.6  	bool IsSupported();
     4.7 -	bool OnClientCommand(int client);
     4.8 +	bool OnClientCommand(int client, const char *cmd);
     4.9  public:
    4.10  	CRadioDisplay *MakeRadioDisplay(CRadioMenu *menu=NULL);
    4.11  	void FreeRadioDisplay(CRadioDisplay *display);
     5.1 --- a/core/MenuStyle_Valve.cpp	Wed Aug 15 16:21:28 2007 +0000
     5.2 +++ b/core/MenuStyle_Valve.cpp	Wed Aug 15 17:14:48 2007 +0000
     5.3 @@ -53,10 +53,8 @@
     5.4  	return &m_players[client];
     5.5  }
     5.6  
     5.7 -bool ValveMenuStyle::OnClientCommand(int client)
     5.8 +bool ValveMenuStyle::OnClientCommand(int client, const char *cmd)
     5.9  {
    5.10 -	const char *cmd = engine->Cmd_Argv(0);
    5.11 -
    5.12  	if (strcmp(cmd, "sm_vmenuselect") == 0)
    5.13  	{
    5.14  		int key_press = atoi(engine->Cmd_Argv(1));
     6.1 --- a/core/MenuStyle_Valve.h	Wed Aug 15 16:21:28 2007 +0000
     6.2 +++ b/core/MenuStyle_Valve.h	Wed Aug 15 17:14:48 2007 +0000
     6.3 @@ -59,7 +59,7 @@
     6.4  {
     6.5  public:
     6.6  	ValveMenuStyle();
     6.7 -	bool OnClientCommand(int client);
     6.8 +	bool OnClientCommand(int client, const char *cmd);
     6.9  public: //BaseMenuStyle
    6.10  	CBaseMenuPlayer *GetMenuPlayer(int client);
    6.11  	void SendDisplay(int client, IMenuPanel *display);
     7.1 --- a/core/PlayerManager.cpp	Wed Aug 15 16:21:28 2007 +0000
     7.2 +++ b/core/PlayerManager.cpp	Wed Aug 15 17:14:48 2007 +0000
     7.3 @@ -535,23 +535,28 @@
     7.4  
     7.5  void PlayerManager::OnClientCommand(edict_t *pEntity)
     7.6  {
     7.7 +	/**
     7.8 +	 * We cache this because the engine is not re-entrant.
     7.9 +	 */
    7.10 +	char cmd[300];
    7.11 +	int args = engine->Cmd_Argc() - 1;
    7.12 +	strncopy(cmd, engine->Cmd_Argv(0), sizeof(cmd));
    7.13 +
    7.14  	int client = engine->IndexOfEdict(pEntity);
    7.15  	cell_t res = Pl_Continue;
    7.16  
    7.17 -	bool result = g_ValveMenuStyle.OnClientCommand(client);
    7.18 +	bool result = g_ValveMenuStyle.OnClientCommand(client, cmd);
    7.19  	if (result)
    7.20  	{
    7.21  		res = Pl_Handled;
    7.22  	} else {
    7.23 -		result = g_RadioMenuStyle.OnClientCommand(client);
    7.24 +		result = g_RadioMenuStyle.OnClientCommand(client, cmd);
    7.25  		if (result)
    7.26  		{
    7.27  			res = Pl_Handled;
    7.28  		}
    7.29  	}
    7.30  
    7.31 -	int args = engine->Cmd_Argc() - 1;
    7.32 -
    7.33  	cell_t res2 = Pl_Continue;
    7.34  	m_clcommand->PushCell(client);
    7.35  	m_clcommand->PushCell(args);
    7.36 @@ -567,7 +572,7 @@
    7.37  		RETURN_META(MRES_SUPERCEDE);
    7.38  	}
    7.39  
    7.40 -	res = g_ConCmds.DispatchClientCommand(client, (ResultType)res);
    7.41 +	res = g_ConCmds.DispatchClientCommand(client, cmd, args, (ResultType)res);
    7.42  
    7.43  	if (res >= Pl_Handled)
    7.44  	{