Clone of PhatAC @ https://github.com/floaterxk/PhatAC

PacketController.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #pragma once
  2. class FragmentStack;
  3. typedef std::list<BlobPacket_s *> BlobList;
  4. typedef std::list<FragmentStack *> FragmentList;
  5. #ifdef _DEBUG
  6. #define FlagEvilClient() EvilClient( __FILE__, __LINE__, FALSE )
  7. #else
  8. #define FlagEvilClient() EvilClient( NULL, NULL, TRUE )
  9. #endif
  10. #pragma pack(push, 4)
  11. struct EventHeader
  12. {
  13. DWORD dwF7B0;
  14. DWORD dwPlayer;
  15. DWORD dwSequence;
  16. };
  17. #pragma pack(pop)
  18. class CNetwork;
  19. class CPacketController : public CKillable
  20. {
  21. public:
  22. CPacketController(CClient *);
  23. ~CPacketController();
  24. void Think(void); //Generic work cycle.
  25. void ThinkInbound(void);
  26. void ThinkOutbound(void);
  27. BOOL HasConnection();
  28. void IncomingBlob(BlobPacket_s *);
  29. DWORD GetNextSequence(void);
  30. DWORD GetLastSequence(void);
  31. DWORD GetNextEvent(void);
  32. DWORD GetLastEvent(void);
  33. void ResetEvent(void);
  34. BOOL SendNetMessage(void *data, DWORD length, WORD group);
  35. template<class T>
  36. void EraseInternal(T *data);
  37. template<class T>
  38. void EraseInternalA(T *data);
  39. private:
  40. WORD GetElapsedTime(void);
  41. void Cleanup(void);
  42. void FlushFragments(void);
  43. void FlushPeerCache(void);
  44. void PerformLoginSync();
  45. void UpdatePeerTime(void);
  46. void UpdateCharacters(void);
  47. void ProcessMessage(BYTE *data, DWORD length, WORD);
  48. void ProcessBlob(BlobPacket_s *);
  49. void EvilClient(const char* szSource, DWORD dwLine, BOOL bKill);
  50. void ResendBlob(BlobPacket_s *);
  51. void SendGenericBlob(BlobPacket_s *, DWORD dwFlags, DWORD dwSequence);
  52. void SendFragmentBlob(BlobPacket_s *);
  53. void QueueFragment(FragHeader_s *header, BYTE *data);
  54. CClient *m_pClient;
  55. SOCKADDR_IN *m_pPeer;
  56. BOOL m_bEvil;
  57. struct InputPCVars_t
  58. {
  59. InputPCVars_t()
  60. {
  61. logintime = g_pGlobals->Time();
  62. lastactivity = g_pGlobals->Time();
  63. lastrequest = g_pGlobals->Time();
  64. sequence = 0;
  65. activesequence = 1;
  66. flushsequence = 0;
  67. }
  68. double logintime; // When the client connected. Used for time subtraction.
  69. double lastactivity; // When the last SUCCESSFUL packet received.
  70. double lastrequest; //When the last lost packets request was made.
  71. //Sequencing.
  72. DWORD sequence; //The blob counter. The last one we know the client sent.
  73. DWORD activesequence; //The blob counter. The last sequence we processed.
  74. DWORD flushsequence; //The last sequence the client processed.
  75. //CRC
  76. DWORD clientcrc[3];
  77. std::list<FragmentStack *> fragstack; // All incomplete messages stack here.
  78. std::list<BlobPacket_s *> blobstack; // All queued blobs wait here. (for sequencing)
  79. } m_in;
  80. struct OutputPCVars_t
  81. {
  82. //Network variables for outgoing data.
  83. OutputPCVars_t()
  84. {
  85. lastflush = g_pGlobals->Time();
  86. lasttimeupdate = -1000.0; // g_pGlobals->Time();
  87. lastloginsync = 0;
  88. loginsyncs = 0; // -1;
  89. sequence = 1;
  90. fragment_counter = 1;
  91. event_counter = 0;
  92. initchars = FALSE;
  93. }
  94. double lastflush; //Used to clean the peer's blob cache.
  95. double lasttimeupdate; //Used to correct the client's time.
  96. double lastloginsync; //Used to sync the time at login.
  97. long loginsyncs; //The number of login syncs performed.
  98. BOOL initchars;
  99. //Sequencing.
  100. DWORD sequence; //The blob counter.
  101. DWORD fragment_counter; //The fragment counter.
  102. DWORD event_counter; //The game event counter.
  103. //CRC
  104. DWORD servercrc[3];
  105. std::list<FragPacket_s *> fragqueue; //All fragments to be sent will wait here.
  106. std::list<BlobPacket_s *> blobcache; //Remember blobs until the client receives them.
  107. } m_out;
  108. };