aboutsummaryrefslogtreecommitdiff
path: root/sp/src/public/tier1/convar_serverbounded.h
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
committerJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
commit39ed87570bdb2f86969d4be821c94b722dc71179 (patch)
treeabc53757f75f40c80278e87650ea92808274aa59 /sp/src/public/tier1/convar_serverbounded.h
downloadsource-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz
source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip
First version of the SOurce SDK 2013
Diffstat (limited to 'sp/src/public/tier1/convar_serverbounded.h')
-rw-r--r--sp/src/public/tier1/convar_serverbounded.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/sp/src/public/tier1/convar_serverbounded.h b/sp/src/public/tier1/convar_serverbounded.h
new file mode 100644
index 00000000..59287ec6
--- /dev/null
+++ b/sp/src/public/tier1/convar_serverbounded.h
@@ -0,0 +1,53 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: Helper class for cvars that have restrictions on their value.
+//
+//=============================================================================//
+
+#ifndef CONVAR_SERVERBOUNDED_H
+#define CONVAR_SERVERBOUNDED_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+
+// This class is used to virtualize a ConVar's value, so the client can restrict its
+// value while connected to a server. When using this across modules, it's important
+// to dynamic_cast it to a ConVar_ServerBounded or you won't get the restricted value.
+//
+// NOTE: FCVAR_USERINFO vars are not virtualized before they are sent to the server
+// (we have no way to detect if the virtualized value would change), so
+// if you want to use a bounded cvar's value on the server, you must rebound it
+// the same way the client does.
+class ConVar_ServerBounded : public ConVar
+{
+public:
+ ConVar_ServerBounded( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString )
+ : ConVar( pName, pDefaultValue, flags, pHelpString )
+ {
+ }
+
+ ConVar_ServerBounded( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, FnChangeCallback_t callback )
+ : ConVar( pName, pDefaultValue, flags, pHelpString, callback )
+ {
+ }
+
+ ConVar_ServerBounded( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax )
+ : ConVar( pName, pDefaultValue, flags, pHelpString, bMin, fMin, bMax, fMax ) {}
+
+ // You must implement GetFloat.
+ virtual float GetFloat() const = 0;
+
+ // You can optionally implement these.
+ virtual int GetInt() const { return (int)GetFloat(); }
+ virtual bool GetBool() const { return ( GetInt() != 0 ); }
+
+ // Use this to get the underlying cvar's value.
+ float GetBaseFloatValue() const
+ {
+ return ConVar::GetFloat();
+ }
+};
+
+
+#endif // CONVAR_SERVERBOUNDED_H