|
@ -9,7 +9,7 @@ use rand::Rng; |
|
|
use thiserror::Error;
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
|
use libpso::packet::ship::*;
|
|
|
use libpso::packet::ship::*;
|
|
|
use libpso::packet::login::{RedirectClient, Login, LoginResponse, Session, ShipList};
|
|
|
|
|
|
|
|
|
use libpso::packet::login::{RedirectClient, Login, LoginResponse, ShipList};
|
|
|
use libpso::packet::messages::*;
|
|
|
use libpso::packet::messages::*;
|
|
|
use libpso::{PacketParseError, PSOPacket};
|
|
|
use libpso::{PacketParseError, PSOPacket};
|
|
|
use libpso::crypto::bb::PSOBBCipher;
|
|
|
use libpso::crypto::bb::PSOBBCipher;
|
|
@ -24,17 +24,15 @@ use crate::common::interserver::{AuthToken, Ship, ServerId, InterserverActor, Lo |
|
|
use crate::login::character::SHIP_MENU_ID;
|
|
|
use crate::login::character::SHIP_MENU_ID;
|
|
|
|
|
|
|
|
|
use crate::entity::gateway::{EntityGateway, GatewayError};
|
|
|
use crate::entity::gateway::{EntityGateway, GatewayError};
|
|
|
use crate::entity::account::{UserAccountEntity, UserSettingsEntity};
|
|
|
|
|
|
use crate::entity::character::{CharacterEntity, SectionID};
|
|
|
|
|
|
use crate::entity::item;
|
|
|
|
|
|
|
|
|
use crate::entity::character::SectionID;
|
|
|
|
|
|
|
|
|
use crate::ship::location::{ClientLocation, RoomLobby, MAX_ROOMS, ClientLocationError, GetNeighborError, GetClientsError, GetAreaError, RoomId};
|
|
|
|
|
|
|
|
|
use crate::ship::location::{ClientLocation, RoomLobby, ClientLocationError, RoomId};
|
|
|
|
|
|
|
|
|
use crate::ship::items;
|
|
|
use crate::ship::items;
|
|
|
use crate::ship::room;
|
|
|
use crate::ship::room;
|
|
|
use crate::ship::map::{MapsError, MapAreaError, MapArea};
|
|
|
|
|
|
|
|
|
use crate::ship::map::{MapsError, MapAreaError};
|
|
|
use crate::ship::packet::handler;
|
|
|
use crate::ship::packet::handler;
|
|
|
use crate::ship::shops::{WeaponShop, ToolShop, ArmorShop, WeaponShopItem, ToolShopItem, ArmorShopItem};
|
|
|
|
|
|
|
|
|
use crate::ship::shops::{WeaponShop, ToolShop, ArmorShop};
|
|
|
use crate::ship::trade::TradeState;
|
|
|
use crate::ship::trade::TradeState;
|
|
|
|
|
|
|
|
|
// TODO: remove once stuff settles down
|
|
|
// TODO: remove once stuff settles down
|
|
@ -56,16 +54,7 @@ pub enum ShipError { |
|
|
#[error("too many clients")]
|
|
|
#[error("too many clients")]
|
|
|
TooManyClients,
|
|
|
TooManyClients,
|
|
|
#[error("client error location {0}")]
|
|
|
#[error("client error location {0}")]
|
|
|
//ClientLocationError(#[from] ClientLocationError),
|
|
|
|
|
|
ClientLocationError(ClientLocationError),
|
|
|
ClientLocationError(ClientLocationError),
|
|
|
/*
|
|
|
|
|
|
#[error("get neighbor error {0}")]
|
|
|
|
|
|
GetNeighborError(#[from] GetNeighborError),
|
|
|
|
|
|
#[error("get clients error {0}")]
|
|
|
|
|
|
GetClientsError(#[from] GetClientsError),
|
|
|
|
|
|
#[error("get area error {0}")]
|
|
|
|
|
|
GetAreaError(#[from] GetAreaError),
|
|
|
|
|
|
*/
|
|
|
|
|
|
#[error("maps error {0}")]
|
|
|
#[error("maps error {0}")]
|
|
|
MapsError(#[from] MapsError),
|
|
|
MapsError(#[from] MapsError),
|
|
|
#[error("map area error {0}")]
|
|
|
#[error("map area error {0}")]
|
|
@ -89,9 +78,9 @@ pub enum ShipError { |
|
|
#[error("box already dropped item {0} {1}")]
|
|
|
#[error("box already dropped item {0} {1}")]
|
|
|
BoxAlreadyDroppedItem(ClientId, u16),
|
|
|
BoxAlreadyDroppedItem(ClientId, u16),
|
|
|
#[error("invalid quest category {0}")]
|
|
|
#[error("invalid quest category {0}")]
|
|
|
InvalidQuestCategory(u32),
|
|
|
|
|
|
|
|
|
InvalidQuestCategory(u16),
|
|
|
#[error("invalid quest {0}")]
|
|
|
#[error("invalid quest {0}")]
|
|
|
InvalidQuest(u32),
|
|
|
|
|
|
|
|
|
InvalidQuest(u16),
|
|
|
#[error("invalid quest filename {0}")]
|
|
|
#[error("invalid quest filename {0}")]
|
|
|
InvalidQuestFilename(String),
|
|
|
InvalidQuestFilename(String),
|
|
|
#[error("io error {0}")]
|
|
|
#[error("io error {0}")]
|
|
@ -118,24 +107,10 @@ pub enum ShipError { |
|
|
MessageError(#[from] crate::ship::packet::handler::direct_message::MessageError),
|
|
|
MessageError(#[from] crate::ship::packet::handler::direct_message::MessageError),
|
|
|
#[error("room creation error {0}")]
|
|
|
#[error("room creation error {0}")]
|
|
|
RoomCreationError(#[from] room::RoomCreationError),
|
|
|
RoomCreationError(#[from] room::RoomCreationError),
|
|
|
|
|
|
#[error("channel send error {0}")]
|
|
|
|
|
|
SendError(#[from] async_std::channel::SendError<ShipMessage>),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
impl From<ClientLocationError> for ShipError {
|
|
|
|
|
|
fn from(other: &ClientLocationError) -> ShipError {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
impl<I: Into<ClientLocationError>> Into<ShipError> for I {
|
|
|
|
|
|
fn into(other: I) -> ShipError {
|
|
|
|
|
|
ShipError::ClientLocationError(other.into())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
impl<I: Into<ClientLocationError>> From<I> for ShipError {
|
|
|
impl<I: Into<ClientLocationError>> From<I> for ShipError {
|
|
|
fn from(other: I) -> ShipError {
|
|
|
fn from(other: I) -> ShipError {
|
|
|
ShipError::ClientLocationError(other.into())
|
|
|
ShipError::ClientLocationError(other.into())
|
|
@ -420,45 +395,23 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
|
|
|
|
#[derive(Clone, Default)]
|
|
|
pub struct Block {
|
|
|
pub struct Block {
|
|
|
client_location: ClientLocation,
|
|
|
client_location: ClientLocation,
|
|
|
pub rooms: room::Rooms,
|
|
|
pub rooms: room::Rooms,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl Default for Block {
|
|
|
|
|
|
fn default() -> Block {
|
|
|
|
|
|
Block {
|
|
|
|
|
|
client_location: ClientLocation::default(),
|
|
|
|
|
|
rooms: room::Rooms::default(),
|
|
|
|
|
|
//rooms: core::array::from_fn(|_| Arc::new(RwLock::new(None))),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
impl Block {
|
|
|
|
|
|
fn with<F, T>(&self, func: F) -> T
|
|
|
|
|
|
where
|
|
|
|
|
|
T: Send,
|
|
|
|
|
|
F: FnOnce(&Block) -> T,
|
|
|
|
|
|
{
|
|
|
|
|
|
func(self)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
#[derive(Clone)]
|
|
|
pub struct Blocks(pub Vec<Block>);
|
|
|
pub struct Blocks(pub Vec<Block>);
|
|
|
|
|
|
|
|
|
impl Blocks {
|
|
|
impl Blocks {
|
|
|
async fn from_client(&mut self, id: ClientId, clients: &Clients) -> Result<&mut Block, ShipError> {
|
|
|
|
|
|
|
|
|
async fn get_from_client(&mut self, id: ClientId, clients: &Clients) -> Result<&mut Block, ShipError> {
|
|
|
let block = clients.with(id, |client| Box::pin(async move {
|
|
|
let block = clients.with(id, |client| Box::pin(async move {
|
|
|
client.block
|
|
|
client.block
|
|
|
})).await?;
|
|
|
})).await?;
|
|
|
self.0
|
|
|
self.0
|
|
|
.get_mut(block)
|
|
|
.get_mut(block)
|
|
|
.ok_or(ShipError::InvalidBlock(block))
|
|
|
|
|
|
|
|
|
.ok_or_else(|| ShipError::InvalidBlock(block))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
@ -477,7 +430,6 @@ pub struct ShipServerState<EG: EntityGateway + Clone + 'static> { |
|
|
|
|
|
|
|
|
auth_token: AuthToken,
|
|
|
auth_token: AuthToken,
|
|
|
ship_list: Vec<Ship>,
|
|
|
ship_list: Vec<Ship>,
|
|
|
//shipgate_sender: Option<Box<dyn Fn(ShipMessage) + Send + Sync>>,
|
|
|
|
|
|
shipgate_sender: Option<channel::Sender<ShipMessage>>,
|
|
|
shipgate_sender: Option<channel::Sender<ShipMessage>>,
|
|
|
trades: TradeState,
|
|
|
trades: TradeState,
|
|
|
}
|
|
|
}
|
|
@ -490,42 +442,42 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerState<EG> { |
|
|
async fn message(&mut self, id: ClientId, msg: Message) -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
|
|
|
async fn message(&mut self, id: ClientId, msg: Message) -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
|
|
|
Ok(match msg.msg {
|
|
|
Ok(match msg.msg {
|
|
|
GameMessage::RequestExp(request_exp) => {
|
|
|
GameMessage::RequestExp(request_exp) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
handler::message::request_exp(id, request_exp, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms).await?
|
|
|
handler::message::request_exp(id, request_exp, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerDropItem(player_drop_item) => {
|
|
|
GameMessage::PlayerDropItem(player_drop_item) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
handler::message::player_drop_item(id, player_drop_item, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await?
|
|
|
handler::message::player_drop_item(id, player_drop_item, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::DropCoordinates(drop_coordinates) => {
|
|
|
GameMessage::DropCoordinates(drop_coordinates) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::message::drop_coordinates(id, drop_coordinates, &block.client_location, &mut self.clients, &block.rooms).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::message::drop_coordinates(id, drop_coordinates, &block.client_location, &self.clients, &block.rooms).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerNoLongerHasItem(no_longer_has_item) => {
|
|
|
GameMessage::PlayerNoLongerHasItem(no_longer_has_item) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::message::no_longer_has_item(id, no_longer_has_item, &mut self.entity_gateway, &block.client_location, &mut self.clients, &mut self.item_state).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::message::no_longer_has_item(id, no_longer_has_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerChangedMap(_) | GameMessage::PlayerChangedMap2(_) | GameMessage::TellOtherPlayerMyLocation(_) |
|
|
|
GameMessage::PlayerChangedMap(_) | GameMessage::PlayerChangedMap2(_) | GameMessage::TellOtherPlayerMyLocation(_) |
|
|
|
GameMessage::PlayerWarpingToFloor(_) | GameMessage::PlayerTeleported(_) | GameMessage::PlayerStopped(_) |
|
|
|
GameMessage::PlayerWarpingToFloor(_) | GameMessage::PlayerTeleported(_) | GameMessage::PlayerStopped(_) |
|
|
|
GameMessage::PlayerLoadedIn(_) | GameMessage::PlayerWalking(_) | GameMessage::PlayerRunning(_) |
|
|
|
GameMessage::PlayerLoadedIn(_) | GameMessage::PlayerWalking(_) | GameMessage::PlayerRunning(_) |
|
|
|
GameMessage::PlayerWarped(_) | GameMessage::PlayerChangedFloor(_) | GameMessage::InitializeSpeechNpc(_) => {
|
|
|
GameMessage::PlayerWarped(_) | GameMessage::PlayerChangedFloor(_) | GameMessage::InitializeSpeechNpc(_) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::message::update_player_position(id, msg, &mut self.clients, &block.client_location, &block.rooms).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::message::update_player_position(id, msg, &self.clients, &block.client_location, &block.rooms).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::ChargeAttack(charge_attack) => {
|
|
|
GameMessage::ChargeAttack(charge_attack) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::message::charge_attack(id, charge_attack, &mut self.entity_gateway, &block.client_location, &mut self.clients, &mut self.item_state).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::message::charge_attack(id, charge_attack, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerUseItem(player_use_item) => {
|
|
|
GameMessage::PlayerUseItem(player_use_item) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::message::player_uses_item(id, player_use_item, &mut self.entity_gateway, &block.client_location, &mut self.clients, &mut self.item_state).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::message::player_uses_item(id, player_use_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerUsedMedicalCenter(player_used_medical_center) => {
|
|
|
GameMessage::PlayerUsedMedicalCenter(player_used_medical_center) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::message::player_used_medical_center(id, player_used_medical_center, &mut self.entity_gateway, &block.client_location, &mut self.clients, &mut self.item_state).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::message::player_used_medical_center(id, player_used_medical_center, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerFeedMag(player_feed_mag) => {
|
|
|
GameMessage::PlayerFeedMag(player_feed_mag) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
handler::message::player_feed_mag(id, player_feed_mag, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
|
|
|
handler::message::player_feed_mag(id, player_feed_mag, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerEquipItem(player_equip_item) => {
|
|
|
GameMessage::PlayerEquipItem(player_equip_item) => {
|
|
@ -538,11 +490,11 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerState<EG> { |
|
|
handler::message::player_sorts_items(id, sort_items, &mut self.entity_gateway, &self.clients, &mut self.item_state).await?
|
|
|
handler::message::player_sorts_items(id, sort_items, &mut self.entity_gateway, &self.clients, &mut self.item_state).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::PlayerSoldItem(player_sold_item) => {
|
|
|
GameMessage::PlayerSoldItem(player_sold_item) => {
|
|
|
handler::message::player_sells_item(id, player_sold_item, &mut self.entity_gateway, &mut self.clients, &mut self.item_state).await?
|
|
|
|
|
|
|
|
|
handler::message::player_sells_item(id, player_sold_item, &mut self.entity_gateway, &self.clients, &mut self.item_state).await?
|
|
|
},
|
|
|
},
|
|
|
_ => {
|
|
|
_ => {
|
|
|
let cmsg = msg.clone();
|
|
|
let cmsg = msg.clone();
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
block.client_location.get_client_neighbors(id).await.unwrap().into_iter()
|
|
|
block.client_location.get_client_neighbors(id).await.unwrap().into_iter()
|
|
|
.map(move |client| {
|
|
|
.map(move |client| {
|
|
|
(client.client, SendShipPacket::Message(cmsg.clone()))
|
|
|
(client.client, SendShipPacket::Message(cmsg.clone()))
|
|
@ -554,7 +506,7 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerState<EG> { |
|
|
|
|
|
|
|
|
async fn direct_message(&mut self, id: ClientId, msg: DirectMessage) -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
|
|
|
async fn direct_message(&mut self, id: ClientId, msg: DirectMessage) -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
|
|
|
let target = msg.flag;
|
|
|
let target = msg.flag;
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
Ok(match msg.msg {
|
|
|
Ok(match msg.msg {
|
|
|
GameMessage::GuildcardSend(guildcard_send) => {
|
|
|
GameMessage::GuildcardSend(guildcard_send) => {
|
|
|
handler::direct_message::guildcard_send(id, guildcard_send, target, &block.client_location, &self.clients).await?
|
|
|
handler::direct_message::guildcard_send(id, guildcard_send, target, &block.client_location, &self.clients).await?
|
|
@ -575,7 +527,7 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerState<EG> { |
|
|
handler::direct_message::bank_interaction(id, bank_interaction, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
|
|
|
handler::direct_message::bank_interaction(id, bank_interaction, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::ShopRequest(shop_request) => {
|
|
|
GameMessage::ShopRequest(shop_request) => {
|
|
|
handler::direct_message::shop_request(id, shop_request, &block.client_location, &self.clients, &block.rooms, &mut self.shops).await?
|
|
|
|
|
|
|
|
|
handler::direct_message::shop_request(id, shop_request, &block.client_location, &self.clients, &block.rooms, &self.shops).await?
|
|
|
},
|
|
|
},
|
|
|
GameMessage::BuyItem(buy_item) => {
|
|
|
GameMessage::BuyItem(buy_item) => {
|
|
|
handler::direct_message::buy_item(id, buy_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
|
|
|
handler::direct_message::buy_item(id, buy_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
|
|
@ -630,11 +582,6 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> { |
|
|
})).await {
|
|
|
})).await {
|
|
|
self.entity_gateway.set_character_playtime(&char_id, char_playtime).await?;
|
|
|
self.entity_gateway.set_character_playtime(&char_id, char_playtime).await?;
|
|
|
}
|
|
|
}
|
|
|
/*
|
|
|
|
|
|
if let Some(client) = self.clients.get_mut(&id) {
|
|
|
|
|
|
client.update_playtime();
|
|
|
|
|
|
self.entity_gateway.set_character_playtime(&client.character.id, client.character.playtime).await?;
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
Ok(match pkt {
|
|
|
Ok(match pkt {
|
|
|
RecvShipPacket::Login(login) => {
|
|
|
RecvShipPacket::Login(login) => {
|
|
@ -645,14 +592,14 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> { |
|
|
.collect()
|
|
|
.collect()
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::QuestDetailRequest(questdetailrequest) => {
|
|
|
RecvShipPacket::QuestDetailRequest(questdetailrequest) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
match questdetailrequest.menu {
|
|
|
match questdetailrequest.menu {
|
|
|
QUEST_SELECT_MENU_ID => handler::quest::quest_detail(id, questdetailrequest, &block.client_location, &mut block.rooms).await?,
|
|
|
|
|
|
|
|
|
QUEST_SELECT_MENU_ID => handler::quest::quest_detail(id, questdetailrequest, &block.client_location, &block.rooms).await?,
|
|
|
_ => unreachable!(),
|
|
|
_ => unreachable!(),
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::MenuSelect(menuselect) => {
|
|
|
RecvShipPacket::MenuSelect(menuselect) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
match menuselect.menu {
|
|
|
match menuselect.menu {
|
|
|
SHIP_MENU_ID => {
|
|
|
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().into_iter().flatten();
|
|
@ -664,73 +611,39 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> { |
|
|
let select_block = handler::lobby::block_selected(id, menuselect, &self.clients, &self.item_state).await?.into_iter();
|
|
|
let select_block = handler::lobby::block_selected(id, menuselect, &self.clients, &self.item_state).await?.into_iter();
|
|
|
leave_lobby.chain(select_block).collect()
|
|
|
leave_lobby.chain(select_block).collect()
|
|
|
}
|
|
|
}
|
|
|
ROOM_MENU_ID => handler::room::join_room(id, menuselect, &mut block.client_location, &self.clients, &mut self.item_state, &mut block.rooms).await?,
|
|
|
|
|
|
QUEST_CATEGORY_MENU_ID => handler::quest::select_quest_category(id, menuselect, &block.client_location, &mut block.rooms).await?,
|
|
|
|
|
|
|
|
|
ROOM_MENU_ID => handler::room::join_room(id, menuselect, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms).await?,
|
|
|
|
|
|
QUEST_CATEGORY_MENU_ID => handler::quest::select_quest_category(id, menuselect, &block.client_location, &block.rooms).await?,
|
|
|
_ => unreachable!(),
|
|
|
_ => unreachable!(),
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::QuestMenuSelect(questmenuselect) => {
|
|
|
RecvShipPacket::QuestMenuSelect(questmenuselect) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::quest::player_chose_quest(id, questmenuselect, &mut self.clients, &block.client_location, &mut block.rooms).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::quest::player_chose_quest(id, questmenuselect, &self.clients, &block.client_location, &block.rooms).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::MenuDetail(menudetail) => {
|
|
|
RecvShipPacket::MenuDetail(menudetail) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::lobby::get_room_tab_info(id, menudetail, &mut block.client_location, &self.clients, &mut block.rooms).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::lobby::get_room_tab_info(id, menudetail, &mut block.client_location, &self.clients).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::RoomPasswordReq(room_password_req) => {
|
|
|
RecvShipPacket::RoomPasswordReq(room_password_req) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
let password = room_password_req.password;
|
|
|
|
|
|
let correct_password = block.rooms.with(RoomId(room_password_req.item as usize), |room| Box::pin(async move {
|
|
|
|
|
|
password == room.password
|
|
|
|
|
|
})).await?;
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let room_password = block.rooms.with(RoomId(room_password_req.item as usize), |room| Box::pin(async move {
|
|
|
let room_password = block.rooms.with(RoomId(room_password_req.item as usize), |room| Box::pin(async move {
|
|
|
room.password
|
|
|
room.password
|
|
|
})).await?;
|
|
|
})).await?;
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
let correct_password = room_password_req.password == block.rooms
|
|
|
|
|
|
.get(RoomId(room_password_req.item as usize))
|
|
|
|
|
|
.await
|
|
|
|
|
|
.map(|room| room.password)
|
|
|
|
|
|
.unwrap_or_else(false);
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
//if correct_password {
|
|
|
|
|
|
if room_password_req.password == room_password {
|
|
|
if room_password_req.password == room_password {
|
|
|
let menuselect = MenuSelect {
|
|
|
let menuselect = MenuSelect {
|
|
|
menu: room_password_req.menu,
|
|
|
menu: room_password_req.menu,
|
|
|
item: room_password_req.item,
|
|
|
item: room_password_req.item,
|
|
|
};
|
|
|
};
|
|
|
handler::room::join_room(id, menuselect, &mut block.client_location, &mut self.clients, &mut self.item_state, &mut block.rooms).await?
|
|
|
|
|
|
|
|
|
handler::room::join_room(id, menuselect, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms).await?
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
else {
|
|
|
vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("Incorrect password".into())))]
|
|
|
vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("Incorrect password".into())))]
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
if room_password_req.password == block.rooms[room_password_req.item as usize]
|
|
|
|
|
|
.read()
|
|
|
|
|
|
.await
|
|
|
|
|
|
.as_ref()
|
|
|
|
|
|
.ok_or(ShipError::InvalidRoom(room_password_req.item))?
|
|
|
|
|
|
.password {
|
|
|
|
|
|
let menuselect = MenuSelect {
|
|
|
|
|
|
menu: room_password_req.menu,
|
|
|
|
|
|
item: room_password_req.item,
|
|
|
|
|
|
};
|
|
|
|
|
|
handler::room::join_room(id, &menuselect, &mut block.client_location, &mut self.clients, &mut self.item_state, &mut block.rooms).await?
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("Incorrect password".into())))].into_iter())
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::CharData(chardata) => {
|
|
|
RecvShipPacket::CharData(chardata) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
handler::lobby::send_player_to_lobby(id, chardata, &mut block.client_location, &self.clients, &self.item_state).await?
|
|
|
handler::lobby::send_player_to_lobby(id, chardata, &mut block.client_location, &self.clients, &self.item_state).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::Message(msg) => {
|
|
|
RecvShipPacket::Message(msg) => {
|
|
@ -740,65 +653,65 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> { |
|
|
self.direct_message(id, msg).await?
|
|
|
self.direct_message(id, msg).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::PlayerChat(msg) => {
|
|
|
RecvShipPacket::PlayerChat(msg) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
handler::communication::player_chat(id, msg, &block.client_location, &self.clients).await?
|
|
|
handler::communication::player_chat(id, msg, &block.client_location, &self.clients).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::CreateRoom(create_room) => {
|
|
|
RecvShipPacket::CreateRoom(create_room) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::room::create_room(id, create_room, &mut block.client_location, &mut self.clients, &mut self.item_state, &mut block.rooms).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::room::create_room(id, create_room, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::RoomNameRequest(_req) => {
|
|
|
RecvShipPacket::RoomNameRequest(_req) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
handler::room::room_name_request(id, &block.client_location, &block.rooms).await?
|
|
|
handler::room::room_name_request(id, &block.client_location, &block.rooms).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::UpdateConfig(pkt) => {
|
|
|
RecvShipPacket::UpdateConfig(pkt) => {
|
|
|
handler::settings::update_config(id, pkt, &mut self.clients, &mut self.entity_gateway).await?
|
|
|
|
|
|
|
|
|
handler::settings::update_config(id, pkt, &self.clients, &mut self.entity_gateway).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::ViewInfoboardRequest(_pkt) => {
|
|
|
RecvShipPacket::ViewInfoboardRequest(_pkt) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
handler::communication::request_infoboard(id, &block.client_location, &self.clients).await?
|
|
|
handler::communication::request_infoboard(id, &block.client_location, &self.clients).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::WriteInfoboard(pkt) => {
|
|
|
RecvShipPacket::WriteInfoboard(pkt) => {
|
|
|
handler::communication::write_infoboard(id, pkt, &self.clients, &mut self.entity_gateway).await?
|
|
|
handler::communication::write_infoboard(id, pkt, &self.clients, &mut self.entity_gateway).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::RoomListRequest(_req) => {
|
|
|
RecvShipPacket::RoomListRequest(_req) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
handler::room::request_room_list(id, &block.client_location, &block.rooms).await
|
|
|
handler::room::request_room_list(id, &block.client_location, &block.rooms).await
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::Like62ButCooler(cool62) => {
|
|
|
RecvShipPacket::Like62ButCooler(cool62) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::room::cool_62(id, cool62, &block.client_location).await
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::room::cool_62(id, cool62, &block.client_location).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::ClientCharacterData(_) => {
|
|
|
RecvShipPacket::ClientCharacterData(_) => {
|
|
|
// TOOD: validate this in some way?
|
|
|
// TOOD: validate this in some way?
|
|
|
Vec::new()
|
|
|
Vec::new()
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::DoneBursting(_) => {
|
|
|
RecvShipPacket::DoneBursting(_) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::room::done_bursting(id, &block.client_location, &mut block.rooms).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::room::done_bursting(id, &block.client_location, &block.rooms).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::DoneBursting2(_) => {
|
|
|
RecvShipPacket::DoneBursting2(_) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::room::done_bursting(id, &block.client_location, &mut block.rooms).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::room::done_bursting(id, &block.client_location, &block.rooms).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::LobbySelect(pkt) => {
|
|
|
RecvShipPacket::LobbySelect(pkt) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::lobby::change_lobby(id, pkt.lobby, &mut block.client_location, &self.clients, &mut self.item_state, &mut block.rooms, &mut self.entity_gateway).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::lobby::change_lobby(id, pkt.lobby, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms, &mut self.entity_gateway).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::RequestQuestList(rql) => {
|
|
|
RecvShipPacket::RequestQuestList(rql) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::quest::send_quest_category_list(id, rql, &block.client_location, &mut block.rooms).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::quest::send_quest_category_list(id, rql, &block.client_location, &block.rooms).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::QuestFileRequest(quest_file_request) => {
|
|
|
RecvShipPacket::QuestFileRequest(quest_file_request) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
handler::quest::quest_file_request(id, quest_file_request, &block.client_location, &mut block.rooms).await?
|
|
|
handler::quest::quest_file_request(id, quest_file_request, &block.client_location, &mut block.rooms).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::QuestChunkAck(quest_chunk_ack) => {
|
|
|
RecvShipPacket::QuestChunkAck(quest_chunk_ack) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::quest::quest_chunk_ack(id, quest_chunk_ack, &block.client_location, &mut block.rooms).await?
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
|
|
handler::quest::quest_chunk_ack(id, quest_chunk_ack, &block.client_location, &block.rooms).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::DoneLoadingQuest(_) => {
|
|
|
RecvShipPacket::DoneLoadingQuest(_) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
handler::quest::done_loading_quest(id, &self.clients, &block.client_location).await?
|
|
|
handler::quest::done_loading_quest(id, &self.clients, &block.client_location).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::FullCharacterData(_full_character_data) => {
|
|
|
RecvShipPacket::FullCharacterData(_full_character_data) => {
|
|
@ -814,11 +727,11 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> { |
|
|
handler::ship::block_list(id, &self.name, self.blocks.0.len())
|
|
|
handler::ship::block_list(id, &self.name, self.blocks.0.len())
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::ItemsToTrade(items_to_trade) => {
|
|
|
RecvShipPacket::ItemsToTrade(items_to_trade) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
handler::trade::items_to_trade(id, items_to_trade, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await?
|
|
|
handler::trade::items_to_trade(id, items_to_trade, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::TradeConfirmed(_) => {
|
|
|
RecvShipPacket::TradeConfirmed(_) => {
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
handler::trade::trade_confirmed(id, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await?
|
|
|
handler::trade::trade_confirmed(id, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await?
|
|
|
},
|
|
|
},
|
|
|
RecvShipPacket::KeyboardConfig(keyboard_config) => {
|
|
|
RecvShipPacket::KeyboardConfig(keyboard_config) => {
|
|
@ -832,7 +745,7 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> { |
|
|
|
|
|
|
|
|
async fn on_disconnect(&mut self, id: ClientId) -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
|
|
|
async fn on_disconnect(&mut self, id: ClientId) -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
|
|
|
//let client = self.clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
//let client = self.clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
let block = self.blocks.from_client(id, &self.clients).await?;
|
|
|
|
|
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
let area_client = block.client_location.get_local_client(id).await?;
|
|
|
let area_client = block.client_location.get_local_client(id).await?;
|
|
|
let neighbors = block.client_location.get_client_neighbors(id).await?;
|
|
|
let neighbors = block.client_location.get_client_neighbors(id).await?;
|
|
|
|
|
|
|
|
@ -896,7 +809,7 @@ impl<EG: EntityGateway + Clone> InterserverActor for ShipServerState<EG> { |
|
|
]
|
|
|
]
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn on_action(&mut self, id: ServerId, msg: Self::RecvMessage) -> Result<Vec<(ServerId, Self::SendMessage)>, Self::Error> {
|
|
|
|
|
|
|
|
|
async fn on_action(&mut self, _id: ServerId, msg: Self::RecvMessage) -> Result<Vec<(ServerId, Self::SendMessage)>, Self::Error> {
|
|
|
match msg {
|
|
|
match msg {
|
|
|
LoginMessage::SendMail{..} => {
|
|
|
LoginMessage::SendMail{..} => {
|
|
|
Ok(Vec::new())
|
|
|
Ok(Vec::new())
|
|
|