Made client listen and made UI matter maybe

This commit is contained in:
Sofia 2017-11-22 00:33:16 +02:00
parent 8bc8b692a8
commit d9b6cc2165
6 changed files with 67 additions and 38 deletions

1
.gitignore vendored
View File

@ -3,5 +3,4 @@
/.mono/ /.mono/
/mono/ /mono/
/dist/ /dist/
/Properties/
*.import *.import

View 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("")]

View File

@ -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

View File

@ -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) {

View File

@ -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);
} }
//extends Node2D private void SetAddressAndPort(out string address, out int port, string defaultAddress, int defaultPort) {
if (IPAddressEdit == null || IPAddressEdit.GetText() == "") {
//# Member variables address = defaultAddress;
//var thread = Thread.new() } else {
address = IPAddressEdit.GetText();
//# This function runs in a thread! }
//# Threads always take one userdata argument port = defaultPort;
//func _bg_load(path): if (PortEdit != null && PortEdit.GetText() != "") {
// print("THREAD FUNC!") //port = PortEdit.GetText();
// # Load the resource Int32.TryParse(PortEdit.GetText(), out port);
// 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")

View File

@ -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) {