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.

124 lines
5.0 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef INETCHANNEL_H
  7. #define INETCHANNEL_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier0/platform.h"
  12. #include "inetchannelinfo.h"
  13. #include "tier1/bitbuf.h"
  14. #include "tier1/netadr.h"
  15. #include "tier1/ns_address.h"
  16. class IDemoRecorder;
  17. class INetMessage;
  18. class INetChannelHandler;
  19. class INetChannelInfo;
  20. class INetMessageBinder;
  21. typedef struct netpacket_s netpacket_t;
  22. #ifndef NET_PACKET_ST_DEFINED
  23. #define NET_PACKET_ST_DEFINED
  24. typedef struct netpacket_s
  25. {
  26. ns_address from; // sender address
  27. int source; // received source
  28. double received; // received time
  29. unsigned char *data; // pointer to raw packet data
  30. bf_read message; // easy bitbuf data access
  31. int size; // size in bytes
  32. int wiresize; // size in bytes before decompression
  33. bool stream; // was send as stream
  34. struct netpacket_s *pNext; // for internal use, should be NULL in public
  35. } netpacket_t;
  36. #endif // NET_PACKET_ST_DEFINED
  37. abstract_class INetChannel : public INetChannelInfo
  38. {
  39. public:
  40. virtual ~INetChannel( void ) {};
  41. virtual void SetDataRate(float rate) = 0;
  42. virtual bool RegisterMessage(INetMessageBinder *msg) = 0;
  43. virtual bool UnregisterMessage(INetMessageBinder *msg) = 0;
  44. virtual bool StartStreaming( unsigned int challengeNr ) = 0;
  45. virtual void ResetStreaming( void ) = 0;
  46. virtual void SetTimeout(float seconds, bool bForceExact = false) = 0;
  47. virtual void SetDemoRecorder(IDemoRecorder *recorder) = 0;
  48. virtual void SetChallengeNr(unsigned int chnr) = 0;
  49. virtual void Reset( void ) = 0;
  50. virtual void Clear( void ) = 0;
  51. virtual void Shutdown(const char *reason) = 0;
  52. virtual void ProcessPlayback( void ) = 0;
  53. virtual bool ProcessStream( void ) = 0;
  54. virtual void ProcessPacket( struct netpacket_s* packet, bool bHasHeader ) = 0;
  55. virtual bool SendNetMsg(INetMessage &msg, bool bForceReliable = false, bool bVoice = false ) = 0;
  56. #ifdef POSIX
  57. FORCEINLINE bool SendNetMsg(INetMessage const &msg, bool bForceReliable = false, bool bVoice = false ) { return SendNetMsg( *( (INetMessage *) &msg ), bForceReliable, bVoice ); }
  58. #endif
  59. virtual bool SendData(bf_write &msg, bool bReliable = true) = 0;
  60. virtual bool SendFile(const char *filename, unsigned int transferID, bool bIsReplayDemoFile ) = 0;
  61. virtual void DenyFile(const char *filename, unsigned int transferID, bool bIsReplayDemoFile ) = 0;
  62. virtual void RequestFile_OLD(const char *filename, unsigned int transferID) = 0; // get rid of this function when we version the
  63. virtual void SetChoked( void ) = 0;
  64. virtual int SendDatagram(bf_write *data) = 0;
  65. virtual bool Transmit(bool onlyReliable = false) = 0;
  66. virtual const ns_address &GetRemoteAddress( void ) const = 0;
  67. virtual INetChannelHandler *GetMsgHandler( void ) const = 0;
  68. virtual int GetDropNumber( void ) const = 0;
  69. virtual int GetSocket( void ) const = 0;
  70. virtual unsigned int GetChallengeNr( void ) const = 0;
  71. virtual void GetSequenceData( int &nOutSequenceNr, int &nInSequenceNr, int &nOutSequenceNrAck ) = 0;
  72. virtual void SetSequenceData( int nOutSequenceNr, int nInSequenceNr, int nOutSequenceNrAck ) = 0;
  73. virtual void UpdateMessageStats( int msggroup, int bits) = 0;
  74. virtual bool CanPacket( void ) const = 0;
  75. virtual bool IsOverflowed( void ) const = 0;
  76. virtual bool IsTimedOut( void ) const = 0;
  77. virtual bool HasPendingReliableData( void ) = 0;
  78. virtual void SetFileTransmissionMode(bool bBackgroundMode) = 0;
  79. virtual void SetCompressionMode( bool bUseCompression ) = 0;
  80. virtual unsigned int RequestFile(const char *filename, bool bIsReplayDemoFile ) = 0;
  81. virtual float GetTimeSinceLastReceived( void ) const = 0; // get time since last received packet in seconds
  82. virtual void SetMaxBufferSize(bool bReliable, int nBytes, bool bVoice = false ) = 0;
  83. virtual bool IsNull() const = 0;
  84. virtual int GetNumBitsWritten( bool bReliable ) = 0;
  85. virtual void SetInterpolationAmount( float flInterpolationAmount ) = 0;
  86. virtual void SetRemoteFramerate( float flFrameTime, float flFrameTimeStdDeviation, float flFrameStartTimeStdDeviation ) = 0;
  87. // Max # of payload bytes before we must split/fragment the packet
  88. virtual void SetMaxRoutablePayloadSize( int nSplitSize ) = 0;
  89. virtual int GetMaxRoutablePayloadSize() = 0;
  90. // For routing messages to a different handler
  91. virtual bool SetActiveChannel( INetChannel *pNewChannel ) = 0;
  92. virtual void AttachSplitPlayer( int nSplitPlayerSlot, INetChannel *pChannel ) = 0;
  93. virtual void DetachSplitPlayer( int nSplitPlayerSlot ) = 0;
  94. virtual bool IsRemoteDisconnected() const = 0;
  95. virtual bool WasLastMessageReliable() const = 0; // True if the last (or currently processing) message was sent via the reliable channel
  96. virtual const unsigned char * GetChannelEncryptionKey() const = 0; // Returns a buffer with channel encryption key data (network layer determines the buffer size)
  97. virtual bool EnqueueVeryLargeAsyncTransfer( INetMessage &msg ) = 0; // Enqueues a message for a large async transfer
  98. };
  99. #endif // INETCHANNEL_H