GodotTicTacToe/scripts/net/Net.cs

41 lines
1.1 KiB
C#

using Godot;
using System;
namespace Network {
public class Net : Node {
private PacketPeerUDP PacketPeer;
private Client Client;
private Server Server;
public bool IsClient { get { return Client != null; } }
public bool IsServer { get { return Server != null; } }
public override void _Ready() {
PacketPeer = new PacketPeerUDP();
}
public override void _Process(float delta) {
if (IsServer) { Server.Update(delta); }
if (IsClient) { Client.Update(delta); }
}
public override void _ExitTree() {
if (IsServer) { Server.Free(); }
if (IsClient) { Client.Free(); }
}
public void StartClient(string address, int port) {
if (IsClient || IsServer) { return; }
Client = new Client(PacketPeer);
Client.Initialize(address, port);
}
public void StartServer(string address, int port) {
if (IsClient || IsServer) { return; }
Server = new Server(PacketPeer);
Server.Initialize(address, port);
}
}
}