69 lines
1.9 KiB
C#
69 lines
1.9 KiB
C#
|
|
using Godot;
|
|
using Network.PacketHandling;
|
|
using Network.PacketHandling.Packets;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Network.Syncing {
|
|
public class ConnectionHandler {
|
|
|
|
public readonly Connection Connection;
|
|
|
|
private readonly Peer Peer;
|
|
|
|
private int LastUnreliableIDReceived = -1;
|
|
private int LastReliableIDReceived = -1;
|
|
|
|
private int LastUnreliableIDTheyReceived = -1;
|
|
private int LastReliableIDTheyReceived = -1;
|
|
|
|
private float TimeSinceLastPacket = 0;
|
|
|
|
private List<Serializable> ReliableQueue = new List<Serializable>();
|
|
private List<Serializable> UnreliableQueue = new List<Serializable>();
|
|
|
|
public ConnectionHandler(Peer peer, Connection connection) {
|
|
Peer = peer;
|
|
Connection = connection;
|
|
}
|
|
|
|
public void SerializeAndSendQueues(int UnreliableSyncID) {
|
|
PacketBuffer Buffer = PacketBuffer.WithSignature();
|
|
|
|
SyncPkt Sync = new SyncPkt();
|
|
Sync.Reliable = false;
|
|
Sync.ID = UnreliableSyncID;
|
|
|
|
Sync.Serialize(Buffer);
|
|
|
|
// Add Queues
|
|
|
|
GD.print("Sending sync-" + Sync.ID);
|
|
Peer.SendBuffer(Buffer, Connection);
|
|
}
|
|
|
|
public void ReceiveBuffer(PacketBuffer packetBuffer) {
|
|
SyncPkt Sync = new SyncPkt();
|
|
Sync.Deserialize(packetBuffer);
|
|
|
|
GD.print("Received sync-" + Sync.ID);
|
|
|
|
// Read Queues
|
|
}
|
|
|
|
public void AddReliable(Serializable serializable, int ReliableID) {
|
|
serializable.Reliable = true;
|
|
serializable.ID = ReliableID;
|
|
ReliableQueue.Add(serializable);
|
|
}
|
|
|
|
public void AddUnreliable(Serializable serializable, int UnreliableID) {
|
|
serializable.Reliable = false;
|
|
serializable.ID = UnreliableID;
|
|
UnreliableQueue.Add(serializable);
|
|
}
|
|
|
|
|
|
}
|
|
}
|