2017-11-22 19:39:24 +01:00
|
|
|
|
using Godot;
|
|
|
|
|
using Network.PacketHandling;
|
2017-11-25 14:21:06 +01:00
|
|
|
|
using Network.PacketHandling.Packets;
|
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 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-25 14:21:06 +01:00
|
|
|
|
Timer += delta;
|
|
|
|
|
if (Timer > 10) {
|
|
|
|
|
Timer = 0;
|
|
|
|
|
TextMessagePkt Pkt = new TextMessagePkt();
|
|
|
|
|
Pkt.Text = "Hello, Server!";
|
|
|
|
|
PacketDistributor.AddReliableForAll(Pkt);
|
|
|
|
|
}
|
2017-11-22 19:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Connected(Connection conn) {
|
|
|
|
|
GD.print("Connected to " + conn.Name + " at " + conn.Address + ":" + conn.Port);
|
2017-11-25 14:30:34 +01:00
|
|
|
|
PacketDistributor.AddHandler(ServerConn);
|
2017-11-22 19:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|