diff --git a/macros/src/protos.rs b/macros/src/protos.rs index 2e95e71..f7e7d0d 100644 --- a/macros/src/protos.rs +++ b/macros/src/protos.rs @@ -1,7 +1,7 @@ use proc_macro2::{Ident, Span, TokenStream}; use quote::{quote, ToTokens}; use syn::token::{Brace, Paren, Semi}; -use syn::{Attribute, LitInt, LitStr, ReturnType, Type}; +use syn::{LitInt, LitStr, ReturnType, Type}; pub struct ProtoMethodData { pub id: LitInt, diff --git a/proxy-common/src/lib.rs b/proxy-common/src/lib.rs index 5cc13b7..d5ef302 100644 --- a/proxy-common/src/lib.rs +++ b/proxy-common/src/lib.rs @@ -1,12 +1,12 @@ use log::{error, info}; use rnex_core::{ PID, - executables::common::{OWN_IP_PUBLIC, try_get_ip}, + executables::common::try_get_ip, prudp::{socket_addr::PRUDPSockAddr, virtual_port::VirtualPort}, reggie::{RemoteEdgeNodeHolder, UnitPacketWrite}, rmc::{ protocols::{ - OnlyRemote, RemoteDisconnectable, RmcCallable, RmcConnection, RmcPureRemoteObject, + RemoteDisconnectable, RmcCallable, RmcConnection, RmcPureRemoteObject, new_rmc_gateway_connection, }, structures::RmcSerialize, @@ -17,7 +17,7 @@ use rnex_core::{ use std::{ env::{self, VarError}, error, - net::{AddrParseError, IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4}, + net::{AddrParseError, Ipv4Addr, SocketAddr, SocketAddrV4}, ops::Deref, panic, str::FromStr, @@ -75,6 +75,7 @@ const VIRTUAL_PORT_INSECURE: LazyLock = const VIRTUAL_PORT_SECURE: LazyLock = LazyLock::new(|| VirtualPort::parse(env!("RNEX_VIRTUAL_PORT_SECURE")).unwrap()); impl ProxyStartupParam { + #[inline(always)] pub fn new(prox_ty: ProxyType) -> Result { let port = RNEX_DEFAULT_PORT + match prox_ty { @@ -82,7 +83,7 @@ impl ProxyStartupParam { ProxyType::Secure => 1, }; let self_private = try_get_env("SERVER_IP_PRIVATE") - .unwrap_or(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, RNEX_DEFAULT_PORT)); + .unwrap_or(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, port)); let self_public: SocketAddrV4 = match try_get_env("SERVER_IP_PUBLIC") { Ok(v) => v, Err(e) => try_get_ip() @@ -121,6 +122,7 @@ impl Option<(PID, Vec)> { + fn new_connection(&self, _data: &[u8]) -> Option<(PID, Vec)> { Some((100, vec![])) } fn new() -> Self { diff --git a/prudplite/src/main.rs b/prudplite/src/executable.rs similarity index 100% rename from prudplite/src/main.rs rename to prudplite/src/executable.rs diff --git a/prudplite/src/lib.rs b/prudplite/src/lib.rs index 05938d7..0df7b2e 100644 --- a/prudplite/src/lib.rs +++ b/prudplite/src/lib.rs @@ -17,7 +17,7 @@ use rnex_core::{ types_flags::{ TypesFlags, flags::{ACK, NEED_ACK, RELIABLE}, - types::{CONNECT, DATA, DISCONNECT, SYN}, + types::{CONNECT, DATA, DISCONNECT, PING, SYN}, }, virtual_port::VirtualPort, }, @@ -26,20 +26,20 @@ use rnex_core::{ use tokio::net::{TcpListener, TcpStream}; use tokio_tungstenite::{ WebSocketStream, - tungstenite::{ - Bytes, Message, client::IntoClientRequest, http::header::ACCESS_CONTROL_REQUEST_METHOD, - }, + tungstenite::{Bytes, Message}, }; struct ConnectionState { param: Arc, active: bool, websocket: WebSocketStream, + #[allow(dead_code)] pid: PID, backend_conn: SplittableBufferConnection, addr: PRUDPSockAddr, incoming_reliable: HashMap>, client_reliable_counter: u16, + #[allow(dead_code)] server_reliable_counter: u16, } @@ -71,10 +71,16 @@ impl ConnectionState { ); let data: Bytes = data.into(); if header.types_flags.get_types() == DISCONNECT { - self.websocket.send(Message::Binary(data.clone())).await; - self.websocket.send(Message::Binary(data.clone())).await; + self.websocket + .send(Message::Binary(data.clone())) + .await + .ok(); + self.websocket + .send(Message::Binary(data.clone())) + .await + .ok(); } - self.websocket.send(Message::Binary(data)).await; + self.websocket.send(Message::Binary(data)).await.ok(); } if (header.types_flags.get_flags() & ACK) != 0 { @@ -111,6 +117,7 @@ impl ConnectionState { } } } + #[allow(dead_code)] pub async fn process_reliable(&mut self) { while let Some(v) = self.incoming_reliable.remove(&self.client_reliable_counter) { self.handle_incoming_prudp(v, true).await; @@ -131,7 +138,7 @@ impl ConnectionState { } } } - v = self.backend_conn.recv() => { + _ = self.backend_conn.recv() => { } } @@ -197,7 +204,7 @@ pub async fn websocket_thread_unconnected( ], &[], ); - websocket.send(Message::Binary(data.into())).await; + websocket.send(Message::Binary(data.into())).await.ok(); } CONNECT => { let Some(supported) = packet.packet_specific_iter() else { @@ -242,7 +249,7 @@ pub async fn websocket_thread_unconnected( ], &data, ); - websocket.send(Message::Binary(data.into())).await; + websocket.send(Message::Binary(data.into())).await.ok(); let addr = PRUDPSockAddr::new( addr, diff --git a/prudplite/src/packet.rs b/prudplite/src/packet.rs index bd8d87c..e75750b 100644 --- a/prudplite/src/packet.rs +++ b/prudplite/src/packet.rs @@ -3,8 +3,7 @@ use std::{ io::{self, Cursor, Read, Write}, }; -use bytemuck::{Pod, Zeroable, bytes_of}; -use futures_util::Stream; +use bytemuck::{Pod, Zeroable, bytes_of_mut}; use rnex_core::prudp::types_flags::TypesFlags; use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions}; @@ -30,10 +29,10 @@ pub enum PacketSpecificData { impl PacketSpecificData { fn consume(reader: &mut impl Read) -> io::Result { - let mut option_id = 0; - reader.read_exact(&mut [option_id])?; - let mut size = 0; - reader.read_exact(&mut [size])?; + let mut option_id = 0u8; + reader.read_exact(bytes_of_mut(&mut option_id))?; + let mut size = 0u8; + reader.read_exact(bytes_of_mut(&mut size))?; match option_id { 0 => { @@ -156,7 +155,7 @@ impl> LitePacket { .get_mut(size_of::()..size_of::() + len as usize) } - pub fn packet_specific_iter(&self) -> Option { + pub fn packet_specific_iter<'a>(&'a self) -> Option> { self.packet_specific_raw() .map(Cursor::new) .map(PacketSpecificIter) diff --git a/prudpv0/src/crypto/friends_insecure.rs b/prudpv0/src/crypto/friends_insecure.rs index 1f05681..ead738a 100644 --- a/prudpv0/src/crypto/friends_insecure.rs +++ b/prudpv0/src/crypto/friends_insecure.rs @@ -1,4 +1,4 @@ -use std::{io::Write, rc::Rc}; +use std::io::Write; use hmac::Mac; use md5::{Digest, Md5}; @@ -18,6 +18,7 @@ use crate::crypto::{ pub struct InsecureInstance { pair: EncryptionPair>, self_signat: [u8; 4], + #[allow(dead_code)] remote_signat: [u8; 4], } @@ -62,7 +63,7 @@ impl Crypto for Insecure { fn instantiate( &self, - packet_data: &[u8], + _packet_data: &[u8], self_signat: [u8; 4], remote_signat: [u8; 4], ) -> Option<(Self::Instance, Vec)> { diff --git a/prudpv0/src/crypto/friends_secure.rs b/prudpv0/src/crypto/friends_secure.rs index acfa3bc..14bdf7c 100644 --- a/prudpv0/src/crypto/friends_secure.rs +++ b/prudpv0/src/crypto/friends_secure.rs @@ -24,6 +24,7 @@ pub struct SecureInstance { pair: EncryptionPair>, uid: u32, self_signat: [u8; 4], + #[allow(dead_code)] remote_signat: [u8; 4], } diff --git a/prudpv0/src/lib.rs b/prudpv0/src/lib.rs index 444899a..86afe42 100644 --- a/prudpv0/src/lib.rs +++ b/prudpv0/src/lib.rs @@ -1,26 +1,13 @@ -cfg_if::cfg_if! { +use cfg_if::cfg_if; +cfg_if! { if #[cfg(feature = "prudpv0")] { - use bytemuck::{Pod, Zeroable}; - use cfg_if::cfg_if; - use log::{error, info, warn}; - use proxy_common::{ProxyStartupParam, setup_edge_node_connection}; - use rnex_core::executables::common::{OWN_IP_PRIVATE, OWN_IP_PUBLIC, SERVER_PORT}; - use rnex_core::prudp::types_flags::TypesFlags; - use rnex_core::prudp::types_flags::types::SYN; - use rnex_core::prudp::virtual_port::VirtualPort; - use rnex_core::reggie::EdgeNodeHolderConnectOption::Register; - use rnex_core::reggie::RemoteEdgeNodeHolder; - use rnex_core::rmc::protocols::{OnlyRemote, new_rmc_gateway_connection}; - use rnex_core::rmc::structures::RmcSerialize; - use rnex_core::util::SplittableBufferConnection; + use log::info; + use proxy_common::ProxyStartupParam; use std::env; use std::net::SocketAddrV4; - use std::process::abort; use std::sync::{Arc, LazyLock}; - use tokio::net::UdpSocket; use crate::crypto::{Crypto, Insecure, Secure}; - use crate::packet::PRUDPV0Packet; use crate::server::Server; mod crypto; @@ -44,8 +31,6 @@ cfg_if::cfg_if! { //implementations, e.g. secure and insecure(this also includes special cases like friends) async fn start_proxy(param: ProxyStartupParam) { - info!("creating cryptography instance"); - let mut crypto = Arc::new(T::new()); info!("binding to socket"); let server: Arc> = Arc::new(Server::new(param).await); diff --git a/prudpv0/src/packet.rs b/prudpv0/src/packet.rs index 50bfe55..b78102f 100644 --- a/prudpv0/src/packet.rs +++ b/prudpv0/src/packet.rs @@ -1,11 +1,9 @@ -use std::mem::transmute; - use bytemuck::{Pod, Zeroable, try_from_bytes, try_from_bytes_mut}; -use log::{error, info, warn}; +use log::{info, warn}; use rnex_core::prudp::{ types_flags::{ - self, TypesFlags, - flags::{HAS_SIZE, NEED_ACK}, + TypesFlags, + flags::HAS_SIZE, types::{CONNECT, DATA, DISCONNECT, PING, SYN}, }, virtual_port::VirtualPort, @@ -165,6 +163,7 @@ impl> PRUDPV0Packet { const DEFAULT_SIGNAT: [u8; 4] = [0x12, 0x34, 0x56, 0x78]; #[inline(always)] +#[allow(dead_code)] const fn get_size_offset(tf: TypesFlags) -> usize { size_of::() + (if tf.get_types() & (SYN | CONNECT) != 0 { diff --git a/prudpv0/src/server.rs b/prudpv0/src/server.rs index 899bbd6..96b6416 100644 --- a/prudpv0/src/server.rs +++ b/prudpv0/src/server.rs @@ -1,32 +1,24 @@ use std::{ collections::HashMap, - hash::Hash, - net::{Ipv4Addr, SocketAddr, SocketAddrV4}, - sync::{ - Arc, LazyLock, Weak, - atomic::{AtomicBool, AtomicU32}, - }, + net::{SocketAddr, SocketAddrV4}, + sync::{Arc, Weak}, time::Duration, }; use log::{error, info, warn}; use proxy_common::{ProxyStartupParam, new_backend_connection}; use rnex_core::{ - executables::common::{OWN_IP_PRIVATE, SERVER_PORT}, prudp::{ socket_addr::PRUDPSockAddr, types_flags::{ - TypesFlags, - flags::{ACK, HAS_SIZE, NEED_ACK, RELIABLE}, + flags::{ACK, NEED_ACK, RELIABLE}, types::{CONNECT, DATA, DISCONNECT, PING, SYN}, }, - virtual_port::VirtualPort, }, - rnex_proxy_common::ConnectionInitData, util::{SendingBufferConnection, SplittableBufferConnection}, }; use tokio::{ - net::{TcpSocket, UdpSocket}, + net::UdpSocket, spawn, sync::{Mutex, RwLock}, time::{Instant, sleep}, @@ -35,8 +27,8 @@ use tokio::{ use crate::{ crypto::{Crypto, CryptoInstance}, packet::{ - PRUDPV0Header, PRUDPV0Packet, new_connect_packet, new_data_packet, new_disconnect_packet, - new_ping_packet, new_syn_packet, precalc_size, + PRUDPV0Packet, new_connect_packet, new_data_packet, new_disconnect_packet, new_ping_packet, + new_syn_packet, }, }; @@ -49,16 +41,14 @@ pub struct InternalConnection { packet_queue: HashMap>)>, } pub struct Connection { - alive: AtomicBool, session_id: u8, target: SendingBufferConnection, - self_signat: [u8; 4], - remote_signat: [u8; 4], addr: PRUDPSockAddr, inner: Mutex>, } impl InternalConnection { + #[allow(dead_code)] fn next_server_count(&mut self) -> u16 { let prev_val = self.server_packet_counter; let (val, _) = self.server_packet_counter.overflowing_add(1); @@ -148,7 +138,8 @@ impl Server { this.socket .send_to(&data, conn.addr.regular_socket_addr) - .await; + .await + .ok(); break; } @@ -192,7 +183,8 @@ impl Server { self.socket .send_to(&packet, conn.addr.regular_socket_addr) - .await; + .await + .ok(); } if (Instant::now() - inner.last_action).as_secs() > 15 { @@ -210,13 +202,16 @@ impl Server { self.socket .send_to(&packet, conn.addr.regular_socket_addr) - .await; + .await + .ok(); self.socket .send_to(&packet, conn.addr.regular_socket_addr) - .await; + .await + .ok(); self.socket .send_to(&packet, conn.addr.regular_socket_addr) - .await; + .await + .ok(); drop(inner); let mut conns = self.connections.write().await; @@ -236,7 +231,10 @@ impl Server { let signat = [signat[0], signat[1], signat[2], signat[3]]; let packet = new_syn_packet(ACK, header.destination, header.source, signat, &self.crypto); - self.socket.send_to(&packet, addr.regular_socket_addr).await; + self.socket + .send_to(&packet, addr.regular_socket_addr) + .await + .ok(); } async fn handle_connect(self: Arc, packet: PRUDPV0Packet>, addr: PRUDPSockAddr) { let Some(data) = packet.payload() else { @@ -275,11 +273,8 @@ impl Server { let conn = Arc::new(Connection { target: buf_conn.duplicate_sender(), - remote_signat, - self_signat, addr, session_id: header.session_id, - alive: AtomicBool::new(true), inner: Mutex::new(InternalConnection { last_action: Instant::now(), crypto_instance: ci, @@ -320,9 +315,12 @@ impl Server { ); info!("sending back connection accept"); - self.socket.send_to(&packet, addr.regular_socket_addr).await; + self.socket + .send_to(&packet, addr.regular_socket_addr) + .await + .ok(); } - async fn handle_data(self: Arc, mut packet: PRUDPV0Packet>, addr: PRUDPSockAddr) { + async fn handle_data(self: Arc, packet: PRUDPV0Packet>, addr: PRUDPSockAddr) { let Some(frag_id) = packet.fragment_id() else { warn!("invalid packet from: {:?}", addr); return; @@ -349,7 +347,10 @@ impl Server { &mut conn.crypto_instance, &self.crypto, ); - self.socket.send_to(&ack, addr.regular_socket_addr).await; + self.socket + .send_to(&ack, addr.regular_socket_addr) + .await + .ok(); conn.packet_queue.insert( packet.header().unwrap().sequence_id, (Instant::now(), packet), @@ -375,7 +376,7 @@ impl Server { drop(conn); } - async fn handle_ping(self: Arc, mut packet: PRUDPV0Packet>, addr: PRUDPSockAddr) { + async fn handle_ping(self: Arc, packet: PRUDPV0Packet>, addr: PRUDPSockAddr) { info!("got ping"); let header = packet.header().unwrap(); @@ -395,11 +396,14 @@ impl Server { ); drop(inner); - self.socket.send_to(&packet, addr.regular_socket_addr).await; + self.socket + .send_to(&packet, addr.regular_socket_addr) + .await + .ok(); } async fn handle_disconnect( self: Arc, - mut packet: PRUDPV0Packet>, + packet: PRUDPV0Packet>, addr: PRUDPSockAddr, ) { info!("got disconnect"); @@ -425,9 +429,18 @@ impl Server { conns.remove(&(addr, header.session_id)); drop(conns); - self.socket.send_to(&packet, addr.regular_socket_addr).await; - self.socket.send_to(&packet, addr.regular_socket_addr).await; - self.socket.send_to(&packet, addr.regular_socket_addr).await; + self.socket + .send_to(&packet, addr.regular_socket_addr) + .await + .ok(); + self.socket + .send_to(&packet, addr.regular_socket_addr) + .await + .ok(); + self.socket + .send_to(&packet, addr.regular_socket_addr) + .await + .ok(); } async fn get_connection( &self, diff --git a/rnex-core/src/executables/backend_server_secure.rs b/rnex-core/src/executables/backend_server_secure.rs index 91b83b3..5ec36f1 100644 --- a/rnex-core/src/executables/backend_server_secure.rs +++ b/rnex-core/src/executables/backend_server_secure.rs @@ -1,13 +1,6 @@ use cfg_if::cfg_if; use rnex_core::common::setup; -use rnex_core::executables::common::new_simple_backend; use rnex_core::executables::friends_backend::start_friends_backend; -use rnex_core::nex::matchmake::MatchmakeManager; -use rnex_core::nex::remote_console::RemoteConsole; -use rnex_core::nex::user::User; -use rnex_core::rmc::protocols::{RemoteDisconnectable, RmcPureRemoteObject}; -use std::sync::Arc; -use std::sync::atomic::AtomicU32; #[tokio::main] async fn main() { diff --git a/rnex-core/src/executables/friends_backend.rs b/rnex-core/src/executables/friends_backend.rs index 5dfcf02..d2ce497 100644 --- a/rnex-core/src/executables/friends_backend.rs +++ b/rnex-core/src/executables/friends_backend.rs @@ -8,15 +8,11 @@ use log::error; use tokio::net::TcpListener; use crate::{ - executables::common::{OWN_IP_PRIVATE, SERVER_PORT, new_simple_backend}, - nex::friends_handler::{ - FriendsGuest, FriendsManager, FriendsUser, RemoteFriendRemote, RemoteFriendsUser, - }, + executables::common::{OWN_IP_PRIVATE, SERVER_PORT}, + nex::friends_handler::{FriendsGuest, FriendsManager, FriendsUser, RemoteFriendRemote}, reggie::UnitPacketRead, rmc::{ - protocols::{ - RmcCallable, RmcPureRemoteObject, friends::RemoteFriends, new_rmc_gateway_connection, - }, + protocols::{RmcPureRemoteObject, new_rmc_gateway_connection}, structures::RmcSerialize, }, rnex_proxy_common::ConnectionInitData, @@ -65,8 +61,8 @@ pub async fn start_friends_backend() { }) }); } else { - new_rmc_gateway_connection(stream.into(), move |r| { - Arc::new_cyclic(move |this| FriendsGuest { + new_rmc_gateway_connection(stream.into(), move |_| { + Arc::new_cyclic(move |_| FriendsGuest { fm, addr: c.prudpsock_addr, }) diff --git a/rnex-core/src/executables/mod.rs b/rnex-core/src/executables/mod.rs index cc9b83d..83a9df5 100644 --- a/rnex-core/src/executables/mod.rs +++ b/rnex-core/src/executables/mod.rs @@ -1,3 +1,10 @@ +use cfg_if::cfg_if; + pub mod common; -pub mod friends_backend; -pub mod regular_backend; +cfg_if! { + if #[cfg(feature = "friends")]{ + pub mod friends_backend; + } else { + pub mod regular_backend; + } +} diff --git a/rnex-core/src/kerberos/mod.rs b/rnex-core/src/kerberos/mod.rs index 205c62a..f67af94 100644 --- a/rnex-core/src/kerberos/mod.rs +++ b/rnex-core/src/kerberos/mod.rs @@ -18,13 +18,13 @@ use rnex_core::PID; cfg_if! { if #[cfg(feature = "friends")]{ - pub type SESSION_KEY_LENGTH_TY = U16; + pub type SessionLengthTy = U16; } else { use rc4::consts::U32; - pub type SESSION_KEY_LENGTH_TY = U32; + pub type SessionLengthTy = U32; } } -pub const SESSION_KEY_LENGTH: usize = SESSION_KEY_LENGTH_TY::USIZE; +pub const SESSION_KEY_LENGTH: usize = SessionLengthTy::USIZE; type Md5Hmac = Hmac; diff --git a/rnex-core/src/nex/auth_handler.rs b/rnex-core/src/nex/auth_handler.rs index 341dc93..97b1008 100644 --- a/rnex-core/src/nex/auth_handler.rs +++ b/rnex-core/src/nex/auth_handler.rs @@ -337,82 +337,3 @@ impl Auth for AuthHandler { Err(ErrorCode::Core_Exception) } } - -mod test { - use std::io::Cursor; - - use rc4::{KeyInit, Rc4, StreamCipher}; - use rnex_core::PID; - use rnex_core::kerberos::KerberosDateTime; - use rnex_core::rmc::structures::connection_data::ConnectionData; - use rnex_core::rmc::{ - response::ErrorCode, - structures::{RmcSerialize, qresult::QResult}, - }; - - use crate::kerberos::{self, derive_key}; - use crate::rmc; - use crate::rmc::message::RMCMessage; - use crate::rmc::response::{RMCResponse, RMCResponseResult}; - - #[test] - fn test() { - return; - let packet = [ - 26, 1, 0, 0, 10, 1, 30, 0, 0, 0, 1, 128, 0, 0, 1, 0, 1, 0, 86, 4, 0, 0, 116, 0, 0, 0, - 144, 209, 130, 175, 45, 215, 95, 55, 226, 192, 51, 54, 201, 84, 118, 150, 159, 164, 32, - 103, 134, 252, 199, 168, 178, 5, 6, 208, 206, 241, 94, 23, 136, 37, 109, 247, 156, 252, - 189, 233, 142, 115, 206, 72, 180, 57, 106, 223, 37, 59, 144, 208, 250, 197, 51, 202, - 185, 156, 51, 159, 219, 117, 250, 103, 184, 1, 103, 108, 15, 14, 174, 160, 192, 146, - 135, 10, 55, 125, 68, 181, 88, 127, 183, 34, 4, 213, 19, 146, 81, 56, 248, 213, 241, - 168, 205, 253, 29, 10, 123, 198, 177, 157, 247, 209, 113, 167, 231, 42, 214, 15, 12, - 200, 192, 230, 125, 227, 74, 0, 112, 114, 117, 100, 112, 115, 58, 47, 80, 73, 68, 61, - 50, 59, 115, 105, 100, 61, 49, 59, 115, 116, 114, 101, 97, 109, 61, 49, 48, 59, 116, - 121, 112, 101, 61, 50, 59, 97, 100, 100, 114, 101, 115, 115, 61, 57, 49, 46, 57, 56, - 46, 49, 50, 56, 46, 56, 54, 59, 112, 111, 114, 116, 61, 54, 48, 48, 49, 59, 67, 73, 68, - 61, 49, 0, 0, 0, 0, 0, 1, 0, 0, 162, 243, 240, 168, 31, 0, 0, 0, 51, 0, 98, 114, 97, - 110, 99, 104, 58, 111, 114, 105, 103, 105, 110, 47, 112, 114, 111, 106, 101, 99, 116, - 47, 119, 117, 112, 45, 97, 103, 109, 106, 32, 98, 117, 105, 108, 100, 58, 51, 95, 56, - 95, 49, 53, 95, 50, 48, 48, 52, 95, 48, 0, - ]; - let rmc_packet = RMCResponse::new(&mut Cursor::new(&packet)).unwrap(); - println!("{:?}", rmc_packet); - - let RMCResponseResult::Success { - call_id, - method_id, - data, - } = rmc_packet.response_result - else { - panic!(); - }; - - println!("{}", hex::encode(&data)); - - let mut data = - <(QResult, PID, Vec, ConnectionData, String) as RmcSerialize>::deserialize( - &mut Cursor::new(&data[..]), - ) - .unwrap(); - - println!("{:?}", data); - - let key = derive_key(1110, "AAAAAAAAAAAAAAAA".as_bytes()); - - let mut rc4 = Rc4::new((&key).into()); - - rc4.apply_keystream(&mut data.2); - println!("raw tick: {:?}", data.2); - - let tick: &kerberos::Ticket = - bytemuck::from_bytes(&data.2[..size_of::()]); - - let remainder = &data.2[size_of::()..]; - - println!("tick: {:?}", tick); - let data = as RmcSerialize>::deserialize(&mut Cursor::new(remainder)).unwrap(); - println!("inner ticket raw: {:?}", data); - - println!("{:?}", data); - } -} diff --git a/rnex-core/src/nex/friends_handler.rs b/rnex-core/src/nex/friends_handler.rs index 71cd652..27f31d9 100644 --- a/rnex-core/src/nex/friends_handler.rs +++ b/rnex-core/src/nex/friends_handler.rs @@ -312,7 +312,7 @@ impl Friends for FriendsUser { async fn delete_persistent_notification( &self, - notifs: Vec, + _notifs: Vec, ) -> Result<(), ErrorCode> { Ok(()) } diff --git a/rnex-core/src/nex/mod.rs b/rnex-core/src/nex/mod.rs index 0f52c13..79c2085 100644 --- a/rnex-core/src/nex/mod.rs +++ b/rnex-core/src/nex/mod.rs @@ -1,7 +1,15 @@ +use cfg_if::cfg_if; + pub mod account; pub mod auth_handler; pub mod common; -pub mod friends_handler; -pub mod matchmake; -pub mod remote_console; -pub mod user; + +cfg_if! { + if #[cfg(feature = "friends")]{ + pub mod friends_handler; + } else { + pub mod matchmake; + pub mod remote_console; + pub mod user; + } +} diff --git a/rnex-core/src/prudp/ticket.rs b/rnex-core/src/prudp/ticket.rs index 98e181f..97dc5d5 100644 --- a/rnex-core/src/prudp/ticket.rs +++ b/rnex-core/src/prudp/ticket.rs @@ -6,7 +6,7 @@ use typenum::U16; use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions}; use crate::{ - kerberos::{SESSION_KEY_LENGTH, SESSION_KEY_LENGTH_TY, TicketInternalData, derive_key}, + kerberos::{SESSION_KEY_LENGTH, SessionLengthTy, TicketInternalData, derive_key}, nex::account::Account, rmc::structures::RmcSerialize, }; @@ -53,7 +53,7 @@ pub fn read_secure_connection_data( let request_data_length = request_data.len(); let request_data = &mut request_data[0..request_data_length - 0x10]; - let mut rc4: StreamCipherCoreWrapper> = + let mut rc4: StreamCipherCoreWrapper> = Rc4::new_from_slice(&session_key).expect("unable to init rc4 keystream"); rc4.apply_keystream(request_data); diff --git a/rnex-core/src/prudp/virtual_port.rs b/rnex-core/src/prudp/virtual_port.rs index 625709b..b23b5d0 100644 --- a/rnex-core/src/prudp/virtual_port.rs +++ b/rnex-core/src/prudp/virtual_port.rs @@ -1,8 +1,5 @@ use bytemuck::{Pod, Zeroable}; -use std::{ - fmt::{Debug, Formatter}, - slice, -}; +use std::fmt::{Debug, Formatter}; use v_byte_helpers::SwapEndian; #[repr(transparent)] diff --git a/rnex-core/src/rmc/protocols/auth.rs b/rnex-core/src/rmc/protocols/auth.rs index ca387f9..a065418 100644 --- a/rnex-core/src/rmc/protocols/auth.rs +++ b/rnex-core/src/rmc/protocols/auth.rs @@ -8,11 +8,11 @@ use rnex_core::rmc::structures::qresult::QResult; cfg_if! { if #[cfg(feature = "nx")]{ - type LOGIN_EX_RET = (QResult, PID, Vec, ConnectionData, String, String); - type REQUEST_TICKET_RET = (QResult, Vec, String); + type LoginExRet = (QResult, PID, Vec, ConnectionData, String, String); + type RequestTicketRet = (QResult, Vec, String); } else { - type LOGIN_EX_RET = (QResult, PID, Vec, ConnectionData, String); - type REQUEST_TICKET_RET = (QResult, Vec); + type LoginExRet = (QResult, PID, Vec, ConnectionData, String); + type RequestTicketRet = (QResult, Vec); } } @@ -31,14 +31,14 @@ pub trait Auth { /// representation of the `LoginEx` method(for details see the /// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol)) #[method_id(2)] - async fn login_ex(&self, name: String, extra_data: Any) -> Result; + async fn login_ex(&self, name: String, extra_data: Any) -> Result; #[method_id(3)] async fn request_ticket( &self, source_pid: PID, destination_pid: PID, - ) -> Result; + ) -> Result; /// representation of the `RequestTicket` method(for details see the /// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol)) diff --git a/rnex-core/src/rmc/protocols/friends.rs b/rnex-core/src/rmc/protocols/friends.rs index 81dd63e..98fa501 100644 --- a/rnex-core/src/rmc/protocols/friends.rs +++ b/rnex-core/src/rmc/protocols/friends.rs @@ -2,7 +2,7 @@ use macros::{RmcSerialize, method_id, rmc_proto}; use rnex_core::{kerberos::KerberosDateTime, rmc::response::ErrorCode}; -use rnex_core::rmc::structures::{data::Data, rmc_struct}; +use rnex_core::rmc::structures::data::Data; #[derive(RmcSerialize, Debug, Clone)] #[rmc_struct(0)] diff --git a/rnex-core/src/rmc/protocols/notifications.rs b/rnex-core/src/rmc/protocols/notifications.rs index eef5c6c..afbebd8 100644 --- a/rnex-core/src/rmc/protocols/notifications.rs +++ b/rnex-core/src/rmc/protocols/notifications.rs @@ -1,4 +1,4 @@ -use macros::{RmcSerialize, method_id, rmc_proto, rmc_struct}; +use macros::{RmcSerialize, method_id, rmc_proto}; use rnex_core::PID; diff --git a/rnex-core/src/rmc/protocols/ranking.rs b/rnex-core/src/rmc/protocols/ranking.rs index b9dba06..eff1ae4 100644 --- a/rnex-core/src/rmc/protocols/ranking.rs +++ b/rnex-core/src/rmc/protocols/ranking.rs @@ -1,4 +1,4 @@ -use macros::{rmc_struct, rmc_proto, RmcSerialize, method_id}; +use macros::{RmcSerialize, method_id, rmc_proto}; use rnex_core::kerberos::KerberosDateTime; use rnex_core::rmc::structures::qbuffer::QBuffer; @@ -8,9 +8,9 @@ use rnex_core::rmc::structures::ranking::UploadCompetitionData; #[derive(RmcSerialize, Debug, Default, Clone)] #[rmc_struct(0)] -pub struct ResultsRange{ +pub struct ResultsRange { pub offset: u32, - pub size: u32 + pub size: u32, } #[derive(RmcSerialize, Debug, Default, Clone)] @@ -23,29 +23,35 @@ pub struct CompetitionRankingGetParam { #[derive(RmcSerialize, Debug, Default, Clone)] #[rmc_struct(0)] -pub struct CompetitionRankingScoreInfo{ +pub struct CompetitionRankingScoreInfo { pub fest_id: u32, pub score_data: Vec, pub unk: u32, pub team_wins: Vec, - pub team_votes: Vec + pub team_votes: Vec, } #[derive(RmcSerialize, Debug, Clone)] #[rmc_struct(0)] -pub struct CompetitionRankingScoreData{ +pub struct CompetitionRankingScoreData { pub unk: u32, pub pid: u32, pub score: u32, pub modified: KerberosDateTime, pub unk2: u8, - pub appdata: QBuffer + pub appdata: QBuffer, } #[rmc_proto(112)] -pub trait Ranking{ +pub trait Ranking { #[method_id(16)] - async fn competition_ranking_get_param(&self, param: CompetitionRankingGetParam) -> Result,ErrorCode>; + async fn competition_ranking_get_param( + &self, + param: CompetitionRankingGetParam, + ) -> Result, ErrorCode>; #[method_id(18)] - async fn upload_competition_ranking_score(&self, param: UploadCompetitionData) -> Result; + async fn upload_competition_ranking_score( + &self, + param: UploadCompetitionData, + ) -> Result; }