listen to port with peer, report errors
This commit is contained in:
parent
edc23b3e8c
commit
7c8c298c68
34
Cargo.lock
generated
34
Cargo.lock
generated
@ -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"
|
||||
|
||||
@ -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"
|
||||
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"
|
||||
@ -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::<CommandLinePanel>(CLI_GLOBAL_NAME)
|
||||
.bind_mut()
|
||||
let mut cli = get_autoload_by_name::<CommandLinePanel>(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::<CommandLinePanel>(CLI_GLOBAL_NAME)
|
||||
.bind_mut()
|
||||
let mut cli = get_autoload_by_name::<CommandLinePanel>(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),
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit e2960002a23ee61dccaafd6951de16fc17c0ee19
|
||||
Subproject commit 0e2166fea4a494c10bd527fc09211002b3ce2df6
|
||||
Loading…
Reference in New Issue
Block a user