fix this keyconfig nonsense
This commit is contained in:
parent
31ebc1af32
commit
d495ec97f2
@ -64,12 +64,12 @@ fn main() {
|
||||
};
|
||||
let fake_user = entity_gateway.create_user(fake_user).await.unwrap();
|
||||
entity_gateway.create_user_settings(NewUserSettingsEntity::new(fake_user.id)).await.unwrap();
|
||||
let mut character = NewCharacterEntity::new(fake_user.id, 1);
|
||||
let mut character = NewCharacterEntity::new(fake_user.id);
|
||||
character.name = format!("Test Char {}", i*2);
|
||||
let character = entity_gateway.create_character(character).await.unwrap();
|
||||
entity_gateway.set_character_meseta(&character.id, item::Meseta(999999)).await.unwrap();
|
||||
entity_gateway.set_bank_meseta(&character.id, &item::BankName("".into()), item::Meseta(999999)).await.unwrap();
|
||||
let mut character = NewCharacterEntity::new(fake_user.id, 1);
|
||||
let mut character = NewCharacterEntity::new(fake_user.id);
|
||||
character.slot = 2;
|
||||
character.name = "ItemRefactor".into();
|
||||
character.exp = 80000000;
|
||||
|
@ -264,82 +264,6 @@ pub struct CharacterMaterials {
|
||||
pub tp: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CharacterKeyboardConfig {
|
||||
pub keyboard_config: [u8; 0x16C],
|
||||
}
|
||||
|
||||
impl Default for CharacterKeyboardConfig {
|
||||
fn default() -> CharacterKeyboardConfig {
|
||||
CharacterKeyboardConfig {
|
||||
keyboard_config: DEFAULT_KEYBOARD_CONFIG1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CharacterKeyboardConfig {
|
||||
fn new(preset: usize) -> CharacterKeyboardConfig {
|
||||
match preset {
|
||||
1 => {
|
||||
CharacterKeyboardConfig {
|
||||
keyboard_config: DEFAULT_KEYBOARD_CONFIG1,
|
||||
}
|
||||
},
|
||||
2 => {
|
||||
CharacterKeyboardConfig {
|
||||
keyboard_config: DEFAULT_KEYBOARD_CONFIG2,
|
||||
}
|
||||
},
|
||||
3 => {
|
||||
CharacterKeyboardConfig {
|
||||
keyboard_config: DEFAULT_KEYBOARD_CONFIG3,
|
||||
}
|
||||
},
|
||||
4 => {
|
||||
CharacterKeyboardConfig {
|
||||
keyboard_config: DEFAULT_KEYBOARD_CONFIG4,
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
CharacterKeyboardConfig {
|
||||
keyboard_config: DEFAULT_KEYBOARD_CONFIG1,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, new_config: &KeyboardConfig) {
|
||||
self.keyboard_config = new_config.keyboard_config;
|
||||
}
|
||||
|
||||
pub fn as_bytes(&self) -> [u8; 0x16C] {
|
||||
self.keyboard_config
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CharacterGamepadConfig {
|
||||
pub gamepad_config: [u8; 0x38],
|
||||
}
|
||||
|
||||
impl Default for CharacterGamepadConfig {
|
||||
fn default() -> CharacterGamepadConfig {
|
||||
CharacterGamepadConfig {
|
||||
gamepad_config: DEFAULT_GAMEPAD_CONFIG,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CharacterGamepadConfig {
|
||||
pub fn update(&mut self, new_config: &GamepadConfig) {
|
||||
self.gamepad_config = new_config.gamepad_config;
|
||||
}
|
||||
|
||||
pub fn as_bytes(&self) -> [u8; 0x38] {
|
||||
self.gamepad_config
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default, derive_more::Display)]
|
||||
pub struct CharacterEntityId(pub u32);
|
||||
|
||||
@ -363,12 +287,10 @@ pub struct NewCharacterEntity {
|
||||
|
||||
pub tech_menu: CharacterTechMenu,
|
||||
pub option_flags: u32,
|
||||
pub keyboard_config: CharacterKeyboardConfig,
|
||||
pub gamepad_config: CharacterGamepadConfig,
|
||||
}
|
||||
|
||||
impl NewCharacterEntity {
|
||||
pub fn new(user: UserAccountId, keyboard_config_preset: usize,) -> NewCharacterEntity {
|
||||
pub fn new(user: UserAccountId) -> NewCharacterEntity {
|
||||
NewCharacterEntity {
|
||||
user_id: user,
|
||||
slot: 0,
|
||||
@ -384,8 +306,6 @@ impl NewCharacterEntity {
|
||||
materials: CharacterMaterials::default(),
|
||||
tech_menu: CharacterTechMenu::default(),
|
||||
option_flags: 0,
|
||||
keyboard_config: CharacterKeyboardConfig::new(keyboard_config_preset),
|
||||
gamepad_config: CharacterGamepadConfig::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -411,8 +331,6 @@ pub struct CharacterEntity {
|
||||
|
||||
pub tech_menu: CharacterTechMenu,
|
||||
pub option_flags: u32,
|
||||
pub keyboard_config: CharacterKeyboardConfig,
|
||||
pub gamepad_config: CharacterGamepadConfig,
|
||||
|
||||
pub playtime: u32,
|
||||
}
|
||||
|
@ -452,8 +452,6 @@ impl EntityGateway for InMemoryGateway {
|
||||
materials: character.materials,
|
||||
tech_menu: character.tech_menu,
|
||||
option_flags: character.option_flags,
|
||||
keyboard_config: character.keyboard_config,
|
||||
gamepad_config: character.gamepad_config,
|
||||
playtime: 0,
|
||||
};
|
||||
characters.insert(new_character.id, new_character.clone());
|
||||
|
@ -0,0 +1,3 @@
|
||||
alter table player_character
|
||||
drop column keyboard_config,
|
||||
drop column gamepad_config;
|
@ -217,8 +217,6 @@ pub struct PgCharacter {
|
||||
tp: i16,
|
||||
|
||||
tech_menu: Vec<u8>,
|
||||
keyboard_config: Vec<u8>,
|
||||
gamepad_config: Vec<u8>,
|
||||
|
||||
playtime: i32,
|
||||
}
|
||||
@ -270,12 +268,6 @@ impl From<PgCharacter> for CharacterEntity {
|
||||
tech_menu: CharacterTechMenu {
|
||||
tech_menu: vec_to_array(other.tech_menu)
|
||||
},
|
||||
keyboard_config: CharacterKeyboardConfig {
|
||||
keyboard_config: vec_to_array(other.keyboard_config)
|
||||
},
|
||||
gamepad_config: CharacterGamepadConfig {
|
||||
gamepad_config: vec_to_array(other.gamepad_config)
|
||||
},
|
||||
playtime: other.playtime as u32,
|
||||
}
|
||||
}
|
||||
|
@ -229,8 +229,7 @@ async fn create_character(conn: &mut sqlx::PgConnection, char: NewCharacterEntit
|
||||
hair, hair_r, hair_g, hair_b, prop_x,
|
||||
prop_y, techs, config, infoboard, guildcard,
|
||||
power, mind, def, evade, luck,
|
||||
hp, tp, tech_menu, option_flags, keyboard_config,
|
||||
gamepad_config, playtime)
|
||||
hp, tp, tech_menu, option_flags, playtime)
|
||||
values
|
||||
($1, $2, $3, $4, $5,
|
||||
$6, $7, $8, $9, $10,
|
||||
@ -270,8 +269,6 @@ async fn create_character(conn: &mut sqlx::PgConnection, char: NewCharacterEntit
|
||||
.bind(char.materials.tp as i16)
|
||||
.bind(char.tech_menu.tech_menu.to_vec())
|
||||
.bind(char.option_flags as i32)
|
||||
.bind(&char.keyboard_config.keyboard_config.to_vec())
|
||||
.bind(&char.gamepad_config.gamepad_config.to_vec())
|
||||
.bind(0)
|
||||
.fetch_one(conn).await?;
|
||||
|
||||
@ -298,8 +295,8 @@ async fn save_character(conn: &mut sqlx::PgConnection, char: &CharacterEntity) -
|
||||
let q = r#"update player_character set
|
||||
user_account=$1, slot=$2, name=$3, exp=$4, class=$5, section_id=$6, costume=$7, skin=$8, face=$9, head=$10, hair=$11, hair_r=$12,
|
||||
hair_g=$13, hair_b=$14, prop_x=$15, prop_y=$16, techs=$17, config=$18, infoboard=$19, guildcard=$20, power=$21, mind=$22, def=$23,
|
||||
evade=$24, luck=$25, hp=$26, tp=$27, tech_menu=$28, option_flags=$29, keyboard_config=$30, gamepad_config=$31, playtime=$32
|
||||
where id=$33;"#;
|
||||
evade=$24, luck=$25, hp=$26, tp=$27, tech_menu=$28, option_flags=$29, playtime=$30
|
||||
where id=$31;"#;
|
||||
sqlx::query(q)
|
||||
.bind(char.user_id.0) // $1
|
||||
.bind(char.slot as i16) // $2
|
||||
@ -330,10 +327,8 @@ async fn save_character(conn: &mut sqlx::PgConnection, char: &CharacterEntity) -
|
||||
.bind(char.materials.tp as i16) // $27
|
||||
.bind(char.tech_menu.tech_menu.to_vec()) // $28
|
||||
.bind(char.option_flags as i32) // $29
|
||||
.bind(&char.keyboard_config.keyboard_config.to_vec()) // $30
|
||||
.bind(&char.gamepad_config.gamepad_config.to_vec()) // $31
|
||||
.bind(char.playtime as i32) // $32
|
||||
.bind(char.id.0 as i32) // $33
|
||||
.bind(char.playtime as i32) // $30
|
||||
.bind(char.id.0 as i32) // $31
|
||||
.execute(conn).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -747,7 +747,7 @@ impl<EG: EntityGateway + Clone> InterserverActor for CharacterServerState<EG> {
|
||||
|
||||
|
||||
fn new_character_from_preview(user: &UserAccountEntity, preview: &CharacterPreview) -> NewCharacterEntity {
|
||||
let mut character = NewCharacterEntity::new(user.id, 1); // it should not be possible for the client to specify the kbm config preset from the char create screen
|
||||
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();
|
||||
|
@ -113,7 +113,7 @@ where
|
||||
move |(mut item_state, mut transaction), _| {
|
||||
Box::pin(async move {
|
||||
let mut inventory = item_state.inventory(&character_id).await?;
|
||||
let item = inventory.take_item(&item_id, amount).ok_or_else(|| ItemStateError::NoFloorItem(item_id))?;
|
||||
let item = inventory.take_item(&item_id, amount).ok_or_else(|| ItemStateError::NoInventoryItem(item_id))?;
|
||||
|
||||
transaction.gateway().set_character_inventory(&character_id, &inventory.as_inventory_entity(&character_id)).await?;
|
||||
item_state.set_inventory(inventory).await;
|
||||
|
@ -34,8 +34,8 @@ pub async fn block_selected(id: ClientId,
|
||||
.meseta(inventory.meseta)
|
||||
.inventory(&inventory)
|
||||
.bank(&bank)
|
||||
.keyboard_config(&client.character.keyboard_config.as_bytes())
|
||||
.gamepad_config(&client.character.gamepad_config.as_bytes())
|
||||
.keyboard_config(&client.settings.settings.keyboard_config)
|
||||
.gamepad_config(&client.settings.settings.gamepad_config)
|
||||
.symbol_chat(&client.settings.settings.symbol_chats)
|
||||
.tech_menu(&client.character.tech_menu.as_bytes())
|
||||
.option_flags(client.character.option_flags)
|
||||
|
@ -48,8 +48,8 @@ where
|
||||
clients.with_mut(id, |client| {
|
||||
let mut entity_gateway = entity_gateway.clone();
|
||||
Box::pin(async move {
|
||||
client.character.keyboard_config.update(&keyboard_config);
|
||||
entity_gateway.save_character(&client.character).await
|
||||
client.settings.settings.keyboard_config = keyboard_config.keyboard_config;
|
||||
entity_gateway.save_user_settings(&client.settings).await
|
||||
})}).await??;
|
||||
Ok(Vec::new())
|
||||
}
|
||||
@ -65,8 +65,8 @@ where
|
||||
clients.with_mut(id, |client| {
|
||||
let mut entity_gateway = entity_gateway.clone();
|
||||
Box::pin(async move {
|
||||
client.character.gamepad_config.update(&gamepad_config);
|
||||
entity_gateway.save_character(&client.character).await
|
||||
client.settings.settings.gamepad_config = gamepad_config.gamepad_config;
|
||||
entity_gateway.save_user_settings(&client.settings).await
|
||||
})}).await??;
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ use libpso::packet::login::{Login, Session};
|
||||
use libpso::{utf8_to_array, utf8_to_utf16_array};
|
||||
|
||||
|
||||
//TODO: remove kb_conf_preset
|
||||
pub async fn new_user_character<EG: EntityGateway + Clone>(entity_gateway: &mut EG, username: &str, password: &str, kb_conf_preset: usize) -> (UserAccountEntity, CharacterEntity) {
|
||||
let new_user = NewUserAccountEntity {
|
||||
email: format!("{}@pso.com", username),
|
||||
@ -26,7 +27,7 @@ pub async fn new_user_character<EG: EntityGateway + Clone>(entity_gateway: &mut
|
||||
let user = entity_gateway.create_user(new_user).await.unwrap();
|
||||
let new_settings = NewUserSettingsEntity::new(user.id);
|
||||
let _settings = entity_gateway.create_user_settings(new_settings).await.unwrap();
|
||||
let new_character = NewCharacterEntity::new(user.id, kb_conf_preset);
|
||||
let new_character = NewCharacterEntity::new(user.id);
|
||||
let character = entity_gateway.create_character(new_character).await.unwrap();
|
||||
entity_gateway.set_character_meseta(&character.id, Meseta(0)).await.unwrap();
|
||||
entity_gateway.set_bank_meseta(&character.id, &BankName("".into()), Meseta(0)).await.unwrap();
|
||||
|
@ -31,26 +31,6 @@ async fn test_save_options() {
|
||||
assert!(char.option_flags == 12345);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_default3_keyboard_mappings() {
|
||||
/*
|
||||
check if keyboard is set to default3 when specified. this will only occur for things like creating characters from the web page.
|
||||
normal client behaviour will simply use default1 when creating a character.
|
||||
gamepad only has 1 default config
|
||||
*/
|
||||
let mut entity_gateway = InMemoryGateway::default();
|
||||
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 3).await;
|
||||
assert!(char1.keyboard_config.as_bytes() == DEFAULT_KEYBOARD_CONFIG3);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_invalid_keyboard_preset_value() {
|
||||
// check if keyboard_config self-corrects to DEFAULT1 if an invalid value (>4) is given
|
||||
let mut entity_gateway = InMemoryGateway::default();
|
||||
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 10).await;
|
||||
assert!(char1.keyboard_config.as_bytes() == DEFAULT_KEYBOARD_CONFIG1);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_change_keyboard_mappings() {
|
||||
let mut entity_gateway = InMemoryGateway::default();
|
||||
@ -63,7 +43,8 @@ async fn test_change_keyboard_mappings() {
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
|
||||
assert!(char1.keyboard_config.as_bytes() == DEFAULT_KEYBOARD_CONFIG2);
|
||||
let settings = entity_gateway.get_user_settings_by_user(&user1).await.unwrap();
|
||||
assert!(settings.settings.keyboard_config == DEFAULT_KEYBOARD_CONFIG1);
|
||||
|
||||
// update from default2 to default4
|
||||
// the client simply sends the full 364 bytes...
|
||||
@ -95,8 +76,6 @@ async fn test_change_keyboard_mappings() {
|
||||
],
|
||||
})).await.unwrap();
|
||||
|
||||
let characters = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
||||
let char = characters[0].as_ref().unwrap();
|
||||
|
||||
assert!(char.keyboard_config.as_bytes() == DEFAULT_KEYBOARD_CONFIG4);
|
||||
let settings = entity_gateway.get_user_settings_by_user(&user1).await.unwrap();
|
||||
assert!(settings.settings.keyboard_config == DEFAULT_KEYBOARD_CONFIG4);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user