From 1363883dd50af8e665b556dfc16495d877ce0bce Mon Sep 17 00:00:00 2001 From: Tipragot Date: Mon, 8 Apr 2024 17:45:18 +0200 Subject: [PATCH] Remove last system Co-authored-by: CoCoSol --- Cargo.lock | 811 +------------------------------- crates/bevnet/Cargo.toml | 20 - crates/bevnet/src/lib.rs | 152 ------ crates/border-wars/Cargo.toml | 2 - crates/relay-client/Cargo.toml | 20 - crates/relay-client/src/lib.rs | 361 -------------- crates/relay-server/Cargo.toml | 22 - crates/relay-server/src/main.rs | 160 ------- crates/server/Cargo.toml | 10 + crates/server/src/main.rs | 3 + 10 files changed, 23 insertions(+), 1538 deletions(-) delete mode 100644 crates/bevnet/Cargo.toml delete mode 100644 crates/bevnet/src/lib.rs delete mode 100644 crates/relay-client/Cargo.toml delete mode 100644 crates/relay-client/src/lib.rs delete mode 100644 crates/relay-server/Cargo.toml delete mode 100644 crates/relay-server/src/main.rs create mode 100644 crates/server/Cargo.toml create mode 100644 crates/server/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 7621658..5c74ed4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,12 +175,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anyhow" -version = "1.0.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" - [[package]] name = "approx" version = "0.5.1" @@ -203,7 +197,7 @@ dependencies = [ "objc", "objc-foundation", "objc_id", - "parking_lot 0.12.1", + "parking_lot", "thiserror", "winapi", "x11rb", @@ -316,17 +310,6 @@ version = "4.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799" -[[package]] -name = "async-trait" -version = "0.1.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - [[package]] name = "atomic-waker" version = "1.1.2" @@ -339,64 +322,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "axum" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e" -dependencies = [ - "async-trait", - "axum-core", - "base64 0.21.7", - "bytes", - "futures-util", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-util", - "itoa", - "matchit", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "serde_json", - "serde_path_to_error", - "serde_urlencoded", - "sha1", - "sync_wrapper", - "tokio", - "tokio-tungstenite", - "tower", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "axum-core" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http", - "http-body", - "http-body-util", - "mime", - "pin-project-lite", - "rustversion", - "sync_wrapper", - "tower-layer", - "tower-service", - "tracing", -] - [[package]] name = "backtrace" version = "0.3.69" @@ -424,18 +349,6 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" -[[package]] -name = "bevnet" -version = "0.2.0" -dependencies = [ - "bevy", - "bincode", - "dashmap", - "relay-client", - "serde", - "uuid", -] - [[package]] name = "bevy" version = "0.12.1" @@ -515,7 +428,7 @@ dependencies = [ "futures-io", "futures-lite 1.13.0", "js-sys", - "parking_lot 0.12.1", + "parking_lot", "ron", "serde", "thiserror", @@ -1188,15 +1101,6 @@ dependencies = [ "winit", ] -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - [[package]] name = "bindgen" version = "0.69.4" @@ -1266,15 +1170,6 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - [[package]] name = "block-sys" version = "0.1.0-beta.1" @@ -1314,7 +1209,6 @@ dependencies = [ name = "border-wars" version = "0.1.0" dependencies = [ - "bevnet", "bevy", "bevy_egui", "noise", @@ -1576,22 +1470,13 @@ dependencies = [ "ndk-context", "oboe", "once_cell", - "parking_lot 0.12.1", + "parking_lot", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", "windows 0.46.0", ] -[[package]] -name = "cpufeatures" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" -dependencies = [ - "libc", -] - [[package]] name = "crc32fast" version = "1.3.2" @@ -1610,31 +1495,12 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - [[package]] name = "d3d12" version = "0.7.0" @@ -1646,19 +1512,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown 0.14.3", - "lock_api", - "once_cell", - "parking_lot_core 0.9.9", -] - [[package]] name = "dasp_sample" version = "0.11.0" @@ -1671,16 +1524,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - [[package]] name = "dispatch" version = "0.2.0" @@ -1772,7 +1615,7 @@ dependencies = [ "ecolor", "emath", "nohash-hasher", - "parking_lot 0.12.1", + "parking_lot", ] [[package]] @@ -1954,58 +1797,12 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fs2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - [[package]] name = "futures-core" version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - [[package]] name = "futures-io" version = "0.3.30" @@ -2040,66 +1837,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "gethostname" version = "0.3.0" @@ -2317,25 +2054,6 @@ dependencies = [ "svg_fmt", ] -[[package]] -name = "h2" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31d030e59af851932b72ceebadf4a2b5986dba4c3b99dd2493f8273a0f151943" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap 2.2.2", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -2368,12 +2086,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "hermit-abi" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3" - [[package]] name = "hexasphere" version = "9.1.0" @@ -2399,87 +2111,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "http" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" -dependencies = [ - "bytes", - "http", -] - -[[package]] -name = "http-body-util" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" -dependencies = [ - "bytes", - "futures-util", - "http", - "http-body", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - -[[package]] -name = "httpdate" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" - -[[package]] -name = "hyper" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "hyper-util" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" -dependencies = [ - "bytes", - "futures-util", - "http", - "http-body", - "hyper", - "pin-project-lite", - "socket2", - "tokio", -] - [[package]] name = "idna" version = "0.5.0" @@ -2794,12 +2425,6 @@ dependencies = [ "regex-automata 0.1.10", ] -[[package]] -name = "matchit" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" - [[package]] name = "memchr" version = "2.7.1" @@ -2830,12 +2455,6 @@ dependencies = [ "paste", ] -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -3040,16 +2659,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "num_enum" version = "0.5.11" @@ -3204,12 +2813,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - [[package]] name = "orbclient" version = "0.3.47" @@ -3240,17 +2843,6 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.6", -] - [[package]] name = "parking_lot" version = "0.12.1" @@ -3258,21 +2850,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.9", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "winapi", + "parking_lot_core", ] [[package]] @@ -3310,38 +2888,12 @@ dependencies = [ "indexmap 2.2.2", ] -[[package]] -name = "pin-project" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - [[package]] name = "pin-project-lite" version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "piper" version = "0.2.1" @@ -3525,15 +3077,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0d463f2884048e7153449a55166f91028d5b0ea53c79377099ce4e8cf0cf9bb" -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.3.5" @@ -3602,52 +3145,12 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" -[[package]] -name = "relay-client" -version = "0.2.0" -dependencies = [ - "home", - "log", - "mio", - "rand 0.8.5", - "tungstenite", - "uuid", -] - -[[package]] -name = "relay-server" -version = "0.2.0" -dependencies = [ - "anyhow", - "axum", - "dashmap", - "futures", - "lazy_static", - "sled", - "tokio", - "uuid", -] - [[package]] name = "renderdoc-sys" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b" -[[package]] -name = "ring" -version = "0.17.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" -dependencies = [ - "cc", - "getrandom 0.2.12", - "libc", - "spin", - "untrusted", - "windows-sys 0.48.0", -] - [[package]] name = "rodio" version = "0.17.3" @@ -3682,66 +3185,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustls" -version = "0.22.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87c9956bd9807afa1f77e0f7594af32566e830e088a5576d27c5b6f30f49d41" -dependencies = [ - "log", - "ring", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-native-certs" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" -dependencies = [ - "openssl-probe", - "rustls-pemfile", - "rustls-pki-types", - "schannel", - "security-framework", -] - -[[package]] -name = "rustls-pemfile" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35e4980fa29e4c4b212ffb3db068a564cbf560e51d3944b7c88bd8bf5bec64f4" -dependencies = [ - "base64 0.21.7", - "rustls-pki-types", -] - -[[package]] -name = "rustls-pki-types" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a716eb65e3158e90e17cd93d855216e27bde02745ab842f2cab4a39dba1bacf" - -[[package]] -name = "rustls-webpki" -version = "0.102.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - [[package]] name = "ruzstd" version = "0.4.0" @@ -3768,44 +3211,12 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "schannel" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "security-framework" -version = "2.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "serde" version = "1.0.197" @@ -3838,37 +3249,8 @@ dependencies = [ ] [[package]] -name = "serde_path_to_error" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd154a240de39fdebcf5775d2675c204d7c13cf39a4c697be6493c8e734337c" -dependencies = [ - "itoa", - "serde", -] - -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] +name = "server" +version = "0.1.0" [[package]] name = "sharded-slab" @@ -3900,22 +3282,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "sled" -version = "0.34.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935" -dependencies = [ - "crc32fast", - "crossbeam-epoch", - "crossbeam-utils", - "fs2", - "fxhash", - "libc", - "log", - "parking_lot 0.11.2", -] - [[package]] name = "slotmap" version = "1.0.7" @@ -3943,22 +3309,6 @@ dependencies = [ "serde", ] -[[package]] -name = "socket2" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" -dependencies = [ - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "spirv" version = "0.2.0+1.5.4" @@ -3981,12 +3331,6 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "svg_fmt" version = "0.4.1" @@ -4015,12 +3359,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - [[package]] name = "sysinfo" version = "0.29.11" @@ -4132,60 +3470,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "tokio" -version = "1.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "pin-project-lite", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "tokio-tungstenite" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" -dependencies = [ - "futures-util", - "log", - "tokio", - "tungstenite", -] - -[[package]] -name = "tokio-util" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", -] - [[package]] name = "toml_datetime" version = "0.6.5" @@ -4214,41 +3498,12 @@ dependencies = [ "winnow", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - [[package]] name = "tracing" version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -4332,28 +3587,6 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" -[[package]] -name = "tungstenite" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http", - "httparse", - "log", - "rand 0.8.5", - "rustls", - "rustls-native-certs", - "rustls-pki-types", - "sha1", - "thiserror", - "url", - "utf-8", -] - [[package]] name = "twox-hash" version = "1.6.3" @@ -4364,12 +3597,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - [[package]] name = "unicode-bidi" version = "0.3.15" @@ -4403,12 +3630,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - [[package]] name = "url" version = "2.5.0" @@ -4420,12 +3641,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - [[package]] name = "uuid" version = "1.7.0" @@ -4603,7 +3818,7 @@ dependencies = [ "js-sys", "log", "naga", - "parking_lot 0.12.1", + "parking_lot", "profiling", "raw-window-handle", "smallvec", @@ -4628,7 +3843,7 @@ dependencies = [ "codespan-reporting", "log", "naga", - "parking_lot 0.12.1", + "parking_lot", "profiling", "raw-window-handle", "rustc-hash", @@ -4666,7 +3881,7 @@ dependencies = [ "metal", "naga", "objc", - "parking_lot 0.12.1", + "parking_lot", "profiling", "range-alloc", "raw-window-handle", @@ -5108,9 +4323,3 @@ dependencies = [ "quote", "syn 2.0.48", ] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/crates/bevnet/Cargo.toml b/crates/bevnet/Cargo.toml deleted file mode 100644 index a5850b5..0000000 --- a/crates/bevnet/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "bevnet" -version = "0.2.0" -edition = "2021" -license = "GPL-3.0-or-later" -description = "A library for networking in Bevy." -authors = ["Tipragot "] -keywords = ["bevy", "network", "game"] -categories = ["network-programming", "game-development"] - -[lints] -workspace = true - -[dependencies] -relay-client = { path = "../relay-client" } -serde = "1.0.196" -bincode = "1.3.3" -dashmap = "5.5.3" -bevy = "0.12.1" -uuid = "1.7.0" diff --git a/crates/bevnet/src/lib.rs b/crates/bevnet/src/lib.rs deleted file mode 100644 index 62efd0d..0000000 --- a/crates/bevnet/src/lib.rs +++ /dev/null @@ -1,152 +0,0 @@ -//! A networking library for Bevy. - -use std::borrow::Cow; -use std::collections::LinkedList; - -use bevy::prelude::*; -use dashmap::DashMap; -use serde::de::DeserializeOwned; -use serde::Serialize; -pub use uuid::Uuid; - -/// A connection to a relay server. -#[derive(Resource)] -pub struct Connection(relay_client::Connection); - -/// A resource that stores the received messages. -#[derive(Resource)] -pub struct ReceivedMessages(DashMap)>>); - -impl Connection { - /// Returns the identifier of the connection. - pub const fn identifier(&self) -> Option { - self.0.identifier() - } -} - -/// A bevy plugin to make multiplayer game using a relay server. -pub struct NetworkPlugin(String); - -impl NetworkPlugin { - /// Create a new [NetworkPlugin] plugin with the given domain for the relay - /// server. - pub fn new<'a>(domain: impl Into>) -> Self { - Self(domain.into().into_owned()) - } -} - -/// Update the relay connection. -fn update_connection(mut connection: ResMut, received_messages: Res) { - let messages = connection.0.update(); - for (sender, mut message) in messages { - if message.len() < 2 { - error!("message too short received"); - continue; - } - let id_start = message.len() - 2; - let event_id = u16::from_be_bytes([message[id_start], message[id_start + 1]]); - message.truncate(id_start); - received_messages - .0 - .entry(event_id) - .or_default() - .push_back((sender, message)); - } -} - -/// A system that clear the received messages. -fn clear_received_messages(received_messages: Res) { - received_messages.0.clear(); -} - -impl Plugin for NetworkPlugin { - fn build(&self, app: &mut App) { - app.insert_resource(Connection( - relay_client::Connection::new(&self.0).expect("could not create connection"), - )) - .insert_resource(ReceivedMessages(DashMap::new())) - .add_systems(PreUpdate, update_connection) - .add_systems(PreUpdate, clear_received_messages.after(update_connection)); - } -} - -/// A resource that store the last event id used to register an [Event]. -/// -/// This is used to give an unique id to each event. -#[derive(Resource, Default)] -struct LastEventId(u16); - -/// An [Event] used to send an [Event] to another client on the relay server. -#[derive(Event)] -pub struct SendTo(pub Uuid, pub T); - -/// An [Event] used to receive an [Event] from another client on the relay -/// server. -#[derive(Event)] -pub struct Receive(pub Uuid, pub T); - -/// A trait that extends a bevy [App] to add multiplayer support. -pub trait NetworkAppExt { - /// Setup the application to manage network events of type `T`. - fn add_network_event(&mut self) -> &mut Self; -} - -impl NetworkAppExt for App { - fn add_network_event(&mut self) -> &mut Self { - // Get a new event id. - let mut event_id = self.world.get_resource_or_insert_with(LastEventId::default); - event_id.0 += 1; - let event_id = event_id.0; - - // Register the event. - self.add_event::>() - .add_event::>() - .add_systems( - PreUpdate, - (move |mut events: EventReader>, connection: Res| { - for event in events.read() { - // Get the size of the serialized event. - let size = match bincode::serialized_size(&event.1) { - Ok(size) => size, - Err(e) => { - error!("failed to serialize event: {}", e); - continue; - } - }; - - // Serialize the event we add 18 here because we will add the event id (2 - // bytes) at the end and after that, the relay client will add the target id - // at the end (16 bytes). - let mut data = Vec::with_capacity(size as usize + 18); - if let Err(e) = bincode::serialize_into(&mut data, &event.1) { - error!("failed to serialize event: {}", e); - continue; - } - - // Add the event id. - data.extend_from_slice(&event_id.to_be_bytes()); - - // Send the event. - connection.0.send(event.0, data); - } - }) - .before(update_connection), - ) - .add_systems( - PreUpdate, - (move |mut writer: EventWriter>, - received_messages: Res| { - if let Some(mut messages) = received_messages.0.get_mut(&event_id) { - while let Some((sender, message)) = messages.pop_front() { - match bincode::deserialize(&message) { - Ok(event) => writer.send(Receive(sender, event)), - Err(e) => error!("failed to deserialize event: {}", e), - } - } - } - }) - .before(clear_received_messages) - .after(update_connection), - ) - } -} diff --git a/crates/border-wars/Cargo.toml b/crates/border-wars/Cargo.toml index 68e7ebf..28720df 100644 --- a/crates/border-wars/Cargo.toml +++ b/crates/border-wars/Cargo.toml @@ -5,7 +5,6 @@ edition = "2021" license = "GPL-3.0-or-later" description = "An online turn based game." repository = "https://git.tipragot.fr/corentin/border-wars.git" -authors = ["CoCoSol"] [lints] workspace = true @@ -15,6 +14,5 @@ bevy = "0.12.1" bevy_egui = "0.24.0" noise = "0.8.2" paste = "1.0.14" -bevnet = { path = "../bevnet" } serde = "1.0.197" rand = "0.8.5" diff --git a/crates/relay-client/Cargo.toml b/crates/relay-client/Cargo.toml deleted file mode 100644 index e64f98d..0000000 --- a/crates/relay-client/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "relay-client" -version = "0.2.0" -edition = "2021" -license = "GPL-3.0-or-later" -description = "A client to use a relay server." -authors = ["Tipragot "] -keywords = ["bevy", "network", "game"] -categories = ["network-programming", "game-development"] - -[lints] -workspace = true - -[dependencies] -tungstenite = { version = "0.21.0", features = ["rustls-tls-native-roots"] } -mio = { version = "0.8.10", features = ["net", "os-poll"] } -uuid = "1.7.0" -rand = "0.8.5" -home = "0.5.9" -log = "0.4.20" diff --git a/crates/relay-client/src/lib.rs b/crates/relay-client/src/lib.rs deleted file mode 100644 index b390d21..0000000 --- a/crates/relay-client/src/lib.rs +++ /dev/null @@ -1,361 +0,0 @@ -//! A library containing a client to use a relay server. - -use std::borrow::Cow; -use std::collections::LinkedList; -use std::fs; -use std::io::{self}; -use std::net::{SocketAddr, ToSocketAddrs}; -use std::path::PathBuf; -use std::sync::Mutex; -use std::time::{Duration, Instant}; - -use log::warn; -use mio::net::TcpStream; -use rand::seq::SliceRandom; -use tungstenite::handshake::MidHandshake; -use tungstenite::stream::MaybeTlsStream; -use tungstenite::{ClientHandshake, HandshakeError, Message, WebSocket}; -use uuid::Uuid; - -/// The state of a [Connection]. -#[derive(Debug)] -enum ConnectionState { - /// The [Connection] is not connected. - Disconnected, - - /// The underlying [TcpStream] is connecting. - Connecting(TcpStream, Instant), - - /// The underlying [TcpStream] is connected. - Connected(TcpStream), - - /// The websocket handshake is in progress. - Handshaking(MidHandshake>>), - - /// The websocket handshake is finished. - Handshaked(WebSocket>), - - /// The [Connection] is registering with the relay server. - Registering(WebSocket>), - - /// The [Connection] is connected. - Active(WebSocket>), -} - -/// A connection to a relay server. -pub struct Connection { - /// The address list corresponding to the relay server. - address_list: Vec, - - /// The domain of the relay server. - domain: String, - - /// The path to the file where the identifier and secret key are stored. - data_path: PathBuf, - - /// The identifier of the connection for the relay server. - identifier: Option, - - /// The secret key used to authenticate with the relay server. - secret: Option, - - /// A list of messages that needs to be sent. - to_send: Mutex>, - - /// The state of the connection. - state: ConnectionState, -} - -impl Connection { - /// Create a new [Connection]. - pub fn new<'a>(domain: impl Into>) -> io::Result { - let domain = domain.into(); - - // Loads the identifier and secret key from disk. - let (data_path, identifier, secret) = { - // Find the relay data file path. - let mut path = home::home_dir().ok_or_else(|| { - io::Error::new(io::ErrorKind::NotFound, "could not find home directory") - })?; - path.push(".relay-data"); - - // Check if the file exists. - match false { - true => { - // Read the file and parse the identifier and secret key. - let contents = fs::read(&path)?; - if contents.len() != 32 { - return Err(io::Error::new( - io::ErrorKind::InvalidData, - "invalid data in .relay-data", - )); - } - let identifier = Uuid::from_slice(&contents[..16]).map_err(io::Error::other)?; - let secret = Uuid::from_slice(&contents[16..]).map_err(io::Error::other)?; - (path, Some(identifier), Some(secret)) - } - false => (path, None, None), - } - }; - - // Create the connection and return it. - Ok(Self { - address_list: (domain.as_ref(), 443).to_socket_addrs()?.collect(), - domain: domain.into_owned(), - data_path, - identifier, - secret, - to_send: Mutex::new(LinkedList::new()), - state: ConnectionState::Disconnected, - }) - } - - /// Get the identifier of the connection. - pub const fn identifier(&self) -> Option { - self.identifier - } - - /// Send a message to the target client. - pub fn send<'a>(&self, target_id: Uuid, message: impl Into>) { - let mut data = message.into().into_owned(); - data.extend_from_slice(target_id.as_bytes()); - if let Ok(mut to_send) = self.to_send.lock() { - to_send.push_back(Message::binary(data)); - } - } - - /// Create a new [TcpStream] to the relay server. - fn create_stream(&mut self) -> ConnectionState { - // Take a random relay address. - let Some(address) = self.address_list.choose(&mut rand::thread_rng()) else { - warn!("no relay address available"); - return ConnectionState::Disconnected; - }; - - // Create the new TCP stream. - match TcpStream::connect(address.to_owned()) { - Ok(stream) => ConnectionState::Connecting(stream, Instant::now()), - Err(e) => { - warn!("failed to start connection to the relay server: {e}"); - ConnectionState::Disconnected - } - } - } - - /// Check if the [TcpStream] of the [Connection] is connected. - fn check_connection(&mut self, stream: TcpStream, start: Instant) -> ConnectionState { - // Check for connection errors. - if let Err(e) = stream.take_error() { - warn!("failed to connect to the relay server: {e}"); - return ConnectionState::Disconnected; - } - - // Check if the stream is connected. - let connected = match stream.peek(&mut [0]) { - Ok(_) => true, - Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => true, - Err(ref e) if e.kind() == io::ErrorKind::NotConnected => false, - Err(e) => { - warn!("failed to connect to the relay server: {e}"); - return ConnectionState::Disconnected; - } - }; - - // Check if the connection has timed out. - let elapsed = start.elapsed(); - if elapsed > Duration::from_secs(5) { - warn!("connection to the relay server timed out"); - return ConnectionState::Disconnected; - } - - // Update the connection state if connected. - match connected { - true => ConnectionState::Connected(stream), - false => ConnectionState::Connecting(stream, start), - } - } - - /// Start the websocket handshake. - fn start_handshake(&mut self, stream: TcpStream) -> ConnectionState { - match tungstenite::client_tls(format!("wss://{}", self.domain), stream) { - Ok((socket, _)) => ConnectionState::Handshaked(socket), - Err(HandshakeError::Interrupted(handshake)) => ConnectionState::Handshaking(handshake), - Err(HandshakeError::Failure(e)) => { - warn!("handshake failed with the relay server: {e}"); - ConnectionState::Disconnected - } - } - } - - /// Continue the websocket handshake. - fn continue_handshake( - &mut self, - handshake: MidHandshake>>, - ) -> ConnectionState { - match handshake.handshake() { - Ok((socket, _)) => ConnectionState::Handshaked(socket), - Err(HandshakeError::Interrupted(handshake)) => ConnectionState::Handshaking(handshake), - Err(HandshakeError::Failure(e)) => { - warn!("handshake failed with the relay server: {e}"); - ConnectionState::Disconnected - } - } - } - - /// Start authentication with the relay server. - fn start_authentication( - &mut self, - mut socket: WebSocket>, - ) -> ConnectionState { - match (self.identifier, self.secret) { - (Some(identifier), Some(secret)) => { - // Create the authentication message. - let mut data = Vec::with_capacity(32); - data.extend(identifier.as_bytes()); - data.extend(secret.as_bytes()); - - // Send the authentication message. - match socket.send(Message::Binary(data)) { - Ok(()) => ConnectionState::Active(socket), - Err(e) => { - warn!("failed to send authentication message: {e}"); - ConnectionState::Disconnected - } - } - } - _ => { - // Send empty authentication message to request a new identifier and secret key. - match socket.send(Message::Binary(vec![])) { - Ok(()) => ConnectionState::Registering(socket), - Err(e) => { - warn!("failed to send registration message: {e}"); - ConnectionState::Disconnected - } - } - } - } - } - - /// Wait for the registration response. - fn get_registration_response( - &mut self, - mut socket: WebSocket>, - ) -> ConnectionState { - match socket.read() { - Ok(message) => { - // Check the message length. - let data = message.into_data(); - if data.len() != 32 { - warn!("received malformed registration response"); - return ConnectionState::Disconnected; - } - - // Extract the client identifier and secret. - self.identifier = Some(Uuid::from_slice(&data[..16]).expect("invalid identifier")); - self.secret = Some(Uuid::from_slice(&data[16..]).expect("invalid secret")); - - // Save the client identifier and secret. - fs::write(&self.data_path, data).ok(); - - // Activate the connection. - ConnectionState::Active(socket) - } - Err(tungstenite::Error::Io(ref e)) - if e.kind() == std::io::ErrorKind::WouldBlock - || e.kind() == std::io::ErrorKind::Interrupted => - { - ConnectionState::Registering(socket) - } - Err(e) => { - warn!("failed to receive registration response: {e}"); - ConnectionState::Disconnected - } - } - } - - /// Update the [Connection] by receiving and sending messages. - fn update_connection( - &mut self, - mut socket: WebSocket>, - messages: &mut LinkedList<(Uuid, Vec)>, - ) -> ConnectionState { - // Unlock the sending list. - let Ok(mut to_send) = self.to_send.lock() else { - warn!("sending list closed"); - return ConnectionState::Disconnected; - }; - - // Send messages from the send channel to the socket. - while let Some(message) = to_send.pop_front() { - match socket.send(message) { - Ok(()) => (), - Err(tungstenite::Error::Io(ref e)) - if e.kind() == std::io::ErrorKind::WouldBlock - || e.kind() == std::io::ErrorKind::Interrupted => - { - break; - } - Err(e) => { - warn!("relay connection closed: {e}"); - return ConnectionState::Disconnected; - } - } - } - - // Receive messages from the socket and send them to the receive channel. - loop { - match socket.read() { - Ok(message) => { - // Check the message length. - let mut data = message.into_data(); - if data.len() < 16 { - warn!("received malformed message with length: {}", data.len()); - continue; - } - - // Extract the sender ID. - let id_start = data.len() - 16; - let sender_id = Uuid::from_slice(&data[id_start..]).expect("invalid sender id"); - data.truncate(id_start); - - // Add the message to the message list. - messages.push_back((sender_id, data)); - } - Err(tungstenite::Error::Io(ref e)) - if e.kind() == std::io::ErrorKind::WouldBlock - || e.kind() == std::io::ErrorKind::Interrupted => - { - break; - } - Err(e) => { - warn!("relay connection closed: {e}"); - return ConnectionState::Disconnected; - } - } - } - - // Keep the connection connected. - ConnectionState::Active(socket) - } - - /// Update the [Connection] and return the received messages. - /// - /// This function will connect to the relay server if it's not already - /// connected, and will send and receive messages from the relay server - /// if it's connected. - /// - /// This function will not block the current thread. - pub fn update(&mut self) -> LinkedList<(Uuid, Vec)> { - let mut messages = LinkedList::new(); - self.state = match std::mem::replace(&mut self.state, ConnectionState::Disconnected) { - ConnectionState::Disconnected => self.create_stream(), - ConnectionState::Connecting(stream, start) => self.check_connection(stream, start), - ConnectionState::Connected(stream) => self.start_handshake(stream), - ConnectionState::Handshaking(handshake) => self.continue_handshake(handshake), - ConnectionState::Handshaked(socket) => self.start_authentication(socket), - ConnectionState::Registering(socket) => self.get_registration_response(socket), - ConnectionState::Active(socket) => self.update_connection(socket, &mut messages), - }; - messages - } -} diff --git a/crates/relay-server/Cargo.toml b/crates/relay-server/Cargo.toml deleted file mode 100644 index 1dda50e..0000000 --- a/crates/relay-server/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "relay-server" -version = "0.2.0" -edition = "2021" -license = "GPL-3.0-or-later" -description = "A relay server for bevnet." -authors = ["Tipragot "] -keywords = ["bevy", "network", "game"] -categories = ["network-programming", "game-development"] - -[lints] -workspace = true - -[dependencies] -tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] } -axum = { version = "0.7.4", features = ["ws"] } -uuid = { version = "1.7.0", features = ["v4"] } -lazy_static = "1.4.0" -futures = "0.3.30" -dashmap = "5.5.3" -anyhow = "1.0.79" -sled = "0.34.7" diff --git a/crates/relay-server/src/main.rs b/crates/relay-server/src/main.rs deleted file mode 100644 index afa29b6..0000000 --- a/crates/relay-server/src/main.rs +++ /dev/null @@ -1,160 +0,0 @@ -//! A relay server for bevnet. - -use std::io; - -use anyhow::bail; -use axum::extract::ws::{Message, WebSocket}; -use axum::extract::WebSocketUpgrade; -use axum::routing::get; -use axum::Router; -use dashmap::DashMap; -use futures::{SinkExt, StreamExt}; -use lazy_static::lazy_static; -use sled::transaction::{ConflictableTransactionResult, TransactionalTree}; -use sled::{Db, IVec}; -use tokio::sync::mpsc::{channel, Receiver, Sender}; -use uuid::Uuid; - -lazy_static! { - static ref CLIENTS: DashMap>> = DashMap::new(); - static ref DB: Db = sled::open("/data/secrets.db").expect("unable to open the database"); -} - -#[tokio::main] -async fn main() { - let app = Router::new().route( - "/", - get(|ws: WebSocketUpgrade| async { - ws.on_upgrade(|socket| async { - handle(socket).await.ok(); - }) - }), - ); - let listener = tokio::net::TcpListener::bind("0.0.0.0:80") - .await - .expect("failed to bind"); - axum::serve(listener, app).await.expect("failed to serve"); -} - -/// Create a new client and add it to the database. -fn create_client(tx: &TransactionalTree) -> ConflictableTransactionResult<(Uuid, Uuid), io::Error> { - // Generates a new identifier for the client. - let client_id = loop { - // Generates a new random identifier. - let id = Uuid::new_v4(); - - // Check if the id isn't already in the database. - if tx.get(id.as_bytes())?.is_none() { - break id; - } - }; - - // Generate a random secret for the client. - let secret = Uuid::new_v4(); - - // Add the new client to the database. - tx.insert(client_id.as_bytes(), secret.as_bytes())?; - - // Returns the client identifier and his secret. - Ok((client_id, secret)) -} - -/// Handle the websocket connection. -async fn handle(mut socket: WebSocket) -> anyhow::Result<()> { - // Receive the first request from the client. - let data = match socket.recv().await { - Some(Ok(message)) => message.into_data(), - _ => return Ok(()), - }; - - // If the request is empty it means that the client want a new identifier and - // secret, so we create them and send them to the client. - let client_id = if data.is_empty() { - // Generate the new client. - let (client_id, secret) = DB.transaction(create_client)?; - DB.flush_async().await?; - println!("{client_id} created"); - - // Send the data to the client. - let mut data = Vec::with_capacity(32); - data.extend_from_slice(client_id.as_bytes()); - data.extend_from_slice(secret.as_bytes()); - socket.send(Message::Binary(data)).await?; - - // Returns the client identifier. - client_id - } - // Otherwise it means that the client want to reuse an identifier, so it will - // send it along with his secret to prove that he is the right client. - else { - // Check for the message length to detect malformed messages. - if data.len() != 32 { - bail!("malformed message"); - } - - // Get the client identifier and secret from the message. - let client_id = Uuid::from_slice(&data[..16])?; - let secret = Uuid::from_slice(&data[16..])?; - - // Check with the database if the secret is correct. - if DB.get(client_id.as_bytes())? != Some(IVec::from(secret.as_bytes())) { - bail!("invalid secret") - } - - // Returns the client identifier. - client_id - }; - - // Handle the client connection. - println!("{client_id} connected"); - let (sender, receiver) = channel(128); - CLIENTS.insert(client_id, sender); - handle_client(socket, client_id, receiver).await.ok(); - CLIENTS.remove(&client_id); - println!("{client_id} disconnected"); - - // Returns success. - Ok(()) -} - -/// Handle the client connection. -async fn handle_client( - socket: WebSocket, - client_id: Uuid, - mut receiver: Receiver>, -) -> anyhow::Result<()> { - // Split the socket into sender and receiver. - let (mut writer, mut reader) = socket.split(); - - // Handle sending messages to the client. - tokio::spawn(async move { - while let Some(message) = receiver.recv().await { - writer.send(Message::Binary(message)).await?; - } - Ok::<(), axum::Error>(()) - }); - - // Handle messages from the client. - while let Some(Ok(message)) = reader.next().await { - // Get the target ID from the message. - let mut data = message.into_data(); - if data.len() < 16 { - bail!("malformed message"); - } - let id_start = data.len() - 16; - let target_id = Uuid::from_slice(&data[id_start..])?; - - // Write the sender ID to the message. - for (i, &byte) in client_id.as_bytes().iter().enumerate() { - data[id_start + i] = byte; - } - - // Send the message to the target client. - if let Some(sender) = CLIENTS.get(&target_id) { - sender.send(data).await?; - } - } - - // Returns success. - Ok(()) -} diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml new file mode 100644 index 0000000..dbc5494 --- /dev/null +++ b/crates/server/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "server" +version = "0.1.0" +edition = "2021" +license = "GPL-3.0-or-later" +description = "The server of Border Wars" +repository = "https://git.tipragot.fr/corentin/border-wars.git" + +# [lints] +# workspace = true diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/crates/server/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}