@ -42,6 +42,57 @@ pub const SHIP_PORT: u16 = 23423;
pub const QUEST_CATEGORY_MENU_ID : u32 = 0xA2 ;
pub const QUEST_SELECT_MENU_ID : u32 = 0xA3 ;
#[ derive(Clone, Copy) ]
pub enum ShipEvent {
None ,
Christmas ,
Valentines ,
Easter ,
Halloween ,
Sonic ,
NewYear ,
Summer ,
White ,
Wedding ,
Fall ,
Spring ,
Summer2 ,
Spring2 ,
}
impl From < ShipEvent > for u32 {
fn from ( other : ShipEvent ) -> u32 {
u16 ::from ( other ) as u32
}
}
impl From < ShipEvent > for u16 {
fn from ( other : ShipEvent ) -> u16 {
u8 ::from ( other ) as u16
}
}
impl From < ShipEvent > for u8 {
fn from ( other : ShipEvent ) -> u8 {
match other {
ShipEvent ::None = > 0 ,
ShipEvent ::Christmas = > 1 ,
ShipEvent ::Valentines = > 3 ,
ShipEvent ::Easter = > 4 ,
ShipEvent ::Halloween = > 5 ,
ShipEvent ::Sonic = > 6 ,
ShipEvent ::NewYear = > 7 ,
ShipEvent ::Summer = > 8 ,
ShipEvent ::White = > 9 ,
ShipEvent ::Wedding = > 10 ,
ShipEvent ::Fall = > 11 ,
ShipEvent ::Spring = > 12 ,
ShipEvent ::Summer2 = > 13 ,
ShipEvent ::Spring2 = > 14 ,
}
}
}
#[ derive(Error, Debug) ]
pub enum ShipError {
@ -240,6 +291,7 @@ pub enum SendShipPacket {
AcknowledgeTrade ( AcknowledgeTrade ) ,
CancelTrade ( CancelTrade ) ,
TradeSuccessful ( TradeSuccessful ) ,
LobbyEvent ( LobbyEvent ) ,
}
impl SendServerPacket for SendShipPacket {
@ -282,6 +334,7 @@ impl SendServerPacket for SendShipPacket {
SendShipPacket ::AcknowledgeTrade ( pkt ) = > pkt . as_bytes ( ) ,
SendShipPacket ::CancelTrade ( pkt ) = > pkt . as_bytes ( ) ,
SendShipPacket ::TradeSuccessful ( pkt ) = > pkt . as_bytes ( ) ,
SendShipPacket ::LobbyEvent ( pkt ) = > pkt . as_bytes ( ) ,
}
}
}
@ -321,6 +374,7 @@ pub struct ShipServerStateBuilder<EG: EntityGateway + Clone + 'static> {
ip : Option < Ipv4Addr > ,
port : Option < u16 > ,
auth_token : Option < AuthToken > ,
event : Option < ShipEvent > ,
num_blocks : usize ,
}
@ -332,6 +386,7 @@ impl<EG: EntityGateway + Clone + 'static> Default for ShipServerStateBuilder<EG>
ip : None ,
port : None ,
auth_token : None ,
event : None ,
num_blocks : 2 ,
}
}
@ -368,6 +423,12 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> {
self
}
#[ must_use ]
pub fn event ( mut self , event : ShipEvent ) -> ShipServerStateBuilder < EG > {
self . event = Some ( event ) ;
self
}
#[ must_use ]
pub fn blocks ( mut self , num_blocks : usize ) -> ShipServerStateBuilder < EG > {
self . num_blocks = num_blocks ;
@ -385,6 +446,7 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> {
port : self . port . unwrap_or ( SHIP_PORT ) ,
shops : ItemShops ::default ( ) ,
blocks : Blocks ( blocks ) ,
event : self . event . unwrap_or ( ShipEvent ::None ) ,
auth_token : self . auth_token . unwrap_or_else ( | | AuthToken ( "" . into ( ) ) ) ,
ship_list : Vec ::new ( ) ,
@ -424,6 +486,7 @@ pub struct ShipServerState<EG: EntityGateway + Clone + 'static> {
item_state : items ::state ::ItemState ,
shops : ItemShops ,
pub blocks : Blocks ,
event : ShipEvent ,
ip : Ipv4Addr ,
port : u16 ,
@ -611,14 +674,14 @@ 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 , & block . rooms ) . await ? ,
ROOM_MENU_ID = > handler ::room ::join_room ( id , menuselect , & mut block . client_location , & self . clients , & mut self . item_state , & block . rooms , self . event ) . 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 . get_from_client ( id , & self . clients ) . await ? ;
handler ::quest ::player_chose_quest ( id , questmenuselect , & self . clients , & block . client_location , & block . rooms ) . await ?
handler ::quest ::player_chose_quest ( id , questmenuselect , & self . clients , & block . client_location , & block . rooms , self . event ) . await ?
} ,
RecvShipPacket ::MenuDetail ( menudetail ) = > {
let block = self . blocks . get_from_client ( id , & self . clients ) . await ? ;
@ -636,7 +699,7 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> {
menu : room_password_req . menu ,
item : room_password_req . item ,
} ;
handler ::room ::join_room ( id , menuselect , & mut block . client_location , & self . clients , & mut self . item_state , & block . rooms ) . await ?
handler ::room ::join_room ( id , menuselect , & mut block . client_location , & self . clients , & mut self . item_state , & block . rooms , self . event ) . await ?
}
else {
vec ! [ ( id , SendShipPacket ::SmallDialog ( SmallDialog ::new ( "Incorrect password" . into ( ) ) ) ) ]
@ -644,7 +707,7 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> {
} ,
RecvShipPacket ::CharData ( chardata ) = > {
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 , self . event ) . await ?
} ,
RecvShipPacket ::Message ( msg ) = > {
self . message ( id , msg ) . await ?
@ -658,7 +721,7 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> {
} ,
RecvShipPacket ::CreateRoom ( create_room ) = > {
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 ?
handler ::room ::create_room ( id , create_room , & mut block . client_location , & self . clients , & mut self . item_state , & block . rooms , self . event ) . await ?
} ,
RecvShipPacket ::RoomNameRequest ( _req ) = > {
let block = self . blocks . get_from_client ( id , & self . clients ) . await ? ;
@ -696,7 +759,7 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> {
} ,
RecvShipPacket ::LobbySelect ( pkt ) = > {
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 ?
handler ::lobby ::change_lobby ( id , pkt . lobby , & mut block . client_location , & self . clients , & mut self . item_state , & block . rooms , & mut self . entity_gateway , self . event ) . await ?
} ,
RecvShipPacket ::RequestQuestList ( rql ) = > {
let block = self . blocks . get_from_client ( id , & self . clients ) . await ? ;
@ -744,7 +807,6 @@ 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 . 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 ? ;
@ -763,17 +825,6 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> {
}
} ;
/*
if let Some ( shipgate_sender ) = self . shipgate_sender . as_ref ( ) {
shipgate_sender . send ( ShipMessage ::RemoveUser ( client . user . id ) ) . await ;
}
block . client_location . remove_client_from_area ( id ) . await ;
self . clients . with ( id , | client | Box ::pin ( async move {
self . item_state . remove_character_from_room ( & client . character ) . await
} ) ) . await ? ;
* /
if let Some ( mut client ) = self . clients . remove ( & id ) . await {
client . user . at_ship = false ;
self . entity_gateway . save_user ( & client . user ) . await ;