diff --git a/src/ship/room.rs b/src/ship/room.rs index 982c0c1..7f693c9 100644 --- a/src/ship/room.rs +++ b/src/ship/room.rs @@ -94,7 +94,7 @@ pub enum RoomMode { #[derive(Debug)] pub struct RoomState { mode: RoomMode, - name: [u16; 16], + pub name: [u16; 16], password: [u16; 16], pub maps: [u32; 0x20], // drop_table diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 9a8637a..f4f3e17 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -9,7 +9,6 @@ use libpso::packet::messages::*; use libpso::{PacketParseError, PSOPacket}; use libpso::crypto::bb::PSOBBCipher; use libpso::character::character; -use libpso::utf8_to_utf16_array; use crate::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY}; use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId}; @@ -20,7 +19,7 @@ use crate::entity::account::{UserAccount, UserSettings, USERFLAG_NEWCHAR, USERFL use crate::entity::character::Character; use crate::entity::item::ItemLocation; use crate::login::login::get_login_status; -use crate::ship::location::{ClientLocation, LobbyId, RoomId, AreaType}; +use crate::ship::location::{ClientLocation, LobbyId, RoomId, AreaType, MAX_ROOMS}; use crate::ship::character::{CharacterBuilder, FullCharacterBuilder}; use crate::ship::room; @@ -42,6 +41,7 @@ pub enum RecvShipPacket { DirectMessage(DirectMessage), PlayerChat(PlayerChat), CreateRoom(CreateRoom), + RoomNameRequest(RoomNameRequest), } impl RecvServerPacket for RecvShipPacket { @@ -54,6 +54,7 @@ impl RecvServerPacket for RecvShipPacket { 0x62 => Ok(RecvShipPacket::DirectMessage(DirectMessage::from_bytes(data)?)), 0x06 => Ok(RecvShipPacket::PlayerChat(PlayerChat::from_bytes(data)?)), 0xC1 => Ok(RecvShipPacket::CreateRoom(CreateRoom::from_bytes(data)?)), + 0x8A => Ok(RecvShipPacket::RoomNameRequest(RoomNameRequest::from_bytes(data)?)), _ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec())) } } @@ -76,6 +77,7 @@ pub enum SendShipPacket { AddToRoom(AddToRoom), LeaveLobby(LeaveLobby), LeaveRoom(LeaveRoom), + RoomNameResponse(RoomNameResponse), } impl SendServerPacket for SendShipPacket { @@ -96,6 +98,7 @@ impl SendServerPacket for SendShipPacket { SendShipPacket::AddToRoom(pkt) => pkt.as_bytes(), SendShipPacket::LeaveLobby(pkt) => pkt.as_bytes(), SendShipPacket::LeaveRoom(pkt) => pkt.as_bytes(), + SendShipPacket::RoomNameResponse(pkt) => pkt.as_bytes(), } } } @@ -130,6 +133,7 @@ pub struct ShipServerState { client_location: ClientLocation, level_table: CharacterLevelTable, name: String, + rooms: [Option; MAX_ROOMS], } impl ShipServerState { @@ -140,6 +144,7 @@ impl ShipServerState { client_location: ClientLocation::new(), level_table: CharacterLevelTable::new(), name: "Sona-Nyl".into(), + rooms: [None; MAX_ROOMS], } } @@ -384,12 +389,19 @@ impl ShipServerState { single_player: create_room.single_player, unknown: 0, }; + self.rooms[room_id.0] = Some(room); let leader = area.leader(); Box::new(vec![(id, SendShipPacket::JoinRoom(join_room))].into_iter().chain(other_clients.map(move |c| { (c.client_id, SendShipPacket::LeaveLobby(LeaveLobby::new(area_client.index as u8, leader.index as u8))) }))) } + + fn room_name_request(&mut self, id: ClientId) -> Box> { + let area = self.client_location.get_area_by_user(id); + let room_state = self.rooms[area.id()].as_ref().unwrap(); + Box::new(vec![(id, SendShipPacket::RoomNameResponse(RoomNameResponse {name: String::from_utf16_lossy(&room_state.name)}))].into_iter()) + } } @@ -439,6 +451,9 @@ impl ServerState for ShipServerState { }, RecvShipPacket::CreateRoom(create_room) => { self.create_room(id, create_room) + }, + RecvShipPacket::RoomNameRequest(_req) => { + self.room_name_request(id) } }) }