Made client listen and made UI matter maybe
This commit is contained in:
parent
8bc8b692a8
commit
d9b6cc2165
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,5 +3,4 @@
|
|||||||
/.mono/
|
/.mono/
|
||||||
/mono/
|
/mono/
|
||||||
/dist/
|
/dist/
|
||||||
/Properties/
|
|
||||||
*.import
|
*.import
|
||||||
|
25
Properties/AssemblyInfo.cs
Normal file
25
Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
// Information about this assembly is defined by the following attributes.
|
||||||
|
// Change them to the values specific to your project.
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("TicTacToe")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("")]
|
||||||
|
[assembly: AssemblyCopyright("")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||||
|
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||||
|
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
|
// The following attributes are used to specify the signing key for the assembly,
|
||||||
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|
||||||
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
|
//[assembly: AssemblyKeyFile("")]
|
@ -169,9 +169,9 @@ anchor_top = 0.5
|
|||||||
anchor_right = 0.5
|
anchor_right = 0.5
|
||||||
anchor_bottom = 0.5
|
anchor_bottom = 0.5
|
||||||
margin_left = -84.0
|
margin_left = -84.0
|
||||||
margin_top = -39.0
|
margin_top = -36.0
|
||||||
margin_right = 83.0
|
margin_right = 83.0
|
||||||
margin_bottom = -15.0
|
margin_bottom = -12.0
|
||||||
rect_pivot_offset = Vector2( 0, 0 )
|
rect_pivot_offset = Vector2( 0, 0 )
|
||||||
rect_clip_content = false
|
rect_clip_content = false
|
||||||
mouse_filter = 0
|
mouse_filter = 0
|
||||||
|
@ -14,12 +14,13 @@ public class Client : Peer {
|
|||||||
|
|
||||||
public override void Initialize(string address, int port) {
|
public override void Initialize(string address, int port) {
|
||||||
GD.print("Start client.");
|
GD.print("Start client.");
|
||||||
|
GD.print("Starting to send stuff to " + address + ":" + port);
|
||||||
ServerConn = new Connection(address, port);
|
ServerConn = new Connection(address, port);
|
||||||
|
StartListening(port, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReceivePacket(byte[] buffer, string address, int port) {
|
public override void ReceivePacket(byte[] buffer, string address, int port) {
|
||||||
GD.print("Client received stuff from " + address + " : " + port + " :");
|
GD.print("Client received stuff from " + address + " : " + port + " :");
|
||||||
GD.print(buffer[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float delta) {
|
public override void Update(float delta) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using System;
|
||||||
|
|
||||||
public class Net : Node {
|
public class Net : Node {
|
||||||
|
|
||||||
@ -6,11 +7,21 @@ public class Net : Node {
|
|||||||
private Client Client;
|
private Client Client;
|
||||||
private Server Server;
|
private Server Server;
|
||||||
|
|
||||||
|
private LineEdit IPAddressEdit;
|
||||||
|
private LineEdit PortEdit;
|
||||||
|
|
||||||
public bool IsClient { get { return Client != null; } }
|
public bool IsClient { get { return Client != null; } }
|
||||||
public bool IsServer { get { return Server != null; } }
|
public bool IsServer { get { return Server != null; } }
|
||||||
|
|
||||||
public override void _Ready() {
|
public override void _Ready() {
|
||||||
PacketPeer = new PacketPeerUDP();
|
PacketPeer = new PacketPeerUDP();
|
||||||
|
var IPAddressNode = GetNode("IPAddress");
|
||||||
|
var PortNode = GetNode("Port");
|
||||||
|
if (IPAddressNode is LineEdit) {
|
||||||
|
IPAddressEdit = (LineEdit) IPAddressNode;
|
||||||
|
} if (PortNode is LineEdit) {
|
||||||
|
PortEdit = (LineEdit) PortNode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(float delta) {
|
public override void _Process(float delta) {
|
||||||
@ -24,44 +35,33 @@ public class Net : Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void StartClient() {
|
public void StartClient() {
|
||||||
//if (IsClient() || IsServer()) { return; }
|
if (IsClient || IsServer) { return; }
|
||||||
Client = new Client(PacketPeer);
|
Client = new Client(PacketPeer);
|
||||||
Client.Initialize("localhost", 7070);
|
string address;
|
||||||
|
int port;
|
||||||
|
SetAddressAndPort(out address, out port, "localhost", 7070);
|
||||||
|
Client.Initialize(address, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartServer() {
|
public void StartServer() {
|
||||||
//if (IsClient() || IsServer()) { return; }
|
if (IsClient || IsServer) { return; }
|
||||||
Server = new Server(PacketPeer);
|
Server = new Server(PacketPeer);
|
||||||
Server.Initialize("*", 7070);
|
string address;
|
||||||
|
int port;
|
||||||
|
SetAddressAndPort(out address, out port, "*", 7070);
|
||||||
|
Server.Initialize(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() != "") {
|
||||||
|
//port = PortEdit.GetText();
|
||||||
|
Int32.TryParse(PortEdit.GetText(), out port);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//extends Node2D
|
|
||||||
|
|
||||||
//# Member variables
|
|
||||||
//var thread = Thread.new()
|
|
||||||
|
|
||||||
//# This function runs in a thread!
|
|
||||||
//# Threads always take one userdata argument
|
|
||||||
//func _bg_load(path):
|
|
||||||
// print("THREAD FUNC!")
|
|
||||||
// # Load the resource
|
|
||||||
// var tex = ResourceLoader.load(path)
|
|
||||||
// # Call _bg_load_done on main thread
|
|
||||||
// call_deferred("_bg_load_done")
|
|
||||||
// return tex # return it
|
|
||||||
|
|
||||||
|
|
||||||
//func _bg_load_done():
|
|
||||||
// # Wait for the thread to complete, get the returned value
|
|
||||||
// var tex = thread.wait_to_finish()
|
|
||||||
// # Set to the sprite
|
|
||||||
// get_node("sprite").set_texture(tex)
|
|
||||||
|
|
||||||
|
|
||||||
//func _on_load_pressed():
|
|
||||||
// if (thread.is_active()):
|
|
||||||
// # Already working
|
|
||||||
// return
|
|
||||||
// print("START THREAD!")
|
|
||||||
// thread.start(self, "_bg_load", "res://mona.png")
|
|
@ -5,6 +5,8 @@ public class Server : Peer {
|
|||||||
|
|
||||||
private static PacketPeerUDP PacketPeer;
|
private static PacketPeerUDP PacketPeer;
|
||||||
|
|
||||||
|
private byte[] TempBuffer = { 1 };
|
||||||
|
|
||||||
public Server(PacketPeerUDP packetPeer) : base(packetPeer) {
|
public Server(PacketPeerUDP packetPeer) : base(packetPeer) {
|
||||||
PacketPeer = packetPeer;
|
PacketPeer = packetPeer;
|
||||||
}
|
}
|
||||||
@ -12,6 +14,7 @@ public class Server : Peer {
|
|||||||
public override void Initialize(string address, int port) {
|
public override void Initialize(string address, int port) {
|
||||||
StartListening(port, address);
|
StartListening(port, address);
|
||||||
GD.print("Server initialization finished.");
|
GD.print("Server initialization finished.");
|
||||||
|
GD.print("Started server on " + address + ":" + port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReceivePacket(byte[] buffer, string address, int port) {
|
public override void ReceivePacket(byte[] buffer, string address, int port) {
|
||||||
@ -19,6 +22,7 @@ public class Server : Peer {
|
|||||||
for (int i = 0; i < buffer.Length; i++) {
|
for (int i = 0; i < buffer.Length; i++) {
|
||||||
GD.print(buffer[i]);
|
GD.print(buffer[i]);
|
||||||
}
|
}
|
||||||
|
SendBuffer(TempBuffer, new Connection(address, port));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float delta) {
|
public override void Update(float delta) {
|
||||||
|
Loading…
Reference in New Issue
Block a user