First push
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
[package]
|
||||
name = "sdkserver"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
env_logger.workspace = true
|
||||
|
||||
axum.workspace = true
|
||||
axum-server.workspace = true
|
||||
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
|
||||
tokio.workspace = true
|
||||
tokio-util.workspace = true
|
||||
|
||||
tracing.workspace = true
|
||||
tracing-futures.workspace = true
|
||||
tracing-log.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
tracing-bunyan-formatter.workspace = true
|
||||
ansi_term.workspace = true
|
||||
|
||||
prost.workspace = true
|
||||
rbase64.workspace = true
|
||||
proto.workspace = true
|
||||
@@ -0,0 +1,29 @@
|
||||
#[macro_export]
|
||||
macro_rules! log_error {
|
||||
($e:expr) => {
|
||||
if let Err(e) = $e {
|
||||
tracing::error!(error.message = %format!("{}", &e), "{:?}", e);
|
||||
}
|
||||
};
|
||||
($context:expr, $e:expr $(,)?) => {
|
||||
if let Err(e) = $e {
|
||||
let e = format!("{:?}", ::anyhow::anyhow!(e).context($context));
|
||||
tracing::error!(error.message = %format!("{}", &e), "{:?}", e);
|
||||
}
|
||||
};
|
||||
($ok_context:expr, $err_context:expr, $e:expr $(,)?) => {
|
||||
if let Err(e) = $e {
|
||||
let e = format!("{:?}", ::anyhow::anyhow!(e).context($err_context));
|
||||
tracing::error!(error.message = %format!("{}", &e), "{:?}", e);
|
||||
} else {
|
||||
tracing::info!($ok_context);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn init_tracing() {
|
||||
#[cfg(target_os = "windows")]
|
||||
ansi_term::enable_ansi_support().unwrap();
|
||||
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
use anyhow::Result;
|
||||
use axum::routing::{get, post};
|
||||
use axum::Router;
|
||||
use logging::init_tracing;
|
||||
use services::{auth, dispatch, errors};
|
||||
use tracing::Level;
|
||||
|
||||
mod logging;
|
||||
mod services;
|
||||
|
||||
const PORT: u16 = 21000;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
init_tracing();
|
||||
|
||||
let span = tracing::span!(Level::DEBUG, "main");
|
||||
let _ = span.enter();
|
||||
|
||||
let router = Router::new()
|
||||
.route(
|
||||
dispatch::QUERY_DISPATCH_ENDPOINT,
|
||||
get(dispatch::query_dispatch),
|
||||
)
|
||||
.route(
|
||||
dispatch::QUERY_GATEWAY_ENDPOINT,
|
||||
get(dispatch::query_gateway),
|
||||
)
|
||||
.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),
|
||||
)
|
||||
.fallback(errors::not_found);
|
||||
|
||||
let addr = format!("0.0.0.0:{PORT}");
|
||||
let server = axum_server::bind(addr.parse()?);
|
||||
|
||||
tracing::info!("sdkserver is listening at {addr}");
|
||||
server.serve(router.into_make_service()).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
use axum::Json;
|
||||
use serde_json::json;
|
||||
|
||||
pub const LOGIN_WITH_PASSWORD_ENDPOINT: &str = "/:product_name/mdk/shield/api/login/";
|
||||
pub const LOGIN_WITH_SESSION_TOKEN_ENDPOINT: &str = "/:product_name/mdk/shield/api/verify";
|
||||
pub const GRANTER_LOGIN_VERIFICATION_ENDPOINT: &str = "/:product_name/combo/granter/login/v2/login";
|
||||
pub const RISKY_API_CHECK_ENDPOINT: &str = "/account/risky/api/check";
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn login_with_password() -> Json<serde_json::Value> {
|
||||
Json(json!({
|
||||
"data": {
|
||||
"account": {
|
||||
"area_code": "**",
|
||||
"email": "ReversedRooms",
|
||||
"country": "RU",
|
||||
"is_email_verify": "1",
|
||||
"token": "mostsecuretokenever",
|
||||
"uid": "1337"
|
||||
},
|
||||
"device_grant_required": false,
|
||||
"reactivate_required": false,
|
||||
"realperson_required": false,
|
||||
"safe_mobile_required": false
|
||||
},
|
||||
"message": "OK",
|
||||
"retcode": 0
|
||||
}))
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn login_with_session_token() -> Json<serde_json::Value> {
|
||||
Json(json!({
|
||||
"data": {
|
||||
"account": {
|
||||
"area_code": "**",
|
||||
"email": "ReversedRooms",
|
||||
"country": "RU",
|
||||
"is_email_verify": "1",
|
||||
"token": "mostsecuretokenever",
|
||||
"uid": "1337"
|
||||
},
|
||||
"device_grant_required": false,
|
||||
"reactivate_required": false,
|
||||
"realperson_required": false,
|
||||
"safe_mobile_required": false
|
||||
},
|
||||
"message": "OK",
|
||||
"retcode": 0
|
||||
}))
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn granter_login_verification() -> Json<serde_json::Value> {
|
||||
Json(json!({
|
||||
"data": {
|
||||
"account_type": 1,
|
||||
"combo_id": "1337",
|
||||
"combo_token": "9065ad8507d5a1991cb6fddacac5999b780bbd92",
|
||||
"data": "{\"guest\":false}",
|
||||
"heartbeat": false,
|
||||
"open_id": "1337"
|
||||
},
|
||||
"message": "OK",
|
||||
"retcode": 0
|
||||
}))
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn risky_api_check() -> Json<serde_json::Value> {
|
||||
Json(json!({
|
||||
"data": {
|
||||
"id": "06611ed14c3131a676b19c0d34c0644b",
|
||||
"action": "ACTION_NONE",
|
||||
"geetest": null
|
||||
},
|
||||
"message": "OK",
|
||||
"retcode": 0
|
||||
}))
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
use prost::Message;
|
||||
use proto::{Dispatch, Gateserver, RegionInfo};
|
||||
|
||||
pub const QUERY_DISPATCH_ENDPOINT: &str = "/query_dispatch";
|
||||
pub const QUERY_GATEWAY_ENDPOINT: &str = "/query_gateway";
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn query_dispatch() -> String {
|
||||
let rsp = Dispatch {
|
||||
retcode: 0,
|
||||
region_list: vec![RegionInfo {
|
||||
name: String::from("RobinSR"),
|
||||
title: String::from("RobinSR"),
|
||||
env_type: String::from("9"),
|
||||
dispatch_url: String::from("http://127.0.0.1:21000/query_gateway"),
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut buff = Vec::new();
|
||||
rsp.encode(&mut buff).unwrap();
|
||||
|
||||
rbase64::encode(&buff)
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn query_gateway() -> String {
|
||||
let rsp = Gateserver {
|
||||
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",
|
||||
),
|
||||
ifix_version: String::from("0"),
|
||||
lua_version: String::from("6755976"),
|
||||
jblkncaoiao: true,
|
||||
hjdjakjkdbi: true,
|
||||
ldknmcpffim: true,
|
||||
feehapamfci: true,
|
||||
eebfeohfpph: true,
|
||||
dfmjjcfhfea: true,
|
||||
najikcgjgan: true,
|
||||
giddjofkndm: true,
|
||||
fbnbbembcgn: false,
|
||||
dedgfjhbnok: false,
|
||||
use_tcp: true,
|
||||
linlaijbboh: false,
|
||||
ahmbfbkhmgh: false,
|
||||
nmdccehcdcc: false,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut buff = Vec::new();
|
||||
rsp.encode(&mut buff).unwrap();
|
||||
|
||||
rbase64::encode(&buff)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
use axum::http::{StatusCode, Uri};
|
||||
use axum::response::IntoResponse;
|
||||
|
||||
pub async fn not_found(uri: Uri) -> impl IntoResponse {
|
||||
tracing::warn!("unhandled http request: {uri}");
|
||||
StatusCode::NOT_FOUND
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod auth;
|
||||
pub mod dispatch;
|
||||
pub mod errors;
|
||||
Reference in New Issue
Block a user