This commit is contained in:
Maple Nebel 2026-06-10 21:34:18 +02:00
commit 0f94a33564
13 changed files with 39 additions and 27 deletions

View file

@ -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] {

View file

@ -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<Rc4<U16>>,
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] {

View file

@ -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 {

View file

@ -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
}

View file

@ -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;

View file

@ -62,7 +62,7 @@ impl CryptoHandlerConnectionInstance for UnsecureInstance {
}
}
fn get_user_id(&self) -> u32 {
fn get_user_id(&self) -> i32 {
0
}

View file

@ -166,7 +166,7 @@ impl Client {
.find(|v| v.0 == "pid")
.ok_or(SomethingHappened)?
.1
.as_u32()
.as_i32()
else {
return Err(SomethingHappened);
};

View file

@ -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;

View file

@ -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> {

View file

@ -26,7 +26,7 @@ pub struct MatchmakeManager {
pub sessions: RwLock<HashMap<u32, Arc<Mutex<ExtendedMatchmakeSession>>>>,
pub rv_cid_counter: AtomicU32,
pub users: RwLock<HashMap<u32, Weak<User>>>,
pub users_by_pid: RwLock<HashMap<u32, Weak<User>>>,
pub users_by_pid: RwLock<HashMap<PID, Weak<User>>>,
}
impl MatchmakeManager {

View file

@ -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,

View file

@ -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,

View file

@ -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,