Browse Source

lint src/ship/packet/handler/*

pull/42/head
jake 3 years ago
parent
commit
3cf834ed55
  1. 7
      src/ship/packet/handler/auth.rs
  2. 22
      src/ship/packet/handler/direct_message.rs
  3. 9
      src/ship/packet/handler/lobby.rs
  4. 2
      src/ship/packet/handler/message.rs
  5. 14
      src/ship/packet/handler/quest.rs
  6. 14
      src/ship/packet/handler/room.rs

7
src/ship/packet/handler/auth.rs

@ -7,13 +7,14 @@ use crate::entity::gateway::EntityGateway;
use crate::ship::items::ItemManager;
use crate::common::interserver::ShipMessage;
#[allow(clippy::too_many_arguments)]
pub async fn validate_login<EG: EntityGateway>(id: ClientId,
pkt: &Login,
entity_gateway: &mut EG,
clients: &mut Clients,
item_manager: &mut ItemManager,
shipgate_sender: &Option<Box<dyn Fn(ShipMessage) + Send + Sync>>,
ship_name: &String,
ship_name: &str,
num_blocks: usize)
-> Result<Vec<SendShipPacket>, anyhow::Error> {
Ok(match get_login_status(entity_gateway, pkt).await {
@ -32,10 +33,10 @@ pub async fn validate_login<EG: EntityGateway>(id: ClientId,
item_manager.load_character(entity_gateway, &character).await?;
if let Some(shipgate_sender) = shipgate_sender.as_ref() {
shipgate_sender(ShipMessage::AddUser(user.id.clone()));
shipgate_sender(ShipMessage::AddUser(user.id));
}
clients.insert(id, ClientState::new(user, settings, character, pkt.session));
vec![SendShipPacket::LoginResponse(response), SendShipPacket::ShipBlockList(ShipBlockList::new(&&ship_name, num_blocks))]
vec![SendShipPacket::LoginResponse(response), SendShipPacket::ShipBlockList(ShipBlockList::new(ship_name, num_blocks))]
},
Err(err) => {
vec![SendShipPacket::LoginResponse(LoginResponse::by_status(err, Session::new()))]

22
src/ship/packet/handler/direct_message.rs

@ -65,7 +65,7 @@ pub fn guildcard_send(id: ClientId,
class: client.character.char_class.into(),
}),
};
send_to_client(id, target as u8, msg, &client_location)
send_to_client(id, target as u8, msg, client_location)
}
pub async fn request_item<EG>(id: ClientId,
@ -110,7 +110,7 @@ where
};
let client = clients.get_mut(&area_client.client).ok_or(ShipError::ClientNotFound(area_client.client))?;
let floor_item = item_manager.enemy_drop_item_on_local_floor(entity_gateway, &client.character, item_drop).await?;
let item_drop_msg = builder::message::item_drop(request_item.client, request_item.target, &floor_item)?;
let item_drop_msg = builder::message::item_drop(request_item.client, request_item.target, floor_item)?;
item_drop_packets.push((area_client.client, SendShipPacket::Message(Message::new(GameMessage::ItemDrop(item_drop_msg)))));
}
@ -135,7 +135,7 @@ where
// TODO: should not need to fetch the item here to construct this packet
let (item, floor_type) = item_manager.get_floor_item_by_id(&client.character, ClientItemId(pickup_item.item_id))?;
let remove_item = builder::message::remove_item_from_floor(area_client, &item)?;
let remove_item = builder::message::remove_item_from_floor(area_client, item)?;
let create_item = match item {
FloorItem::Individual(individual_floor_item) => Some(builder::message::create_item(area_client, item.item_id(), &individual_floor_item.item)?),
FloorItem::Stacked(stacked_floor_item) => Some(builder::message::create_item(area_client, item.item_id(), &item::ItemDetail::Tool(stacked_floor_item.tool))?),
@ -216,7 +216,7 @@ EG: EntityGateway
};
let client = clients.get_mut(&area_client.client).ok_or(ShipError::ClientNotFound(area_client.client))?;
let floor_item = item_manager.enemy_drop_item_on_local_floor(entity_gateway, &client.character, item_drop).await?; // TODO: unwrap
let item_drop_msg = builder::message::item_drop(box_drop_request.client, box_drop_request.target, &floor_item)?;
let item_drop_msg = builder::message::item_drop(box_drop_request.client, box_drop_request.target, floor_item)?;
item_drop_packets.push((area_client.client, SendShipPacket::Message(Message::new(GameMessage::ItemDrop(item_drop_msg)))))
}
@ -233,7 +233,7 @@ pub async fn send_bank_list(id: ClientId,
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
let bank_items = item_manager.get_character_bank(&client.character)?;
let bank_items_pkt = builder::message::bank_item_list(&bank_items, client.character.bank_meseta);
let bank_items_pkt = builder::message::bank_item_list(bank_items, client.character.bank_meseta);
Ok(Box::new(vec![(id, SendShipPacket::BankItemList(bank_items_pkt))].into_iter()))
}
@ -277,7 +277,7 @@ where
}
else {
let item_added_to_inventory = item_manager.player_withdraws_item(entity_gateway, &client.character, ClientItemId(bank_interaction.item_id), bank_interaction.item_amount as usize).await?;
let item_created = builder::message::create_withdrawn_inventory_item(area_client, &item_added_to_inventory)?;
let item_created = builder::message::create_withdrawn_inventory_item(area_client, item_added_to_inventory)?;
vec![SendShipPacket::Message(Message::new(GameMessage::CreateItem(item_created)))]
}
},
@ -357,18 +357,12 @@ where
},
SHOP_OPTION_TOOL => {
let item = client.tool_shop.get(buy_item.shop_index as usize).ok_or(ShipError::ShopError)?;
let remove = match item {
ToolShopItem::Tech(_) => true,
_ => false,
};
let remove = matches!(item, ToolShopItem::Tech(_));
(item, remove)
},
SHOP_OPTION_ARMOR => {
let item = client.armor_shop.get(buy_item.shop_index as usize).ok_or(ShipError::ShopError)?;
let remove = match item {
ArmorShopItem::Unit(_) => true,
_ => false,
};
let remove = matches!(item, ArmorShopItem::Unit(_));
(item, remove)
},
_ => {

9
src/ship/packet/handler/lobby.rs

@ -28,8 +28,8 @@ pub fn block_selected(id: ClientId,
.character(&client.character)
.stats(&stats)
.level(level)
.inventory(&inventory)
.bank(&bank)
.inventory(inventory)
.bank(bank)
.key_config(&client.settings.settings.key_config)
.joystick_config(&client.settings.settings.joystick_config)
.symbol_chat(&client.settings.settings.symbol_chats)
@ -63,6 +63,7 @@ pub fn send_player_to_lobby(id: ClientId,
.map(|c| (c.client, SendShipPacket::AddToLobby(addto.clone())))).collect())
}
#[allow(clippy::too_many_arguments)]
pub async fn change_lobby<EG: EntityGateway>(id: ClientId,
requested_lobby: u32,
client_location: &mut ClientLocation,
@ -81,7 +82,7 @@ pub async fn change_lobby<EG: EntityGateway>(id: ClientId,
}
},
RoomLobby::Room(old_room) => {
if client_location.get_client_neighbors(id).map_err(|err| -> ClientLocationError {err.into()})?.len() == 0 {
if client_location.get_client_neighbors(id)?.is_empty() {
ship_rooms[old_room.0] = None;
}
item_manager.remove_character_from_room(&client.character);
@ -90,7 +91,7 @@ pub async fn change_lobby<EG: EntityGateway>(id: ClientId,
let leave_lobby = packet::builder::lobby::remove_from_lobby(id, client_location)?;
let old_neighbors = client_location.get_client_neighbors(id).unwrap();
let mut lobby = LobbyId(requested_lobby as usize);
if let Err(_) = client_location.add_client_to_lobby(id, lobby) {
if client_location.add_client_to_lobby(id, lobby).is_err() {
match prev_area {
RoomLobby::Lobby(_lobby) => {
let dialog = SmallDialog::new(String::from("Lobby is full."));

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

@ -26,7 +26,7 @@ pub async fn request_exp<EG: EntityGateway>(id: ClientId,
.ok_or_else(|| ShipError::InvalidRoom(room_id.0 as u32))?;
let monster = room.maps.enemy_by_id(request_exp.enemy_id as usize)?;
let monster_stats = room.monster_stats.get(&monster.monster).ok_or(ShipError::UnknownMonster(monster.monster.clone()))?;
let monster_stats = room.monster_stats.get(&monster.monster).ok_or(ShipError::UnknownMonster(monster.monster))?;
let exp_gain = if request_exp.last_hitter == 1 {
monster_stats.exp

14
src/ship/packet/handler/quest.rs

@ -17,8 +17,8 @@ fn parse_filename(filename_bytes: &[u8; 16]) -> Result<(u16, u16, QuestFileType)
let filename = array_to_utf8(*filename_bytes).map_err(|_| ShipError::InvalidQuestFilename("NOT UTF8".to_string()))?;
let (filename, suffix) = {
let mut s = filename.splitn(2, '.');
(s.next().ok_or(ShipError::InvalidQuestFilename(filename.to_owned()))?,
s.next().ok_or(ShipError::InvalidQuestFilename(filename.to_owned()))?)
(s.next().ok_or_else(|| ShipError::InvalidQuestFilename(filename.to_owned()))?,
s.next().ok_or_else(|| ShipError::InvalidQuestFilename(filename.to_owned()))?)
};
let datatype = match suffix {
@ -29,8 +29,8 @@ fn parse_filename(filename_bytes: &[u8; 16]) -> Result<(u16, u16, QuestFileType)
let (category, quest) = {
let mut s = filename.splitn(2, '-');
(s.next().and_then(|k| k.parse().ok()).ok_or(ShipError::InvalidQuestFilename(filename.to_owned()))?,
s.next().and_then(|k| k.parse().ok()).ok_or(ShipError::InvalidQuestFilename(filename.to_owned()))?)
(s.next().and_then(|k| k.parse().ok()).ok_or_else(|| ShipError::InvalidQuestFilename(filename.to_owned()))?,
s.next().and_then(|k| k.parse().ok()).ok_or_else(|| ShipError::InvalidQuestFilename(filename.to_owned()))?)
};
Ok((category, quest, datatype))
@ -63,7 +63,7 @@ pub fn quest_detail(id: ClientId, questdetailrequest: &QuestDetailRequest, quest
q.id == questdetailrequest.quest as u16
}).ok_or(ShipError::InvalidQuest(questdetailrequest.quest as u32))?;
let qd = quest::quest_detail(&quest);
let qd = quest::quest_detail(quest);
Ok(Box::new(vec![(id, SendShipPacket::QuestDetail(qd))].into_iter()))
}
@ -91,9 +91,9 @@ pub fn load_quest(id: ClientId, questmenuselect: &QuestMenuSelect, quests: &Ques
let area_clients = client_location.get_all_clients_by_client(id).map_err(|err| -> ClientLocationError { err.into() })?;
area_clients.iter().for_each(|c| {
clients.get_mut(&c.client).map(|client| {
if let Some(client) = clients.get_mut(&c.client) {
client.done_loading_quest = false;
});
}
});
Ok(Box::new(area_clients.into_iter().map(move |c| {
vec![(c.client, SendShipPacket::QuestHeader(bin.clone())), (c.client, SendShipPacket::QuestHeader(dat.clone()))]

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

@ -66,8 +66,8 @@ pub fn join_room(id: ClientId,
let original_area = client_location.get_area(id).unwrap();
let original_neighbors = client_location.get_client_neighbors(id).unwrap();
let room = rooms.get(pkt.item as usize)
.ok_or_else(|| ShipError::InvalidRoom(pkt.item))?.as_ref()
.ok_or_else(|| ShipError::InvalidRoom(pkt.item))?;
.ok_or(ShipError::InvalidRoom(pkt.item))?.as_ref()
.ok_or(ShipError::InvalidRoom(pkt.item))?;
if room.bursting {
return Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("player is bursting\nplease wait".into())))].into_iter()))
}
@ -81,8 +81,8 @@ pub fn join_room(id: ClientId,
item_manager.add_character_to_room(room_id, &client.character, area_client);
let leader = client_location.get_room_leader(room_id).map_err(|err| -> ClientLocationError { err.into() })?;
let join_room = builder::room::join_room(id, clients, client_location, room_id, &room)?;
let add_to = builder::room::add_to_room(id, &client, &area_client, &leader, item_manager, level_table, room_id)?;
let join_room = builder::room::join_room(id, clients, client_location, room_id, room)?;
let add_to = builder::room::add_to_room(id, client, &area_client, &leader, item_manager, level_table, room_id)?;
let room = rooms.get_mut(room_id.0).unwrap().as_mut().unwrap();
room.bursting = true;
@ -90,7 +90,7 @@ pub fn join_room(id: ClientId,
let mut result: Box<dyn Iterator<Item=(ClientId, SendShipPacket)> + Send> = Box::new(
vec![(id, SendShipPacket::JoinRoom(join_room))]
.into_iter()
.chain(original_room_clients.clone().into_iter()
.chain(original_room_clients.into_iter()
.map(move |c| (c.client, SendShipPacket::AddToRoom(add_to.clone())))
));
@ -109,9 +109,9 @@ pub fn done_bursting(id: ClientId,
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
let area = client_location.get_area(id).unwrap();
if let RoomLobby::Room(room_id) = area {
rooms.get_mut(room_id.0).unwrap().as_mut().map(|room| {
if let Some(room) = rooms.get_mut(room_id.0).unwrap().as_mut() {
room.bursting = false;
});
}
}
let area_client = client_location.get_local_client(id).unwrap(); // TODO: unwrap
Box::new(client_location.get_client_neighbors(id).unwrap().into_iter() // TODO: unwrap

Loading…
Cancel
Save