|
|
@ -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<EG: EntityGateway> { |
|
|
|
client_location: ClientLocation,
|
|
|
|
level_table: CharacterLevelTable,
|
|
|
|
name: String,
|
|
|
|
rooms: [Option<room::RoomState>; MAX_ROOMS],
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<EG: EntityGateway> ShipServerState<EG> {
|
|
|
@ -140,6 +144,7 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
|
client_location: ClientLocation::new(),
|
|
|
|
level_table: CharacterLevelTable::new(),
|
|
|
|
name: "Sona-Nyl".into(),
|
|
|
|
rooms: [None; MAX_ROOMS],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
@ -384,12 +389,19 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
|
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<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) => {
|
|
|
|
self.create_room(id, create_room)
|
|
|
|
},
|
|
|
|
RecvShipPacket::RoomNameRequest(_req) => {
|
|
|
|
self.room_name_request(id)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|