feat: preview user info
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1121,6 +1121,7 @@ dependencies = [
|
|||||||
"nyquest-preset",
|
"nyquest-preset",
|
||||||
"palc",
|
"palc",
|
||||||
"sdgb-api",
|
"sdgb-api",
|
||||||
|
"serde_json",
|
||||||
"snafu",
|
"snafu",
|
||||||
"spdlog-rs",
|
"spdlog-rs",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ resolver = "3"
|
|||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
sdgb-api = { path = "./sdgb-api" }
|
sdgb-api = { path = "./sdgb-api" }
|
||||||
|
|
||||||
snafu = { version = "0.8.6", features = ["backtrace", "rust_1_81"] }
|
snafu = { version = "0.8.6", features = ["backtrace", "rust_1_81"] }
|
||||||
|
serde_json = "1.0.141"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ license = "GPL-3.0"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
snafu = { workspace = true }
|
snafu = { workspace = true }
|
||||||
|
serde_json = { workspace = true }
|
||||||
|
|
||||||
digest = "0.10.7"
|
digest = "0.10.7"
|
||||||
hmac-sha256 = { version = "1.1.12", features = ["digest010", "traits010"] }
|
hmac-sha256 = { version = "1.1.12", features = ["digest010", "traits010"] }
|
||||||
@@ -20,7 +21,6 @@ nyquest = { version = "0.2.0", features = ["async", "json"] }
|
|||||||
|
|
||||||
# (de)serialization
|
# (de)serialization
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.141"
|
|
||||||
|
|
||||||
flate2 = "1.1.2"
|
flate2 = "1.1.2"
|
||||||
cbc = "0.1.2"
|
cbc = "0.1.2"
|
||||||
|
|||||||
70
sdgb-api/src/title/model/get_user_preview_api/mod.rs
Normal file
70
sdgb-api/src/title/model/get_user_preview_api/mod.rs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct GetUserPreviewApi {
|
||||||
|
pub user_id: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct GetUserPreviewApiResp {
|
||||||
|
pub user_id: i64,
|
||||||
|
pub user_name: String,
|
||||||
|
pub is_login: bool,
|
||||||
|
pub last_rom_version: String,
|
||||||
|
pub last_data_version: String,
|
||||||
|
pub last_login_date: String,
|
||||||
|
pub last_play_date: String,
|
||||||
|
pub player_rating: i64,
|
||||||
|
pub nameplate_id: i64,
|
||||||
|
pub icon_id: i64,
|
||||||
|
pub trophy_id: i64,
|
||||||
|
pub is_net_member: i64,
|
||||||
|
pub is_inherit: bool,
|
||||||
|
pub total_awake: i64,
|
||||||
|
pub disp_rate: i64,
|
||||||
|
pub daily_bonus_date: String,
|
||||||
|
pub ban_state: i64,
|
||||||
|
// pub last_game_id: Value,
|
||||||
|
// pub head_phone_volume: Value,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for GetUserPreviewApiResp {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.write_fmt(format_args!("ID: {}\n", self.user_id))?;
|
||||||
|
f.write_fmt(format_args!("昵称: {}\n", self.user_name))?;
|
||||||
|
f.write_fmt(format_args!("登录中: {}\n", self.is_login))?;
|
||||||
|
|
||||||
|
f.write_fmt(format_args!("上次游戏版本: {}\n", self.last_rom_version))?;
|
||||||
|
f.write_fmt(format_args!("上次数据版本: {}\n", self.last_data_version))?;
|
||||||
|
|
||||||
|
f.write_fmt(format_args!("DX Rating: {}\n", self.player_rating))?;
|
||||||
|
f.write_fmt(format_args!("牌子: {}\n", self.nameplate_id))?;
|
||||||
|
f.write_fmt(format_args!("图标: {}\n", self.icon_id))?;
|
||||||
|
f.write_fmt(format_args!("trophy: {}\n", self.trophy_id))?;
|
||||||
|
f.write_fmt(format_args!("Net成员: {}\n", self.is_net_member))?;
|
||||||
|
f.write_fmt(format_args!("继承账号: {}\n", self.is_inherit))?;
|
||||||
|
f.write_fmt(format_args!("总觉醒: {}\n", self.total_awake))?;
|
||||||
|
|
||||||
|
f.write_fmt(format_args!(
|
||||||
|
"状态显示: {}\n",
|
||||||
|
match self.disp_rate {
|
||||||
|
0 => "全部都显示",
|
||||||
|
1 => "显示评级和段位",
|
||||||
|
2 => "显示评级和阶级",
|
||||||
|
3 => "显示段位和阶级",
|
||||||
|
4 => "只显示评级",
|
||||||
|
5 => "只显示段位",
|
||||||
|
6 => "只显示阶级",
|
||||||
|
7 => "全部都不显示",
|
||||||
|
_ => "未知",
|
||||||
|
}
|
||||||
|
))?;
|
||||||
|
|
||||||
|
f.write_fmt(format_args!("封禁状态: {}\n", self.ban_state))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,3 +2,6 @@ use serde::Serialize;
|
|||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Ping {}
|
pub struct Ping {}
|
||||||
|
|
||||||
|
mod get_user_preview_api;
|
||||||
|
pub use get_user_preview_api::{GetUserPreviewApi, GetUserPreviewApiResp};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ description = "CLI tool for SDGB protocol"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
snafu = { workspace = true }
|
snafu = { workspace = true }
|
||||||
sdgb-api = { workspace = true }
|
sdgb-api = { workspace = true }
|
||||||
|
serde_json = { workspace = true }
|
||||||
|
|
||||||
nyquest-preset = { version = "0.2.0", features = ["async"] }
|
nyquest-preset = { version = "0.2.0", features = ["async"] }
|
||||||
compio = { version = "0.15.0", default-features = false, features = [
|
compio = { version = "0.15.0", default-features = false, features = [
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ pub struct Cli {
|
|||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum Commands {
|
pub enum Commands {
|
||||||
Ping,
|
Ping,
|
||||||
|
Preview {
|
||||||
|
#[arg(short, long)]
|
||||||
|
user_id: u32,
|
||||||
|
},
|
||||||
/// Login with QRCode from wechat
|
/// Login with QRCode from wechat
|
||||||
QRLogin {
|
QRLogin {
|
||||||
/// content of the qrcode, only the last 64 characters were used
|
/// content of the qrcode, only the last 64 characters were used
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ use nyquest_preset::nyquest::ClientBuilder;
|
|||||||
use palc::Parser;
|
use palc::Parser;
|
||||||
use sdgb_api::{
|
use sdgb_api::{
|
||||||
all_net::QRCode,
|
all_net::QRCode,
|
||||||
title::{MaiVersionExt, Sdgb1_40, Sdgb1_50, methods::APIMethod, model::Ping},
|
title::{
|
||||||
|
MaiVersionExt, Sdgb1_40, Sdgb1_50,
|
||||||
|
methods::APIMethod,
|
||||||
|
model::{GetUserPreviewApi, GetUserPreviewApiResp, Ping},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use spdlog::{error, info};
|
use spdlog::{error, info};
|
||||||
|
|
||||||
@@ -18,8 +22,26 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
|
|||||||
let client = ClientBuilder::default().build_async().await?;
|
let client = ClientBuilder::default().build_async().await?;
|
||||||
|
|
||||||
match cmd.command {
|
match cmd.command {
|
||||||
|
commands::Commands::Preview { user_id } => {
|
||||||
|
let preview = Sdgb1_50::request(
|
||||||
|
&client,
|
||||||
|
APIMethod::GetUserPreviewApi,
|
||||||
|
user_id,
|
||||||
|
GetUserPreviewApi { user_id },
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let preview: GetUserPreviewApiResp = serde_json::from_slice(&preview)?;
|
||||||
|
println!("{preview}");
|
||||||
|
}
|
||||||
commands::Commands::Ping => {
|
commands::Commands::Ping => {
|
||||||
let decoded = Sdgb1_40::request(&client, APIMethod::Ping, "", Ping {}).await?;
|
let decoded = Sdgb1_40::request(
|
||||||
|
&client,
|
||||||
|
APIMethod::Ping,
|
||||||
|
"",
|
||||||
|
Ping {}, // note: must not be `Ping`, or serde_json serializes to nothing
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
info!("sdgb 1.40 resp: {:?}", String::from_utf8_lossy(&decoded));
|
info!("sdgb 1.40 resp: {:?}", String::from_utf8_lossy(&decoded));
|
||||||
let decoded = Sdgb1_50::request(&client, APIMethod::Ping, "", Ping {}).await?;
|
let decoded = Sdgb1_50::request(&client, APIMethod::Ping, "", Ping {}).await?;
|
||||||
info!("sdgb 1.50 resp: {:?}", String::from_utf8_lossy(&decoded));
|
info!("sdgb 1.50 resp: {:?}", String::from_utf8_lossy(&decoded));
|
||||||
|
|||||||
Reference in New Issue
Block a user