Compare commits

...

2 Commits

Author SHA1 Message Date
17f89182c4 all hunters are cool, not just humars
All checks were successful
continuous-integration/drone/push Build is passing
2022-07-18 18:49:43 +00:00
9fb2da6518 only save exp instead of entire character. fix db issues 2022-07-18 18:42:18 +00:00
7 changed files with 46 additions and 20 deletions

View File

@ -131,4 +131,8 @@ pub trait EntityGateway: Send + Sync + Clone {
async fn set_bank_meseta(&mut self, _char_id: &CharacterEntityId, _bank: BankName, _amount: Meseta) -> Result<(), GatewayError> { async fn set_bank_meseta(&mut self, _char_id: &CharacterEntityId, _bank: BankName, _amount: Meseta) -> Result<(), GatewayError> {
unimplemented!(); unimplemented!();
} }
async fn set_character_exp(&mut self, _char_id: &CharacterEntityId, _exp: u32) -> Result<(), GatewayError> {
unimplemented!();
}
} }

View File

@ -349,4 +349,14 @@ impl EntityGateway for InMemoryGateway {
Err(GatewayError::Error) Err(GatewayError::Error)
} }
} }
async fn set_character_exp(&mut self, char_id: &CharacterEntityId, exp: u32) -> Result<(), GatewayError> {
let mut chars = self.characters.lock().unwrap();
if let Some(character) = chars.get_mut(char_id) {
character.exp = exp;
Ok(())
} else {
Err(GatewayError::Error)
}
}
} }

View File

@ -19,8 +19,8 @@ create table user_settings (
id serial primary key not null, id serial primary key not null,
user_account integer references user_accounts (id) not null, user_account integer references user_accounts (id) not null,
blocked_users bytea not null, blocked_users bytea not null,
key_config bytea not null, keyboard_config bytea not null,
joystick_config bytea not null, gamepad_config bytea not null,
option_flags integer not null, option_flags integer not null,
shortcuts bytea not null, shortcuts bytea not null,
symbol_chats bytea not null, symbol_chats bytea not null,
@ -65,12 +65,10 @@ create table player_character (
tp smallint not null, tp smallint not null,
tech_menu bytea not null, tech_menu bytea not null,
meseta integer not null, keyboard_config bytea not null,
bank_meseta integer not null gamepad_config bytea not null
); );
create table item ( create table item (
id serial primary key not null, id serial primary key not null,
item jsonb not null item jsonb not null

View File

@ -1,4 +1,4 @@
drop table item_location; drop table if exists item_location;
create table item_note ( create table item_note (
item integer references item (id) not null, item integer references item (id) not null,

View File

@ -1,15 +1,16 @@
create table character_meseta ( create table character_meseta (
pchar integer references character (id) not null unique, pchar integer references player_character (id) not null unique,
meseta integer not null, meseta integer not null
); );
create table bank_meseta ( create table bank_meseta (
pchar integer references character (id) not null, pchar integer references player_character (id) not null,
bank varchar(128) not null, bank varchar(128) not null,
meseta integer not null, meseta integer not null,
unique (pchar, bank) unique (pchar, bank)
); );
alter table player_character alter table if exists player_character
drop column meseta, bank_meseta; drop column if exists meseta,
drop column if exists bank_meseta;

View File

@ -182,7 +182,7 @@ impl EntityGateway for PostgresGateway {
async fn create_character(&mut self, char: NewCharacterEntity) -> Result<CharacterEntity, GatewayError> { async fn create_character(&mut self, char: NewCharacterEntity) -> Result<CharacterEntity, GatewayError> {
let q = r#"insert into player_character let q = r#"insert into player_character
(user_account, slot, name, exp, class, section_id, costume, skin, face, head, hair, hair_r, hair_g, hair_b, prop_x, prop_y, techs, (user_account, slot, name, exp, class, section_id, costume, skin, face, head, 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) config, infoboard, guildcard, option_flags, power, mind, def, evade, luck, hp, tp, tech_menu, keyboard_config, gamepad_config)
values values
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31) ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31)
returning *;"#; returning *;"#;
@ -207,6 +207,7 @@ impl EntityGateway for PostgresGateway {
.bind(&char.config.as_bytes().to_vec()) .bind(&char.config.as_bytes().to_vec())
.bind(String::from_utf16_lossy(&char.info_board.board).trim_matches(char::from(0))) .bind(String::from_utf16_lossy(&char.info_board.board).trim_matches(char::from(0)))
.bind(char.guildcard.description) .bind(char.guildcard.description)
.bind(char.option_flags as i32)
.bind(char.materials.power as i16) .bind(char.materials.power as i16)
.bind(char.materials.mind as i16) .bind(char.materials.mind as i16)
.bind(char.materials.def as i16) .bind(char.materials.def as i16)
@ -215,7 +216,8 @@ impl EntityGateway for PostgresGateway {
.bind(char.materials.hp as i16) .bind(char.materials.hp as i16)
.bind(char.materials.tp as i16) .bind(char.materials.tp as i16)
.bind(char.tech_menu.tech_menu.to_vec()) .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())
.fetch_one(&self.pool).await?; .fetch_one(&self.pool).await?;
Ok(character.into()) Ok(character.into())
@ -548,7 +550,7 @@ impl EntityGateway for PostgresGateway {
} }
async fn set_character_meseta(&mut self, char_id: &CharacterEntityId, meseta: Meseta) -> Result<(), GatewayError> { async fn set_character_meseta(&mut self, char_id: &CharacterEntityId, meseta: Meseta) -> Result<(), GatewayError> {
sqlx::query("insert into character_meseta values ($1, $2) on conflict (pchar) do update set items = $2") sqlx::query("insert into character_meseta values ($1, $2) on conflict (pchar) do update set meseta = $2")
.bind(char_id.0) .bind(char_id.0)
.bind(meseta.0 as i32) .bind(meseta.0 as i32)
.execute(&self.pool) .execute(&self.pool)
@ -559,7 +561,7 @@ impl EntityGateway for PostgresGateway {
async fn get_character_meseta(&mut self, char_id: &CharacterEntityId) -> Result<Meseta, GatewayError> { async fn get_character_meseta(&mut self, char_id: &CharacterEntityId) -> Result<Meseta, GatewayError> {
#[derive(sqlx::FromRow)] #[derive(sqlx::FromRow)]
struct PgMeseta(i32); struct PgMeseta(i32);
let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where id = $1"#) let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where pchar = $1"#)
.bind(char_id.0) .bind(char_id.0)
.fetch_one(&self.pool) .fetch_one(&self.pool)
.await?; .await?;
@ -567,10 +569,10 @@ impl EntityGateway for PostgresGateway {
} }
async fn set_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName, meseta: Meseta) -> Result<(), GatewayError> { async fn set_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName, meseta: Meseta) -> Result<(), GatewayError> {
sqlx::query("insert into bank_meseta values ($1, $2, $3) on conflict (pchar, bank) do update set items = $2") sqlx::query("insert into bank_meseta values ($1, $2, $3) on conflict (pchar, bank) do update set meseta = $3")
.bind(char_id.0) .bind(char_id.0)
.bind(meseta.0 as i32)
.bind(bank.0) .bind(bank.0)
.bind(meseta.0 as i32)
.execute(&self.pool) .execute(&self.pool)
.await?; .await?;
Ok(()) Ok(())
@ -579,11 +581,21 @@ impl EntityGateway for PostgresGateway {
async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName) -> Result<Meseta, GatewayError> { async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName) -> Result<Meseta, GatewayError> {
#[derive(sqlx::FromRow)] #[derive(sqlx::FromRow)]
struct PgMeseta(i32); struct PgMeseta(i32);
let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where id = $1 and bank = $2"#) let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from bank_meseta where pchar = $1 and bank = $2"#)
.bind(char_id.0) .bind(char_id.0)
.bind(bank.0) .bind(bank.0)
.fetch_one(&self.pool) .fetch_one(&self.pool)
.await?; .await?;
Ok(Meseta(meseta.0 as u32)) Ok(Meseta(meseta.0 as u32))
} }
async fn set_character_exp(&mut self, char_id: &CharacterEntityId, exp: u32) -> Result<(), GatewayError> {
let q = r#"update player_character set exp=$1 where id=$2;"#;
sqlx::query(q)
.bind(exp as i32)
.bind(char_id.0 as i32)
.execute(&self.pool)
.await?;
Ok(())
}
} }

View File

@ -57,7 +57,8 @@ pub async fn request_exp<EG: EntityGateway>(id: ClientId,
} }
client.character.exp += exp_gain; client.character.exp += exp_gain;
entity_gateway.save_character(&client.character).await?; // entity_gateway.save_character(&client.character).await?;
entity_gateway.set_character_exp(&client.character.id, client.character.exp).await?;
Ok(exp_pkts) Ok(exp_pkts)
} }