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.

138 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef CLIENTNETMESSAGE_H
  7. #define CLIENTNETMESSAGE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #pragma warning(disable : 4100) // unreferenced formal parameter
  11. #pragma warning(disable : 4514) // unreferenced inline function has been removed
  12. #endif
  13. #include "inetmessage.h"
  14. #include "protocol.h"
  15. #include "checksum_crc.h"
  16. #include "tier0/dbg.h"
  17. class bf_read;
  18. class bf_write;
  19. #define DECLARE_CLIENTNETMESSAGE( msgtype ) \
  20. public: \
  21. int ReadFromBuffer( bf_read * buffer ); \
  22. int WriteToBuffer( bf_write * buffer ); \
  23. void Clear(); \
  24. const char *ToString(); \
  25. static int GetType() { return msgtype; }; \
  26. static const char *GetName() { return #msgtype; };
  27. class CNetMessage : public INetMessage
  28. {
  29. public:
  30. CNetMessage() { m_bReliable = 0; m_bOwnData = false; };
  31. virtual ~CNetMessage() {};
  32. void SetReliable( bool state = true) {m_bReliable = state;};
  33. bool IsReliable() { return m_bReliable; };
  34. bool IsConnectionless() { return false;};
  35. virtual const char *ToString() { return "Unknown CNetMessage"; };
  36. public:
  37. bool m_bReliable; // true if message should be send reliable
  38. bool m_bOwnData; // true if message object uses dynamic allocated memory
  39. };
  40. class CLC_SendFile : public CNetMessage
  41. {
  42. DECLARE_CLIENTNETMESSAGE( clc_sendfile );
  43. CLC_SendFile(CRC32_t fileCRC)
  44. {
  45. m_bReliable = true;
  46. m_bOwnData = false;
  47. m_FileCRC = fileCRC;
  48. }
  49. public:
  50. CRC32_t m_FileCRC; // CRC of file to send
  51. };
  52. class CLC_Move : public CNetMessage
  53. {
  54. DECLARE_CLIENTNETMESSAGE( clc_move );
  55. CLC_Move( int numBackup, int numNew, int length, unsigned char * data)
  56. {
  57. m_bReliable = true;
  58. m_bOwnData = false;
  59. m_nNumBackupCommands = numBackup;
  60. m_nNumNewCommands = numNew;
  61. m_nLength = length; // in bits
  62. m_Data = data;
  63. }
  64. public:
  65. int m_nNumBackupCommands;
  66. int m_nNumNewCommands;
  67. int m_nLength;
  68. unsigned char *m_Data;
  69. };
  70. class CLC_StringCmd : public CNetMessage
  71. {
  72. DECLARE_CLIENTNETMESSAGE( clc_stringcmd );
  73. CLC_StringCmd(const char *command)
  74. {
  75. Assert( command );
  76. m_szClientCommand = (char*)command;
  77. m_bReliable = true;
  78. m_bOwnData = false;
  79. };
  80. public:
  81. char *m_szClientCommand;
  82. };
  83. class CLC_Delta : public CNetMessage
  84. {
  85. DECLARE_CLIENTNETMESSAGE( clc_delta );
  86. CLC_Delta( int deltaSequeenceNr );
  87. public:
  88. int m_nSequenceNumber;
  89. };
  90. class CLC_VoiceData : public CNetMessage
  91. {
  92. DECLARE_CLIENTNETMESSAGE( clc_voicedata );
  93. CLC_VoiceData( unsigned char *data, int length )
  94. {
  95. Assert( data );
  96. m_Data = data;
  97. m_nLength = length;
  98. m_bReliable = false;
  99. m_bOwnData = false;
  100. };
  101. public:
  102. int m_nLength;
  103. unsigned char *m_Data;
  104. };
  105. #endif // CLIENTNETMESSAGE_H