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.

51 lines
1.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A network message that sends chat messages
  4. //
  5. // $Revision: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "networkmessages.h"
  9. #include "networkmanager.h"
  10. #include "tier1/bitbuf.h"
  11. //-----------------------------------------------------------------------------
  12. // Chat network message
  13. //-----------------------------------------------------------------------------
  14. REGISTER_NETWORK_MESSAGE( CNetworkMessage_Chat );
  15. CNetworkMessage_Chat::CNetworkMessage_Chat()
  16. {
  17. SetReliable( false );
  18. }
  19. bool CNetworkMessage_Chat::WriteToBuffer( bf_write &buffer )
  20. {
  21. int nLen = m_Message.Length();
  22. buffer.WriteShort( nLen );
  23. if ( nLen )
  24. {
  25. buffer.WriteBytes( m_Message.Get(), nLen );
  26. }
  27. return !buffer.IsOverflowed();
  28. }
  29. bool CNetworkMessage_Chat::ReadFromBuffer( bf_read &buffer )
  30. {
  31. int nLen = buffer.ReadShort();
  32. if ( nLen )
  33. {
  34. m_Message.SetLength( nLen + 1 );
  35. char *pDest = m_Message.Get();
  36. buffer.ReadBytes( pDest, nLen );
  37. pDest[ nLen ] = 0;
  38. }
  39. else
  40. {
  41. m_Message.Set( NULL );
  42. }
  43. return !buffer.IsOverflowed();
  44. }