2017-11-22 19:39:24 +01:00
|
|
|
|
using Godot;
|
|
|
|
|
using Network.PacketHandling;
|
2017-11-23 01:41:37 +01:00
|
|
|
|
using System;
|
2017-11-22 19:39:24 +01:00
|
|
|
|
|
|
|
|
|
namespace Network {
|
|
|
|
|
public class Client : Peer {
|
|
|
|
|
|
|
|
|
|
private PacketPeerUDP PacketPeer;
|
|
|
|
|
|
|
|
|
|
private Connection ServerConn;
|
|
|
|
|
|
|
|
|
|
private PacketBuffer TempBuffer;
|
|
|
|
|
private float Timer = 0;
|
|
|
|
|
|
2017-11-25 11:26:55 +01:00
|
|
|
|
public Client(PacketPeerUDP packetPeer) : base(packetPeer, false) {
|
2017-11-22 19:39:24 +01:00
|
|
|
|
PacketPeer = packetPeer;
|
2017-11-25 11:26:55 +01:00
|
|
|
|
TempBuffer = PacketBuffer.WithSignature();
|
2017-11-22 19:39:24 +01:00
|
|
|
|
TempBuffer.Write(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Initialize(string address, int port) {
|
|
|
|
|
GD.print("Start client.");
|
|
|
|
|
ServerConn = new Connection(address, port);
|
|
|
|
|
ServerConn.Name = "Server";
|
2017-11-22 22:02:12 +01:00
|
|
|
|
ConnectionList.AddConnection(ServerConn);
|
2017-11-22 19:39:24 +01:00
|
|
|
|
StartListening(port, "*");
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 11:26:55 +01:00
|
|
|
|
public override void Process(float delta) {
|
2017-11-22 19:39:24 +01:00
|
|
|
|
Timer += delta;
|
|
|
|
|
if (Timer < 1) { return; }
|
|
|
|
|
Timer = 0;
|
|
|
|
|
SendBuffer(TempBuffer, ServerConn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Connected(Connection conn) {
|
|
|
|
|
GD.print("Connected to " + conn.Name + " at " + conn.Address + ":" + conn.Port);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|