diff --git a/Cargo.toml b/Cargo.toml index 7dffbc2..ba25d9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libfj" -version = "0.7.4" +version = "0.7.5" authors = ["NGnius (Graham) "] edition = "2018" description = "An unofficial collection of APIs used in FreeJam games and mods" @@ -16,22 +16,22 @@ exclude = [ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -serde = { version = "^1", features = ["derive"]} -serde_json = "^1" -reqwest = { version = "^0.11", features = ["json", "rustls-tls"], optional = true, default-features=false} -url = "^2.2" -ureq = { version = "^2", features = ["json"], optional = true} +serde = { version = "1", features = ["derive"]} +serde_json = "1" +reqwest = { version = "0.12", features = ["json", "rustls-tls"], optional = true, default-features=false} +url = "2" +ureq = { version = "2", features = ["json"], optional = true} async-trait = { version = "0.1", optional = true } -base64 = "^0.13" -num_enum = "^0.5" -chrono = {version = "^0.4", optional = true} +base64 = "0.22" +num_enum = "0.5" +chrono = {version = "0.4", optional = true} highhash = {version = "^0.1", optional = true} -half = {version = "^1.7", optional = true} +half = {version = "2", optional = true} libfj_parsable_macro_derive = {version = "0.5.3", optional = true} #libfj_parsable_macro_derive = {path = "./parsable_macro_derive", optional = true} -obj = {version = "^0.10", optional = true} -genmesh = {version = "^0.6", optional = true} -cgmath = {version = "^0.18", optional = true} +obj = {version = "0.10", optional = true} +genmesh = {version = "0.6", optional = true} +cgmath = {version = "0.18", optional = true} [dev-dependencies] tokio = { version = "1.4.0", features = ["macros"]} diff --git a/parsable_macro_derive/Cargo.toml b/parsable_macro_derive/Cargo.toml index e6eac35..87c4d37 100644 --- a/parsable_macro_derive/Cargo.toml +++ b/parsable_macro_derive/Cargo.toml @@ -12,5 +12,5 @@ repository = "https://github.com/NGnius/libfj" proc-macro = true [dependencies] -syn = "1.0" +syn = "2.0" quote = "1.0" diff --git a/src/cardlife/client_json.rs b/src/cardlife/client_json.rs new file mode 100644 index 0000000..5658988 --- /dev/null +++ b/src/cardlife/client_json.rs @@ -0,0 +1,25 @@ +use std::path::PathBuf; +use serde::{Deserialize, Serialize}; + +/// ServerConfig.json format in the root of the game files +#[derive(Deserialize, Serialize, Clone)] +pub struct ServerConfig { + #[serde(rename = "AuthUrl")] + pub auth_url: String, + #[serde(rename = "LobbyUrl")] + pub lobby_url: String, + #[serde(rename = "InventoryUrl")] + pub inventory_url: String, + #[serde(rename = "FallbackAuthUrl")] + pub fallback_auth_url: String, + #[serde(rename = "FallbackLobbyUrl")] + pub fallback_lobby_url: String, + #[serde(rename = "FallbackInventoryUrl")] + pub fallback_inventory_url: String, + #[serde(rename = "GameServerPath")] + pub game_server_path: PathBuf, + #[serde(rename = "GameServerExe")] + pub game_server_exe: PathBuf, + #[serde(rename = "PhotonUrl")] + pub photon_url: String, +} diff --git a/src/cardlife/live.rs b/src/cardlife/live.rs index 7ef1846..f8a0a3c 100644 --- a/src/cardlife/live.rs +++ b/src/cardlife/live.rs @@ -3,8 +3,8 @@ use url::{Url}; use crate::cardlife::{AuthenticationInfo, AuthenticationPayload, LobbyInfo, LobbyPayload}; -const AUTHENTICATION_DOMAIN: &str = "https://live-auth.cardlifegame.com/"; -const LOBBY_DOMAIN: &str = "https://live-lobby.cardlifegame.com/"; +pub const AUTHENTICATION_DOMAIN: &str = "https://live-auth.cardlifegame.com/"; +pub const LOBBY_DOMAIN: &str = "https://live-lobby.cardlifegame.com/"; /// Cardlife live information API pub struct LiveAPI { diff --git a/src/cardlife/live_json.rs b/src/cardlife/live_json.rs index 161ab10..a5fa5a6 100644 --- a/src/cardlife/live_json.rs +++ b/src/cardlife/live_json.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize, Clone)] -pub(crate) struct AuthenticationPayload { +pub struct AuthenticationPayload { #[serde(rename = "EmailAddress")] pub email_address: String, #[serde(rename = "Password")] @@ -49,7 +49,7 @@ impl std::string::ToString for AuthenticationInfo { } #[derive(Deserialize, Serialize, Clone)] -pub(crate) struct LobbyPayload { +pub struct LobbyPayload { #[serde(rename = "PublicId")] pub public_id: String, } diff --git a/src/cardlife/mod.rs b/src/cardlife/mod.rs index f934e04..46e0fde 100644 --- a/src/cardlife/mod.rs +++ b/src/cardlife/mod.rs @@ -2,6 +2,8 @@ //! LiveAPI and CLreServer are mostly complete, but some other APIs are missing. mod client; +mod client_json; +pub use client_json::ServerConfig; mod server; mod server_json; @@ -10,6 +12,6 @@ pub use self::server::{CLreServer}; mod live; mod live_json; -pub use self::live::{LiveAPI}; +pub use self::live::{LiveAPI, AUTHENTICATION_DOMAIN, LOBBY_DOMAIN}; pub use self::live_json::{AuthenticationInfo, LobbyInfo, LiveGameInfo}; -pub(crate) use self::live_json::{AuthenticationPayload, LobbyPayload}; +pub use self::live_json::{AuthenticationPayload, LobbyPayload}; diff --git a/src/robocraft/account.rs b/src/robocraft/account.rs index 2d888cd..1df25e9 100644 --- a/src/robocraft/account.rs +++ b/src/robocraft/account.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; use ureq::{Agent, Error}; use serde_json::{to_string, from_slice}; +use base64::Engine; use crate::robocraft::ITokenProvider; @@ -101,7 +102,7 @@ impl AuthenticationResponseInfo { // header is before dot, signature is after dot. // data is sandwiched in the middle, and it's all we care about let data = self.token.split(".").collect::>()[1]; - let data_vec = base64::decode(data).unwrap(); + let data_vec = base64::engine::general_purpose::STANDARD.decode(data).unwrap(); from_slice::(&data_vec).unwrap() } } diff --git a/src/robocraft/cubes.rs b/src/robocraft/cubes.rs index b3307f4..868a661 100644 --- a/src/robocraft/cubes.rs +++ b/src/robocraft/cubes.rs @@ -1,5 +1,5 @@ -use base64::{decode_config_buf, STANDARD}; use std::io::Read; +use base64::Engine; // TODO(maybe) parse iteratively instead of one-shot @@ -203,10 +203,8 @@ impl std::default::Default for Cube { impl std::convert::From for Cubes { fn from(other: crate::robocraft::FactoryRobotGetInfo) -> Self { - let mut cube_buf = Vec::new(); - let mut colour_buf = Vec::new(); - decode_config_buf(other.cube_data, STANDARD, &mut cube_buf).unwrap(); - decode_config_buf(other.colour_data, STANDARD, &mut colour_buf).unwrap(); + let mut cube_buf = base64::engine::general_purpose::STANDARD.decode(other.cube_data).unwrap(); + let mut colour_buf = base64::engine::general_purpose::STANDARD.decode(other.colour_data).unwrap(); Self::parse(&mut cube_buf, &mut colour_buf).unwrap() } } diff --git a/src/robocraft2/portal.rs b/src/robocraft2/portal.rs index 62c94cc..58740bc 100644 --- a/src/robocraft2/portal.rs +++ b/src/robocraft2/portal.rs @@ -4,7 +4,8 @@ use reqwest::{Client, Error}; //use cookie_store::CookieStore; //use url::{Url}; use serde_json::from_slice; -use chrono::{DateTime, naive::NaiveDateTime, Utc}; +use chrono::{DateTime, Utc}; +use base64::Engine; const GAME_VERSION: &str = "100.0"; // currently, this accepts any version >= current public release const GAME_TARGET: &str = "Techblox"; @@ -172,7 +173,7 @@ impl PortalTokenProvider { impl ITokenProvider for PortalTokenProvider { async fn token(&mut self) -> Result { let decoded_jwt = self.jwt.decode_jwt_data(); - let expiry = DateTime::::from_utc(NaiveDateTime::from_timestamp(decoded_jwt.exp as i64, 0), Utc); + let expiry = DateTime::::from_timestamp(decoded_jwt.exp as i64, 0).unwrap(); let now = Utc::now(); if now >= expiry || self.token.token.is_none() { // refresh token when expired @@ -255,7 +256,7 @@ impl PortalCheckResponse { // header is before dot, signature is after dot. // data is sandwiched in the middle, and it's all we care about let data = self.token.split(".").collect::>()[1]; - let data_vec = base64::decode(data).unwrap(); + let data_vec = base64::engine::general_purpose::STANDARD.decode(data).unwrap(); from_slice::(&data_vec).unwrap() } } diff --git a/src/techblox/gamesave.rs b/src/techblox/gamesave.rs index 7f863ea..72384c1 100644 --- a/src/techblox/gamesave.rs +++ b/src/techblox/gamesave.rs @@ -74,7 +74,7 @@ impl Parsable for GameSave { let year = parse_u32(data)?; // parsed as i32 in-game for some reason let month = parse_u32(data)?; let day = parse_u32(data)?; - let date = NaiveDate::from_ymd(year as i32, month, day); + let date = NaiveDate::from_ymd_opt(year as i32, month, day).unwrap(); let ticks = parse_i64(data)?; // unused let cube_count = parse_u32(data)?; // parsed as i32 in-game for some reason let max_e_id = parse_u32(data)?; // unused