using Godot;

public class Net : Node {
    
    private PacketPeerUDP PacketPeer;
    private Client Client;
    private Server Server;

    public override void _Ready() {
        PacketPeer = new PacketPeerUDP();
    }

    public override void _Process(float delta) {
        if (IsServer()) { Server.Update(delta); }
        if (IsClient()) { Client.Update(delta); }
    }

    public void StartClient() {
        //if (IsClient() || IsServer()) { return; }
        Client = new Client(PacketPeer);
        Client.Initialize("localhost", 8080);
    }

    public void StartServer() {
        //if (IsClient() || IsServer()) { return; }
        Server = new Server(PacketPeer);
        Server.Initialize("*", 8080);
    }

    public bool IsClient() {
        return Client != null;
    }

    public bool IsServer() {
        return Server != null;
    }
}
