PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/EQEmuServer/common/EmuTCPConnection.h

http://projecteqemu.googlecode.com/
C Header | 103 lines | 73 code | 25 blank | 5 comment | 0 complexity | 6e54bbc4b603cdec371fde49ade6a5f5 MD5 | raw file
Possible License(s): GPL-2.0
  1. #ifndef EmuTCPCONNECTION_H_
  2. #define EmuTCPCONNECTION_H_
  3. #include "TCPConnection.h"
  4. #include "timer.h"
  5. //moved out of TCPConnection:: to be more exportable
  6. #pragma pack(1)
  7. struct EmuTCPNetPacket_Struct {
  8. uint32 size;
  9. struct {
  10. uint8
  11. compressed : 1,
  12. destination : 1,
  13. flag3 : 1,
  14. flag4 : 1,
  15. flag5 : 1,
  16. flag6 : 1,
  17. flag7 : 1,
  18. flag8 : 1;
  19. } flags;
  20. uint16 opcode;
  21. uchar buffer[0];
  22. };
  23. #pragma pack()
  24. struct SPackSendQueue;
  25. class EmuTCPServer;
  26. class EmuTCPConnection : public TCPConnection {
  27. public:
  28. enum eTCPMode { modeConsole, modeTransition, modePacket };
  29. enum ePacketMode { packetModeZone, packetModeLauncher, packetModeLogin, packetModeUCS, packetModeQueryServ };
  30. EmuTCPConnection(uint32 ID, EmuTCPServer* iServer, SOCKET iSock, uint32 irIP, uint16 irPort, bool iOldFormat = false);
  31. EmuTCPConnection(bool iOldFormat = false, EmuTCPServer* iRelayServer = 0, eTCPMode iMode = modePacket); // for outgoing connections
  32. EmuTCPConnection(uint32 ID, EmuTCPServer* iServer, EmuTCPConnection* iRelayLink, uint32 iRemoteID, uint32 irIP, uint16 irPort); // for relay connections
  33. virtual ~EmuTCPConnection();
  34. virtual bool ConnectIP(uint32 irIP, uint16 irPort, char* errbuf = 0);
  35. virtual void Disconnect(bool iSendRelayDisconnect = true);
  36. static EmuTCPNetPacket_Struct* MakePacket(ServerPacket* pack, uint32 iDestination = 0);
  37. static SPackSendQueue* MakeOldPacket(ServerPacket* pack);
  38. virtual bool SendPacket(ServerPacket* pack, uint32 iDestination = 0);
  39. virtual bool SendPacket(EmuTCPNetPacket_Struct* tnps);
  40. ServerPacket* PopPacket(); // OutQueuePop()
  41. void SetPacketMode(ePacketMode mode) { PacketMode = mode; }
  42. eTCPMode GetMode() const { return TCPMode; }
  43. ePacketMode GetPacketMode() const { return(PacketMode); }
  44. //relay crap:
  45. inline bool IsRelayServer() const { return RelayServer; }
  46. inline TCPConnection* GetRelayLink() const { return RelayLink; }
  47. inline uint32 GetRemoteID() const { return RemoteID; }
  48. protected:
  49. void OutQueuePush(ServerPacket* pack);
  50. void RemoveRelay(EmuTCPConnection* relay, bool iSendRelayDisconnect);
  51. void SendNetErrorPacket(const char* reason = 0);
  52. virtual bool SendData(bool &sent_something, char* errbuf = 0);
  53. virtual bool RecvData(char* errbuf = 0);
  54. virtual bool ProcessReceivedData(char* errbuf = 0);
  55. bool ProcessReceivedDataAsPackets(char* errbuf = 0);
  56. bool ProcessReceivedDataAsOldPackets(char* errbuf = 0);
  57. void ProcessNetworkLayerPacket(ServerPacket* pack);
  58. virtual bool LineOutQueuePush(char* line);
  59. virtual void ClearBuffers();
  60. EmuTCPServer* Server;
  61. eTCPMode TCPMode;
  62. ePacketMode PacketMode;
  63. bool pOldFormat;
  64. Timer keepalive_timer;
  65. Timer timeout_timer;
  66. //relay crap:
  67. EmuTCPConnection* RelayLink;
  68. int32 RelayCount;
  69. bool RelayServer;
  70. uint32 RemoteID;
  71. //input queue...
  72. void InModeQueuePush(EmuTCPNetPacket_Struct* tnps);
  73. MyQueue<EmuTCPNetPacket_Struct> InModeQueue;
  74. //output queue...
  75. MyQueue<ServerPacket> OutQueue;
  76. Mutex MOutQueueLock;
  77. };
  78. #endif /*EmuTCPCONNECTION_H_*/