From 3ca179b954e22b640ef753bd8064727a328d6250 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 19 May 2017 16:31:29 +0200 Subject: [PATCH] Network/ENet: Separate Connect event into OutgoingConnect and IncomingConnect --- include/Nazara/Network/ENetHost.hpp | 2 +- include/Nazara/Network/ENetProtocol.hpp | 18 +++++++++++------- src/Nazara/Network/ENetHost.cpp | 15 +++++++++++---- src/Nazara/Network/ENetPeer.cpp | 6 +++--- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/include/Nazara/Network/ENetHost.hpp b/include/Nazara/Network/ENetHost.hpp index 4941df353..eb5c7d6de 100644 --- a/include/Nazara/Network/ENetHost.hpp +++ b/include/Nazara/Network/ENetHost.hpp @@ -87,7 +87,7 @@ namespace Nz int ReceiveIncomingCommands(ENetEvent* event); - void NotifyConnect(ENetPeer* peer, ENetEvent* event); + void NotifyConnect(ENetPeer* peer, ENetEvent* event, bool incoming); void NotifyDisconnect(ENetPeer*, ENetEvent* event); void SendAcknowledgements(ENetPeer* peer); diff --git a/include/Nazara/Network/ENetProtocol.hpp b/include/Nazara/Network/ENetProtocol.hpp index 7cd613ab0..dab014aa2 100644 --- a/include/Nazara/Network/ENetProtocol.hpp +++ b/include/Nazara/Network/ENetProtocol.hpp @@ -118,11 +118,6 @@ namespace Nz /** no event occurred within the specified time limit */ None, - /** a connection request initiated by enet_host_connect has completed. - * The peer field contains the peer which successfully connected. - */ - Connect, - /** a peer has disconnected. This event is generated on a successful * completion of a disconnect initiated by enet_peer_disconnect, if * a peer has timed out, or if a connection request initialized by @@ -132,11 +127,20 @@ namespace Nz */ Disconnect, + /** a connection request initiated by enet_host_connect from this host has completed. + * The peer field contains the peer which successfully connected. + */ + OutgoingConnect, + + /** a connection request initiated by enet_host_connect from another host has completed. + * The peer field contains the peer which successfully connected. + */ + IncomingConnect, + /** a packet has been received from a peer. The peer field specifies the * peer which sent the packet. The channelID field specifies the channel * number upon which the packet was received. The packet field contains - * the packet that was received; this packet must be destroyed with - * enet_packet_destroy after use. + * the packet that was received; */ Receive }; diff --git a/src/Nazara/Network/ENetHost.cpp b/src/Nazara/Network/ENetHost.cpp index d4d1be9f9..ade03bb10 100644 --- a/src/Nazara/Network/ENetHost.cpp +++ b/src/Nazara/Network/ENetHost.cpp @@ -352,10 +352,17 @@ namespace Nz switch (peer.GetState()) { case ENetPeerState::ConnectionPending: + peer.ChangeState(ENetPeerState::Connected); + + event->type = ENetEventType::IncomingConnect; + event->peer = &peer; + event->data = peer.m_eventData; + return true; + case ENetPeerState::ConnectionSucceeded: peer.ChangeState(ENetPeerState::Connected); - event->type = ENetEventType::Connect; + event->type = ENetEventType::OutgoingConnect; event->peer = &peer; event->data = peer.m_eventData; return true; @@ -728,7 +735,7 @@ namespace Nz return -1; } - void ENetHost::NotifyConnect(ENetPeer* peer, ENetEvent* event) + void ENetHost::NotifyConnect(ENetPeer* peer, ENetEvent* event, bool incoming) { m_recalculateBandwidthLimits = true; @@ -736,12 +743,12 @@ namespace Nz { peer->ChangeState(ENetPeerState::Connected); - event->type = ENetEventType::Connect; + event->type = (incoming) ? ENetEventType::IncomingConnect : ENetEventType::OutgoingConnect; event->peer = peer; event->data = peer->m_eventData; } else - peer->DispatchState(peer->GetState() == ENetPeerState::Connecting ? ENetPeerState::ConnectionSucceeded : ENetPeerState::ConnectionPending); + peer->DispatchState((peer->GetState() == ENetPeerState::Connecting) ? ENetPeerState::ConnectionSucceeded : ENetPeerState::ConnectionPending); } void ENetHost::NotifyDisconnect(ENetPeer* peer, ENetEvent* event) diff --git a/src/Nazara/Network/ENetPeer.cpp b/src/Nazara/Network/ENetPeer.cpp index 5ce92a1e4..cbae37148 100644 --- a/src/Nazara/Network/ENetPeer.cpp +++ b/src/Nazara/Network/ENetPeer.cpp @@ -501,7 +501,7 @@ namespace Nz if (commandNumber != ENetProtocolCommand_VerifyConnect) return false; - m_host->NotifyConnect(this, event); + m_host->NotifyConnect(this, event, true); break; case ENetPeerState::Disconnecting: @@ -864,7 +864,7 @@ namespace Nz NetToHost(command->verifyConnect.packetThrottleInterval) != m_packetThrottleInterval || NetToHost(command->verifyConnect.packetThrottleAcceleration) != m_packetThrottleAcceleration || NetToHost(command->verifyConnect.packetThrottleDeceleration) != m_packetThrottleDeceleration || - command->verifyConnect.connectID != m_connectID) + command->verifyConnect.connectID != m_connectID) { m_eventData = 0; @@ -891,7 +891,7 @@ namespace Nz m_incomingBandwidth = NetToHost(command->verifyConnect.incomingBandwidth); m_outgoingBandwidth = NetToHost(command->verifyConnect.outgoingBandwidth); - m_host->NotifyConnect(this, event); + m_host->NotifyConnect(this, event, false); return true; }