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.

110 lines
3.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "baseentity.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. class CTest_ProxyToggle_Networkable;
  12. static CTest_ProxyToggle_Networkable *g_pTestObj = 0;
  13. static bool g_bEnableProxy = true;
  14. // ---------------------------------------------------------------------------------------- //
  15. // CTest_ProxyToggle_Networkable
  16. // ---------------------------------------------------------------------------------------- //
  17. class CTest_ProxyToggle_Networkable : public CBaseEntity
  18. {
  19. public:
  20. DECLARE_CLASS( CTest_ProxyToggle_Networkable, CBaseEntity );
  21. DECLARE_SERVERCLASS();
  22. CTest_ProxyToggle_Networkable()
  23. {
  24. m_WithProxy = 1241;
  25. g_pTestObj = this;
  26. }
  27. ~CTest_ProxyToggle_Networkable()
  28. {
  29. g_pTestObj = NULL;
  30. }
  31. int UpdateTransmitState()
  32. {
  33. return SetTransmitState( FL_EDICT_ALWAYS );
  34. }
  35. CNetworkVar( int, m_WithProxy );
  36. };
  37. void* SendProxy_TestProxyToggle( const SendProp *pProp, const void *pStructBase, const void *pData, CSendProxyRecipients *pRecipients, int objectID )
  38. {
  39. if ( g_bEnableProxy )
  40. {
  41. return (void*)pData;
  42. }
  43. else
  44. {
  45. pRecipients->ClearAllRecipients();
  46. return NULL;
  47. }
  48. }
  49. REGISTER_SEND_PROXY_NON_MODIFIED_POINTER( SendProxy_TestProxyToggle );
  50. // ---------------------------------------------------------------------------------------- //
  51. // Datatables.
  52. // ---------------------------------------------------------------------------------------- //
  53. LINK_ENTITY_TO_CLASS( test_proxytoggle, CTest_ProxyToggle_Networkable );
  54. BEGIN_SEND_TABLE_NOBASE( CTest_ProxyToggle_Networkable, DT_ProxyToggle_ProxiedData )
  55. SendPropInt( SENDINFO( m_WithProxy ) )
  56. END_SEND_TABLE()
  57. IMPLEMENT_SERVERCLASS_ST( CTest_ProxyToggle_Networkable, DT_ProxyToggle )
  58. SendPropDataTable( "blah", 0, &REFERENCE_SEND_TABLE( DT_ProxyToggle_ProxiedData ), SendProxy_TestProxyToggle )
  59. END_SEND_TABLE()
  60. // ---------------------------------------------------------------------------------------- //
  61. // Console commands for this test.
  62. // ---------------------------------------------------------------------------------------- //
  63. void Test_ProxyToggle_EnableProxy( const CCommand &args )
  64. {
  65. if ( args.ArgC() < 2 )
  66. {
  67. Error( "Test_ProxyToggle_EnableProxy: requires parameter (0 or 1)." );
  68. }
  69. g_bEnableProxy = !!atoi( args[ 1 ] );
  70. }
  71. void Test_ProxyToggle_SetValue( const CCommand &args )
  72. {
  73. if ( args.ArgC() < 2 )
  74. {
  75. Error( "Test_ProxyToggle_SetValue: requires value parameter." );
  76. }
  77. else if ( !g_pTestObj )
  78. {
  79. Error( "Test_ProxyToggle_SetValue: no entity present." );
  80. }
  81. g_pTestObj->m_WithProxy = atoi( args[ 1 ] );
  82. }
  83. ConCommand cc_Test_ProxyToggle_EnableProxy( "Test_ProxyToggle_EnableProxy", Test_ProxyToggle_EnableProxy, 0, FCVAR_CHEAT );
  84. ConCommand cc_Test_ProxyToggle_SetValue( "Test_ProxyToggle_SetValue", Test_ProxyToggle_SetValue, 0, FCVAR_CHEAT );