diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..64cd88d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "grpc-protobufs"] + path = grpc-protobufs + url = https://github.com/PretendoNetwork/grpc-protobufs.git diff --git a/Cargo.lock b/Cargo.lock index 81b7408..4bfb3e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,6 +23,7 @@ dependencies = [ "mii", "minio", "once_cell", + "prost", "quick-xml", "rocket", "serde", @@ -31,6 +32,8 @@ dependencies = [ "sqlx", "thiserror", "tokio", + "tonic", + "tonic-build", ] [[package]] @@ -139,6 +142,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "anyhow" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" + [[package]] name = "argon2" version = "0.5.3" @@ -231,6 +240,53 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "axum" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" +dependencies = [ + "async-trait", + "axum-core", + "bytes", + "futures-util", + "http 1.2.0", + "http-body 1.0.1", + "http-body-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper", + "tower 0.5.2", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.2.0", + "http-body 1.0.1", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.74" @@ -722,6 +778,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "fixedbitset" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" + [[package]] name = "flume" version = "0.11.1" @@ -947,7 +1009,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap", + "indexmap 2.7.1", "slab", "tokio", "tokio-util", @@ -966,13 +1028,19 @@ dependencies = [ "futures-core", "futures-sink", "http 1.2.0", - "indexmap", + "indexmap 2.7.1", "slab", "tokio", "tokio-util", "tracing", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hashbrown" version = "0.14.5" @@ -1186,6 +1254,19 @@ dependencies = [ "tower-service", ] +[[package]] +name = "hyper-timeout" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" +dependencies = [ + "hyper 1.6.0", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + [[package]] name = "hyper-tls" version = "0.6.0" @@ -1383,6 +1464,16 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + [[package]] name = "indexmap" version = "2.7.1" @@ -1433,6 +1524,15 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.14" @@ -1532,6 +1632,12 @@ dependencies = [ "regex-automata 0.1.10", ] +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "md-5" version = "0.10.6" @@ -1901,6 +2007,36 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "petgraph" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3672b37090dbd86368a4145bc067582552b29c27377cad4e0a306c97f9bd7772" +dependencies = [ + "fixedbitset", + "indexmap 2.7.1", +] + +[[package]] +name = "pin-project" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.98", +] + [[package]] name = "pin-project-lite" version = "0.2.16" @@ -1955,6 +2091,16 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "prettyplease" +version = "0.2.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1ccf34da56fc294e7d4ccf69a85992b7dfb826b7cf57bac6a70bba3494cc08a" +dependencies = [ + "proc-macro2", + "syn 2.0.98", +] + [[package]] name = "proc-macro2" version = "1.0.93" @@ -1977,6 +2123,58 @@ dependencies = [ "yansi", ] +[[package]] +name = "prost" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2796faa41db3ec313a31f7624d9286acf277b52de526150b7e69f3debf891ee5" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be769465445e8c1474e9c5dac2018218498557af32d9ed057325ec9a41ae81bf" +dependencies = [ + "heck", + "itertools", + "log", + "multimap", + "once_cell", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "regex", + "syn 2.0.98", + "tempfile", +] + +[[package]] +name = "prost-derive" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 2.0.98", +] + +[[package]] +name = "prost-types" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52c2c1bf36ddb1a1c396b3601a3cec27c2462e45f07c386894ec3ccf5332bd16" +dependencies = [ + "prost", +] + [[package]] name = "quick-xml" version = "0.37.2" @@ -2135,7 +2333,7 @@ dependencies = [ "tokio", "tokio-native-tls", "tokio-util", - "tower", + "tower 0.5.2", "tower-service", "url", "wasm-bindgen", @@ -2173,7 +2371,7 @@ dependencies = [ "either", "figment", "futures", - "indexmap", + "indexmap 2.7.1", "log", "memchr", "multer", @@ -2204,7 +2402,7 @@ checksum = "575d32d7ec1a9770108c879fc7c47815a80073f96ca07ff9525a94fcede1dd46" dependencies = [ "devise", "glob", - "indexmap", + "indexmap 2.7.1", "proc-macro2", "quote", "rocket_http", @@ -2224,7 +2422,7 @@ dependencies = [ "futures", "http 0.2.12", "hyper 0.14.32", - "indexmap", + "indexmap 2.7.1", "log", "memchr", "pear", @@ -2561,7 +2759,7 @@ dependencies = [ "futures-util", "hashbrown 0.15.2", "hashlink", - "indexmap", + "indexmap 2.7.1", "log", "memchr", "native-tls", @@ -3026,13 +3224,77 @@ version = "0.22.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" dependencies = [ - "indexmap", + "indexmap 2.7.1", "serde", "serde_spanned", "toml_datetime", "winnow", ] +[[package]] +name = "tonic" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" +dependencies = [ + "async-stream", + "async-trait", + "axum", + "base64", + "bytes", + "h2 0.4.8", + "http 1.2.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.6.0", + "hyper-timeout", + "hyper-util", + "percent-encoding", + "pin-project", + "prost", + "socket2", + "tokio", + "tokio-stream", + "tower 0.4.13", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tonic-build" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9557ce109ea773b399c9b9e5dca39294110b74f1f342cb347a80d1fce8c26a11" +dependencies = [ + "prettyplease", + "proc-macro2", + "prost-build", + "prost-types", + "quote", + "syn 2.0.98", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "indexmap 1.9.3", + "pin-project", + "pin-project-lite", + "rand", + "slab", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower" version = "0.5.2" diff --git a/Cargo.toml b/Cargo.toml index 84aa610..cc97298 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,4 +30,11 @@ cbc = "0.1.2" mii = { path = "./mii" } minio = { git = "https://github.com/minio/minio-rs.git" } crc32fast = "1.4.2" -gxhash = "3.4.1" \ No newline at end of file +gxhash = "3.4.1" + +tonic = "0.12.3" +prost = "0.13.4" + + +[build-dependencies] +tonic-build = "0.12.3" \ No newline at end of file diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..f7a79e0 --- /dev/null +++ b/build.rs @@ -0,0 +1,11 @@ + +fn main(){ + tonic_build::configure() + .build_server(true) + .build_client(false) + .compile_protos( + &["grpc-protobufs/account/account_service.proto"], + &["grpc-protobufs/account"] + ) + .unwrap(); +} \ No newline at end of file diff --git a/grpc-protobufs b/grpc-protobufs new file mode 160000 index 0000000..405fe9b --- /dev/null +++ b/grpc-protobufs @@ -0,0 +1 @@ +Subproject commit 405fe9b47b416e76b21d7087b2ed11606deccfcf diff --git a/src/grpc/mod.rs b/src/grpc/mod.rs new file mode 100644 index 0000000..9c6304e --- /dev/null +++ b/src/grpc/mod.rs @@ -0,0 +1,30 @@ +use tonic::{async_trait, Request, Response, Status}; +use crate::grpc::grpc::{ExchangeTokenForUserDataRequest, GetNexDataRequest, GetNexDataResponse, GetNexPasswordRequest, GetNexPasswordResponse, GetUserDataRequest, GetUserDataResponse, UpdatePnidPermissionsRequest}; +use crate::Pool; + +mod grpc { + tonic::include_proto!("account"); +} + + +pub struct AccountService(pub Pool); + +#[async_trait] +impl grpc::account_server::Account for AccountService{ + async fn exchange_token_for_user_data(&self, request: Request) -> Result, Status> { + todo!() + } + async fn get_nex_data(&self, request: Request) -> Result, Status> { + todo!() + } + async fn get_nex_password(&self, request: Request) -> Result, Status> { + todo!() + } + async fn update_pnid_permissions(&self, request: Request) -> Result, Status> { + todo!() + } + + async fn get_user_data(&self, request: Request) -> Result, Status> { + todo!() + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 4863ab3..a4d3560 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ mod account; mod error; mod dsresponse; mod data_wrapper; +mod grpc; type Pool = sqlx::Pool; @@ -61,6 +62,7 @@ async fn launch() -> _ { nnid::email::validate, nnid::people::create_account, nnid::people::get_own_profile, - nnid::oauth::generate_token::generate_token + nnid::oauth::generate_token::generate_token, + nnid::provider::get_nex_token, ]) } diff --git a/src/nnid/mod.rs b/src/nnid/mod.rs index 9c22585..3fa13c1 100644 --- a/src/nnid/mod.rs +++ b/src/nnid/mod.rs @@ -6,3 +6,4 @@ pub mod email; pub mod oauth; mod pid_distribution; pub mod people; +pub mod provider; diff --git a/src/nnid/oauth/generate_token.rs b/src/nnid/oauth/generate_token.rs index 33eb667..c8ffea8 100644 --- a/src/nnid/oauth/generate_token.rs +++ b/src/nnid/oauth/generate_token.rs @@ -117,8 +117,6 @@ pub async fn generate_token(pool: &State, data: Form> let access_token = TokenReturnData::new(user.pid, pool).await; - - Ok(Xml(TokenRequestReturnData{ access_token })) diff --git a/src/nnid/provider.rs b/src/nnid/provider.rs new file mode 100644 index 0000000..224add1 --- /dev/null +++ b/src/nnid/provider.rs @@ -0,0 +1,20 @@ +use std::net::Ipv4Addr; +use std::str::FromStr; +use rocket::get; +use serde::Serialize; +use crate::xml::Xml; + +#[derive(Serialize)] +#[serde(rename = "nex_token")] +struct NexToken{ + host: Ipv4Addr, + nex_password: String, + pid: i32, + port: u16, + token: String +} + +#[get("/v1/api/provider/nex_token/@me?")] +pub async fn get_nex_token(game_server_id: String) -> Option>{ + None +} \ No newline at end of file