From 3cb5df45776a1b31804a2a8b33a95beec88be325 Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 30 May 2020 09:27:34 -0600 Subject: [PATCH] message/direct_message return a result --- src/ship/ship.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 3f6a5de..90edcb7 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -261,52 +261,52 @@ impl ShipServerState { } } - fn message(&mut self, id: ClientId, msg: &Message) -> Box + Send> { + fn message(&mut self, id: ClientId, msg: &Message) -> Result + Send>, ShipError> { match &msg.msg { GameMessage::RequestExp(request_exp) => { - handler::message::request_exp(id, request_exp, &self.client_location, &self.rooms) + Ok(handler::message::request_exp(id, request_exp, &self.client_location, &self.rooms)) }, GameMessage::PlayerDropItem(player_drop_item) => { - handler::message::player_drop_item(id, player_drop_item, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.rooms, &mut self.item_manager).unwrap() + handler::message::player_drop_item(id, player_drop_item, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.rooms, &mut self.item_manager) }, GameMessage::DropCoordinates(drop_coordinates) => { - handler::message::drop_coordinates(id, drop_coordinates, &self.client_location, &mut self.clients, &self.rooms).unwrap() + handler::message::drop_coordinates(id, drop_coordinates, &self.client_location, &mut self.clients, &self.rooms) }, GameMessage::PlayerSplitItemStack(split_item_stack) => { - handler::message::split_item_stack(id, split_item_stack, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager).unwrap() + handler::message::split_item_stack(id, split_item_stack, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager) }, _ => { let cmsg = msg.clone(); - Box::new(self.client_location.get_client_neighbors(id).unwrap().into_iter() + Ok(Box::new(self.client_location.get_client_neighbors(id).unwrap().into_iter() .map(move |client| { (client.client, SendShipPacket::Message(cmsg.clone())) - })) + }))) }, } } - fn direct_message(&mut self, id: ClientId, msg: &DirectMessage) -> Box + Send> { + fn direct_message(&mut self, id: ClientId, msg: &DirectMessage) -> Result + Send>, ShipError> { let target = msg.flag; match &msg.msg { GameMessage::GuildcardSend(guildcard_send) => { - handler::direct_message::guildcard_send(id, guildcard_send, target, &self.client_location, &self.clients) + Ok(handler::direct_message::guildcard_send(id, guildcard_send, target, &self.client_location, &self.clients)) }, GameMessage::RequestItem(request_item) => { - handler::direct_message::request_item(id, request_item, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.rooms, &mut self.item_manager).unwrap() + handler::direct_message::request_item(id, request_item, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.rooms, &mut self.item_manager) }, GameMessage::PickupItem(pickup_item) => { - handler::direct_message::pickup_item(id, pickup_item, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager).unwrap() + handler::direct_message::pickup_item(id, pickup_item, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager) }, GameMessage::BoxDropRequest(box_drop_request) => { - handler::direct_message::request_box_item(id, box_drop_request, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.rooms, &mut self.item_manager).unwrap() // TODO: unwrap + handler::direct_message::request_box_item(id, box_drop_request, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.rooms, &mut self.item_manager) } _ => { let cmsg = msg.clone(); - Box::new(self.client_location.get_all_clients_by_client(id).unwrap().into_iter() + Ok(Box::new(self.client_location.get_all_clients_by_client(id).unwrap().into_iter() .filter(move |client| client.local_client.id() == target as u8) .map(move |client| { (client.client, SendShipPacket::DirectMessage(cmsg.clone())) - })) + }))) }, } } @@ -375,10 +375,10 @@ impl ServerState for ShipServerState { Box::new(handler::lobby::send_player_to_lobby(id, chardata, &mut self.client_location, &self.clients, &self.item_manager, &self.level_table)?.into_iter()) }, RecvShipPacket::Message(msg) => { - self.message(id, msg) + self.message(id, msg)? }, RecvShipPacket::DirectMessage(msg) => { - self.direct_message(id, msg) + self.direct_message(id, msg)? }, RecvShipPacket::PlayerChat(msg) => { Box::new(handler::communication::player_chat(id, msg, &self.client_location, &self.clients)?.into_iter())