Skip to content

Commit 943503a

Browse files
committed
Fix cvar getting
You can now get the cvar value by typing the variable names, as originally intended. Also, setting the cvar now works for the abnormal spacing of `key =value`.
1 parent 98423bb commit 943503a

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

Client/core/CClientVariables.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.0
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
55
* FILE: core/CClientVariables.h
66
* PURPOSE: Header file for client variable class
@@ -11,8 +11,7 @@
1111
*
1212
*****************************************************************************/
1313

14-
#ifndef __CCLIENTVARIABLES_H
15-
#define __CCLIENTVARIABLES_H
14+
#pragma once
1615

1716
#include <string>
1817
#include "CSingleton.h"
@@ -78,5 +77,3 @@ class CClientVariables : public CCVarsInterface, public CSingleton < CClientVari
7877
CXMLNode *m_pStorage;
7978
int m_iRevision;
8079
};
81-
82-
#endif

Client/core/CCommands.cpp

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -145,30 +145,42 @@ bool CCommands::Execute ( const char* szCommand, const char* szParametersIn, boo
145145
}
146146
}
147147

148+
// Recompose the original command text
149+
std::string val = std::string (szCommand) + " " + std::string (szParameters ? szParameters : "");
150+
148151
// Is it a cvar? (syntax: cvar[ = value])
149-
std::string val = std::string ( szCommand ) + " " + std::string ( szParameters ? szParameters : "" );
150-
unsigned int nOpIndex = val.find ( '=' );
151-
std::string key = val.substr ( 0, nOpIndex );
152-
if (val.find(" = ") != std::string::npos) {
153-
key = val.substr ( 0, nOpIndex-1 );
154-
}
155-
if ( CClientVariables::GetSingleton ().Exists ( key ) && !bIsScriptedBind ) {
156-
std::stringstream ss;
157-
158-
// Determine whether this is an atomic get or set query
159-
if ( nOpIndex != std::string::npos ) {
160-
// (set) some_cvar=value
161-
val = val.substr ( nOpIndex + 1 );
162-
TrimWhiteSpace ( val );
163-
CVARS_SET ( key, val );
164-
} else {
165-
// (get) some_cvar
166-
CVARS_GET ( key, val );
152+
{
153+
// Check to see if '=' exists
154+
unsigned int nOpIndex = val.find ('=');
155+
std::string key = val.substr (0, nOpIndex);
156+
157+
// Check to see if ' =' exists
158+
if (val.find (" =") != std::string::npos) {
159+
key = val.substr (0, nOpIndex - 1);
160+
}
161+
162+
TrimWhiteSpace (key);
163+
164+
// Handle the cvar if it exists
165+
if (CClientVariables::GetSingleton ().Exists (key) && !bIsScriptedBind) {
166+
std::stringstream ss;
167+
168+
// Determine whether this is an atomic get or set query
169+
if (nOpIndex != std::string::npos) {
170+
// (set) some_cvar=value
171+
val = val.substr (nOpIndex + 1);
172+
TrimWhiteSpace (val);
173+
CVARS_SET (key, val);
174+
}
175+
else {
176+
// (get) some_cvar
177+
CVARS_GET (key, val);
178+
}
179+
ss << key << " = " << val;
180+
val = ss.str ();
181+
CCore::GetSingleton ().GetConsole ()->Print (val.c_str ());
182+
return true;
167183
}
168-
ss << key << " = " << val;
169-
val = ss.str ();
170-
CCore::GetSingleton ().GetConsole ()->Print ( val.c_str () );
171-
return true;
172184
}
173185

174186
// HACK: if its a 'nick' command, save it here

0 commit comments

Comments
 (0)