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.

107 lines
2.7 KiB

  1. //========= Copyright � 1996-2001, Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #if !defined( MSGBUFFER_H )
  8. #define MSGBUFFER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "netadr.h"
  13. //-----------------------------------------------------------------------------
  14. // Purpose: Generic byte level message buffer with read/write support
  15. //-----------------------------------------------------------------------------
  16. class CMsgBuffer
  17. {
  18. public:
  19. enum
  20. {
  21. NET_MAXMESSAGE = 8192
  22. };
  23. // Buffers must be named
  24. CMsgBuffer( const char *buffername = "unnamed", void (*ef)( const char *fmt, ... ) = 0 );
  25. virtual ~CMsgBuffer( void );
  26. // Reset the buffer for writing
  27. void Clear( void );
  28. // Get current # of bytes
  29. int GetCurSize( void );
  30. // Get max # of bytes
  31. int GetMaxSize( void );
  32. // Get pointer to raw data
  33. void *GetData( void );
  34. // Set/unset the allow overflow flag
  35. void SetOverflow( bool allowed );
  36. // Start reading from buffer
  37. void BeginReading( void );
  38. // Get current read byte
  39. int GetReadCount( void );
  40. // Push read count ( to peek at data )
  41. void Push( void );
  42. void Pop( void );
  43. // Writing functions
  44. void WriteByte(int c);
  45. void WriteShort(int c);
  46. void WriteLong(int c);
  47. void WriteFloat(float f);
  48. void WriteString(const char *s);
  49. void WriteBuf( int iSize, void *buf );
  50. // Reading functions
  51. int ReadByte( void );
  52. int ReadShort( void );
  53. int ReadLong( void );
  54. float ReadFloat( void );
  55. char *ReadString( void );
  56. int ReadBuf( int iSize, void *pbuf );
  57. // setting and storing time received
  58. void SetTime(float time);
  59. float GetTime();
  60. // net address received from
  61. void SetNetAddress(netadr_t &adr);
  62. netadr_t &GetNetAddress();
  63. private:
  64. // Ensures sufficient space to append an object of length
  65. void *GetSpace( int length );
  66. // Copy buffer in at current writing point
  67. void Write( const void *data, int length );
  68. private:
  69. // Name of buffer in case of debugging/errors
  70. const char *m_pszBufferName;
  71. // Optional error callback
  72. void ( *m_pfnErrorFunc )( const char *fmt, ... );
  73. // Current read pointer
  74. int m_nReadCount;
  75. // Push/pop read state
  76. int m_nPushedCount;
  77. bool m_bPushed;
  78. // Did we hit the end of the read buffer?
  79. bool m_bBadRead;
  80. // Max size of buffer
  81. int m_nMaxSize;
  82. // Current bytes written
  83. int m_nCurSize;
  84. // if false, call m_pfnErrorFunc
  85. bool m_bAllowOverflow;
  86. // set to true when buffer hits end
  87. bool m_bOverFlowed;
  88. // Internal storage
  89. unsigned char m_rgData[ NET_MAXMESSAGE ];
  90. // time received
  91. float m_fRecvTime;
  92. // address received from
  93. netadr_t m_NetAddr;
  94. };
  95. #endif // !MSGBUFFER_H