40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using Godot;
|
|
using Network.PacketHandling;
|
|
using System;
|
|
|
|
namespace Network {
|
|
public class Client : Peer {
|
|
|
|
private PacketPeerUDP PacketPeer;
|
|
|
|
private Connection ServerConn;
|
|
|
|
private PacketBuffer TempBuffer;
|
|
private float Timer = 0;
|
|
|
|
public Client(PacketPeerUDP packetPeer) : base(packetPeer, false) {
|
|
PacketPeer = packetPeer;
|
|
TempBuffer = PacketBuffer.WithSignature();
|
|
TempBuffer.Write(1);
|
|
}
|
|
|
|
public override void Initialize(string address, int port) {
|
|
GD.print("Start client.");
|
|
ServerConn = new Connection(address, port);
|
|
ServerConn.Name = "Server";
|
|
ConnectionList.AddConnection(ServerConn);
|
|
StartListening(port, "*");
|
|
}
|
|
|
|
public override void Process(float delta) {
|
|
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);
|
|
}
|
|
}
|
|
} |