You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1023 B

using Godot;
using System;
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);
}
}