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.

238 lines
7.8 KiB

  1. //====== Copyright (c), Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: This file defines all of the Game Coordinator messages for the
  4. // current IS-embedded implementation of the GC
  5. //
  6. //=============================================================================
  7. #ifndef GCMSG_H
  8. #define GCMSG_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "msgbase.h"
  13. #include "messagelist.h"
  14. #pragma pack( push, 1 )
  15. namespace GCSDK
  16. {
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Header for messages from a client or gameserver to or from the GC
  19. //-----------------------------------------------------------------------------
  20. struct GCMsgHdr_t
  21. {
  22. MsgType_t m_eMsg; // The message type
  23. uint32 m_nSrcGCDirIndex; // The GC index that this message was sent from (set to the same as the current GC if not routed through another GC)
  24. uint64 m_ulSteamID; // User's SteamID
  25. const char *GetHeaderDescription( );
  26. const char *PchMsgName( ) const { return PchMsgNameFromEMsg( m_eMsg ); }
  27. };
  28. //-----------------------------------------------------------------------------
  29. // Purpose: Header for messages from a client or gameserver to or from the GC
  30. // That contains source and destination jobs for the purpose of
  31. // replying messages.
  32. //-----------------------------------------------------------------------------
  33. struct GCMsgHdrEx_t
  34. {
  35. //NOTE: The following fields must be binary equivalent with GCMsgHdr_t above
  36. MsgType_t m_eMsg;
  37. uint32 m_nSrcGCDirIndex;
  38. uint64 m_ulSteamID;
  39. // ----
  40. uint16 m_nHdrVersion;
  41. JobID_t m_JobIDTarget;
  42. JobID_t m_JobIDSource;
  43. const char *GetHeaderDescription( );
  44. const char *PchMsgName( ) const { return PchMsgNameFromEMsg( m_eMsg ); }
  45. };
  46. #pragma pack( push, 1 )
  47. struct ProtoBufMsgHeader_t
  48. {
  49. int32 m_EMsgFlagged; // High bit should be set to indicate this message header type is in use. The rest of the bits indicate message type.
  50. uint32 m_cubProtoBufExtHdr; // Size of the extended header which is a serialized protobuf object. Indicates where it ends and the serialized body protobuf begins.
  51. ProtoBufMsgHeader_t() : m_EMsgFlagged( 0 ), m_cubProtoBufExtHdr( 0 ) {}
  52. ProtoBufMsgHeader_t( MsgType_t eMsg, uint32 cubProtoBufExtHdr ) : m_EMsgFlagged( eMsg | k_EMsgProtoBufFlag ), m_cubProtoBufExtHdr( cubProtoBufExtHdr ) {}
  53. const char *PchMsgName() const { return PchMsgNameFromEMsg( GetEMsg() ); }
  54. MsgType_t GetEMsg() const { return (MsgType_t)(m_EMsgFlagged & (~k_EMsgProtoBufFlag) ); }
  55. };
  56. #pragma pack(pop)
  57. //-----------------------------------------------------------------------------
  58. // CStructNetPacket
  59. // Thin wrapper around raw CNetPacket which implements our IMsgNetPacket interface.
  60. //-----------------------------------------------------------------------------
  61. class CStructNetPacket : public IMsgNetPacket
  62. {
  63. #ifdef GC
  64. DECLARE_CLASS_MEMPOOL( CStructNetPacket );
  65. #endif
  66. public:
  67. CStructNetPacket( CNetPacket *pNetPacket )
  68. {
  69. m_pHeader = (GCMsgHdrEx_t*)pNetPacket->PubData();
  70. m_pNetPacket = pNetPacket;
  71. m_pNetPacket->AddRef();
  72. }
  73. EMsgFormatType GetEMsgFormatType() const { return k_EMsgFormatTypeStruct; }
  74. CNetPacket *GetCNetPacket() const { return m_pNetPacket; }
  75. uint8 *PubData() const { return m_pNetPacket->PubData(); }
  76. uint CubData() const { return m_pNetPacket->CubData(); }
  77. MsgType_t GetEMsg() const { return (MsgType_t)m_pHeader->m_eMsg; }
  78. JobID_t GetSourceJobID() const { return m_pHeader->m_JobIDSource; }
  79. JobID_t GetTargetJobID() const { return m_pHeader->m_JobIDTarget; }
  80. void SetTargetJobID( JobID_t ulJobID ) { m_pHeader->m_JobIDTarget = ulJobID; }
  81. CSteamID GetSteamID() const { return CSteamID( m_pHeader->m_ulSteamID ); }
  82. void SetSteamID( CSteamID steamID ) { m_pHeader->m_ulSteamID = steamID.ConvertToUint64(); }
  83. AppId_t GetSourceAppID() const { return k_uAppIdInvalid; }
  84. void SetSourceAppID( AppId_t appId ) {}
  85. // Routing to a job name is not permitted with the old packet format
  86. virtual bool BHasTargetJobName() const { return false; }
  87. virtual const char *GetTargetJobName() const { return NULL; }
  88. private:
  89. virtual ~CStructNetPacket()
  90. {
  91. m_pNetPacket->Release();
  92. }
  93. CNetPacket *m_pNetPacket;
  94. GCMsgHdrEx_t *m_pHeader;
  95. };
  96. #define GCMSG_EX_HEADER_SIZE ( sizeof( GCSDK::GCMsgHdrEx_t ) - sizeof( GCSDK::GCMsgHdr_t ) )
  97. static const uint16 k_nHdrVersion = 0x1;
  98. //-----------------------------------------------------------------------------
  99. // Purpose: Header for messages from one GC to another
  100. //-----------------------------------------------------------------------------
  101. struct GCMsgInterHdr_t
  102. {
  103. MsgType_t m_eMsg; // The message type
  104. uint32 m_unSourceAppId; // App ID of the source GC
  105. uint16 m_nHdrVersion;
  106. JobID_t m_JobIDTarget;
  107. JobID_t m_JobIDSource;
  108. const char *GetHeaderDescription( );
  109. const char *PchMsgName( ) const { return PchMsgNameFromEMsg( m_eMsg ); }
  110. };
  111. #pragma pack( pop )
  112. //-----------------------------------------------------------------------------
  113. // CGCMsgBase
  114. // Message class for messages between the GC and a GS or client
  115. // Handles a message with a header of type GCMsgHdrEx_t, a payload of type MSG_BODY_TYPE, and optional variable length data
  116. //-----------------------------------------------------------------------------
  117. typedef CMsgBase_t<GCMsgHdrEx_t> CGCMsgBase;
  118. //-----------------------------------------------------------------------------
  119. //
  120. //-----------------------------------------------------------------------------
  121. template <typename MSG_BODY_TYPE>
  122. class CGCMsg : public CGCMsgBase
  123. {
  124. public:
  125. // Client send constructor
  126. CGCMsg( MsgType_t eMsg, uint32 cubReserve = 64 ) :
  127. CGCMsgBase( sizeof( MSG_BODY_TYPE ), cubReserve )
  128. {
  129. // Fill out the message header
  130. Hdr().m_eMsg = eMsg;
  131. Hdr().m_nHdrVersion = k_nHdrVersion;
  132. Hdr().m_JobIDSource = k_GIDNil;
  133. Hdr().m_JobIDTarget = k_GIDNil;
  134. }
  135. // reply constructor
  136. CGCMsg( MsgType_t eMsg, const CGCMsgBase &msg, uint32 cubReserve = 64 ) :
  137. CGCMsgBase( sizeof( MSG_BODY_TYPE ), cubReserve )
  138. {
  139. // Fill out the message header
  140. Hdr().m_eMsg = eMsg;
  141. Hdr().m_ulSteamID = msg.Hdr().m_ulSteamID;
  142. Hdr().m_nHdrVersion = k_nHdrVersion;
  143. Hdr().m_JobIDSource = k_GIDNil;
  144. Hdr().m_JobIDTarget = msg.Hdr().m_JobIDSource;
  145. }
  146. CGCMsg( uint8 *pubPkt, uint32 cubPkt ) :
  147. CGCMsgBase( sizeof( GCMsgHdrEx_t ), sizeof( MSG_BODY_TYPE ), pubPkt, cubPkt )
  148. {
  149. }
  150. // Receive constructor
  151. // Use this constructor when creating a message from a received network packet
  152. CGCMsg( CIMsgNetPacketAutoRelease &refNetPacket )
  153. :CGCMsgBase( sizeof( GCMsgHdrEx_t ), sizeof( MSG_BODY_TYPE ), refNetPacket->PubData(), refNetPacket->CubData() )
  154. {
  155. }
  156. // Receive constructor
  157. // Use this constructor when creating a message from a received network packet
  158. CGCMsg( IMsgNetPacket *pNetPacket )
  159. :CGCMsgBase( sizeof( GCMsgHdrEx_t ), sizeof( MSG_BODY_TYPE ), pNetPacket->PubData(), pNetPacket->CubData() )
  160. {
  161. }
  162. // Receive constructor
  163. // Use this constructor when creating a message from a received network packet
  164. CGCMsg( CNetPacket *pNetPacket )
  165. :CGCMsgBase( sizeof( GCMsgHdrEx_t ), sizeof( MSG_BODY_TYPE ), pNetPacket->PubData(), pNetPacket->CubData() )
  166. {
  167. }
  168. // empty constructor
  169. CGCMsg() :
  170. CGCMsgBase( sizeof( GCMsgHdrEx_t ), sizeof( MSG_BODY_TYPE ), NULL, 0 )
  171. {
  172. }
  173. ~CGCMsg()
  174. {
  175. }
  176. // Accessors
  177. MSG_BODY_TYPE &Body() { return * ( MSG_BODY_TYPE * ) ( m_pubPkt + m_cubMsgHdr ); }
  178. const MSG_BODY_TYPE &Body() const { return * ( MSG_BODY_TYPE * ) ( m_pubPkt + m_cubMsgHdr ); }
  179. GCMsgHdrEx_t * PGCMsgHdr() { return ( ( GCMsgHdrEx_t * ) m_pubPkt ); }
  180. MsgType_t GetEMsg() const { return Hdr().m_eMsg; }
  181. // Called to set the JobID that will be expecting
  182. // a reply to this message.
  183. void ExpectingReply( JobID_t jobIDSource )
  184. {
  185. Hdr().m_JobIDSource = jobIDSource;
  186. }
  187. bool BIsExpectingReply() { return Hdr().m_JobIDSource != k_GIDNil; }
  188. };
  189. } // namespace GCSDK
  190. #endif // GCMSG_H