|
|
@ -46,6 +46,7 @@ pub enum RecvShipPacket { |
|
|
|
UpdateConfig(UpdateConfig),
|
|
|
|
ViewInfoboardRequest(ViewInfoboardRequest),
|
|
|
|
WriteInfoboard(WriteInfoboard),
|
|
|
|
RoomListRequest(RoomListRequest),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RecvServerPacket for RecvShipPacket {
|
|
|
@ -62,6 +63,7 @@ impl RecvServerPacket for RecvShipPacket { |
|
|
|
0x7ED => Ok(RecvShipPacket::UpdateConfig(UpdateConfig::from_bytes(data)?)),
|
|
|
|
0xD8 => Ok(RecvShipPacket::ViewInfoboardRequest(ViewInfoboardRequest::from_bytes(data)?)),
|
|
|
|
0xD9 => Ok(RecvShipPacket::WriteInfoboard(WriteInfoboard::from_bytes(data)?)),
|
|
|
|
0x08 => Ok(RecvShipPacket::RoomListRequest(RoomListRequest::from_bytes(data)?)),
|
|
|
|
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -86,6 +88,7 @@ pub enum SendShipPacket { |
|
|
|
LeaveRoom(LeaveRoom),
|
|
|
|
RoomNameResponse(RoomNameResponse),
|
|
|
|
ViewInfoboardResponse(ViewInfoboardResponse),
|
|
|
|
RoomListResponse(RoomListResponse),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SendServerPacket for SendShipPacket {
|
|
|
@ -108,11 +111,11 @@ impl SendServerPacket for SendShipPacket { |
|
|
|
SendShipPacket::LeaveRoom(pkt) => pkt.as_bytes(),
|
|
|
|
SendShipPacket::RoomNameResponse(pkt) => pkt.as_bytes(),
|
|
|
|
SendShipPacket::ViewInfoboardResponse(pkt) => pkt.as_bytes(),
|
|
|
|
SendShipPacket::RoomListResponse(pkt) => pkt.as_bytes(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct ClientState {
|
|
|
|
user: UserAccount,
|
|
|
|
settings: UserSettings,
|
|
|
@ -137,12 +140,6 @@ impl ClientState { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct ShipServerState<EG: EntityGateway> {
|
|
|
|
entity_gateway: EG,
|
|
|
|
clients: HashMap<ClientId, ClientState>,
|
|
|
@ -439,8 +436,32 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
|
self.entity_gateway.set_character(&client.character);
|
|
|
|
Box::new(None.into_iter())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn request_room_list(&mut self, id: ClientId, request_roomlist: &RoomListRequest) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
|
|
|
let active_room_list = self.rooms.iter()
|
|
|
|
.enumerate()
|
|
|
|
.filter_map(|(i, r)| {
|
|
|
|
r.as_ref().map(|room| {
|
|
|
|
RoomList {
|
|
|
|
menu_id: 1,
|
|
|
|
item_id: i as u32,
|
|
|
|
difficulty: 0x22,//room.mode.difficulty().into(),
|
|
|
|
players: room.players,
|
|
|
|
name: libpso::utf8_to_utf16_array!(room.name, 16),
|
|
|
|
episode: 0x40,//room.mode.episode().into(),
|
|
|
|
flags: room.mode.get_flags(),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
Box::new(vec![(id, SendShipPacket::RoomListResponse(RoomListResponse {
|
|
|
|
menu_id: 1,
|
|
|
|
title_id: 1,
|
|
|
|
zero: 0,
|
|
|
|
menu_title: libpso::utf8_to_utf16_array!("base_room", 17),
|
|
|
|
room_list: active_room_list.collect()
|
|
|
|
}))].into_iter())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
|
|
|
|
type SendPacket = SendShipPacket;
|
|
|
@ -503,6 +524,10 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> { |
|
|
|
RecvShipPacket::WriteInfoboard(pkt) => {
|
|
|
|
self.write_infoboard(id, pkt)
|
|
|
|
},
|
|
|
|
|
|
|
|
RecvShipPacket::RoomListRequest(pkt) => {
|
|
|
|
self.request_room_list(id, pkt)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|