Browse Source

clippy

pull/127/head
jake 1 year ago
parent
commit
f3682d0b82
  1. 2
      src/bin/main.rs
  2. 4
      src/entity/character.rs
  3. 1
      src/entity/gateway/entitygateway.rs
  4. 4
      src/entity/gateway/postgres/postgres.rs
  5. 1
      src/lib.rs
  6. 2
      src/login/character.rs
  7. 6
      src/patch/patch.rs
  8. 2
      src/ship/drops/mod.rs
  9. 23
      src/ship/items/apply_item.rs
  10. 2
      src/ship/items/state.rs
  11. 2
      src/ship/map/enemy.rs
  12. 1
      src/ship/packet/handler/room.rs
  13. 2
      src/ship/packet/handler/settings.rs
  14. 12
      src/ship/room.rs
  15. 13
      src/ship/ship.rs

2
src/bin/main.rs

@ -52,7 +52,7 @@ fn main() {
for i in 0..5 {
let fake_user = NewUserAccountEntity {
email: format!("fake{}@email.com", i),
email: format!("fake{i}@email.com"),
username: if i == 0 { "hi".to_string() } else { format!("hi{}", i+1) },
password: bcrypt::hash("qwer", 5).unwrap(),
guildcard: i + 1,

4
src/entity/character.rs

@ -2,8 +2,8 @@ use std::convert::{From, Into};
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use libpso::packet::ship::{UpdateConfig, WriteInfoboard, KeyboardConfig, GamepadConfig};
use libpso::character::settings::{DEFAULT_PALETTE_CONFIG, DEFAULT_TECH_MENU, DEFAULT_KEYBOARD_CONFIG1, DEFAULT_KEYBOARD_CONFIG2, DEFAULT_KEYBOARD_CONFIG3, DEFAULT_KEYBOARD_CONFIG4, DEFAULT_GAMEPAD_CONFIG};
use libpso::packet::ship::{UpdateConfig, WriteInfoboard};
use libpso::character::settings::{DEFAULT_PALETTE_CONFIG, DEFAULT_TECH_MENU};
use crate::entity::item::tech::Technique;
use crate::entity::account::UserAccountId;

1
src/entity/gateway/entitygateway.rs

@ -1,4 +1,3 @@
use std::convert::From;
use thiserror::Error;
use futures::Future;

4
src/entity/gateway/postgres/postgres.rs

@ -2,7 +2,7 @@
#![allow(clippy::explicit_auto_deref)]
use std::convert::{From, TryFrom, Into};
use futures::{Future, TryStreamExt};
use futures::Future;
use async_std::stream::StreamExt;
use async_std::sync::{Arc, Mutex};
use libpso::character::guildcard;
@ -67,7 +67,7 @@ impl<'t> PostgresGateway<'t> {
let pool = async_std::task::block_on(async move {
PgPoolOptions::new()
.max_connections(5)
.connect(&format!("postgresql://{}:{}@{}:5432/{}", username, password, host, dbname)).await.unwrap()
.connect(&format!("postgresql://{username}:{password}@{host}:5432/{dbname}")).await.unwrap()
});
PostgresGateway {

1
src/lib.rs

@ -1,3 +1,4 @@
#![allow(clippy::type_complexity)]
#![allow(incomplete_features)]
#![feature(inline_const)]
#![feature(drain_filter)]

2
src/login/character.rs

@ -393,7 +393,7 @@ impl<EG: EntityGateway + Clone> CharacterServerState<EG> {
Ok(settings) => settings,
Err(_) => {
let user_settings = NewUserSettingsEntity::new(user.id);
self.entity_gateway.create_user_settings(user_settings).await.map_err(|err| CharacterError::CouldNotLoadSettings(err))?
self.entity_gateway.create_user_settings(user_settings).await.map_err(CharacterError::CouldNotLoadSettings)?
}
};

6
src/patch/patch.rs

@ -395,18 +395,18 @@ pub struct PatchConfig {
pub fn load_config() -> PatchConfig {
let ini_file = match fs::File::open(std::path::Path::new("patch.ron")) {
Err(err) => panic!("Failed to open patch.ron config file. \n{}", err),
Err(err) => panic!("Failed to open patch.ron config file. \n{err}"),
Ok(ini_file) => ini_file,
};
let mut s = String::new();
if let Err(err) = (&ini_file).read_to_string(&mut s) {
panic!("Failed to read patch.ron config file. \n{}", err);
panic!("Failed to read patch.ron config file. \n{err}");
}
let config: PatchConfig = match from_str(s.as_str()) {
Ok(config) => config,
Err(err) => panic!("Failed to load values from patch.ron \n{}",err),
Err(err) => panic!("Failed to load values from patch.ron \n{err}"),
};
config
}

2
src/ship/drops/mod.rs

@ -257,7 +257,7 @@ impl DropTableBuilder {
unit_table: self.unit_table.unwrap_or_else(|| GenericUnitTable::new(episode, difficulty, section_id)),
tool_table: self.tool_table.unwrap_or_else(|| ToolTable::new(episode, difficulty, section_id)),
box_table: self.box_table.unwrap_or_else(|| BoxDropTable::new(episode, difficulty, section_id)),
rng: self.rng.unwrap_or_else(|| rand_chacha::ChaCha20Rng::from_entropy()),
rng: self.rng.unwrap_or_else(rand_chacha::ChaCha20Rng::from_entropy),
}
}
}

23
src/ship/items/apply_item.rs

@ -8,9 +8,9 @@ use crate::entity::gateway::{EntityGateway, GatewayError};
use crate::entity::character::{CharacterEntity, TechLevel};
use crate::entity::item::mag::{MagCell, MagCellError};
use crate::entity::item::tool::{Tool, ToolType};
use crate::entity::item::tech::{TechniqueDisk, Technique};
use crate::entity::item::tech::TechniqueDisk;
use crate::entity::item::{ItemDetail, ItemEntityId};
use crate::ship::items::state::{ItemStateProxy, ItemStateError};
use crate::ship::items::state::ItemStateProxy;
use crate::ship::items::inventory::{InventoryItem, InventoryItemDetail};
@ -26,10 +26,6 @@ pub enum ApplyItemError {
InvalidTool,
#[error("gateway error {0}")]
GatewayError(#[from] GatewayError),
//#[error("itemstate error {0}")]
//ItemStateError(Box<ItemStateError>),
#[error("magcell error {0}")]
MagCellError(#[from] MagCellError),
}
@ -42,15 +38,6 @@ pub enum ApplyItemAction {
//RemoveItem,
}
/*
impl From<ItemStateError> for ApplyItemError {
fn from(other: ItemStateError) -> ApplyItemError {
ApplyItemError::ItemStateError(Box::new(other))
}
}
*/
async fn power_material<EG: EntityGateway + ?Sized>(entity_gateway: &mut EG, character: &mut CharacterEntity) -> Result<Vec<ApplyItemAction>, anyhow::Error> {
character.materials.power += 1;
entity_gateway.save_character(character).await?;
@ -315,14 +302,14 @@ where
// TODO: rest of these
_ => Err(anyhow::Error::from(ApplyItemError::InvalidTool))
.with_context(|| {
format!("invalid tool {:?}", tool)
format!("invalid tool {tool:?}")
})
}
}
async fn apply_tech<'a, EG>(item_state: &mut ItemStateProxy,
async fn apply_tech<'a, EG>(_item_state: &mut ItemStateProxy,
entity_gateway: &mut EG,
character: &mut CharacterEntity,
_entity_id: ItemEntityId,
@ -353,7 +340,7 @@ where
ItemDetail::TechniqueDisk(tech) => apply_tech(item_state, entity_gateway, character, individual_item.entity_id, tech).await,
_ => Err(anyhow::Error::from(ApplyItemError::InvalidItem))
.with_context(|| {
format!("item {:?}", individual_item)
format!("item {individual_item:?}")
})
}
},

2
src/ship/items/state.rs

@ -372,7 +372,7 @@ impl ItemState {
.map(|item| (item.clone(), FloorType::Shared))
})
.ok_or_else(|| ItemStateError::NoFloorItem(*item_id))
.with_context(|| format!("character {}\nlocal floors: {:#?}\nshared floors: {:#?}", character_id, local_floors, shared_floors))
.with_context(|| format!("character {character_id}\nlocal floors: {local_floors:#?}\nshared floors: {shared_floors:#?}"))
}
}

2
src/ship/map/enemy.rs

@ -103,7 +103,7 @@ impl RareMonsterAppearTable {
rand_chacha::ChaChaRng::from_entropy().gen::<f32>() < *self.appear_rate.get(monster).unwrap_or(&0.0f32)
}
pub fn apply(&self, mut enemy: MapEnemy, event: ShipEvent) -> MapEnemy {
pub fn apply(&self, enemy: MapEnemy, event: ShipEvent) -> MapEnemy {
if enemy.can_be_rare() && self.roll_is_rare(&enemy.monster) {
enemy.into_rare(event)
}

1
src/ship/packet/handler/room.rs

@ -16,6 +16,7 @@ use crate::ship::location::{ClientLocation, RoomId, RoomLobby, GetAreaError};
use crate::ship::packet::builder;
use crate::ship::items::state::ItemState;
#[allow(clippy::too_many_arguments)]
pub async fn create_room(id: ClientId,
create_room: CreateRoom,
client_location: &mut ClientLocation,

2
src/ship/packet/handler/settings.rs

@ -1,6 +1,6 @@
use libpso::packet::ship::*;
use crate::common::serverstate::ClientId;
use crate::ship::ship::{SendShipPacket, ShipError, Clients};
use crate::ship::ship::{SendShipPacket, Clients};
use crate::entity::gateway::EntityGateway;
pub async fn update_config<EG>(id: ClientId,

12
src/ship/room.rs

@ -13,12 +13,10 @@ use crate::ship::drops::DropTable;
use crate::entity::character::SectionID;
use crate::ship::monster::{load_monster_stats_table, MonsterType, MonsterStats};
use crate::ship::map::area::MapAreaLookup;
use crate::ship::map::enemy::RareMonsterAppearTable;
use crate::ship::quests;
use crate::ship::ship::{ShipError, ShipEvent};
use crate::ship::location::{MAX_ROOMS, RoomId};
#[derive(Clone)]
pub struct Rooms([Arc<RwLock<Option<RoomState>>>; MAX_ROOMS]);
@ -261,17 +259,11 @@ impl RoomMode {
}
pub fn battle(&self) -> bool {
match self {
RoomMode::Battle {..} => true,
_ => false,
}
matches!(self, RoomMode::Battle {..})
}
pub fn challenge(&self) -> bool {
match self {
RoomMode::Challenge {..} => true,
_ => false,
}
matches!(self, RoomMode::Challenge {..})
}
pub fn player_mode(&self) -> PlayerMode {

13
src/ship/ship.rs

@ -2,11 +2,8 @@
use std::net::Ipv4Addr;
use std::collections::HashMap;
use std::backtrace::Backtrace;
use async_std::channel;
use async_std::sync::{Arc, Mutex, RwLock};
use rand::Rng;
use thiserror::Error;
@ -15,21 +12,15 @@ use libpso::packet::login::{RedirectClient, Login, LoginResponse, ShipList};
use libpso::packet::messages::*;
use libpso::{PacketParseError, PSOPacket};
use libpso::crypto::bb::PSOBBCipher;
use libpso::packet::ship::{BLOCK_MENU_ID, ROOM_MENU_ID};
use crate::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY};
use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId};
use crate::common::interserver::{AuthToken, Ship, ServerId, InterserverActor, LoginMessage, ShipMessage};
use crate::login::character::SHIP_MENU_ID;
use crate::entity::gateway::{EntityGateway, GatewayError};
use crate::entity::character::SectionID;
use crate::ship::location::{ClientLocation, RoomLobby, ClientLocationError, RoomId};
use crate::ship::drops::DropTable;
use crate::ship::items;
use crate::ship::room;
@ -690,12 +681,12 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> {
let block = self.blocks.get_from_client(id, &self.clients).await?;
match menuselect.menu {
SHIP_MENU_ID => {
let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().into_iter().flatten();
let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().flatten();
let select_ship = handler::ship::selected_ship(id, menuselect, &self.ship_list).await?;
leave_lobby.chain(select_ship).collect()
}
BLOCK_MENU_ID => {
let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().into_iter().flatten();
let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().flatten();
let select_block = handler::lobby::block_selected(id, menuselect, &self.clients, &self.item_state).await?.into_iter();
leave_lobby.chain(select_block).collect()
}

Loading…
Cancel
Save