GodotTicTacToe/scripts/net/Server.cs

39 lines
1.2 KiB
C#
Raw Normal View History

using Godot;
using Network.PacketHandling;
using System.Threading;
namespace Network {
public class Server : Peer {
private static PacketPeerUDP PacketPeer;
private PacketBuffer TempBuffer;
public Server(PacketPeerUDP packetPeer) : base(packetPeer) {
PacketPeer = packetPeer;
TempBuffer = NewPacketBuffer();
TempBuffer.Write(2);
}
public override void Initialize(string address, int port) {
StartListening(port, address);
GD.print("Server initialization finished.");
GD.print("Started server on " + address + ":" + port);
}
public override void Update(float delta) {
}
public override void ReceivePacket(PacketBuffer packetBuffer, Connection connection) {
GD.print("Server received stuff from " + connection.Name + " at " + connection.Address + " : " + connection.Port + " :");
while (packetBuffer.HasNext) {
GD.print(packetBuffer.Read());
}
SendBuffer(TempBuffer, connection);
}
public override void Connected(Connection conn) {
GD.print("Someone connected at " + conn.Address + ":" + conn.Port);
}
}
}