From f1d16e40a18ecaf707d68ae3f29dc2f112a3cbb5 Mon Sep 17 00:00:00 2001 From: Maple Nebel Date: Mon, 13 Jul 2026 23:47:15 +0200 Subject: [PATCH] progress --- Cargo.lock | 1079 ++--------------- proxy/Cargo.toml | 2 + proxy/src/insecure.rs | 3 +- proxy/src/lib.rs | 2 +- proxy/src/secure.rs | 3 +- prudpv0/Cargo.toml | 9 +- prudpv0/src/crypto/friends_insecure.rs | 22 +- prudpv0/src/crypto/friends_secure.rs | 32 +- prudpv0/src/crypto/mod.rs | 5 +- prudpv0/src/lib.rs | 2 +- prudpv0/src/packet.rs | 4 +- prudpv0/src/server.rs | 18 +- rnex-core-deprecated/src/lib.rs | 5 - rnex-protocols/ds-protos/Cargo.toml | 3 + rnex-protocols/ds-protos/src/datastore.rs | 6 +- rnex-protocols/ds-protos/src/lib.rs | 1 + rnex-rmc/src/rmc_struct.rs | 3 +- rnex-server-nex-modules/rnex-base/src/user.rs | 8 +- rnex-server-nex-modules/rnex-ds/Cargo.toml | 7 +- .../rnex-ds/src/datastore.rs | 78 +- rnex-server-nex-modules/rnex-ds/src/lib.rs | 12 +- .../rnex-ds/src/s3presigner.rs | 1 + rnex-server-nex-modules/rnex-fpd/Cargo.toml | 16 + .../rnex-fpd/src}/friends_handler.rs | 396 +++--- rnex-server-nex-modules/rnex-fpd/src/lib.rs | 102 ++ rnex-server-nex-modules/rnex-fpd/src/main.rs | 3 - rnex-server-nex-modules/rnex-msg/Cargo.toml | 5 +- rnex-server-nex-modules/rnex-msg/src/lib.rs | 40 + rnex-server-nex-modules/rnex-msg/src/main.rs | 3 - rnex-server-nex-modules/rnex-msg/src/user.rs | 22 +- rnex-server-nex-modules/rnex-rk/Cargo.toml | 9 + rnex-server-nex-modules/rnex-rk/src/lib.rs | 86 ++ rnex-server-nex-modules/rnex-rk/src/main.rs | 3 - rnex-server-nex-modules/rnex-rk/src/user.rs | 95 +- rnex-util/Cargo.toml | 1 + rnex-util/src/account.rs | 14 + 36 files changed, 719 insertions(+), 1381 deletions(-) rename {rnex-core-deprecated/src/nex => rnex-server-nex-modules/rnex-fpd/src}/friends_handler.rs (83%) create mode 100644 rnex-server-nex-modules/rnex-fpd/src/lib.rs delete mode 100644 rnex-server-nex-modules/rnex-fpd/src/main.rs create mode 100644 rnex-server-nex-modules/rnex-msg/src/lib.rs delete mode 100644 rnex-server-nex-modules/rnex-msg/src/main.rs create mode 100644 rnex-server-nex-modules/rnex-rk/src/lib.rs delete mode 100644 rnex-server-nex-modules/rnex-rk/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index cda40e3..a9c3ad0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -206,15 +206,6 @@ version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3" -[[package]] -name = "arc-swap" -version = "1.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c049c0be4daef0b145cb3555416b3b8ef5b7888a38aea1a3a155801fe7b0810b" -dependencies = [ - "rustversion", -] - [[package]] name = "async-trait" version = "0.1.89" @@ -247,487 +238,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" -[[package]] -name = "aws-config" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47712fde1909402600ccfbb26e47d482d2e58bb9e9e603d9f17e67cc435a6319" -dependencies = [ - "aws-credential-types", - "aws-runtime", - "aws-sdk-sso", - "aws-sdk-ssooidc", - "aws-sdk-sts", - "aws-smithy-async", - "aws-smithy-http", - "aws-smithy-json", - "aws-smithy-runtime", - "aws-smithy-runtime-api", - "aws-smithy-schema", - "aws-smithy-types", - "aws-types", - "bytes", - "fastrand", - "hex", - "http 1.4.0", - "sha1 0.10.7", - "time", - "tokio", - "tracing", - "url", - "zeroize", -] - -[[package]] -name = "aws-credential-types" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e93964ffdaf57857f544be3666a5f57570bb699e934700f11b49708f61bb556e" -dependencies = [ - "aws-smithy-async", - "aws-smithy-runtime-api", - "aws-smithy-types", - "zeroize", -] - -[[package]] -name = "aws-lc-rs" -version = "1.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4342d8937fc7e5dd9b1c60292261c0670c882a2cd1719cfc11b1af41731e32ad" -dependencies = [ - "aws-lc-sys", - "zeroize", -] - -[[package]] -name = "aws-lc-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d9ceb1da931507a12f4fccea479dccd00da1943e1b4ae72d8e502d707361444" -dependencies = [ - "cc", - "cmake", - "dunce", - "fs_extra", - "pkg-config", -] - -[[package]] -name = "aws-runtime" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7816e98ee912159f45d307e5ee6bfea4a335a55aee15f7f3e32f81a6f3000f1d" -dependencies = [ - "aws-credential-types", - "aws-sigv4", - "aws-smithy-async", - "aws-smithy-eventstream", - "aws-smithy-http", - "aws-smithy-runtime", - "aws-smithy-runtime-api", - "aws-smithy-types", - "aws-types", - "bytes", - "bytes-utils", - "fastrand", - "http 0.2.12", - "http 1.4.0", - "http-body 0.4.6", - "http-body 1.0.1", - "percent-encoding", - "pin-project-lite", - "tracing", - "uuid", -] - -[[package]] -name = "aws-sdk-s3" -version = "1.138.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c29be98554a0deea25d4eaca131240a224dcbcaf20357e35cc432e17b721ab5" -dependencies = [ - "arc-swap", - "aws-credential-types", - "aws-runtime", - "aws-sigv4", - "aws-smithy-async", - "aws-smithy-checksums", - "aws-smithy-eventstream", - "aws-smithy-http", - "aws-smithy-json", - "aws-smithy-observability", - "aws-smithy-runtime", - "aws-smithy-runtime-api", - "aws-smithy-schema", - "aws-smithy-types", - "aws-smithy-xml", - "aws-types", - "bytes", - "fastrand", - "hex", - "hmac 0.13.0", - "http 0.2.12", - "http 1.4.0", - "http-body 1.0.1", - "lru", - "percent-encoding", - "regex-lite", - "sha2 0.11.0", - "tracing", - "url", -] - -[[package]] -name = "aws-sdk-sso" -version = "1.103.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0469f435f645ad2162cfb463b15bde37115966ee3acf2d87fb4871ee309b8401" -dependencies = [ - "arc-swap", - "aws-credential-types", - "aws-runtime", - "aws-smithy-async", - "aws-smithy-http", - "aws-smithy-json", - "aws-smithy-observability", - "aws-smithy-runtime", - "aws-smithy-runtime-api", - "aws-smithy-schema", - "aws-smithy-types", - "aws-types", - "bytes", - "fastrand", - "http 0.2.12", - "http 1.4.0", - "regex-lite", - "tracing", -] - -[[package]] -name = "aws-sdk-ssooidc" -version = "1.105.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "085faefb253f770655e162b9304321e62a1e71adf7f019ee1f4454228a377b3a" -dependencies = [ - "arc-swap", - "aws-credential-types", - "aws-runtime", - "aws-smithy-async", - "aws-smithy-http", - "aws-smithy-json", - "aws-smithy-observability", - "aws-smithy-runtime", - "aws-smithy-runtime-api", - "aws-smithy-schema", - "aws-smithy-types", - "aws-types", - "bytes", - "fastrand", - "http 0.2.12", - "http 1.4.0", - "regex-lite", - "tracing", -] - -[[package]] -name = "aws-sdk-sts" -version = "1.108.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c72b08911d8128dd360fe1b22a9fec0fa8b552dde8ec828dcf20ef5ec974e9f" -dependencies = [ - "arc-swap", - "aws-credential-types", - "aws-runtime", - "aws-smithy-async", - "aws-smithy-http", - "aws-smithy-json", - "aws-smithy-observability", - "aws-smithy-query", - "aws-smithy-runtime", - "aws-smithy-runtime-api", - "aws-smithy-schema", - "aws-smithy-types", - "aws-smithy-xml", - "aws-types", - "fastrand", - "http 0.2.12", - "http 1.4.0", - "regex-lite", - "tracing", -] - -[[package]] -name = "aws-sigv4" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723c2234ad7511ceef63eab016b7ba6ff7c55590fefb96fa8467af014a07309f" -dependencies = [ - "aws-credential-types", - "aws-smithy-eventstream", - "aws-smithy-http", - "aws-smithy-runtime-api", - "aws-smithy-types", - "bytes", - "crypto-bigint", - "form_urlencoded", - "hex", - "hmac 0.13.0", - "http 0.2.12", - "http 1.4.0", - "p256", - "percent-encoding", - "sha2 0.11.0", - "subtle", - "time", - "tracing", - "zeroize", -] - -[[package]] -name = "aws-smithy-async" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f02e407fb3b54891734224b9ffac8a71fdd35f542500fa1af95754a6b2beb316" -dependencies = [ - "futures-util", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "aws-smithy-checksums" -version = "0.65.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67ecd999972b58e67cab052f5129906c08c25883bd0788ceefc55ef97d61307" -dependencies = [ - "aws-smithy-http", - "aws-smithy-types", - "bytes", - "crc-fast", - "hex", - "http 1.4.0", - "http-body 1.0.1", - "http-body-util", - "md-5 0.11.0", - "pin-project-lite", - "sha1 0.11.0", - "sha2 0.11.0", - "tracing", -] - -[[package]] -name = "aws-smithy-eventstream" -version = "0.61.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a9381123ab62d20c13082b151f30f962a3b112b727345394536dfa39a482944" -dependencies = [ - "aws-smithy-types", - "bytes", - "crc32fast", -] - -[[package]] -name = "aws-smithy-http" -version = "0.64.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37843d9add67c3aff5856f409c6dc315d3cdff60f9c0cb5b670dab1e9920306d" -dependencies = [ - "aws-smithy-eventstream", - "aws-smithy-runtime-api", - "aws-smithy-types", - "bytes", - "bytes-utils", - "futures-core", - "futures-util", - "http 1.4.0", - "http-body 1.0.1", - "http-body-util", - "percent-encoding", - "pin-project-lite", - "pin-utils", - "tracing", -] - -[[package]] -name = "aws-smithy-http-client" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "635d23afda0a6ab48d666c4d447c4873e8d1e83518a2be2093122397e50b838e" -dependencies = [ - "aws-smithy-async", - "aws-smithy-runtime-api", - "aws-smithy-types", - "h2 0.3.27", - "h2 0.4.13", - "http 0.2.12", - "http 1.4.0", - "http-body 0.4.6", - "hyper 0.14.32", - "hyper 1.9.0", - "hyper-rustls 0.24.2", - "hyper-rustls 0.27.9", - "hyper-util", - "pin-project-lite", - "rustls 0.21.12", - "rustls 0.23.41", - "rustls-native-certs", - "rustls-pki-types", - "tokio", - "tokio-rustls 0.26.4", - "tower", - "tracing", -] - -[[package]] -name = "aws-smithy-json" -version = "0.63.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dc65a121adb4b33729919fcfa14fa36fb33c1555a8f06bb0e2188dbfdc1d9ef" -dependencies = [ - "aws-smithy-runtime-api", - "aws-smithy-schema", - "aws-smithy-types", -] - -[[package]] -name = "aws-smithy-observability" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e86338c869539a581bf161247762a6e87f92c5c075060057b5ed6d06632ed0c" -dependencies = [ - "aws-smithy-runtime-api", -] - -[[package]] -name = "aws-smithy-query" -version = "0.61.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd22a6ba36e3f113cb8d5b3d1fe0ed31c76ee608ef63322d753bb8d2c9479e77" -dependencies = [ - "aws-smithy-types", - "urlencoding", -] - -[[package]] -name = "aws-smithy-runtime" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bea94a9ff8464016338c851e24b472d7131c388c88898a502e781815b2ee6045" -dependencies = [ - "aws-smithy-async", - "aws-smithy-http", - "aws-smithy-http-client", - "aws-smithy-observability", - "aws-smithy-runtime-api", - "aws-smithy-schema", - "aws-smithy-types", - "bytes", - "fastrand", - "http 0.2.12", - "http 1.4.0", - "http-body 0.4.6", - "http-body 1.0.1", - "http-body-util", - "pin-project-lite", - "pin-utils", - "tokio", - "tracing", -] - -[[package]] -name = "aws-smithy-runtime-api" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ed1ebe6e0a95ea84570225f5a8208dec4b8f77e61a9b0d6f51773fcb4612f0" -dependencies = [ - "aws-smithy-async", - "aws-smithy-runtime-api-macros", - "aws-smithy-types", - "bytes", - "http 0.2.12", - "http 1.4.0", - "pin-project-lite", - "tokio", - "tracing", - "zeroize", -] - -[[package]] -name = "aws-smithy-runtime-api-macros" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "221eaa237ddf1ca79b60d1372aad77e47f9c0ea5b3ce5099da8c61d027dc77b3" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.117", -] - -[[package]] -name = "aws-smithy-schema" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d56e0a4e53127a632224e43633b0fe045fa9e1e3cfc68b9830f1115e103f910" -dependencies = [ - "aws-smithy-runtime-api", - "aws-smithy-types", - "http 1.4.0", -] - -[[package]] -name = "aws-smithy-types" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6dc683efb34b9e755675b37fedbe0103141e5b6df7bdc9eb6967756a8c167d8" -dependencies = [ - "base64-simd", - "bytes", - "bytes-utils", - "futures-core", - "http 0.2.12", - "http 1.4.0", - "http-body 0.4.6", - "http-body 1.0.1", - "http-body-util", - "itoa", - "num-integer", - "pin-project-lite", - "pin-utils", - "ryu", - "serde", - "time", - "tokio", - "tokio-util", -] - -[[package]] -name = "aws-smithy-xml" -version = "0.61.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea3f68eec3607f02acd24067969ce2abc6ba16aa7d5ce59ca450ed2fb5f78957" -dependencies = [ - "aws-smithy-runtime-api", - "aws-smithy-schema", - "aws-smithy-types", - "xmlparser", -] - -[[package]] -name = "aws-types" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e957a6c6dbce82b7a91f44231c09273159703769f447cbe85e854dfe9cf67f86" -dependencies = [ - "aws-credential-types", - "aws-smithy-async", - "aws-smithy-runtime-api", - "aws-smithy-schema", - "aws-smithy-types", - "rustc_version", - "tracing", -] - [[package]] name = "axum" version = "0.8.9" @@ -738,7 +248,7 @@ dependencies = [ "bytes", "futures-util", "http 1.4.0", - "http-body 1.0.1", + "http-body", "http-body-util", "itoa", "matchit", @@ -762,7 +272,7 @@ dependencies = [ "bytes", "futures-core", "http 1.4.0", - "http-body 1.0.1", + "http-body", "http-body-util", "mime", "pin-project-lite", @@ -796,28 +306,12 @@ dependencies = [ "windows-link", ] -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - [[package]] name = "base64" version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" -[[package]] -name = "base64-simd" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "339abbe78e73178762e23bea9dfd08e697eb3f3301cd4be981c0f78ba5859195" -dependencies = [ - "outref", - "vsimd", -] - [[package]] name = "base64ct" version = "1.8.3" @@ -898,16 +392,6 @@ version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" -[[package]] -name = "bytes-utils" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dafe3a8757b027e2be6e4e5601ed563c55989fcf1546e933c66c8eb3a058d35" -dependencies = [ - "bytes", - "either", -] - [[package]] name = "bytestring" version = "1.5.1" @@ -924,8 +408,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d16d90359e986641506914ba71350897565610e87ce0ad9e6f28569db3dd5c6d" dependencies = [ "find-msvc-tools", - "jobserver", - "libc", "shlex", ] @@ -986,15 +468,6 @@ dependencies = [ "inout 0.2.2", ] -[[package]] -name = "cmake" -version = "0.1.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" -dependencies = [ - "cc", -] - [[package]] name = "cmov" version = "0.5.3" @@ -1010,12 +483,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "const-oid" version = "0.10.2" @@ -1031,6 +498,35 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "cookie" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + +[[package]] +name = "cookie_store" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b2c103cf610ec6cae3da84a766285b42fd16aad564758459e6ecf128c75206" +dependencies = [ + "cookie", + "document-features", + "idna", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "time", + "url", +] + [[package]] name = "core-foundation" version = "0.10.1" @@ -1086,16 +582,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "217698eaf96b4a3f0bc4f3662aaa55bdf913cd54d7204591faa790070c6d0853" -[[package]] -name = "crc-fast" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e75b2483e97a5a7da73ac68a05b629f9c53cff58d8ed1c77866079e18b00dba5" -dependencies = [ - "digest 0.10.7", - "spin 0.10.0", -] - [[package]] name = "crc32fast" version = "1.5.0" @@ -1120,18 +606,6 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core 0.6.4", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.7" @@ -1180,24 +654,13 @@ dependencies = [ "uuid", ] -[[package]] -name = "der" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" -dependencies = [ - "const-oid 0.9.6", - "pem-rfc7468 0.7.0", - "zeroize", -] - [[package]] name = "der" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a69dedd701da44b0536442edf09c81a64b0ab97a7a4a5e3d1971f00027cbc63d" dependencies = [ - "pem-rfc7468 1.0.0", + "pem-rfc7468", "zeroize", ] @@ -1240,7 +703,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", - "const-oid 0.9.6", "crypto-common 0.1.7", "subtle", ] @@ -1252,7 +714,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ "block-buffer 0.12.0", - "const-oid 0.10.2", + "const-oid", "crypto-common 0.2.1", "ctutils", ] @@ -1278,6 +740,15 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "document-features" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61" +dependencies = [ + "litrs", +] + [[package]] name = "dotenv" version = "0.15.0" @@ -1290,26 +761,6 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" -[[package]] -name = "dunce" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der 0.7.10", - "digest 0.10.7", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - [[package]] name = "either" version = "1.15.0" @@ -1319,26 +770,6 @@ dependencies = [ "serde", ] -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest 0.10.7", - "ff", - "generic-array", - "group", - "pem-rfc7468 0.7.0", - "pkcs8", - "rand_core 0.6.4", - "sec1", - "subtle", - "zeroize", -] - [[package]] name = "encoding_rs" version = "0.8.35" @@ -1391,16 +822,6 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" -[[package]] -name = "ff" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393" -dependencies = [ - "rand_core 0.6.4", - "subtle", -] - [[package]] name = "find-msvc-tools" version = "0.1.9" @@ -1443,7 +864,7 @@ checksum = "5e139bc46ca777eb5efaf62df0ab8cc5fd400866427e56c68b22e414e53bd3be" dependencies = [ "futures-core", "futures-sink", - "spin 0.9.8", + "spin", ] [[package]] @@ -1488,12 +909,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fs_extra" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" - [[package]] name = "futures" version = "0.3.32" @@ -1601,7 +1016,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -1647,36 +1061,6 @@ version = "0.32.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7" -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core 0.6.4", - "subtle", -] - -[[package]] -name = "h2" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0beca50380b1fc32983fc1cb4587bfa4bb9e78fc259aad4a0032d2080309222d" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http 0.2.12", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "h2" version = "0.4.13" @@ -1802,17 +1186,6 @@ dependencies = [ "itoa", ] -[[package]] -name = "http-body" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" -dependencies = [ - "bytes", - "http 0.2.12", - "pin-project-lite", -] - [[package]] name = "http-body" version = "1.0.1" @@ -1832,7 +1205,7 @@ dependencies = [ "bytes", "futures-core", "http 1.4.0", - "http-body 1.0.1", + "http-body", "pin-project-lite", ] @@ -1858,30 +1231,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "hyper" -version = "0.14.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2 0.3.27", - "http 0.2.12", - "http-body 0.4.6", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2 0.5.10", - "tokio", - "tower-service", - "tracing", - "want", -] - [[package]] name = "hyper" version = "1.9.0" @@ -1892,9 +1241,9 @@ dependencies = [ "bytes", "futures-channel", "futures-core", - "h2 0.4.13", + "h2", "http 1.4.0", - "http-body 1.0.1", + "http-body", "httparse", "httpdate", "itoa", @@ -1904,21 +1253,6 @@ dependencies = [ "want", ] -[[package]] -name = "hyper-rustls" -version = "0.24.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" -dependencies = [ - "futures-util", - "http 0.2.12", - "hyper 0.14.32", - "log", - "rustls 0.21.12", - "tokio", - "tokio-rustls 0.24.1", -] - [[package]] name = "hyper-rustls" version = "0.27.9" @@ -1926,12 +1260,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" dependencies = [ "http 1.4.0", - "hyper 1.9.0", + "hyper", "hyper-util", - "rustls 0.23.41", - "rustls-native-certs", + "rustls", "tokio", - "tokio-rustls 0.26.4", + "tokio-rustls", "tower-service", ] @@ -1941,7 +1274,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" dependencies = [ - "hyper 1.9.0", + "hyper", "hyper-util", "pin-project-lite", "tokio", @@ -1956,7 +1289,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper 1.9.0", + "hyper", "hyper-util", "native-tls", "tokio", @@ -1975,8 +1308,8 @@ dependencies = [ "futures-channel", "futures-util", "http 1.4.0", - "http-body 1.0.1", - "hyper 1.9.0", + "http-body", + "hyper", "ipnet", "libc", "percent-encoding", @@ -2177,16 +1510,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" -[[package]] -name = "jobserver" -version = "0.1.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" -dependencies = [ - "getrandom 0.4.2", - "libc", -] - [[package]] name = "js-sys" version = "0.3.97" @@ -2257,6 +1580,12 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" +[[package]] +name = "litrs" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092" + [[package]] name = "local-waker" version = "0.1.4" @@ -2278,15 +1607,6 @@ version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" -[[package]] -name = "lru" -version = "0.16.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39" -dependencies = [ - "hashbrown 0.16.1", -] - [[package]] name = "macros" version = "0.1.1" @@ -2439,15 +1759,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6673768db2d862beb9b39a78fdcb1a69439615d5794a1be50caa9bc92c81967" -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -2699,24 +2010,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "outref" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a80800c0488c3a21695ea981a54918fbb37abf04f4d0720c453632255e2ff0e" - -[[package]] -name = "p256" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" -dependencies = [ - "ecdsa", - "elliptic-curve", - "primeorder", - "sha2 0.10.9", -] - [[package]] name = "parking" version = "2.2.1" @@ -2752,15 +2045,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" -[[package]] -name = "pem-rfc7468" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" -dependencies = [ - "base64ct", -] - [[package]] name = "pem-rfc7468" version = "1.0.0" @@ -2813,22 +2097,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der 0.7.10", - "spki", -] - [[package]] name = "pkg-config" version = "0.3.33" @@ -2869,15 +2137,6 @@ dependencies = [ "syn 2.0.117", ] -[[package]] -name = "primeorder" -version = "0.13.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" -dependencies = [ - "elliptic-curve", -] - [[package]] name = "proc-macro2" version = "1.0.106" @@ -2949,7 +2208,9 @@ dependencies = [ "prudpv0", "prudpv1", "rnex-prudp", + "rnex-server", "tokio", + "tracing", ] [[package]] @@ -2973,12 +2234,15 @@ version = "0.1.0" dependencies = [ "bytemuck", "cfg-if", - "hmac 0.12.1", - "md-5 0.10.6", + "hmac 0.13.0", + "md-5 0.11.0", "proxy-common", - "rc4 0.1.0", + "rc4 0.2.0", "rnex-prudp", + "rnex-rmc", + "rnex-util", "tokio", + "tracing", "typenum", ] @@ -3074,15 +2338,6 @@ dependencies = [ "rand_core 0.9.5", ] -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom 0.2.17", -] - [[package]] name = "rand_core" version = "0.9.5" @@ -3171,12 +2426,12 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2 0.4.13", + "h2", "http 1.4.0", - "http-body 1.0.1", + "http-body", "http-body-util", - "hyper 1.9.0", - "hyper-rustls 0.27.9", + "hyper", + "hyper-rustls", "hyper-tls", "hyper-util", "js-sys", @@ -3199,16 +2454,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac 0.12.1", - "subtle", -] - [[package]] name = "ring" version = "0.17.14" @@ -3278,8 +2523,6 @@ dependencies = [ name = "rnex-ds" version = "0.1.0" dependencies = [ - "aws-config", - "aws-sdk-s3", "base64", "chrono", "futures", @@ -3311,6 +2554,24 @@ dependencies = [ [[package]] name = "rnex-fpd" version = "0.1.0" +dependencies = [ + "bytemuck", + "chrono", + "hex", + "hmac 0.13.0", + "md-5 0.11.0", + "nex-account", + "rand 0.10.2", + "rnex-base", + "rnex-fpd-protos", + "rnex-rmc", + "rnex-server", + "rnex-util", + "sqlx", + "thiserror", + "tokio", + "tracing", +] [[package]] name = "rnex-fpd-protos" @@ -3352,6 +2613,12 @@ dependencies = [ [[package]] name = "rnex-msg" version = "0.1.0" +dependencies = [ + "rnex-msg-protos", + "rnex-rmc", + "rnex-server", + "tokio", +] [[package]] name = "rnex-msg-protos" @@ -3398,6 +2665,17 @@ dependencies = [ [[package]] name = "rnex-rk" version = "0.1.0" +dependencies = [ + "rnex-rk-protos", + "rnex-rmc", + "rnex-server", + "rnex-util", + "serde", + "serde_json", + "tokio", + "tracing", + "ureq", +] [[package]] name = "rnex-rk-protos" @@ -3467,6 +2745,7 @@ dependencies = [ "bytemuck", "chrono", "md-5 0.11.0", + "nex-account", "thiserror", "tokio", "tracing", @@ -3500,46 +2779,21 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "rustls" -version = "0.21.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" -dependencies = [ - "log", - "ring", - "rustls-webpki 0.101.7", - "sct", -] - [[package]] name = "rustls" version = "0.23.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b92b125634d9b795e7beca796cc790df15a7fb38323bf3196fda83292d06b1f" dependencies = [ - "aws-lc-rs", "log", "once_cell", "ring", "rustls-pki-types", - "rustls-webpki 0.103.13", + "rustls-webpki", "subtle", "zeroize", ] -[[package]] -name = "rustls-native-certs" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dab5152771c58876a2146916e53e35057e1a4dfa2b9df0f0305b07f611fdea4d" -dependencies = [ - "openssl-probe", - "rustls-pki-types", - "schannel", - "security-framework", -] - [[package]] name = "rustls-pki-types" version = "1.15.0" @@ -3549,23 +2803,12 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rustls-webpki" -version = "0.101.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "rustls-webpki" version = "0.103.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" dependencies = [ - "aws-lc-rs", "ring", "rustls-pki-types", "untrusted", @@ -3598,30 +2841,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "sct" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der 0.7.10", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "security-framework" version = "3.7.0" @@ -3828,17 +3047,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha1" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" -dependencies = [ - "cfg-if", - "cpufeatures 0.2.17", - "digest 0.10.7", -] - [[package]] name = "sha1" version = "0.11.0" @@ -3897,16 +3105,6 @@ dependencies = [ "libc", ] -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest 0.10.7", - "rand_core 0.6.4", -] - [[package]] name = "simd-adler32" version = "0.3.9" @@ -3984,22 +3182,6 @@ dependencies = [ "lock_api", ] -[[package]] -name = "spin" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5fe4ccb98d9c292d56fec89a5e07da7fc4cf0dc11e156b41793132775d3e591" - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der 0.7.10", -] - [[package]] name = "sqlx" version = "0.9.0" @@ -4022,6 +3204,7 @@ dependencies = [ "base64", "bytes", "cfg-if", + "chrono", "crc", "crossbeam-queue", "either", @@ -4095,6 +3278,7 @@ dependencies = [ "bitflags", "byteorder", "bytes", + "chrono", "crc", "digest 0.11.3", "dotenvy", @@ -4105,7 +3289,7 @@ dependencies = [ "log", "percent-encoding", "serde", - "sha1 0.11.0", + "sha1", "sha2 0.11.0", "sqlx-core", "thiserror", @@ -4122,6 +3306,7 @@ dependencies = [ "base64", "bitflags", "byteorder", + "chrono", "crc", "dotenvy", "etcetera", @@ -4154,6 +3339,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "488e99c397a62007e4229aec669a179816339afc6d2620ca6fa420dbee2e982c" dependencies = [ "atoi", + "chrono", "flume", "form_urlencoded", "futures-channel", @@ -4383,23 +3569,13 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-rustls" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" -dependencies = [ - "rustls 0.21.12", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" dependencies = [ - "rustls 0.23.41", + "rustls", "tokio", ] @@ -4437,11 +3613,11 @@ dependencies = [ "axum", "base64", "bytes", - "h2 0.4.13", + "h2", "http 1.4.0", - "http-body 1.0.1", + "http-body", "http-body-util", - "hyper 1.9.0", + "hyper", "hyper-timeout", "hyper-util", "percent-encoding", @@ -4524,7 +3700,7 @@ dependencies = [ "bytes", "futures-util", "http 1.4.0", - "http-body 1.0.1", + "http-body", "pin-project-lite", "tower", "tower-layer", @@ -4681,13 +3857,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dea7109cdcd5864d4eeb1b58a1648dc9bf520360d7af16ec26d0a9354bafcfc0" dependencies = [ "base64", - "der 0.8.1", + "cookie_store", + "der", "flate2", "log", "native-tls", "percent-encoding", - "rustls 0.23.41", + "rustls", "rustls-pki-types", + "serde", + "serde_json", "ureq-proto", "utf8-zero", "webpki-root-certs", @@ -4775,12 +3954,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" -[[package]] -name = "vsimd" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64" - [[package]] name = "want" version = "0.3.1" @@ -5209,12 +4382,6 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" -[[package]] -name = "xmlparser" -version = "0.13.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" - [[package]] name = "yoke" version = "0.8.2" diff --git a/proxy/Cargo.toml b/proxy/Cargo.toml index 6e4500f..57273e1 100644 --- a/proxy/Cargo.toml +++ b/proxy/Cargo.toml @@ -13,6 +13,8 @@ prudpv1 = { path = "../prudpv1", optional = true } proxy-common = { path = "../proxy-common" } cfg-if = "1.0.4" rnex-prudp = { path = "../rnex-prudp" } +rnex-server = { path = "../rnex-server" } +tracing = "0.1.44" [features] prudpv0 = ["dep:prudpv0"] diff --git a/proxy/src/insecure.rs b/proxy/src/insecure.rs index 6dbed45..1574ecb 100644 --- a/proxy/src/insecure.rs +++ b/proxy/src/insecure.rs @@ -1,6 +1,6 @@ use proxy::edge_node_dc_callback; use proxy_common::{ProxyStartupParam, setup_edge_node_connection}; -use rnex_core::common::with_setup; +use rnex_server::with_setup; #[tokio::main] async fn main() { @@ -11,6 +11,7 @@ async fn main() { setup_edge_node_connection(¶m, edge_node_dc_callback).await; proxy::start_insecure(param).await; + Ok(()) }) .await; } diff --git a/proxy/src/lib.rs b/proxy/src/lib.rs index ea5b02c..444ca56 100644 --- a/proxy/src/lib.rs +++ b/proxy/src/lib.rs @@ -1,7 +1,7 @@ use std::process::abort; use cfg_if::cfg_if; -use log::error; +use tracing::error; cfg_if! { if #[cfg(feature = "prudpv0")]{ diff --git a/proxy/src/secure.rs b/proxy/src/secure.rs index 8e7212f..7901177 100644 --- a/proxy/src/secure.rs +++ b/proxy/src/secure.rs @@ -1,6 +1,6 @@ use proxy::edge_node_dc_callback; use proxy_common::{ProxyStartupParam, setup_edge_node_connection}; -use rnex_core::common::with_setup; +use rnex_server::with_setup; #[tokio::main] async fn main() { @@ -10,6 +10,7 @@ async fn main() { setup_edge_node_connection(¶m, edge_node_dc_callback).await; proxy::start_secure(param).await; + Ok(()) }) .await; } diff --git a/prudpv0/Cargo.toml b/prudpv0/Cargo.toml index 4429315..33dcdb5 100644 --- a/prudpv0/Cargo.toml +++ b/prudpv0/Cargo.toml @@ -8,14 +8,17 @@ workspace = true [dependencies] rnex-prudp = { path = "../rnex-prudp" } +rnex-util = { path = "../rnex-util" } +rnex-rmc = { path = "../rnex-rmc" } tokio = { version = "1.47.0", features = ["full"] } bytemuck = { version = "1.23.1", features = ["derive"] } typenum = "1.18.0" -rc4 = "0.1.0" +rc4 = "0.2.0" cfg-if = "1.0.4" proxy-common = {path = "../proxy-common"} -hmac = "0.12.1" -md-5 = "^0.10.6" +hmac = "0.13.0" +md-5 = "0.11.0" +tracing = "0.1.44" [features] prudpv0 = [] diff --git a/prudpv0/src/crypto/friends_insecure.rs b/prudpv0/src/crypto/friends_insecure.rs index e914836..9172512 100644 --- a/prudpv0/src/crypto/friends_insecure.rs +++ b/prudpv0/src/crypto/friends_insecure.rs @@ -3,13 +3,11 @@ use std::io::Write; use hmac::Mac; use md5::{Digest, Md5}; use rc4::{KeyInit, Rc4, StreamCipher}; -use rnex_core::{ - PID, - prudp::{ - encryption::{DEFAULT_KEY, EncryptionPair}, - types_flags::{TypesFlags, types::DATA}, - }, +use rnex_prudp::{ + encryption::{DEFAULT_KEY, EncryptionPair}, + types_flags::{TypesFlags, types::DATA}, }; +use rnex_util::PID; use typenum::U5; use crate::crypto::{ @@ -19,7 +17,7 @@ use crate::crypto::{ }; pub struct InsecureInstance { - pair: EncryptionPair>, + pair: EncryptionPair, self_signat: [u8; 4], #[allow(dead_code)] remote_signat: [u8; 4], @@ -41,8 +39,8 @@ impl CryptoInstance for InsecureInstance { [0x78, 0x56, 0x34, 0x12] } else { let mut hash = Md5::new(); - hash.write(ACCESS_KEY.as_bytes()).unwrap(); - let mut hmac = ::new_from_slice(&hash.finalize().as_slice()) + hash.update(ACCESS_KEY.as_bytes()); + let mut hmac = HmacMd5::new_from_slice(&hash.finalize().as_slice()) .expect("unable to create hmac md5"); hmac.update(data); hmac.finalize().into_bytes()[0..4].try_into().unwrap() @@ -57,7 +55,7 @@ pub struct Insecure(); impl Crypto for Insecure { type Instance = InsecureInstance; - fn new() -> Self { + async fn new() -> Self { Self() } fn calculate_checksum(&self, data: &[u8]) -> u8 { @@ -72,7 +70,9 @@ impl Crypto for Insecure { ) -> Option<(Self::Instance, Vec)> { Some(( InsecureInstance { - pair: EncryptionPair::init_both(|| Rc4::new(&DEFAULT_KEY)), + pair: EncryptionPair::init_both(|| { + Rc4::new_from_slice(DEFAULT_KEY).expect("incorrect key size") + }), self_signat, remote_signat, }, diff --git a/prudpv0/src/crypto/friends_secure.rs b/prudpv0/src/crypto/friends_secure.rs index ca63ccf..545a6dd 100644 --- a/prudpv0/src/crypto/friends_secure.rs +++ b/prudpv0/src/crypto/friends_secure.rs @@ -1,17 +1,13 @@ use hmac::Mac; use md5::{Digest, Md5}; use rc4::{KeyInit, Rc4, StreamCipher}; -use rnex_core::{ - PID, - executables::common::SECURE_SERVER_ACCOUNT, - nex::account::Account, - prudp::{ - encryption::EncryptionPair, - ticket::read_secure_connection_data, - types_flags::{TypesFlags, types::DATA}, - }, - rmc::structures::RmcSerialize, +use rnex_prudp::{ + encryption::EncryptionPair, + ticket::read_secure_connection_data, + types_flags::{TypesFlags, types::DATA}, }; +use rnex_rmc::serialization::RmcSerialize; +use rnex_util::{PID, account::Account}; use std::io::Write; use typenum::U16; @@ -22,7 +18,7 @@ use crate::crypto::{ }; pub struct SecureInstance { - pair: EncryptionPair>, + pair: EncryptionPair, uid: PID, self_signat: [u8; 4], #[allow(dead_code)] @@ -45,8 +41,8 @@ impl CryptoInstance for SecureInstance { [0x78, 0x56, 0x34, 0x12] } else { let mut hash = Md5::new(); - hash.write(ACCESS_KEY.as_bytes()).unwrap(); - let mut hmac = ::new_from_slice(&hash.finalize().as_slice()) + hash.update(ACCESS_KEY.as_bytes()); + let mut hmac = HmacMd5::new_from_slice(&hash.finalize().as_slice()) .expect("unable to create hmac md5"); hmac.update(data); hmac.finalize().into_bytes()[0..4].try_into().unwrap() @@ -57,12 +53,16 @@ impl CryptoInstance for SecureInstance { } } -pub struct Secure(&'static Account); +pub struct Secure(Account); impl Crypto for Secure { type Instance = SecureInstance; - fn new() -> Self { - Self(&SECURE_SERVER_ACCOUNT) + async fn new() -> Self { + Self( + Account::from_nexact(2, "Quazal Rendez-Vous") + .await + .expect("unable to get account info"), + ) } fn calculate_checksum(&self, data: &[u8]) -> u8 { common_checksum(ACCESS_KEY, data) diff --git a/prudpv0/src/crypto/mod.rs b/prudpv0/src/crypto/mod.rs index 829f7c5..6429e5a 100644 --- a/prudpv0/src/crypto/mod.rs +++ b/prudpv0/src/crypto/mod.rs @@ -1,5 +1,6 @@ use cfg_if::cfg_if; -use rnex_core::{PID, prudp::types_flags::TypesFlags}; +use rnex_prudp::types_flags::TypesFlags; +use rnex_util::PID; mod common_crypto; @@ -12,7 +13,7 @@ pub trait CryptoInstance: Send + 'static { pub trait Crypto: Send + Sync + 'static { type Instance: CryptoInstance; - fn new() -> Self; + async fn new() -> Self; fn calculate_checksum(&self, data: &[u8]) -> u8; fn instantiate( &self, diff --git a/prudpv0/src/lib.rs b/prudpv0/src/lib.rs index 86afe42..ac0d559 100644 --- a/prudpv0/src/lib.rs +++ b/prudpv0/src/lib.rs @@ -1,7 +1,7 @@ use cfg_if::cfg_if; cfg_if! { if #[cfg(feature = "prudpv0")] { - use log::info; + use tracing::info; use proxy_common::ProxyStartupParam; use std::env; use std::net::SocketAddrV4; diff --git a/prudpv0/src/packet.rs b/prudpv0/src/packet.rs index b78102f..ad5e40f 100644 --- a/prudpv0/src/packet.rs +++ b/prudpv0/src/packet.rs @@ -1,6 +1,5 @@ use bytemuck::{Pod, Zeroable, try_from_bytes, try_from_bytes_mut}; -use log::{info, warn}; -use rnex_core::prudp::{ +use rnex_prudp::{ types_flags::{ TypesFlags, flags::HAS_SIZE, @@ -8,6 +7,7 @@ use rnex_core::prudp::{ }, virtual_port::VirtualPort, }; +use tracing::{info, warn}; use crate::crypto::{Crypto, CryptoInstance}; diff --git a/prudpv0/src/server.rs b/prudpv0/src/server.rs index 96b6416..eecf069 100644 --- a/prudpv0/src/server.rs +++ b/prudpv0/src/server.rs @@ -5,24 +5,22 @@ use std::{ time::Duration, }; -use log::{error, info, warn}; use proxy_common::{ProxyStartupParam, new_backend_connection}; -use rnex_core::{ - prudp::{ - socket_addr::PRUDPSockAddr, - types_flags::{ - flags::{ACK, NEED_ACK, RELIABLE}, - types::{CONNECT, DATA, DISCONNECT, PING, SYN}, - }, +use rnex_prudp::{ + socket_addr::PRUDPSockAddr, + types_flags::{ + flags::{ACK, NEED_ACK, RELIABLE}, + types::{CONNECT, DATA, DISCONNECT, PING, SYN}, }, - util::{SendingBufferConnection, SplittableBufferConnection}, }; +use rnex_util::{SendingBufferConnection, SplittableBufferConnection}; use tokio::{ net::UdpSocket, spawn, sync::{Mutex, RwLock}, time::{Instant, sleep}, }; +use tracing::{error, info, warn}; use crate::{ crypto::{Crypto, CryptoInstance}, @@ -528,7 +526,7 @@ impl Server { .expect("unable to bind socket"); Self { socket, - crypto: C::new(), + crypto: C::new().await, connections: RwLock::new(HashMap::new()), param, } diff --git a/rnex-core-deprecated/src/lib.rs b/rnex-core-deprecated/src/lib.rs index 89dcfb7..63ea799 100644 --- a/rnex-core-deprecated/src/lib.rs +++ b/rnex-core-deprecated/src/lib.rs @@ -4,11 +4,6 @@ #![allow(async_fn_in_trait)] //#![warn(missing_docs)] -#[cfg(feature = "big_pid")] -pub type PID = i64; -#[cfg(not(feature = "big_pid"))] -pub type PID = i32; - pub use ctor::ctor; pub mod prudp; diff --git a/rnex-protocols/ds-protos/Cargo.toml b/rnex-protocols/ds-protos/Cargo.toml index 42d535b..a69fd5a 100644 --- a/rnex-protocols/ds-protos/Cargo.toml +++ b/rnex-protocols/ds-protos/Cargo.toml @@ -8,5 +8,8 @@ ctor = "1.0.8" rnex-rmc = { path = "../../rnex-rmc" } rnex-base-protos = { path = "../base-protos" } +[feature] +datastore = [] + [lints] workspace = true diff --git a/rnex-protocols/ds-protos/src/datastore.rs b/rnex-protocols/ds-protos/src/datastore.rs index f26852e..94bedaa 100644 --- a/rnex-protocols/ds-protos/src/datastore.rs +++ b/rnex-protocols/ds-protos/src/datastore.rs @@ -22,14 +22,14 @@ pub struct Permission { pub recipient_ids: Vec, } -#[derive(RmcSerialize, Clone, Default)] +#[derive(RmcSerialize, Clone, Default, Debug)] #[rmc_struct(0)] pub struct RatingInfoWithSlot { pub slot: i8, pub rating: RatingInfo, } -#[derive(RmcSerialize, Clone, Default)] +#[derive(RmcSerialize, Clone, Default, Debug)] #[rmc_struct(0)] pub struct RatingInfo { pub total_value: i64, @@ -46,7 +46,7 @@ pub struct GetMetaParam { pub access_password: i64, } -#[derive(RmcSerialize, Clone, Default)] +#[derive(RmcSerialize, Clone, Default, Debug)] #[rmc_struct(0)] pub struct GetMetaInfo { pub dataid: i64, diff --git a/rnex-protocols/ds-protos/src/lib.rs b/rnex-protocols/ds-protos/src/lib.rs index 3a90e51..bfd29e0 100644 --- a/rnex-protocols/ds-protos/src/lib.rs +++ b/rnex-protocols/ds-protos/src/lib.rs @@ -1,4 +1,5 @@ #![allow(async_fn_in_trait)] +#![cfg(feature = "datastore")] pub mod datastore; use datastore::{DataStore, RawDataStore, RawDataStoreInfo, RemoteDataStore}; diff --git a/rnex-rmc/src/rmc_struct.rs b/rnex-rmc/src/rmc_struct.rs index fa7b315..d3bc13a 100644 --- a/rnex-rmc/src/rmc_struct.rs +++ b/rnex-rmc/src/rmc_struct.rs @@ -1,4 +1,3 @@ -#[cfg(not(feature = "rmc_struct_header"))] use std::io::Read; use std::{ fmt::Arguments, @@ -102,7 +101,7 @@ pub fn read_struct( version: u8, pred: impl FnOnce(&mut SubRead) -> Result, ) -> Result { - use crate::rmc::structures::Error::VersionMismatch; + use crate::serialization::Error::VersionMismatch; use v_byte_helpers::IS_BIG_ENDIAN; use v_byte_helpers::ReadExtensions; let ver: u8 = reader.read_struct(IS_BIG_ENDIAN)?; diff --git a/rnex-server-nex-modules/rnex-base/src/user.rs b/rnex-server-nex-modules/rnex-base/src/user.rs index 46d7a80..4383f52 100644 --- a/rnex-server-nex-modules/rnex-base/src/user.rs +++ b/rnex-server-nex-modules/rnex-base/src/user.rs @@ -122,13 +122,7 @@ impl Secure for BaseUser { println!("{:?}", station_urls); /* - let mut users = self.matchmake_manager.users.write().await; - users.insert(cid, self.this.clone()); - drop(users); - let mut users = self.matchmake_manager.users_by_pid.write().await; - users.insert(self.pid, self.this.clone()); - drop(users); - */ + */ let stations = get_station_urls(&station_urls, self.addr, self.pid, cid).await?; diff --git a/rnex-server-nex-modules/rnex-ds/Cargo.toml b/rnex-server-nex-modules/rnex-ds/Cargo.toml index c61b373..1773ae2 100644 --- a/rnex-server-nex-modules/rnex-ds/Cargo.toml +++ b/rnex-server-nex-modules/rnex-ds/Cargo.toml @@ -10,12 +10,10 @@ rnex-base = { path = "../rnex-base" } rnex-base-protos = { path = "../../rnex-protocols/base-protos" } rnex-ds-protos = { path = "../../rnex-protocols/ds-protos" } rnex-server = { path = "../../rnex-server" } -sqlx = "0.9.0" +sqlx = { version = "0.9.0", features = ["chrono"] } tracing = "0.1.44" thiserror = "2.0.18" chrono = "0.4.45" -aws-sdk-s3 = "1.138.0" -aws-config = "1.9.0" sha2 = "0.11.0" hmac = "0.13.0" base64 = "0.22.1" @@ -24,5 +22,8 @@ hex = "0.4.3" urlencoding = "2.1.3" futures = "0.3.32" +[features] +datastore = [] + [lints] workspace = true diff --git a/rnex-server-nex-modules/rnex-ds/src/datastore.rs b/rnex-server-nex-modules/rnex-ds/src/datastore.rs index e897375..19e72e7 100644 --- a/rnex-server-nex-modules/rnex-ds/src/datastore.rs +++ b/rnex-server-nex-modules/rnex-ds/src/datastore.rs @@ -1,5 +1,5 @@ use chrono::Utc; -use futures::future::join_all; +use futures::{TryStreamExt, future::join_all}; use rnex_base::user::BaseUser; use rnex_ds_protos::{ LocalDatastoreProtocol, @@ -11,8 +11,8 @@ use rnex_ds_protos::{ DataStorePrepareGetParam, DataStoreRateObjectParam, DataStoreRatingTarget, DataStoreReportCourseParam, DataStoreReqGetInfo, DataStoreSearchParam, DataStoreUploadCourseRecordParam, GetMetaInfo, GetMetaParam, KeyValue, Permission, - PersistenceTarget, PreparePostParam, RatingInfo, RatingInfoWithSlot, - RatingInitParamWithSlot, ReqPostInfo, + PersistenceTarget, PreparePostParam, RateCustomRankingParam, RatingInfo, + RatingInfoWithSlot, RatingInitParamWithSlot, ReqPostInfo, }, }; use rnex_rmc::{qbuffer::QBuffer, qresult::QResult, response::ErrorCode, rmc_struct}; @@ -20,12 +20,13 @@ use rnex_server::PassthroughInitModule; use rnex_util::{PID, date_time::DateTime}; use sqlx::query; use std::convert; -use tracing::{error, info, warn}; +use tracing::{error, info, instrument, warn}; use crate::{DatastoreManager, s3presigner::S3Presigner}; // todo: refactor this further to make some of the helper functions attached to the user and some to // the manager and also move the usages of pid into the helper functions attached to user +#[derive(Debug)] #[rmc_struct(DatastoreProtocol)] pub struct DatastoreUser { pub base: PassthroughInitModule, @@ -33,6 +34,7 @@ pub struct DatastoreUser { } impl DatastoreUser { + #[instrument] fn map_row_to_meta_info( &self, row_data_id: i64, @@ -88,6 +90,7 @@ impl DatastoreUser { } } + #[instrument] pub async fn check_object_availability( &self, data_id: i64, @@ -121,6 +124,7 @@ impl DatastoreUser { Ok(()) } + #[instrument] pub async fn get_object_ratings( &self, data_id: i64, @@ -158,6 +162,7 @@ impl DatastoreUser { Ok(ratings) } + #[instrument] pub async fn get_object_info_by_data_id( &self, data_id: i64, @@ -210,6 +215,7 @@ impl DatastoreUser { )) } + #[instrument] async fn get_object_info_by_persistence_target( &self, target: PersistenceTarget, @@ -271,6 +277,7 @@ impl DatastoreUser { )) } + #[instrument] async fn get_buffer_queues_by_data_id_and_slot( &self, data_id: i64, @@ -300,13 +307,13 @@ impl DatastoreUser { Ok(buffer_queues) } + #[instrument] fn verify_object_permission( &self, owner_id: PID, - viewer_id: PID, permission: &Permission, ) -> Result<(), ErrorCode> { - if owner_id == viewer_id { + if owner_id == self.base.pid { return Ok(()); } @@ -315,7 +322,7 @@ impl DatastoreUser { 1 => Err(ErrorCode::DataStore_PermissionDenied), // Friends only, unimplemented 2 => { // Recipient IDs can read - if permission.recipient_ids.contains(&viewer_id) { + if permission.recipient_ids.contains(&self.base.pid) { Ok(()) } else { Err(ErrorCode::DataStore_PermissionDenied) @@ -327,6 +334,7 @@ impl DatastoreUser { } } + #[instrument] fn filter_properties_by_result_option(&self, meta_info: &mut GetMetaInfo, result_option: u8) { if (result_option & 0x01) == 0 { meta_info.meta_binary = QBuffer(Vec::new()); @@ -339,6 +347,7 @@ impl DatastoreUser { // No idea what the other things do. :shrug: } + #[instrument] async fn init_object_rating_slot(&self, data_id: i64, rating_param: RatingInitParamWithSlot) { info!("running init object rating slot"); sqlx::query!( @@ -376,11 +385,12 @@ impl DatastoreUser { .map_err(|e| { error!("DB Error: {:?}", e); ErrorCode::DataStore_NotFound - }); + })?; info!("done running"); } // Dawg... + #[instrument] async fn get_custom_rankings_by_data_ids( &self, application_id: u32, @@ -431,6 +441,7 @@ impl DatastoreUser { results } + #[instrument] async fn get_user_course_object_ids(&self, owner_pid: PID) -> Result, ErrorCode> { let rows = sqlx::query!( r#" @@ -459,6 +470,7 @@ impl DatastoreUser { Ok(valid_ids) } + #[instrument] fn get_blacklist_1(&self) -> Vec { vec![ "けされ", @@ -533,6 +545,7 @@ impl DatastoreUser { .collect() } + #[instrument] fn get_blacklist_2(&self) -> Vec { vec![ "ゼロから", @@ -548,6 +561,7 @@ impl DatastoreUser { .collect() } + #[instrument] fn get_blacklist_3(&self) -> Vec { vec![ "いいね", @@ -617,6 +631,7 @@ impl DatastoreUser { .collect() } + #[instrument] // couldn't find a better way to do this im going crazyy async fn rate_object( &self, @@ -651,6 +666,7 @@ impl DatastoreUser { Ok(rating) } + #[instrument] async fn change_meta_object_check( &self, param: &DataStoreChangeMetaParam, @@ -679,6 +695,7 @@ impl DatastoreUser { Ok(()) } + #[instrument] async fn get_rating_with_slot_data_id( &self, dataid: i64, @@ -713,6 +730,7 @@ impl DatastoreUser { Ok(ratings) } + #[instrument] pub async fn insert_buffer(&self, dataid: i64, slot: i32, buffer: &QBuffer) { let db_now = Utc::now().naive_utc(); @@ -756,8 +774,7 @@ impl DataStore for DatastoreUser { .await? }; - let current_pid = self.pid; - self.verify_object_permission(meta_info.owner, current_pid, &meta_info.permission)?; + self.verify_object_permission(meta_info.owner, &meta_info.permission)?; self.filter_properties_by_result_option(&mut meta_info, metaparam.result_option); @@ -794,7 +811,7 @@ impl DataStore for DatastoreUser { $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17 ) RETURNING data_id "#, - self.pid as i32, + self.base.pid as i32, postparam.size as i32, postparam.name, postparam.data_type as i32, @@ -815,7 +832,7 @@ impl DataStore for DatastoreUser { .fetch_one(&self.dm.db_pool) .await .map_err(|e| { - log::error!("DB Error: {:?}", e); + error!("DB Error: {:?}", e); ErrorCode::DataStore_NotFound })?; @@ -998,7 +1015,7 @@ impl DataStore for DatastoreUser { ], 10 => vec![35, 75, 96, 40, 5, 6], _ => { - log::error!("unknown SMM app id: {}", appid); + error!("unknown SMM app id: {}", appid); return Err(ErrorCode::DataStore_Unknown); } }; @@ -1081,7 +1098,7 @@ impl DataStore for DatastoreUser { }; info!("verifying object permission"); - self.verify_object_permission(meta_info.owner, self.base.pid, &meta_info.permission)?; + self.verify_object_permission(meta_info.owner, &meta_info.permission)?; let key = format!("data/{}.bin", meta_info.dataid); let download_url = self.dm.s3_presigner.generate_presigned_get(&key); @@ -1123,8 +1140,7 @@ impl DataStore for DatastoreUser { res.meta_info.ratings = Vec::new(); } if course_search_param.result_option & 0x4 == 0 { - res.meta_info.meta_binary = - rnex_core::rmc::structures::qbuffer::QBuffer(Vec::new()); + res.meta_info.meta_binary = QBuffer(Vec::new()); } if course_search_param.result_option & 0x20 == 0 { res.score = 0; @@ -1180,9 +1196,7 @@ impl DataStore for DatastoreUser { match info_result { Ok(mut meta) => { - if let Err(e) = - self.verify_object_permission(meta.owner, self.base.pid, &meta.permission) - { + if let Err(e) = self.verify_object_permission(meta.owner, &meta.permission) { metas.push(GetMetaInfo::default()); results.push(QResult::error(e)); } else { @@ -1255,7 +1269,7 @@ impl DataStore for DatastoreUser { $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17 ) RETURNING data_id "#, - self.pid as i32, + self.base.pid as i32, param.post_param.size as i32, param.post_param.name, param.post_param.data_type as i32, @@ -1349,11 +1363,7 @@ impl DataStore for DatastoreUser { .get_object_info_by_data_id(target.dataid, param.access_password) .await?; info!("object info get complete"); - self.verify_object_permission( - object_info.owner, - self.base.pid, - &object_info.permission, - )?; + self.verify_object_permission(object_info.owner, &object_info.permission)?; info!("object permission complete"); if fetch_ratings { @@ -1386,11 +1396,11 @@ impl DataStore for DatastoreUser { } async fn change_meta(&self, param: DataStoreChangeMetaParam) -> Result<(), ErrorCode> { - let object_info = get_object_info_by_data_id(param.dataid, 0).await?; - verify_object_permission(object_info.owner, self.pid, &object_info.permission).await?; + let object_info = self.get_object_info_by_data_id(param.dataid, 0).await?; + self.verify_object_permission(object_info.owner, &object_info.permission)?; if param.modifies_flag & 0x08 != 0 { - change_meta_object_check(¶m).await?; + self.change_meta_object_check(¶m).await?; sqlx::query!( r#"UPDATE datastore.objects SET period=$1 WHERE data_id=$2"#, @@ -1406,7 +1416,7 @@ impl DataStore for DatastoreUser { } if param.modifies_flag & 0x10 != 0 { - change_meta_object_check(¶m).await?; + self.change_meta_object_check(¶m).await?; sqlx::query!( r#"UPDATE datastore.objects SET meta_binary=$1 WHERE data_id=$2"#, @@ -1422,7 +1432,7 @@ impl DataStore for DatastoreUser { } if param.modifies_flag & 0x80 != 0 { - change_meta_object_check(¶m).await?; + self.change_meta_object_check(¶m).await?; sqlx::query!( r#"UPDATE datastore.objects SET data_type=$1 WHERE data_id=$2"#, @@ -1583,8 +1593,8 @@ impl DataStore for DatastoreUser { "#, upload_course_record_param.dataid, upload_course_record_param.slot as i16, - self.pid, - self.pid, + self.base.pid, + self.base.pid, upload_course_record_param.score, now, now @@ -1641,7 +1651,7 @@ impl DataStore for DatastoreUser { ) -> Result, ErrorCode> { let mut results = Vec::new(); - let client_pid = self.pid; + let client_pid = self.base.pid; for (param, buffer) in bufferparam.iter().zip(buffers.iter()) { if param.slot == 0 { @@ -1713,7 +1723,7 @@ impl DataStore for DatastoreUser { ) "#, report_course_param.dataid, - self.pid, + self.base.pid, report_course_param.report_category as i16, report_course_param.report_reason ) diff --git a/rnex-server-nex-modules/rnex-ds/src/lib.rs b/rnex-server-nex-modules/rnex-ds/src/lib.rs index 73f67bc..43a7913 100644 --- a/rnex-server-nex-modules/rnex-ds/src/lib.rs +++ b/rnex-server-nex-modules/rnex-ds/src/lib.rs @@ -1,3 +1,4 @@ +#![cfg(feature = "datastore")] use std::env; use rnex_server::{ConnectionInitData, RnexManager, RnexModule}; @@ -9,20 +10,21 @@ use crate::{datastore::DatastoreUser, s3presigner::S3Presigner}; pub mod datastore; pub(crate) mod s3presigner; -struct DatastoreManager { +#[derive(Debug)] +pub struct DatastoreManager { db_pool: PgPool, s3_presigner: S3Presigner, } -struct DatastoreModule; +pub struct DatastoreModule; impl RnexManager for DatastoreManager { type User = DatastoreUser; type InitData = ConnectionInitData; async fn init_new_user( this: rnex_server::PassthroughInitModule, mod_holder: &rnex_server::ModuleHolder, - remote: &rnex_rmc::RmcConnection, - init_data: &Self::InitData, - weak_user: rnex_server::WeakPassthroughInitModule, + _: &rnex_rmc::RmcConnection, + _: &Self::InitData, + _: rnex_server::WeakPassthroughInitModule, ) -> Self::User { DatastoreUser { dm: this, diff --git a/rnex-server-nex-modules/rnex-ds/src/s3presigner.rs b/rnex-server-nex-modules/rnex-ds/src/s3presigner.rs index e78a23c..c67960f 100644 --- a/rnex-server-nex-modules/rnex-ds/src/s3presigner.rs +++ b/rnex-server-nex-modules/rnex-ds/src/s3presigner.rs @@ -4,6 +4,7 @@ use hmac::{Hmac, KeyInit, Mac}; use serde_json::json; use sha2::{Digest, Sha256}; +#[derive(Debug)] pub struct S3Presigner { endpoint: String, bucket: String, diff --git a/rnex-server-nex-modules/rnex-fpd/Cargo.toml b/rnex-server-nex-modules/rnex-fpd/Cargo.toml index cbdd650..7510221 100644 --- a/rnex-server-nex-modules/rnex-fpd/Cargo.toml +++ b/rnex-server-nex-modules/rnex-fpd/Cargo.toml @@ -4,6 +4,22 @@ version = "0.1.0" edition = "2024" [dependencies] +bytemuck = { version = "1.25.1", features = ["derive"] } +rnex-rmc = { path = "../../rnex-rmc" } +rnex-util = { path = "../../rnex-util" } +rnex-fpd-protos = { path = "../../rnex-protocols/fpd-protos" } +rnex-base = { path = "../rnex-base" } +rnex-server = { path = "../../rnex-server" } +tokio = { version = "1.52.3", features = ["sync"] } +rand = "0.10.2" +tracing = "0.1.44" +sqlx = { version = "0.9.0", features = ["chrono"] } +chrono = "0.4.45" +hmac = "0.13.0" +md-5 = "0.11.0" +nex-account = { version = "0.2.4", registry = "spbr" } +hex = "0.4.3" +thiserror = "2.0.18" [lints] workspace = true diff --git a/rnex-core-deprecated/src/nex/friends_handler.rs b/rnex-server-nex-modules/rnex-fpd/src/friends_handler.rs similarity index 83% rename from rnex-core-deprecated/src/nex/friends_handler.rs rename to rnex-server-nex-modules/rnex-fpd/src/friends_handler.rs index 4ded520..0bc32aa 100644 --- a/rnex-core-deprecated/src/nex/friends_handler.rs +++ b/rnex-server-nex-modules/rnex-fpd/src/friends_handler.rs @@ -1,92 +1,38 @@ -use std::collections::HashMap; -use std::sync::{Arc, atomic::AtomicU32}; -use std::sync::{LazyLock, Weak}; -use std::time::Duration; -use std::{env, mem}; +use std::{ + collections::HashMap, + mem, + sync::{Arc, Weak}, + time::Duration, +}; -use crate::rmc::protocols::account_management::{ - AccountExtraInfo, AccountManagement, RawAccountManagement, RawAccountManagementInfo, - RemoteAccountManagement, -}; -use crate::rmc::protocols::friends_3ds::{ - Friends3DS, RawFriends3DS, RawFriends3DSInfo, RemoteFriends3DS, -}; -use crate::rmc::protocols::friends_wiiu::{ - FriendsWiiU, RawFriendsWiiU, RawFriendsWiiUInfo, RemoteFriendsWiiU, -}; -use crate::rmc::protocols::nintendo_notification::{ - NintendoNotification, RawNintendoNotification, RawNintendoNotificationInfo, - RemoteNintendoNotification, -}; -use crate::rmc::protocols::secure::{RawSecure, RawSecureInfo, RemoteSecure, Secure}; -use crate::{ - define_rmc_proto, - kerberos::KerberosDateTime, - nex::common::get_station_urls, - prudp::{socket_addr::PRUDPSockAddr, station_url::StationUrl}, - rmc::{ - protocols::friends_wiiu::{ - BlacklistedPrincipal, Comment, FriendInfo, FriendRequest, NNAInfo, NintendoPresenceV2, - PersistentNotification, PrincipalPreference, PrincipalRequestBlockSetting, - }, - response::ErrorCode, - structures::{any::Any, qresult::QResult}, - }, -}; use bytemuck::{Pod, Zeroable}; use chrono::{TimeZone, Utc}; -use rnex_rmc::rmc_struct; -use sqlx::query; -use std::sync::atomic::Ordering::Relaxed; -use tokio::spawn; -use tokio::sync::RwLock; -use tokio::time::sleep; -use tracing::warn; -use tracing::{error, info}; - -use crate::rmc::protocols::friends_wiiu::{GameKey, MiiV2, PrincipalBasicInfo}; - -use crate::PID; - -use crate::rmc::protocols::account_management::NintendoCreateAccountData; -use crate::rmc::protocols::nintendo_notification::NintendoNotificationEvent; - -use crate::rmc::structures::data::Data; - -use crate::executables::common::get_db; - -use crate::rmc::protocols::friends_3ds::{ - FriendComment, FriendMii, FriendMiiList, FriendPersistentInfo, FriendPicture, FriendPresence, - FriendRelationship, Mii, MiiList, MyProfile, NintendoPresence, PlayedGame, +use nex_account::{derive_pid_hmac, grpc::ActCreateInfo, grpc_client}; +use rnex_fpd_protos::{ + LocalFriendsGuest, LocalFriendsUser, RemoteFriendRemote, + account_management::{AccountExtraInfo, AccountManagement, NintendoCreateAccountData}, + friends_3ds::{ + self, FriendComment, FriendMii, FriendMiiList, FriendPersistentInfo, FriendPicture, + FriendPresence, FriendRelationship, Friends3DS, Mii, MiiList, MyProfile, NintendoPresence, + PlayedGame, + }, + friends_wiiu::{ + self, BlacklistedPrincipal, Comment, FriendRequest, FriendRequestMessage, FriendsWiiU, + MiiV2, NNAInfo, NintendoPresenceV2, PersistentNotification, PrincipalBasicInfo, + PrincipalPreference, PrincipalRequestBlockSetting, + }, + nintendo_notification::{ + NintendoNotificationEvent, NintendoNotificationEventGeneral, RemoteNintendoNotification, + }, }; -use crate::rmc::protocols::friends_wiiu::FriendRequestMessage; -use crate::rmc::protocols::nintendo_notification::NintendoNotificationEventGeneral; -use crate::rmc::response::ErrorCode::FPD_InvalidArgument; -use crate::rmc::structures::qbuffer::QBuffer; -use nex_account::grpc::ActCreateInfo; -use nex_account::{derive_pid_hmac, grpc_client}; +use rnex_rmc::{any::Any, data::Data, qbuffer::QBuffer, response::ErrorCode, rmc_struct}; +use rnex_server::{PassthroughInitModule, WeakPassthroughInitModule}; +use rnex_util::{PID, date_time::DateTime}; +use sqlx::query; +use tokio::{spawn, sync::RwLock, time::sleep}; +use tracing::{error, info, warn}; -define_rmc_proto!( - proto FriendsUser{ - Secure, - FriendsWiiU, - Friends3DS - } -); -define_rmc_proto!( - proto FriendRemote{ - NintendoNotification - } -); -define_rmc_proto!( - proto FriendsGuest{ - Secure, - AccountManagement - } -); - -static NEX_ACCOUNT_URL: LazyLock = - LazyLock::new(|| env::var("NEX_ACCOUNT_ENDPOINT").expect("NEX_ACCOUNT_ENDPOINT not set")); +use crate::FriendsManager; #[repr(C, packed)] #[derive(Pod, Zeroable, Copy, Clone, Debug)] @@ -96,10 +42,11 @@ pub struct NascToken { pub pwd_hash: [u8; 4], } +#[derive(Debug)] #[rmc_struct(FriendsUser)] pub struct FriendsUser { - pub fm: Arc, - pub addr: PRUDPSockAddr, + pub fm: PassthroughInitModule, + //pub addr: PRUDPSockAddr, pub pid: PID, pub friend_pids: RwLock>, pub maybe_remote_friend: RwLock>>, @@ -108,27 +55,14 @@ pub struct FriendsUser { pub remote: RemoteFriendRemote, } +#[derive(Debug)] #[rmc_struct(FriendsGuest)] -pub struct FriendsGuest { - pub fm: Arc, - pub addr: PRUDPSockAddr, -} - -pub struct FriendsManager { - pub cid_counter: AtomicU32, - pub users: RwLock>>, -} - -impl FriendsManager { - pub fn next_cid(&self) -> u32 { - self.cid_counter.fetch_add(1, Relaxed) - } -} +pub struct FriendsGuest; impl FriendsManager { async fn denies_friend_requests(&self, pid: PID) -> Result { query!("select principal_preference_block_friend_requests from nintendo_network_accounts where pid = $1", pid) - .fetch_one(get_db()) + .fetch_one(&self.db) .await .map_err(|_| ErrorCode::FPD_InvalidAccount) .map(|v| v.principal_preference_block_friend_requests) @@ -165,7 +99,7 @@ impl Friends3DS for FriendsUser { async fn get_friend_mii( &self, - _friends: Vec, + _friends: Vec, ) -> Result, ErrorCode> { // sorry for the copying pretendo but i don't have a mii on hand rn let data: Vec = vec![ @@ -196,7 +130,7 @@ impl Friends3DS for FriendsUser { async fn get_friend_mii_list( &self, - _friends: Vec, + _friends: Vec, ) -> Result, ErrorCode> { Err(ErrorCode::Core_NotImplemented) } @@ -204,7 +138,7 @@ impl Friends3DS for FriendsUser { async fn is_active_game( &self, _unk: Vec, - _game_key: crate::rmc::protocols::friends_3ds::GameKey, + _game_key: friends_3ds::GameKey, ) -> Result, ErrorCode> { Err(ErrorCode::Core_NotImplemented) } @@ -298,9 +232,9 @@ impl Friends3DS for FriendsUser { async fn update_favorite_game_key( &self, - game_key: rnex_core::rmc::protocols::friends_3ds::GameKey, + game_key: friends_3ds::GameKey, ) -> Result<(), ErrorCode> { - log::info!("favorite game key: {:?}", game_key); + info!("favorite game key: {:?}", game_key); Ok(()) } @@ -314,7 +248,7 @@ impl Friends3DS for FriendsUser { } async fn get_friend_presence(&self, unk: Vec) -> Result, ErrorCode> { - log::info!("pids: {:?}", unk); + info!("pids: {:?}", unk); let presence = FriendPresence { data: Data {}, @@ -322,7 +256,7 @@ impl Friends3DS for FriendsUser { presence: NintendoPresence { data: Data {}, changed_bit_flag: 0xFFFF_FFFF, - game_key: rnex_core::rmc::protocols::friends_3ds::GameKey { + game_key: friends_3ds::GameKey { data: Data {}, title_id: 1_125_899_907_457_280, version: 2064, @@ -343,7 +277,7 @@ impl Friends3DS for FriendsUser { async fn get_friend_comment( &self, - _unk: Vec, + _unk: Vec, ) -> Result, ErrorCode> { Err(ErrorCode::Core_NotImplemented) } @@ -364,15 +298,15 @@ impl Friends3DS for FriendsUser { area: 0, language: 0, platform: 0, - game_key: rnex_core::rmc::protocols::friends_3ds::GameKey { + game_key: friends_3ds::GameKey { data: Data {}, title_id: 1_125_899_907_457_280, version: 2064, }, message: "yo whats up".to_string(), - msg_updated_at: KerberosDateTime::now(), - friended_at: KerberosDateTime::now(), - last_online: KerberosDateTime::now(), + msg_updated_at: DateTime::now(), + friended_at: DateTime::now(), + last_online: DateTime::now(), }; Ok(vec![dummypersistentinfo]) @@ -399,7 +333,7 @@ macro_rules! basic_principal_from_record { nnid: $record.nnid.clone(), mii: MiiV2 { data: Data {}, - date_time: KerberosDateTime(bytemuck::cast($record.mii_unk_datetime)), + date_time: DateTime(bytemuck::cast($record.mii_unk_datetime)), mii_data: $record.mii_ffl_data.clone(), name: QBuffer($record.mii_name.clone()), unk: mii_unk1, @@ -424,7 +358,7 @@ macro_rules! nna_info_from_record { macro_rules! game_key_from_record { ($record:expr) => { - GameKey { + friends_wiiu::GameKey { data: Data {}, tid: $record.game_key_tid, version: $record.game_key_version, @@ -440,7 +374,7 @@ macro_rules! friend_request_from_record { basic_info: basic_principal_from_record!($record), request_message: FriendRequestMessage { data: Data {}, - expires_on: KerberosDateTime::from_naive( + expires_on: DateTime::from_naive( Utc.timestamp_opt(Utc::now().timestamp() + 2592000, 0) .unwrap() .naive_utc(), @@ -452,9 +386,9 @@ macro_rules! friend_request_from_record { unk, unk2, unk3: $record.unk_2, - unk4: KerberosDateTime(bytemuck::cast($record.unk_3)), + unk4: DateTime(bytemuck::cast($record.unk_3)), }, - sent_on: KerberosDateTime::from_naive($record.creation_time), + sent_on: DateTime::from_naive($record.creation_time), } }}; } @@ -464,12 +398,12 @@ impl FriendsWiiU for FriendsUser { &self, info: NNAInfo, presence: NintendoPresenceV2, - birthday: KerberosDateTime, + birthday: DateTime, ) -> Result< ( PrincipalPreference, Comment, - Vec, + Vec, Vec, Vec, Vec, @@ -512,7 +446,7 @@ impl FriendsWiiU for FriendsUser { smoosh_to_i16(info.unk, info.unk2), bytemuck::cast::<_, i64>(birthday) ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await else { println!("psql failed(unable to update user)"); return Err(ErrorCode::Core_SystemError) @@ -528,7 +462,7 @@ impl FriendsWiiU for FriendsUser { ", self.pid ) - .fetch_all(get_db()) + .fetch_all(&self.fm.db) .await .map(|v| { v.into_iter() @@ -549,7 +483,7 @@ impl FriendsWiiU for FriendsUser { ", self.pid ) - .fetch_all(get_db()) + .fetch_all(&self.fm.db) .await .map(|v| { v.into_iter() @@ -580,7 +514,7 @@ impl FriendsWiiU for FriendsUser { inner join nintendo_network_accounts on friendships.pid = nintendo_network_accounts.pid", self.pid ) - .fetch_all(get_db()) + .fetch_all(&self.fm.db) .await else { println!("error whilest getting friends"); @@ -624,7 +558,7 @@ impl FriendsWiiU for FriendsUser { drop(remo_friends); } - friends.push(FriendInfo { + friends.push(friends_wiiu::FriendInfo { data: Data {}, nna_info: nna_info_from_record!(friend), presence, @@ -632,10 +566,10 @@ impl FriendsWiiU for FriendsUser { data: Data {}, unk: (bytemuck::cast::<_, u16>(friend.comment_unk) & 0xFF) as u8, message: friend.comment_message, - last_changed: KerberosDateTime::from_naive(friend.comment_lastchanged), + last_changed: DateTime::from_naive(friend.comment_lastchanged), }, - became_friends: KerberosDateTime::from_naive(friend_since), - last_online: KerberosDateTime::from_naive(friend.last_online), + became_friends: DateTime::from_naive(friend_since), + last_online: DateTime::from_naive(friend.last_online), unk: 0, }); } @@ -650,13 +584,13 @@ impl FriendsWiiU for FriendsUser { ", self.pid ) - .fetch_all(get_db()) + .fetch_all(&self.fm.db) .await .map(|v| { v.into_iter() .map(|v| BlacklistedPrincipal { basic_info: basic_principal_from_record!(v), - since: KerberosDateTime::from_naive(v.since), + since: DateTime::from_naive(v.since), ..Default::default() }) .collect::>() @@ -681,7 +615,7 @@ impl FriendsWiiU for FriendsUser { }, Comment { data: Data {}, - last_changed: KerberosDateTime::from_naive(query.comment_lastchanged), + last_changed: DateTime::from_naive(query.comment_lastchanged), message: query.comment_message, unk: (bytemuck::cast::<_, u16>(query.comment_unk) & 0xFF) as u8, }, @@ -697,15 +631,18 @@ impl FriendsWiiU for FriendsUser { ))) } - async fn add_friend(&self, friend: PID) -> Result<(FriendRequest, FriendInfo), ErrorCode> { + async fn add_friend( + &self, + friend: PID, + ) -> Result<(FriendRequest, friends_wiiu::FriendInfo), ErrorCode> { self.add_friend_request( friend, 0, "".into(), 0, "".into(), - GameKey::default(), - KerberosDateTime::now(), + friends_wiiu::GameKey::default(), + DateTime::now(), ) .await } @@ -713,12 +650,12 @@ impl FriendsWiiU for FriendsUser { async fn add_friend_by_name( &self, name: String, - ) -> Result<(FriendRequest, FriendInfo), ErrorCode> { + ) -> Result<(FriendRequest, friends_wiiu::FriendInfo), ErrorCode> { let Ok(pid) = query!( "select pid from nintendo_network_accounts where nnid = $1", name ) - .fetch_optional(get_db()) + .fetch_optional(&self.fm.db) .await else { println!("db error when trying to look up nnid"); @@ -737,7 +674,7 @@ impl FriendsWiiU for FriendsUser { self.pid, friend ) - .execute(get_db()) + .execute(&self.fm.db) .await else { return Err(ErrorCode::FPD_InvalidMessageID); @@ -790,9 +727,9 @@ impl FriendsWiiU for FriendsUser { message: String, _unk2: u8, unk3: String, - game_key: GameKey, - unk4: KerberosDateTime, - ) -> Result<(FriendRequest, FriendInfo), ErrorCode> { + game_key: friends_wiiu::GameKey, + unk4: DateTime, + ) -> Result<(FriendRequest, friends_wiiu::FriendInfo), ErrorCode> { let unk1 = 0; let unk2 = 1; @@ -805,12 +742,12 @@ impl FriendsWiiU for FriendsUser { "insert into friendships (pid_a, pid_b) values(99, $1)", self.pid ) - .execute(get_db()) + .execute(&self.fm.db) .await .ok(); let Ok(v) = query!("select * from nintendo_network_accounts where pid = 99") - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await else { return Err(ErrorCode::Core_Exception); @@ -829,22 +766,22 @@ impl FriendsWiiU for FriendsUser { drop(friends); let Ok(r) = query!("select * from nintendo_network_accounts where pid = 99") - .fetch_one(get_db()) + .fetch_one(&this.fm.db) .await else { return; }; - let data = Any::new(&FriendInfo { + let data = Any::new(&friends_wiiu::FriendInfo { data: Data {}, nna_info: nna_info_from_record!(r), - became_friends: KerberosDateTime::now(), + became_friends: DateTime::now(), comment: Comment { data: Data {}, - last_changed: KerberosDateTime::from_naive(r.comment_lastchanged), + last_changed: DateTime::from_naive(r.comment_lastchanged), message: r.comment_message, unk: (bytemuck::cast::<_, u16>(r.comment_unk) & 0xFF) as u8, }, - last_online: KerberosDateTime::now(), + last_online: DateTime::now(), presence: NintendoPresenceV2::default(), unk: 0, }) @@ -870,21 +807,21 @@ impl FriendsWiiU for FriendsUser { unk2: 1, unk3: "Dummy".into(), game_key, - unk4: KerberosDateTime::now(), - expires_on: KerberosDateTime::now(), + unk4: DateTime::now(), + expires_on: DateTime::now(), }, data: Data {}, - sent_on: KerberosDateTime::now(), + sent_on: DateTime::now(), }, - FriendInfo { - became_friends: KerberosDateTime::now(), + friends_wiiu::FriendInfo { + became_friends: DateTime::now(), comment: Comment { data: Data {}, unk: bytemuck::cast::<_, u16>(v.comment_unk & 0xFF) as u8, message: v.comment_message, - last_changed: KerberosDateTime::from_naive(v.comment_lastchanged), + last_changed: DateTime::from_naive(v.comment_lastchanged), }, - last_online: KerberosDateTime::now(), + last_online: DateTime::now(), nna_info: nna_info_from_record!(v), ..Default::default() }, @@ -896,7 +833,7 @@ impl FriendsWiiU for FriendsUser { friend, self.pid ) - .fetch_optional(get_db()) + .fetch_optional(&self.fm.db) .await else { return Err(ErrorCode::Authentication_AccountLibraryError); @@ -911,7 +848,7 @@ impl FriendsWiiU for FriendsUser { "select count(recipient) from friend_requests where sender = $1", self.pid ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await else { println!("friend request count check failed to execute on database"); @@ -924,7 +861,7 @@ impl FriendsWiiU for FriendsUser { "select count(recipient) from friend_requests where recipient = $1", friend ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await else { println!("friend request count check failed to execute on database"); @@ -955,7 +892,7 @@ impl FriendsWiiU for FriendsUser { game_key.tid, game_key.version ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await; let query = match query { @@ -993,7 +930,7 @@ impl FriendsWiiU for FriendsUser { "select * from nintendo_network_accounts where pid = $1", self.pid ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await else { println!("failed to acquire account info after adding friend"); @@ -1012,7 +949,7 @@ impl FriendsWiiU for FriendsUser { dbg!(Ok(( fr, - FriendInfo { + friends_wiiu::FriendInfo { presence: NintendoPresenceV2 { game_key, app_data: vec![0x00], @@ -1029,7 +966,7 @@ impl FriendsWiiU for FriendsUser { bytemuck::cast::<_, i64>(id), self.pid ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await else { return Err(ErrorCode::FPD_InvalidMessageID); @@ -1055,8 +992,8 @@ impl FriendsWiiU for FriendsUser { Ok(()) } - async fn accept_friend_request(&self, id: u64) -> Result { - let Ok(mut tx) = get_db().begin().await else { + async fn accept_friend_request(&self, id: u64) -> Result { + let Ok(mut tx) = self.fm.db.begin().await else { return Err(ErrorCode::Core_Exception); }; let Ok(query) = query!( @@ -1120,17 +1057,17 @@ impl FriendsWiiU for FriendsUser { println!("internal server error whilest getting nna info"); return Err(ErrorCode::Core_Exception); }; - let data = Any::new(&FriendInfo { + let data = Any::new(&friends_wiiu::FriendInfo { data: Data {}, nna_info: nna_info_from_record!(r), - became_friends: KerberosDateTime::now(), + became_friends: DateTime::now(), comment: Comment { data: Data {}, - last_changed: KerberosDateTime::from_naive(r.comment_lastchanged), + last_changed: DateTime::from_naive(r.comment_lastchanged), message: r.comment_message, unk: (bytemuck::cast::<_, u16>(r.comment_unk) & 0xFF) as u8, }, - last_online: KerberosDateTime::now(), + last_online: DateTime::now(), presence: self.presence.read().await.clone().unwrap_or_default(), unk: 0, }) @@ -1155,18 +1092,18 @@ impl FriendsWiiU for FriendsUser { tx.commit().await.ok(); - Ok(FriendInfo { + Ok(friends_wiiu::FriendInfo { data: Data {}, nna_info: nna_info_from_record!(query), presence, comment: Comment { data: Data {}, - last_changed: KerberosDateTime::from_naive(query.comment_lastchanged), + last_changed: DateTime::from_naive(query.comment_lastchanged), message: query.comment_message, unk: (bytemuck::cast::<_, u16>(query.comment_unk) & 0xFF) as u8, }, - became_friends: KerberosDateTime::now(), - last_online: KerberosDateTime::from_naive(query.last_online), + became_friends: DateTime::now(), + last_online: DateTime::from_naive(query.last_online), unk: 0, }) } @@ -1176,7 +1113,7 @@ impl FriendsWiiU for FriendsUser { "delete from friend_requests where id = $1 returning sender, recipient", bytemuck::cast::<_, i64>(id), ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await else { return Err(ErrorCode::FPD_InvalidMessageID); @@ -1216,7 +1153,7 @@ impl FriendsWiiU for FriendsUser { bytemuck::cast::<_, i64>(id), self.pid ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await else { return Err(ErrorCode::FPD_InvalidMessageID); @@ -1235,7 +1172,7 @@ impl FriendsWiiU for FriendsUser { self.pid, query.sender ) - .execute(get_db()) + .execute(&self.fm.db) .await { println!("{}", e); @@ -1264,18 +1201,18 @@ impl FriendsWiiU for FriendsUser { "select * from nintendo_network_accounts where pid = $1", query.sender ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await else { println!("attempt to get invalid user which is in friend request"); - return Err(FPD_InvalidArgument); + return Err(ErrorCode::FPD_InvalidArgument); }; Ok(BlacklistedPrincipal { data: Data {}, basic_info: basic_principal_from_record!(user), - game_key: GameKey::default(), - since: KerberosDateTime::now(), + game_key: friends_wiiu::GameKey::default(), + since: DateTime::now(), }) } @@ -1285,7 +1222,7 @@ impl FriendsWiiU for FriendsUser { "update friend_requests set is_recieved = true where id = $1", bytemuck::cast::<_, i64>(id) ) - .execute(get_db()) + .execute(&self.fm.db) .await .ok(); } @@ -1301,7 +1238,7 @@ impl FriendsWiiU for FriendsUser { self.pid, principal.basic_info.pid ) - .execute(get_db()) + .execute(&self.fm.db) .await { println!("{}", e); @@ -1312,18 +1249,18 @@ impl FriendsWiiU for FriendsUser { "select * from nintendo_network_accounts where pid = $1", principal.basic_info.pid ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await else { println!("attempt to get invalid user which is in friend request"); - return Err(FPD_InvalidArgument); + return Err(ErrorCode::FPD_InvalidArgument); }; Ok(BlacklistedPrincipal { data: Data {}, basic_info: basic_principal_from_record!(user), - game_key: GameKey::default(), - since: KerberosDateTime::now(), + game_key: friends_wiiu::GameKey::default(), + since: DateTime::now(), }) } @@ -1333,7 +1270,7 @@ impl FriendsWiiU for FriendsUser { self.pid, id ) - .execute(get_db()) + .execute(&self.fm.db) .await { println!("{}", e); @@ -1343,16 +1280,16 @@ impl FriendsWiiU for FriendsUser { } async fn update_presence(&self, mut presence: NintendoPresenceV2) -> Result<(), ErrorCode> { - if !query!("select principal_preference_show_currently_playing_title from nintendo_network_accounts where pid = $1", self.pid).fetch_one(get_db()).await.map_err(|_| ErrorCode::FPD_InvalidAccount)?.principal_preference_show_currently_playing_title{ + if !query!("select principal_preference_show_currently_playing_title from nintendo_network_accounts where pid = $1", self.pid).fetch_one(&self.fm.db).await.map_err(|_| ErrorCode::FPD_InvalidAccount)?.principal_preference_show_currently_playing_title{ presence.game_server_id = 0; - presence.game_key = GameKey::default(); + presence.game_key = friends_wiiu::GameKey::default(); presence.app_data = vec![]; } if !query!( "select principal_preference_show_online from nintendo_network_accounts where pid = $1", self.pid ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await .map_err(|_| ErrorCode::FPD_InvalidAccount)? .principal_preference_show_online @@ -1380,7 +1317,7 @@ impl FriendsWiiU for FriendsUser { Ok(()) } - async fn update_mii(&self, mii: MiiV2) -> Result { + async fn update_mii(&self, mii: MiiV2) -> Result { if let Err(e) = query!( " update nintendo_network_accounts @@ -1392,7 +1329,7 @@ impl FriendsWiiU for FriendsUser { bytemuck::cast::<_, i64>(mii.date_time.0), self.pid ) - .execute(get_db()) + .execute(&self.fm.db) .await { println!("internal server error whilest updating mii: {}", e); @@ -1403,7 +1340,7 @@ impl FriendsWiiU for FriendsUser { "select * from nintendo_network_accounts where pid = $1", self.pid ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await else { println!("internal server error whilest getting nna info"); @@ -1425,10 +1362,10 @@ impl FriendsWiiU for FriendsUser { .await; } - Ok(KerberosDateTime::now()) + Ok(DateTime::now()) } - async fn update_comment(&self, comment: Comment) -> Result { + async fn update_comment(&self, comment: Comment) -> Result { if let Err(e) = query!( " update nintendo_network_accounts @@ -1438,7 +1375,7 @@ impl FriendsWiiU for FriendsUser { comment.message.clone(), self.pid ) - .execute(get_db()) + .execute(&self.fm.db) .await { println!("internal server error whilest updating mii: {}", e); @@ -1463,7 +1400,7 @@ impl FriendsWiiU for FriendsUser { .await; } - Ok(KerberosDateTime::now()) + Ok(DateTime::now()) } async fn update_preference(&self, preference: PrincipalPreference) -> Result<(), ErrorCode> { @@ -1480,7 +1417,7 @@ impl FriendsWiiU for FriendsUser { preference.block_friend_request, self.pid ) - .execute(get_db()) + .execute(&self.fm.db) .await { println!("internal server error whilest updating mii: {e}"); @@ -1494,14 +1431,14 @@ impl FriendsWiiU for FriendsUser { if !preference.show_playing_title { presence.game_server_id = 0; - presence.game_key = GameKey::default(); + presence.game_key = friends_wiiu::GameKey::default(); presence.app_data = vec![]; } query!( "update nintendo_network_accounts set last_online = now() where pid = $1", self.pid ) - .execute(get_db()) + .execute(&self.fm.db) .await .ok(); let friends = self.maybe_remote_friend.read().await; @@ -1530,7 +1467,7 @@ impl FriendsWiiU for FriendsUser { event_type: 10, sender: self.pid, data: Any::new(&NintendoNotificationEventGeneral { - param3: KerberosDateTime::now().0, + param3: DateTime::now().0, ..Default::default() }) .expect("type error"), @@ -1551,7 +1488,7 @@ impl FriendsWiiU for FriendsUser { "select * from nintendo_network_accounts where pid = $1", pid ) - .fetch_one(get_db()) + .fetch_one(&self.fm.db) .await else { return Err(ErrorCode::FPD_NotFriend); @@ -1591,7 +1528,7 @@ impl FriendsWiiU for FriendsUser { pid, self.pid ) - .fetch_optional(get_db()) + .fetch_optional(&self.fm.db) .await else { warn!("user requested request setting of invalid user"); @@ -1619,61 +1556,12 @@ impl FriendsWiiU for FriendsUser { type HMacMd5 = hmac::Hmac; -impl Secure for FriendsUser { - async fn register( - &self, - station_urls: Vec, - ) -> Result<(QResult, u32, StationUrl), ErrorCode> { - let cid = self.fm.next_cid(); - Ok(( - QResult::success(ErrorCode::Core_Unknown), - cid, - get_station_urls(&station_urls, self.addr, self.pid, cid).await?[0].clone(), - )) - } - async fn register_ex( - &self, - station_urls: Vec, - _data: Any, - ) -> Result<(QResult, u32, StationUrl), ErrorCode> { - info!("register"); - self.register(station_urls).await - } - async fn replace_url(&self, _target: StationUrl, _dest: StationUrl) -> Result<(), ErrorCode> { - Err(ErrorCode::Core_NotImplemented) - } -} - -impl Secure for FriendsGuest { - async fn register( - &self, - station_urls: Vec, - ) -> Result<(QResult, u32, StationUrl), ErrorCode> { - let cid = self.fm.next_cid(); - Ok(( - QResult::success(ErrorCode::Core_Unknown), - cid, - get_station_urls(&station_urls, self.addr, 100, cid).await?[0].clone(), - )) - } - async fn register_ex( - &self, - station_urls: Vec, - _data: Any, - ) -> Result<(QResult, u32, StationUrl), ErrorCode> { - info!("register"); - self.register(station_urls).await - } - async fn replace_url(&self, _target: StationUrl, _dest: StationUrl) -> Result<(), ErrorCode> { - Err(ErrorCode::Core_NotImplemented) - } -} - impl Drop for FriendsUser { fn drop(&mut self) { let friends = mem::take(&mut self.maybe_remote_friend); let users = friends.into_inner(); let pid = self.pid; + let fm = self.fm.clone(); tokio::spawn(async move { for user in users { let Some(user) = user.1.upgrade() else { @@ -1685,7 +1573,7 @@ impl Drop for FriendsUser { event_type: 10, sender: pid, data: Any::new(&NintendoNotificationEventGeneral { - param3: KerberosDateTime::now().0, + param3: DateTime::now().0, ..Default::default() }) .expect("type error"), @@ -1696,7 +1584,7 @@ impl Drop for FriendsUser { "update nintendo_network_accounts set last_online = now() where pid = $1", pid ) - .execute(get_db()) + .execute(&fm.db) .await .ok(); }); diff --git a/rnex-server-nex-modules/rnex-fpd/src/lib.rs b/rnex-server-nex-modules/rnex-fpd/src/lib.rs new file mode 100644 index 0000000..e9a1f4b --- /dev/null +++ b/rnex-server-nex-modules/rnex-fpd/src/lib.rs @@ -0,0 +1,102 @@ +use crate::friends_handler::{FriendsGuest, FriendsUser}; +use nex_account::GUEST_PID; +use rnex_fpd_protos::RemoteFriendRemote; +use rnex_rmc::{RmcCallable, RmcPureRemoteObject}; +use rnex_server::{ConnectionInitData, RnexManager, RnexModule, WeakPassthroughInitModule}; +use rnex_util::PID; +use sqlx::PgPool; +use std::{ + collections::HashMap, + env, + sync::{Arc, Weak, atomic::AtomicU32}, +}; +use thiserror::Error; +use tokio::sync::RwLock; +pub mod friends_handler; + +#[derive(Error, Debug)] +pub enum ModuleInitError { + #[error(transparent)] + Sqlx(#[from] sqlx::Error), + #[error(transparent)] + Env(#[from] env::VarError), +} + +#[derive(Debug)] +pub enum FriendsMaybeGuest { + Guest(FriendsGuest), + User(Arc), +} + +impl RmcCallable for FriendsMaybeGuest { + async fn rmc_call( + &self, + responder: &rnex_util::SendingBufferConnection, + protocol_id: u16, + method_id: u32, + call_id: u32, + rest: &[u8], + ) -> bool { + match self { + FriendsMaybeGuest::Guest(friends_guest) => { + friends_guest + .rmc_call(responder, protocol_id, method_id, call_id, rest) + .await + } + FriendsMaybeGuest::User(friends_user) => { + friends_user + .rmc_call(responder, protocol_id, method_id, call_id, rest) + .await + } + } + } +} + +#[derive(Debug)] +pub struct FriendsManager { + pub users: RwLock>>, + pub db: PgPool, +} + +pub struct FriendsModule; + +impl RnexManager for FriendsManager { + type InitData = ConnectionInitData; + type User = FriendsMaybeGuest; + + async fn init_new_user( + mgr: rnex_server::PassthroughInitModule, + mod_holder: &rnex_server::ModuleHolder, + remote: &rnex_rmc::RmcConnection, + init_data: &Self::InitData, + weak_user: WeakPassthroughInitModule, + ) -> Self::User { + if init_data.pid == GUEST_PID { + return FriendsMaybeGuest::Guest(FriendsGuest); + } + FriendsMaybeGuest::User(Arc::new_cyclic(|this| FriendsUser { + fm: mgr, + pid: init_data.pid, + friend_pids: Default::default(), + maybe_remote_friend: Default::default(), + presence: Default::default(), + this: this.clone(), + remote: RemoteFriendRemote::new(remote.clone()), + })) + } +} + +impl RnexModule for FriendsModule { + type Manager = FriendsManager; + + type InitError = ModuleInitError; + + async fn create_manager( + mod_holder: &rnex_server::ModuleHolder, + ) -> Result { + Ok(FriendsManager { + users: Default::default(), + db: PgPool::connect(&env::var("RNEX_DATASTORE_DATABASE")?).await?, + }) + } +} diff --git a/rnex-server-nex-modules/rnex-fpd/src/main.rs b/rnex-server-nex-modules/rnex-fpd/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/rnex-server-nex-modules/rnex-fpd/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/rnex-server-nex-modules/rnex-msg/Cargo.toml b/rnex-server-nex-modules/rnex-msg/Cargo.toml index 116c996..e9fda6d 100644 --- a/rnex-server-nex-modules/rnex-msg/Cargo.toml +++ b/rnex-server-nex-modules/rnex-msg/Cargo.toml @@ -4,6 +4,9 @@ version = "0.1.0" edition = "2024" [dependencies] - +rnex-rmc = { path = "../../rnex-rmc" } +rnex-msg-protos = { path = "../../rnex-protocols/msg-protos" } +rnex-server = { path = "../../rnex-server" } +tokio = { version = "1.52.3", features = ["sync"] } [lints] workspace = true diff --git a/rnex-server-nex-modules/rnex-msg/src/lib.rs b/rnex-server-nex-modules/rnex-msg/src/lib.rs new file mode 100644 index 0000000..9490f9f --- /dev/null +++ b/rnex-server-nex-modules/rnex-msg/src/lib.rs @@ -0,0 +1,40 @@ +use std::collections::HashMap; + +use rnex_msg_protos::RemoteMessagingClient; +use rnex_rmc::{RmcPureRemoteObject, util::PID}; +use rnex_server::{ConnectionInitData, RnexManager, WeakPassthroughInitModule}; +use tokio::sync::RwLock; + +use crate::user::MessagingUser; + +pub mod user; + +pub struct MessagingManager { + users_by_pid: RwLock>>, +} + +pub struct MessagingModule; + +impl RnexManager for MessagingManager { + type User = MessagingUser; + + type InitData = ConnectionInitData; + + async fn init_new_user( + this: rnex_server::PassthroughInitModule, + mod_holder: &rnex_server::ModuleHolder, + remote: &rnex_rmc::RmcConnection, + init_data: &Self::InitData, + weak_user: rnex_server::WeakPassthroughInitModule, + ) -> Self::User { + this.users_by_pid + .write() + .await + .insert(init_data.pid, weak_user); + MessagingUser { + msgm: this, + pid: init_data.pid, + remote: RemoteMessagingClient::new(remote.clone()), + } + } +} diff --git a/rnex-server-nex-modules/rnex-msg/src/main.rs b/rnex-server-nex-modules/rnex-msg/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/rnex-server-nex-modules/rnex-msg/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/rnex-server-nex-modules/rnex-msg/src/user.rs b/rnex-server-nex-modules/rnex-msg/src/user.rs index 04ffb37..5825904 100644 --- a/rnex-server-nex-modules/rnex-msg/src/user.rs +++ b/rnex-server-nex-modules/rnex-msg/src/user.rs @@ -1,16 +1,32 @@ -impl MessageDelivery for User { +use crate::MessagingManager; +use rnex_msg_protos::message_delivery::RemoteMessageDeliveryNoResponse; +use rnex_msg_protos::{ + LocalMessagingProtocol, RemoteMessagingClient, message_delivery::MessageDelivery, + messaging::UserMessage, +}; +use rnex_rmc::{any::Any, response::ErrorCode, rmc_struct, util::PID}; +use rnex_server::{PassthroughInitModule, WeakPassthroughInitModule}; + +#[rmc_struct(MessagingProtocol)] +pub struct MessagingUser { + pub msgm: PassthroughInitModule, + pub pid: PID, + pub remote: RemoteMessagingClient, +} + +impl MessageDelivery for MessagingUser { async fn deliver_message(&self, mut message: Any) -> Result<(), ErrorCode> { let mut msg = message.get()?; let _users = match msg.recipient_type { 1 => { let Some(user) = self - .matchmake_manager + .msgm .users_by_pid .read() .await .get(&msg.recipient_id) - .map(Weak::upgrade) + .map(WeakPassthroughInitModule::upgrade) .flatten() else { return Err(ErrorCode::Core_InvalidArgument); diff --git a/rnex-server-nex-modules/rnex-rk/Cargo.toml b/rnex-server-nex-modules/rnex-rk/Cargo.toml index b1aafdb..9b8e99b 100644 --- a/rnex-server-nex-modules/rnex-rk/Cargo.toml +++ b/rnex-server-nex-modules/rnex-rk/Cargo.toml @@ -4,6 +4,15 @@ version = "0.1.0" edition = "2024" [dependencies] +rnex-rmc = { path = "../../rnex-rmc" } +rnex-util = { path = "../../rnex-util" } +rnex-rk-protos = { path = "../../rnex-protocols/rk-protos" } +rnex-server = { path = "../../rnex-server" } +serde = { version = "1.0.228", features = ["derive"] } +tracing = "0.1.44" +ureq = { version = "3.3.0", features = ["json"] } +tokio = { version = "1.52.3", features = ["rt"] } +serde_json = "1.0.150" [lints] workspace = true diff --git a/rnex-server-nex-modules/rnex-rk/src/lib.rs b/rnex-server-nex-modules/rnex-rk/src/lib.rs new file mode 100644 index 0000000..44b074b --- /dev/null +++ b/rnex-server-nex-modules/rnex-rk/src/lib.rs @@ -0,0 +1,86 @@ +use std::env::{self, VarError}; + +use rnex_rmc::response::ErrorCode; +use rnex_server::{ConnectionInitData, RnexManager, RnexModule}; +use std::str::FromStr; +use tracing::error; + +use crate::user::RankingUser; + +pub mod user; + +pub struct RankingManager { + rnex_result_get: String, + rnex_result_votes_get: String, + rnex_result_post: String, +} + +pub struct RankingModule; + +impl RankingManager { + // Seperate function because I cannot give a fuck right now + async fn fetch_team_votes(&self, fest_id: u32) -> Result, ErrorCode> { + let url_votes = format!("{}?splatfest_id={}", self.rnex_result_votes_get, fest_id); + let Ok(response) = tokio::task::spawn_blocking(move || { + ureq::get(&url_votes).call().map_err(|e| { + error!("GET for votes failed: {:?}", e); + ErrorCode::RendezVous_InvalidConfiguration + }) + }) + .await + else { + error!("failed to make request"); + return Err(ErrorCode::Core_Exception); + }; + + let mut response = response?; + + let body = response.body_mut().read_to_string().map_err(|e| { + error!("failed to read votes body: {:?}", e); + ErrorCode::RendezVous_InvalidConfiguration + })?; + + let body = body.trim().trim_start_matches('[').trim_end_matches(']'); + let votes: Result, _> = body.split(',').map(|s| u32::from_str(s.trim())).collect(); + + votes.map_err(|e| { + error!("failed to parse votes: {:?}", e); + ErrorCode::RendezVous_InvalidConfiguration + }) + } +} + +impl RnexManager for RankingManager { + type User = RankingUser; + + type InitData = ConnectionInitData; + + async fn init_new_user( + this: rnex_server::PassthroughInitModule, + mod_holder: &rnex_server::ModuleHolder, + remote: &rnex_rmc::RmcConnection, + init_data: &Self::InitData, + weak_user: rnex_server::WeakPassthroughInitModule, + ) -> Self::User { + RankingUser { + rm: this, + pid: init_data.pid, + } + } +} + +impl RnexModule for RankingModule { + type Manager = RankingManager; + + type InitError = VarError; + + async fn create_manager( + _: &rnex_server::ModuleHolder, + ) -> Result { + Ok(RankingManager { + rnex_result_votes_get: env::var("RNEX_SPLATOON_RESULTS_VOTES_GET")?, + rnex_result_post: env::var("RNEX_SPLATOON_RESULTS_POST")?, + rnex_result_get: env::var("RNEX_SPLATOON_RESULTS_GET")?, + }) + } +} diff --git a/rnex-server-nex-modules/rnex-rk/src/main.rs b/rnex-server-nex-modules/rnex-rk/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/rnex-server-nex-modules/rnex-rk/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/rnex-server-nex-modules/rnex-rk/src/user.rs b/rnex-server-nex-modules/rnex-rk/src/user.rs index a6a17cb..279bb9f 100644 --- a/rnex-server-nex-modules/rnex-rk/src/user.rs +++ b/rnex-server-nex-modules/rnex-rk/src/user.rs @@ -1,3 +1,25 @@ +use rnex_rk_protos::{ + LocalRankingProtocol, + ranking::{ + CompetitionRankingGetParam, CompetitionRankingScoreData, CompetitionRankingScoreInfo, + Ranking, UploadCompetitionData, + }, +}; +use rnex_rmc::{qbuffer::QBuffer, response::ErrorCode, rmc_struct}; +use rnex_server::PassthroughInitModule; +use rnex_util::{PID, date_time::DateTime}; +use serde::{Deserialize, Serialize}; +use std::{env, str::FromStr}; +use tracing::{error, info}; + +use crate::RankingManager; + +#[rmc_struct(RankingProtocol)] +pub struct RankingUser { + pub rm: PassthroughInitModule, + pub pid: PID, +} + #[derive(Serialize, Deserialize)] pub struct CompetitionPostResults { pub splatfest_id: u32, @@ -7,50 +29,20 @@ pub struct CompetitionPostResults { pub user: PID, } -// Seperate function because I cannot give a fuck right now -async fn fetch_team_votes(fest_id: u32) -> Result, ErrorCode> { - let endpoint_votes = env::var("RNEX_SPLATOON_RESULTS_VOTES_GET").map_err(|_| { - error!("RNEX_SPLATOON_RESULTS_VOTES_GET not set"); - ErrorCode::RendezVous_InvalidConfiguration - })?; - - let url_votes = format!("{}?splatfest_id={}", endpoint_votes, fest_id); - let mut response = tokio::task::spawn_blocking(|| { - ureq::get(&url_votes).call().map_err(|e| { - error!("GET for votes failed: {:?}", e); - ErrorCode::RendezVous_InvalidConfiguration - }) - }) - .await?; - - let body = response.body_mut().read_to_string().map_err(|e| { - error!("failed to read votes body: {:?}", e); - ErrorCode::RendezVous_InvalidConfiguration - })?; - - let body = body.trim().trim_start_matches('[').trim_end_matches(']'); - let votes: Result, _> = body.split(',').map(|s| u32::from_str(s.trim())).collect(); - - votes.map_err(|e| { - error!("failed to parse votes: {:?}", e); - ErrorCode::RendezVous_InvalidConfiguration - }) -} - -impl Ranking for User { +impl Ranking for RankingUser { async fn competition_ranking_get_param( &self, param: CompetitionRankingGetParam, ) -> Result, ErrorCode> { let fest_id = param.festival_ids.get(0).copied().unwrap_or(0); - let endpoint_results = env::var("RNEX_SPLATOON_RESULTS_GET").map_err(|_| { - error!("RNEX_SPLATOON_RESULTS_GET not set"); - ErrorCode::RendezVous_InvalidConfiguration - })?; - - let url_results = format!("{}?splatfest_id={}", endpoint_results, fest_id); - let response_results = ureq::get(&url_results).call(); + let url_results = format!("{}?splatfest_id={}", self.rm.rnex_result_get, fest_id); + let Ok(response_results) = + tokio::task::spawn_blocking(move || ureq::get(&url_results).call()).await + else { + error!("failed to join task"); + return Err(ErrorCode::Core_Exception); + }; let results: Vec = match response_results { Ok(mut res) => res.body_mut().read_json().map_err(|e| { @@ -69,7 +61,7 @@ impl Ranking for User { let start = offset.min(results.len()); let end = (start + size).min(results.len()); - let team_votes = fetch_team_votes(fest_id)?; + let team_votes = self.rm.fetch_team_votes(fest_id).await?; let mut wins = vec![0u32, 0u32]; for r in &results { let won_team = (r.team_id ^ (!r.team_win)) & 1; @@ -84,7 +76,7 @@ impl Ranking for User { unk: 1, pid: r.user, score: r.score, - modified: KerberosDateTime::now(), + modified: DateTime::now(), unk2: 1, appdata: QBuffer(vec![]), }) @@ -113,14 +105,6 @@ impl Ranking for User { info!("team id: {:?}", param.team_id); info!("did current team win: {:?}", param.team_win); - let endpoint = match env::var("RNEX_SPLATOON_RESULTS_POST") { - Ok(url) => url, - Err(_) => { - error!("RNEX_SPLATOON_RESULTS_POST not set"); - return Ok(false); - } - }; - let payload = CompetitionPostResults { splatfest_id: param.splatfest_id, score: param.score, @@ -137,9 +121,18 @@ impl Ranking for User { } }; - let response = ureq::post(&endpoint) - .header("Content-Type", "application/json") - .send(json_body); + let rm = self.rm.clone(); + + let Ok(response) = tokio::task::spawn_blocking(move || { + ureq::post(&rm.rnex_result_post) + .header("Content-Type", "application/json") + .send(json_body) + }) + .await + else { + error!("unable to spawn blocking"); + return Err(ErrorCode::Core_Exception); + }; match response { Ok(res) => { diff --git a/rnex-util/Cargo.toml b/rnex-util/Cargo.toml index 855e4bb..7928fdf 100644 --- a/rnex-util/Cargo.toml +++ b/rnex-util/Cargo.toml @@ -10,6 +10,7 @@ chrono = "0.4.39" bytemuck = { version = "1.25.0", features = ["derive"] } md-5 = "0.11.0" thiserror = "2.0.18" +nex-account = { version = "0.2.4", registry = "spbr" } [features] nx = [] diff --git a/rnex-util/src/account.rs b/rnex-util/src/account.rs index e2829e8..2f20252 100644 --- a/rnex-util/src/account.rs +++ b/rnex-util/src/account.rs @@ -1,4 +1,5 @@ use md5::{Digest, Md5}; +use nex_account::{grpc::Pid, grpc_client}; use crate::PID; @@ -44,4 +45,17 @@ impl Account { pub fn get_login_data(&self) -> (PID, [u8; 16]) { (self.pid, self.nex_key) } + pub async fn from_nexact(pid: PID, username: &str) -> Option { + let key: [u8; 16] = grpc_client() + .await + .ok()? + .get_nex_key_by_pid(Pid { pid }) + .await + .ok()? + .into_inner() + .key + .try_into() + .ok()?; + Some(Self::new_raw_key(pid, username, key)) + } }