From bccf928bbe49e9675abc64fe9a88e6191c740179 Mon Sep 17 00:00:00 2001 From: xeon Date: Fri, 29 Mar 2024 13:31:19 +0300 Subject: [PATCH] SDKServer: query_gateway cdn links configuration --- Cargo.toml | 10 +++------- sdkserver/.env | 4 ++++ sdkserver/Cargo.toml | 3 +++ sdkserver/src/main.rs | 26 ++++++++++++++++++++++++++ sdkserver/src/services/dispatch.rs | 16 ++++++---------- 5 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 sdkserver/.env diff --git a/Cargo.toml b/Cargo.toml index 39d8521..1dff403 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,17 +14,13 @@ lazy_static = "1.4.0" axum = "0.7.4" axum-server = "0.6.0" +dirs = "5.0.1" +dotenv = "0.15.0" + env_logger = "0.11.3" rbase64 = "2.0.3" rand = "0.8.5" -rsa = { version = "0.9.6", features = [ - "sha1", - "nightly", - "pkcs5", - "serde", - "sha2", -] } prost = "0.12.3" prost-types = "0.12.3" diff --git a/sdkserver/.env b/sdkserver/.env new file mode 100644 index 0000000..fc74ce2 --- /dev/null +++ b/sdkserver/.env @@ -0,0 +1,4 @@ +ASSET_BUNDLE_URL=https://autopatchcn.bhsr.com/asb/BetaLive/output_6744505_89b2f5dc973e +EX_RESOURCE_URL=https://autopatchcn.bhsr.com/design_data/BetaLive/output_6759713_b4e0e740f0da +LUA_URL=https://autopatchcn.bhsr.com/lua/BetaLive/output_6755976_3c46d7c46e2c +LUA_VERSION=6755976 \ No newline at end of file diff --git a/sdkserver/Cargo.toml b/sdkserver/Cargo.toml index 9bca29b..11836b4 100644 --- a/sdkserver/Cargo.toml +++ b/sdkserver/Cargo.toml @@ -10,6 +10,9 @@ env_logger.workspace = true axum.workspace = true axum-server.workspace = true +dirs.workspace = true +dotenv.workspace = true + serde.workspace = true serde_json.workspace = true diff --git a/sdkserver/src/main.rs b/sdkserver/src/main.rs index cdbcbc5..724c066 100644 --- a/sdkserver/src/main.rs +++ b/sdkserver/src/main.rs @@ -3,16 +3,19 @@ use axum::routing::{get, post}; use axum::Router; use logging::init_tracing; use services::{auth, dispatch, errors}; +use std::path::Path; use tracing::Level; mod logging; mod services; const PORT: u16 = 21000; +const DEFAULT_DOTENV: &str = include_str!("../.env"); #[tokio::main] async fn main() -> Result<()> { init_tracing(); + init_config()?; let span = tracing::span!(Level::DEBUG, "main"); let _ = span.enter(); @@ -49,3 +52,26 @@ async fn main() -> Result<()> { Ok(()) } + +fn init_config() -> Result<()> { + let local_dotenv = Path::new(".env"); + if local_dotenv.exists() { + dotenv::dotenv()?; + } else { + let config = dirs::config_dir() + .ok_or_else(|| anyhow::anyhow!("No config directory found"))? + .join("hkrpg-sdkserver"); + + std::fs::create_dir_all(&config)?; + + let env = config.join(".env"); + + if !env.exists() { + std::fs::write(&env, DEFAULT_DOTENV)?; + } + + dotenv::from_path(&env)?; + } + + Ok(()) +} diff --git a/sdkserver/src/services/dispatch.rs b/sdkserver/src/services/dispatch.rs index 951514f..a79e8e5 100644 --- a/sdkserver/src/services/dispatch.rs +++ b/sdkserver/src/services/dispatch.rs @@ -1,3 +1,5 @@ +use std::env; + use prost::Message; use proto::{Dispatch, Gateserver, RegionInfo}; @@ -30,17 +32,11 @@ pub async fn query_gateway() -> String { retcode: 0, ip: String::from("127.0.0.1"), port: 23301, - asset_bundle_url: String::from( - "https://autopatchcn.bhsr.com/asb/BetaLive/output_6744505_89b2f5dc973e", - ), - lua_url: String::from( - "https://autopatchcn.bhsr.com/lua/BetaLive/output_6755976_3c46d7c46e2c", - ), - ex_resource_url: String::from( - "https://autopatchcn.bhsr.com/design_data/BetaLive/output_6759713_b4e0e740f0da", - ), + asset_bundle_url: env::var("ASSET_BUNDLE_URL").unwrap(), + ex_resource_url: env::var("EX_RESOURCE_URL").unwrap(), + lua_url: env::var("LUA_URL").unwrap(), + lua_version: env::var("LUA_VERSION").unwrap(), ifix_version: String::from("0"), - lua_version: String::from("6755976"), jblkncaoiao: true, hjdjakjkdbi: true, ldknmcpffim: true,