Fix new connections adding constantly

This commit is contained in:
Sofia 2017-11-25 13:34:17 +02:00
parent 88f1a9a8a1
commit 621a37be41
3 changed files with 12 additions and 5 deletions

View File

@ -46,5 +46,9 @@ namespace Network {
} }
return Optional<Connection>.None; return Optional<Connection>.None;
} }
public Optional<Connection> GetOriginal(string address, int port) {
return GetOriginal(new Connection(address, port));
}
} }
} }

View File

@ -2,6 +2,7 @@ using Godot;
using Network.PacketHandling; using Network.PacketHandling;
using Network.Syncing; using Network.Syncing;
using System.Threading; using System.Threading;
using Util;
using Thread = System.Threading.Thread; using Thread = System.Threading.Thread;
namespace Network { namespace Network {
@ -80,10 +81,13 @@ namespace Network {
} }
if (Confirmed) { if (Confirmed) {
Connection conn = new Connection(Address, Port); Optional<Connection> Conn = Singleton.ConnectionList.GetOriginal(Address, Port);
Singleton.ConnectionList.AddConnection(conn); if (Conn.isEmpty) {
Singleton.PacketDistributor.AddHandler(conn); Conn = new Connection(Address, Port);
Singleton.PacketDistributor.HandleRawPacket(PB, Singleton.ConnectionList.GetOriginal(conn)); Singleton.ConnectionList.AddConnection(Conn);
Singleton.PacketDistributor.AddHandler(Conn);
}
Singleton.PacketDistributor.HandleRawPacket(PB, Singleton.ConnectionList.GetOriginal(Conn));
} }
} }
} }

View File

@ -23,7 +23,6 @@ namespace Network.Syncing {
} }
public void Update(float delta) { public void Update(float delta) {
//GD.print("Update! + " + delta);
TimeSinceLastSync += delta; TimeSinceLastSync += delta;
if (TimeSinceLastSync > Interval) { if (TimeSinceLastSync > Interval) {
TimeSinceLastSync = 0; TimeSinceLastSync = 0;