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.

94 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Holds function bodies for GCSDK
  4. //
  5. //=============================================================================
  6. #include "stdafx.h"
  7. #include "gcmsg.h"
  8. #include "msgprotobuf.h"
  9. #include "tier0/memdbgoff.h"
  10. #ifdef GC
  11. namespace GCSDK
  12. {
  13. IMPLEMENT_CLASS_MEMPOOL( CStructNetPacket, 1000, UTLMEMORYPOOL_GROW_SLOW );
  14. }
  15. #endif
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. namespace GCSDK
  19. {
  20. CUtlString GCMsgHdr_t::GetHeaderDescription( )
  21. {
  22. CUtlString desc;
  23. desc.Format( "gc msg %s, SteamID %llu", PchMsgNameFromEMsg( m_eMsg ), m_ulSteamID );
  24. return desc;
  25. }
  26. CUtlString GCMsgHdrEx_t::GetHeaderDescription( )
  27. {
  28. CUtlString desc;
  29. desc.Format( "gc msg %s, SteamID %llu, version %hd, job source %llu, job target %llu", PchMsgNameFromEMsg( m_eMsg ), m_ulSteamID, m_nHdrVersion, m_JobIDSource, m_JobIDTarget );
  30. return desc;
  31. }
  32. CUtlString GCMsgInterHdr_t::GetHeaderDescription( )
  33. {
  34. CUtlString desc;
  35. desc.Format( "gc inter msg %s, SourceAppID %d, version %hd, job source %llu, job target %llu", PchMsgNameFromEMsg( m_eMsg ), m_unSourceAppId, m_nHdrVersion, m_JobIDSource, m_JobIDTarget );
  36. return desc;
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose: Takes a pNetPacket, then converts it to the appropriate actual message
  40. // type and return the IMsgNetPacket interface.
  41. //-----------------------------------------------------------------------------
  42. IMsgNetPacket *IMsgNetPacketFromCNetPacket( CNetPacket *pNetPacket )
  43. {
  44. uint32 cubPkt = pNetPacket->CubData();
  45. uint8* pubPkt = pNetPacket->PubData();
  46. if ( cubPkt >= sizeof( ProtoBufMsgHeader_t ) && ( ( ( ProtoBufMsgHeader_t *) pubPkt )->m_EMsgFlagged & k_EMsgProtoBufFlag ) )
  47. {
  48. CProtoBufNetPacket *pMsgNetPacket = new CProtoBufNetPacket( pNetPacket, GCProtoBufMsgSrc_Unspecified, CSteamID(), 0, 0x7FFFFFFF & ( ( ProtoBufMsgHeader_t *) pubPkt )->m_EMsgFlagged );
  49. if ( !pMsgNetPacket->IsValid() )
  50. {
  51. pMsgNetPacket->Release();
  52. return NULL;
  53. }
  54. return pMsgNetPacket;
  55. }
  56. else
  57. {
  58. if ( cubPkt >= sizeof( GCMsgHdrEx_t ) )
  59. {
  60. CStructNetPacket *pMsgNetPacket = (CStructNetPacket*)malloc( sizeof( CStructNetPacket ) );
  61. Construct( pMsgNetPacket, pNetPacket );
  62. return pMsgNetPacket;
  63. }
  64. }
  65. EmitError( SPEW_GC, "IMsgNetPacketFromCNetPacket: malformed packet, size %d bytes\n", cubPkt );
  66. for ( uint32 i = 0 ; i < cubPkt ; i += 16 )
  67. {
  68. char buf[512];
  69. char *d = buf;
  70. d += Q_snprintf(d, 12, "%08X:", i );
  71. for ( uint32 j = i ; j < i+16 && j < cubPkt ; ++j )
  72. {
  73. d += Q_snprintf(d, 8, " %02X", pubPkt[j] );
  74. }
  75. *d = '\0';
  76. EmitError( SPEW_GC, "%s\n", buf );
  77. }
  78. AssertMsg( false, "IMsgNetPacketFromCNetPacket couldn't detect any appropriate msg format, returning NULL." );
  79. return NULL;
  80. }
  81. } // namespace GCSDK