From 621a37be415f39cc4b8f3bb7be5c9ce70765d84e Mon Sep 17 00:00:00 2001 From: teascade Date: Sat, 25 Nov 2017 13:34:17 +0200 Subject: [PATCH] Fix new connections adding constantly --- scripts/net/ConnectionList.cs | 4 ++++ scripts/net/Peer.cs | 12 ++++++++---- scripts/net/syncing/PacketDistributor.cs | 1 - 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/net/ConnectionList.cs b/scripts/net/ConnectionList.cs index b3e6594..c40c522 100644 --- a/scripts/net/ConnectionList.cs +++ b/scripts/net/ConnectionList.cs @@ -46,5 +46,9 @@ namespace Network { } return Optional.None; } + + public Optional GetOriginal(string address, int port) { + return GetOriginal(new Connection(address, port)); + } } } \ No newline at end of file diff --git a/scripts/net/Peer.cs b/scripts/net/Peer.cs index a69e682..4a783c6 100644 --- a/scripts/net/Peer.cs +++ b/scripts/net/Peer.cs @@ -2,6 +2,7 @@ using Godot; using Network.PacketHandling; using Network.Syncing; using System.Threading; +using Util; using Thread = System.Threading.Thread; namespace Network { @@ -80,10 +81,13 @@ namespace Network { } if (Confirmed) { - Connection conn = new Connection(Address, Port); - Singleton.ConnectionList.AddConnection(conn); - Singleton.PacketDistributor.AddHandler(conn); - Singleton.PacketDistributor.HandleRawPacket(PB, Singleton.ConnectionList.GetOriginal(conn)); + Optional Conn = Singleton.ConnectionList.GetOriginal(Address, Port); + if (Conn.isEmpty) { + Conn = new Connection(Address, Port); + Singleton.ConnectionList.AddConnection(Conn); + Singleton.PacketDistributor.AddHandler(Conn); + } + Singleton.PacketDistributor.HandleRawPacket(PB, Singleton.ConnectionList.GetOriginal(Conn)); } } } diff --git a/scripts/net/syncing/PacketDistributor.cs b/scripts/net/syncing/PacketDistributor.cs index 9a3cd3f..d1586af 100644 --- a/scripts/net/syncing/PacketDistributor.cs +++ b/scripts/net/syncing/PacketDistributor.cs @@ -23,7 +23,6 @@ namespace Network.Syncing { } public void Update(float delta) { - //GD.print("Update! + " + delta); TimeSinceLastSync += delta; if (TimeSinceLastSync > Interval) { TimeSinceLastSync = 0;