mirror of
https://github.com/redstrate/Kawari.git
synced 2025-06-30 11:47:45 +00:00
Fix more easy Clippy warnings
This commit is contained in:
parent
a76de282c9
commit
ddb67383af
5 changed files with 27 additions and 45 deletions
|
@ -58,7 +58,7 @@ impl GameData {
|
||||||
let sheet = WorldSheet::read_from(&mut self.game_data, Language::None)?;
|
let sheet = WorldSheet::read_from(&mut self.game_data, Language::None)?;
|
||||||
let row = sheet.get_row(world_id as u32)?;
|
let row = sheet.get_row(world_id as u32)?;
|
||||||
|
|
||||||
row.Name().into_string().map(|x| x.clone())
|
row.Name().into_string().cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the starting city-state from a given class/job id.
|
/// Gets the starting city-state from a given class/job id.
|
||||||
|
@ -66,7 +66,7 @@ impl GameData {
|
||||||
let sheet = ClassJobSheet::read_from(&mut self.game_data, Language::English)?;
|
let sheet = ClassJobSheet::read_from(&mut self.game_data, Language::English)?;
|
||||||
let row = sheet.get_row(classjob_id as u32)?;
|
let row = sheet.get_row(classjob_id as u32)?;
|
||||||
|
|
||||||
row.StartingTown().into_u8().map(|x| *x)
|
row.StartingTown().into_u8().copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_racial_base_attributes(&mut self, tribe_id: u8) -> Option<Attributes> {
|
pub fn get_racial_base_attributes(&mut self, tribe_id: u8) -> Option<Attributes> {
|
||||||
|
@ -127,11 +127,7 @@ impl GameData {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves a zone's internal name, place name or parent region name.
|
// Retrieves a zone's internal name, place name or parent region name.
|
||||||
pub fn get_territory_name(
|
pub fn get_territory_name(&mut self, zone_id: u32, which: TerritoryNameKind) -> Option<String> {
|
||||||
&mut self,
|
|
||||||
zone_id: u32,
|
|
||||||
which: TerritoryNameKind,
|
|
||||||
) -> Option<String> {
|
|
||||||
let sheet = TerritoryTypeSheet::read_from(&mut self.game_data, Language::None)?;
|
let sheet = TerritoryTypeSheet::read_from(&mut self.game_data, Language::None)?;
|
||||||
let row = sheet.get_row(zone_id)?;
|
let row = sheet.get_row(zone_id)?;
|
||||||
|
|
||||||
|
@ -269,7 +265,7 @@ impl GameData {
|
||||||
.Weather()
|
.Weather()
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.zip(row.Rate().clone())
|
.zip(row.Rate())
|
||||||
.map(|(x, y)| (*x.into_i32().unwrap(), *y.into_u8().unwrap() as i32))
|
.map(|(x, y)| (*x.into_i32().unwrap(), *y.into_u8().unwrap() as i32))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
|
@ -2,19 +2,11 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{Item, Storage};
|
use super::{Item, Storage};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||||
pub struct GenericStorage<const N: usize> {
|
pub struct GenericStorage<const N: usize> {
|
||||||
pub slots: Vec<Item>,
|
pub slots: Vec<Item>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> GenericStorage<N> {
|
|
||||||
pub fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
slots: vec![Item::default(); N],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<const N: usize> Storage for GenericStorage<N> {
|
impl<const N: usize> Storage for GenericStorage<N> {
|
||||||
fn max_slots(&self) -> u32 {
|
fn max_slots(&self) -> u32 {
|
||||||
N as u32
|
N as u32
|
||||||
|
|
|
@ -46,12 +46,12 @@ pub enum SegmentType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(import(kind: &SegmentType, size: u32, encryption_key: Option<&[u8]>))]
|
#[brw(import(kind: SegmentType, size: u32, encryption_key: Option<&[u8]>))]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum SegmentData<T: ReadWriteIpcSegment> {
|
pub enum SegmentData<T: ReadWriteIpcSegment> {
|
||||||
#[br(pre_assert(*kind == SegmentType::None))]
|
#[br(pre_assert(kind == SegmentType::None))]
|
||||||
None(),
|
None(),
|
||||||
#[br(pre_assert(*kind == SegmentType::Setup))]
|
#[br(pre_assert(kind == SegmentType::Setup))]
|
||||||
Setup {
|
Setup {
|
||||||
#[brw(pad_before = 4)] // empty
|
#[brw(pad_before = 4)] // empty
|
||||||
#[brw(pad_size_to = 36)]
|
#[brw(pad_size_to = 36)]
|
||||||
|
@ -60,13 +60,13 @@ pub enum SegmentData<T: ReadWriteIpcSegment> {
|
||||||
#[bw(map = write_string)]
|
#[bw(map = write_string)]
|
||||||
ticket: String, // square enix in their infinite wisdom has this as a STRING REPRESENTATION of an integer. what
|
ticket: String, // square enix in their infinite wisdom has this as a STRING REPRESENTATION of an integer. what
|
||||||
},
|
},
|
||||||
#[br(pre_assert(*kind == SegmentType::Initialize))]
|
#[br(pre_assert(kind == SegmentType::Initialize))]
|
||||||
Initialize {
|
Initialize {
|
||||||
player_id: u32,
|
player_id: u32,
|
||||||
#[brw(pad_after = 32)]
|
#[brw(pad_after = 32)]
|
||||||
timestamp: u32,
|
timestamp: u32,
|
||||||
},
|
},
|
||||||
#[br(pre_assert(*kind == SegmentType::SecuritySetup))]
|
#[br(pre_assert(kind == SegmentType::SecuritySetup))]
|
||||||
SecuritySetup {
|
SecuritySetup {
|
||||||
#[brw(pad_before = 36)] // empty
|
#[brw(pad_before = 36)] // empty
|
||||||
#[brw(pad_size_to = 32)]
|
#[brw(pad_size_to = 32)]
|
||||||
|
@ -79,24 +79,24 @@ pub enum SegmentData<T: ReadWriteIpcSegment> {
|
||||||
#[brw(pad_after = 512)] // empty
|
#[brw(pad_after = 512)] // empty
|
||||||
key: [u8; 4],
|
key: [u8; 4],
|
||||||
},
|
},
|
||||||
#[br(pre_assert(*kind == SegmentType::Ipc))]
|
#[br(pre_assert(kind == SegmentType::Ipc))]
|
||||||
Ipc {
|
Ipc {
|
||||||
#[br(parse_with = decrypt, args(size, encryption_key))]
|
#[br(parse_with = decrypt, args(size, encryption_key))]
|
||||||
#[bw(write_with = encrypt, args(size, encryption_key))]
|
#[bw(write_with = encrypt, args(size, encryption_key))]
|
||||||
data: T,
|
data: T,
|
||||||
},
|
},
|
||||||
#[br(pre_assert(*kind == SegmentType::KeepAliveRequest))]
|
#[br(pre_assert(kind == SegmentType::KeepAliveRequest))]
|
||||||
KeepAliveRequest { id: u32, timestamp: u32 },
|
KeepAliveRequest { id: u32, timestamp: u32 },
|
||||||
#[br(pre_assert(*kind == SegmentType::SecurityInitialize))]
|
#[br(pre_assert(kind == SegmentType::SecurityInitialize))]
|
||||||
SecurityInitialize {
|
SecurityInitialize {
|
||||||
#[br(count = 0x280)]
|
#[br(count = 0x280)]
|
||||||
#[brw(pad_size_to = 640)]
|
#[brw(pad_size_to = 640)]
|
||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
},
|
},
|
||||||
#[br(pre_assert(*kind == SegmentType::KeepAliveResponse))]
|
#[br(pre_assert(kind == SegmentType::KeepAliveResponse))]
|
||||||
KeepAliveResponse { id: u32, timestamp: u32 },
|
KeepAliveResponse { id: u32, timestamp: u32 },
|
||||||
|
|
||||||
#[br(pre_assert(*kind == SegmentType::KawariIpc))]
|
#[br(pre_assert(kind == SegmentType::KawariIpc))]
|
||||||
KawariIpc { data: CustomIpcSegment },
|
KawariIpc { data: CustomIpcSegment },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,8 @@ pub struct PacketSegment<T: ReadWriteIpcSegment> {
|
||||||
pub target_actor: u32,
|
pub target_actor: u32,
|
||||||
#[brw(pad_after = 2)] // padding
|
#[brw(pad_after = 2)] // padding
|
||||||
pub segment_type: SegmentType,
|
pub segment_type: SegmentType,
|
||||||
#[brw(args(&segment_type, size, encryption_key))]
|
#[bw(args(*segment_type, size, encryption_key))]
|
||||||
|
#[br(args(segment_type, size, encryption_key))]
|
||||||
#[br(err_context("segment size = {}", size))]
|
#[br(err_context("segment size = {}", size))]
|
||||||
pub data: SegmentData<T>,
|
pub data: SegmentData<T>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,11 +51,9 @@ impl WorldDatabase {
|
||||||
connection.execute(query, ()).unwrap();
|
connection.execute(query, ()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let this = Self {
|
Self {
|
||||||
connection: Mutex::new(connection),
|
connection: Mutex::new(connection),
|
||||||
};
|
}
|
||||||
|
|
||||||
this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn import_character(&self, service_account_id: u32, path: &str) {
|
pub fn import_character(&self, service_account_id: u32, path: &str) {
|
||||||
|
|
|
@ -93,17 +93,14 @@ impl WorldServer {
|
||||||
|
|
||||||
/// Finds the instance associated with a zone, or creates it if it doesn't exist yet
|
/// Finds the instance associated with a zone, or creates it if it doesn't exist yet
|
||||||
fn find_instance_mut(&mut self, zone_id: u16) -> &mut Instance {
|
fn find_instance_mut(&mut self, zone_id: u16) -> &mut Instance {
|
||||||
self.instances.entry(zone_id).or_insert(Instance::default())
|
self.instances.entry(zone_id).or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds the instance associated with an actor, or returns None if they are not found.
|
/// Finds the instance associated with an actor, or returns None if they are not found.
|
||||||
fn find_actor_instance_mut(&mut self, actor_id: u32) -> Option<&mut Instance> {
|
fn find_actor_instance_mut(&mut self, actor_id: u32) -> Option<&mut Instance> {
|
||||||
for instance in self.instances.values_mut() {
|
self.instances
|
||||||
if instance.actors.contains_key(&ObjectId(actor_id)) {
|
.values_mut()
|
||||||
return Some(instance);
|
.find(|instance| instance.actors.contains_key(&ObjectId(actor_id)))
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tell all the clients that a new NPC spawned.
|
/// Tell all the clients that a new NPC spawned.
|
||||||
|
@ -139,9 +136,9 @@ pub async fn server_main_loop(mut recv: Receiver<ToServer>) -> Result<(), std::i
|
||||||
let mut data = data.lock().unwrap();
|
let mut data = data.lock().unwrap();
|
||||||
|
|
||||||
// create a new instance if necessary
|
// create a new instance if necessary
|
||||||
if !data.instances.contains_key(&zone_id) {
|
data.instances
|
||||||
data.instances.insert(zone_id, Instance::default());
|
.entry(zone_id)
|
||||||
}
|
.or_insert_with(Instance::default);
|
||||||
|
|
||||||
// Send existing player data, if any
|
// Send existing player data, if any
|
||||||
if let Some(instance) = data.find_instance(zone_id).cloned() {
|
if let Some(instance) = data.find_instance(zone_id).cloned() {
|
||||||
|
@ -571,7 +568,7 @@ pub async fn server_main_loop(mut recv: Receiver<ToServer>) -> Result<(), std::i
|
||||||
|
|
||||||
if cast_time == 0 {
|
if cast_time == 0 {
|
||||||
// If instantaneous, send right back
|
// If instantaneous, send right back
|
||||||
send_execution(from_id.clone(), data.clone());
|
send_execution(from_id, data.clone());
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, delay
|
// Otherwise, delay
|
||||||
// NOTE: I know this won't scale, but it's a fine hack for now
|
// NOTE: I know this won't scale, but it's a fine hack for now
|
||||||
|
@ -582,8 +579,6 @@ pub async fn server_main_loop(mut recv: Receiver<ToServer>) -> Result<(), std::i
|
||||||
);
|
);
|
||||||
|
|
||||||
// we have to shadow these variables to tell rust not to move them into the async closure
|
// we have to shadow these variables to tell rust not to move them into the async closure
|
||||||
let cast_time = cast_time.clone();
|
|
||||||
let from_id = from_id.clone();
|
|
||||||
let data = data.clone();
|
let data = data.clone();
|
||||||
tokio::task::spawn(async move {
|
tokio::task::spawn(async move {
|
||||||
let mut interval =
|
let mut interval =
|
||||||
|
|
Loading…
Add table
Reference in a new issue