Team Fortress 2 Source Code as on 22/4/2020
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.

130 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Defines gc-specific convars that integrate their AppIDs so that
  4. // two GC's in the same shell don' overwrite each other
  5. //
  6. //=============================================================================
  7. #ifndef GCCONVAR_H
  8. #define GCCONVAR_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tier1/convar.h"
  13. //-----------------------------------------------------------------------------
  14. // Purpose: GC specifc ConVar
  15. //-----------------------------------------------------------------------------
  16. class GCConVar : public ConVar
  17. {
  18. public:
  19. GCConVar( const char *pName, const char *pDefaultValue, const char *pHelpString, int flags = 0 )
  20. : ConVar( pName, pDefaultValue, flags, pHelpString ) {}
  21. GCConVar( const char *pName, const char *pDefaultValue, int flags = 0)
  22. : ConVar( pName, pDefaultValue, flags) {}
  23. GCConVar( const char *pName, const char *pDefaultValue, int flags, const char *pHelpString )
  24. : ConVar( pName, pDefaultValue, flags, pHelpString ) {}
  25. GCConVar( const char *pName, const char *pDefaultValue, int flags, const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax )
  26. : ConVar( pName, pDefaultValue, flags, pHelpString, bMin, fMin, bMax, fMax ) {}
  27. GCConVar( const char *pName, const char *pDefaultValue, int flags, const char *pHelpString, FnChangeCallback_t callback )
  28. : ConVar( pName, pDefaultValue, flags, pHelpString, callback ) {}
  29. GCConVar( const char *pName, const char *pDefaultValue, int flags, const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax, FnChangeCallback_t callback )
  30. : ConVar( pName, pDefaultValue, flags, pHelpString, bMin, fMin, bMax, fMax, callback ) {}
  31. virtual const char *GetName( void ) const;
  32. const char *GetBaseName() const { GetName(); return m_pchBaseName; } // returns the name without the appID suffix
  33. protected:
  34. mutable CUtlString m_strGCName;
  35. mutable const char *m_pchBaseName;
  36. };
  37. //-----------------------------------------------------------------------------
  38. // Purpose: GC specific ConCommand
  39. //-----------------------------------------------------------------------------
  40. class GCConCommand : public ConCommand
  41. {
  42. public:
  43. GCConCommand( const char *pName, FnCommandCallbackVoid_t callback, const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 )
  44. : ConCommand( pName, callback, pHelpString, flags, completionFunc ) {}
  45. GCConCommand( const char *pName, FnCommandCallback_t callback, const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 )
  46. : ConCommand( pName, callback, pHelpString, flags, completionFunc ) {}
  47. GCConCommand( const char *pName, ICommandCallback *pCallback, const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 )
  48. : ConCommand( pName, pCallback, pHelpString, flags, pCommandCompletionCallback ) {}
  49. virtual const char *GetName( void ) const;
  50. const char *GetBaseName() const { GetName(); return m_pchBaseName; } // returns the name without the appID suffix
  51. protected:
  52. mutable CUtlString m_strGCName;
  53. mutable const char *m_pchBaseName;
  54. };
  55. //utility function to help identify the expected number of arguments and returns false if an inappropriate number are provided and lists the help for the con command
  56. bool BCheckArgs( int nArgs, const CCommand &args, const ConCommandBase &command );
  57. //utility function that will determine if the appropriate GC type is running, and if not, will print out a descriptive message about which GC type it should be run on
  58. bool BGCConCommandVerifyGCType( uint32 nGCType );
  59. //called to declare a console command
  60. // !FIXME DOTAMERGE
  61. // CCommandContext
  62. //#define GC_CON_COMMAND( name, description ) \
  63. // static void con_command_##name( const CCommandContext &ctx, const CCommand &args ); \
  64. // static GCConCommand name##_command( #name, con_command_##name, description ); \
  65. // static void con_command_##name( const CCommandContext &ctx, const CCommand &args )
  66. #define GC_CON_COMMAND( name, description ) \
  67. static void con_command_##name( const CCommand &args ); \
  68. static GCConCommand name##_command( #name, con_command_##name, description ); \
  69. static void con_command_##name( const CCommand &args )
  70. //declares a console command that requires at least the specified number of arguments, and if not, will print out the help and not execute. For example, if you require a single
  71. //parameter, pass in 1 for numparams. This won't block if there are additional parameters
  72. // !FIXME DOTAMERGE
  73. // CCommandContext
  74. //#define GC_CON_COMMAND_PARAMS( name, numparams, description ) \
  75. // static void con_command_##name##_ValidateParams( const CCommandContext &ctx, const CCommand &args ); \
  76. // static GCConCommand name##_command( #name, con_command_##name##_ValidateParams, description ); \
  77. // static void con_command_##name( const CCommandContext &ctx, const CCommand &args ); \
  78. // static void con_command_##name##_ValidateParams( const CCommandContext &ctx, const CCommand &args ) \
  79. // { \
  80. // if( BCheckArgs( numparams, args, name##_command ) ) { con_command_##name( ctx, args ); } \
  81. // } \
  82. // static void con_command_##name( const CCommandContext &ctx, const CCommand &args )
  83. #define GC_CON_COMMAND_PARAMS( name, numparams, description ) \
  84. static void con_command_##name##_ValidateParams( const CCommand &args ); \
  85. static GCConCommand name##_command( #name, con_command_##name##_ValidateParams, description ); \
  86. static void con_command_##name( const CCommand &args ); \
  87. static void con_command_##name##_ValidateParams( const CCommand &args ) \
  88. { \
  89. if( BCheckArgs( numparams, args, name##_command ) ) { con_command_##name( args ); } \
  90. } \
  91. static void con_command_##name( const CCommand &args )
  92. // Also see GC_CON_COMMAND_PARAMS_WEBAPI_ENABLED in gcwebapi.h
  93. #define RESTRICT_GC_TYPE_CON_COMMAND( gctype ) \
  94. { \
  95. if ( !BGCConCommandVerifyGCType( gctype ) ) \
  96. return; \
  97. } //
  98. #define AUTO_CONFIRM_CON_COMMAND() \
  99. { \
  100. static RTime32 rtimeLastRan = 0; \
  101. if ( CRTime::RTime32TimeCur() - rtimeLastRan > 3 ) \
  102. { \
  103. rtimeLastRan = CRTime::RTime32TimeCur(); \
  104. EmitInfo( SPEW_CONSOLE, SPEW_ALWAYS, LOG_ALWAYS, "Auto-confirm: Please repeat command within 3 seconds to confirm.\n" ); \
  105. return; \
  106. } \
  107. else \
  108. { \
  109. rtimeLastRan = 0; \
  110. } \
  111. }
  112. #endif