|
@ -1,15 +1,16 @@ |
|
|
// this lint is currently bugged and suggests incorrect code https://github.com/rust-lang/rust-clippy/issues/9123
|
|
|
// this lint is currently bugged and suggests incorrect code https://github.com/rust-lang/rust-clippy/issues/9123
|
|
|
#![allow(clippy::explicit_auto_deref)]
|
|
|
#![allow(clippy::explicit_auto_deref)]
|
|
|
|
|
|
|
|
|
use std::convert::{From, TryFrom, Into};
|
|
|
|
|
|
|
|
|
use std::convert::{From, Into};
|
|
|
use futures::future::{Future, BoxFuture};
|
|
|
use futures::future::{Future, BoxFuture};
|
|
|
use futures::stream::{StreamExt, FuturesOrdered};
|
|
|
use futures::stream::{StreamExt, FuturesOrdered};
|
|
|
use async_std::sync::{Arc, Mutex};
|
|
|
use async_std::sync::{Arc, Mutex};
|
|
|
use libpso::character::guildcard;
|
|
|
use libpso::character::guildcard;
|
|
|
use crate::entity::account::*;
|
|
|
|
|
|
use crate::entity::character::*;
|
|
|
|
|
|
use crate::entity::gateway::{EntityGateway, EntityGatewayTransaction, GatewayError};
|
|
|
|
|
|
use crate::entity::item::*;
|
|
|
|
|
|
|
|
|
use crate::account::*;
|
|
|
|
|
|
use crate::character::*;
|
|
|
|
|
|
use crate::gateway::{EntityGateway, EntityGatewayTransaction, GatewayError};
|
|
|
|
|
|
use crate::item::*;
|
|
|
|
|
|
use crate::room::*;
|
|
|
use super::models::*;
|
|
|
use super::models::*;
|
|
|
|
|
|
|
|
|
use sqlx::postgres::PgPoolOptions;
|
|
|
use sqlx::postgres::PgPoolOptions;
|
|
@ -18,7 +19,7 @@ use sqlx::Connection; |
|
|
|
|
|
|
|
|
mod embedded {
|
|
|
mod embedded {
|
|
|
use refinery::embed_migrations;
|
|
|
use refinery::embed_migrations;
|
|
|
embed_migrations!("src/entity/gateway/postgres/migrations");
|
|
|
|
|
|
|
|
|
embed_migrations!("src/gateway/postgres/migrations");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -178,7 +179,7 @@ async fn create_user(conn: &mut sqlx::PgConnection, user: NewUserAccountEntity) |
|
|
async fn get_user_by_id(conn: &mut sqlx::PgConnection, id: UserAccountId) -> Result<UserAccountEntity, GatewayError>
|
|
|
async fn get_user_by_id(conn: &mut sqlx::PgConnection, id: UserAccountId) -> Result<UserAccountEntity, GatewayError>
|
|
|
{
|
|
|
{
|
|
|
let user = sqlx::query_as::<_, PgUserAccount>("select * from user_accounts where id = $1")
|
|
|
let user = sqlx::query_as::<_, PgUserAccount>("select * from user_accounts where id = $1")
|
|
|
.bind(id.0)
|
|
|
|
|
|
|
|
|
.bind(id.0 as i32)
|
|
|
.fetch_one(conn).await?;
|
|
|
.fetch_one(conn).await?;
|
|
|
Ok(user.into())
|
|
|
Ok(user.into())
|
|
|
}
|
|
|
}
|
|
@ -199,8 +200,8 @@ async fn save_user(conn: &mut sqlx::PgConnection, user: &UserAccountEntity) -> R |
|
|
.bind(&user.password)
|
|
|
.bind(&user.password)
|
|
|
.bind(user.banned_until)
|
|
|
.bind(user.banned_until)
|
|
|
.bind(user.muted_until)
|
|
|
.bind(user.muted_until)
|
|
|
.bind(user.flags)
|
|
|
|
|
|
.bind(user.id.0)
|
|
|
|
|
|
|
|
|
.bind(user.flags as i32)
|
|
|
|
|
|
.bind(user.id.0 as i32)
|
|
|
.execute(conn).await?;
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
@ -209,7 +210,7 @@ async fn create_user_settings(conn: &mut sqlx::PgConnection, settings: NewUserSe |
|
|
{
|
|
|
{
|
|
|
let new_settings = sqlx::query_as::<_, PgUserSettings>("insert into user_settings (user_account, blocked_users, key_config, joystick_config, option_flags, shortcuts, symbol_chats, team_name)
|
|
|
let new_settings = sqlx::query_as::<_, PgUserSettings>("insert into user_settings (user_account, blocked_users, key_config, joystick_config, option_flags, shortcuts, symbol_chats, team_name)
|
|
|
values ($1, $2, $3, $4, $5, $6, $7, $8) returning *;")
|
|
|
values ($1, $2, $3, $4, $5, $6, $7, $8) returning *;")
|
|
|
.bind(settings.user_id.0)
|
|
|
|
|
|
|
|
|
.bind(settings.user_id.0 as i32)
|
|
|
.bind(settings.settings.blocked_users.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
|
.bind(settings.settings.blocked_users.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
|
.bind(settings.settings.keyboard_config.to_vec())
|
|
|
.bind(settings.settings.keyboard_config.to_vec())
|
|
|
.bind(settings.settings.gamepad_config.to_vec())
|
|
|
.bind(settings.settings.gamepad_config.to_vec())
|
|
@ -224,7 +225,7 @@ async fn create_user_settings(conn: &mut sqlx::PgConnection, settings: NewUserSe |
|
|
async fn get_user_settings_by_user(conn: &mut sqlx::PgConnection, user: &UserAccountEntity) -> Result<UserSettingsEntity, GatewayError>
|
|
|
async fn get_user_settings_by_user(conn: &mut sqlx::PgConnection, user: &UserAccountEntity) -> Result<UserSettingsEntity, GatewayError>
|
|
|
{
|
|
|
{
|
|
|
let settings = sqlx::query_as::<_, PgUserSettings>("select * from user_settings where user_account = $1")
|
|
|
let settings = sqlx::query_as::<_, PgUserSettings>("select * from user_settings where user_account = $1")
|
|
|
.bind(user.id.0)
|
|
|
|
|
|
|
|
|
.bind(user.id.0 as i32)
|
|
|
.fetch_one(conn).await?;
|
|
|
.fetch_one(conn).await?;
|
|
|
Ok(settings.into())
|
|
|
Ok(settings.into())
|
|
|
}
|
|
|
}
|
|
@ -235,11 +236,11 @@ async fn save_user_settings(conn: &mut sqlx::PgConnection, settings: &UserSettin |
|
|
.bind(settings.settings.blocked_users.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
|
.bind(settings.settings.blocked_users.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
|
.bind(&settings.settings.keyboard_config.to_vec())
|
|
|
.bind(&settings.settings.keyboard_config.to_vec())
|
|
|
.bind(&settings.settings.gamepad_config.to_vec())
|
|
|
.bind(&settings.settings.gamepad_config.to_vec())
|
|
|
.bind(settings.settings.option_flags)
|
|
|
|
|
|
|
|
|
.bind(settings.settings.option_flags as i32)
|
|
|
.bind(&settings.settings.shortcuts.to_vec())
|
|
|
.bind(&settings.settings.shortcuts.to_vec())
|
|
|
.bind(&settings.settings.symbol_chats.to_vec())
|
|
|
.bind(&settings.settings.symbol_chats.to_vec())
|
|
|
.bind(settings.settings.team_name.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
|
.bind(settings.settings.team_name.iter().copied().flat_map(|i| i.to_le_bytes().to_vec()).collect::<Vec<u8>>())
|
|
|
.bind(settings.id.0)
|
|
|
|
|
|
|
|
|
.bind(settings.id.0 as i32)
|
|
|
.execute(conn).await?;
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
@ -262,7 +263,7 @@ async fn create_character(conn: &mut sqlx::PgConnection, char: NewCharacterEntit |
|
|
$26, $27, $28, $29, $30)
|
|
|
$26, $27, $28, $29, $30)
|
|
|
returning *;"#;
|
|
|
returning *;"#;
|
|
|
let character = sqlx::query_as::<_, PgCharacter>(q)
|
|
|
let character = sqlx::query_as::<_, PgCharacter>(q)
|
|
|
.bind(char.user_id.0)
|
|
|
|
|
|
|
|
|
.bind(char.user_id.0 as i32)
|
|
|
.bind(char.slot as i16)
|
|
|
.bind(char.slot as i16)
|
|
|
.bind(char.name)
|
|
|
.bind(char.name)
|
|
|
.bind(char.exp as i32)
|
|
|
.bind(char.exp as i32)
|
|
@ -300,7 +301,7 @@ async fn create_character(conn: &mut sqlx::PgConnection, char: NewCharacterEntit |
|
|
async fn get_characters_by_user(conn: &mut sqlx::PgConnection, user: &UserAccountEntity) -> Result<[Option<CharacterEntity>; 4], GatewayError>
|
|
|
async fn get_characters_by_user(conn: &mut sqlx::PgConnection, user: &UserAccountEntity) -> Result<[Option<CharacterEntity>; 4], GatewayError>
|
|
|
{
|
|
|
{
|
|
|
let stream = sqlx::query_as::<_, PgCharacter>("select * from player_character where user_account = $1 and slot < 4 order by created_at;")
|
|
|
let stream = sqlx::query_as::<_, PgCharacter>("select * from player_character where user_account = $1 and slot < 4 order by created_at;")
|
|
|
.bind(user.id.0)
|
|
|
|
|
|
|
|
|
.bind(user.id.0 as i32)
|
|
|
.fetch(conn);
|
|
|
.fetch(conn);
|
|
|
|
|
|
|
|
|
Ok(stream.fold(core::array::from_fn(|_| None), |mut acc, char| async move {
|
|
|
Ok(stream.fold(core::array::from_fn(|_| None), |mut acc, char| async move {
|
|
@ -320,7 +321,7 @@ async fn save_character(conn: &mut sqlx::PgConnection, char: &CharacterEntity) - |
|
|
evade=$24, luck=$25, hp=$26, tp=$27, tech_menu=$28, option_flags=$29, playtime=$30
|
|
|
evade=$24, luck=$25, hp=$26, tp=$27, tech_menu=$28, option_flags=$29, playtime=$30
|
|
|
where id=$31;"#;
|
|
|
where id=$31;"#;
|
|
|
sqlx::query(q)
|
|
|
sqlx::query(q)
|
|
|
.bind(char.user_id.0) // $1
|
|
|
|
|
|
|
|
|
.bind(char.user_id.0 as i32) // $1
|
|
|
.bind(char.slot as i16) // $2
|
|
|
.bind(char.slot as i16) // $2
|
|
|
.bind(&char.name) // $3
|
|
|
.bind(&char.name) // $3
|
|
|
.bind(char.exp as i32) // $4
|
|
|
.bind(char.exp as i32) // $4
|
|
@ -370,7 +371,7 @@ async fn create_item(conn: &mut sqlx::PgConnection, item: NewItemEntity) -> Resu |
|
|
async fn add_item_note(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, item_note: ItemNote) -> Result<(), GatewayError>
|
|
|
async fn add_item_note(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, item_note: ItemNote) -> Result<(), GatewayError>
|
|
|
{
|
|
|
{
|
|
|
sqlx::query("insert into item_note(item, note) values ($1, $2)")
|
|
|
sqlx::query("insert into item_note(item, note) values ($1, $2)")
|
|
|
.bind(item_id.0)
|
|
|
|
|
|
|
|
|
.bind(item_id.0 as i32)
|
|
|
.bind(sqlx::types::Json(PgItemNoteDetail::from(item_note)))
|
|
|
.bind(sqlx::types::Json(PgItemNoteDetail::from(item_note)))
|
|
|
.execute(conn).await?;
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
@ -379,7 +380,7 @@ async fn add_item_note(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, it |
|
|
async fn feed_mag(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) -> Result<(), GatewayError>
|
|
|
async fn feed_mag(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) -> Result<(), GatewayError>
|
|
|
{
|
|
|
{
|
|
|
sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);")
|
|
|
sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);")
|
|
|
.bind(mag_item_id.0)
|
|
|
|
|
|
|
|
|
.bind(mag_item_id.0 as i32)
|
|
|
.bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::FeedMag{food: *tool_item_id})))
|
|
|
.bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::FeedMag{food: *tool_item_id})))
|
|
|
.execute(conn).await?;
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
@ -388,7 +389,7 @@ async fn feed_mag(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, too |
|
|
async fn change_mag_owner(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, character: &CharacterEntity) -> Result<(), GatewayError>
|
|
|
async fn change_mag_owner(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, character: &CharacterEntity) -> Result<(), GatewayError>
|
|
|
{
|
|
|
{
|
|
|
sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);")
|
|
|
sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);")
|
|
|
.bind(mag_item_id.0)
|
|
|
|
|
|
|
|
|
.bind(mag_item_id.0 as i32)
|
|
|
.bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::OwnerChange(character.char_class, character.section_id))))
|
|
|
.bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::OwnerChange(character.char_class, character.section_id))))
|
|
|
.execute(conn).await?;
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
@ -397,7 +398,7 @@ async fn change_mag_owner(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntit |
|
|
async fn use_mag_cell(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, mag_cell_id: &ItemEntityId) -> Result<(), GatewayError>
|
|
|
async fn use_mag_cell(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, mag_cell_id: &ItemEntityId) -> Result<(), GatewayError>
|
|
|
{
|
|
|
{
|
|
|
sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);")
|
|
|
sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);")
|
|
|
.bind(mag_item_id.0)
|
|
|
|
|
|
|
|
|
.bind(mag_item_id.0 as i32)
|
|
|
.bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::MagCell(*mag_cell_id))))
|
|
|
.bind(sqlx::types::Json(PgMagModifierDetail::from(mag::MagModifier::MagCell(*mag_cell_id))))
|
|
|
.execute(conn).await?;
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
@ -406,7 +407,7 @@ async fn use_mag_cell(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, |
|
|
async fn add_weapon_modifier(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError>
|
|
|
async fn add_weapon_modifier(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError>
|
|
|
{
|
|
|
{
|
|
|
sqlx::query("insert into weapon_modifier (weapon, modifier) values ($1, $2);")
|
|
|
sqlx::query("insert into weapon_modifier (weapon, modifier) values ($1, $2);")
|
|
|
.bind(item_id.0)
|
|
|
|
|
|
|
|
|
.bind(item_id.0 as i32)
|
|
|
.bind(sqlx::types::Json(modifier))
|
|
|
.bind(sqlx::types::Json(modifier))
|
|
|
.execute(conn).await?;
|
|
|
.execute(conn).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
@ -416,7 +417,7 @@ async fn get_character_inventory(conn: &mut sqlx::PgConnection, char_id: &Charac |
|
|
{
|
|
|
{
|
|
|
let conn = Arc::new(Mutex::new(conn.begin().await?)); // this is some degen shit
|
|
|
let conn = Arc::new(Mutex::new(conn.begin().await?)); // this is some degen shit
|
|
|
let inventory = sqlx::query_as::<_, PgInventoryEntity>("select * from inventory where pchar = $1")
|
|
|
let inventory = sqlx::query_as::<_, PgInventoryEntity>("select * from inventory where pchar = $1")
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.fetch_one(&mut **conn.lock().await).await?;
|
|
|
.fetch_one(&mut **conn.lock().await).await?;
|
|
|
|
|
|
|
|
|
Ok(InventoryEntity::new(
|
|
|
Ok(InventoryEntity::new(
|
|
@ -441,14 +442,14 @@ async fn get_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEn |
|
|
let bank = match bank_identifier {
|
|
|
let bank = match bank_identifier {
|
|
|
BankIdentifier::Character => {
|
|
|
BankIdentifier::Character => {
|
|
|
sqlx::query_as::<_, PgInventoryEntity>("select * from bank where pchar = $1")
|
|
|
sqlx::query_as::<_, PgInventoryEntity>("select * from bank where pchar = $1")
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.fetch_one(&mut **conn.lock().await).await?
|
|
|
.fetch_one(&mut **conn.lock().await).await?
|
|
|
},
|
|
|
},
|
|
|
BankIdentifier::Shared(bank_name) => {
|
|
|
BankIdentifier::Shared(bank_name) => {
|
|
|
sqlx::query_as::<_, PgInventoryEntity>("select player_character.id as pchar, shared_bank.items as items from shared_bank
|
|
|
sqlx::query_as::<_, PgInventoryEntity>("select player_character.id as pchar, shared_bank.items as items from shared_bank
|
|
|
join player_character on shared_bank.user_account = player_character.user_account
|
|
|
join player_character on shared_bank.user_account = player_character.user_account
|
|
|
where player_character.id = $1 and shared_bank.name = $2")
|
|
|
where player_character.id = $1 and shared_bank.name = $2")
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.bind(&bank_name.0)
|
|
|
.bind(&bank_name.0)
|
|
|
.fetch_optional(&mut **conn.lock().await)
|
|
|
.fetch_optional(&mut **conn.lock().await)
|
|
|
.await?
|
|
|
.await?
|
|
@ -491,7 +492,7 @@ async fn set_character_inventory(conn: &mut sqlx::PgConnection, char_id: &Charac |
|
|
.collect::<Vec<_>>();
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
sqlx::query("insert into inventory (pchar, items) values ($1, $2) on conflict (pchar) do update set items = $2")
|
|
|
sqlx::query("insert into inventory (pchar, items) values ($1, $2) on conflict (pchar) do update set items = $2")
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.bind(sqlx::types::Json(inventory))
|
|
|
.bind(sqlx::types::Json(inventory))
|
|
|
.execute(conn)
|
|
|
.execute(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
@ -516,7 +517,7 @@ async fn set_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEn |
|
|
match bank_identifier {
|
|
|
match bank_identifier {
|
|
|
BankIdentifier::Character => {
|
|
|
BankIdentifier::Character => {
|
|
|
sqlx::query("insert into bank (pchar, items, name) values ($1, $2, '') on conflict (pchar, name) do update set items = $2")
|
|
|
sqlx::query("insert into bank (pchar, items, name) values ($1, $2, '') on conflict (pchar, name) do update set items = $2")
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.bind(sqlx::types::Json(bank))
|
|
|
.bind(sqlx::types::Json(bank))
|
|
|
.execute(conn)
|
|
|
.execute(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
@ -526,7 +527,7 @@ async fn set_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEn |
|
|
select player_character.user_account, $2, $3 from player_character
|
|
|
select player_character.user_account, $2, $3 from player_character
|
|
|
where player_character.id = $1
|
|
|
where player_character.id = $1
|
|
|
on conflict (user_account, name) do update set items = $2;")
|
|
|
on conflict (user_account, name) do update set items = $2;")
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.bind(sqlx::types::Json(bank))
|
|
|
.bind(sqlx::types::Json(bank))
|
|
|
.bind(&bank_name.0)
|
|
|
.bind(&bank_name.0)
|
|
|
.execute(conn)
|
|
|
.execute(conn)
|
|
@ -539,7 +540,7 @@ async fn set_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEn |
|
|
async fn get_character_equips(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId) -> Result<EquippedEntity, GatewayError>
|
|
|
async fn get_character_equips(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId) -> Result<EquippedEntity, GatewayError>
|
|
|
{
|
|
|
{
|
|
|
let equips = sqlx::query_as::<_, PgEquipped>("select * from equipped where pchar = $1")
|
|
|
let equips = sqlx::query_as::<_, PgEquipped>("select * from equipped where pchar = $1")
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.fetch_one(conn)
|
|
|
.fetch_one(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
|
|
|
|
|
|
@ -550,7 +551,7 @@ async fn set_character_equips(conn: &mut sqlx::PgConnection, char_id: &Character |
|
|
{
|
|
|
{
|
|
|
sqlx::query(r#"insert into equipped (pchar, weapon, armor, shield, unit0, unit1, unit2, unit3, mag) values ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
|
sqlx::query(r#"insert into equipped (pchar, weapon, armor, shield, unit0, unit1, unit2, unit3, mag) values ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
|
on conflict (pchar) do update set weapon=$2, armor=$3, shield=$4, unit0=$5, unit1=$6, unit2=$7, unit3=$8, mag=$9"#)
|
|
|
on conflict (pchar) do update set weapon=$2, armor=$3, shield=$4, unit0=$5, unit1=$6, unit2=$7, unit3=$8, mag=$9"#)
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.bind(equips.weapon.map(|i| i.0 as i32))
|
|
|
.bind(equips.weapon.map(|i| i.0 as i32))
|
|
|
.bind(equips.armor.map(|i| i.0 as i32))
|
|
|
.bind(equips.armor.map(|i| i.0 as i32))
|
|
|
.bind(equips.shield.map(|i| i.0 as i32))
|
|
|
.bind(equips.shield.map(|i| i.0 as i32))
|
|
@ -568,7 +569,7 @@ async fn set_character_equips(conn: &mut sqlx::PgConnection, char_id: &Character |
|
|
async fn set_character_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, meseta: Meseta) -> Result<(), GatewayError>
|
|
|
async fn set_character_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, meseta: Meseta) -> Result<(), GatewayError>
|
|
|
{
|
|
|
{
|
|
|
sqlx::query("insert into character_meseta values ($1, $2) on conflict (pchar) do update set meseta = $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 as i32)
|
|
|
.bind(meseta.0 as i32)
|
|
|
.bind(meseta.0 as i32)
|
|
|
.execute(conn)
|
|
|
.execute(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
@ -580,7 +581,7 @@ async fn get_character_meseta(conn: &mut sqlx::PgConnection, char_id: &Character |
|
|
#[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 pchar = $1"#)
|
|
|
let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where pchar = $1"#)
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.fetch_one(conn)
|
|
|
.fetch_one(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
|
Ok(Meseta(meseta.0 as u32))
|
|
|
Ok(Meseta(meseta.0 as u32))
|
|
@ -591,7 +592,7 @@ async fn set_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit |
|
|
match bank_identifier {
|
|
|
match bank_identifier {
|
|
|
BankIdentifier::Character => {
|
|
|
BankIdentifier::Character => {
|
|
|
sqlx::query("insert into bank_meseta values ($1, '', $2) on conflict (pchar, bank) do update set meseta = $2")
|
|
|
sqlx::query("insert into bank_meseta values ($1, '', $2) on conflict (pchar, bank) do update set meseta = $2")
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.bind(meseta.0 as i32)
|
|
|
.bind(meseta.0 as i32)
|
|
|
.execute(conn)
|
|
|
.execute(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
@ -601,7 +602,7 @@ async fn set_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit |
|
|
select player_character.user_account, $2, $3 from player_character
|
|
|
select player_character.user_account, $2, $3 from player_character
|
|
|
where player_character.id = $1
|
|
|
where player_character.id = $1
|
|
|
on conflict (user_account, name) do update set meseta = $3")
|
|
|
on conflict (user_account, name) do update set meseta = $3")
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.bind(&bank_name.0)
|
|
|
.bind(&bank_name.0)
|
|
|
.bind(meseta.0 as i32)
|
|
|
.bind(meseta.0 as i32)
|
|
|
.execute(conn)
|
|
|
.execute(conn)
|
|
@ -620,7 +621,7 @@ async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit |
|
|
let meseta = match bank_identifier {
|
|
|
let meseta = match bank_identifier {
|
|
|
BankIdentifier::Character => {
|
|
|
BankIdentifier::Character => {
|
|
|
sqlx::query_as::<_, PgMeseta>(r#"select meseta from bank_meseta where pchar = $1"#)
|
|
|
sqlx::query_as::<_, PgMeseta>(r#"select meseta from bank_meseta where pchar = $1"#)
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.fetch_one(conn)
|
|
|
.fetch_one(conn)
|
|
|
.await?
|
|
|
.await?
|
|
|
},
|
|
|
},
|
|
@ -628,7 +629,7 @@ async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit |
|
|
sqlx::query_as::<_, PgMeseta>(r#"select shared_bank_meseta.meseta from shared_bank_meseta
|
|
|
sqlx::query_as::<_, PgMeseta>(r#"select shared_bank_meseta.meseta from shared_bank_meseta
|
|
|
join player_character on shared_bank_meseta.user_account = player_character.user_account
|
|
|
join player_character on shared_bank_meseta.user_account = player_character.user_account
|
|
|
where player_character.id = $1 and shared_bank_meseta.name = $2"#)
|
|
|
where player_character.id = $1 and shared_bank_meseta.name = $2"#)
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
.bind(&bank_name.0)
|
|
|
.bind(&bank_name.0)
|
|
|
.fetch_optional(conn)
|
|
|
.fetch_optional(conn)
|
|
|
.await?
|
|
|
.await?
|
|
@ -641,8 +642,8 @@ async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit |
|
|
async fn create_trade(conn: &mut sqlx::PgConnection, char_id1: &CharacterEntityId, char_id2: &CharacterEntityId) -> Result<TradeEntity, GatewayError>
|
|
|
async fn create_trade(conn: &mut sqlx::PgConnection, char_id1: &CharacterEntityId, char_id2: &CharacterEntityId) -> Result<TradeEntity, GatewayError>
|
|
|
{
|
|
|
{
|
|
|
let trade = sqlx::query_as::<_, PgTradeEntity>(r#"insert into trades (character1, character2) values ($1, $2) returning *;"#)
|
|
|
let trade = sqlx::query_as::<_, PgTradeEntity>(r#"insert into trades (character1, character2) values ($1, $2) returning *;"#)
|
|
|
.bind(char_id1.0)
|
|
|
|
|
|
.bind(char_id2.0)
|
|
|
|
|
|
|
|
|
.bind(char_id1.0 as i32)
|
|
|
|
|
|
.bind(char_id2.0 as i32)
|
|
|
.fetch_one(conn)
|
|
|
.fetch_one(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
|
Ok(trade.into())
|
|
|
Ok(trade.into())
|
|
@ -651,8 +652,30 @@ async fn create_trade(conn: &mut sqlx::PgConnection, char_id1: &CharacterEntityI |
|
|
async fn set_character_playtime(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, playtime: u32) -> Result<(), GatewayError>
|
|
|
async fn set_character_playtime(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, playtime: u32) -> Result<(), GatewayError>
|
|
|
{
|
|
|
{
|
|
|
sqlx::query(r#"update player_character set playtime=$2 where id=$1;"#)
|
|
|
sqlx::query(r#"update player_character set playtime=$2 where id=$1;"#)
|
|
|
.bind(char_id.0)
|
|
|
|
|
|
.bind(playtime)
|
|
|
|
|
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
|
|
|
.bind(playtime as i32)
|
|
|
|
|
|
.execute(conn)
|
|
|
|
|
|
.await?;
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn create_room(conn: &mut sqlx::PgConnection, room: NewRoomEntity) -> Result<RoomEntity, GatewayError> {
|
|
|
|
|
|
sqlx::query_as::<_, PgRoomEntity>("insert into room (name, section_id, mode, episode, difficulty) values ($1, $2, $3, $4, $5) returning *")
|
|
|
|
|
|
.bind(room.name)
|
|
|
|
|
|
.bind(u8::from(room.section_id) as i8)
|
|
|
|
|
|
.bind(u8::from(room.mode) as i8)
|
|
|
|
|
|
.bind(u8::from(room.episode) as i8)
|
|
|
|
|
|
.bind(u8::from(room.difficulty) as i8)
|
|
|
|
|
|
.fetch_one(conn)
|
|
|
|
|
|
.await
|
|
|
|
|
|
.map(|room| room.into())
|
|
|
|
|
|
.map_err(|err| err.into())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn add_room_note(conn: &mut sqlx::PgConnection, room_id: RoomEntityId, note: RoomNote) -> Result<(), GatewayError> {
|
|
|
|
|
|
sqlx::query("insert into room_note (room, note) values ($1, $2)")
|
|
|
|
|
|
.bind(room_id.0 as i32)
|
|
|
|
|
|
.bind(sqlx::types::Json(note))
|
|
|
.execute(conn)
|
|
|
.execute(conn)
|
|
|
.await?;
|
|
|
.await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
@ -797,6 +820,14 @@ impl EntityGateway for PostgresGateway { |
|
|
async fn set_character_playtime(&mut self, char_id: &CharacterEntityId, playtime: u32) -> Result<(), GatewayError> {
|
|
|
async fn set_character_playtime(&mut self, char_id: &CharacterEntityId, playtime: u32) -> Result<(), GatewayError> {
|
|
|
set_character_playtime(&mut *self.pool.acquire().await?, char_id, playtime).await
|
|
|
set_character_playtime(&mut *self.pool.acquire().await?, char_id, playtime).await
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn create_room(&mut self, room: NewRoomEntity) -> Result<RoomEntity, GatewayError> {
|
|
|
|
|
|
create_room(&mut *self.pool.acquire().await?, room).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn add_room_note(&mut self, room_id: RoomEntityId, note: RoomNote) -> Result<(), GatewayError> {
|
|
|
|
|
|
add_room_note(&mut *self.pool.acquire().await?, room_id, note).await
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -923,5 +954,13 @@ impl<'c> EntityGateway for PostgresTransaction<'c> { |
|
|
async fn set_character_playtime(&mut self, char_id: &CharacterEntityId, playtime: u32) -> Result<(), GatewayError> {
|
|
|
async fn set_character_playtime(&mut self, char_id: &CharacterEntityId, playtime: u32) -> Result<(), GatewayError> {
|
|
|
set_character_playtime(&mut *self.pgtransaction.lock().await, char_id, playtime).await
|
|
|
set_character_playtime(&mut *self.pgtransaction.lock().await, char_id, playtime).await
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn create_room(&mut self, room: NewRoomEntity) -> Result<RoomEntity, GatewayError> {
|
|
|
|
|
|
create_room(&mut *self.pgtransaction.lock().await, room).await
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn add_room_note(&mut self, room_id: RoomEntityId, note: RoomNote) -> Result<(), GatewayError> {
|
|
|
|
|
|
add_room_note(&mut *self.pgtransaction.lock().await, room_id, note).await
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|