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.

145 lines
6.1 KiB

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