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;
}
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.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<Connection> 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));
}
}
}

View File

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