Iron out some bugs
This commit is contained in:
parent
fa71a3c02e
commit
a7b690ec9f
@ -32,6 +32,10 @@ impl INode for NetworkManager {
|
||||
.signals()
|
||||
.on_join()
|
||||
.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) {
|
||||
@ -60,6 +64,7 @@ impl INode for NetworkManager {
|
||||
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 {
|
||||
|
||||
@ -52,6 +52,10 @@ impl IPanel for CommandLinePanel {
|
||||
commands.insert("help".to_owned(), Rc::new(Box::new(HelpCommand)));
|
||||
commands.insert("host".to_string(), Rc::new(Box::new(HostCommand)));
|
||||
commands.insert("join".to_string(), Rc::new(Box::new(JoinCommand)));
|
||||
commands.insert(
|
||||
"disconnect".to_string(),
|
||||
Rc::new(Box::new(DisconnectCommand)),
|
||||
);
|
||||
|
||||
CommandLinePanel {
|
||||
input_field: None,
|
||||
@ -88,6 +92,8 @@ impl CommandLinePanel {
|
||||
pub fn on_host(port: u16);
|
||||
#[signal]
|
||||
pub fn on_join(port: String);
|
||||
#[signal]
|
||||
pub fn on_disconnect();
|
||||
|
||||
pub fn input_command(&mut self, command: String) {
|
||||
self.publish_message(format!("> {}", command), CliColor::Command);
|
||||
@ -192,3 +198,15 @@ impl Command for JoinCommand {
|
||||
"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
|
||||
Loading…
Reference in New Issue
Block a user