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.

202 lines
7.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: declares a variety of constants
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef GCCONSTANTS_H
  8. #define GCCONSTANTS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "steam/steamtypes.h"
  13. #include "tier0/t0constants.h"
  14. #include "gamecoordinator/igcsqlquery.h"
  15. namespace GCSDK
  16. {
  17. //-----------------------------------------------------------------------------
  18. // Timing constants
  19. //-----------------------------------------------------------------------------
  20. // How long each frame should last
  21. const int k_cMicroSecPerShellFrame = 50 * k_nThousand;
  22. // How many frames per second should we have
  23. const uint32 k_cFramesPerSec = k_nMillion / k_cMicroSecPerShellFrame;
  24. // Task granularity -- the longest time in microseconds you should spend without yielding
  25. const int k_cMicroSecTaskGranularity = 5 * k_nThousand;
  26. // If a frame runs longer than it's supposed to (which they always will by at least a little),
  27. // we subtract the overage from the next frame. This is the maximum amount to correct each frame.
  28. const int k_cMicroSecMaxFrameCorrection = 25 * k_nThousand;
  29. // if server time is too far behind, we will start skipping frames to re-synchronize it with real time
  30. const int k_cMicroSecBehindToStartFrameSkipping = (k_nMillion * 2);
  31. // Default Max time to allow a job to be blocked on I/O
  32. const int k_cMicroSecJobPausedTimeout = 20 * k_nMillion;
  33. // How much time a job should run before heartbeating
  34. const int k_cMicroSecJobHeartbeat = k_cMicroSecJobPausedTimeout / 4;
  35. // Default Max number of job heartbeat intervals to allow a job to be blocked on I/O
  36. const int k_cJobHeartbeatsBeforeTimeoutDefault = k_cMicroSecJobPausedTimeout / k_cMicroSecJobHeartbeat;
  37. // Number of seconds to take to cycle through all active sessions
  38. const int k_nUserSessionRunInterval = 5 * k_nMillion;
  39. const int k_nGSSessionRunInterval = 5 * k_nMillion;
  40. const int k_nAccountDetailsRunInterval = 30 * k_nMillion;
  41. const int k_nLocksRunInterval = 120 * k_nMillion;
  42. // Time to keep an unused lock before removing it
  43. const uint64 k_cMicroSecLockLifetime = (uint64)k_nSecondsPerHour * (uint64)k_nMillion;
  44. //-----------------------------------------------------------------------------
  45. // Server types
  46. //-----------------------------------------------------------------------------
  47. // EServerType
  48. // Specifies the type of a specific server
  49. // MUST BE KEPT IN SYNC with g_rgchServerTypeName !!!
  50. enum EServerType
  51. {
  52. k_EServerTypeInvalid = -1,
  53. k_EServerTypeShell = 0,
  54. k_EServerTypeGC = 1,
  55. k_EServerTypeGCClient = 2,
  56. // Must be last!!!
  57. k_EServerTypeMax = 2,
  58. };
  59. const EServerType k_EServerTypeFirst = k_EServerTypeShell;
  60. //-----------------------------------------------------------------------------
  61. // Alert constants
  62. //-----------------------------------------------------------------------------
  63. enum EAlertType
  64. {
  65. k_EAlertTypeAssert,
  66. k_EAlertTypeInfo,
  67. k_EAlertTypeReport,
  68. };
  69. //-----------------------------------------------------------------------------
  70. // Spew / EmitEvent constants
  71. //-----------------------------------------------------------------------------
  72. #define SPEW_ALWAYS 1
  73. #define SPEW_NEVER 5
  74. #define LOG_ALWAYS 1
  75. #define LOG_NEVER 5
  76. //-----------------------------------------------------------------------------
  77. // string constants
  78. //-----------------------------------------------------------------------------
  79. const char k_rgchUnknown[] = "Unknown";
  80. #ifdef GC
  81. //-----------------------------------------------------------------------------
  82. // SQL constants
  83. //-----------------------------------------------------------------------------
  84. const int k_cSQLObjectNameMax = 128; // max length of a SQL identifier (column name, index name, table name ... )
  85. const int k_cchSQLStatementTextMax = 8192; // nominal max length of a SQL statement
  86. const uint32 k_cubRecordMax = 4 * k_nMillion; // Max size of a single record
  87. const uint32 k_cubVarFieldMax = 1 * k_nMillion; // Max size of a variable-length field
  88. const int k_cMaxCol = 50;
  89. const uint32 k_cMaxBindParams = 500; // the largest number of bind parameters allowed in a single query
  90. const uint32 k_cMaxFreeBindParamBuffers = 2000; // How many bind param buffers should we leave free before we start deleting some
  91. const uint32 k_cMaxFreeBindWebAPIBuffers = 32; // How many WebAPI buffers should we leave free before we start deleting some
  92. // iTable constants
  93. const int k_iTableNil = -1; // No table at all
  94. const int k_iFieldNil = -1; // No field at all
  95. enum EForeignKeyAction
  96. {
  97. k_EForeignKeyActionNoAction = 0,
  98. k_EForeignKeyActionCascade = 1,
  99. k_EForeignKeyActionSetNULL = 2,
  100. };
  101. const char *PchNameFromEForeignKeyAction( EForeignKeyAction eForeignKeyAction );
  102. EForeignKeyAction EForeignKeyActionFromName( const char *pchName );
  103. const char *PchNameFromEGCSQLType( EGCSQLType eForeignKeyAction );
  104. #ifndef SQLRETURN
  105. typedef short SQLRETURN;
  106. #endif // SQLRETURN
  107. #endif // GC
  108. //-----------------------------------------------------------------------------
  109. // WebAPI constants
  110. //-----------------------------------------------------------------------------
  111. const uint32 k_cubWebAPIKey = 16; // size of the web api key
  112. const uint32 k_cchWebAPIKeyStringMax = (k_cubWebAPIKey * 2) + 1; // size of string representing web API key (hex encoded so twice the size + NUL)
  113. typedef unsigned char WebAPIKey_t[ k_cubWebAPIKey ];
  114. // used to revoke WebAPI keys. Stored in the database... do not reorder.
  115. enum EWebAPIKeyStatus
  116. {
  117. k_EWebAPIKeyValid = 0,
  118. k_EWebAPIKeyRevoked = 1,
  119. k_EWebAPIKeyInvalid = 255,
  120. };
  121. //-----------------------------------------------------------------------------
  122. // Game Server constants
  123. //-----------------------------------------------------------------------------
  124. const uint32 k_cubGameServerToken = 16; // size of the game server identity token key
  125. const uint32 k_cchGameServerTokenStringMax = (k_cubGameServerToken * 2) + 1; // size of string representing game server identity token (hex encoded so twice the size + NUL)
  126. typedef unsigned char GameServerIdentityToken_t[ k_cubGameServerToken ];
  127. //-----------------------------------------------------------------------------
  128. // Other constants
  129. //-----------------------------------------------------------------------------
  130. const int k_cSmallBuff = 255; // smallish buffer
  131. const int k_cMedBuff = 1024; // medium buffer
  132. const int k_cubMsgSizeSmall = 512; // small sized packet
  133. const int k_cInitialNetworkBuffers = 10; // # of network buffers to see the system with
  134. const int k_cubMaxExpectedMsgDataSize = 5 * k_nMegabyte;// the maximum application data that we EXPECT to be sent in a single message
  135. #define STRINGIFY(x) #x
  136. #define TOSTRING(x) STRINGIFY(x)
  137. #define FILE_AND_LINE __FILE__ ":" TOSTRING(__LINE__)
  138. // Default capacity for session hash tables
  139. const int k_cGCUserSessionInit = 10 * k_nThousand; // Can grow indefinitely by this increment
  140. const int k_cBucketGCUserSession = 100 * k_nThousand; // Fixed size
  141. const int k_cGCGSSessionInit = 1 * k_nThousand; // Can grow indefinitely by this increment
  142. const int k_cBucketGCGSSession = 10 * k_nThousand; // Fixed size
  143. const int k_cAccountDetailsInit = 10 * k_nThousand; // Can grow indefinitely by this increment
  144. const int k_cBucketAccountDetails = 100 * k_nThousand; // Fixed size
  145. const int k_cGCLocksInit = 50 * k_nThousand; // Can grow indefinitely by this increment
  146. const int k_cBucketGCLocks = 500 * k_nThousand; // Fixed size
  147. const char *PchNameFromEUniverse( EUniverse eUniverse );
  148. EUniverse EUniverseFromName( const char *pchName );
  149. } // namespace GCSDK
  150. #endif // GCCONSTANTS_H