|
@ -9,6 +9,7 @@ use libpso::packet::messages::*; |
|
|
use libpso::{PacketParseError, PSOPacket};
|
|
|
use libpso::{PacketParseError, PSOPacket};
|
|
|
use libpso::crypto::bb::PSOBBCipher;
|
|
|
use libpso::crypto::bb::PSOBBCipher;
|
|
|
use libpso::character::character;
|
|
|
use libpso::character::character;
|
|
|
|
|
|
use libpso::packet::ship::{ROOM_MENU_ID};
|
|
|
|
|
|
|
|
|
use crate::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY};
|
|
|
use crate::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY};
|
|
|
use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId};
|
|
|
use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId};
|
|
@ -46,6 +47,7 @@ pub enum RecvShipPacket { |
|
|
UpdateConfig(UpdateConfig),
|
|
|
UpdateConfig(UpdateConfig),
|
|
|
ViewInfoboardRequest(ViewInfoboardRequest),
|
|
|
ViewInfoboardRequest(ViewInfoboardRequest),
|
|
|
WriteInfoboard(WriteInfoboard),
|
|
|
WriteInfoboard(WriteInfoboard),
|
|
|
|
|
|
RoomListRequest(RoomListRequest),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl RecvServerPacket for RecvShipPacket {
|
|
|
impl RecvServerPacket for RecvShipPacket {
|
|
@ -62,6 +64,7 @@ impl RecvServerPacket for RecvShipPacket { |
|
|
0x7ED => Ok(RecvShipPacket::UpdateConfig(UpdateConfig::from_bytes(data)?)),
|
|
|
0x7ED => Ok(RecvShipPacket::UpdateConfig(UpdateConfig::from_bytes(data)?)),
|
|
|
0xD8 => Ok(RecvShipPacket::ViewInfoboardRequest(ViewInfoboardRequest::from_bytes(data)?)),
|
|
|
0xD8 => Ok(RecvShipPacket::ViewInfoboardRequest(ViewInfoboardRequest::from_bytes(data)?)),
|
|
|
0xD9 => Ok(RecvShipPacket::WriteInfoboard(WriteInfoboard::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()))
|
|
|
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -86,6 +89,7 @@ pub enum SendShipPacket { |
|
|
LeaveRoom(LeaveRoom),
|
|
|
LeaveRoom(LeaveRoom),
|
|
|
RoomNameResponse(RoomNameResponse),
|
|
|
RoomNameResponse(RoomNameResponse),
|
|
|
ViewInfoboardResponse(ViewInfoboardResponse),
|
|
|
ViewInfoboardResponse(ViewInfoboardResponse),
|
|
|
|
|
|
RoomListResponse(RoomListResponse),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl SendServerPacket for SendShipPacket {
|
|
|
impl SendServerPacket for SendShipPacket {
|
|
@ -108,11 +112,11 @@ impl SendServerPacket for SendShipPacket { |
|
|
SendShipPacket::LeaveRoom(pkt) => pkt.as_bytes(),
|
|
|
SendShipPacket::LeaveRoom(pkt) => pkt.as_bytes(),
|
|
|
SendShipPacket::RoomNameResponse(pkt) => pkt.as_bytes(),
|
|
|
SendShipPacket::RoomNameResponse(pkt) => pkt.as_bytes(),
|
|
|
SendShipPacket::ViewInfoboardResponse(pkt) => pkt.as_bytes(),
|
|
|
SendShipPacket::ViewInfoboardResponse(pkt) => pkt.as_bytes(),
|
|
|
|
|
|
SendShipPacket::RoomListResponse(pkt) => pkt.as_bytes(),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ClientState {
|
|
|
struct ClientState {
|
|
|
user: UserAccount,
|
|
|
user: UserAccount,
|
|
|
settings: UserSettings,
|
|
|
settings: UserSettings,
|
|
@ -137,12 +141,6 @@ impl ClientState { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct ShipServerState<EG: EntityGateway> {
|
|
|
pub struct ShipServerState<EG: EntityGateway> {
|
|
|
entity_gateway: EG,
|
|
|
entity_gateway: EG,
|
|
|
clients: HashMap<ClientId, ClientState>,
|
|
|
clients: HashMap<ClientId, ClientState>,
|
|
@ -439,8 +437,39 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
self.entity_gateway.set_character(&client.character);
|
|
|
self.entity_gateway.set_character(&client.character);
|
|
|
Box::new(None.into_iter())
|
|
|
Box::new(None.into_iter())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn request_room_list(&mut self, id: ClientId) -> 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: ROOM_MENU_ID,
|
|
|
|
|
|
item_id: i as u32,
|
|
|
|
|
|
difficulty: room.get_difficulty_for_room_list(),
|
|
|
|
|
|
players: self.client_location.get_client_count_in_room(RoomId(i)), // TODO
|
|
|
|
|
|
name: libpso::utf8_to_utf16_array!(room.name, 16),
|
|
|
|
|
|
episode: room.get_episode_for_room_list(),
|
|
|
|
|
|
flags: room.get_flags_for_room_list(),
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
});
|
|
|
|
|
|
let baseroom: RoomList = RoomList {
|
|
|
|
|
|
menu_id: ROOM_MENU_ID,
|
|
|
|
|
|
item_id: ROOM_MENU_ID,
|
|
|
|
|
|
difficulty: 0x00,
|
|
|
|
|
|
players: 0x00,
|
|
|
|
|
|
name: libpso::utf8_to_utf16_array!("Room list menu", 16),
|
|
|
|
|
|
episode: 0,
|
|
|
|
|
|
flags: 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Box::new(vec![(id, SendShipPacket::RoomListResponse(RoomListResponse {
|
|
|
|
|
|
baseroom,
|
|
|
|
|
|
rooms: active_room_list.collect()
|
|
|
|
|
|
}))].into_iter())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
|
|
|
impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
|
|
|
type SendPacket = SendShipPacket;
|
|
|
type SendPacket = SendShipPacket;
|
|
@ -503,6 +532,10 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> { |
|
|
RecvShipPacket::WriteInfoboard(pkt) => {
|
|
|
RecvShipPacket::WriteInfoboard(pkt) => {
|
|
|
self.write_infoboard(id, pkt)
|
|
|
self.write_infoboard(id, pkt)
|
|
|
},
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
RecvShipPacket::RoomListRequest(_req) => {
|
|
|
|
|
|
self.request_room_list(id)
|
|
|
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|