|
|
@ -375,93 +375,93 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
|
ShipServerStateBuilder::new()
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn message(&mut self, id: ClientId, msg: &Message) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
|
|
|
match &msg.msg {
|
|
|
|
async fn message(&mut self, id: ClientId, msg: &Message) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error> {
|
|
|
|
Ok(match &msg.msg {
|
|
|
|
GameMessage::RequestExp(request_exp) => {
|
|
|
|
handler::message::request_exp(id, request_exp, &mut self.entity_gateway, &self.client_location, &mut self.clients, &mut self.rooms, &self.level_table).await
|
|
|
|
handler::message::request_exp(id, request_exp, &mut self.entity_gateway, &self.client_location, &mut self.clients, &mut self.rooms, &self.level_table).await?
|
|
|
|
},
|
|
|
|
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).await
|
|
|
|
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).await?
|
|
|
|
},
|
|
|
|
GameMessage::DropCoordinates(drop_coordinates) => {
|
|
|
|
handler::message::drop_coordinates(id, drop_coordinates, &self.client_location, &mut self.clients, &self.rooms)
|
|
|
|
handler::message::drop_coordinates(id, drop_coordinates, &self.client_location, &mut self.clients, &self.rooms)?
|
|
|
|
},
|
|
|
|
GameMessage::PlayerNoLongerHasItem(no_longer_has_item) => {
|
|
|
|
handler::message::split_item_stack(id, no_longer_has_item, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager).await
|
|
|
|
handler::message::split_item_stack(id, no_longer_has_item, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
},
|
|
|
|
GameMessage::PlayerChangedMap(_) | GameMessage::PlayerChangedMap2(_) | GameMessage::TellOtherPlayerMyLocation(_) |
|
|
|
|
GameMessage::PlayerWarpingToFloor(_) | GameMessage::PlayerTeleported(_) | GameMessage::PlayerStopped(_) |
|
|
|
|
GameMessage::PlayerLoadedIn(_) | GameMessage::PlayerWalking(_) | GameMessage::PlayerRunning(_) |
|
|
|
|
GameMessage::PlayerWarped(_) | GameMessage::PlayerChangedFloor(_) | GameMessage::InitializeSpeechNpc(_) => {
|
|
|
|
handler::message::update_player_position(id, &msg, &mut self.clients, &mut self.client_location, &self.rooms)
|
|
|
|
handler::message::update_player_position(id, &msg, &mut self.clients, &mut self.client_location, &self.rooms)?
|
|
|
|
},
|
|
|
|
GameMessage::ChargeAttack(charge_attack) => {
|
|
|
|
handler::message::charge_attack(id, charge_attack, &mut self.clients, &mut self.entity_gateway).await
|
|
|
|
handler::message::charge_attack(id, charge_attack, &mut self.clients, &mut self.entity_gateway).await?
|
|
|
|
},
|
|
|
|
GameMessage::PlayerUseItem(player_use_item) => {
|
|
|
|
handler::message::use_item(id, player_use_item, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager).await
|
|
|
|
handler::message::use_item(id, player_use_item, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
},
|
|
|
|
GameMessage::PlayerUsedMedicalCenter(player_used_medical_center) => {
|
|
|
|
handler::message::player_used_medical_center(id, &player_used_medical_center, &mut self.entity_gateway, &mut self.clients).await
|
|
|
|
handler::message::player_used_medical_center(id, &player_used_medical_center, &mut self.entity_gateway, &mut self.clients).await?
|
|
|
|
},
|
|
|
|
GameMessage::PlayerFeedMag(player_feed_mag) => {
|
|
|
|
handler::message::player_feed_mag(id, &player_feed_mag, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager).await
|
|
|
|
handler::message::player_feed_mag(id, &player_feed_mag, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
},
|
|
|
|
GameMessage::PlayerEquipItem(player_equip_item) => {
|
|
|
|
handler::message::player_equips_item(id, &player_equip_item, &mut self.entity_gateway, &mut self.clients, &mut self.item_manager).await
|
|
|
|
handler::message::player_equips_item(id, &player_equip_item, &mut self.entity_gateway, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
},
|
|
|
|
GameMessage::PlayerUnequipItem(player_unequip_item) => {
|
|
|
|
handler::message::player_unequips_item(id, &player_unequip_item, &mut self.entity_gateway, &mut self.clients, &mut self.item_manager).await
|
|
|
|
handler::message::player_unequips_item(id, &player_unequip_item, &mut self.entity_gateway, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
},
|
|
|
|
GameMessage::SortItems(sort_items) => {
|
|
|
|
handler::message::player_sorts_items(id, sort_items, &mut self.entity_gateway, &mut self.clients, &mut self.item_manager).await
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
let cmsg = msg.clone();
|
|
|
|
Ok(Box::new(self.client_location.get_client_neighbors(id).unwrap().into_iter()
|
|
|
|
Box::new(self.client_location.get_client_neighbors(id).unwrap().into_iter()
|
|
|
|
.map(move |client| {
|
|
|
|
(client.client, SendShipPacket::Message(cmsg.clone()))
|
|
|
|
})))
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn direct_message(&mut self, id: ClientId, msg: &DirectMessage) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
|
|
|
async fn direct_message(&mut self, id: ClientId, msg: &DirectMessage) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error> {
|
|
|
|
let target = msg.flag;
|
|
|
|
match &msg.msg {
|
|
|
|
Ok(match &msg.msg {
|
|
|
|
GameMessage::GuildcardSend(guildcard_send) => {
|
|
|
|
Ok(handler::direct_message::guildcard_send(id, guildcard_send, target, &self.client_location, &self.clients))
|
|
|
|
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).await
|
|
|
|
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).await?
|
|
|
|
},
|
|
|
|
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).await
|
|
|
|
handler::direct_message::pickup_item(id, pickup_item, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
},
|
|
|
|
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).await
|
|
|
|
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).await?
|
|
|
|
},
|
|
|
|
GameMessage::BankRequest(_bank_request) => {
|
|
|
|
handler::direct_message::send_bank_list(id, &self.clients, &mut self.item_manager).await
|
|
|
|
handler::direct_message::send_bank_list(id, &self.clients, &mut self.item_manager).await?
|
|
|
|
},
|
|
|
|
GameMessage::BankInteraction(bank_interaction) => {
|
|
|
|
handler::direct_message::bank_interaction(id, bank_interaction, &mut self.entity_gateway, &self.client_location, &mut self.clients, &mut self.item_manager).await
|
|
|
|
handler::direct_message::bank_interaction(id, bank_interaction, &mut self.entity_gateway, &self.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
},
|
|
|
|
GameMessage::ShopRequest(shop_request) => {
|
|
|
|
handler::direct_message::shop_request(id, shop_request, &self.client_location, &mut self.clients, &self.rooms, &self.level_table, &mut self.shops).await
|
|
|
|
handler::direct_message::shop_request(id, shop_request, &self.client_location, &mut self.clients, &self.rooms, &self.level_table, &mut self.shops).await?
|
|
|
|
},
|
|
|
|
GameMessage::BuyItem(buy_item) => {
|
|
|
|
handler::direct_message::buy_item(id, buy_item, &mut self.entity_gateway, &self.client_location, &mut self.clients, &mut self.item_manager).await
|
|
|
|
handler::direct_message::buy_item(id, buy_item, &mut self.entity_gateway, &self.client_location, &mut self.clients, &mut self.item_manager).await?
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
let cmsg = msg.clone();
|
|
|
|
Ok(Box::new(self.client_location.get_all_clients_by_client(id).unwrap().into_iter()
|
|
|
|
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()))
|
|
|
|
})))
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
@ -469,9 +469,9 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
|
impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
|
|
|
|
type SendPacket = SendShipPacket;
|
|
|
|
type RecvPacket = RecvShipPacket;
|
|
|
|
type PacketError = ShipError;
|
|
|
|
type PacketError = anyhow::Error;
|
|
|
|
|
|
|
|
async fn on_connect(&mut self, _id: ClientId) -> Result<Vec<OnConnect<Self::SendPacket>>, ShipError> {
|
|
|
|
async fn on_connect(&mut self, _id: ClientId) -> Result<Vec<OnConnect<Self::SendPacket>>, anyhow::Error> {
|
|
|
|
let mut rng = rand::thread_rng();
|
|
|
|
|
|
|
|
let mut server_key = [0u8; 48];
|
|
|
@ -486,7 +486,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> { |
|
|
|
}
|
|
|
|
|
|
|
|
async fn handle(&mut self, id: ClientId, pkt: &RecvShipPacket)
|
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error> {
|
|
|
|
Ok(match pkt {
|
|
|
|
RecvShipPacket::Login(login) => {
|
|
|
|
Box::new(handler::auth::validate_login(id, login, &mut self.entity_gateway, &mut self.clients, &mut self.item_manager, &self.name).await?.into_iter().map(move |pkt| (id, pkt)))
|
|
|
@ -593,7 +593,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> { |
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn on_disconnect(&mut self, id: ClientId) -> Result<Vec<(ClientId, SendShipPacket)>, ShipError> {
|
|
|
|
async fn on_disconnect(&mut self, id: ClientId) -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
|
|
|
|
// TODO: don't unwrap!
|
|
|
|
let client = self.clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
let area_client = self.client_location.get_local_client(id)?;
|
|
|
|