diff --git a/Cargo.lock b/Cargo.lock index 1a35a22..87e8d7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,9 +141,43 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "teanet" version = "0.1.0" +dependencies = [ + "thiserror", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "unicode-ident" diff --git a/godot/QuakeBall.gdextension b/godot/QuakeBall.gdextension index 6812bbe..14166ee 100644 --- a/godot/QuakeBall.gdextension +++ b/godot/QuakeBall.gdextension @@ -4,11 +4,11 @@ compatibility_minimum = 4.1 reloadable = true [libraries] -linux.debug.x86_64 = "res://../rust/target/debug/libquakeball.so" -linux.release.x86_64 = "res://../rust/target/release/libquakeball.so" -windows.debug.x86_64 = "res://../rust/target/debug/quakeball.dll" -windows.release.x86_64 = "res://../rust/target/release/quakeball.dll" -macos.debug = "res://../rust/target/debug/libquakeball.dylib" -macos.release = "res://../rust/target/release/libquakeball.dylib" -macos.debug.arm64 = "res://../rust/target/debug/libquakeball.dylib" -macos.release.arm64 = "res://../rust/target/release/libquakeball.dylib" \ No newline at end of file +linux.debug.x86_64 = "res://../target/debug/libquakeball.so" +linux.release.x86_64 = "res://../target/release/libquakeball.so" +windows.debug.x86_64 = "res://../target/debug/quakeball.dll" +windows.release.x86_64 = "res://../target/release/quakeball.dll" +macos.debug = "res://../target/debug/libquakeball.dylib" +macos.release = "res://../target/release/libquakeball.dylib" +macos.debug.arm64 = "res://../target/debug/libquakeball.dylib" +macos.release.arm64 = "res://../target/release/libquakeball.dylib" \ No newline at end of file diff --git a/rust/src/network_manager.rs b/rust/src/network_manager.rs index e6c0f27..ab9a61a 100644 --- a/rust/src/network_manager.rs +++ b/rust/src/network_manager.rs @@ -36,26 +36,50 @@ impl INode for NetworkManager { } impl NetworkManager { - pub fn host(&mut self, port: u32) { + pub fn host(&mut self, port: u16) { if self.peer.is_none() { - get_autoload_by_name::(CLI_GLOBAL_NAME) - .bind_mut() + let mut cli = get_autoload_by_name::(CLI_GLOBAL_NAME); + cli.bind_mut() .publish_message(format!("Hosting server at {}", port), CliColor::Info); - self.peer = Some(PeerKind::Server(Peer::default(), port)); + let peer = Peer::listen(Some(port)); + match peer { + Ok(peer) => { + self.peer = Some(PeerKind::Server(peer, port)); + + cli.bind_mut() + .publish_message(format!("Server hosted"), CliColor::Info); + } + Err(err) => { + cli.bind_mut() + .publish_message(format!("Error hosting server: {}", err), CliColor::Error); + } + } } } pub fn join(&mut self, addr: SocketAddr) { if self.peer.is_none() { - get_autoload_by_name::(CLI_GLOBAL_NAME) - .bind_mut() + let mut cli = get_autoload_by_name::(CLI_GLOBAL_NAME); + cli.bind_mut() .publish_message(format!("Joining server at {}", addr), CliColor::Info); - self.peer = Some(PeerKind::Client(Peer::default(), addr)); + let peer = Peer::listen(None); + match peer { + Ok(peer) => { + self.peer = Some(PeerKind::Client(peer, addr)); + + cli.bind_mut() + .publish_message(format!("Server joined"), CliColor::Info); + } + Err(err) => { + cli.bind_mut() + .publish_message(format!("Error joining server: {}", err), CliColor::Error); + } + } } } } pub enum PeerKind { Client(Peer, SocketAddr), - Server(Peer, u32), + Server(Peer, u16), } diff --git a/rust/src/ui/cli.rs b/rust/src/ui/cli.rs index a7e05af..813c0ed 100644 --- a/rust/src/ui/cli.rs +++ b/rust/src/ui/cli.rs @@ -85,7 +85,7 @@ impl IPanel for CommandLinePanel { #[godot_api] impl CommandLinePanel { #[signal] - pub fn on_host(port: u32); + pub fn on_host(port: u16); #[signal] pub fn on_join(port: String); @@ -157,7 +157,7 @@ struct HostCommand; impl Command for HostCommand { fn execute(&self, cli: &mut CommandLinePanel, params: &[&str]) { if let Some(port_str) = params.first() { - if let Ok(port) = u32::from_str_radix(*port_str, 10) { + if let Ok(port) = u16::from_str_radix(*port_str, 10) { cli.signals().on_host().emit(port); } else { cli.publish_message(format!("Invalid port: {}", port_str), CliColor::Error); diff --git a/teanet-rust b/teanet-rust index e296000..0e2166f 160000 --- a/teanet-rust +++ b/teanet-rust @@ -1 +1 @@ -Subproject commit e2960002a23ee61dccaafd6951de16fc17c0ee19 +Subproject commit 0e2166fea4a494c10bd527fc09211002b3ce2df6