|
|
@ -9,7 +9,7 @@ use rand::Rng; |
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
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::{PacketParseError, PSOPacket};
|
|
|
|
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::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::room;
|
|
|
|
use crate::ship::map::{MapsError, MapAreaError, MapArea};
|
|
|
|
use crate::ship::map::{MapsError, MapAreaError};
|
|
|
|
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;
|
|
|
|
|
|
|
|
// TODO: remove once stuff settles down
|
|
|
@ -56,16 +54,7 @@ pub enum ShipError { |
|
|
|
#[error("too many clients")]
|
|
|
|
TooManyClients,
|
|
|
|
#[error("client error location {0}")]
|
|
|
|
//ClientLocationError(#[from] 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}")]
|
|
|
|
MapsError(#[from] MapsError),
|
|
|
|
#[error("map area error {0}")]
|
|
|
@ -89,9 +78,9 @@ pub enum ShipError { |
|
|
|
#[error("box already dropped item {0} {1}")]
|
|
|
|
BoxAlreadyDroppedItem(ClientId, u16),
|
|
|
|
#[error("invalid quest category {0}")]
|
|
|
|
InvalidQuestCategory(u32),
|
|
|
|
InvalidQuestCategory(u16),
|
|
|
|
#[error("invalid quest {0}")]
|
|
|
|
InvalidQuest(u32),
|
|
|
|
InvalidQuest(u16),
|
|
|
|
#[error("invalid quest filename {0}")]
|
|
|
|
InvalidQuestFilename(String),
|
|
|
|
#[error("io error {0}")]
|
|
|
@ -118,24 +107,10 @@ pub enum ShipError { |
|
|
|
MessageError(#[from] crate::ship::packet::handler::direct_message::MessageError),
|
|
|
|
#[error("room creation error {0}")]
|
|
|
|
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 {
|
|
|
|
fn from(other: I) -> ShipError {
|
|
|
|
ShipError::ClientLocationError(other.into())
|
|
|
@ -420,45 +395,23 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> { |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
#[derive(Clone, Default)]
|
|
|
|
pub struct Block {
|
|
|
|
client_location: ClientLocation,
|
|
|
|
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)]
|
|
|
|
pub struct Blocks(pub Vec<Block>);
|
|
|
|
|
|
|
|
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 {
|
|
|
|
client.block
|
|
|
|
})).await?;
|
|
|
|
self.0
|
|
|
|
.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,
|
|
|
|
ship_list: Vec<Ship>,
|
|
|
|
//shipgate_sender: Option<Box<dyn Fn(ShipMessage) + Send + Sync>>,
|
|
|
|
shipgate_sender: Option<channel::Sender<ShipMessage>>,
|
|
|
|
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> {
|
|
|
|
Ok(match msg.msg {
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
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) => {
|
|
|
|
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::PlayerWarpingToFloor(_) | GameMessage::PlayerTeleported(_) | GameMessage::PlayerStopped(_) |
|
|
|
|
GameMessage::PlayerLoadedIn(_) | GameMessage::PlayerWalking(_) | GameMessage::PlayerRunning(_) |
|
|
|
|
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) => {
|
|
|
|
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) => {
|
|
|
|
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) => {
|
|
|
|
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) => {
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
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 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()
|
|
|
|
.map(move |client| {
|
|
|
|
(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> {
|
|
|
|
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 {
|
|
|
|
GameMessage::GuildcardSend(guildcard_send) => {
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
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) => {
|
|
|
|
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 {
|
|
|
|
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 {
|
|
|
|
RecvShipPacket::Login(login) => {
|
|
|
@ -645,14 +592,14 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> { |
|
|
|
.collect()
|
|
|
|
},
|
|
|
|
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 {
|
|
|
|
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!(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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 {
|
|
|
|
SHIP_MENU_ID => {
|
|
|
|
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();
|
|
|
|
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!(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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) => {
|
|
|
|
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) => {
|
|
|
|
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 {
|
|
|
|
room.password
|
|
|
|
})).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 {
|
|
|
|
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?
|
|
|
|
handler::room::join_room(id, menuselect, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms).await?
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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) => {
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
RecvShipPacket::Message(msg) => {
|
|
|
@ -740,65 +653,65 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> { |
|
|
|
self.direct_message(id, msg).await?
|
|
|
|
},
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
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) => {
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
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) => {
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
RecvShipPacket::WriteInfoboard(pkt) => {
|
|
|
|
handler::communication::write_infoboard(id, pkt, &self.clients, &mut self.entity_gateway).await?
|
|
|
|
},
|
|
|
|
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
|
|
|
|
},
|
|
|
|
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(_) => {
|
|
|
|
// TOOD: validate this in some way?
|
|
|
|
Vec::new()
|
|
|
|
},
|
|
|
|
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(_) => {
|
|
|
|
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) => {
|
|
|
|
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) => {
|
|
|
|
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) => {
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
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(_) => {
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
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())
|
|
|
|
},
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
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?
|
|
|
|
},
|
|
|
|
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> {
|
|
|
|
//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 neighbors = block.client_location.get_client_neighbors(id).await?;
|
|
|
|
|
|
|
@ -886,7 +799,7 @@ impl<EG: EntityGateway + Clone> InterserverActor for ShipServerState<EG> { |
|
|
|
async fn on_connect(&mut self, id: ServerId) -> Vec<(ServerId, Self::SendMessage)> {
|
|
|
|
vec![
|
|
|
|
(id, ShipMessage::Authenticate(self.auth_token.clone())),
|
|
|
|
(id, ShipMessage::NewShip(Ship {
|
|
|
|
(id, ShipMessage::NewShip(Ship {
|
|
|
|
name: self.name.clone(),
|
|
|
|
ip: self.ip,
|
|
|
|
port: self.port,
|
|
|
@ -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 {
|
|
|
|
LoginMessage::SendMail{..} => {
|
|
|
|
Ok(Vec::new())
|
|
|
|