diff --git a/src/bin/kawari-admin.rs b/src/bin/kawari-admin.rs index 3c03ecf..cb54233 100644 --- a/src/bin/kawari-admin.rs +++ b/src/bin/kawari-admin.rs @@ -2,10 +2,10 @@ use std::net::SocketAddr; use axum::response::{Html, Redirect}; use axum::routing::post; -use axum::{Json, Router, extract::Form, routing::get}; -use kawari::config::{Config, get_config}; +use axum::{Router, extract::Form, routing::get}; +use kawari::config::get_config; use kawari::setup_default_environment; -use minijinja::{Environment, context}; +use minijinja::context; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/bin/kawari-frontier.rs b/src/bin/kawari-frontier.rs index a2a343c..ad1778d 100644 --- a/src/bin/kawari-frontier.rs +++ b/src/bin/kawari-frontier.rs @@ -1,7 +1,7 @@ use std::net::SocketAddr; use axum::{Json, Router, routing::get}; -use kawari::config::{Config, get_config}; +use kawari::config::get_config; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/bin/kawari-login.rs b/src/bin/kawari-login.rs index c92dc99..f987d31 100644 --- a/src/bin/kawari-login.rs +++ b/src/bin/kawari-login.rs @@ -5,8 +5,6 @@ use axum::response::Html; use axum::routing::post; use axum::{Form, Router, routing::get}; use kawari::generate_sid; -use rand::Rng; -use rand::distributions::Alphanumeric; use serde::Deserialize; #[derive(Deserialize)] diff --git a/src/bin/kawari-patch.rs b/src/bin/kawari-patch.rs index 9412660..ad0c92a 100644 --- a/src/bin/kawari-patch.rs +++ b/src/bin/kawari-patch.rs @@ -3,16 +3,12 @@ use std::fs::read_dir; use std::net::SocketAddr; use axum::extract::Path; -use axum::extract::Query; use axum::http::{HeaderMap, StatusCode}; -use axum::response::Html; use axum::response::IntoResponse; use axum::routing::post; -use axum::{Form, Json, Router, routing::get}; -use kawari::config::{Config, get_config}; +use axum::{Router, routing::get}; +use kawari::config::get_config; use kawari::patchlist::{PatchEntry, PatchList, PatchType}; -use minijinja::filters::list; -use serde::{Deserialize, Serialize}; fn list_patch_files(dir_path: &str) -> Vec { // If the dir doesn't exist, pretend there is no patch files @@ -38,7 +34,7 @@ fn list_patch_files(dir_path: &str) -> Vec { .collect(); game_patches.sort_by(|a, b| { // Ignore H/D in front of filenames - let mut a_path = a + let a_path = a .as_path() .file_name() .unwrap() @@ -48,7 +44,7 @@ fn list_patch_files(dir_path: &str) -> Vec { if a_path.starts_with("H") { return Ordering::Less; } - let mut b_path = b + let b_path = b .as_path() .file_name() .unwrap() @@ -117,7 +113,7 @@ async fn verify_boot(Path((platform, boot_version)): Path<(String, String)>) -> } } - let mut headers = HeaderMap::new(); + let headers = HeaderMap::new(); (headers).into_response() } diff --git a/src/bin/kawari-web.rs b/src/bin/kawari-web.rs index 4b06c19..a1a5993 100644 --- a/src/bin/kawari-web.rs +++ b/src/bin/kawari-web.rs @@ -2,10 +2,10 @@ use std::net::SocketAddr; use axum::response::{Html, Redirect}; use axum::routing::post; -use axum::{Json, Router, extract::Form, routing::get}; -use kawari::config::{Config, get_config}; +use axum::{Router, extract::Form, routing::get}; +use kawari::config::get_config; use kawari::setup_default_environment; -use minijinja::{Environment, context}; +use minijinja::context; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -58,7 +58,7 @@ struct Input { async fn apply(Form(input): Form) -> Redirect { tracing::info!("Apply config changes..."); - let mut config = get_config(); + let config = get_config(); serde_json::to_writer(&std::fs::File::create("config.json").unwrap(), &config) .expect("TODO: panic message"); diff --git a/src/encryption.rs b/src/encryption.rs index 0425733..943aa22 100644 --- a/src/encryption.rs +++ b/src/encryption.rs @@ -1,4 +1,3 @@ -use std::fs::write; use std::{io::Cursor, slice}; use binrw::{BinRead, BinResult, BinWrite}; @@ -9,30 +8,14 @@ const GAME_VERSION: u16 = 7000; pub fn generate_encryption_key(key: &[u8], phrase: &str) -> [u8; 16] { let mut base_key = vec![0x78, 0x56, 0x34, 0x12]; - base_key.extend_from_slice(&key); + base_key.extend_from_slice(key); base_key.extend_from_slice(&GAME_VERSION.to_le_bytes()); base_key.extend_from_slice(&[0; 2]); // padding (possibly for game version?) - base_key.extend_from_slice(&phrase.as_bytes()); + base_key.extend_from_slice(phrase.as_bytes()); md5::compute(&base_key).0 } -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_encryption_key() { - let key = generate_encryption_key(&[0x00, 0x00, 0x00, 0x00], "foobar"); - assert_eq!( - key, - [ - 169, 78, 235, 31, 57, 151, 26, 74, 250, 196, 1, 120, 206, 173, 202, 48 - ] - ); - } -} - #[binrw::parser(reader, endian)] pub(crate) fn decrypt(size: u32, encryption_key: Option<&[u8]>) -> BinResult where @@ -87,3 +70,19 @@ where Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_encryption_key() { + let key = generate_encryption_key(&[0x00, 0x00, 0x00, 0x00], "foobar"); + assert_eq!( + key, + [ + 169, 78, 235, 31, 57, 151, 26, 74, 250, 196, 1, 120, 206, 173, 202, 48 + ] + ); + } +} diff --git a/src/packet.rs b/src/packet.rs index b289957..b76f0fb 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -5,7 +5,7 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; -use binrw::{BinRead, BinResult, BinWrite, binrw, helpers::until_eof}; +use binrw::{BinRead, BinWrite, binrw}; use tokio::{ io::{AsyncWriteExt, WriteHalf}, net::TcpStream, @@ -122,11 +122,11 @@ struct IPCSegment { impl IPCSegment { fn calc_size(&self) -> u32 { let header = 16; - return header + header + match self.data { IPCOpCode::ClientVersionInfo { .. } => todo!(), IPCOpCode::LobbyServiceAccountList { .. } => 19, - }; + } } } @@ -197,14 +197,14 @@ struct PacketSegment { impl PacketSegment { fn calc_size(&self) -> u32 { let header = std::mem::size_of::() * 4; - return header as u32 + header as u32 + match &self.segment_type { SegmentType::InitializeEncryption { .. } => 616, SegmentType::InitializationEncryptionResponse { .. } => 640, SegmentType::IPC { data } => data.calc_size(), SegmentType::KeepAlive { .. } => todo!(), SegmentType::KeepAliveResponse { .. } => 0x8, - }; + } } } diff --git a/src/patchlist.rs b/src/patchlist.rs index 22a43aa..119aadd 100644 --- a/src/patchlist.rs +++ b/src/patchlist.rs @@ -55,42 +55,42 @@ impl PatchList { for patch in &self.patches { // length str.push_str(&patch.length.to_string()); - str.push_str("\t"); + str.push('\t'); // TODO: unknown value, but i *suspect* is the size of the game on disk once this patch is applied. // which would make sense for the launcher to check for str.push_str(&patch.size_on_disk.to_string()); - str.push_str("\t"); + str.push('\t'); // TODO: totally unknown str.push_str(&patch.unknown_a.to_string()); - str.push_str("\t"); + str.push('\t'); // TODO: unknown too str.push_str(&patch.unknown_b.to_string()); - str.push_str("\t"); + str.push('\t'); // version (e.g. 2023.09.15.0000.0000) str.push_str(&patch.version); - str.push_str("\t"); + str.push('\t'); - if (self.patch_type == PatchType::Game) { + if self.patch_type == PatchType::Game { // hash type // TODO: does this need to be configurable? str.push_str("sha1"); - str.push_str("\t"); + str.push('\t'); // hash block size str.push_str(&patch.hash_block_size.to_string()); - str.push_str("\t"); + str.push('\t'); // hashes str.push_str(&patch.hashes[0]); for hash in &patch.hashes[1..] { - str.push_str(","); - str.push_str(&hash); + str.push(','); + str.push_str(hash); } - str.push_str("\t"); + str.push('\t'); } // url @@ -108,7 +108,6 @@ impl PatchList { #[cfg(test)] mod tests { - use std::fs; use super::*;