From eef2178df8aafd877f31105d6e37313f9f0d316d Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 18 Mar 2020 21:46:13 -0300 Subject: [PATCH] cleanup and fix errors. still need to get room player counts --- src/ship/room.rs | 28 +++++++++++++--------------- src/ship/ship.rs | 25 ++++++++++++++----------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/ship/room.rs b/src/ship/room.rs index e40d0fc..9bf4338 100644 --- a/src/ship/room.rs +++ b/src/ship/room.rs @@ -140,32 +140,34 @@ impl RoomState { } }*/ - pub fn get_flags(mode: &RoomMode, password: [u16; 16]) -> u8 { + pub fn get_flags_for_room_list(&self) -> u8 { let mut flags = 0u8; - match mode { + match self.mode { RoomMode::Single {..} => {flags += 0x04} RoomMode::Battle {..} => {flags += 0x10}, RoomMode::Challenge {..} => {flags += 0x20}, _ => {flags += 0x40}, }; - if password[0] > 0 { + if self.password[0] > 0 { flags += 0x02; } flags } - pub fn get_episode(mode: &RoomMode) -> u8 { - let mut episode = 0u8; + pub fn get_episode_for_room_list(&self) -> u8 { + let episode: u8 = self.mode.episode().into(); - episode = mode.episode().into(); - - match mode { - RoomMode::Single {..} => {episode += 0x10}, - _ => {episode += 0x40}, + match self.mode { + RoomMode::Single {..} => episode + 0x10, + _ => episode + 0x40, } - episode + } + + pub fn get_difficulty_for_room_list(&self) -> u8 { + let difficulty: u8 = self.mode.difficulty().into(); + difficulty + 0x22 } pub fn from_create_room(create_room: &libpso::packet::ship::CreateRoom) -> Result { @@ -203,10 +205,6 @@ impl RoomState { password: create_room.password, //maps: [0; 0x20], maps: Maps::new(room_mode.episode()), - difficulty: create_room.difficulty + 0x22, - players: 0, - episode: RoomState::get_episode(&room_mode), - flags: RoomState::get_flags(&room_mode, create_room.password), }) } diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 99313f4..ae12b84 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -438,7 +438,7 @@ impl ShipServerState { Box::new(None.into_iter()) } - fn request_room_list(&mut self, id: ClientId, request_roomlist: &RoomListRequest) -> Box + Send> { + fn request_room_list(&mut self, id: ClientId) -> Box + Send> { let active_room_list = self.rooms.iter() .enumerate() .filter_map(|(i, r)| { @@ -446,19 +446,22 @@ impl ShipServerState { RoomList { menu_id: ROOM_MENU_ID, item_id: i as u32, - difficulty: room.difficulty, - players: room.players, + difficulty: room.get_difficulty_for_room_list(), + players: 0, // TODO name: libpso::utf8_to_utf16_array!(room.name, 16), - episode: room.episode, - flags: room.flags, + episode: room.get_episode_for_room_list(), + flags: room.get_flags_for_room_list(), } }) }); - let baseroom: BaseRoom = BaseRoom { + let baseroom: RoomList = RoomList { menu_id: ROOM_MENU_ID, - title_id: ROOM_MENU_ID, - zero: 0x0000, - menu_title: libpso::utf8_to_utf16_array!("Room list menu", 17), + 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 { @@ -530,8 +533,8 @@ impl ServerState for ShipServerState { self.write_infoboard(id, pkt) }, - RecvShipPacket::RoomListRequest(pkt) => { - self.request_room_list(id, pkt) + RecvShipPacket::RoomListRequest(_req) => { + self.request_room_list(id) }, }) }