diff --git a/src/entity/item/unit.rs b/src/entity/item/unit.rs index 061551a..fcf4f0b 100644 --- a/src/entity/item/unit.rs +++ b/src/entity/item/unit.rs @@ -368,14 +368,13 @@ impl Unit { pub fn from_bytes(data: [u8; 16]) -> Result { let u = UnitType::parse_type([data[0], data[1], data[2]]); if u.is_ok() { - let mut m = None; - match u16::from_le_bytes([data[7], data[8]]) { - 0x03 => m = Some(UnitModifier::PlusPlus), - 0x01 => m = Some(UnitModifier::Plus), - 0xFEFF => m = Some(UnitModifier::Minus), - 0xFFFF => m = Some(UnitModifier::MinusMinus), - _ => m = None, - } + let m = match u16::from_le_bytes([data[7], data[8]]) { + 0x03 => Some(UnitModifier::PlusPlus), + 0x01 => Some(UnitModifier::Plus), + 0xFEFF => Some(UnitModifier::Minus), + 0xFFFF => Some(UnitModifier::MinusMinus), + _ => None, + }; Ok(Unit{ unit: u.unwrap(), diff --git a/src/ship/packet/handler/quest.rs b/src/ship/packet/handler/quest.rs index bf1b49f..320a8bc 100644 --- a/src/ship/packet/handler/quest.rs +++ b/src/ship/packet/handler/quest.rs @@ -1,5 +1,3 @@ -use std::collections::HashMap; -use std::convert::TryInto; use std::io::{Cursor, Read, Seek, SeekFrom}; use libpso::packet::ship::*; use crate::common::serverstate::ClientId; @@ -7,7 +5,6 @@ use crate::ship::ship::{SendShipPacket, ShipError, Clients, Rooms}; use crate::ship::quests::QuestList; use crate::ship::location::{ClientLocation, ClientLocationError}; use crate::ship::packet::builder::quest; -use libpso::utf8_to_array; use libpso::util::array_to_utf8; // TOOD: enum @@ -143,7 +140,7 @@ pub fn quest_chunk_ack(id: ClientId, quest_chunk_ack: &QuestChunkAck, quests: &Q }; let mut blob_cursor = Cursor::new(blob); - blob_cursor.seek(SeekFrom::Start((quest_chunk_ack.chunk_num as u64 + 1) * 0x400)); + blob_cursor.seek(SeekFrom::Start((quest_chunk_ack.chunk_num as u64 + 1) * 0x400))?; let mut subblob = [0u8; 0x400]; let blob_length = blob_cursor.read(&mut subblob)?; if blob_length == 0 { @@ -154,7 +151,7 @@ pub fn quest_chunk_ack(id: ClientId, quest_chunk_ack: &QuestChunkAck, quests: &Q Ok(Box::new(vec![(id, SendShipPacket::QuestChunk(qc))].into_iter())) } -pub fn done_loading_quest(id: ClientId, quests: &QuestList, clients: &mut Clients, client_location: &ClientLocation) +pub fn done_loading_quest(id: ClientId, clients: &mut Clients, client_location: &ClientLocation) -> Result + Send>, ShipError> { let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?; client.done_loading_quest = true; diff --git a/src/ship/quests.rs b/src/ship/quests.rs index 02c0a8a..f7dfd6e 100644 --- a/src/ship/quests.rs +++ b/src/ship/quests.rs @@ -3,12 +3,11 @@ use std::collections::{HashMap, BTreeMap, BTreeSet}; use std::fs::File; use std::io::{Read, Write, Cursor, Seek, SeekFrom}; use std::path::PathBuf; -use std::convert::{TryInto, TryFrom}; +use std::convert::TryInto; use thiserror::Error; use serde::{Serialize, Deserialize}; use ages_prs::{LegacyPrsDecoder, LegacyPrsEncoder}; use byteorder::{LittleEndian, ReadBytesExt}; -use libpso::packet::ship::QuestChunk; use libpso::util::array_to_utf16; use crate::ship::map::{MapArea, MapAreaError, MapObject, MapEnemy, enemy_data_from_stream, objects_from_stream}; use crate::ship::room::Episode; @@ -42,7 +41,7 @@ struct QuestListConfig { #[derive(Error, Debug)] #[error("")] -enum ParseDatError { +pub enum ParseDatError { IoError(#[from] std::io::Error), MapError(#[from] MapAreaError), UnknownDatHeader(u32), @@ -62,7 +61,7 @@ enum DatBlock { fn read_dat_section_header(cursor: &mut T, episode: &Episode) -> Result { let header = cursor.read_u32::()?; - let offset = cursor.read_u32::()?; + let _offset = cursor.read_u32::()?; let area = cursor.read_u32::()?; let length = cursor.read_u32::()?; @@ -71,7 +70,7 @@ fn read_dat_section_header(cursor: &mut T, episode: &Episode) -> match header { DAT_OBJECT_HEADER_ID => { let mut obj_data = vec![0u8; length as usize]; - cursor.read(&mut obj_data); + cursor.read(&mut obj_data)?; let mut obj_cursor = Cursor::new(obj_data); let objects = objects_from_stream(&mut obj_cursor, episode, &map_area); @@ -79,7 +78,7 @@ fn read_dat_section_header(cursor: &mut T, episode: &Episode) -> }, DAT_ENEMY_HEADER_ID => { let mut enemy_data = vec![0u8; length as usize]; - cursor.read(&mut enemy_data); + cursor.read(&mut enemy_data)?; let mut enemy_cursor = Cursor::new(enemy_data); let enemies = enemy_data_from_stream(&mut enemy_cursor, &map_area, episode); @@ -87,7 +86,7 @@ fn read_dat_section_header(cursor: &mut T, episode: &Episode) -> Ok(DatBlock::Enemy(enemies)) }, DAT_WAVE_HEADER_ID => { - cursor.seek(SeekFrom::Current(length as i64)); + cursor.seek(SeekFrom::Current(length as i64))?; Ok(DatBlock::Wave) }, _ => Err(ParseDatError::UnknownDatHeader(header)) @@ -134,11 +133,10 @@ fn parse_dat(dat: &[u8], episode: &Episode) -> Result<(Vec>, Ve #[derive(Error, Debug)] #[error("")] pub enum QuestLoadError { + IoError(#[from] std::io::Error), ParseDatError(#[from] ParseDatError), CouldNotReadMetadata, CouldNotLoadConfigFile, - QuestFileNotFound(String), - CouldNotLoadFile(String), } #[derive(Debug)] @@ -166,9 +164,9 @@ impl Quest { let (enemies, objects) = parse_dat(&dat, &episode)?; let mut prs_bin = LegacyPrsEncoder::new(Vec::new()); - prs_bin.write(&bin); + prs_bin.write(&bin)?; let mut prs_dat = LegacyPrsEncoder::new(Vec::new()); - prs_dat.write(&dat); + prs_dat.write(&dat)?; Ok(Quest { name: name, @@ -190,7 +188,7 @@ pub type QuestList = BTreeMap>; pub fn load_quests(quest_path: PathBuf) -> Result { let mut f = File::open(quest_path).map_err(|_| QuestLoadError::CouldNotLoadConfigFile)?; let mut s = String::new(); - f.read_to_string(&mut s); + f.read_to_string(&mut s)?; let mut used_quest_ids = BTreeSet::new(); let ql: BTreeMap = toml::from_str(s.as_str()).map_err(|_| QuestLoadError::CouldNotLoadConfigFile)?; diff --git a/src/ship/ship.rs b/src/ship/ship.rs index b6874c1..0c39912 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -427,7 +427,7 @@ impl ServerState for ShipServerState { handler::quest::quest_chunk_ack(id, quest_chunk_ack, &self.quests)? }, RecvShipPacket::DoneLoadingQuest(_) => { - handler::quest::done_loading_quest(id, &self.quests, &mut self.clients, &self.client_location)? + handler::quest::done_loading_quest(id, &mut self.clients, &self.client_location)? }, }) }