|
@ -6,6 +6,8 @@ use libpso::packet::ship::*; |
|
|
use libpso::packet::login::{Login, LoginResponse, AccountStatus, Session};
|
|
|
use libpso::packet::login::{Login, LoginResponse, AccountStatus, Session};
|
|
|
use libpso::{PacketParseError, PSOPacket};
|
|
|
use libpso::{PacketParseError, PSOPacket};
|
|
|
use libpso::crypto::bb::PSOBBCipher;
|
|
|
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::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY};
|
|
|
use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId};
|
|
|
use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId};
|
|
@ -25,12 +27,16 @@ pub enum ShipError { |
|
|
#[derive(Debug)]
|
|
|
#[derive(Debug)]
|
|
|
pub enum RecvShipPacket {
|
|
|
pub enum RecvShipPacket {
|
|
|
Login(Login),
|
|
|
Login(Login),
|
|
|
|
|
|
MenuSelect(MenuSelect),
|
|
|
|
|
|
CharData(CharData),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl RecvServerPacket for RecvShipPacket {
|
|
|
impl RecvServerPacket for RecvShipPacket {
|
|
|
fn from_bytes(data: &[u8]) -> Result<RecvShipPacket, PacketParseError> {
|
|
|
fn from_bytes(data: &[u8]) -> Result<RecvShipPacket, PacketParseError> {
|
|
|
match u16::from_le_bytes([data[2], data[3]]) {
|
|
|
match u16::from_le_bytes([data[2], data[3]]) {
|
|
|
0x93 => Ok(RecvShipPacket::Login(Login::from_bytes(data)?)),
|
|
|
0x93 => Ok(RecvShipPacket::Login(Login::from_bytes(data)?)),
|
|
|
|
|
|
0x10 => Ok(RecvShipPacket::MenuSelect(MenuSelect::from_bytes(data)?)),
|
|
|
|
|
|
0x61 => Ok(RecvShipPacket::CharData(CharData::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()))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -41,6 +47,9 @@ pub enum SendShipPacket { |
|
|
ShipWelcome(ShipWelcome),
|
|
|
ShipWelcome(ShipWelcome),
|
|
|
LoginResponse(LoginResponse),
|
|
|
LoginResponse(LoginResponse),
|
|
|
ShipBlockList(ShipBlockList),
|
|
|
ShipBlockList(ShipBlockList),
|
|
|
|
|
|
FullCharacter(FullCharacter),
|
|
|
|
|
|
CharDataRequest(CharDataRequest),
|
|
|
|
|
|
JoinLobby(JoinLobby),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl SendServerPacket for SendShipPacket {
|
|
|
impl SendServerPacket for SendShipPacket {
|
|
@ -49,6 +58,9 @@ impl SendServerPacket for SendShipPacket { |
|
|
SendShipPacket::ShipWelcome(pkt) => pkt.as_bytes(),
|
|
|
SendShipPacket::ShipWelcome(pkt) => pkt.as_bytes(),
|
|
|
SendShipPacket::LoginResponse(pkt) => pkt.as_bytes(),
|
|
|
SendShipPacket::LoginResponse(pkt) => pkt.as_bytes(),
|
|
|
SendShipPacket::ShipBlockList(pkt) => pkt.as_bytes(),
|
|
|
SendShipPacket::ShipBlockList(pkt) => pkt.as_bytes(),
|
|
|
|
|
|
SendShipPacket::FullCharacter(pkt) => pkt.as_bytes(),
|
|
|
|
|
|
SendShipPacket::CharDataRequest(pkt) => pkt.as_bytes(),
|
|
|
|
|
|
SendShipPacket::JoinLobby(pkt) => pkt.as_bytes(),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -58,6 +70,7 @@ struct ClientState { |
|
|
user: Option<UserAccount>,
|
|
|
user: Option<UserAccount>,
|
|
|
characters: Option<[Option<Character>; 4]>,
|
|
|
characters: Option<[Option<Character>; 4]>,
|
|
|
session: Session,
|
|
|
session: Session,
|
|
|
|
|
|
block: u32,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl ClientState {
|
|
|
impl ClientState {
|
|
@ -65,7 +78,8 @@ impl ClientState { |
|
|
ClientState {
|
|
|
ClientState {
|
|
|
user: None,
|
|
|
user: None,
|
|
|
characters: None,
|
|
|
characters: None,
|
|
|
session: Session::new()
|
|
|
|
|
|
|
|
|
session: Session::new(),
|
|
|
|
|
|
block: 0,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -100,6 +114,65 @@ impl<EG: EntityGateway> ShipServerState<EG> { |
|
|
}
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn block_selected(&mut self, id: ClientId, pkt: &MenuSelect) -> Result<Vec<SendShipPacket>, ShipError> {
|
|
|
|
|
|
let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
|
|
client.block = pkt.item as u32;
|
|
|
|
|
|
|
|
|
|
|
|
let mut fc = character::FullCharacter::default();
|
|
|
|
|
|
fc.character.hp = 4000;
|
|
|
|
|
|
fc.character.atp = 1200;
|
|
|
|
|
|
fc.character.lck = 1300;
|
|
|
|
|
|
|
|
|
|
|
|
//Ok(Vec::new())
|
|
|
|
|
|
Ok(vec![
|
|
|
|
|
|
SendShipPacket::FullCharacter(FullCharacter {
|
|
|
|
|
|
character: fc,
|
|
|
|
|
|
}),
|
|
|
|
|
|
SendShipPacket::CharDataRequest(CharDataRequest {}),
|
|
|
|
|
|
])
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn send_player_to_lobby(&mut self, id: ClientId, pkt: &CharData) -> Result<Vec<SendShipPacket>, ShipError> {
|
|
|
|
|
|
let mut c = character::Character::default();
|
|
|
|
|
|
c.hp = 1000;
|
|
|
|
|
|
c.atp = 1100;
|
|
|
|
|
|
c.lck = 1200;
|
|
|
|
|
|
let joinlobby = JoinLobby {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
leader: 0,
|
|
|
|
|
|
one: 1,
|
|
|
|
|
|
lobby: 0,
|
|
|
|
|
|
block: 1,
|
|
|
|
|
|
event: 0,
|
|
|
|
|
|
padding: 0,
|
|
|
|
|
|
playerinfo: vec![
|
|
|
|
|
|
PlayerInfo {
|
|
|
|
|
|
header: PlayerHeader {
|
|
|
|
|
|
tag: 0,
|
|
|
|
|
|
guildcard: 12345,
|
|
|
|
|
|
_unknown1: [0; 5],
|
|
|
|
|
|
client_id: 0,
|
|
|
|
|
|
name: utf8_to_utf16_array!("HELLO", 16),
|
|
|
|
|
|
_unknown2: 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
inventory: character::Inventory {
|
|
|
|
|
|
item_count: 0,
|
|
|
|
|
|
hp_mats_used: 0,
|
|
|
|
|
|
tp_mats_used: 0,
|
|
|
|
|
|
language: 0,
|
|
|
|
|
|
items: [character::InventoryItem::default(); 30],
|
|
|
|
|
|
},
|
|
|
|
|
|
character: c
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(vec![
|
|
|
|
|
|
SendShipPacket::JoinLobby(joinlobby)
|
|
|
|
|
|
])
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -130,6 +203,15 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> { |
|
|
RecvShipPacket::Login(login) => {
|
|
|
RecvShipPacket::Login(login) => {
|
|
|
Box::new(self.validate_login(id, login)?.into_iter().map(move |pkt| (id, pkt)))
|
|
|
Box::new(self.validate_login(id, login)?.into_iter().map(move |pkt| (id, pkt)))
|
|
|
},
|
|
|
},
|
|
|
|
|
|
RecvShipPacket::MenuSelect(menuselect) => {
|
|
|
|
|
|
match menuselect.menu {
|
|
|
|
|
|
BLOCK_MENU_ID => Box::new(self.block_selected(id, menuselect)?.into_iter().map(move |pkt| (id, pkt))),
|
|
|
|
|
|
_ => unreachable!(),
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
RecvShipPacket::CharData(chardata) => {
|
|
|
|
|
|
Box::new(self.send_player_to_lobby(id, chardata)?.into_iter().map(move |pkt| (id, pkt)))
|
|
|
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|