Browse Source

Merge pull request 'use New variants of entities for creation' (#98) from new_entities into master

pbs
jake 5 years ago
parent
commit
f0f125822f
  1. 52
      src/entity/account.rs
  2. 29
      src/entity/character.rs
  3. 24
      src/entity/gateway/entitygateway.rs
  4. 100
      src/entity/gateway/inmemory.rs
  5. 7
      src/entity/item/mod.rs
  6. 64
      src/login/character.rs
  7. 6
      src/login/login.rs
  8. 28
      src/main.rs
  9. 18
      src/ship/items.rs
  10. 16
      src/ship/ship.rs

52
src/entity/account.rs

@ -13,9 +13,22 @@ pub struct UserSettingsId(pub u32);
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct GuildCardDataId(pub u32);
#[derive(Clone, Debug)]
pub struct NewUserAccountEntity {
pub username: String,
pub password: String,
pub guildcard: u32,
pub team_id: Option<u32>,
pub banned: bool,
pub muted_until: SystemTime,
pub created_at: SystemTime,
pub flags: u32,
}
#[derive(Clone, Debug)]
pub struct UserAccountEntity {
pub id: Option<UserAccountId>,
pub id: UserAccountId,
pub username: String,
pub password: String,
pub guildcard: u32,
@ -27,26 +40,47 @@ pub struct UserAccountEntity {
}
#[derive(Clone, Debug)]
pub struct UserSettingsEntity {
pub id: Option<UserSettingsId>,
pub struct NewUserSettingsEntity {
pub user_id: UserAccountId,
pub settings: settings::UserSettings,
}
impl UserSettingsEntity {
pub fn new(user_id: UserAccountId) -> UserSettingsEntity {
UserSettingsEntity {
id: None,
impl NewUserSettingsEntity {
pub fn new(user_id: UserAccountId) -> NewUserSettingsEntity {
NewUserSettingsEntity {
user_id: user_id,
settings: settings::UserSettings::default(),
}
}
}
#[derive(Clone, Debug)]
pub struct UserSettingsEntity {
pub id: UserSettingsId,
pub user_id: UserAccountId,
pub settings: settings::UserSettings,
}
#[derive(Clone)]
pub struct NewGuildCardDataEntity {
pub user_id: UserAccountId,
pub guildcard: guildcard::GuildCardData,
}
impl NewGuildCardDataEntity {
pub fn new(user_id: UserAccountId) -> NewGuildCardDataEntity {
NewGuildCardDataEntity {
user_id: user_id,
guildcard: guildcard::GuildCardData::default(),
}
}
}
// TODO: implement this properly
#[derive(Clone)]
pub struct GuildCardDataEntity {
pub id: Option<GuildCardDataId>,
pub id: GuildCardDataId,
pub user_id: UserAccountId,
pub guildcard: guildcard::GuildCardData,
}
@ -54,7 +88,7 @@ pub struct GuildCardDataEntity {
impl GuildCardDataEntity {
pub fn new(user_id: UserAccountId) -> GuildCardDataEntity {
GuildCardDataEntity {
id: None,
id: GuildCardDataId(0),
user_id: user_id,
guildcard: guildcard::GuildCardData::default(),
}

29
src/entity/character.rs

@ -233,8 +233,7 @@ pub struct CharacterGuildCard {
pub struct CharacterEntityId(pub u32);
#[derive(Clone)]
pub struct CharacterEntity {
pub id: Option<CharacterEntityId>,
pub struct NewCharacterEntity {
pub user_id: UserAccountId,
pub slot: u32,
@ -251,10 +250,9 @@ pub struct CharacterEntity {
pub guildcard: CharacterGuildCard,
}
impl CharacterEntity {
pub fn new(user: UserAccountId) -> CharacterEntity {
CharacterEntity {
id: None,
impl NewCharacterEntity {
pub fn new(user: UserAccountId) -> NewCharacterEntity {
NewCharacterEntity {
user_id: user,
slot: 0,
name: "".into(),
@ -269,3 +267,22 @@ impl CharacterEntity {
}
}
}
#[derive(Clone)]
pub struct CharacterEntity {
pub id: CharacterEntityId,
pub user_id: UserAccountId,
pub slot: u32,
pub name: String,
pub exp: u32,
pub char_class: CharacterClass,
pub section_id: SectionID,
pub appearance: CharacterAppearance,
pub techs: CharacterTechniques,
pub config: CharacterConfig,
pub info_board: CharacterInfoboard,
pub guildcard: CharacterGuildCard,
}

24
src/entity/gateway/entitygateway.rs

@ -5,6 +5,10 @@ use crate::entity::item::*;
use libpso::item;
pub trait EntityGateway {
fn create_user(&mut self, _user: NewUserAccountEntity) -> Option<UserAccountEntity> {
unimplemented!()
}
fn get_user_by_id(&self, _id: UserAccountId) -> Option<UserAccountEntity> {
unimplemented!();
}
@ -13,7 +17,11 @@ pub trait EntityGateway {
unimplemented!();
}
fn set_user(&mut self, _user: &mut UserAccountEntity) {
fn save_user(&mut self, _user: &UserAccountEntity) {
unimplemented!();
}
fn create_user_settings(&mut self, _settings: NewUserSettingsEntity) -> Option<UserSettingsEntity> {
unimplemented!();
}
@ -21,7 +29,11 @@ pub trait EntityGateway {
unimplemented!();
}
fn set_user_settings(&mut self, _settings: &mut UserSettingsEntity) {
fn save_user_settings(&mut self, _settings: &UserSettingsEntity) {
unimplemented!();
}
fn create_character(&mut self, _char: NewCharacterEntity) -> Option<CharacterEntity> {
unimplemented!();
}
@ -29,7 +41,7 @@ pub trait EntityGateway {
unimplemented!();
}
fn set_character(&mut self, _char: &mut CharacterEntity) {
fn save_character(&mut self, _char: &CharacterEntity) {
unimplemented!();
}
@ -37,7 +49,11 @@ pub trait EntityGateway {
unimplemented!();
}
fn set_item(&mut self, _item: &mut ItemEntity) {
fn create_item(&mut self, _item: NewItemEntity) -> Option<ItemEntity> {
unimplemented!();
}
fn save_item(&mut self, _item: &ItemEntity) {
unimplemented!();
}

100
src/entity/gateway/inmemory.rs

@ -31,6 +31,27 @@ impl InMemoryGateway {
}
impl EntityGateway for InMemoryGateway {
fn create_user(&mut self, user: NewUserAccountEntity) -> Option<UserAccountEntity> {
let mut users = self.users.lock().unwrap();
let id = users
.iter()
.fold(0, |sum, (i, _)| std::cmp::max(sum, i.0))
+ 1;
let user = UserAccountEntity {
id: UserAccountId(id),
username: user.username,
password: user.password,
guildcard: user.guildcard,
team_id: user.team_id,
banned: user.banned,
muted_until: user.muted_until,
created_at: user.created_at,
flags: user.flags,
};
users.insert(user.id, user.clone());
Some(user)
}
fn get_user_by_id(&self, id: UserAccountId) -> Option<UserAccountEntity> {
let users = self.users.lock().unwrap();
users.get(&id).map(|k| k.clone())
@ -44,37 +65,32 @@ impl EntityGateway for InMemoryGateway {
.map(|(_, k)| k.clone())
}
fn set_user(&mut self, user: &mut UserAccountEntity) {
fn save_user(&mut self, user: &UserAccountEntity) {
let mut users = self.users.lock().unwrap();
if let None = user.id {
let id = users
.iter()
.fold(0, |sum, (i, _)| std::cmp::max(sum, i.0))
+ 1;
user.id = Some(UserAccountId(id));
}
users.insert(user.id.unwrap(), user.clone());
users.insert(user.id, user.clone());
}
fn get_user_settings_by_user(&self, user: &UserAccountEntity) -> Option<UserSettingsEntity> {
let user_settings = self.user_settings.lock().unwrap();
user_settings
.iter()
.find(|(_, k)| k.user_id == user.id.unwrap())
.find(|(_, k)| k.user_id == user.id)
.map(|(_, k)| k.clone())
}
fn set_user_settings(&mut self, user_setting: &mut UserSettingsEntity) {
fn create_user_settings(&mut self, settings: NewUserSettingsEntity) -> Option<UserSettingsEntity> {
let mut user_settings = self.user_settings.lock().unwrap();
if let None = user_setting.id {
let id = user_settings
.iter()
.fold(0, |sum, (i, _)| std::cmp::max(sum, i.0))
+ 1;
user_setting.id = Some(UserSettingsId(id));
}
user_settings.insert(user_setting.id.unwrap(), user_setting.clone());
let new_settings = UserSettingsEntity {
id: UserSettingsId(id),
user_id: settings.user_id,
settings: settings.settings,
};
user_settings.insert(new_settings.id, new_settings.clone());
Some(new_settings)
}
fn get_characters_by_user(&self, user: &UserAccountEntity) -> [Option<CharacterEntity>; 4] {
@ -82,37 +98,63 @@ impl EntityGateway for InMemoryGateway {
let mut chars = [None; 4];
characters
.iter()
.filter(|(_, c)| c.user_id == user.id.unwrap())
.filter(|(_, c)| c.user_id == user.id)
.for_each(|(_, c)| chars[c.slot as usize] = Some(c.clone()));
chars
}
fn set_character(&mut self, char: &mut CharacterEntity) {
fn create_character(&mut self, character: NewCharacterEntity) -> Option<CharacterEntity> {
let mut characters = self.characters.lock().unwrap();
if let None = char.id {
let id = characters
.iter()
.fold(0, |sum, (i, _)| std::cmp::max(sum, i.0))
+ 1;
char.id = Some(CharacterEntityId(id));
}
characters.insert(char.id.unwrap(), char.clone());
let new_character = CharacterEntity {
id: CharacterEntityId(id),
user_id: character.user_id,
slot: character.slot,
name: character.name,
exp: character.exp,
char_class: character.char_class,
section_id: character.section_id,
appearance: character.appearance,
techs: character.techs,
config: character.config,
info_board: character.info_board,
guildcard: character.guildcard,
};
characters.insert(new_character.id, new_character.clone());
Some(new_character)
}
fn save_character(&mut self, char: &CharacterEntity) {
let mut characters = self.characters.lock().unwrap();
characters.insert(char.id, char.clone());
}
fn get_guild_card_data_by_user(&self, user: &UserAccountEntity) -> GuildCardDataEntity {
GuildCardDataEntity::new(user.id.unwrap())
GuildCardDataEntity::new(user.id)
}
fn set_item(&mut self, item: &mut ItemEntity) {
fn create_item(&mut self, item: NewItemEntity) -> Option<ItemEntity> {
let mut items = self.items.lock().unwrap();
if let None = item.id {
let id = items
.iter()
.fold(0, |sum, (i, _)| std::cmp::max(sum, i.0))
+ 1;
item.id = Some(ItemEntityId(id));
let new_item = ItemEntity {
id: ItemEntityId(id),
location: item.location,
item: item.item,
};
items.insert(ItemEntityId(id), new_item.clone());
Some(new_item)
}
items.insert(item.id.unwrap(), item.clone());
fn save_item(&mut self, item: &ItemEntity) {
let mut items = self.items.lock().unwrap();
items.insert(item.id, item.clone());
}
fn get_items_by_character(&self, character: &CharacterEntity) -> Vec<ItemEntity> {
@ -121,8 +163,8 @@ impl EntityGateway for InMemoryGateway {
.iter()
.filter(|(_, k)| {
match k.location {
ItemLocation::Inventory{character_id, ..} => character_id == character.id.unwrap(),
ItemLocation::Bank{character_id, ..} => character_id == character.id.unwrap(),
ItemLocation::Inventory{character_id, ..} => character_id == character.id,
ItemLocation::Bank{character_id, ..} => character_id == character.id,
_ => false
}
})

7
src/entity/item/mod.rs

@ -85,10 +85,15 @@ impl ItemDetail {
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct NewItemEntity {
pub location: ItemLocation,
pub item: ItemDetail,
}
#[derive(Clone, Debug, PartialEq)]
pub struct ItemEntity {
pub id: Option<ItemEntityId>,
pub id: ItemEntityId,
pub location: ItemLocation,
pub item: ItemDetail,
}

64
src/login/character.rs

@ -16,14 +16,14 @@ use crate::common::leveltable::CharacterLevelTable;
use libpso::{utf8_to_array, utf8_to_utf16_array};
use crate::entity::gateway::EntityGateway;
use crate::entity::account::{UserAccountEntity, UserSettingsEntity, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM};
use crate::entity::item::{ItemEntity, ItemDetail, ItemLocation};
use crate::entity::account::{UserAccountEntity, UserSettingsEntity, NewUserAccountEntity, NewUserSettingsEntity, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM};
use crate::entity::item::{NewItemEntity, ItemEntity, ItemDetail, ItemLocation};
use crate::entity::item::weapon::Weapon;
use crate::entity::item::armor::Armor;
use crate::entity::item::tech::Technique;
use crate::entity::item::tool::Tool;
use crate::entity::item::mag::{Mag, MagType};
use crate::entity::character::{CharacterEntity, CharacterClass, TechLevel};
use crate::entity::character::{CharacterEntity, NewCharacterEntity, CharacterClass, TechLevel};
use crate::login::login::get_login_status;
@ -198,7 +198,7 @@ fn new_character<EG: EntityGateway>(entity_gateway: &mut EG, user: &UserAccountE
_ => {}
}
entity_gateway.set_character(&mut character);
let character = entity_gateway.create_character(character).unwrap();
let new_weapon = match character.char_class {
CharacterClass::HUmar | CharacterClass::HUnewearl | CharacterClass::HUcast | CharacterClass::HUcaseal => item::weapon::WeaponType::Saber,
@ -207,9 +207,8 @@ fn new_character<EG: EntityGateway>(entity_gateway: &mut EG, user: &UserAccountE
};
entity_gateway.set_item(
&mut ItemEntity {
id: None,
entity_gateway.create_item(
NewItemEntity {
item : ItemDetail::Weapon(
Weapon {
weapon: new_weapon,
@ -219,14 +218,13 @@ fn new_character<EG: EntityGateway>(entity_gateway: &mut EG, user: &UserAccountE
tekked: true,
}),
location: ItemLocation::Inventory {
character_id: character.id.unwrap(),
character_id: character.id,
index: 0,
equipped: true,
}});
entity_gateway.set_item(
&mut ItemEntity {
id: None,
entity_gateway.create_item(
NewItemEntity {
item: ItemDetail::Armor (
Armor {
armor: item::armor::ArmorType::Frame,
@ -235,14 +233,13 @@ fn new_character<EG: EntityGateway>(entity_gateway: &mut EG, user: &UserAccountE
slots: 0,
}),
location: ItemLocation::Inventory {
character_id: character.id.unwrap(),
character_id: character.id,
index: 1,
equipped: true,
}});
entity_gateway.set_item(
&mut ItemEntity {
id: None,
entity_gateway.create_item(
NewItemEntity {
item: ItemDetail::Mag(
Mag {
mag: MagType::Mag,
@ -255,33 +252,31 @@ fn new_character<EG: EntityGateway>(entity_gateway: &mut EG, user: &UserAccountE
photon_blast: [None; 3],
}),
location: ItemLocation::Inventory {
character_id: character.id.unwrap(),
character_id: character.id,
index: 2,
equipped: true,
}});
for _ in 0..4 {
entity_gateway.set_item(
&mut ItemEntity {
id: None,
entity_gateway.create_item(
NewItemEntity {
item: ItemDetail::Tool (
Tool {
tool: item::tool::ToolType::Monomate,
}),
location: ItemLocation::Inventory {
character_id: character.id.unwrap(),
character_id: character.id,
index: 3,
equipped: false,
}});
entity_gateway.set_item(
&mut ItemEntity {
id: None,
entity_gateway.create_item(
NewItemEntity {
item: ItemDetail::Tool (
Tool {
tool: item::tool::ToolType::Monofluid,
}),
location: ItemLocation::Inventory {
character_id: character.id.unwrap(),
character_id: character.id,
index: 4,
equipped: false,
}});
@ -346,9 +341,8 @@ impl<EG: EntityGateway> CharacterServerState<EG> {
let settings = match self.entity_gateway.get_user_settings_by_user(&user) {
Some(settings) => settings,
None => {
let mut user_settings = UserSettingsEntity::new(user.id.unwrap());
self.entity_gateway.set_user_settings(&mut user_settings);
user_settings
let user_settings = NewUserSettingsEntity::new(user.id);
self.entity_gateway.create_user_settings(user_settings).unwrap()
}
};
@ -437,7 +431,7 @@ impl<EG: EntityGateway> CharacterServerState<EG> {
let client = self.clients.get_mut(&id).ok_or(CharacterError::ClientNotFound(id))?;
let mut user = client.user.as_mut().unwrap();
user.flags = setflag.flags;
self.entity_gateway.set_user(&mut user);
self.entity_gateway.save_user(&user);
Ok(None.into_iter())
}
@ -475,7 +469,7 @@ impl<EG: EntityGateway> CharacterServerState<EG> {
client.session.action = SessionAction::SelectCharacter;
client.session.character_slot = preview.slot as u8;
user.flags = 0;
self.entity_gateway.set_user(&mut user);
self.entity_gateway.save_user(&user);
Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_char_select(user.guildcard,
user.team_id.unwrap_or(1),
client.session)),
@ -568,8 +562,8 @@ impl<EG: EntityGateway> ServerState for CharacterServerState<EG> {
}
fn new_character_from_preview(user: &UserAccountEntity, preview: &CharacterPreview) -> CharacterEntity {
let mut character = CharacterEntity::new(user.id.unwrap());
fn new_character_from_preview(user: &UserAccountEntity, preview: &CharacterPreview) -> NewCharacterEntity {
let mut character = NewCharacterEntity::new(user.id);
character.slot = preview.slot;
character.name = String::from_utf16_lossy(&preview.character.name).trim_matches(char::from(0)).into();
character.section_id = preview.character.section_id.into();
@ -667,8 +661,8 @@ mod test {
impl EntityGateway for TestData {
fn get_user_settings_by_user(&self, user: &UserAccountEntity) -> Option<UserSettingsEntity> {
Some(UserSettingsEntity {
id: Some(UserSettingsId(0)),
user_id: user.id.unwrap(),
id: UserSettingsId(0),
user_id: user.id,
settings: settings::UserSettings::default()
})
}
@ -677,7 +671,7 @@ mod test {
let mut server = CharacterServerState::new(TestData {});
let mut clientstate = ClientState::new();
clientstate.user = Some(UserAccountEntity {
id: Some(UserAccountId(1)),
id: UserAccountId(1),
username: "testuser".to_owned(),
password: bcrypt::hash("mypassword", 5).unwrap(),
guildcard: 0,
@ -719,7 +713,7 @@ mod test {
let TestData = InMemoryGateway::new();
let mut fake_user = ClientState::new();
fake_user.user = Some(UserAccountEntity {
id: Some(UserAccountId(3)),
id: UserAccountId(3),
username: "hi3".to_string(),
password: bcrypt::hash("qwer", 5).unwrap(),
guildcard: 3,

6
src/login/login.rs

@ -175,7 +175,7 @@ mod test {
fn get_user_by_name(&self, name: String) -> Option<UserAccountEntity> {
assert!(name == "testuser");
Some(UserAccountEntity {
id: Some(UserAccountId(1)),
id: UserAccountId(1),
username: "testuser".to_owned(),
password: bcrypt::hash("mypassword", 5).unwrap(),
guildcard: 0,
@ -255,7 +255,7 @@ mod test {
fn get_user_by_name(&self, name: String) -> Option<UserAccountEntity> {
assert!(name == "testuser");
Some(UserAccountEntity {
id: Some(UserAccountId(1)),
id: UserAccountId(1),
username: "testuser".to_owned(),
password: bcrypt::hash("notpassword", 5).unwrap(),
guildcard: 0,
@ -298,7 +298,7 @@ mod test {
fn get_user_by_name(&self, name: String) -> Option<UserAccountEntity> {
assert!(name == "testuser");
Some(UserAccountEntity {
id: Some(UserAccountId(1)),
id: UserAccountId(1),
username: "testuser".to_owned(),
password: bcrypt::hash("mypassword", 5).unwrap(),
guildcard: 0,

28
src/main.rs

@ -18,10 +18,10 @@ use patch::patch::{PatchServerState, generate_patch_tree, load_config, load_motd
use login::login::LoginServerState;
use login::character::CharacterServerState;
use ship::ship::ShipServerState;
use entity::account::{UserAccountEntity, UserSettingsEntity};
use entity::account::{NewUserAccountEntity, NewUserSettingsEntity};
use entity::gateway::{EntityGateway, InMemoryGateway};
use entity::character::CharacterEntity;
use entity::item::{ItemEntity, ItemDetail, ItemLocation};
use entity::character::NewCharacterEntity;
use entity::item::{NewItemEntity, ItemDetail, ItemLocation};
use crate::entity::item;
@ -60,8 +60,7 @@ fn main() {
let mut entity_gateway = InMemoryGateway::new();
for i in 0..5 {
let mut fake_user = UserAccountEntity {
id: None,
let mut fake_user = NewUserAccountEntity {
username: if i == 0 { "hi".to_string() } else { format!("hi{}", i+1) },
password: bcrypt::hash("qwer", 5).unwrap(),
guildcard: i + 1,
@ -71,20 +70,19 @@ fn main() {
created_at: SystemTime::now(),
flags: 0,
};
entity_gateway.set_user(&mut fake_user);
entity_gateway.set_user_settings(&mut UserSettingsEntity::new(fake_user.id.unwrap()));
let mut character = CharacterEntity::new(fake_user.id.unwrap());
let fake_user = entity_gateway.create_user(fake_user).unwrap();
entity_gateway.create_user_settings(NewUserSettingsEntity::new(fake_user.id));
let mut character = NewCharacterEntity::new(fake_user.id);
character.name = format!("Test Char {}", i*2);
entity_gateway.set_character(&mut character);
let mut character = CharacterEntity::new(fake_user.id.unwrap());
entity_gateway.create_character(character);
let mut character = NewCharacterEntity::new(fake_user.id);
character.slot = 2;
character.name = "\tE12345678".into();
character.exp = 80000000;
entity_gateway.set_character(&mut character);
let character = entity_gateway.create_character(character).unwrap();
entity_gateway.set_item(
&mut ItemEntity {
id: None,
entity_gateway.create_item(
NewItemEntity {
item: ItemDetail::Weapon(
item::weapon::Weapon {
weapon: item::weapon::WeaponType::Handgun,
@ -95,7 +93,7 @@ fn main() {
}
),
location: ItemLocation::Inventory {
character_id: character.id.unwrap(),
character_id: character.id,
index: 0,
equipped: true,
}

18
src/ship/items.rs

@ -178,7 +178,7 @@ mod test {
#[test]
fn test_stack_items() {
let item1 = ItemEntity {
id: Some(ItemEntityId(1)),
id: ItemEntityId(1),
location: ItemLocation::Inventory {
character_id: CharacterEntityId(0),
index: 0,
@ -193,7 +193,7 @@ mod test {
})
};
let item2 = ItemEntity {
id: Some(ItemEntityId(2)),
id: ItemEntityId(2),
location: ItemLocation::Inventory {
character_id: CharacterEntityId(0),
index: 1,
@ -204,7 +204,7 @@ mod test {
})
};
let item3 = ItemEntity {
id: Some(ItemEntityId(3)),
id: ItemEntityId(3),
location: ItemLocation::Inventory {
character_id: CharacterEntityId(0),
index: 2,
@ -219,7 +219,7 @@ mod test {
})
};
let item4 = ItemEntity {
id: Some(ItemEntityId(4)),
id: ItemEntityId(4),
location: ItemLocation::Inventory {
character_id: CharacterEntityId(0),
index: 1,
@ -230,7 +230,7 @@ mod test {
})
};
let item5 = ItemEntity {
id: Some(ItemEntityId(5)),
id: ItemEntityId(5),
location: ItemLocation::Inventory {
character_id: CharacterEntityId(0),
index: 1,
@ -241,7 +241,7 @@ mod test {
})
};
let item6 = ItemEntity {
id: Some(ItemEntityId(6)),
id: ItemEntityId(6),
location: ItemLocation::Inventory {
character_id: CharacterEntityId(0),
index: 3,
@ -256,7 +256,7 @@ mod test {
})
};
let item7 = ItemEntity {
id: Some(ItemEntityId(7)),
id: ItemEntityId(7),
location: ItemLocation::Inventory {
character_id: CharacterEntityId(0),
index: 4,
@ -267,7 +267,7 @@ mod test {
})
};
let item8 = ItemEntity {
id: Some(ItemEntityId(8)),
id: ItemEntityId(8),
location: ItemLocation::Inventory {
character_id: CharacterEntityId(0),
index: 4,
@ -278,7 +278,7 @@ mod test {
})
};
let item9 = ItemEntity {
id: Some(ItemEntityId(9)),
id: ItemEntityId(9),
location: ItemLocation::Inventory {
character_id: CharacterEntityId(0),
index: 4,

16
src/ship/ship.rs

@ -171,7 +171,7 @@ impl<EG: EntityGateway> ShipServerState<EG> {
Ok(match get_login_status(&self.entity_gateway, pkt) {
Ok(user) => {
let mut response = LoginResponse::by_status(AccountStatus::Ok, Session::new());
response.guildcard = user.id.unwrap().0 as u32;
response.guildcard = user.id.0 as u32;
response.team_id = user.team_id.map_or(31, |ti| ti) as u32;
let characters = self.entity_gateway.get_characters_by_user(&user);
let character = characters
@ -233,7 +233,7 @@ impl<EG: EntityGateway> ShipServerState<EG> {
PlayerInfo {
header: PlayerHeader {
tag: 0x100,
guildcard: client.user.id.unwrap().0,
guildcard: client.user.id.0,
_unknown1: [0; 5],
client_id: room_client.index as u32,
name: c.name,
@ -289,7 +289,7 @@ impl<EG: EntityGateway> ShipServerState<EG> {
playerinfo: PlayerInfo {
header: PlayerHeader {
tag: 0x100,
guildcard: client.user.id.unwrap().0,
guildcard: client.user.id.0,
_unknown1: [0; 5],
client_id: client_id as u32,
name: c.name,
@ -336,7 +336,7 @@ impl<EG: EntityGateway> ShipServerState<EG> {
msg: GameMessage::GuildcardRecv(GuildcardRecv {
client: guildcard_send.client,
target: guildcard_send.target,
guildcard: client.user.id.unwrap().0,
guildcard: client.user.id.0,
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),
@ -365,7 +365,7 @@ impl<EG: EntityGateway> ShipServerState<EG> {
fn player_chat(&mut self, id: ClientId, msg: &PlayerChat) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
let cmsg = PlayerChat::new(client.user.id.unwrap().0, msg.message.clone());
let cmsg = PlayerChat::new(client.user.id.0, msg.message.clone());
Ok(Box::new(self.client_location.get_area_by_user(id).clients().iter()
.map(move |client| {
@ -392,7 +392,7 @@ impl<EG: EntityGateway> ShipServerState<EG> {
let client = self.clients.get_mut(&id).unwrap();//.ok_or(ShipError::ClientNotFound(id)).unwrap();
let players = [PlayerHeader {
tag: 0x00010000,
guildcard: client.user.id.unwrap().0,
guildcard: client.user.id.0,
_unknown1: [0; 5],
client_id: 0,
name: libpso::utf8_to_utf16_array!(client.character.name, 16),
@ -434,7 +434,7 @@ impl<EG: EntityGateway> ShipServerState<EG> {
fn update_config(&mut self, id: ClientId, update_config: &UpdateConfig) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
client.character.config.update(update_config);
self.entity_gateway.set_character(&mut client.character);
self.entity_gateway.save_character(&client.character);
Box::new(None.into_iter())
}
@ -460,7 +460,7 @@ impl<EG: EntityGateway> ShipServerState<EG> {
fn write_infoboard(&mut self, id: ClientId, new_infoboard: &WriteInfoboard) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
client.character.info_board.update_infoboard(new_infoboard);
self.entity_gateway.set_character(&mut client.character);
self.entity_gateway.save_character(&client.character);
Box::new(None.into_iter())
}

Loading…
Cancel
Save