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.

144 lines
6.2 KiB

  1. #ifndef GCWGJOB_H
  2. #define GCWGJOB_H
  3. #ifdef _WIN32
  4. #pragma once
  5. #endif
  6. namespace GCSDK
  7. {
  8. class CGCWGJobMgr;
  9. // defines a single parameter to a web api func
  10. struct WebApiParam_t
  11. {
  12. const char *m_pchParam;
  13. const char *m_pchDescription;
  14. bool m_bOptional; // true if optional
  15. };
  16. //-----------------------------------------------------------------------------
  17. // Privilege type for WG requests
  18. // NOTE: This enum is a copy of EWegApiPrivilege from servercommon.h.
  19. enum EGCWebApiPrivilege
  20. {
  21. k_EGCWebApiPriv_None = 0, // doens't require any privileges
  22. k_EGCWebApiPriv_Account = 1, // user must have a Steam account with password set
  23. k_EGCWebApiPriv_Approved = 2, // user must not be blocked from community activity
  24. k_EGCWebApiPriv_Session = 3, // user must have a current Steam3 session
  25. k_EGCWebApiPriv_Support = 4, // user must have Support flag set
  26. k_EGCWebApiPriv_Admin = 5, // user must have Admin flag set
  27. //////////////////////////////////////////////////////////////////////////
  28. // Steamworks Application Editing -
  29. //
  30. // This represents a minimal requirement - The user must have some of the
  31. // EAppRights available to his account for a particular application.
  32. // This value is stored in the g_WebApiFuncs table.
  33. //
  34. // The functions dispatched to from the g_WebApiFuncs table are responsible
  35. // for doing finer grain permissions checks.
  36. // At this time, only the k_EAppRightManageCEG check is performed at the coarser grain.
  37. //
  38. // Some privileges such k_EAppRightEditInfo are implemented entirely within the
  39. // Web Server's .php code, as these rights do not manipulate data through the Web Gateway,
  40. // but manipulate through direct access to file system files and perforce operations !
  41. //
  42. k_EGCWebApiPriv_EditApp = 6, // user has some rights onto specific app - is publisher-affiliated and rights match app (or is admin)
  43. //
  44. // End Steamworks Application Editing -
  45. //
  46. //////////////////////////////////////////////////////////////////////////
  47. //////////////////////////////////////////////////////////////////////////
  48. // Steamworks Publisher Editing -
  49. //
  50. // These represent requests for particular rights involving the manipulation of
  51. // publisher data. k_EGCWebApiPriv_MemberPublisher only requires that the user be a member of a publisher,
  52. // whereas k_EGCWebApiPriv_EditPublisher specifically requires the user has k_EPubRightManagerUsers permission
  53. // within a particular publisher. That is because at this time k_EPubRightManagerUsers is the ONLY
  54. // right defined so the coarse grain view of k_EGCWebApiPriv_EditPublisher exactly matches the finer grain
  55. // view defined by EPubRights.
  56. //
  57. k_EGCWebApiPriv_MemberPublisher = 7, // user is publisher-affiliated with specific publisher (or is admin)
  58. k_EGCWebApiPriv_EditPublisher = 8, // user can edit specific publisher (or is admin)
  59. //
  60. // End Steamworks Publisher Editing -
  61. //
  62. //////////////////////////////////////////////////////////////////////////
  63. k_EGCWebApiPriv_AccountOptional = 9, // validate the token if we get one but also allow public requests through
  64. };
  65. //-----------------------------------------------------------------------------
  66. struct WebApiFunc_t
  67. {
  68. const char *m_pchRequestName;
  69. const char *m_pchRequestHandlerJobName;
  70. EGCWebApiPrivilege m_eRequiredPrivilege;
  71. WebApiParam_t m_rgParams[20];
  72. };
  73. class CGCWGJobMgr
  74. {
  75. public:
  76. CGCWGJobMgr( );
  77. ~CGCWGJobMgr();
  78. bool BHandleMsg( IMsgNetPacket *pNetPacket );
  79. static CUtlDict< const WebApiFunc_t* > &GetWGRequestMap();
  80. static void SendErrorMessage( const CGCMsg<MsgGCWGRequest_t> & msg, const char *pchErrorMsg, int32 nResult );
  81. static void SetErrorMessage( KeyValues *pkvErr, const char *pchErrorMsg, int32 nResult );
  82. static void SendResponse( const CGCMsg<MsgGCWGRequest_t> & msg, KeyValues *pkvResponse, bool bResult );
  83. #ifdef DBGFLAG_VALIDATE
  84. virtual void Validate( CValidator &validator, const char *pchName ); // Validate our internal structures
  85. static void ValidateStatics( CValidator &validator );
  86. #endif // DBGFLAG_VALIDATE
  87. protected:
  88. static void RegisterWGJob( const WebApiFunc_t *pWGJobType, const JobType_t *pJobCreationFunc );
  89. friend void GCWGJob_RegisterWGJobType( const WebApiFunc_t *pWGJobType, const JobType_t *pJobCreationFunc );
  90. bool BVerifyPrivileges( const CGCMsg<MsgGCWGRequest_t> & msg, const WebApiFunc_t * pFunc );
  91. bool BVerifyParams( const CGCMsg<MsgGCWGRequest_t> & msg, const WebApiFunc_t * pFunc );
  92. };
  93. inline void GCWGJob_RegisterWGJobType( const WebApiFunc_t *pWGJobType, const JobType_t *pJobCreationFunc )
  94. {
  95. CGCWGJobMgr::RegisterWGJob( pWGJobType, pJobCreationFunc );
  96. }
  97. // declares a job as a wg job, require/optional params should be placed between begin and end declare.
  98. #define DECLARE_GCWG_JOB( gcbaseSubclass, jobclass, requestname, requiredprivilege ) \
  99. CJob *CreateWGJob_##jobclass( gcbaseSubclass *pvParent, void * pvStartParam ); \
  100. static const JobType_t g_JobType_##jobclass = { #jobclass, k_EGCMsgInvalid, k_EServerTypeGC, (JobCreationFunc_t)CreateWGJob_##jobclass }; \
  101. CJob *CreateWGJob_##jobclass( gcbaseSubclass *pvParent, void * pvStartParam ) \
  102. { \
  103. CJob *job = CJob::AllocateJob<jobclass>( pvParent ); \
  104. Job_SetJobType( *job, &g_JobType_##jobclass ); \
  105. if ( pvStartParam ) job->SetStartParam( pvStartParam ); \
  106. return job; \
  107. } \
  108. static const WebApiFunc_t g_WGRequestInfo_##jobclass = { requestname, #jobclass, requiredprivilege, {
  109. #define REQUIRED_GCWG_PARAM( pstrParameter, pstrDescription ) { pstrParameter, pstrDescription, false },
  110. #define OPTIONAL_GCWG_PARAM( pstrParameter, pstrDescription ) { pstrParameter, pstrDescription, true },
  111. #define END_DECLARE_GCWG_JOB( jobclass ) } }; \
  112. static class CRegWGJob_##jobclass \
  113. { \
  114. public: CRegWGJob_##jobclass() \
  115. { \
  116. GCWGJob_RegisterWGJobType( &g_WGRequestInfo_##jobclass, &g_JobType_##jobclass ); \
  117. } \
  118. } g_RegWGJob_##jobclass;
  119. // quick and dirty - register a job with no required/optional parameters
  120. #define REG_GCWG_JOB( jobclass, requestname, requiredprivilege ) \
  121. DECLARE_WG_JOB( jobclass, requestname, requiredprivilege ) \
  122. END_DECLARE_GCWG_JOB( jobclass )
  123. } // namespace GCSDK
  124. #endif