From 37439492a26c900dafdd6cadc057be136dd22d7b Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Wed, 19 Apr 2023 21:04:33 +0300 Subject: [PATCH] feat(client): functional login and register --- Cargo.lock | 635 +++++++++++++++++- client/Cargo.toml | 11 + client/src/api/mod.rs | 9 + client/src/api/user/login.rs | 58 ++ client/src/api/user/mod.rs | 23 + client/src/api/user/register.rs | 41 ++ client/src/macros/async_task.rs | 91 +++ client/src/macros/mod.rs | 31 + client/src/main.rs | 23 + client/src/plugins/async_tasks/mod.rs | 33 + client/src/plugins/async_tasks/req_login.rs | 41 ++ .../src/plugins/async_tasks/req_register.rs | 42 ++ client/src/plugins/menu/mod.rs | 3 +- client/src/plugins/menu/ui/login.rs | 14 +- client/src/plugins/menu/ui/mod.rs | 17 +- client/src/plugins/menu/ui/register.rs | 15 +- client/src/plugins/mod.rs | 2 + 17 files changed, 1063 insertions(+), 26 deletions(-) create mode 100644 client/src/api/mod.rs create mode 100644 client/src/api/user/login.rs create mode 100644 client/src/api/user/mod.rs create mode 100644 client/src/api/user/register.rs create mode 100644 client/src/macros/async_task.rs create mode 100644 client/src/macros/mod.rs create mode 100644 client/src/plugins/async_tasks/mod.rs create mode 100644 client/src/plugins/async_tasks/req_login.rs create mode 100644 client/src/plugins/async_tasks/req_register.rs diff --git a/Cargo.lock b/Cargo.lock index 4055cf5..365cf35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -217,6 +217,19 @@ dependencies = [ "futures-core", ] +[[package]] +name = "async-compression" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "942c7cd7ae39e91bde4820d74132e9862e62c2f386c3aa90ccf55949f5bad63a" +dependencies = [ + "flate2", + "futures-core", + "memchr", + "pin-project-lite", + "tokio", +] + [[package]] name = "async-executor" version = "1.5.1" @@ -279,6 +292,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" + [[package]] name = "bevy" version = "0.10.1" @@ -1384,6 +1403,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "encoding_rs" +version = "0.8.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +dependencies = [ + "cfg-if", +] + [[package]] name = "epaint" version = "0.21.0" @@ -1409,6 +1437,27 @@ dependencies = [ "serde", ] +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "error-code" version = "2.3.1" @@ -1468,6 +1517,12 @@ dependencies = [ "miniz_oxide 0.6.2", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "foreign-types" version = "0.3.2" @@ -1492,6 +1547,15 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures-channel" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +dependencies = [ + "futures-core", +] + [[package]] name = "futures-core" version = "0.3.28" @@ -1519,6 +1583,33 @@ dependencies = [ "waker-fn", ] +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + +[[package]] +name = "futures-task" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" + +[[package]] +name = "futures-util" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +dependencies = [ + "futures-core", + "futures-io", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "fxhash" version = "0.2.1" @@ -1658,6 +1749,25 @@ dependencies = [ "svg_fmt", ] +[[package]] +name = "h2" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17f8a914c2987b688368b5138aa05321db91f4090cf26118185672ad588bce21" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -1683,6 +1793,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "hexasphere" version = "8.1.0" @@ -1699,6 +1824,77 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "http" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "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.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab302d72a6f11a3b910431ff93aae7e773078c769f0a3ef15fb9ec692ed147d4" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "idna" version = "0.3.0" @@ -1746,6 +1942,29 @@ dependencies = [ "web-sys", ] +[[package]] +name = "io-lifetimes" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" +dependencies = [ + "hermit-abi 0.3.1", + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "ipnet" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + [[package]] name = "jni" version = "0.21.1" @@ -1759,7 +1978,7 @@ dependencies = [ "log", "thiserror", "walkdir", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -1810,6 +2029,9 @@ dependencies = [ "bevy", "bevy_editor_pls", "bevy_egui", + "futures-lite", + "reqwest", + "serde", ] [[package]] @@ -1834,6 +2056,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "linux-raw-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f508063cc7bb32987c71511216bd5a32be15bccb6a80b52df8b9d7f01fc3aa2" + [[package]] name = "lock_api" version = "0.4.9" @@ -1900,6 +2128,12 @@ dependencies = [ "objc", ] +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "miniz_oxide" version = "0.6.2" @@ -1928,7 +2162,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -1953,6 +2187,24 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "ndk" version = "0.7.0" @@ -2049,6 +2301,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi 0.2.6", + "libc", +] + [[package]] name = "num_enum" version = "0.5.11" @@ -2160,6 +2422,50 @@ dependencies = [ "winapi", ] +[[package]] +name = "openssl" +version = "0.10.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e30d8bc91859781f0a943411186324d580f2bbeb71b452fe91ae344806af3f1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.15", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d3d193fb1488ad46ffe3aaabc912cc931d02ee8518fe2959aea8ef52718b0c0" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "orbclient" version = "0.3.44" @@ -2213,7 +2519,7 @@ dependencies = [ "libc", "redox_syscall 0.2.16", "smallvec", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -2244,6 +2550,12 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkg-config" version = "0.3.26" @@ -2397,13 +2709,52 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1382d1f0a252c4bf97dc20d979a2fdd05b024acd7c2ed0f7595d7817666a157" +[[package]] +name = "reqwest" +version = "0.11.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b71749df584b7f4cac2c426c127a7c785a5106cc98f7a8feb044115f0fa254" +dependencies = [ + "async-compression", + "base64 0.21.0", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tokio-util", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "ron" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "300a51053b1cb55c80b7a9fde4120726ddf25ca241a1cbb926626f62fb136bff" dependencies = [ - "base64", + "base64 0.13.1", "bitflags", "serde", ] @@ -2420,6 +2771,26 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustix" +version = "0.37.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "722529a737f5a942fdbac3a46cee213053196737c5eaa3386d52e85b786f2659" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.48.0", +] + +[[package]] +name = "ryu" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + [[package]] name = "same-file" version = "1.0.6" @@ -2429,12 +2800,44 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +dependencies = [ + "windows-sys 0.42.0", +] + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "security-framework" +version = "2.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.160" @@ -2455,6 +2858,29 @@ dependencies = [ "syn 2.0.15", ] +[[package]] +name = "serde_json" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +dependencies = [ + "itoa", + "ryu", + "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 = "sharded-slab" version = "0.1.4" @@ -2497,6 +2923,16 @@ dependencies = [ "serde", ] +[[package]] +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "spin_sleep" version = "1.1.1" @@ -2582,6 +3018,19 @@ dependencies = [ "slotmap", ] +[[package]] +name = "tempfile" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall 0.3.5", + "rustix", + "windows-sys 0.45.0", +] + [[package]] name = "termcolor" version = "1.2.0" @@ -2647,6 +3096,46 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +[[package]] +name = "tokio" +version = "1.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" +dependencies = [ + "autocfg", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.45.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + [[package]] name = "toml_datetime" version = "0.6.1" @@ -2664,6 +3153,12 @@ dependencies = [ "winnow", ] +[[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.37" @@ -2737,6 +3232,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "try-lock" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" + [[package]] name = "ttf-parser" version = "0.18.1" @@ -2803,6 +3304,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.4" @@ -2825,6 +3332,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -3095,7 +3612,7 @@ checksum = "9e745dab35a0c4c77aa3ce42d595e13d2003d6902d6b08c9ef5fc326d08da12b" dependencies = [ "windows-implement", "windows-interface", - "windows-targets", + "windows-targets 0.42.2", ] [[package]] @@ -3120,13 +3637,37 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-sys" version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", ] [[package]] @@ -3135,13 +3676,28 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -3150,42 +3706,84 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "winit" version = "0.28.3" @@ -3212,7 +3810,7 @@ dependencies = [ "wasm-bindgen", "wayland-scanner", "web-sys", - "windows-sys", + "windows-sys 0.45.0", "x11-dl", ] @@ -3225,6 +3823,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + [[package]] name = "x11-dl" version = "2.21.0" diff --git a/client/Cargo.toml b/client/Cargo.toml index 1a288e0..7723a16 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -11,6 +11,17 @@ license = "GPL-3.0-only" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +futures-lite = "1.13.0" + +reqwest = { version = "0.11.16", features = [ "blocking", "json", "gzip" ] } + +[dependencies.serde] +version = "1.0.160" +default-features = false +features = [ + "std", + "derive" +] [dependencies.bevy] version = "0.10.1" diff --git a/client/src/api/mod.rs b/client/src/api/mod.rs new file mode 100644 index 0000000..c0c5c1d --- /dev/null +++ b/client/src/api/mod.rs @@ -0,0 +1,9 @@ +/* + * This file is part of laurelin_client + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +pub mod user; diff --git a/client/src/api/user/login.rs b/client/src/api/user/login.rs new file mode 100644 index 0000000..d18041c --- /dev/null +++ b/client/src/api/user/login.rs @@ -0,0 +1,58 @@ +/* + * This file is part of laurelin_client + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use serde::{Deserialize, Serialize}; + +use crate::NetworkingOptions; + +use super::User; + +#[derive(Deserialize)] +struct LoginResponseJson { + id: String, + created_at: String, + updated_at: String, + username: String, + token: String, +} + +impl LoginResponseJson { + fn to_user(&self) -> User { + User { + id: self.id.clone(), + created_at: self.created_at.clone(), + updated_at: self.updated_at.clone(), + username: self.username.clone(), + } + } +} + +pub type LoginResponse = Result; + +#[derive(Serialize)] +struct LoginPost { + email: String, + password: String, +} + +pub fn login(no: &mut NetworkingOptions, email: &str, password: &str) -> LoginResponse { + let res = no.req + .post(&format!("{}/user/token", &no.api_address)) + .json(&LoginPost { + email: email.to_string(), + password: password.to_string(), + }) + .send() + .unwrap(); + + let tmp: LoginResponseJson = res.json().unwrap(); + + no.user_token = tmp.token.clone(); + + Ok(tmp.to_user()) +} diff --git a/client/src/api/user/mod.rs b/client/src/api/user/mod.rs new file mode 100644 index 0000000..8557e10 --- /dev/null +++ b/client/src/api/user/mod.rs @@ -0,0 +1,23 @@ +/* + * This file is part of laurelin_client + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use serde::Deserialize; + +mod login; +pub use login::*; + +mod register; +pub use register::*; + +#[derive(Deserialize)] +pub struct User { + pub id: String, + pub created_at: String, + pub updated_at: String, + pub username: String, +} diff --git a/client/src/api/user/register.rs b/client/src/api/user/register.rs new file mode 100644 index 0000000..82b3c37 --- /dev/null +++ b/client/src/api/user/register.rs @@ -0,0 +1,41 @@ +/* + * This file is part of laurelin_client + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use serde::Serialize; + +use crate::NetworkingOptions; + +use super::User; + +pub type RegisterResponse = Result; + +#[derive(Serialize)] +struct RegisterPost { + username: String, + email: String, + password: String, +} + +pub fn register( + no: &NetworkingOptions, + username: &str, + email: &str, + password: &str, +) -> RegisterResponse { + let res = no.req + .post(&format!("{}/user", &no.api_address)) + .json(&RegisterPost { + username: username.to_string(), + email: email.to_string(), + password: password.to_string(), + }) + .send() + .unwrap(); + + Ok(res.json().unwrap()) +} diff --git a/client/src/macros/async_task.rs b/client/src/macros/async_task.rs new file mode 100644 index 0000000..48ac443 --- /dev/null +++ b/client/src/macros/async_task.rs @@ -0,0 +1,91 @@ +/* + * This file is part of laurelin_client + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +#[macro_export] +macro_rules! async_task_start_call { + ($call_event_type:ty, $call_type:expr, |$ev:ident| $func:expr) => { + pub fn start_call( + mut commands: Commands, + mut start_ev_r: EventReader<$call_event_type>, + ) { + for ev in start_ev_r.iter() { + let thread_pool = AsyncComputeTaskPool::get(); + let $ev = ev.clone(); + let task = thread_pool.spawn(async move { + $func + }); + commands.spawn($call_type(task)); + } + } + }; + + ($call_event_type:ty, $call_type:expr, |$ev:ident, $no:ident| $func:expr) => { + pub fn start_call( + mut commands: Commands, + mut start_ev_r: EventReader<$call_event_type>, + no: Res + ) { + for ev in start_ev_r.iter() { + let thread_pool = AsyncComputeTaskPool::get(); + let $ev = ev.clone(); + let mut $no = no.clone(); + let task = thread_pool.spawn(async move { + $func + }); + commands.spawn($call_type(task)); + } + } + }; +} + +#[macro_export] +macro_rules! async_task_handle_call { + ($call_type:ty, |$response:ident| $handler_func:expr) => { + pub fn handle_call( + mut commands: Commands, + mut tasks: Query<(Entity, &mut $call_type)>, + ) { + match tasks.get_single_mut() { + Ok((entity, mut task)) => { + if let Some($response) = future::block_on(future::poll_once(&mut task.0)) { + $handler_func; + + // remove the task + commands.entity(entity).remove::<$call_type>(); + commands.entity(entity).despawn_recursive(); + } + } + // NOTE: don't do anything if the wanted thingy doesn't exist + _ => {} + } + } + }; + + ($call_type:ty, |$response:ident, $menu_data:ident| $handler_func:expr) => { + pub fn handle_call( + mut commands: Commands, + mut tasks: Query<(Entity, &mut $call_type)>, + mut $menu_data: ResMut, + ) { + match tasks.get_single_mut() { + Ok((entity, mut task)) => { + if let Some($response) = future::block_on(future::poll_once(&mut task.0)) { + $handler_func; + + // remove the task + commands.entity(entity).remove::<$call_type>(); + commands.entity(entity).despawn_recursive(); + } + } + // NOTE: don't do anything if the wanted thingy doesn't exist + _ => {} + } + } + }; + +} diff --git a/client/src/macros/mod.rs b/client/src/macros/mod.rs new file mode 100644 index 0000000..f4cec30 --- /dev/null +++ b/client/src/macros/mod.rs @@ -0,0 +1,31 @@ +/* + * This file is part of laurelin_client + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +mod async_task; + +/* +use crate::{async_task_start_call, async_task_handle_call}; + +use bevy::{prelude::*, tasks::{Task, AsyncComputeTaskPool}}; +use futures_lite::future; + +struct SomeResponse {} + +#[derive(Component)] +struct SomeCall(Task); + +struct SomeCallEvent; + +async_task_start_call!(SomeCallEvent, SomeCall, { + SomeResponse {} +}); + +async_task_handle_call!(SomeCall, { + +}); +*/ diff --git a/client/src/main.rs b/client/src/main.rs index 1c7330b..893e80d 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -10,6 +10,8 @@ use bevy::prelude::*; use bevy_editor_pls::EditorPlugin; use bevy_egui::EguiPlugin; +mod api; +mod macros; mod util; mod plugins; @@ -47,6 +49,16 @@ fn main() { // add the top level app state app.add_state::(); + // holds networking options and a request agent + app.insert_resource(NetworkingOptions { + api_address: "http://localhost:8080/api".to_string(), + req: reqwest::blocking::Client::new(), + user_token: "".to_string(), + }); + + // has handlers for all async tasks + app.add_plugin(plugins::AsyncTasksPlugin); + app.add_plugin(plugins::MenuPlugin); app.add_startup_system(setup); @@ -59,3 +71,14 @@ fn setup(mut commands: Commands) { let camera_bundle = Camera3dBundle::default(); commands.spawn(camera_bundle); } + +#[derive(Clone, Resource)] +pub struct NetworkingOptions { + /// api address with no trailing slash + api_address: String, + /// reqwest agent + /// NOTE: mainly for the future, because it can hold cookies + req: reqwest::blocking::Client, + /// feels wrong storing this here but "it's temporary" + user_token: String, +} diff --git a/client/src/plugins/async_tasks/mod.rs b/client/src/plugins/async_tasks/mod.rs new file mode 100644 index 0000000..747d434 --- /dev/null +++ b/client/src/plugins/async_tasks/mod.rs @@ -0,0 +1,33 @@ +/* + * This file is part of laurelin_client + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use bevy::prelude::*; + +mod req_login; +pub use req_login::LoginCallEvent; + +mod req_register; +pub use req_register::RegisterCallEvent; + +pub struct AsyncTasksPlugin; + +impl Plugin for AsyncTasksPlugin { + fn build(&self, app: &mut App) { + app + .add_event::() + .add_event::() + .add_systems( + ( + req_login::start_call, + req_login::handle_call, + req_register::start_call, + req_register::handle_call, + ).chain() + ); + } +} diff --git a/client/src/plugins/async_tasks/req_login.rs b/client/src/plugins/async_tasks/req_login.rs new file mode 100644 index 0000000..0d25a12 --- /dev/null +++ b/client/src/plugins/async_tasks/req_login.rs @@ -0,0 +1,41 @@ +/* + * This file is part of laurelin_client + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use crate::{ + async_task_start_call, async_task_handle_call, + api::{self, user::LoginResponse}, NetworkingOptions, + plugins::{menu::MenuData, MenuUIState}, +}; + +use bevy::{prelude::*, tasks::{Task, AsyncComputeTaskPool}}; +use futures_lite::future; + +#[derive(Component)] +pub struct LoginCall(Task); + +#[derive(Clone)] +pub struct LoginCallEvent { + pub email: String, + pub password: String, +} + +async_task_start_call!(LoginCallEvent, LoginCall, |ev, no| { + let res = api::user::login(&mut no, &ev.email, &ev.password); + + res +}); + +async_task_handle_call!(LoginCall, |response, menu_data| { + match response { + Err(_err) => panic!("login failed, handle me"), + Ok(resp) => { + info!("logged in {}", resp.username); + menu_data.ui_state = MenuUIState::Main; + } + } +}); diff --git a/client/src/plugins/async_tasks/req_register.rs b/client/src/plugins/async_tasks/req_register.rs new file mode 100644 index 0000000..74ea700 --- /dev/null +++ b/client/src/plugins/async_tasks/req_register.rs @@ -0,0 +1,42 @@ +/* + * This file is part of laurelin_client + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use crate::{ + async_task_start_call, async_task_handle_call, + api::{self, user::RegisterResponse}, NetworkingOptions, + plugins::{menu::MenuData, MenuUIState}, +}; + +use bevy::{prelude::*, tasks::{Task, AsyncComputeTaskPool}}; +use futures_lite::future; + +#[derive(Component)] +pub struct RegisterCall(Task); + +#[derive(Clone)] +pub struct RegisterCallEvent { + pub username: String, + pub email: String, + pub password: String, +} + +async_task_start_call!(RegisterCallEvent, RegisterCall, |ev, no| { + let res = api::user::register(&mut no, &ev.username, &ev.email, &ev.password); + + res +}); + +async_task_handle_call!(RegisterCall, |response, menu_data| { + match response { + Err(_err) => panic!("register failed, handle me"), + Ok(resp) => { + info!("registered {}", resp.username); + menu_data.ui_state = MenuUIState::Main; + } + } +}); diff --git a/client/src/plugins/menu/mod.rs b/client/src/plugins/menu/mod.rs index d165a98..f399961 100644 --- a/client/src/plugins/menu/mod.rs +++ b/client/src/plugins/menu/mod.rs @@ -32,7 +32,7 @@ enum MenuState { #[derive(Resource)] pub struct MenuData { - ui_state: MenuUIState, + pub ui_state: MenuUIState, error: String, @@ -68,6 +68,7 @@ pub enum MenuUIState { Loading, // for waiting for requests to finish Login, Register, + Main, } diff --git a/client/src/plugins/menu/ui/login.rs b/client/src/plugins/menu/ui/login.rs index 8201d5b..bc9c7f0 100644 --- a/client/src/plugins/menu/ui/login.rs +++ b/client/src/plugins/menu/ui/login.rs @@ -6,13 +6,18 @@ * See LICENSE for licensing information. */ +use bevy::prelude::*; use bevy_egui::egui; -use crate::util::egui::password; +use crate::{util::egui::password, plugins::LoginCallEvent}; use super::{MenuData, MenuUIState}; -pub fn view(ui: &mut egui::Ui, data: &mut MenuData) { +pub fn view( + ui: &mut egui::Ui, + data: &mut MenuData, + login_ev_w: &mut EventWriter, +) { ui.horizontal(|ui| { ui.label("Email:"); ui.text_edit_singleline(&mut data.login_email) @@ -31,7 +36,10 @@ pub fn view(ui: &mut egui::Ui, data: &mut MenuData) { data.error.clear(); data.ui_state = MenuUIState::Loading; - // use dem fields to do stuff + login_ev_w.send(LoginCallEvent { + email: data.login_email.clone(), + password: data.login_password.clone(), + }); } }); diff --git a/client/src/plugins/menu/ui/mod.rs b/client/src/plugins/menu/ui/mod.rs index 0fdee78..edfe67e 100644 --- a/client/src/plugins/menu/ui/mod.rs +++ b/client/src/plugins/menu/ui/mod.rs @@ -9,12 +9,19 @@ use bevy::prelude::*; use bevy_egui::{EguiContexts, egui}; +use crate::plugins::{LoginCallEvent, RegisterCallEvent}; + pub use super::{MenuData, MenuUIState}; mod login; mod register; -pub fn ui(mut contexts: EguiContexts, mut data: ResMut) { +pub fn ui( + mut contexts: EguiContexts, + mut data: ResMut, + mut login_ev_w: EventWriter, + mut register_ev_w: EventWriter, +) { egui::Window::new(format!("{:?}", data.ui_state)) .collapsible(false) .resizable(false) @@ -27,10 +34,10 @@ pub fn ui(mut contexts: EguiContexts, mut data: ResMut) { ui.label("something may or may not be happening"); }); } - MenuUIState::Login => login::view(ui, &mut data), - MenuUIState::Register => register::view(ui, &mut data), - _ => { - ui.spinner(); + MenuUIState::Login => login::view(ui, &mut data, &mut login_ev_w), + MenuUIState::Register => register::view(ui, &mut data, &mut register_ev_w), + MenuUIState::Main => { + ui.label("main menu"); } } }); diff --git a/client/src/plugins/menu/ui/register.rs b/client/src/plugins/menu/ui/register.rs index 87f6846..78dcde6 100644 --- a/client/src/plugins/menu/ui/register.rs +++ b/client/src/plugins/menu/ui/register.rs @@ -6,13 +6,18 @@ * See LICENSE for licensing information. */ +use bevy::prelude::*; use bevy_egui::egui; -use crate::util::egui::password; +use crate::{util::egui::password, plugins::RegisterCallEvent}; use super::{MenuData, MenuUIState}; -pub fn view(ui: &mut egui::Ui, data: &mut MenuData) { +pub fn view( + ui: &mut egui::Ui, + data: &mut MenuData, + register_ev_w: &mut EventWriter, +) { ui.horizontal(|ui| { ui.label("Username:"); ui.text_edit_singleline(&mut data.register_username) @@ -40,7 +45,11 @@ pub fn view(ui: &mut egui::Ui, data: &mut MenuData) { data.error.clear(); data.ui_state = MenuUIState::Loading; - // do stuff with fields + register_ev_w.send(RegisterCallEvent { + username: data.register_username.clone(), + email: data.register_email.clone(), + password: data.register_password.clone(), + }); } }); }); diff --git a/client/src/plugins/mod.rs b/client/src/plugins/mod.rs index 47658c9..244dec9 100644 --- a/client/src/plugins/mod.rs +++ b/client/src/plugins/mod.rs @@ -9,3 +9,5 @@ mod menu; pub use menu::*; +mod async_tasks; +pub use async_tasks::*; -- 2.44.1