parent
f098a3cd9b
commit
3ef5eb2a56
5 changed files with 53 additions and 177 deletions
75
Cargo.toml
75
Cargo.toml
|
@ -1,24 +1,55 @@
|
|||
[package]
|
||||
name = "sdkserver"
|
||||
edition = "2021"
|
||||
version.workspace = true
|
||||
[workspace]
|
||||
members = [ "common","gameserver", "protocol", "qwer", "qwer/qwer-derive", "sdkserver"]
|
||||
resolver = "2"
|
||||
|
||||
[dependencies]
|
||||
axum.workspace = true
|
||||
axum-server.workspace = true
|
||||
encoding.workspace = true
|
||||
leb128.workspace = true
|
||||
anyhow.workspace = true
|
||||
env_logger.workspace = true
|
||||
tokio.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
tokio-util.workspace = true
|
||||
ansi_term.workspace = true
|
||||
rand.workspace = true
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
|
||||
[[bin]]
|
||||
name = "nap-sdkserver"
|
||||
path = "src/main.rs"
|
||||
[workspace.dependencies]
|
||||
ansi_term = "0.12.1"
|
||||
anyhow = "1.0.81"
|
||||
axum = "0.7.4"
|
||||
axum-server = "0.6.0"
|
||||
byteorder = "1.5.0"
|
||||
dirs = "5.0.1"
|
||||
encoding = "0.2.33"
|
||||
env_logger = "0.11.3"
|
||||
heck = "0.5.0"
|
||||
hex = "0.4.3"
|
||||
leb128 = "0.2.5"
|
||||
paste = "1.0.14"
|
||||
sysinfo = "0.30.7"
|
||||
rand = "0.8.5"
|
||||
parking_lot = "0.12.3"
|
||||
|
||||
csv = "1.3.0"
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde_json = "1.0.114"
|
||||
|
||||
tokio = { version = "1.36.0", features = ["full"] }
|
||||
tokio-util = { version = "0.7.10", features = ["io"] }
|
||||
|
||||
tracing = "0.1.40"
|
||||
tracing-futures = "0.2.5"
|
||||
tracing-log = { version = "0.2.0", features = ["std", "log-tracer"] }
|
||||
tracing-subscriber = { version = "0.3.18", features = [
|
||||
"env-filter",
|
||||
"registry",
|
||||
"std",
|
||||
"tracing",
|
||||
"tracing-log",
|
||||
] }
|
||||
tracing-bunyan-formatter = "0.3.9"
|
||||
|
||||
itertools = "0.13.0"
|
||||
|
||||
common = { version = "0.1.0", path = "common" }
|
||||
protocol = { version = "0.1.0", path = "protocol" }
|
||||
qwer = { version = "0.1.0", path = "qwer", features = ["full"] }
|
||||
qwer-derive = { version = "0.1.0", path = "qwer/qwer-derive" }
|
||||
|
||||
[profile.release]
|
||||
strip = true # Automatically strip symbols from the binary.
|
||||
lto = true # Link-time optimization.
|
||||
opt-level = 3 # Optimize for speed.
|
||||
codegen-units = 1 # Maximum size reduction optimizations.
|
||||
|
|
38
config.rs
38
config.rs
|
@ -1,38 +0,0 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct ConfigInfo {
|
||||
pub min_version: String,
|
||||
pub latest_version: String,
|
||||
pub game_res_url: String,
|
||||
pub design_data_url: String,
|
||||
pub server_list_url: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct ConfigInfoGroup {
|
||||
pub version_info_groups: HashMap<String, ConfigInfo>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct AppConfig {
|
||||
pub info_groups: HashMap<String, ConfigInfoGroup>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ServerListInfo {
|
||||
pub sid: i32,
|
||||
pub server_name: String,
|
||||
pub ip: String,
|
||||
pub port: String,
|
||||
pub notice_region: String,
|
||||
pub protocol: String,
|
||||
#[serde(rename = "$Type")]
|
||||
ty: String,
|
||||
}
|
23
crypto.rs
23
crypto.rs
|
@ -1,23 +0,0 @@
|
|||
use encoding::all::UTF_16LE;
|
||||
use encoding::{EncoderTrap, Encoding};
|
||||
|
||||
pub fn encrypt_config(content: &str, key: &str) -> Vec<u8> {
|
||||
let mut content_bytes = UTF_16LE.encode(content, EncoderTrap::Strict).unwrap();
|
||||
let key_bytes = UTF_16LE.encode(key, EncoderTrap::Strict).unwrap();
|
||||
|
||||
for i in 0..content_bytes.len() {
|
||||
content_bytes[i] ^= key_bytes[i % key_bytes.len()];
|
||||
}
|
||||
|
||||
let k = key.as_bytes();
|
||||
|
||||
let mut out = Vec::with_capacity(4 + k.len() + 8 + content_bytes.len());
|
||||
|
||||
leb128::write::unsigned(&mut out, u64::try_from(k.len()).unwrap()).unwrap();
|
||||
out.extend_from_slice(k);
|
||||
out.extend([0u8; 4]);
|
||||
out.extend(u32::try_from(content_bytes.len()).unwrap().to_le_bytes());
|
||||
out.extend(content_bytes);
|
||||
|
||||
out
|
||||
}
|
23
entry.rs
23
entry.rs
|
@ -1,23 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct HttpRet<Ext> {
|
||||
pub error_code: i32,
|
||||
pub error_msg: Option<String>,
|
||||
pub ext: Ext,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct EntryTokenRet {
|
||||
pub birthday: String,
|
||||
pub country: String,
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct EntryAccountServerRet {
|
||||
pub address: String,
|
||||
}
|
71
main.rs
71
main.rs
|
@ -1,71 +0,0 @@
|
|||
use anyhow::Result;
|
||||
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
|
||||
|
||||
use axum::{
|
||||
routing::{get, post},
|
||||
Router,
|
||||
};
|
||||
|
||||
mod crypto;
|
||||
mod data;
|
||||
mod services;
|
||||
|
||||
use services::{auth, config, entry, errors};
|
||||
|
||||
const HOST: &str = "0.0.0.0";
|
||||
const PORT: u16 = 21000;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
init_tracing()?;
|
||||
|
||||
let router = Router::new()
|
||||
.route(auth::RISKY_API_CHECK_ENDPOINT, post(auth::risky_api_check))
|
||||
.route(
|
||||
auth::LOGIN_WITH_PASSWORD_ENDPOINT,
|
||||
post(auth::login_with_password),
|
||||
)
|
||||
.route(
|
||||
auth::LOGIN_WITH_SESSION_TOKEN_ENDPOINT,
|
||||
post(auth::login_with_session_token),
|
||||
)
|
||||
.route(
|
||||
auth::GRANTER_LOGIN_VERIFICATION_ENDPOINT,
|
||||
post(auth::granter_login_verification),
|
||||
)
|
||||
.route(config::APP_CONFIG_ENDPOINT, get(config::application))
|
||||
.route(config::SERVER_LIST_ENDPOINT, get(config::server_list))
|
||||
.route(
|
||||
config::VERSIONS_BUNDLE_ENDPOINT,
|
||||
get(config::versions_bundle),
|
||||
)
|
||||
.route(entry::ACCOUNT_TOKEN_ENDPOINT, post(entry::account_token))
|
||||
.route(entry::ACCOUNT_SERVER_ENDPOINT, post(entry::account_server))
|
||||
.fallback(errors::not_found);
|
||||
|
||||
let bind_url = format!("{HOST}:{PORT}");
|
||||
let http_server = axum_server::bind(bind_url.parse()?);
|
||||
tracing::info!("SDK Server is listening at {bind_url}");
|
||||
|
||||
http_server.serve(router.into_make_service()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn init_tracing() -> Result<()> {
|
||||
#[cfg(target_os = "windows")]
|
||||
ansi_term::enable_ansi_support().unwrap();
|
||||
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
let log_filter = EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| EnvFilter::try_new("info").unwrap())
|
||||
.add_directive("sdkserver=debug".parse().unwrap());
|
||||
|
||||
tracing::subscriber::set_global_default(
|
||||
Registry::default()
|
||||
.with(log_filter)
|
||||
.with(tracing_subscriber::fmt::Layer::default()),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in a new issue