SDKServer: versions.json configuration for hotfix links
This commit is contained in:
parent
adbdaa38ab
commit
b2427a333b
7 changed files with 95 additions and 57 deletions
|
@ -1,4 +0,0 @@
|
|||
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
|
|
@ -13,6 +13,8 @@ axum-server.workspace = true
|
|||
dirs.workspace = true
|
||||
dotenv.workspace = true
|
||||
|
||||
lazy_static.workspace = true
|
||||
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
|
||||
|
|
3
sdkserver/src/config/mod.rs
Normal file
3
sdkserver/src/config/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
mod version_config;
|
||||
|
||||
pub use version_config::INSTANCE as versions;
|
40
sdkserver/src/config/version_config.rs
Normal file
40
sdkserver/src/config/version_config.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use serde::Deserialize;
|
||||
use serde_json::from_str;
|
||||
|
||||
const DEFAULT_VERSIONS: &str = include_str!("../../versions.json");
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct VersionConfig {
|
||||
pub asset_bundle_url: String,
|
||||
pub ex_resource_url: String,
|
||||
pub lua_url: String,
|
||||
pub lua_version: String,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref INSTANCE: HashMap<String, VersionConfig> = {
|
||||
let local_config = std::path::Path::new("versions.json");
|
||||
let data = if local_config.exists() {
|
||||
std::fs::read_to_string("versions.json").unwrap()
|
||||
} else {
|
||||
let config = dirs::config_dir()
|
||||
.expect("No config directory found")
|
||||
.join("hkrpg-sdkserver");
|
||||
|
||||
std::fs::create_dir_all(&config).unwrap();
|
||||
|
||||
let env = config.join("versions.json");
|
||||
|
||||
if !env.exists() {
|
||||
std::fs::write(&env, DEFAULT_VERSIONS).unwrap();
|
||||
}
|
||||
|
||||
std::fs::read_to_string(&env).unwrap()
|
||||
};
|
||||
|
||||
from_str(&data).unwrap()
|
||||
};
|
||||
}
|
|
@ -3,19 +3,17 @@ 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 config;
|
||||
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();
|
||||
|
@ -52,26 +50,3 @@ 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(())
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use std::env;
|
||||
|
||||
use crate::config::versions;
|
||||
use axum::extract::Query;
|
||||
use prost::Message;
|
||||
use proto::{Dispatch, Gateserver, RegionInfo};
|
||||
use serde::Deserialize;
|
||||
|
||||
pub const QUERY_DISPATCH_ENDPOINT: &str = "/query_dispatch";
|
||||
pub const QUERY_GATEWAY_ENDPOINT: &str = "/query_gateway";
|
||||
|
@ -26,16 +27,22 @@ pub async fn query_dispatch() -> String {
|
|||
rbase64::encode(&buff)
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct QueryGatewayParameters {
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn query_gateway() -> String {
|
||||
let rsp = Gateserver {
|
||||
pub async fn query_gateway(parameters: Query<QueryGatewayParameters>) -> String {
|
||||
let rsp = if let Some(config) = versions.get(¶meters.version) {
|
||||
Gateserver {
|
||||
retcode: 0,
|
||||
ip: String::from("127.0.0.1"),
|
||||
port: 23301,
|
||||
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(),
|
||||
asset_bundle_url: config.asset_bundle_url.clone(),
|
||||
ex_resource_url: config.ex_resource_url.clone(),
|
||||
lua_url: config.lua_url.clone(),
|
||||
lua_version: config.lua_version.clone(),
|
||||
ifix_version: String::from("0"),
|
||||
jblkncaoiao: true,
|
||||
hjdjakjkdbi: true,
|
||||
|
@ -52,6 +59,13 @@ pub async fn query_gateway() -> String {
|
|||
ahmbfbkhmgh: false,
|
||||
nmdccehcdcc: false,
|
||||
..Default::default()
|
||||
}
|
||||
} else {
|
||||
Gateserver {
|
||||
retcode: 9,
|
||||
msg: format!("forbidden version: {} or invalid bind", parameters.version),
|
||||
..Default::default()
|
||||
}
|
||||
};
|
||||
|
||||
let mut buff = Vec::new();
|
||||
|
|
8
sdkserver/versions.json
Normal file
8
sdkserver/versions.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"CNBETAWin2.1.51": {
|
||||
"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"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue