58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using Godot;
|
|
using System;
|
|
using Network;
|
|
using Network.PacketHandling;
|
|
|
|
public class MainMenu : Panel {
|
|
|
|
private Net Net;
|
|
|
|
private LineEdit IPAddressEdit;
|
|
private LineEdit PortEdit;
|
|
|
|
public override void _Ready() {
|
|
Net = (Net) GetNode("/root/Net");
|
|
var IPAddressNode = GetNode("IPAddress");
|
|
var PortNode = GetNode("Port");
|
|
if (IPAddressNode is LineEdit) {
|
|
IPAddressEdit = (LineEdit) IPAddressNode;
|
|
}
|
|
if (PortNode is LineEdit) {
|
|
PortEdit = (LineEdit) PortNode;
|
|
}
|
|
}
|
|
|
|
private void OnLaunchServer() {
|
|
GD.print("Launch Server!");
|
|
string address;
|
|
int port;
|
|
SetAddressAndPort(out address, out port, "*", 7070);
|
|
Net.StartServer(address, port);
|
|
}
|
|
|
|
|
|
private void OnLaunchClient() {
|
|
GD.print("Launch Client!");
|
|
string address;
|
|
int port;
|
|
SetAddressAndPort(out address, out port, "localhost", 7070);
|
|
Net.StartClient(address, port);
|
|
}
|
|
|
|
private void SetAddressAndPort(out string address, out int port, string defaultAddress, int defaultPort) {
|
|
if (IPAddressEdit == null || IPAddressEdit.GetText() == "") {
|
|
address = defaultAddress;
|
|
} else {
|
|
address = IPAddressEdit.GetText();
|
|
}
|
|
port = defaultPort;
|
|
if (PortEdit != null && PortEdit.GetText() != "") {
|
|
int temp_port;
|
|
Int32.TryParse(PortEdit.GetText(), out temp_port);
|
|
if (temp_port > 80) {
|
|
port = temp_port;
|
|
}
|
|
}
|
|
}
|
|
}
|