Iron out some bugs

This commit is contained in:
Sofia 2026-07-16 01:59:31 +03:00
parent fa71a3c02e
commit a7b690ec9f
3 changed files with 33 additions and 1 deletions

View File

@ -32,6 +32,10 @@ impl INode for NetworkManager {
.signals() .signals()
.on_join() .on_join()
.connect_other(self, |s, addr| s.join(addr.parse().unwrap())); .connect_other(self, |s, addr| s.join(addr.parse().unwrap()));
cli.bind_mut()
.signals()
.on_disconnect()
.connect_other(self, |s| s.disconnect());
} }
fn process(&mut self, delta: f64) { fn process(&mut self, delta: f64) {
@ -60,6 +64,7 @@ impl INode for NetworkManager {
CliColor::Error, CliColor::Error,
); );
} }
self.peer = None;
} }
} }
} }
@ -144,6 +149,15 @@ impl NetworkManager {
} }
} }
} }
pub fn disconnect(&mut self) {
if let Some(peer) = &mut self.peer {
match peer {
PeerKind::Client(peer, _) => peer.close(),
PeerKind::Server(peer, _) => peer.close(),
}
}
}
} }
pub enum PeerKind { pub enum PeerKind {

View File

@ -52,6 +52,10 @@ impl IPanel for CommandLinePanel {
commands.insert("help".to_owned(), Rc::new(Box::new(HelpCommand))); commands.insert("help".to_owned(), Rc::new(Box::new(HelpCommand)));
commands.insert("host".to_string(), Rc::new(Box::new(HostCommand))); commands.insert("host".to_string(), Rc::new(Box::new(HostCommand)));
commands.insert("join".to_string(), Rc::new(Box::new(JoinCommand))); commands.insert("join".to_string(), Rc::new(Box::new(JoinCommand)));
commands.insert(
"disconnect".to_string(),
Rc::new(Box::new(DisconnectCommand)),
);
CommandLinePanel { CommandLinePanel {
input_field: None, input_field: None,
@ -88,6 +92,8 @@ impl CommandLinePanel {
pub fn on_host(port: u16); pub fn on_host(port: u16);
#[signal] #[signal]
pub fn on_join(port: String); pub fn on_join(port: String);
#[signal]
pub fn on_disconnect();
pub fn input_command(&mut self, command: String) { pub fn input_command(&mut self, command: String) {
self.publish_message(format!("> {}", command), CliColor::Command); self.publish_message(format!("> {}", command), CliColor::Command);
@ -192,3 +198,15 @@ impl Command for JoinCommand {
"Joins server at a given address:port" "Joins server at a given address:port"
} }
} }
#[derive(Clone)]
struct DisconnectCommand;
impl Command for DisconnectCommand {
fn execute(&self, cli: &mut CommandLinePanel, _params: &[&str]) {
cli.signals().on_disconnect().emit();
}
fn help(&self) -> &str {
"Disconnects from the server, or stops hosting the server"
}
}

@ -1 +1 @@
Subproject commit d8781b55d02060077ab52bfbe625343dd4caac9a Subproject commit f3429ff4e86bb68b1fe42f908aaf561b3a9f3976