From d4913eb6c63c703f1b2ebde8a466c43d326bea50 Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 14 Nov 2023 20:44:47 -0700 Subject: [PATCH 1/4] looks like this is fixed --- src/client/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/client/src/lib.rs b/src/client/src/lib.rs index 43c7a0f..fc91a37 100644 --- a/src/client/src/lib.rs +++ b/src/client/src/lib.rs @@ -81,10 +81,7 @@ impl Clients { } let client_states = unsafe { - // TODO: this should just be a normal transmute but due to compiler limitations it - // does not yet work with const generics - // https://github.com/rust-lang/rust/issues/61956 - std::mem::transmute_copy::<_, [RwLockReadGuard; N]>(&client_states) + std::mem::transmute_copy(&client_states) }; Ok(func(client_states).await) From c851818813546991ece21b5cae316a73371b5be7 Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 14 Nov 2023 20:57:41 -0700 Subject: [PATCH 2/4] remove unused macro --- src/networking/src/lib.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/networking/src/lib.rs b/src/networking/src/lib.rs index c8adde9..d62efe2 100644 --- a/src/networking/src/lib.rs +++ b/src/networking/src/lib.rs @@ -2,17 +2,3 @@ pub mod cipherkeys; pub mod serverstate; pub mod mainloop; pub mod interserver; - -// https://www.reddit.com/r/rust/comments/33xhhu/how_to_create_an_array_of_structs_that_havent/ -#[macro_export] -macro_rules! init_array( - ($ty:ty, $len:expr, $val:expr) => ( - { - let mut array: [$ty; $len] = unsafe { std::mem::uninitialized() }; - for i in array.iter_mut() { - unsafe { ::std::ptr::write(i, $val); } - } - array - } - ) -); From b18ab064fa8f5116ef8782f5476b003ead7c5ee5 Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 14 Nov 2023 22:08:04 -0700 Subject: [PATCH 3/4] match libpso changes --- Cargo.toml | 2 +- src/entity/src/character.rs | 2 +- src/entity/src/gateway/postgres/models.rs | 2 +- src/login_server/src/character.rs | 8 ++++---- src/pktbuilder/src/character.rs | 2 +- src/pktbuilder/src/lib.rs | 2 +- src/pktbuilder/src/quest.rs | 16 ++++++++-------- src/pktbuilder/src/ship.rs | 4 ++-- src/ship_server/src/communication.rs | 2 +- src/ship_server/src/direct_message.rs | 6 +++--- src/ship_server/src/room.rs | 4 ++-- tests/common.rs | 10 +++++----- 12 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dac1d62..bbda680 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ patch_server = { path = "./src/patch_server" } login_server = { path = "./src/login_server" } ship_server = { path = "./src/ship_server" } -libpso = { git = "http://git.sharnoth.com/jake/libpso" } +libpso = { git = "http://git.sharnoth.com/jake/libpso", rev="90246b6" } async-std = { version = "1.9.0", features = ["unstable", "attributes"] } futures = "0.3.5" diff --git a/src/entity/src/character.rs b/src/entity/src/character.rs index 643e009..d766f28 100644 --- a/src/entity/src/character.rs +++ b/src/entity/src/character.rs @@ -223,7 +223,7 @@ impl CharacterInfoboard { } pub fn update_infoboard(&mut self, new_board: &WriteInfoboard) { - self.board = libpso::utf8_to_utf16_array!(new_board.message, 172); + self.board = libpso::util::utf8_to_utf16_array(&new_board.message); } } diff --git a/src/entity/src/gateway/postgres/models.rs b/src/entity/src/gateway/postgres/models.rs index 13c2a6b..a7cfe94 100644 --- a/src/entity/src/gateway/postgres/models.rs +++ b/src/entity/src/gateway/postgres/models.rs @@ -253,7 +253,7 @@ impl From for CharacterEntity { raw_data: vec_to_array(other.config) }, info_board: CharacterInfoboard { - board: libpso::utf8_to_utf16_array!(other.infoboard, 172), + board: libpso::util::utf8_to_utf16_array(other.infoboard), }, guildcard: CharacterGuildCard { description: other.guildcard, diff --git a/src/login_server/src/character.rs b/src/login_server/src/character.rs index ec9d3d3..c317be9 100644 --- a/src/login_server/src/character.rs +++ b/src/login_server/src/character.rs @@ -19,7 +19,7 @@ use networking::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY}; use networking::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId}; use networking::interserver::{ServerId, InterserverActor, LoginMessage, ShipMessage, Ship}; use stats::leveltable::LEVEL_TABLE; -use libpso::{utf8_to_array, utf8_to_utf16_array}; +use libpso::util::{utf8_to_array, utf8_to_utf16_array}; use entity::gateway::{EntityGateway, GatewayError}; use entity::account::{UserAccountId, UserAccountEntity, NewUserSettingsEntity, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM}; @@ -150,7 +150,7 @@ fn generate_param_data(path: &str) -> (ParamDataHeader, Vec) { size: len as u32, checksum: crc.sum32(), offset: buffer.len() as u32, - filename: utf8_to_array!(param.file_name().unwrap().to_str().unwrap(), 0x40), + filename: utf8_to_array(param.file_name().unwrap().to_str().unwrap()), }); buffer.append(&mut filebuf); @@ -379,7 +379,7 @@ impl CharacterServerState { menu: SHIP_MENU_ID, item: i.0 as u32, flags: 0, - name: utf8_to_utf16_array!(s.name, 0x11) + name: utf8_to_utf16_array(&s.name) } }).collect())) ]) @@ -824,7 +824,7 @@ impl<'a> SelectScreenCharacterBuilder<'a> { hair_b: character.appearance.hair_b, prop_x: character.appearance.prop_x, prop_y: character.appearance.prop_y, - name: utf8_to_utf16_array!(character.name, 16), + name: utf8_to_utf16_array(&character.name), play_time: character.playtime, ..character::SelectScreenCharacter::default() } diff --git a/src/pktbuilder/src/character.rs b/src/pktbuilder/src/character.rs index 5d57896..1052af6 100644 --- a/src/pktbuilder/src/character.rs +++ b/src/pktbuilder/src/character.rs @@ -53,7 +53,7 @@ impl<'a> CharacterBytesBuilder<'a> { let level = self.level.unwrap(); let meseta = self.meseta.unwrap(); character::Character { - name: libpso::utf8_to_utf16_array!(character.name, 16), + name: libpso::util::utf8_to_utf16_array(&character.name), hp: stats.hp, atp: stats.atp + character.materials.power as u16 * 2, mst: stats.mst + character.materials.mind as u16 * 2, diff --git a/src/pktbuilder/src/lib.rs b/src/pktbuilder/src/lib.rs index bdcd755..e735521 100644 --- a/src/pktbuilder/src/lib.rs +++ b/src/pktbuilder/src/lib.rs @@ -19,7 +19,7 @@ pub fn player_header(tag: u32, client: &ClientState, area_client: &AreaClient) - guildcard: client.user.id.0, _unknown1: [0; 5], client_id: area_client.local_client.id() as u32, - name: libpso::utf8_to_utf16_array!(client.character.name, 16), + name: libpso::util::utf8_to_utf16_array(&client.character.name), _unknown2: 2, } } diff --git a/src/pktbuilder/src/quest.rs b/src/pktbuilder/src/quest.rs index d3f2f4f..3676e8c 100644 --- a/src/pktbuilder/src/quest.rs +++ b/src/pktbuilder/src/quest.rs @@ -1,6 +1,6 @@ use quests::{Quest, QuestList}; use libpso::packet::ship::*; -use libpso::{utf8_to_array, utf8_to_utf16_array}; +use libpso::util::{utf8_to_array, utf8_to_utf16_array}; pub const QUEST_CATEGORY_MENU_ID: u32 = 0xA2; pub const QUEST_SELECT_MENU_ID: u32 = 0xA3; @@ -12,8 +12,8 @@ pub fn quest_category_list(quests: &QuestList) -> QuestCategoryList { QuestCategory { menu_id: QUEST_CATEGORY_MENU_ID, option_id: i as u32, - name: utf8_to_utf16_array!(category.name, 32), - description: utf8_to_utf16_array!(category.description, 122), + name: utf8_to_utf16_array(&category.name), + description: utf8_to_utf16_array(&category.description), } }) .collect(); @@ -30,8 +30,8 @@ pub fn quest_list(category_id: u32, quests: &[Quest]) -> QuestOptionList { menu_id: QUEST_SELECT_MENU_ID, category_id: category_id as u16, quest_id: quest.id, - name: utf8_to_utf16_array!(quest.name, 32), - description: utf8_to_utf16_array!(quest.description, 122), + name: utf8_to_utf16_array(&quest.name), + description: utf8_to_utf16_array(&quest.description), } }) .collect(); @@ -43,7 +43,7 @@ pub fn quest_list(category_id: u32, quests: &[Quest]) -> QuestOptionList { pub fn quest_detail(quest: &Quest) -> QuestDetail { QuestDetail { - description: utf8_to_utf16_array!(quest.full_description, 288), + description: utf8_to_utf16_array(&quest.full_description), } } @@ -51,9 +51,9 @@ pub fn quest_header(quest_menu_select: &QuestMenuSelect, data_blob: &[u8], suffi let path = format!("{}-{}.{}", quest_menu_select.category, quest_menu_select.quest, suffix); QuestHeader { unknown1: [0; 0x24], - filename: utf8_to_array!(path, 16), + filename: utf8_to_array(&path), length: data_blob.len() as u32, - name: utf8_to_array!(path, 16), + name: utf8_to_array(&path), unknown2: [0; 8], } } diff --git a/src/pktbuilder/src/ship.rs b/src/pktbuilder/src/ship.rs index 41c6ea0..b5a9659 100644 --- a/src/pktbuilder/src/ship.rs +++ b/src/pktbuilder/src/ship.rs @@ -1,5 +1,5 @@ use libpso::packet::login::{ShipList, ShipListEntry}; -use libpso::utf8_to_utf16_array; +use libpso::util::utf8_to_utf16_array; use networking::interserver::Ship; @@ -13,7 +13,7 @@ pub fn ship_list(ships: &[Ship]) -> ShipList { menu: SHIP_MENU_ID, item: i as u32, flags: 0, - name: utf8_to_utf16_array!(ship.name, 0x11) + name: utf8_to_utf16_array(&ship.name) } }) .collect(); diff --git a/src/ship_server/src/communication.rs b/src/ship_server/src/communication.rs index 4949acd..69f8016 100644 --- a/src/ship_server/src/communication.rs +++ b/src/ship_server/src/communication.rs @@ -32,7 +32,7 @@ pub async fn request_infoboard(id: ClientId, .map(|client| async { clients.with(client.client, |client| Box::pin(async move { InfoboardResponse { - name: libpso::utf8_to_utf16_array!(client.character.name, 16), + name: libpso::util::utf8_to_utf16_array(&client.character.name), message: client.character.info_board.as_bytes(), } })).await diff --git a/src/ship_server/src/direct_message.rs b/src/ship_server/src/direct_message.rs index 9ec6f52..74e68e2 100644 --- a/src/ship_server/src/direct_message.rs +++ b/src/ship_server/src/direct_message.rs @@ -13,7 +13,7 @@ use room::Rooms; use items::ClientItemId; use entity::gateway::EntityGateway; use entity::item; -use libpso::utf8_to_utf16_array; +use libpso::util::utf8_to_utf16_array; use pktbuilder as builder; use shops::{ItemShops, ShopItem, ToolShopItem, ArmorShopItem}; use items::state::{ItemState, ItemStateError}; @@ -64,9 +64,9 @@ pub async fn guildcard_send(id: ClientId, client: guildcard_send.client, target: guildcard_send.target, guildcard: client.user.id.0, - name: utf8_to_utf16_array!(client.character.name, 0x18), + name: utf8_to_utf16_array(&client.character.name), team: [0; 0x10], // TODO: teams not yet implemented - desc: utf8_to_utf16_array!(client.character.guildcard.description, 0x58), + desc: utf8_to_utf16_array(&client.character.guildcard.description), one: 1, language: 0, // TODO: add language flag to character section_id: client.character.section_id.into(), diff --git a/src/ship_server/src/room.rs b/src/ship_server/src/room.rs index 254fdd0..73bdb39 100644 --- a/src/ship_server/src/room.rs +++ b/src/ship_server/src/room.rs @@ -260,7 +260,7 @@ pub async fn request_room_list(id: ClientId, .filter_map(|(i, r)| async move { r.as_ref().map(|room| { let difficulty = room.get_difficulty_for_room_list(); - let name = libpso::utf8_to_utf16_array!(room.name, 16); + let name = libpso::util::utf8_to_utf16_array(&room.name); let episode = room.get_episode_for_room_list(); let flags = room.get_flags_for_room_list(); async move { @@ -280,7 +280,7 @@ pub async fn request_room_list(id: ClientId, item_id: ROOM_MENU_ID, difficulty: 0x00, players: 0x00, - name: libpso::utf8_to_utf16_array!("Room list menu", 16), + name: libpso::util::utf8_to_utf16_array("Room list menu"), episode: 0, flags: 0, }; diff --git a/tests/common.rs b/tests/common.rs index ebab507..5a2e835 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -19,7 +19,7 @@ use entity::item; use libpso::packet::ship::*; use libpso::packet::login::{Login, Session}; -use libpso::{utf8_to_array, utf8_to_utf16_array}; +use libpso::util::{utf8_to_array, utf8_to_utf16_array}; fn null_quest_builder(_mode: RoomMode) -> Result { Ok(Default::default()) @@ -107,9 +107,9 @@ pub async fn log_in_char(ship: &mut ShipServerState(ship: &mut ShipServerState(ship: &mut ShipServerState, id: ClientId, name: &str, password: &str, difficulty: Difficulty) { ship.handle(id, RecvShipPacket::CreateRoom(CreateRoom { unknown: [0; 2], - name: utf8_to_utf16_array!(name, 16), - password: utf8_to_utf16_array!(password, 16), + name: utf8_to_utf16_array(name), + password: utf8_to_utf16_array(password), difficulty: difficulty.into(), battle: 0, challenge: 0, From 156821cc6ef89576fbcb2842f65c5ab41c0d3ecb Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 14 Nov 2023 22:16:40 -0700 Subject: [PATCH 4/4] more libpso updates --- src/login_server/src/character.rs | 10 +++++----- src/networking/src/mainloop/client.rs | 2 +- src/patch_server/src/lib.rs | 2 +- src/ship_server/src/auth.rs | 4 ++-- src/ship_server/src/lobby.rs | 2 +- tests/common.rs | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/login_server/src/character.rs b/src/login_server/src/character.rs index c317be9..3bce346 100644 --- a/src/login_server/src/character.rs +++ b/src/login_server/src/character.rs @@ -177,7 +177,7 @@ impl ClientState { user: None, characters: None, guildcard_data_buffer: None, - session: Session::new(), + session: Session::default(), } } } @@ -342,15 +342,15 @@ impl CharacterServerState { if let Some(connected_client) = self.connected_clients.read().await.get(&user.id) { if let Some(expires) = connected_client.expires { if expires > chrono::Utc::now() { - return Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(AccountStatus::AlreadyOnline, Session::new()))]); + return Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(AccountStatus::AlreadyOnline, Session::default()))]); } } else { - return Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(AccountStatus::AlreadyOnline, Session::new()))]); + return Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(AccountStatus::AlreadyOnline, Session::default()))]); } } - let mut response = LoginResponse::by_status(AccountStatus::Ok, Session::new()); + let mut response = LoginResponse::by_status(AccountStatus::Ok, Session::default()); response.guildcard = user.guildcard; response.team_id = user.team_id.map_or(0, |ti| ti); @@ -367,7 +367,7 @@ impl CharacterServerState { Ok(vec![SendCharacterPacket::LoginResponse(response)]) }, Err(err) => { - Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(err, Session::new()))]) + Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(err, Session::default()))]) } } } diff --git a/src/networking/src/mainloop/client.rs b/src/networking/src/mainloop/client.rs index 3bcb971..619a1a6 100644 --- a/src/networking/src/mainloop/client.rs +++ b/src/networking/src/mainloop/client.rs @@ -72,7 +72,7 @@ impl PacketReceiver { let mut dec_buf = { //let mut cipher = self.cipher.lock().await; let block_chunk_len = self.recv_buffer.len() / self.cipher.block_size() * self.cipher.block_size(); - let buf = self.recv_buffer.drain(..block_chunk_len).collect(); + let buf = self.recv_buffer.drain(..block_chunk_len).collect::>(); self.cipher.decrypt(&buf)? }; self.incoming_data.append(&mut dec_buf); diff --git a/src/patch_server/src/lib.rs b/src/patch_server/src/lib.rs index 565530d..ecf51f9 100644 --- a/src/patch_server/src/lib.rs +++ b/src/patch_server/src/lib.rs @@ -341,7 +341,7 @@ impl Iterator for SendFileIterator { if len == 0 { self.current_file = None; self.chunk_num = 0; - Some(SendPatchPacket::EndFileSend(EndFileSend::new())) + Some(SendPatchPacket::EndFileSend(EndFileSend::default())) } else { let mut crc = crc32::Digest::new(crc32::IEEE); diff --git a/src/ship_server/src/auth.rs b/src/ship_server/src/auth.rs index b8f746e..2c60f67 100644 --- a/src/ship_server/src/auth.rs +++ b/src/ship_server/src/auth.rs @@ -23,7 +23,7 @@ where { Ok(match get_login_status(entity_gateway, &pkt).await { Ok(user) => { - let mut response = LoginResponse::by_status(AccountStatus::Ok, Session::new()); + let mut response = LoginResponse::by_status(AccountStatus::Ok, Session::default()); response.guildcard = user.id.0; response.team_id = user.team_id.map_or(31, |ti| ti); let characters = entity_gateway.get_characters_by_user(&user).await?; @@ -44,7 +44,7 @@ where vec![SendShipPacket::LoginResponse(response), SendShipPacket::ShipBlockList(ShipBlockList::new(ship_name, num_blocks))] }, Err(err) => { - vec![SendShipPacket::LoginResponse(LoginResponse::by_status(err, Session::new()))] + vec![SendShipPacket::LoginResponse(LoginResponse::by_status(err, Session::default()))] } }) } diff --git a/src/ship_server/src/lobby.rs b/src/ship_server/src/lobby.rs index 8e6090a..d29d8d4 100644 --- a/src/ship_server/src/lobby.rs +++ b/src/ship_server/src/lobby.rs @@ -48,7 +48,7 @@ pub async fn block_selected(id: ClientId, character: fc, }))), (id, SendShipPacket::CharDataRequest(CharDataRequest {})), - (id, SendShipPacket::LobbyList(LobbyList::new())), + (id, SendShipPacket::LobbyList(LobbyList::default())), ]) })}).await? } diff --git a/tests/common.rs b/tests/common.rs index 5a2e835..31f373e 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -112,7 +112,7 @@ pub async fn log_in_char(ship: &mut ShipServerState