avoiding_doing_real_work #144
@ -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"
|
||||
|
@ -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<ClientState>; N]>(&client_states)
|
||||
std::mem::transmute_copy(&client_states)
|
||||
};
|
||||
|
||||
Ok(func(client_states).await)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ impl From<PgCharacter> 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,
|
||||
|
@ -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<u8>) {
|
||||
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);
|
||||
@ -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<EG: EntityGateway + Clone> CharacterServerState<EG> {
|
||||
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<EG: EntityGateway + Clone> CharacterServerState<EG> {
|
||||
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()))])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -379,7 +379,7 @@ impl<EG: EntityGateway + Clone> CharacterServerState<EG> {
|
||||
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()
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
)
|
||||
);
|
||||
|
@ -72,7 +72,7 @@ impl<C: PSOCipher> PacketReceiver<C> {
|
||||
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::<Vec<_>>();
|
||||
self.cipher.decrypt(&buf)?
|
||||
};
|
||||
self.incoming_data.append(&mut dec_buf);
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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],
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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()))]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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(),
|
||||
|
@ -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?
|
||||
}
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -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<QuestList, QuestLoadError> {
|
||||
Ok(Default::default())
|
||||
@ -107,12 +107,12 @@ pub async fn log_in_char<EG: EntityGateway + Clone>(ship: &mut ShipServerState<E
|
||||
version: 0,
|
||||
unknown1: [0; 6],
|
||||
team: 0,
|
||||
username: utf8_to_array!(username, 16),
|
||||
username: utf8_to_array(&username),
|
||||
unknown2: [0; 32],
|
||||
password: utf8_to_array!(password, 16),
|
||||
password: utf8_to_array(&password),
|
||||
unknown3: [0; 40],
|
||||
hwinfo: [0; 8],
|
||||
session: Session::new(),
|
||||
session: Session::default(),
|
||||
})).await.unwrap();
|
||||
}
|
||||
|
||||
@ -136,8 +136,8 @@ pub async fn leave_room<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG
|
||||
pub async fn create_room_with_difficulty<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, 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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user