Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Helper class for cvars that have restrictions on their value.
  4. //
  5. //=============================================================================//
  6. #ifndef CONVAR_SERVERBOUNDED_H
  7. #define CONVAR_SERVERBOUNDED_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. // This class is used to virtualize a ConVar's value, so the client can restrict its
  12. // value while connected to a server. When using this across modules, it's important
  13. // to dynamic_cast it to a ConVar_ServerBounded or you won't get the restricted value.
  14. //
  15. // NOTE: FCVAR_USERINFO vars are not virtualized before they are sent to the server
  16. // (we have no way to detect if the virtualized value would change), so
  17. // if you want to use a bounded cvar's value on the server, you must rebound it
  18. // the same way the client does.
  19. class ConVar_ServerBounded : public ConVar
  20. {
  21. public:
  22. ConVar_ServerBounded( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString )
  23. : ConVar( pName, pDefaultValue, flags, pHelpString )
  24. {
  25. }
  26. ConVar_ServerBounded( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, FnChangeCallback_t callback )
  27. : ConVar( pName, pDefaultValue, flags, pHelpString, callback )
  28. {
  29. }
  30. ConVar_ServerBounded( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax )
  31. : ConVar( pName, pDefaultValue, flags, pHelpString, bMin, fMin, bMax, fMax ) {}
  32. // You must implement GetFloat.
  33. virtual float GetFloat() const = 0;
  34. // You can optionally implement these.
  35. virtual int GetInt() const { return (int)GetFloat(); }
  36. virtual bool GetBool() const { return ( GetInt() != 0 ); }
  37. // Use this to get the underlying cvar's value.
  38. float GetBaseFloatValue() const
  39. {
  40. return ConVar::GetFloat();
  41. }
  42. };
  43. #endif // CONVAR_SERVERBOUNDED_H