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.

163 lines
4.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: baseclientstate.cpp: implementation of the CBaseClientState class.
  4. //
  5. //=============================================================================//
  6. #include "client.h"
  7. #include "convar.h"
  8. #include "convar_serverbounded.h"
  9. #include "sys.h"
  10. #include "net.h"
  11. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. // These are the server cvars that control our cvars.
  14. extern int ClampClientRate( int nRate );
  15. extern ConVar sv_mincmdrate;
  16. extern ConVar sv_maxcmdrate;
  17. extern ConVar sv_minupdaterate;
  18. extern ConVar sv_maxupdaterate;
  19. extern ConVar sv_client_cmdrate_difference;
  20. extern ConVar sv_client_interp;
  21. extern ConVar sv_client_predict;
  22. // ------------------------------------------------------------------------------------------ //
  23. // rate
  24. // ------------------------------------------------------------------------------------------ //
  25. void CL_RateCvarChanged( IConVar *pConVar, const char *pOldValue, float flOldValue )
  26. {
  27. }
  28. class CBoundedCvar_Rate : public ConVar_ServerBounded
  29. {
  30. public:
  31. CBoundedCvar_Rate() :
  32. ConVar_ServerBounded(
  33. "rate",
  34. STRINGIFY( DEFAULT_RATE ),
  35. FCVAR_ARCHIVE | FCVAR_USERINFO,
  36. "Max bytes/sec the host can receive data",
  37. CL_RateCvarChanged )
  38. {
  39. }
  40. virtual float GetFloat() const
  41. {
  42. #ifdef DEDICATED
  43. return GetBaseFloatValue();
  44. #else
  45. if ( GetBaseLocalClient().m_nSignonState >= SIGNONSTATE_FULL )
  46. {
  47. int nRate = (int)GetBaseFloatValue();
  48. return (float)ClampClientRate( nRate );
  49. }
  50. else
  51. {
  52. return GetBaseFloatValue();
  53. }
  54. #endif
  55. }
  56. };
  57. static CBoundedCvar_Rate cl_rate_var;
  58. ConVar_ServerBounded *cl_rate = &cl_rate_var;
  59. // ------------------------------------------------------------------------------------------ //
  60. // cl_cmdrate
  61. // ------------------------------------------------------------------------------------------ //
  62. class CBoundedCvar_CmdRate : public ConVar_ServerBounded
  63. {
  64. public:
  65. CBoundedCvar_CmdRate() :
  66. ConVar_ServerBounded(
  67. "cl_cmdrate",
  68. "64",
  69. FCVAR_ARCHIVE | FCVAR_USERINFO,
  70. "Max number of command packets sent to server per second", true, MIN_CMD_RATE, true, MAX_CMD_RATE )
  71. {
  72. }
  73. virtual float GetFloat() const
  74. {
  75. float flCmdRate = GetBaseFloatValue();
  76. #ifndef DEDICATED
  77. if ( GetBaseLocalClient().ishltv )
  78. {
  79. extern ConVar tv_snapshotrate;
  80. return tv_snapshotrate.GetFloat();
  81. }
  82. else if ( sv_mincmdrate.GetInt() != 0 && GetBaseLocalClient().m_nSignonState >= SIGNONSTATE_FULL )
  83. {
  84. // First, we make it stay within range of cl_updaterate.
  85. float diff = flCmdRate - cl_updaterate->GetFloat();
  86. if ( fabs( diff ) > sv_client_cmdrate_difference.GetFloat() )
  87. {
  88. if ( diff > 0 )
  89. flCmdRate = cl_updaterate->GetFloat() + sv_client_cmdrate_difference.GetFloat();
  90. else
  91. flCmdRate = cl_updaterate->GetFloat() - sv_client_cmdrate_difference.GetFloat();
  92. }
  93. // Then we clamp to the min/max values the server has set.
  94. return clamp( flCmdRate, sv_mincmdrate.GetFloat(), sv_maxcmdrate.GetFloat() );
  95. }
  96. else
  97. #endif
  98. {
  99. return flCmdRate;
  100. }
  101. }
  102. };
  103. static CBoundedCvar_CmdRate cl_cmdrate_var;
  104. ConVar_ServerBounded *cl_cmdrate = &cl_cmdrate_var;
  105. // ------------------------------------------------------------------------------------------ //
  106. // cl_updaterate
  107. // ------------------------------------------------------------------------------------------ //
  108. class CBoundedCvar_UpdateRate : public ConVar_ServerBounded
  109. {
  110. public:
  111. CBoundedCvar_UpdateRate() :
  112. ConVar_ServerBounded(
  113. "cl_updaterate",
  114. "64",
  115. FCVAR_ARCHIVE | FCVAR_USERINFO | FCVAR_NOT_CONNECTED,
  116. "Number of packets per second of updates you are requesting from the server" )
  117. {
  118. }
  119. virtual float GetFloat() const
  120. {
  121. // Clamp to the min/max values the server has set.
  122. //
  123. // This cvar only takes effect on the server anyway, and this is done there too,
  124. // but we have this here so they'll get the **note thing telling them the value
  125. // isn't functioning the way they set it.
  126. float flValue = GetBaseFloatValue();
  127. #ifndef DEDICATED
  128. if ( GetBaseLocalClient().ishltv )
  129. {
  130. extern ConVar tv_snapshotrate;
  131. return tv_snapshotrate.GetFloat();
  132. }
  133. #endif
  134. return clamp( flValue, sv_minupdaterate.GetFloat(), sv_maxupdaterate.GetFloat() );
  135. }
  136. };
  137. static CBoundedCvar_UpdateRate cl_updaterate_var;
  138. ConVar_ServerBounded *cl_updaterate = &cl_updaterate_var;