diff --git a/rnex-core/src/executables/backend_server_secure.rs b/rnex-core/src/executables/backend_server_secure.rs index 88f2508..aa889ca 100644 --- a/rnex-core/src/executables/backend_server_secure.rs +++ b/rnex-core/src/executables/backend_server_secure.rs @@ -5,23 +5,24 @@ use rnex_core::common::setup; async fn main() { setup(); + #[cfg(feature = "database-support")] + { + use rnex_core::executables::common::DB_POOL; + use sqlx::PgPool; + let database_url = std::env::var("RNEX_DATASTORE_DATABASE_URL") + .expect("RNEX_DATASTORE_DATABASE_URL must be set"); + + let pool = PgPool::connect(&database_url) + .await + .expect("Failed to create pool"); + + DB_POOL.set(pool).expect("failed to set global DB_POOL"); + } + cfg_if! { if #[cfg(feature = "friends")]{ use rnex_core::executables::friends_backend::start_friends_backend; start_friends_backend().await; - } else if #[cfg(feature = "datastore")] { - use rnex_core::executables::common::DB_POOL; - use sqlx::PgPool; - let database_url = std::env::var("RNEX_DATASTORE_DATABASE_URL") - .expect("RNEX_DATASTORE_DATABASE_URL must be set"); - - let pool = PgPool::connect(&database_url) - .await - .expect("Failed to create pool"); - - DB_POOL.set(pool).expect("failed to set global DB_POOL"); - use rnex_core::executables::regular_backend; - regular_backend::start_regular_backend().await } else { use rnex_core::executables::regular_backend; regular_backend::start_regular_backend().await diff --git a/rnex-core/src/executables/common.rs b/rnex-core/src/executables/common.rs index ccc5d41..5115531 100644 --- a/rnex-core/src/executables/common.rs +++ b/rnex-core/src/executables/common.rs @@ -1,23 +1,18 @@ +use crate::reggie::UnitPacketRead; +use cfg_if::cfg_if; +use log::error; use once_cell::sync::Lazy; use rnex_core::nex::account::Account; use rnex_core::rmc::protocols::{RmcCallable, RmcConnection, new_rmc_gateway_connection}; use rnex_core::rmc::structures::RmcSerialize; use rnex_core::rnex_proxy_common::ConnectionInitData; use std::env; +use std::error::Error; use std::fmt::Display; use std::io::{Cursor, Read, Write}; use std::net::{Ipv4Addr, SocketAddrV4, TcpStream}; use std::sync::Arc; use tokio::net::TcpListener; -cfg_if! { - if #[cfg(feature = "datastore")] { - use sqlx::postgres::PgPool; - } -} -use crate::reggie::UnitPacketRead; -use cfg_if::cfg_if; -use log::error; -use std::error::Error; const IP_REQ_SERVICE_URLS: &[(&str, &str, &str)] = &[ ("ipinfo.io:80", "ipinfo.io", "/ip"), @@ -30,11 +25,12 @@ const IP_REQ_SERVICE_URLS: &[(&str, &str, &str)] = &[ ]; cfg_if! { - if #[cfg(feature = "datastore")] { + if #[cfg(feature = "database-support")] { use std::sync::{LazyLock, OnceLock}; - pub static RNEX_DATASTORE_DATABASE_URL: LazyLock = LazyLock::new(|| { - std::env::var("RNEX_DATASTORE_DATABASE_URL") - .expect("RNEX_DATASTORE_DATABASE_URL must be set") + use sqlx::postgres::PgPool; + pub static RNEX_DATABASE_URL: LazyLock = LazyLock::new(|| { + std::env::var("RNEX_DATABASE_URL") + .expect("RNEX_DATABASE_URL must be set") }); pub static DB_POOL: OnceLock = OnceLock::new(); @@ -42,6 +38,10 @@ cfg_if! { pub fn get_db() -> &'static PgPool { DB_POOL.get().expect("db_pool not initialized") } + } +} +cfg_if! { + if #[cfg(feature = "datastore")]{ pub static RNEX_DATASTORE_S3_ENDPOINT: LazyLock = LazyLock::new(|| { std::env::var("RNEX_DATASTORE_S3_ENDPOINT") .expect("RNEX_DATASTORE_S3_ENDPOINT must be set") diff --git a/rnex-core/src/nex/friends_handler.rs b/rnex-core/src/nex/friends_handler.rs index 3af6ff6..1312ab6 100644 --- a/rnex-core/src/nex/friends_handler.rs +++ b/rnex-core/src/nex/friends_handler.rs @@ -10,7 +10,9 @@ use macros::rmc_struct; use rnex_core::rmc::protocols::account_management::{ AccountManagement, RawAccountManagement, RawAccountManagementInfo, RemoteAccountManagement, }; -use rnex_core::rmc::protocols::friends::{Friends, RawFriends, RawFriendsInfo, RemoteFriends}; +use rnex_core::rmc::protocols::friends_wiiu::{ + FriendsWiiU, RawFriendsWiiU, RawFriendsWiiUInfo, RemoteFriendsWiiU, +}; use rnex_core::rmc::protocols::nintendo_notification::{ NintendoNotification, RawNintendoNotification, RawNintendoNotificationInfo, RemoteNintendoNotification, @@ -22,9 +24,9 @@ use rnex_core::{ nex::common::get_station_urls, prudp::{socket_addr::PRUDPSockAddr, station_url::StationUrl}, rmc::{ - protocols::friends::{ + protocols::friends_wiiu::{ BlacklistedPrincipal, Comment, FriendInfo, FriendRequest, NNAInfo, NintendoPresenceV2, - PersistentNotification, PrincipalPreference, + PersistentNotification, PrincipalPreference, PrincipalRequestBlockSetting, }, response::ErrorCode, structures::{any::Any, qresult::QResult}, @@ -34,7 +36,7 @@ use std::sync::atomic::Ordering::Relaxed; use tokio::spawn; use tokio::sync::RwLock; -use rnex_core::rmc::protocols::friends::{GameKey, MiiV2, PrincipalBasicInfo}; +use rnex_core::rmc::protocols::friends_wiiu::{GameKey, MiiV2, PrincipalBasicInfo}; use rnex_core::PID; @@ -47,7 +49,7 @@ use rnex_core::rmc::structures::data::Data; define_rmc_proto!( proto FriendsUser{ Secure, - Friends + FriendsWiiU } ); define_rmc_proto!( @@ -112,7 +114,7 @@ pub fn friend_info_from_user(data: &UserData) -> FriendInfo { } } -impl Friends for FriendsUser { +impl FriendsWiiU for FriendsUser { async fn update_and_get_all_information( &self, info: NNAInfo, @@ -320,8 +322,8 @@ impl Friends for FriendsUser { async fn check_setting_status(&self) -> Result { Ok(0xFF) } - - async fn update_preference(&self, preference: PrincipalPreference) -> Result<(),ErrorCode> { + + async fn update_preference(&self, preference: PrincipalPreference) -> Result<(), ErrorCode> { info!("user updated preference: {:?}", preference); let any_presence: Any = Any::new(&preference).expect("out of memory"); @@ -337,9 +339,87 @@ impl Friends for FriendsUser { .await; } drop(users); - + Ok(()) } + + async fn add_friend(&self, friend: PID) -> Result<(FriendRequest, FriendInfo), ErrorCode> { + todo!() + } + + async fn add_friend_by_name( + &self, + name: String, + ) -> Result<(FriendRequest, FriendInfo), ErrorCode> { + todo!() + } + + async fn remove_friend(&self, friend: PID) -> Result<(), ErrorCode> { + todo!() + } + + async fn add_friend_request( + &self, + friend: PID, + unk1: u8, + message: String, + unk2: u8, + unk3: String, + game_key: GameKey, + unk4: KerberosDateTime, + ) -> Result<(FriendRequest, FriendInfo), ErrorCode> { + todo!() + } + + async fn cancel_friend_request(&self, id: u64) -> Result<(), ErrorCode> { + todo!() + } + + async fn accept_friend_request(&self, id: u64) -> Result { + todo!() + } + + async fn delete_friend_request(&self, id: u64) -> Result<(), ErrorCode> { + todo!() + } + + async fn deny_friend_request(&self, id: u64) -> Result { + todo!() + } + + async fn mark_friend_requests_as_received(&self, ids: Vec) -> Result<(), ErrorCode> { + todo!() + } + + async fn add_blacklist( + &self, + principal: BlacklistedPrincipal, + ) -> Result { + todo!() + } + + async fn remove_blacklist(&self, id: PID) -> Result<(), ErrorCode> { + todo!() + } + + async fn update_mii(&self, presence: MiiV2) -> Result { + todo!() + } + + async fn update_comment(&self, presence: Comment) -> Result { + todo!() + } + + async fn get_basic_info(&self, pids: Vec) -> Result, ErrorCode> { + todo!() + } + + async fn get_request_block_settings( + &self, + unk: Vec, + ) -> Result, ErrorCode> { + todo!() + } } type HMacMd5 = hmac::Hmac; diff --git a/rnex-core/src/rmc/protocols/friends_wiiu.rs b/rnex-core/src/rmc/protocols/friends_wiiu.rs index a539008..5437665 100644 --- a/rnex-core/src/rmc/protocols/friends_wiiu.rs +++ b/rnex-core/src/rmc/protocols/friends_wiiu.rs @@ -4,6 +4,8 @@ use rnex_core::{kerberos::KerberosDateTime, rmc::response::ErrorCode}; use rnex_core::rmc::structures::data::Data; +use rnex_core::PID; + #[derive(RmcSerialize, Debug, Clone)] #[rmc_struct(0)] pub struct MiiV2 { @@ -147,6 +149,15 @@ pub struct PersistentNotification { pub unk5: String, } +#[derive(RmcSerialize)] +#[rmc_struct(0)] +pub struct PrincipalRequestBlockSetting { + #[extends] + pub data: Data, + pub pid: PID, + pub blocked: bool, +} + #[rmc_proto(102)] pub trait FriendsWiiU { #[method_id(1)] @@ -169,10 +180,53 @@ pub trait FriendsWiiU { ), ErrorCode, >; + #[method_id(2)] + async fn add_friend(&self, friend: PID) -> Result<(FriendRequest, FriendInfo), ErrorCode>; + #[method_id(3)] + async fn add_friend_by_name( + &self, + name: String, + ) -> Result<(FriendRequest, FriendInfo), ErrorCode>; + #[method_id(4)] + async fn remove_friend(&self, friend: PID) -> Result<(), ErrorCode>; + #[method_id(5)] + async fn add_friend_request( + &self, + friend: PID, + unk1: u8, + message: String, + unk2: u8, + unk3: String, + game_key: GameKey, + unk4: KerberosDateTime, + ) -> Result<(FriendRequest, FriendInfo), ErrorCode>; + #[method_id(6)] + async fn cancel_friend_request(&self, id: u64) -> Result<(), ErrorCode>; + #[method_id(7)] + async fn accept_friend_request(&self, id: u64) -> Result; + #[method_id(8)] + async fn delete_friend_request(&self, id: u64) -> Result<(), ErrorCode>; + #[method_id(9)] + async fn deny_friend_request(&self, id: u64) -> Result; + #[method_id(10)] + async fn mark_friend_requests_as_received(&self, ids: Vec) -> Result<(), ErrorCode>; + #[method_id(11)] + async fn add_blacklist( + &self, + principal: BlacklistedPrincipal, + ) -> Result; + #[method_id(12)] + async fn remove_blacklist(&self, id: PID) -> Result<(), ErrorCode>; #[method_id(13)] async fn update_presence(&self, presence: NintendoPresenceV2) -> Result<(), ErrorCode>; + #[method_id(14)] + async fn update_mii(&self, presence: MiiV2) -> Result; + #[method_id(15)] + async fn update_comment(&self, presence: Comment) -> Result; #[method_id(16)] async fn update_preference(&self, preference: PrincipalPreference) -> Result<(), ErrorCode>; + #[method_id(17)] + async fn get_basic_info(&self, pids: Vec) -> Result, ErrorCode>; #[method_id(18)] async fn delete_persistent_notification( &self, @@ -180,4 +234,9 @@ pub trait FriendsWiiU { ) -> Result<(), ErrorCode>; #[method_id(19)] async fn check_setting_status(&self) -> Result; + #[method_id(20)] + async fn get_request_block_settings( + &self, + unk: Vec, + ) -> Result, ErrorCode>; }