Implement connecting
This commit is contained in:
parent
7c8c298c68
commit
fa71a3c02e
102
Cargo.lock
generated
102
Cargo.lock
generated
@ -2,6 +2,45 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "ciborium"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e"
|
||||
dependencies = [
|
||||
"ciborium-io",
|
||||
"ciborium-ll",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ciborium-io"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757"
|
||||
|
||||
[[package]]
|
||||
name = "ciborium-ll"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9"
|
||||
dependencies = [
|
||||
"ciborium-io",
|
||||
"half",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
|
||||
|
||||
[[package]]
|
||||
name = "gdextension-api"
|
||||
version = "0.5.1"
|
||||
@ -88,6 +127,17 @@ dependencies = [
|
||||
"venial",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "half"
|
||||
version = "2.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crunchy",
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
@ -141,6 +191,36 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
@ -156,6 +236,8 @@ dependencies = [
|
||||
name = "teanet"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ciborium",
|
||||
"serde",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
@ -194,3 +276,23 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7cbbc0a705a0fd05cc3676525980d2bf5a9bc4adac6d6475209a7887cf59d19"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2e817b7b52d0c7358d3246da9d69935ebb18116b2b102b4230dac079b4862f5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
@ -33,6 +33,75 @@ impl INode for NetworkManager {
|
||||
.on_join()
|
||||
.connect_other(self, |s, addr| s.join(addr.parse().unwrap()));
|
||||
}
|
||||
|
||||
fn process(&mut self, delta: f64) {
|
||||
if let Some(peer) = &mut self.peer {
|
||||
let mut cli = get_autoload_by_name::<CommandLinePanel>(CLI_GLOBAL_NAME);
|
||||
|
||||
match peer {
|
||||
PeerKind::Client(peer, _) => match peer.poll() {
|
||||
Ok(message) => {
|
||||
if let Some(message) = message {
|
||||
match message {
|
||||
teanet::PeerMessage::NewConnection(connection) => {
|
||||
cli.bind_mut().publish_message(
|
||||
format!("Connected to: {}", connection.address),
|
||||
CliColor::Info,
|
||||
);
|
||||
}
|
||||
teanet::PeerMessage::Disconnected(connection, connection_error) => {
|
||||
cli.bind_mut().publish_message(
|
||||
format!("Disconnected from: {}", connection.address),
|
||||
CliColor::Info,
|
||||
);
|
||||
if let Some(err) = &connection_error {
|
||||
cli.bind_mut().publish_message(
|
||||
format!("Error with connection: {}", err),
|
||||
CliColor::Error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
cli.bind_mut()
|
||||
.publish_message(format!("Error: {}", err), CliColor::Info);
|
||||
}
|
||||
},
|
||||
PeerKind::Server(peer, _) => match peer.poll() {
|
||||
Ok(message) => {
|
||||
if let Some(message) = message {
|
||||
match message {
|
||||
teanet::PeerMessage::NewConnection(connection) => {
|
||||
cli.bind_mut().publish_message(
|
||||
format!("Client connected from: {}", connection.address),
|
||||
CliColor::Info,
|
||||
);
|
||||
}
|
||||
teanet::PeerMessage::Disconnected(connection, connection_error) => {
|
||||
cli.bind_mut().publish_message(
|
||||
format!("Client disconnected: {}", connection.address),
|
||||
CliColor::Info,
|
||||
);
|
||||
if let Some(err) = &connection_error {
|
||||
cli.bind_mut().publish_message(
|
||||
format!("Error with connection: {}", err),
|
||||
CliColor::Error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
cli.bind_mut()
|
||||
.publish_message(format!("Error: {}", err), CliColor::Info);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkManager {
|
||||
@ -64,11 +133,9 @@ impl NetworkManager {
|
||||
.publish_message(format!("Joining server at {}", addr), CliColor::Info);
|
||||
let peer = Peer::listen(None);
|
||||
match peer {
|
||||
Ok(peer) => {
|
||||
Ok(mut peer) => {
|
||||
peer.connect_to(addr);
|
||||
self.peer = Some(PeerKind::Client(peer, addr));
|
||||
|
||||
cli.bind_mut()
|
||||
.publish_message(format!("Server joined"), CliColor::Info);
|
||||
}
|
||||
Err(err) => {
|
||||
cli.bind_mut()
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 0e2166fea4a494c10bd527fc09211002b3ce2df6
|
||||
Subproject commit d8781b55d02060077ab52bfbe625343dd4caac9a
|
||||
Loading…
Reference in New Issue
Block a user