Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 26aa3e34a5 |
13 changed files with 1136 additions and 1424 deletions
|
|
@ -1,5 +1,2 @@
|
||||||
[target.'cfg(target_arch = "x86_64")']
|
[target.'cfg(target_arch = "x86_64")']
|
||||||
rustflags = ["-C", "target-feature=+aes,+sse2"]
|
rustflags = ["-C", "target-feature=+aes,+sse2"]
|
||||||
|
|
||||||
[registries]
|
|
||||||
spbr = { index = "sparse+https://crates.spbr.net/api/v1/crates/" }
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "UPDATE users SET account_level = $1 WHERE username = $2",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int4",
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "9d41e04076235e9a8c857c58c6f5fe7b26cba4da50ce8527ba32128152a31ce6"
|
|
||||||
}
|
|
||||||
64
.sqlx/query-e3349c0e5ab82bbef359cf573caf454f23588f3cfa27299e58863dc9397d55de.json
generated
Normal file
64
.sqlx/query-e3349c0e5ab82bbef359cf573caf454f23588f3cfa27299e58863dc9397d55de.json
generated
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "SELECT game_server_id, maintenance_mode, address, port FROM nex_servers WHERE title_id = $1",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "game_server_id",
|
||||||
|
"type_info": "Varchar",
|
||||||
|
"origin": {
|
||||||
|
"Table": {
|
||||||
|
"table": "nex_servers",
|
||||||
|
"name": "game_server_id"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 1,
|
||||||
|
"name": "maintenance_mode",
|
||||||
|
"type_info": "Bool",
|
||||||
|
"origin": {
|
||||||
|
"Table": {
|
||||||
|
"table": "nex_servers",
|
||||||
|
"name": "maintenance_mode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 2,
|
||||||
|
"name": "address",
|
||||||
|
"type_info": "Inet",
|
||||||
|
"origin": {
|
||||||
|
"Table": {
|
||||||
|
"table": "nex_servers",
|
||||||
|
"name": "address"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 3,
|
||||||
|
"name": "port",
|
||||||
|
"type_info": "Int4",
|
||||||
|
"origin": {
|
||||||
|
"Table": {
|
||||||
|
"table": "nex_servers",
|
||||||
|
"name": "port"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Text"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "e3349c0e5ab82bbef359cf573caf454f23588f3cfa27299e58863dc9397d55de"
|
||||||
|
}
|
||||||
2020
Cargo.lock
generated
2020
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -55,4 +55,3 @@ dsa = "0.6.3"
|
||||||
openssl = {version = "0.10.78", features = ["vendored"]}
|
openssl = {version = "0.10.78", features = ["vendored"]}
|
||||||
time = "0.3.47"
|
time = "0.3.47"
|
||||||
hickory-resolver = { version = "0.24", features = ["tokio-runtime"] }
|
hickory-resolver = { version = "0.24", features = ["tokio-runtime"] }
|
||||||
nex-account = { version = "0.2.3", registry = "spbr" }
|
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
use rocket::serde::json::Json;
|
|
||||||
use rocket::{post, FromForm, State};
|
|
||||||
use rocket::form::Form;
|
|
||||||
use rocket::futures::TryFutureExt;
|
|
||||||
use rocket::http::Status;
|
|
||||||
use crate::account::account::Auth;
|
|
||||||
use crate::json_api::oauth::generate_token::TokenRequest;
|
|
||||||
use crate::nnid::people::{build_oauth_profile, GetOwnOAuthProfileData};
|
|
||||||
use crate::Pool;
|
|
||||||
|
|
||||||
#[derive(FromForm)]
|
|
||||||
pub struct AdminRequest<'r> {
|
|
||||||
pub username: &'r str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[post("/api/v2/admin/ban", data = "<request>")]
|
|
||||||
pub async fn ban_user(pool: &State<Pool>, auth: Auth<true>, request: Form<AdminRequest<'_>>) -> Result<(), Status> {
|
|
||||||
if auth.account_level < 2 {
|
|
||||||
return Err(Status::Forbidden);
|
|
||||||
};
|
|
||||||
|
|
||||||
log::info!("banning user {:?} from moderator {:?}", request.username, auth.username);
|
|
||||||
|
|
||||||
let row = sqlx::query!(
|
|
||||||
"UPDATE users SET account_level = $1 WHERE username = $2",
|
|
||||||
-1,
|
|
||||||
request.username
|
|
||||||
)
|
|
||||||
.execute(pool.inner())
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
log::error!("failed to execute query: {:?}", e);
|
|
||||||
return Err::<(), rocket::http::Status>(Status::InternalServerError);
|
|
||||||
});
|
|
||||||
|
|
||||||
log::info!("banned user {:?}", request.username);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
pub mod bans;
|
|
||||||
|
|
@ -1,3 +1,2 @@
|
||||||
pub mod oauth;
|
pub mod oauth;
|
||||||
pub mod users;
|
pub mod users;
|
||||||
pub mod admin;
|
|
||||||
|
|
@ -41,7 +41,10 @@ pub fn verify_nintendo_password(pid: i32, text_password: &str, db_bcrypt_hash: &
|
||||||
sha.update(&[0x02, 0x65, 0x43, 0x46]);
|
sha.update(&[0x02, 0x65, 0x43, 0x46]);
|
||||||
sha.update(text_password.as_bytes());
|
sha.update(text_password.as_bytes());
|
||||||
let hashed_password_hex = hex::encode(sha.finalize());
|
let hashed_password_hex = hex::encode(sha.finalize());
|
||||||
bcrypt::verify(hashed_password_hex, db_bcrypt_hash).unwrap_or_else(|_| false)
|
match bcrypt::verify(hashed_password_hex, db_bcrypt_hash) {
|
||||||
|
Ok(valid) => valid,
|
||||||
|
Err(_) => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy error responses
|
// dummy error responses
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,6 @@ async fn launch() -> _ {
|
||||||
json_api::users::delete::delete_account,
|
json_api::users::delete::delete_account,
|
||||||
json_api::oauth::authorize::authorize_page,
|
json_api::oauth::authorize::authorize_page,
|
||||||
json_api::oauth::authorize::authorize_submit,
|
json_api::oauth::authorize::authorize_submit,
|
||||||
json_api::admin::bans::ban_user,
|
|
||||||
nnid::people::thing,
|
nnid::people::thing,
|
||||||
// graphql::graphiql,
|
// graphql::graphiql,
|
||||||
// graphql::playground,
|
// graphql::playground,
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,31 @@
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
use crate::Pool;
|
|
||||||
use crate::account::account::{Auth, User, generate_nex_password, generate_password};
|
|
||||||
use crate::dsresponse::Ds;
|
|
||||||
use crate::email::send_verification_email;
|
|
||||||
use crate::error::{Error, Errors};
|
|
||||||
use crate::mii_util::get_mii_img_url;
|
|
||||||
use crate::nnid::timezones::OFFSET_FROM_TIMEZONE;
|
|
||||||
use crate::xml::{Xml, YesNoVal};
|
|
||||||
use chrono::{NaiveDate, NaiveDateTime};
|
use chrono::{NaiveDate, NaiveDateTime};
|
||||||
use gxhash::{gxhash32, gxhash64};
|
use gxhash::{gxhash32, gxhash64};
|
||||||
use nex_account::grpc::{ActStageInfo, ActStageReturn};
|
use rocket::{get, post, put, State};
|
||||||
use nex_account::grpc_client;
|
|
||||||
use rand::prelude::*;
|
|
||||||
use rocket::serde::{Deserialize, Serialize};
|
use rocket::serde::{Deserialize, Serialize};
|
||||||
use rocket::{State, get, post, put};
|
use crate::account::account::{Auth, User, generate_nex_password, generate_password};
|
||||||
|
use crate::dsresponse::Ds;
|
||||||
|
use crate::error::{Error, Errors};
|
||||||
|
use crate::nnid::pid_distribution::next_pid;
|
||||||
|
use crate::nnid::timezones::{OFFSET_FROM_TIMEZONE};
|
||||||
|
use crate::Pool;
|
||||||
|
use crate::xml::{Xml, YesNoVal};
|
||||||
|
use crate::email::send_verification_email;
|
||||||
|
use rand::prelude::*;
|
||||||
|
use crate::mii_util::get_mii_img_url;
|
||||||
|
|
||||||
const DATABASE_ERROR: Errors = Errors {
|
const DATABASE_ERROR: Errors = Errors{
|
||||||
error: &[Error {
|
error: &[
|
||||||
code: "9999",
|
Error{
|
||||||
message: "Internal server error",
|
code: "9999",
|
||||||
}],
|
message: "Internal server error"
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Email {
|
pub struct Email{
|
||||||
address: Box<str>,
|
address: Box<str>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
@ -35,7 +36,7 @@ pub struct UpdateMiiData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct Mii {
|
pub struct Mii{
|
||||||
name: Box<str>,
|
name: Box<str>,
|
||||||
primary: YesNoVal,
|
primary: YesNoVal,
|
||||||
data: Box<str>,
|
data: Box<str>,
|
||||||
|
|
@ -43,7 +44,7 @@ pub struct Mii {
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename(serialize = "person"))]
|
#[serde(rename(serialize = "person"))]
|
||||||
pub struct AccountCreationData {
|
pub struct AccountCreationData{
|
||||||
birth_date: NaiveDate,
|
birth_date: NaiveDate,
|
||||||
user_id: Box<str>,
|
user_id: Box<str>,
|
||||||
password: Box<str>,
|
password: Box<str>,
|
||||||
|
|
@ -55,38 +56,24 @@ pub struct AccountCreationData {
|
||||||
gender: Box<str>,
|
gender: Box<str>,
|
||||||
marketing_flag: YesNoVal,
|
marketing_flag: YesNoVal,
|
||||||
off_device_flag: YesNoVal,
|
off_device_flag: YesNoVal,
|
||||||
region: i32,
|
region: i32
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename(serialize = "person"))]
|
#[serde(rename(serialize = "person"))]
|
||||||
pub struct AccountCreationResponseData {
|
pub struct AccountCreationResponseData{
|
||||||
pid: i32,
|
pid: i32
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/v1/api/people", data = "<data>")]
|
#[post("/v1/api/people", data="<data>")]
|
||||||
pub async fn create_account(
|
pub async fn create_account(database: &State<Pool>, data: Xml<AccountCreationData>) -> Result<Xml<AccountCreationResponseData>, Option<Errors<'_>>>{
|
||||||
database: &State<Pool>,
|
|
||||||
data: Xml<AccountCreationData>,
|
|
||||||
) -> Result<Xml<AccountCreationResponseData>, Option<Errors<'_>>> {
|
|
||||||
let database = database.inner();
|
let database = database.inner();
|
||||||
let nex_password = generate_nex_password();
|
|
||||||
|
|
||||||
let mut client = grpc_client().await.expect("unable to connect to grpc");
|
|
||||||
|
|
||||||
let Ok(ret) = client
|
|
||||||
.stage_new_account(ActStageInfo {
|
|
||||||
password: nex_password.clone().into_bytes(),
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
else {
|
|
||||||
return Err(Some(DATABASE_ERROR));
|
|
||||||
};
|
|
||||||
let ActStageReturn { pid, .. } = ret.into_inner();
|
|
||||||
|
|
||||||
// its fine to crash here if we cant get the next pid as that is in my opinion a dead state
|
// its fine to crash here if we cant get the next pid as that is in my opinion a dead state
|
||||||
// anyways as noone can register anymore, EVER
|
// anyways as noone can register anymore, EVER
|
||||||
|
|
||||||
|
let pid = next_pid(database).await;
|
||||||
|
|
||||||
let verification_code: i32 = rand::rng().random_range(100_000..1_000_000);
|
let verification_code: i32 = rand::rng().random_range(100_000..1_000_000);
|
||||||
|
|
||||||
let AccountCreationData {
|
let AccountCreationData {
|
||||||
|
|
@ -95,8 +82,14 @@ pub async fn create_account(
|
||||||
birth_date,
|
birth_date,
|
||||||
tz_name,
|
tz_name,
|
||||||
language,
|
language,
|
||||||
email: Email { address },
|
email: Email{
|
||||||
mii: Mii { name, data, .. },
|
address
|
||||||
|
},
|
||||||
|
mii: Mii{
|
||||||
|
name,
|
||||||
|
data,
|
||||||
|
..
|
||||||
|
},
|
||||||
marketing_flag,
|
marketing_flag,
|
||||||
gender,
|
gender,
|
||||||
region,
|
region,
|
||||||
|
|
@ -105,16 +98,17 @@ pub async fn create_account(
|
||||||
..
|
..
|
||||||
} = data.0;
|
} = data.0;
|
||||||
|
|
||||||
let account_level = if user_id.to_lowercase().contains("omey") {
|
let account_level = if user_id.to_lowercase().contains("omey"){
|
||||||
-1
|
-1
|
||||||
} else {
|
} else {
|
||||||
0
|
1
|
||||||
};
|
};
|
||||||
|
|
||||||
let password = generate_password(pid, &password).ok_or(None)?;
|
|
||||||
|
|
||||||
sqlx::query!(
|
let password = generate_password(pid, &password).ok_or(None)?;
|
||||||
"
|
let nex_password = generate_nex_password();
|
||||||
|
|
||||||
|
sqlx::query!("
|
||||||
INSERT INTO users (
|
INSERT INTO users (
|
||||||
pid,
|
pid,
|
||||||
username,
|
username,
|
||||||
|
|
@ -152,20 +146,19 @@ pub async fn create_account(
|
||||||
verification_code,
|
verification_code,
|
||||||
account_level,
|
account_level,
|
||||||
nex_password
|
nex_password
|
||||||
)
|
).execute(database).await.unwrap();
|
||||||
.execute(database)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
//generate_s3_images(pid, &data).await;
|
//generate_s3_images(pid, &data).await;
|
||||||
|
|
||||||
if let Err(e) =
|
if let Err(e) = send_verification_email(address.as_ref(), verification_code, user_id.as_ref()).await {
|
||||||
send_verification_email(address.as_ref(), verification_code, user_id.as_ref()).await
|
|
||||||
{
|
|
||||||
println!("Failed to send verification email: {e}");
|
println!("Failed to send verification email: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Xml(AccountCreationResponseData { pid }))
|
Ok(
|
||||||
|
Xml(AccountCreationResponseData{
|
||||||
|
pid
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[derive(Serialize)]
|
// #[derive(Serialize)]
|
||||||
|
|
@ -174,7 +167,7 @@ pub async fn create_account(
|
||||||
// }
|
// }
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct EmailInfoOwnProfileData {
|
struct EmailInfoOwnProfileData{
|
||||||
address: String,
|
address: String,
|
||||||
id: u32,
|
id: u32,
|
||||||
parent: YesNoVal,
|
parent: YesNoVal,
|
||||||
|
|
@ -184,11 +177,11 @@ struct EmailInfoOwnProfileData {
|
||||||
email_type: String,
|
email_type: String,
|
||||||
updated_by: String,
|
updated_by: String,
|
||||||
validated: YesNoVal,
|
validated: YesNoVal,
|
||||||
validated_date: Option<NaiveDateTime>,
|
validated_date: Option<NaiveDateTime>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct EmailInfoOwnOAuthProfileData {
|
struct EmailInfoOwnOAuthProfileData{
|
||||||
address: String,
|
address: String,
|
||||||
id: u32,
|
id: u32,
|
||||||
parent: bool,
|
parent: bool,
|
||||||
|
|
@ -198,37 +191,40 @@ struct EmailInfoOwnOAuthProfileData {
|
||||||
email_type: String,
|
email_type: String,
|
||||||
updated_by: String,
|
updated_by: String,
|
||||||
validated: bool,
|
validated: bool,
|
||||||
validated_date: Option<NaiveDateTime>,
|
validated_date: Option<NaiveDateTime>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct MiiImage {
|
struct MiiImage{
|
||||||
cached_url: String,
|
cached_url: String,
|
||||||
id: u32,
|
id: u32,
|
||||||
url: String,
|
url: String,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
image_type: String,
|
image_type: String
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct MiiImages{
|
||||||
|
mii_image: MiiImage
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct MiiImages {
|
struct MiiDataOwnProfileData{
|
||||||
mii_image: MiiImage,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct MiiDataOwnProfileData {
|
|
||||||
status: String,
|
status: String,
|
||||||
data: String,
|
data: String,
|
||||||
id: u32,
|
id: u32,
|
||||||
mii_hash: String,
|
mii_hash: String,
|
||||||
mii_images: MiiImages,
|
mii_images: MiiImages,
|
||||||
name: String,
|
name: String,
|
||||||
primary: YesNoVal,
|
primary: YesNoVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename(serialize = "person"))]
|
#[serde(rename(serialize = "person"))]
|
||||||
pub struct GetOwnProfileData {
|
pub struct GetOwnProfileData{
|
||||||
active_flag: YesNoVal,
|
active_flag: YesNoVal,
|
||||||
birth_date: NaiveDate,
|
birth_date: NaiveDate,
|
||||||
country: String,
|
country: String,
|
||||||
|
|
@ -250,7 +246,7 @@ pub struct GetOwnProfileData {
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename(serialize = "person"))]
|
#[serde(rename(serialize = "person"))]
|
||||||
pub struct GetOwnOAuthProfileData {
|
pub struct GetOwnOAuthProfileData{
|
||||||
active_flag: bool,
|
active_flag: bool,
|
||||||
birth_date: NaiveDate,
|
birth_date: NaiveDate,
|
||||||
country: String,
|
country: String,
|
||||||
|
|
@ -274,17 +270,17 @@ pub struct GetOwnOAuthProfileData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/v1/api/people/@me/profile")]
|
#[get("/v1/api/people/@me/profile")]
|
||||||
pub fn get_own_profile(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>> {
|
pub fn get_own_profile(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
|
||||||
Ds(Xml(build_profile(user.into())))
|
Ds(Xml(build_profile(user.into())))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/v1/api/people/@me/devices/owner")]
|
#[get("/v1/api/people/@me/devices/owner")]
|
||||||
pub fn get_device_owner(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>> {
|
pub fn get_device_owner(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
|
||||||
Ds(Xml(build_profile(user.into())))
|
Ds(Xml(build_profile(user.into())))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/v1/api/people/@me/devices")]
|
#[post("/v1/api/people/@me/devices")]
|
||||||
pub fn get_own_device(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>> {
|
pub fn get_own_device(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
|
||||||
Ds(Xml(build_profile(user.into())))
|
Ds(Xml(build_profile(user.into())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -318,58 +314,59 @@ pub fn build_profile(user: User) -> GetOwnProfileData {
|
||||||
.replace("\r", "")
|
.replace("\r", "")
|
||||||
.replace(" ", "");
|
.replace(" ", "");
|
||||||
|
|
||||||
GetOwnProfileData {
|
|
||||||
active_flag: YesNoVal(true),
|
GetOwnProfileData {
|
||||||
pid,
|
active_flag: YesNoVal(true),
|
||||||
user_id: username,
|
pid,
|
||||||
gender,
|
user_id: username,
|
||||||
birth_date: birthdate,
|
gender,
|
||||||
country,
|
birth_date: birthdate,
|
||||||
create_date: creation_date,
|
country,
|
||||||
tz_name: timezone,
|
create_date: creation_date,
|
||||||
language,
|
tz_name: timezone,
|
||||||
updated,
|
language,
|
||||||
marketing_flag: YesNoVal(marketing_allowed),
|
updated,
|
||||||
email: EmailInfoOwnProfileData {
|
marketing_flag: YesNoVal(marketing_allowed),
|
||||||
id: gxhash32(email.as_bytes(), 0),
|
email: EmailInfoOwnProfileData {
|
||||||
address: email,
|
id: gxhash32(email.as_bytes(), 0),
|
||||||
validated: YesNoVal(email_verified_since.is_some()),
|
address: email,
|
||||||
validated_date: email_verified_since,
|
validated: YesNoVal(email_verified_since.is_some()),
|
||||||
email_type: "DEFAULT".to_string(),
|
validated_date: email_verified_since,
|
||||||
updated_by: "USER".to_string(),
|
email_type: "DEFAULT".to_string(),
|
||||||
reachable: YesNoVal(true),
|
updated_by: "USER".to_string(),
|
||||||
primary: YesNoVal(true),
|
reachable: YesNoVal(true),
|
||||||
parent: YesNoVal(false),
|
primary: YesNoVal(true),
|
||||||
},
|
parent: YesNoVal(false),
|
||||||
mii: MiiDataOwnProfileData {
|
},
|
||||||
id: gxhash32(mii_data.as_bytes(), 0),
|
mii: MiiDataOwnProfileData {
|
||||||
mii_hash: hex::encode(bytemuck::bytes_of(
|
id: gxhash32(mii_data.as_bytes(), 0),
|
||||||
&(gxhash64(mii_data.as_bytes(), 1) & !(0x1000000000000000)),
|
mii_hash: hex::encode(bytemuck::bytes_of(
|
||||||
)),
|
&(gxhash64(mii_data.as_bytes(), 1) & !(0x1000000000000000))
|
||||||
name: crate::mii_util::MiiData::read(&mii_data)
|
)),
|
||||||
|
name: crate::mii_util::MiiData::read(&mii_data)
|
||||||
.map(|v| v.name)
|
.map(|v| v.name)
|
||||||
.unwrap_or_else(|| "INVALID".to_string()),
|
.unwrap_or_else(|| "INVALID".to_string()),
|
||||||
primary: YesNoVal(true),
|
primary: YesNoVal(true),
|
||||||
data: mii_data,
|
data: mii_data,
|
||||||
status: "COMPLETED".to_string(),
|
status: "COMPLETED".to_string(),
|
||||||
mii_images: MiiImages {
|
mii_images: MiiImages {
|
||||||
mii_image: {
|
mii_image: {
|
||||||
let image_url = get_mii_img_url(pid, "tga");
|
let image_url = get_mii_img_url(pid, "tga");
|
||||||
let url_hash = gxhash32(image_url.as_bytes(), 0);
|
let url_hash = gxhash32(image_url.as_bytes(), 0);
|
||||||
MiiImage {
|
MiiImage {
|
||||||
image_type: "standard".to_string(),
|
image_type: "standard".to_string(),
|
||||||
id: url_hash,
|
id: url_hash,
|
||||||
url: image_url.clone(),
|
url: image_url.clone(),
|
||||||
cached_url: image_url,
|
cached_url: image_url,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
},
|
off_device_flag: YesNoVal(off_device_allowed),
|
||||||
off_device_flag: YesNoVal(off_device_allowed),
|
region,
|
||||||
region,
|
utc_offset: timezone_offset,
|
||||||
utc_offset: timezone_offset,
|
account_level,
|
||||||
account_level,
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_oauth_profile(user: User) -> GetOwnOAuthProfileData {
|
pub fn build_oauth_profile(user: User) -> GetOwnOAuthProfileData {
|
||||||
|
|
@ -407,61 +404,62 @@ pub fn build_oauth_profile(user: User) -> GetOwnOAuthProfileData {
|
||||||
.replace("\r", "")
|
.replace("\r", "")
|
||||||
.replace(" ", "");
|
.replace(" ", "");
|
||||||
|
|
||||||
GetOwnOAuthProfileData {
|
|
||||||
id,
|
GetOwnOAuthProfileData {
|
||||||
sub,
|
id,
|
||||||
uid,
|
sub,
|
||||||
active_flag: true,
|
uid,
|
||||||
pid,
|
active_flag: true,
|
||||||
user_id: username,
|
pid,
|
||||||
gender,
|
user_id: username,
|
||||||
birth_date: birthdate,
|
gender,
|
||||||
country,
|
birth_date: birthdate,
|
||||||
create_date: creation_date,
|
country,
|
||||||
tz_name: timezone,
|
create_date: creation_date,
|
||||||
language,
|
tz_name: timezone,
|
||||||
updated,
|
language,
|
||||||
marketing_flag: marketing_allowed,
|
updated,
|
||||||
email: EmailInfoOwnOAuthProfileData {
|
marketing_flag: marketing_allowed,
|
||||||
id: gxhash32(email.as_bytes(), 0),
|
email: EmailInfoOwnOAuthProfileData {
|
||||||
address: email,
|
id: gxhash32(email.as_bytes(), 0),
|
||||||
validated: email_verified_since.is_some(),
|
address: email,
|
||||||
validated_date: email_verified_since,
|
validated: email_verified_since.is_some(),
|
||||||
email_type: "DEFAULT".to_string(),
|
validated_date: email_verified_since,
|
||||||
updated_by: "USER".to_string(),
|
email_type: "DEFAULT".to_string(),
|
||||||
reachable: true,
|
updated_by: "USER".to_string(),
|
||||||
primary: true,
|
reachable: true,
|
||||||
parent: false,
|
primary: true,
|
||||||
},
|
parent: false,
|
||||||
mii: MiiDataOwnProfileData {
|
},
|
||||||
id: gxhash32(mii_data.as_bytes(), 0),
|
mii: MiiDataOwnProfileData {
|
||||||
mii_hash: hex::encode(bytemuck::bytes_of(
|
id: gxhash32(mii_data.as_bytes(), 0),
|
||||||
&(gxhash64(mii_data.as_bytes(), 1) & !(0x1000000000000000)),
|
mii_hash: hex::encode(bytemuck::bytes_of(
|
||||||
)),
|
&(gxhash64(mii_data.as_bytes(), 1) & !(0x1000000000000000))
|
||||||
name: crate::mii_util::MiiData::read(&mii_data)
|
)),
|
||||||
|
name: crate::mii_util::MiiData::read(&mii_data)
|
||||||
.map(|v| v.name)
|
.map(|v| v.name)
|
||||||
.unwrap_or_else(|| "INVALID".to_string()),
|
.unwrap_or_else(|| "INVALID".to_string()),
|
||||||
primary: YesNoVal(true),
|
primary: YesNoVal(true),
|
||||||
data: mii_data,
|
data: mii_data,
|
||||||
status: "COMPLETED".to_string(),
|
status: "COMPLETED".to_string(),
|
||||||
mii_images: MiiImages {
|
mii_images: MiiImages {
|
||||||
mii_image: {
|
mii_image: {
|
||||||
let image_url = get_mii_img_url(pid, "png");
|
let image_url = get_mii_img_url(pid, "png");
|
||||||
let url_hash = gxhash32(image_url.as_bytes(), 0);
|
let url_hash = gxhash32(image_url.as_bytes(), 0);
|
||||||
MiiImage {
|
MiiImage {
|
||||||
image_type: "standard".to_string(),
|
image_type: "standard".to_string(),
|
||||||
id: url_hash,
|
id: url_hash,
|
||||||
url: image_url.clone(),
|
url: image_url.clone(),
|
||||||
cached_url: image_url,
|
cached_url: image_url,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
},
|
off_device_flag: off_device_allowed,
|
||||||
off_device_flag: off_device_allowed,
|
region,
|
||||||
region,
|
utc_offset: timezone_offset,
|
||||||
utc_offset: timezone_offset,
|
account_level,
|
||||||
account_level,
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/v1/api/people/@me/miis/@primary", data = "<data>")]
|
#[put("/v1/api/people/@me/miis/@primary", data = "<data>")]
|
||||||
|
|
@ -481,8 +479,8 @@ pub async fn change_mii(
|
||||||
mii_data,
|
mii_data,
|
||||||
pid
|
pid
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(db)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
println!("Failed to update Mii data for PID {}: {:?}", pid, e);
|
println!("Failed to update Mii data for PID {}: {:?}", pid, e);
|
||||||
|
|
@ -494,5 +492,8 @@ pub async fn change_mii(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[post("/v1/api/people/@me/agreements")]
|
#[post("/v1/api/people/@me/agreements")]
|
||||||
pub async fn thing() {}
|
pub async fn thing(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#![deprecated = "handled by nex-account now"]
|
|
||||||
/*
|
|
||||||
use crate::Pool;
|
use crate::Pool;
|
||||||
|
|
||||||
pub async fn next_pid(pool: &Pool) -> i32{
|
pub async fn next_pid(pool: &Pool) -> i32{
|
||||||
loop {
|
loop {
|
||||||
let next_pid = sqlx::query!("SELECT nextval('pid_counter') as pid")
|
let next_pid = sqlx::query!("SELECT nextval('pid_counter') as pid")
|
||||||
|
|
@ -27,5 +26,4 @@ pub async fn next_pid(pool: &Pool) -> i32{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
@ -1,65 +1,69 @@
|
||||||
use crate::Pool;
|
use std::net::Ipv4Addr;
|
||||||
use crate::account::account::Auth;
|
use rocket::{get, State};
|
||||||
use crate::error::{Error, Errors};
|
|
||||||
use crate::nnid::oauth::generate_token::create_token;
|
|
||||||
use crate::nnid::oauth::generate_token::token_type::NEX_TOKEN;
|
|
||||||
use crate::xml::Xml;
|
|
||||||
use nex_account::grpc::Pid;
|
|
||||||
use reqwest::header::SERVER;
|
|
||||||
use rocket::{State, get};
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use sqlx::types::ipnetwork::IpNetwork::V4;
|
use sqlx::types::ipnetwork::IpNetwork::V4;
|
||||||
use std::net::Ipv4Addr;
|
use crate::account::account::Auth;
|
||||||
|
use crate::error::{Error, Errors};
|
||||||
|
use crate::nnid::oauth::generate_token::{create_token};
|
||||||
|
use crate::nnid::oauth::generate_token::token_type::NEX_TOKEN;
|
||||||
|
use crate::Pool;
|
||||||
|
use crate::xml::Xml;
|
||||||
|
|
||||||
const NO_IPV4_ERROR: Errors = Errors {
|
const NO_IPV4_ERROR: Errors = Errors{
|
||||||
error: &[Error {
|
error: &[
|
||||||
code: "1022",
|
Error{
|
||||||
message: "Server is not a valid IPv4 address",
|
code: "1022",
|
||||||
}],
|
message: "Server is not a valid IPv4 address"
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const SERVER_ERROR: Errors = Errors {
|
const SERVER_ERROR: Errors = Errors{
|
||||||
error: &[Error {
|
error: &[
|
||||||
code: "9999",
|
Error{
|
||||||
message: "Internal Server Error",
|
code: "9999",
|
||||||
}],
|
message: "Internal Server Error"
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const NO_SERVER_ERROR: Errors = Errors {
|
const NO_SERVER_ERROR: Errors = Errors{
|
||||||
error: &[Error {
|
error: &[
|
||||||
code: "1021",
|
Error{
|
||||||
message: "The requested game server was not found",
|
code: "1021",
|
||||||
}],
|
message: "The requested game server was not found"
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const MAINTENANCE_ERROR: Errors = Errors {
|
const MAINTENANCE_ERROR: Errors = Errors{
|
||||||
error: &[Error {
|
error: &[
|
||||||
code: "2002",
|
Error{
|
||||||
message: "The requested game server is under maintenance",
|
code: "2002",
|
||||||
}],
|
message: "The requested game server is under maintenance"
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename = "nex_token")]
|
#[serde(rename = "nex_token")]
|
||||||
pub struct NexToken {
|
pub struct NexToken{
|
||||||
host: Ipv4Addr,
|
host: Ipv4Addr,
|
||||||
nex_password: String,
|
nex_password: String,
|
||||||
pid: i32,
|
pid: i32,
|
||||||
port: u16,
|
port: u16,
|
||||||
token: Box<str>,
|
token: String
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename = "service_token")]
|
#[serde(rename = "service_token")]
|
||||||
pub struct ServiceToken {
|
pub struct ServiceToken{
|
||||||
token: String,
|
token: String
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/v1/api/provider/service_token/@me")]
|
#[get("/v1/api/provider/service_token/@me")]
|
||||||
pub async fn get_service_token(
|
pub async fn get_service_token(pool: &State<Pool>, auth: Auth<true, false>) -> Result<Xml<ServiceToken>, Option<Errors<'static>>>{
|
||||||
pool: &State<Pool>,
|
|
||||||
auth: Auth<true, false>,
|
|
||||||
) -> Result<Xml<ServiceToken>, Option<Errors<'static>>> {
|
|
||||||
// just gonna put this here as a side note for the future:
|
// just gonna put this here as a side note for the future:
|
||||||
// we could also be using key derivation to derive the nex token as if it were a key
|
// we could also be using key derivation to derive the nex token as if it were a key
|
||||||
// that way we could reduce the data the database needs to store and also reduce the transfer
|
// that way we could reduce the data the database needs to store and also reduce the transfer
|
||||||
|
|
@ -71,15 +75,17 @@ pub async fn get_service_token(
|
||||||
|
|
||||||
let token = create_token(pool, auth.pid, NEX_TOKEN, None).await;
|
let token = create_token(pool, auth.pid, NEX_TOKEN, None).await;
|
||||||
|
|
||||||
Ok(Xml(ServiceToken { token }))
|
Ok(
|
||||||
|
Xml(
|
||||||
|
ServiceToken{
|
||||||
|
token
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/v1/api/provider/nex_token/@me?<game_server_id>")]
|
#[get("/v1/api/provider/nex_token/@me?<game_server_id>")]
|
||||||
pub async fn get_nex_token(
|
pub async fn get_nex_token(pool: &State<Pool>, auth: Auth<true, false>, game_server_id: &str) -> Result<Xml<NexToken>, Option<Errors<'static>>>{
|
||||||
pool: &State<Pool>,
|
|
||||||
auth: Auth<true, false>,
|
|
||||||
game_server_id: &str,
|
|
||||||
) -> Result<Xml<NexToken>, Option<Errors<'static>>> {
|
|
||||||
// just gonna put this here as a side note for the future:
|
// just gonna put this here as a side note for the future:
|
||||||
// we could also be using key derivation to derive the nex token as if it were a key
|
// we could also be using key derivation to derive the nex token as if it were a key
|
||||||
// that way we could reduce the data the database needs to store and also reduce the transfer
|
// that way we could reduce the data the database needs to store and also reduce the transfer
|
||||||
|
|
@ -102,37 +108,28 @@ pub async fn get_nex_token(
|
||||||
Some(row) => row,
|
Some(row) => row,
|
||||||
None => return Err(Some(NO_SERVER_ERROR)),
|
None => return Err(Some(NO_SERVER_ERROR)),
|
||||||
}; // only crash on db failure (not missing row)
|
}; // only crash on db failure (not missing row)
|
||||||
|
|
||||||
if server.maintenance_mode {
|
if server.maintenance_mode {
|
||||||
return Err(Some(MAINTENANCE_ERROR));
|
return Err(Some(MAINTENANCE_ERROR))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let token = create_token(pool, auth.pid, NEX_TOKEN, None).await;
|
||||||
|
|
||||||
let V4(host) = server.address else {
|
let V4(host) = server.address else {
|
||||||
return Err(Some(NO_IPV4_ERROR));
|
return Err(Some(NO_IPV4_ERROR));
|
||||||
};
|
};
|
||||||
|
|
||||||
let host = host.ip();
|
let host = host.ip();
|
||||||
|
|
||||||
let mut client = nex_account::grpc_client().await.unwrap();
|
Ok(
|
||||||
let Ok(key) = client.get_nex_key_by_pid(Pid { pid: auth.pid }).await else {
|
Xml(
|
||||||
println!("account does not exist on nex-account server");
|
NexToken{
|
||||||
return Err(Some(SERVER_ERROR));
|
host,
|
||||||
};
|
port: server.port as u16,
|
||||||
|
nex_password: auth.nex_password.clone(),
|
||||||
let token = nex_account::gen_nexact_token(
|
pid: auth.pid,
|
||||||
auth.pid,
|
token
|
||||||
key.into_inner()
|
}
|
||||||
.key
|
)
|
||||||
.try_into()
|
|
||||||
.map_err(|_| Some(SERVER_ERROR))?,
|
|
||||||
)
|
)
|
||||||
.expect("NEX_ACCOUNT_KEYPAIR not set");
|
|
||||||
|
|
||||||
Ok(Xml(NexToken {
|
|
||||||
host,
|
|
||||||
port: server.port as u16,
|
|
||||||
nex_password: auth.nex_password.clone(),
|
|
||||||
pid: auth.pid,
|
|
||||||
token,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue