Browse Source

improve error display a bit

pull/80/head
jake 2 years ago
parent
commit
6d2753d082
  1. 2
      src/common/serverstate.rs
  2. 2
      src/entity/character.rs
  3. 2
      src/entity/item/mod.rs
  4. 15
      src/ship/items/manager.rs
  5. 2
      src/ship/items/mod.rs
  6. 20
      src/ship/location.rs
  7. 7
      src/ship/ship.rs
  8. 2
      src/ship/trade.rs

2
src/common/serverstate.rs

@ -1,7 +1,7 @@
use libpso::PacketParseError;
use libpso::crypto::PSOCipher;
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, derive_more::Display)]
pub struct ClientId(pub usize);
pub enum OnConnect<S: SendServerPacket> {

2
src/entity/character.rs

@ -272,7 +272,7 @@ pub struct CharacterMaterials {
pub tp: u32,
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default, derive_more::Display)]
pub struct CharacterEntityId(pub u32);
#[derive(Clone)]

2
src/entity/item/mod.rs

@ -17,7 +17,7 @@ use crate::ship::drops::ItemDropType;
pub struct ItemEntityId(pub u32);
#[derive(Hash, PartialEq, Eq, Debug, Clone)]
pub struct ItemId(u32);
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, derive_more::Display)]
pub struct BankName(pub String);
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct TradeId(pub u32);

15
src/ship/items/manager.rs

@ -34,33 +34,46 @@ pub enum TriggerCreateItem {
}
#[derive(Error, Debug)]
#[error("")]
#[error("itemmanager")]
pub enum ItemManagerError {
#[error("gateway")]
EntityGatewayError,
#[error("no such item id {0}")]
NoSuchItemId(ClientItemId),
NoCharacter(CharacterEntityId),
NoRoom(RoomId),
CouldNotAddToInventory(ClientItemId),
//ItemBelongsToOtherPlayer,
#[error("shrug")]
Idunnoman,
CouldNotSplitItem(ClientItemId),
#[error("could not drop meseta")]
CouldNotDropMeseta,
InvalidBankName(BankName),
#[error("not enough tools")]
NotEnoughTools(Tool, usize, usize), // have, expected
InventoryItemConsumeError(#[from] InventoryItemConsumeError),
#[error("bank full")]
BankFull,
WrongItemType(ClientItemId),
UseItemError(#[from] use_tool::UseItemError),
#[error("could not buy item")]
CouldNotBuyItem,
#[error("could not add bought item to inventory")]
CouldNotAddBoughtItemToInventory,
ItemIdNotInInventory(ClientItemId),
#[error("cannot get mut item")]
CannotGetMutItem,
#[error("cannot get individual item")]
CannotGetIndividualItem,
InvalidSlot(u8, u8), // slots available, slot attempted
#[error("no armor equipped")]
NoArmorEquipped,
GatewayError(#[from] GatewayError),
#[error("stacked item")]
StackedItemError(Vec<ItemEntity>),
ItemTransactionAction(Box<dyn std::error::Error + Send + Sync>),
#[error("invalid trade")]
InvalidTrade,
}

2
src/ship/items/mod.rs

@ -6,7 +6,7 @@ mod transaction;
pub mod use_tool;
use serde::{Serialize, Deserialize};
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Serialize, Deserialize, derive_more::Display)]
pub struct ClientItemId(pub u32);
// TODO: remove these and fix use statements in the rest of the codebase

20
src/ship/location.rs

@ -15,7 +15,7 @@ pub enum AreaType {
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct LobbyId(pub usize);
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, derive_more::Display)]
pub struct RoomId(pub usize);
impl LobbyId {
@ -26,7 +26,7 @@ impl LobbyId {
#[derive(Error, Debug, PartialEq)]
#[error("")]
#[error("create room")]
pub enum CreateRoomError {
NoOpenSlots,
ClientInAreaAlready,
@ -34,7 +34,7 @@ pub enum CreateRoomError {
}
#[derive(Error, Debug, PartialEq)]
#[error("")]
#[error("join room")]
pub enum JoinRoomError {
RoomDoesNotExist,
RoomFull,
@ -42,7 +42,7 @@ pub enum JoinRoomError {
}
#[derive(Error, Debug, PartialEq)]
#[error("")]
#[error("join lobby")]
pub enum JoinLobbyError {
LobbyDoesNotExist,
LobbyFull,
@ -50,7 +50,7 @@ pub enum JoinLobbyError {
}
#[derive(Error, Debug, PartialEq)]
#[error("")]
#[error("get area")]
pub enum GetAreaError {
NotInRoom,
NotInLobby,
@ -58,28 +58,28 @@ pub enum GetAreaError {
}
#[derive(Error, Debug, PartialEq)]
#[error("")]
#[error("client removal")]
pub enum ClientRemovalError {
ClientNotInArea,
InvalidArea,
}
#[derive(Error, Debug, PartialEq)]
#[error("")]
#[error("get clients")]
pub enum GetClientsError {
InvalidClient,
InvalidArea,
}
#[derive(Error, Debug, PartialEq)]
#[error("")]
#[error("get neighbor")]
pub enum GetNeighborError {
InvalidClient,
InvalidArea,
}
#[derive(Error, Debug, PartialEq)]
#[error("")]
#[error("get leader")]
pub enum GetLeaderError {
InvalidClient,
InvalidArea,
@ -87,7 +87,7 @@ pub enum GetLeaderError {
}
#[derive(Error, Debug, PartialEq)]
#[error("")]
#[error("clientlocation")]
pub enum ClientLocationError {
CreateRoomError(#[from] CreateRoomError),
JoinRoomError(#[from] JoinRoomError),

7
src/ship/ship.rs

@ -42,11 +42,12 @@ pub type Rooms = [Option<room::RoomState>; MAX_ROOMS];
pub type Clients = HashMap<ClientId, ClientState>;
#[derive(Error, Debug)]
#[error("shiperror")]
#[error("shiperror {0:?}")]
pub enum ShipError {
ClientNotFound(ClientId),
NoCharacterInSlot(ClientId, u32),
InvalidSlot(ClientId, u32),
#[error("")]
TooManyClients,
ClientLocationError(#[from] ClientLocationError),
GetNeighborError(#[from] GetNeighborError),
@ -57,10 +58,12 @@ pub enum ShipError {
InvalidRoom(u32),
MonsterAlreadyDroppedItem(ClientId, u16),
SliceError(#[from] std::array::TryFromSliceError),
#[error("")]
ItemError, // TODO: refine this
PickUpInvalidItemId(u32),
DropInvalidItemId(u32),
ItemManagerError(#[from] items::ItemManagerError),
#[error("")]
ItemDropLocationNotSet,
BoxAlreadyDroppedItem(ClientId, u16),
InvalidQuestCategory(u32),
@ -68,12 +71,14 @@ pub enum ShipError {
InvalidQuestFilename(String),
IoError(#[from] std::io::Error),
NotEnoughMeseta(ClientId, u32),
#[error("")]
ShopError,
GatewayError(#[from] GatewayError),
UnknownMonster(crate::ship::monster::MonsterType),
InvalidShip(usize),
InvalidBlock(usize),
InvalidItem(items::ClientItemId),
#[error("tradeerror {0}")]
TradeError(#[from] crate::ship::packet::handler::trade::TradeError),
}

2
src/ship/trade.rs

@ -102,7 +102,7 @@ pub enum TradeStateError {
MismatchedTrade(ClientId, ClientId),
}
#[derive(Default)]
#[derive(Default, Debug)]
pub struct TradeState {
trades: HashMap<ClientId, RefCell<ClientTradeState>>,
}

Loading…
Cancel
Save