diff --git a/prudpv0/src/crypto/friends_insecure.rs b/prudpv0/src/crypto/friends_insecure.rs index ead738a..e914836 100644 --- a/prudpv0/src/crypto/friends_insecure.rs +++ b/prudpv0/src/crypto/friends_insecure.rs @@ -3,9 +3,12 @@ use std::io::Write; use hmac::Mac; use md5::{Digest, Md5}; use rc4::{KeyInit, Rc4, StreamCipher}; -use rnex_core::prudp::{ - encryption::{DEFAULT_KEY, EncryptionPair}, - types_flags::{TypesFlags, types::DATA}, +use rnex_core::{ + PID, + prudp::{ + encryption::{DEFAULT_KEY, EncryptionPair}, + types_flags::{TypesFlags, types::DATA}, + }, }; use typenum::U5; @@ -29,7 +32,7 @@ impl CryptoInstance for InsecureInstance { fn encrypt_outgoing(&mut self, data: &mut [u8]) { self.pair.send.apply_keystream(data); } - fn get_user_id(&self) -> u32 { + fn get_user_id(&self) -> PID { 0 } fn generate_signature(&self, types_flags: TypesFlags, data: &[u8]) -> [u8; 4] { diff --git a/prudpv0/src/crypto/friends_secure.rs b/prudpv0/src/crypto/friends_secure.rs index 14bdf7c..ca63ccf 100644 --- a/prudpv0/src/crypto/friends_secure.rs +++ b/prudpv0/src/crypto/friends_secure.rs @@ -2,6 +2,7 @@ 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::{ @@ -22,7 +23,7 @@ use crate::crypto::{ pub struct SecureInstance { pair: EncryptionPair>, - uid: u32, + uid: PID, self_signat: [u8; 4], #[allow(dead_code)] remote_signat: [u8; 4], @@ -35,7 +36,7 @@ impl CryptoInstance for SecureInstance { fn encrypt_outgoing(&mut self, data: &mut [u8]) { self.pair.send.apply_keystream(data); } - fn get_user_id(&self) -> u32 { + fn get_user_id(&self) -> PID { self.uid } fn generate_signature(&self, types_flags: TypesFlags, data: &[u8]) -> [u8; 4] { diff --git a/prudpv0/src/crypto/mod.rs b/prudpv0/src/crypto/mod.rs index f4806f6..829f7c5 100644 --- a/prudpv0/src/crypto/mod.rs +++ b/prudpv0/src/crypto/mod.rs @@ -1,5 +1,5 @@ use cfg_if::cfg_if; -use rnex_core::prudp::types_flags::TypesFlags; +use rnex_core::{PID, prudp::types_flags::TypesFlags}; mod common_crypto; @@ -7,7 +7,7 @@ pub trait CryptoInstance: Send + 'static { fn decrypt_incoming(&mut self, data: &mut [u8]); fn encrypt_outgoing(&mut self, data: &mut [u8]); fn generate_signature(&self, types_flags: TypesFlags, data: &[u8]) -> [u8; 4]; - fn get_user_id(&self) -> u32; + fn get_user_id(&self) -> PID; } pub trait Crypto: Send + Sync + 'static { diff --git a/prudpv1/src/prudp/secure.rs b/prudpv1/src/prudp/secure.rs index c7d312f..2618b74 100644 --- a/prudpv1/src/prudp/secure.rs +++ b/prudpv1/src/prudp/secure.rs @@ -3,6 +3,7 @@ use crate::prudp::socket::{CryptoHandler, CryptoHandlerConnectionInstance}; use hmac::digest::consts::U32; use rc4::cipher::StreamCipherCoreWrapper; use rc4::{KeyInit, Rc4, Rc4Core, StreamCipher}; +use rnex_core::PID; use rnex_core::nex::account::Account; use rnex_core::prudp::encryption::EncryptionPair; use rnex_core::prudp::ticket::read_secure_connection_data; @@ -49,7 +50,7 @@ pub struct SecureInstance { self_signature: [u8; 16], #[allow(dead_code)] remote_signature: [u8; 16], - pid: u32, + pid: PID, } impl CryptoHandler for Secure { @@ -108,7 +109,7 @@ impl CryptoHandlerConnectionInstance for SecureInstance { } } - fn get_user_id(&self) -> u32 { + fn get_user_id(&self) -> i32 { self.pid } diff --git a/prudpv1/src/prudp/socket.rs b/prudpv1/src/prudp/socket.rs index c6f5faa..19bf24d 100644 --- a/prudpv1/src/prudp/socket.rs +++ b/prudpv1/src/prudp/socket.rs @@ -6,6 +6,7 @@ use async_trait::async_trait; use log::error; use log::{info, warn}; use rc4::StreamCipher; +use rnex_core::PID; use rnex_core::prudp::socket_addr::PRUDPSockAddr; use rnex_core::prudp::types_flags::TypesFlags; use rnex_core::prudp::types_flags::flags::{ACK, HAS_SIZE, MULTI_ACK, NEED_ACK, RELIABLE}; @@ -31,7 +32,7 @@ use tokio::time::{Instant, sleep}; /// PRUDP Socket for accepting connections to then send and recieve data from those clients pub struct CommonConnection { - pub user_id: u32, + pub user_id: PID, pub socket_addr: PRUDPSockAddr, pub server_port: VirtualPort, session_id: u8, @@ -851,7 +852,7 @@ pub trait CryptoHandlerConnectionInstance: Send + Sync + 'static { fn decrypt_incoming(&mut self, substream: u8, data: &mut [u8]); fn encrypt_outgoing(&mut self, substream: u8, data: &mut [u8]); - fn get_user_id(&self) -> u32; + fn get_user_id(&self) -> i32; fn sign_connect(&self, packet: &mut PRUDPV1Packet); fn sign_packet(&self, packet: &mut PRUDPV1Packet); fn verify_packet(&self, packet: &PRUDPV1Packet) -> bool; diff --git a/prudpv1/src/prudp/unsecure.rs b/prudpv1/src/prudp/unsecure.rs index 79cc908..f9a566a 100644 --- a/prudpv1/src/prudp/unsecure.rs +++ b/prudpv1/src/prudp/unsecure.rs @@ -62,7 +62,7 @@ impl CryptoHandlerConnectionInstance for UnsecureInstance { } } - fn get_user_id(&self) -> u32 { + fn get_user_id(&self) -> i32 { 0 } diff --git a/rnex-core/src/grpc/account.rs b/rnex-core/src/grpc/account.rs index 9d2d4e8..70aca04 100644 --- a/rnex-core/src/grpc/account.rs +++ b/rnex-core/src/grpc/account.rs @@ -166,7 +166,7 @@ impl Client { .find(|v| v.0 == "pid") .ok_or(SomethingHappened)? .1 - .as_u32() + .as_i32() else { return Err(SomethingHappened); }; diff --git a/rnex-core/src/lib.rs b/rnex-core/src/lib.rs index 28bdd48..81e254c 100644 --- a/rnex-core/src/lib.rs +++ b/rnex-core/src/lib.rs @@ -5,9 +5,9 @@ //#![warn(missing_docs)] #[cfg(feature = "big_pid")] -pub type PID = u64; +pub type PID = i64; #[cfg(not(feature = "big_pid"))] -pub type PID = u32; +pub type PID = i32; extern crate self as rnex_core; diff --git a/rnex-core/src/nex/friends_handler.rs b/rnex-core/src/nex/friends_handler.rs index 2a44702..71963e3 100644 --- a/rnex-core/src/nex/friends_handler.rs +++ b/rnex-core/src/nex/friends_handler.rs @@ -32,6 +32,7 @@ use rnex_core::{ structures::{any::Any, qresult::QResult}, }, }; +use sqlx::query; use std::sync::atomic::Ordering::Relaxed; use tokio::spawn; use tokio::sync::RwLock; @@ -46,6 +47,8 @@ use rnex_core::rmc::structures::RmcSerialize; use rnex_core::rmc::structures::data::Data; +use crate::executables::common::get_db; + define_rmc_proto!( proto FriendsUser{ Secure, @@ -117,7 +120,8 @@ impl FriendsWiiU for FriendsUser { ), ErrorCode, > { - todo!() + // let query = query!("select ", self.pid).fetch_all(get_db()).await; + Err(ErrorCode::Core_NotImplemented) } async fn add_friend(&self, friend: PID) -> Result<(FriendRequest, FriendInfo), ErrorCode> { diff --git a/rnex-core/src/nex/matchmake.rs b/rnex-core/src/nex/matchmake.rs index 8dde574..1b12f04 100644 --- a/rnex-core/src/nex/matchmake.rs +++ b/rnex-core/src/nex/matchmake.rs @@ -26,7 +26,7 @@ pub struct MatchmakeManager { pub sessions: RwLock>>>, pub rv_cid_counter: AtomicU32, pub users: RwLock>>, - pub users_by_pid: RwLock>>, + pub users_by_pid: RwLock>>, } impl MatchmakeManager { diff --git a/rnex-core/src/nex/user.rs b/rnex-core/src/nex/user.rs index 8dc705f..b8297b8 100644 --- a/rnex-core/src/nex/user.rs +++ b/rnex-core/src/nex/user.rs @@ -455,7 +455,7 @@ impl MatchmakeExtension for User { .users_by_pid .read() .await - .get(&recpipent) + .get(&bytemuck::cast(recpipent)) .and_then(|v| v.upgrade()) else { return Err(ErrorCode::Core_InvalidArgument); @@ -467,8 +467,8 @@ impl MatchmakeExtension for User { .process_notification_event(NotificationEvent { pid_source: self.pid, notif_type: REQUEST_JOIN_GATHERING * 1000, - param_1, - param_2, + param_1: bytemuck::cast(param_1), + param_2: bytemuck::cast(param_2), #[cfg(feature = "third-notif-param")] param_3: 0, str_param, @@ -480,8 +480,8 @@ impl MatchmakeExtension for User { .process_notification_event(NotificationEvent { pid_source: self.pid, notif_type: END_GATHERING * 1000, - param_1, - param_2, + param_1: bytemuck::cast(param_1), + param_2: bytemuck::cast(param_2), #[cfg(feature = "third-notif-param")] param_3: 0, str_param, diff --git a/rnex-core/src/rmc/protocols/friends_wiiu.rs b/rnex-core/src/rmc/protocols/friends_wiiu.rs index 5437665..1764c93 100644 --- a/rnex-core/src/rmc/protocols/friends_wiiu.rs +++ b/rnex-core/src/rmc/protocols/friends_wiiu.rs @@ -23,7 +23,7 @@ pub struct MiiV2 { pub struct PrincipalBasicInfo { #[extends] pub data: Data, - pub pid: u32, + pub pid: PID, pub nnid: String, pub mii: MiiV2, pub unk: u8, diff --git a/rnex-core/src/rmc/protocols/ranking.rs b/rnex-core/src/rmc/protocols/ranking.rs index 68be98f..9a9ca09 100644 --- a/rnex-core/src/rmc/protocols/ranking.rs +++ b/rnex-core/src/rmc/protocols/ranking.rs @@ -1,10 +1,12 @@ use macros::{RmcSerialize, method_id, rmc_proto}; use rnex_core::kerberos::KerberosDateTime; -use rnex_core::rmc::structures::qbuffer::QBuffer; -use rnex_core::rmc::structures::resultsrange::ResultsRange; use rnex_core::rmc::response::ErrorCode; +use rnex_core::rmc::structures::qbuffer::QBuffer; use rnex_core::rmc::structures::ranking::UploadCompetitionData; +use rnex_core::rmc::structures::resultsrange::ResultsRange; + +use crate::PID; #[derive(RmcSerialize, Debug, Default, Clone)] #[rmc_struct(1)] @@ -28,7 +30,7 @@ pub struct CompetitionRankingScoreInfo { #[rmc_struct(0)] pub struct CompetitionRankingScoreData { pub unk: u32, - pub pid: u32, + pub pid: PID, pub score: u32, pub modified: KerberosDateTime, pub unk2: u8,