From e258675eabc874d31bc9c6cf49e4bbc1f7f3f417 Mon Sep 17 00:00:00 2001 From: sapier Date: Fri, 31 Jan 2014 00:24:00 +0100 Subject: Add propper client initialization -add client states to avoid server sending data to uninitialized clients -don't show uninitialized clients to other players -propper client disconnect handling Minor comment fixes in server Minor bugfixes in connection -improved peer id calculation -honor NDEBUG flag -improved disconnect handling -increased initial send window Remove some dead code --- src/connection.h | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'src/connection.h') diff --git a/src/connection.h b/src/connection.h index e43d93fb3..c9474032d 100644 --- a/src/connection.h +++ b/src/connection.h @@ -71,14 +71,6 @@ public: {} }; -/*class ThrottlingException : public BaseException -{ -public: - ThrottlingException(const char *s): - BaseException(s) - {} -};*/ - class InvalidIncomingDataException : public BaseException { public: @@ -406,7 +398,6 @@ enum ConnectionCommandType{ CONNCMD_DISCONNECT_PEER, CONNCMD_SEND, CONNCMD_SEND_TO_ALL, - CONNCMD_DELETE_PEER, CONCMD_ACK, CONCMD_CREATE_PEER, CONCMD_DISABLE_LEGACY @@ -460,11 +451,6 @@ struct ConnectionCommand data = data_; reliable = reliable_; } - void deletePeer(u16 peer_id_) - { - type = CONNCMD_DELETE_PEER; - peer_id = peer_id_; - } void ack(u16 peer_id_, u8 channelnum_, SharedBuffer data_) { @@ -580,16 +566,29 @@ private: class Peer; +enum PeerChangeType +{ + PEER_ADDED, + PEER_REMOVED +}; +struct PeerChange +{ + PeerChangeType type; + u16 peer_id; + bool timeout; +}; + class PeerHandler { public: + PeerHandler() { } virtual ~PeerHandler() { } - + /* This is called after the Peer has been inserted into the Connection's peer container. @@ -771,7 +770,7 @@ public: friend class ConnectionSendThread; UDPPeer(u16 a_id, Address a_address, Connection* connection); - virtual ~UDPPeer(); + virtual ~UDPPeer() {}; void PutReliableSendCommand(ConnectionCommand &c, unsigned int max_packet_size); @@ -781,8 +780,7 @@ public: bool getAddress(MTProtocols type, Address& toset); - void setNonLegacyPeer() - { m_legacy_peer = false; } + void setNonLegacyPeer(); bool getLegacyPeer() { return m_legacy_peer; } @@ -793,6 +791,8 @@ public: SharedBuffer addSpiltPacket(u8 channel, BufferedPacket toadd, bool reliable); + + protected: /* Calculates avg_rtt and resend_timeout. @@ -813,6 +813,7 @@ protected: bool Ping(float dtime,SharedBuffer& data); Channel channels[CHANNEL_COUNT]; + bool m_pending_disconnect; private: // This is changed dynamically float resend_timeout; @@ -1002,13 +1003,12 @@ public: u32 Receive(u16 &peer_id, SharedBuffer &data); void SendToAll(u8 channelnum, SharedBuffer data, bool reliable); void Send(u16 peer_id, u8 channelnum, SharedBuffer data, bool reliable); - void RunTimeouts(float dtime); // dummy u16 GetPeerID(){ return m_peer_id; } Address GetPeerAddress(u16 peer_id); float GetPeerAvgRTT(u16 peer_id); - void DeletePeer(u16 peer_id); const u32 GetProtocolID() const { return m_protocol_id; }; const std::string getDesc(); + void DisconnectPeer(u16 peer_id); protected: PeerHelper getPeer(u16 peer_id); @@ -1033,6 +1033,8 @@ protected: void putEvent(ConnectionEvent &e); + void TriggerSend() + { m_sendThread.Trigger(); } private: std::list getPeers(); @@ -1054,6 +1056,8 @@ private: int m_bc_receive_timeout; bool m_shutting_down; + + u16 m_next_remote_peer_id; }; } // namespace -- cgit v1.2.3