Browse Source

0x8A room name req pkts

pbs
jake 5 years ago
parent
commit
dbba6ff866
  1. 2
      src/ship/room.rs
  2. 19
      src/ship/ship.rs

2
src/ship/room.rs

@ -94,7 +94,7 @@ pub enum RoomMode {
#[derive(Debug)] #[derive(Debug)]
pub struct RoomState { pub struct RoomState {
mode: RoomMode, mode: RoomMode,
name: [u16; 16],
pub name: [u16; 16],
password: [u16; 16], password: [u16; 16],
pub maps: [u32; 0x20], pub maps: [u32; 0x20],
// drop_table // drop_table

19
src/ship/ship.rs

@ -9,7 +9,6 @@ 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::utf8_to_utf16_array;
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};
@ -20,7 +19,7 @@ use crate::entity::account::{UserAccount, UserSettings, USERFLAG_NEWCHAR, USERFL
use crate::entity::character::Character; use crate::entity::character::Character;
use crate::entity::item::ItemLocation; use crate::entity::item::ItemLocation;
use crate::login::login::get_login_status; 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::character::{CharacterBuilder, FullCharacterBuilder};
use crate::ship::room; use crate::ship::room;
@ -42,6 +41,7 @@ pub enum RecvShipPacket {
DirectMessage(DirectMessage), DirectMessage(DirectMessage),
PlayerChat(PlayerChat), PlayerChat(PlayerChat),
CreateRoom(CreateRoom), CreateRoom(CreateRoom),
RoomNameRequest(RoomNameRequest),
} }
impl RecvServerPacket for RecvShipPacket { impl RecvServerPacket for RecvShipPacket {
@ -54,6 +54,7 @@ impl RecvServerPacket for RecvShipPacket {
0x62 => Ok(RecvShipPacket::DirectMessage(DirectMessage::from_bytes(data)?)), 0x62 => Ok(RecvShipPacket::DirectMessage(DirectMessage::from_bytes(data)?)),
0x06 => Ok(RecvShipPacket::PlayerChat(PlayerChat::from_bytes(data)?)), 0x06 => Ok(RecvShipPacket::PlayerChat(PlayerChat::from_bytes(data)?)),
0xC1 => Ok(RecvShipPacket::CreateRoom(CreateRoom::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())) _ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
} }
} }
@ -76,6 +77,7 @@ pub enum SendShipPacket {
AddToRoom(AddToRoom), AddToRoom(AddToRoom),
LeaveLobby(LeaveLobby), LeaveLobby(LeaveLobby),
LeaveRoom(LeaveRoom), LeaveRoom(LeaveRoom),
RoomNameResponse(RoomNameResponse),
} }
impl SendServerPacket for SendShipPacket { impl SendServerPacket for SendShipPacket {
@ -96,6 +98,7 @@ impl SendServerPacket for SendShipPacket {
SendShipPacket::AddToRoom(pkt) => pkt.as_bytes(), SendShipPacket::AddToRoom(pkt) => pkt.as_bytes(),
SendShipPacket::LeaveLobby(pkt) => pkt.as_bytes(), SendShipPacket::LeaveLobby(pkt) => pkt.as_bytes(),
SendShipPacket::LeaveRoom(pkt) => pkt.as_bytes(), SendShipPacket::LeaveRoom(pkt) => pkt.as_bytes(),
SendShipPacket::RoomNameResponse(pkt) => pkt.as_bytes(),
} }
} }
} }
@ -130,6 +133,7 @@ pub struct ShipServerState<EG: EntityGateway> {
client_location: ClientLocation, client_location: ClientLocation,
level_table: CharacterLevelTable, level_table: CharacterLevelTable,
name: String, name: String,
rooms: [Option<room::RoomState>; MAX_ROOMS],
} }
impl<EG: EntityGateway> ShipServerState<EG> { impl<EG: EntityGateway> ShipServerState<EG> {
@ -140,6 +144,7 @@ impl<EG: EntityGateway> ShipServerState<EG> {
client_location: ClientLocation::new(), client_location: ClientLocation::new(),
level_table: CharacterLevelTable::new(), level_table: CharacterLevelTable::new(),
name: "Sona-Nyl".into(), name: "Sona-Nyl".into(),
rooms: [None; MAX_ROOMS],
} }
} }
@ -384,12 +389,19 @@ impl<EG: EntityGateway> ShipServerState<EG> {
single_player: create_room.single_player, single_player: create_room.single_player,
unknown: 0, unknown: 0,
}; };
self.rooms[room_id.0] = Some(room);
let leader = area.leader(); let leader = area.leader();
Box::new(vec![(id, SendShipPacket::JoinRoom(join_room))].into_iter().chain(other_clients.map(move |c| { 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))) (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<dyn Iterator<Item = (ClientId, SendShipPacket)>> {
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<EG: EntityGateway> ServerState for ShipServerState<EG> {
}, },
RecvShipPacket::CreateRoom(create_room) => { RecvShipPacket::CreateRoom(create_room) => {
self.create_room(id, create_room) self.create_room(id, create_room)
},
RecvShipPacket::RoomNameRequest(_req) => {
self.room_name_request(id)
} }
}) })
} }

Loading…
Cancel
Save