fix postgres stuff to get to a game
This commit is contained in:
		
							parent
							
								
									dfd48e1496
								
							
						
					
					
						commit
						43579f7058
					
				
							
								
								
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -1040,6 +1040,7 @@ checksum = "739e9d7726dc32173fed2d69d17eef3c54682169e4e20ff1d0a45dcd37063cef" | |||||||
| [[package]] | [[package]] | ||||||
| name = "libpso" | name = "libpso" | ||||||
| version = "0.1.0" | version = "0.1.0" | ||||||
|  | source = "git+http://git.sharnoth.com/jake/libpso#5051514fb1d3b39a7eb6ff97b624a9ceebd93e40" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "chrono", |  "chrono", | ||||||
|  "psopacket", |  "psopacket", | ||||||
| @ -1398,6 +1399,7 @@ dependencies = [ | |||||||
| [[package]] | [[package]] | ||||||
| name = "psopacket" | name = "psopacket" | ||||||
| version = "1.0.0" | version = "1.0.0" | ||||||
|  | source = "git+http://git.sharnoth.com/jake/libpso#5051514fb1d3b39a7eb6ff97b624a9ceebd93e40" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "proc-macro2", |  "proc-macro2", | ||||||
|  "quote", |  "quote", | ||||||
|  | |||||||
| @ -10,9 +10,10 @@ use crate::entity::item::*; | |||||||
| // TODO: better granularity?
 | // TODO: better granularity?
 | ||||||
| //#[derive(Error, Debug)]
 | //#[derive(Error, Debug)]
 | ||||||
| #[derive(Error, Debug)] | #[derive(Error, Debug)] | ||||||
| #[error("")] |  | ||||||
| pub enum GatewayError { | pub enum GatewayError { | ||||||
|  |     #[error("unknown error")] | ||||||
|     Error, |     Error, | ||||||
|  |     #[error("postgres error {0}")] | ||||||
|     PgError(#[from] sqlx::Error) |     PgError(#[from] sqlx::Error) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,10 +1,10 @@ | |||||||
| 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) | ||||||
| @ -12,4 +12,5 @@ create table bank_meseta ( | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| alter table player_character | alter table player_character | ||||||
|   drop column meseta, bank_meseta; |   drop column meseta, | ||||||
|  |   drop column bank_meseta; | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| create table trades ( | create table trades ( | ||||||
|   id serial primary key not null, |   id serial primary key not null, | ||||||
|   character1 integer references character (id) not null, |   character1 integer references player_character (id) not null, | ||||||
|   character2 integer references character (id) not null, |   character2 integer references player_character (id) not null | ||||||
| ); | ); | ||||||
|  | |||||||
| @ -49,8 +49,8 @@ pub struct PgUserSettings { | |||||||
|     id: i32, |     id: i32, | ||||||
|     user_account: i32, |     user_account: i32, | ||||||
|     blocked_users: Vec<u8>, //[u32; 0x1E],
 |     blocked_users: Vec<u8>, //[u32; 0x1E],
 | ||||||
|     keyboard_config: Vec<u8>, //[u8; 0x16C],
 |     key_config: Vec<u8>, //[u8; 0x16C],
 | ||||||
|     gamepad_config: Vec<u8>, //[u8; 0x38],
 |     joystick_config: Vec<u8>, //[u8; 0x38],
 | ||||||
|     option_flags: i32, |     option_flags: i32, | ||||||
|     shortcuts: Vec<u8>, //[u8; 0xA40],
 |     shortcuts: Vec<u8>, //[u8; 0xA40],
 | ||||||
|     symbol_chats: Vec<u8>, //[u8; 0x4E0],
 |     symbol_chats: Vec<u8>, //[u8; 0x4E0],
 | ||||||
| @ -64,8 +64,8 @@ impl From<PgUserSettings> for UserSettingsEntity { | |||||||
|             user_id: UserAccountId(other.user_account as u32), |             user_id: UserAccountId(other.user_account as u32), | ||||||
|             settings: settings::UserSettings { |             settings: settings::UserSettings { | ||||||
|                 blocked_users: vec_to_array(other.blocked_users.chunks(4).map(|b| u32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect()), |                 blocked_users: vec_to_array(other.blocked_users.chunks(4).map(|b| u32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect()), | ||||||
|                 keyboard_config: vec_to_array(other.keyboard_config), |                 keyboard_config: vec_to_array(other.key_config), | ||||||
|                 gamepad_config: vec_to_array(other.gamepad_config), |                 gamepad_config: vec_to_array(other.joystick_config), | ||||||
|                 option_flags: other.option_flags as u32, |                 option_flags: other.option_flags as u32, | ||||||
|                 shortcuts: vec_to_array(other.shortcuts), |                 shortcuts: vec_to_array(other.shortcuts), | ||||||
|                 symbol_chats: vec_to_array(other.symbol_chats), |                 symbol_chats: vec_to_array(other.symbol_chats), | ||||||
|  | |||||||
| @ -224,10 +224,21 @@ async fn save_user_settings(conn: &mut sqlx::PgConnection, settings: &UserSettin | |||||||
| async fn create_character(conn: &mut sqlx::PgConnection, char: NewCharacterEntity) -> Result<CharacterEntity, GatewayError> | async fn create_character(conn: &mut sqlx::PgConnection, 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, | ||||||
|                config, infoboard, guildcard, power, mind, def, evade, luck, hp, tp, tech_menu, option_flags) |                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, keyboard_config, | ||||||
|  |                gamepad_config, playtime) | ||||||
|               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, $32) | ||||||
|               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) | ||||||
| @ -259,6 +270,9 @@ async fn create_character(conn: &mut sqlx::PgConnection, char: NewCharacterEntit | |||||||
|         .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.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?; |         .fetch_one(conn).await?; | ||||||
| 
 | 
 | ||||||
|     Ok(character.into()) |     Ok(character.into()) | ||||||
| @ -284,8 +298,8 @@ async fn save_character(conn: &mut sqlx::PgConnection, char: &CharacterEntity) - | |||||||
|     let q = r#"update player_character set
 |     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, |                    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, |                    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, playtime=$30 |                    evade=$24, luck=$25, hp=$26, tp=$27, tech_menu=$28, option_flags=$29, keyboard_config=$30, gamepad_config=$31, playtime=$32, | ||||||
|                    where id=$31;"#;
 |                where id=$33;"#;
 | ||||||
|     sqlx::query(q) |     sqlx::query(q) | ||||||
|         .bind(char.user_id.0) // $1
 |         .bind(char.user_id.0) // $1
 | ||||||
|         .bind(char.slot as i16) // $2
 |         .bind(char.slot as i16) // $2
 | ||||||
| @ -316,8 +330,10 @@ async fn save_character(conn: &mut sqlx::PgConnection, char: &CharacterEntity) - | |||||||
|         .bind(char.materials.tp as i16) // $27
 |         .bind(char.materials.tp as i16) // $27
 | ||||||
|         .bind(char.tech_menu.tech_menu.to_vec()) // $28
 |         .bind(char.tech_menu.tech_menu.to_vec()) // $28
 | ||||||
|         .bind(char.option_flags as i32) // $29
 |         .bind(char.option_flags as i32) // $29
 | ||||||
|         .bind(char.playtime as i32) // $20
 |         .bind(&char.keyboard_config.keyboard_config.to_vec()) // $30
 | ||||||
|         .bind(char.id.0 as i32) // $31
 |         .bind(&char.gamepad_config.gamepad_config.to_vec()) // $31
 | ||||||
|  |         .bind(char.playtime as i32) // $32
 | ||||||
|  |         .bind(char.id.0 as i32) // $33
 | ||||||
|         .execute(conn).await?; |         .execute(conn).await?; | ||||||
|     Ok(()) |     Ok(()) | ||||||
| } | } | ||||||
| @ -530,7 +546,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 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(conn) |         .execute(conn) | ||||||
| @ -542,7 +558,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 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(conn) |         .fetch_one(conn) | ||||||
|         .await?; |         .await?; | ||||||
| @ -551,10 +567,10 @@ async fn get_character_meseta(conn: &mut sqlx::PgConnection, char_id: &Character | |||||||
| 
 | 
 | ||||||
| async fn set_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, bank: &BankName, meseta: Meseta) -> Result<(), GatewayError> | async fn set_bank_meseta(conn: &mut sqlx::PgConnection, 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.clone()) |         .bind(bank.0.clone()) | ||||||
|  |         .bind(meseta.0 as i32) | ||||||
|         .execute(conn) |         .execute(conn) | ||||||
|         .await?; |         .await?; | ||||||
|     Ok(()) |     Ok(()) | ||||||
| @ -564,7 +580,7 @@ async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit | |||||||
| { | { | ||||||
|     #[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.clone()) |         .bind(bank.0.clone()) | ||||||
|         .fetch_one(conn) |         .fetch_one(conn) | ||||||
| @ -584,10 +600,10 @@ 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_as::<_, PgTradeEntity>(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(char_id.0) | ||||||
|         .bind(playtime) |         .bind(playtime) | ||||||
|         .fetch_one(conn) |         .execute(conn) | ||||||
|         .await?; |         .await?; | ||||||
|     Ok(()) |     Ok(()) | ||||||
| } | } | ||||||
|  | |||||||
| @ -3,7 +3,6 @@ | |||||||
| #![feature(drain_filter)] | #![feature(drain_filter)] | ||||||
| #![feature(try_blocks)] | #![feature(try_blocks)] | ||||||
| #![feature(once_cell)] | #![feature(once_cell)] | ||||||
| #![feature(pin_macro)] |  | ||||||
| #![feature(test)] | #![feature(test)] | ||||||
| 
 | 
 | ||||||
| extern crate test; | extern crate test; | ||||||
|  | |||||||
| @ -38,13 +38,18 @@ pub const CHARACTER_PORT: u16 = 12001; | |||||||
| pub const SHIP_MENU_ID: u32 = 1; | pub const SHIP_MENU_ID: u32 = 1; | ||||||
| 
 | 
 | ||||||
| #[derive(thiserror::Error, Debug)] | #[derive(thiserror::Error, Debug)] | ||||||
| #[error("")] |  | ||||||
| pub enum CharacterError { | pub enum CharacterError { | ||||||
|  |     #[error("invalid menu selection {0} {1}")] | ||||||
|     InvalidMenuSelection(u32, u32), |     InvalidMenuSelection(u32, u32), | ||||||
|  |     #[error("client not found {0}")] | ||||||
|     ClientNotFound(ClientId), |     ClientNotFound(ClientId), | ||||||
|     CouldNotLoadSettings, |     #[error("could not load settings {0}")] | ||||||
|  |     CouldNotLoadSettings(GatewayError), | ||||||
|  |     #[error("could not load characters")] | ||||||
|     CouldNotLoadCharacters, |     CouldNotLoadCharacters, | ||||||
|  |     #[error("could not load guildcard")] | ||||||
|     CouldNotLoadGuildcard, |     CouldNotLoadGuildcard, | ||||||
|  |     #[error("gateway error {0}")] | ||||||
|     GatewayError(#[from] GatewayError), |     GatewayError(#[from] GatewayError), | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -206,6 +211,7 @@ async fn new_character<EG: EntityGateway + Clone>(entity_gateway: &mut EG, user: | |||||||
| 
 | 
 | ||||||
|     let character = entity_gateway.create_character(character).await?; |     let character = entity_gateway.create_character(character).await?; | ||||||
|     entity_gateway.set_character_meseta(&character.id, Meseta(300)).await?; |     entity_gateway.set_character_meseta(&character.id, Meseta(300)).await?; | ||||||
|  |     entity_gateway.set_bank_meseta(&character.id, &BankName("".into()), Meseta(300)).await?; | ||||||
| 
 | 
 | ||||||
|     let new_weapon = match character.char_class { |     let new_weapon = match character.char_class { | ||||||
|         CharacterClass::HUmar | CharacterClass::HUnewearl | CharacterClass::HUcast | CharacterClass::HUcaseal => item::weapon::WeaponType::Saber, |         CharacterClass::HUmar | CharacterClass::HUnewearl | CharacterClass::HUcast | CharacterClass::HUcaseal => item::weapon::WeaponType::Saber, | ||||||
| @ -385,7 +391,7 @@ impl<EG: EntityGateway + Clone> CharacterServerState<EG> { | |||||||
|             Ok(settings) => settings, |             Ok(settings) => settings, | ||||||
|             Err(_) => { |             Err(_) => { | ||||||
|                 let user_settings = NewUserSettingsEntity::new(user.id); |                 let user_settings = NewUserSettingsEntity::new(user.id); | ||||||
|                 self.entity_gateway.create_user_settings(user_settings).await.map_err(|_| CharacterError::CouldNotLoadSettings)? |                 self.entity_gateway.create_user_settings(user_settings).await.map_err(|err| CharacterError::CouldNotLoadSettings(err))? | ||||||
|             } |             } | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -21,8 +21,8 @@ pub const LOGIN_PORT: u16 = 12000; | |||||||
| pub const COMMUNICATION_PORT: u16 = 12123; | pub const COMMUNICATION_PORT: u16 = 12123; | ||||||
| 
 | 
 | ||||||
| #[derive(thiserror::Error, Debug)] | #[derive(thiserror::Error, Debug)] | ||||||
| #[error("")] |  | ||||||
| pub enum LoginError { | pub enum LoginError { | ||||||
|  |     #[error("dberror")] | ||||||
|     DbError |     DbError | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -834,6 +834,8 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> { | |||||||
|             self.item_state.remove_character_from_room(&client.character).await |             self.item_state.remove_character_from_room(&client.character).await | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         block.client_location.remove_client_from_area(id).await?; | ||||||
|  | 
 | ||||||
|         Ok(neighbors.into_iter().map(|n| { |         Ok(neighbors.into_iter().map(|n| { | ||||||
|             (n.client, pkt.clone()) |             (n.client, pkt.clone()) | ||||||
|         }).collect()) |         }).collect()) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user