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.

140 lines
3.8 KiB

  1. //========= Copyright 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. // These are the server cvars that control our cvars.
  12. extern int ClampClientRate( int nRate );
  13. extern ConVar sv_mincmdrate;
  14. extern ConVar sv_maxcmdrate;
  15. extern ConVar sv_minupdaterate;
  16. extern ConVar sv_maxupdaterate;
  17. extern ConVar sv_client_cmdrate_difference;
  18. extern ConVar sv_client_interp;
  19. extern ConVar sv_client_predict;
  20. // ------------------------------------------------------------------------------------------ //
  21. // rate
  22. // ------------------------------------------------------------------------------------------ //
  23. class CBoundedCvar_Rate : public ConVar_ServerBounded
  24. {
  25. public:
  26. CBoundedCvar_Rate() :
  27. ConVar_ServerBounded(
  28. "rate",
  29. #if defined( _X360 )
  30. "6000",
  31. #else
  32. V_STRINGIFY(DEFAULT_RATE),
  33. #endif
  34. FCVAR_ARCHIVE | FCVAR_USERINFO,
  35. "Max bytes/sec the host can receive data" )
  36. {
  37. }
  38. virtual float GetFloat() const
  39. {
  40. if ( cl.m_nSignonState >= SIGNONSTATE_FULL )
  41. {
  42. int nRate = (int)GetBaseFloatValue();
  43. return (float)ClampClientRate( nRate );
  44. }
  45. else
  46. {
  47. return GetBaseFloatValue();
  48. }
  49. }
  50. };
  51. static CBoundedCvar_Rate cl_rate_var;
  52. ConVar_ServerBounded *cl_rate = &cl_rate_var;
  53. // ------------------------------------------------------------------------------------------ //
  54. // cl_cmdrate
  55. // ------------------------------------------------------------------------------------------ //
  56. class CBoundedCvar_CmdRate : public ConVar_ServerBounded
  57. {
  58. public:
  59. CBoundedCvar_CmdRate() :
  60. ConVar_ServerBounded(
  61. "cl_cmdrate",
  62. "30",
  63. FCVAR_ARCHIVE | FCVAR_USERINFO,
  64. "Max number of command packets sent to server per second", true, MIN_CMD_RATE, true, MAX_CMD_RATE )
  65. {
  66. }
  67. virtual float GetFloat() const
  68. {
  69. float flCmdRate = GetBaseFloatValue();
  70. if ( sv_mincmdrate.GetInt() != 0 && cl.m_nSignonState >= SIGNONSTATE_FULL )
  71. {
  72. // First, we make it stay within range of cl_updaterate.
  73. float diff = flCmdRate - cl_updaterate->GetFloat();
  74. if ( fabs( diff ) > sv_client_cmdrate_difference.GetFloat() )
  75. {
  76. if ( diff > 0 )
  77. flCmdRate = cl_updaterate->GetFloat() + sv_client_cmdrate_difference.GetFloat();
  78. else
  79. flCmdRate = cl_updaterate->GetFloat() - sv_client_cmdrate_difference.GetFloat();
  80. }
  81. // Then we clamp to the min/max values the server has set.
  82. return clamp( flCmdRate, sv_mincmdrate.GetFloat(), sv_maxcmdrate.GetFloat() );
  83. }
  84. else
  85. {
  86. return flCmdRate;
  87. }
  88. }
  89. };
  90. static CBoundedCvar_CmdRate cl_cmdrate_var;
  91. ConVar_ServerBounded *cl_cmdrate = &cl_cmdrate_var;
  92. // ------------------------------------------------------------------------------------------ //
  93. // cl_updaterate
  94. // ------------------------------------------------------------------------------------------ //
  95. class CBoundedCvar_UpdateRate : public ConVar_ServerBounded
  96. {
  97. public:
  98. CBoundedCvar_UpdateRate() :
  99. ConVar_ServerBounded(
  100. "cl_updaterate",
  101. "20",
  102. FCVAR_ARCHIVE | FCVAR_USERINFO | FCVAR_NOT_CONNECTED,
  103. "Number of packets per second of updates you are requesting from the server" )
  104. {
  105. }
  106. virtual float GetFloat() const
  107. {
  108. // Clamp to the min/max values the server has set.
  109. //
  110. // This cvar only takes effect on the server anyway, and this is done there too,
  111. // but we have this here so they'll get the **note thing telling them the value
  112. // isn't functioning the way they set it.
  113. return clamp( GetBaseFloatValue(), sv_minupdaterate.GetFloat(), sv_maxupdaterate.GetFloat() );
  114. }
  115. };
  116. static CBoundedCvar_UpdateRate cl_updaterate_var;
  117. ConVar_ServerBounded *cl_updaterate = &cl_updaterate_var;