|
|
@ -51,6 +51,7 @@ pub enum ShipError { |
|
|
|
pub enum RecvShipPacket {
|
|
|
|
Login(Login),
|
|
|
|
MenuSelect(MenuSelect),
|
|
|
|
RoomPasswordReq(RoomPasswordReq),
|
|
|
|
CharData(CharData),
|
|
|
|
Message(Message),
|
|
|
|
DirectMessage(DirectMessage),
|
|
|
@ -71,7 +72,11 @@ impl RecvServerPacket for RecvShipPacket { |
|
|
|
fn from_bytes(data: &[u8]) -> Result<RecvShipPacket, PacketParseError> {
|
|
|
|
match u16::from_le_bytes([data[2], data[3]]) {
|
|
|
|
0x93 => Ok(RecvShipPacket::Login(Login::from_bytes(data)?)),
|
|
|
|
0x10 => Ok(RecvShipPacket::MenuSelect(MenuSelect::from_bytes(data)?)),
|
|
|
|
0x10 => match data[0] {
|
|
|
|
16 => Ok(RecvShipPacket::MenuSelect(MenuSelect::from_bytes(data)?)),
|
|
|
|
48 => Ok(RecvShipPacket::RoomPasswordReq(RoomPasswordReq::from_bytes(data)?)),
|
|
|
|
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec())),
|
|
|
|
},
|
|
|
|
0x61 => Ok(RecvShipPacket::CharData(CharData::from_bytes(data)?)),
|
|
|
|
0x60 => Ok(RecvShipPacket::Message(Message::from_bytes(data)?)),
|
|
|
|
0x62 => Ok(RecvShipPacket::DirectMessage(DirectMessage::from_bytes(data)?)),
|
|
|
@ -265,6 +270,20 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> { |
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
RecvShipPacket::RoomPasswordReq(room_password_req) => {
|
|
|
|
if room_password_req.password == self.rooms[room_password_req.item as usize].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 self.client_location, &mut self.clients, &self.level_table, &mut self.rooms)?
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("Incorrect password".into())))].into_iter())
|
|
|
|
}
|
|
|
|
},
|
|
|
|
RecvShipPacket::CharData(chardata) => {
|
|
|
|
Box::new(handler::lobby::send_player_to_lobby(id, chardata, &mut self.client_location, &self.clients, &self.level_table)?.into_iter())
|
|
|
|
},
|
|
|
|