Browse Source

andy what were you doing

make guild card sending much more sane
pbs
jake 5 years ago
parent
commit
de8f44f269
  1. 7
      src/entity/account.rs
  2. 7
      src/entity/character.rs
  3. 8
      src/entity/gateway/entitygateway.rs
  4. 38
      src/entity/gateway/inmemory.rs
  5. 8
      src/main.rs
  6. 33
      src/ship/ship.rs

7
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,
}

7
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(),
}
}
}

8
src/entity/gateway/entitygateway.rs

@ -52,12 +52,4 @@ pub trait EntityGateway {
fn get_items_by_character(&self, _char: &CharacterEntity) -> Vec<Item> {
unimplemented!();
}
fn create_guild_card_by_character(&self, _character: &CharacterEntity) -> GuildCard {
unimplemented!();
}
fn get_guild_card_by_character(&self, _character: &CharacterEntity) -> Option<GuildCard> {
unimplemented!();
}
}

38
src/entity/gateway/inmemory.rs

@ -15,7 +15,6 @@ use std::sync::{Arc, Mutex};
pub struct InMemoryGateway {
users: Arc<Mutex<HashMap<u32, UserAccount>>>,
user_settings: Arc<Mutex<HashMap<u32, UserSettings>>>,
guildcards: Arc<Mutex<HashMap<u32, GuildCard>>>,
characters: Arc<Mutex<HashMap<u32, CharacterEntity>>>,
items: Arc<Mutex<HashMap<ItemEntityId, Item>>>,
}
@ -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<GuildCard> {
let guildcards = self.guildcards.lock().unwrap();
guildcards
.iter()
.find(|(_, k)| k.character_id == character.id)
.map(|(_, k)| k.clone())
}
}

8
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 {

33
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<EG: EntityGateway> ShipServerState<EG> {
.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<EG: EntityGateway> ShipServerState<EG> {
fn direct_message(&mut self, id: ClientId, msg: &DirectMessage) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + 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()

Loading…
Cancel
Save