From de8f44f269181616ccbb66c50a16bdd4e1dc70dd Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 29 Mar 2020 13:27:23 -0700 Subject: [PATCH] andy what were you doing make guild card sending much more sane --- src/entity/account.rs | 7 ------ src/entity/character.rs | 7 +++++- src/entity/gateway/entitygateway.rs | 8 ------ src/entity/gateway/inmemory.rs | 38 ----------------------------- src/main.rs | 8 ------ src/ship/ship.rs | 33 ++++++++++++------------- 6 files changed, 21 insertions(+), 80 deletions(-) diff --git a/src/entity/account.rs b/src/entity/account.rs index e0e5667..cc77d92 100644 --- a/src/entity/account.rs +++ b/src/entity/account.rs @@ -32,10 +32,3 @@ pub struct GuildCardData { pub user_id: u32, pub guildcard: guildcard::GuildCardData, } - -#[derive(Clone, Default)] -pub struct GuildCard { - pub id: u32, - pub character_id: u32, - pub guildcard: guildcard::GuildCard, -} \ No newline at end of file diff --git a/src/entity/character.rs b/src/entity/character.rs index 1480016..d10fc44 100644 --- a/src/entity/character.rs +++ b/src/entity/character.rs @@ -1,7 +1,6 @@ use std::convert::{From, Into, TryFrom, TryInto}; use std::collections::HashMap; -use libpso::character::character; use libpso::packet::ship::{UpdateConfig, WriteInfoboard}; use crate::entity::item::tech::Technique; @@ -223,6 +222,10 @@ impl CharacterInfoboard { } } +#[derive(Clone, Default)] +pub struct CharacterGuildCard { + pub description: String, +} #[derive(Clone)] pub struct CharacterEntity { @@ -240,6 +243,7 @@ pub struct CharacterEntity { pub techs: CharacterTechniques, pub config: CharacterConfig, pub info_board: CharacterInfoboard, + pub guildcard: CharacterGuildCard, } impl std::default::Default for CharacterEntity { @@ -256,6 +260,7 @@ impl std::default::Default for CharacterEntity { techs: CharacterTechniques::new(), config: CharacterConfig::new(), info_board: CharacterInfoboard::new(), + guildcard: CharacterGuildCard::default(), } } } diff --git a/src/entity/gateway/entitygateway.rs b/src/entity/gateway/entitygateway.rs index 564d9b2..c478dcb 100644 --- a/src/entity/gateway/entitygateway.rs +++ b/src/entity/gateway/entitygateway.rs @@ -52,12 +52,4 @@ pub trait EntityGateway { fn get_items_by_character(&self, _char: &CharacterEntity) -> Vec { unimplemented!(); } - - fn create_guild_card_by_character(&self, _character: &CharacterEntity) -> GuildCard { - unimplemented!(); - } - - fn get_guild_card_by_character(&self, _character: &CharacterEntity) -> Option { - unimplemented!(); - } } diff --git a/src/entity/gateway/inmemory.rs b/src/entity/gateway/inmemory.rs index 708b6b4..15c90b5 100644 --- a/src/entity/gateway/inmemory.rs +++ b/src/entity/gateway/inmemory.rs @@ -15,7 +15,6 @@ use std::sync::{Arc, Mutex}; pub struct InMemoryGateway { users: Arc>>, user_settings: Arc>>, - guildcards: Arc>>, characters: Arc>>, items: Arc>>, } @@ -25,7 +24,6 @@ impl InMemoryGateway { InMemoryGateway { users: Arc::new(Mutex::new(HashMap::new())), user_settings: Arc::new(Mutex::new(HashMap::new())), - guildcards: Arc::new(Mutex::new(HashMap::new())), characters: Arc::new(Mutex::new(HashMap::new())), items: Arc::new(Mutex::new(HashMap::new())), } @@ -143,40 +141,4 @@ impl EntityGateway for InMemoryGateway { }) .collect() } - - fn create_guild_card_by_character(&self, character: &CharacterEntity) -> GuildCard { - let mut guildcards = self.guildcards.lock().unwrap(); - let user = self.get_user_by_id(character.user_id).unwrap(); - let settings = self.get_user_settings_by_user(&user).unwrap(); - let id = guildcards - .iter() - .fold(0, |sum, (i, _)| std::cmp::max(sum, *i)) - + 1; - let new_guildcard = GuildCard { - id: id, - character_id: character.id, - guildcard: libpso::character::guildcard::GuildCard { - guildcard: user.guildcard, - name: libpso::utf8_to_utf16_array!(character.name, 24), - team: settings.settings.team_name, - desc: [0; 88], // TODO? - reserved1: 1, - language: 0, - section_id: character.section_id.into(), - class: character.char_class.into(), - padding: 0, - comment: [0; 88], // TODO? - }, - }; - guildcards.insert(id, new_guildcard.clone()); - new_guildcard - } - - fn get_guild_card_by_character(&self, character: &CharacterEntity) -> Option { - let guildcards = self.guildcards.lock().unwrap(); - guildcards - .iter() - .find(|(_, k)| k.character_id == character.id) - .map(|(_, k)| k.clone()) - } } diff --git a/src/main.rs b/src/main.rs index 3d506e1..e1dabfd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,13 +73,11 @@ fn main() { entity_gateway.create_user_settings_by_user(&fake_user); let mut character = entity_gateway.new_character_by_user(&fake_user); character.name = "Test Char 1".into(); - entity_gateway.create_guild_card_by_character(&character); entity_gateway.set_character(&character); let mut character = entity_gateway.new_character_by_user(&fake_user); character.slot = 2; character.name = "\tE12345678".into(); character.exp = 80000000; - entity_gateway.create_guild_card_by_character(&character); entity_gateway.set_character(&character); entity_gateway.new_item( @@ -115,12 +113,10 @@ fn main() { entity_gateway.create_user_settings_by_user(&fake_user2); let mut character = entity_gateway.new_character_by_user(&fake_user2); character.name = "Test Char 3".into(); - entity_gateway.create_guild_card_by_character(&character); entity_gateway.set_character(&character); let mut character = entity_gateway.new_character_by_user(&fake_user2); character.slot = 2; character.name = "Test Char 4".into(); - entity_gateway.create_guild_card_by_character(&character); entity_gateway.set_character(&character); let fake_user3 = UserAccount { @@ -138,12 +134,10 @@ fn main() { entity_gateway.create_user_settings_by_user(&fake_user3); let mut character = entity_gateway.new_character_by_user(&fake_user3); character.name = "Test Char 5".into(); - entity_gateway.create_guild_card_by_character(&character); entity_gateway.set_character(&character); let mut character = entity_gateway.new_character_by_user(&fake_user3); character.slot = 2; character.name = "Test Char 6".into(); - entity_gateway.create_guild_card_by_character(&character); entity_gateway.set_character(&character); let fake_user4 = UserAccount { @@ -161,12 +155,10 @@ fn main() { entity_gateway.create_user_settings_by_user(&fake_user4); let mut character = entity_gateway.new_character_by_user(&fake_user4); character.name = "Test Char 7".into(); - entity_gateway.create_guild_card_by_character(&character); entity_gateway.set_character(&character); let mut character = entity_gateway.new_character_by_user(&fake_user4); character.slot = 2; character.name = "Test Char 8".into(); - entity_gateway.create_guild_card_by_character(&character); entity_gateway.set_character(&character); async_std::task::block_on(async move { diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 80f0ccf..518d874 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -10,13 +10,14 @@ use libpso::{PacketParseError, PSOPacket}; use libpso::crypto::bb::PSOBBCipher; use libpso::character::character; use libpso::packet::ship::{ROOM_MENU_ID}; +use libpso::{utf8_to_array, utf8_to_utf16_array}; use crate::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY}; use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId}; use crate::common::leveltable::CharacterLevelTable; use crate::entity::gateway::EntityGateway; -use crate::entity::account::{UserAccount, UserSettings, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM, GuildCard}; +use crate::entity::account::{UserAccount, UserSettings, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM}; use crate::entity::character::CharacterEntity; use crate::entity::item::{ItemLocation, Item}; use crate::login::login::get_login_status; @@ -122,21 +123,20 @@ struct ClientState { settings: UserSettings, character: CharacterEntity, session: Session, - guildcard: GuildCard, + //guildcard: GuildCard, inventory: items::ActiveInventory, //bank: Bank, block: u32, } impl ClientState { - fn new(user: UserAccount, settings: UserSettings, character: CharacterEntity, inventory: items::ActiveInventory, /*bank: Bank,*/ session: Session, guildcard: GuildCard) -> ClientState { + fn new(user: UserAccount, settings: UserSettings, character: CharacterEntity, inventory: items::ActiveInventory, /*bank: Bank,*/ session: Session) -> ClientState { ClientState { user: user, settings: settings, character: character, session: session, inventory: inventory, - guildcard: guildcard, //bank: bank, block: 1, } @@ -181,11 +181,9 @@ impl ShipServerState { .clone(); let settings = self.entity_gateway.get_user_settings_by_user(&user) .ok_or(ShipError::ClientNotFound(id))?; - let guildcard = self.entity_gateway.get_guild_card_by_character(&character) - .ok_or(ShipError::ClientNotFound(id))?; let inventory = self.item_database.get_character_inventory(&mut self.entity_gateway, &character); - self.clients.insert(id, ClientState::new(user, settings, character, inventory, pkt.session, guildcard)); + self.clients.insert(id, ClientState::new(user, settings, character, inventory, pkt.session)); vec![SendShipPacket::LoginResponse(response), SendShipPacket::ShipBlockList(ShipBlockList::new(&self.name, 3))] }, Err(err) => { @@ -331,22 +329,21 @@ impl ShipServerState { fn direct_message(&mut self, id: ClientId, msg: &DirectMessage) -> Box + Send> { let cmsg = msg.clone(); let client = self.clients.get_mut(&id).unwrap(); - let gc = self.entity_gateway.get_guild_card_by_character(&client.character).unwrap(); match &cmsg.msg { - GameMessage::GuildcardSend(GuildcardSend) => { + GameMessage::GuildcardSend(guildcard_send) => { let out_msg = DirectMessage{ flag: cmsg.flag, msg: GameMessage::GuildcardRecv(GuildcardRecv { - client: 141, - target: 8, - guildcard: gc.guildcard.guildcard, - name: gc.guildcard.name, - team: gc.guildcard.team, - desc: gc.guildcard.desc, + client: guildcard_send.client, + target: guildcard_send.target, + guildcard: client.user.id, + name: utf8_to_utf16_array!(client.character.name, 0x18), + team: [0; 0x10], // TODO: teams not yet implemented + desc: utf8_to_utf16_array!(client.character.guildcard.description, 0x58), one: 1, - language: gc.guildcard.language, - section_id: gc.guildcard.section_id, - class: gc.guildcard.class, + language: 0, // TODO: add language flag to character + section_id: client.character.section_id.into(), + class: client.character.char_class.into(), }), }; Box::new(self.client_location.get_area_by_user(id).clients().iter()