From 871493a8357d017c48faf82afa490ba2cf0c2386 Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 16 Nov 2019 23:15:25 -0800 Subject: [PATCH] basic lobby loading --- src/ship/ship.rs | 84 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/src/ship/ship.rs b/src/ship/ship.rs index de11ef2..7349e53 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -6,6 +6,8 @@ use libpso::packet::ship::*; use libpso::packet::login::{Login, LoginResponse, AccountStatus, Session}; 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}; @@ -25,12 +27,16 @@ pub enum ShipError { #[derive(Debug)] pub enum RecvShipPacket { Login(Login), + MenuSelect(MenuSelect), + CharData(CharData), } impl RecvServerPacket for RecvShipPacket { fn from_bytes(data: &[u8]) -> Result { match u16::from_le_bytes([data[2], data[3]]) { 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())) } } @@ -41,6 +47,9 @@ pub enum SendShipPacket { ShipWelcome(ShipWelcome), LoginResponse(LoginResponse), ShipBlockList(ShipBlockList), + FullCharacter(FullCharacter), + CharDataRequest(CharDataRequest), + JoinLobby(JoinLobby), } impl SendServerPacket for SendShipPacket { @@ -49,6 +58,9 @@ impl SendServerPacket for SendShipPacket { SendShipPacket::ShipWelcome(pkt) => pkt.as_bytes(), SendShipPacket::LoginResponse(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, characters: Option<[Option; 4]>, session: Session, + block: u32, } impl ClientState { @@ -65,7 +78,8 @@ impl ClientState { ClientState { user: None, characters: None, - session: Session::new() + session: Session::new(), + block: 0, } } } @@ -100,6 +114,65 @@ impl ShipServerState { } }) } + + fn block_selected(&mut self, id: ClientId, pkt: &MenuSelect) -> Result, 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, 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 ServerState for ShipServerState { RecvShipPacket::Login(login) => { 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))) + } }) } }