Browse Source

cleanup and fix errors. still need to get room player counts

pbs
andy 5 years ago
committed by jake
parent
commit
eef2178df8
  1. 28
      src/ship/room.rs
  2. 25
      src/ship/ship.rs

28
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; let mut flags = 0u8;
match mode {
match self.mode {
RoomMode::Single {..} => {flags += 0x04} RoomMode::Single {..} => {flags += 0x04}
RoomMode::Battle {..} => {flags += 0x10}, RoomMode::Battle {..} => {flags += 0x10},
RoomMode::Challenge {..} => {flags += 0x20}, RoomMode::Challenge {..} => {flags += 0x20},
_ => {flags += 0x40}, _ => {flags += 0x40},
}; };
if password[0] > 0 {
if self.password[0] > 0 {
flags += 0x02; flags += 0x02;
} }
flags 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<RoomState, RoomCreationError> { pub fn from_create_room(create_room: &libpso::packet::ship::CreateRoom) -> Result<RoomState, RoomCreationError> {
@ -203,10 +205,6 @@ impl RoomState {
password: create_room.password, password: create_room.password,
//maps: [0; 0x20], //maps: [0; 0x20],
maps: Maps::new(room_mode.episode()), 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),
}) })
} }

25
src/ship/ship.rs

@ -438,7 +438,7 @@ impl<EG: EntityGateway> ShipServerState<EG> {
Box::new(None.into_iter()) Box::new(None.into_iter())
} }
fn request_room_list(&mut self, id: ClientId, request_roomlist: &RoomListRequest) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
fn request_room_list(&mut self, id: ClientId) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
let active_room_list = self.rooms.iter() let active_room_list = self.rooms.iter()
.enumerate() .enumerate()
.filter_map(|(i, r)| { .filter_map(|(i, r)| {
@ -446,19 +446,22 @@ impl<EG: EntityGateway> ShipServerState<EG> {
RoomList { RoomList {
menu_id: ROOM_MENU_ID, menu_id: ROOM_MENU_ID,
item_id: i as u32, 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), 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, 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 { Box::new(vec![(id, SendShipPacket::RoomListResponse(RoomListResponse {
@ -530,8 +533,8 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
self.write_infoboard(id, pkt) self.write_infoboard(id, pkt)
}, },
RecvShipPacket::RoomListRequest(pkt) => {
self.request_room_list(id, pkt)
RecvShipPacket::RoomListRequest(_req) => {
self.request_room_list(id)
}, },
}) })
} }

Loading…
Cancel
Save