Skip to content

Commit

Permalink
使用 clippy 更新了 format! 宏的新使用方法
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-xmh committed Feb 7, 2023
1 parent 66b0ca3 commit 161e54b
Show file tree
Hide file tree
Showing 23 changed files with 181 additions and 251 deletions.
11 changes: 4 additions & 7 deletions scl-core/src/auth/authlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ pub(crate) struct RefreshBody {
}

async fn get_head_skin(api_location: &str, uuid: &str) -> DynResult<(Vec<u8>, Vec<u8>)> {
let uri = format!(
"{}sessionserver/session/minecraft/profile/{}",
api_location, uuid
);
let uri = format!("{api_location}sessionserver/session/minecraft/profile/{uuid}");
let result: ProfileResponse = crate::http::no_retry::get(&uri)
.await
.map_err(|e| anyhow::anyhow!("发送获取皮肤请求到 {} 时发生错误:{:?}", uri, e))?
Expand Down Expand Up @@ -100,7 +97,7 @@ pub async fn refresh_token(
} = auth_method
{
let res: RequestResult<AuthenticateResponse> = dbg!(crate::http::no_retry::post_data(
dbg!(&format!("{}authserver/refresh", api_location)),
dbg!(&format!("{api_location}authserver/refresh")),
dbg!(&RefreshBody {
access_token: access_token.to_owned_string(),
client_token: client_token.to_owned(),
Expand Down Expand Up @@ -197,7 +194,7 @@ pub async fn start_auth(
let api_location = if api_location.ends_with('/') {
api_location
} else {
format!("{}/", api_location)
format!("{api_location}/")
};
let api_location_url = url::Url::from_str(&api_location)?;

Expand Down Expand Up @@ -238,7 +235,7 @@ pub async fn start_auth(
let server_meta = base64::encode(server_meta);

// 登录链接
let auth_url = format!("{}authserver/authenticate", api_location);
let auth_url = format!("{api_location}authserver/authenticate");
let auth_body = AuthenticateBody {
username: username.to_owned(),
password: password.take_string(),
Expand Down
9 changes: 4 additions & 5 deletions scl-core/src/auth/microsoft/leagcy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub(super) struct XBoxPresenceRescord {
/// 获取 XUID,用途不明,但是在新版本的 Minecraft 有发现需要使用这个 XUID 的地方
pub async fn get_xuid(userhash: &str, token: &str) -> DynResult<String> {
let res = crate::http::get("https://userpresence.xboxlive.com/users/me?level=user")
.header("Authorization", format!("XBL3.0 x={};{}", userhash, token))
.header("Authorization", format!("XBL3.0 x={userhash};{token}"))
.header("x-xbl-contract-version", "3.2")
.header("Accept", "application/json")
.header("Accept-Language", "zh-CN")
Expand Down Expand Up @@ -132,7 +132,7 @@ pub async fn request_token(credit: &str, is_refresh: bool) -> DynResult<(String,
/// 传递给 [`get_mojang_access_token`] 进行下一步验证
pub async fn get_userhash_and_token(access_token: &str) -> DynResult<(String, String)> {
// println!("Getting xbox auth body");
let xbox_auth_body = format!("{{\"Properties\":{{\"AuthMethod\":\"RPS\",\"SiteName\":\"user.auth.xboxlive.com\",\"RpsTicket\":\"{}\"}},\"RelyingParty\":\"http://auth.xboxlive.com\",\"TokenType\":\"JWT\"}}", access_token);
let xbox_auth_body = format!("{{\"Properties\":{{\"AuthMethod\":\"RPS\",\"SiteName\":\"user.auth.xboxlive.com\",\"RpsTicket\":\"{access_token}\"}},\"RelyingParty\":\"http://auth.xboxlive.com\",\"TokenType\":\"JWT\"}}");
let xbox_auth_resp: XBoxAuthResponse =
crate::http::post("https://user.auth.xboxlive.com/user/authenticate")
.header("Content-Type", "application/json")
Expand All @@ -146,7 +146,7 @@ pub async fn get_userhash_and_token(access_token: &str) -> DynResult<(String, St
let token = xbox_auth_resp.token.to_owned();
if let Some(uhs) = xbox_auth_resp.display_claims.xui.first() {
let uhs = uhs.uhs.to_owned();
let xsts_body = format!("{{\"Properties\":{{\"SandboxId\":\"RETAIL\",\"UserTokens\":[\"{}\"]}},\"RelyingParty\":\"rp://api.minecraftservices.com/\",\"TokenType\":\"JWT\"}}", token);
let xsts_body = format!("{{\"Properties\":{{\"SandboxId\":\"RETAIL\",\"UserTokens\":[\"{token}\"]}},\"RelyingParty\":\"rp://api.minecraftservices.com/\",\"TokenType\":\"JWT\"}}");
println!("Getting xbox xsts token");
let xsts_resp: XBoxAuthResponse =
crate::http::post("https://xsts.auth.xboxlive.com/xsts/authorize")
Expand All @@ -171,8 +171,7 @@ pub async fn get_userhash_and_token(access_token: &str) -> DynResult<(String, St
pub async fn get_mojang_access_token(uhs: &str, xsts_token: &str) -> DynResult<String> {
if !uhs.is_empty() && !xsts_token.is_empty() {
// println!("Getting mojang access token");
let minecraft_xbox_body =
format!("{{\"identityToken\":\"XBL3.0 x={};{}\"}}", uhs, xsts_token);
let minecraft_xbox_body = format!("{{\"identityToken\":\"XBL3.0 x={uhs};{xsts_token}\"}}");
let minecraft_xbox_resp: MinecraftXBoxLoginResponse =
crate::http::post("https://api.minecraftservices.com/authentication/login_with_xbox")
.header("Content-Type", "application/json")
Expand Down
10 changes: 4 additions & 6 deletions scl-core/src/auth/microsoft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ impl<T: Display> MicrosoftOAuth<T> {
{\
\"AuthMethod\":\"RPS\",\
\"SiteName\":\"user.auth.xboxlive.com\",\
\"RpsTicket\":\"d={}\"\
\"RpsTicket\":\"d={access_token}\"\
}\
},\
\"RelyingParty\":\"http://auth.xboxlive.com\",\
\"TokenType\":\"JWT\"\
}\
}",
access_token
}"
);
let xbox_auth_resp: XBoxAuthResponse =
crate::http::post("https://user.auth.xboxlive.com/user/authenticate")
Expand All @@ -109,14 +108,13 @@ impl<T: Display> MicrosoftOAuth<T> {
\"Properties\":{\
{\
\"SandboxId\":\"RETAIL\",\
\"UserTokens\":[\"{}\"]\
\"UserTokens\":[\"{token}\"]\
}\
},\
\"RelyingParty\":\"rp://api.minecraftservices.com/\",\
\"TokenType\":\"JWT\"\
}\
}",
token
}"
);
println!("正在获取 XSTS");
let xsts_resp: XBoxAuthResponse =
Expand Down
5 changes: 1 addition & 4 deletions scl-core/src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ pub fn parse_head_skin(result: Vec<u8>) -> DynResult<(Vec<u8>, Vec<u8>)> {

async fn get_head_skin(uuid: &str) -> DynResult<(Vec<u8>, Vec<u8>)> {
// https://sessionserver.mojang.com/session/minecraft/profile/{uuid}
let uri = format!(
"https://sessionserver.mojang.com/session/minecraft/profile/{}",
uuid
);
let uri = format!("https://sessionserver.mojang.com/session/minecraft/profile/{uuid}");
let result: ProfileResponse = crate::http::get(uri)
.await
.map_err(|e| anyhow::anyhow!(e))?
Expand Down
10 changes: 3 additions & 7 deletions scl-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,9 @@ impl Client {
cfg.version_info.version_base,
sep = std::path::MAIN_SEPARATOR
));
args.push(format!("-javaagent:{authlib_injector_path}={api_location}"));
args.push(format!(
"-javaagent:{}={}",
authlib_injector_path, api_location
));
args.push(format!(
"-Dauthlibinjector.yggdrasil.prefetched={}",
server_meta
"-Dauthlibinjector.yggdrasil.prefetched={server_meta}"
));
}
if let Some(max_mem) = variables.get("${max_memory}") {
Expand Down Expand Up @@ -565,7 +561,7 @@ impl Client {

args.insert(0, java_path.to_owned());

println!("CMD: {:?}", cmd);
println!("CMD: {cmd:?}");

Ok(Self {
cmd,
Expand Down
2 changes: 1 addition & 1 deletion scl-core/src/download/authlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<R: Reporter> AuthlibDownloadExt for Downloader<R> {
let resp = crate::http::get(download_url)
.await
.map_err(|e| anyhow::anyhow!(e))?;
let temp_dest_path = format!("{}.tmp", dest_path);
let temp_dest_path = format!("{dest_path}.tmp");
let f = inner_future::fs::OpenOptions::new()
.write(true)
.truncate(true)
Expand Down
27 changes: 13 additions & 14 deletions scl-core/src/download/curseforge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,20 @@ pub async fn search_mods(
);
}
if !game_version.is_empty() {
let _ = write!(&mut base_url, "&gameVersion={}", game_version);
let _ = write!(&mut base_url, "&gameVersion={game_version}");
}
if index > 0 {
let _ = write!(&mut base_url, "&index={}", index);
let _ = write!(&mut base_url, "&index={index}");
}
if page_size > 0 && page_size <= 30 {
let _ = write!(&mut base_url, "&pageSize={}", page_size);
let _ = write!(&mut base_url, "&pageSize={page_size}");
} else {
let _ = write!(&mut base_url, "&pageSize={}", 20);
}
if category_id > 0 {
let _ = write!(&mut base_url, "&categoryID={}", category_id);
let _ = write!(&mut base_url, "&categoryID={category_id}");
}
println!("Searching by {}", base_url);
println!("Searching by {base_url}");
let data: Response<Vec<ModInfo>> = crate::http::get(&base_url)
.header("x-api-key", API_KEY.unwrap_or_default())
.await
Expand All @@ -211,7 +211,7 @@ pub async fn search_mods(

/// 通过模组在 Curseforge 的 ID 获取详情信息
pub async fn get_mod_info(modid: u64) -> DynResult<ModInfo> {
let data: Response<ModInfo> = crate::http::get(&(format!("{}mods/{}", BASE_URL, modid)))
let data: Response<ModInfo> = crate::http::get(&(format!("{BASE_URL}mods/{modid}")))
.header("x-api-key", API_KEY.unwrap_or_default())
.await
.map_err(|e| anyhow::anyhow!(e))?
Expand All @@ -223,14 +223,13 @@ pub async fn get_mod_info(modid: u64) -> DynResult<ModInfo> {

/// 获取模组在 Curseforge 的 ID 获取可下载的模组文件列表
pub async fn get_mod_files(modid: u64) -> DynResult<Vec<ModFile>> {
let data: Response<Vec<ModFile>> =
crate::http::get(&format!("{}mods/{}/files", BASE_URL, modid))
.header("x-api-key", API_KEY.unwrap_or_default())
.await
.map_err(|e| anyhow::anyhow!(e))?
.body_json()
.await
.map_err(|e| anyhow::anyhow!(e))?;
let data: Response<Vec<ModFile>> = crate::http::get(&format!("{BASE_URL}mods/{modid}/files"))
.header("x-api-key", API_KEY.unwrap_or_default())
.await
.map_err(|e| anyhow::anyhow!(e))?
.body_json()
.await
.map_err(|e| anyhow::anyhow!(e))?;
Ok(data.data)
}

Expand Down
25 changes: 9 additions & 16 deletions scl-core/src/download/fabric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,16 @@ pub trait FabricDownloadExt: Sync {
impl<R: Reporter> FabricDownloadExt for Downloader<R> {
async fn get_avaliable_loaders(&self, vanilla_version: &str) -> DynResult<Vec<LoaderMetaItem>> {
let mut result = crate::http::retry_get(match self.source {
DownloadSource::Default => format!(
"https://meta.fabricmc.net/v2/versions/loader/{}",
vanilla_version
),
DownloadSource::Default => {
format!("https://meta.fabricmc.net/v2/versions/loader/{vanilla_version}")
}
DownloadSource::BMCLAPI => format!(
"https://bmclapi2.bangbang93.com/fabric-meta/v2/versions/loader/{}",
vanilla_version
"https://bmclapi2.bangbang93.com/fabric-meta/v2/versions/loader/{vanilla_version}"
),
DownloadSource::MCBBS => format!(
"https://download.mcbbs.net/fabric-meta/v2/versions/loader/{}",
vanilla_version
),
_ => format!(
"https://meta.fabricmc.net/v2/versions/loader/{}",
vanilla_version
"https://download.mcbbs.net/fabric-meta/v2/versions/loader/{vanilla_version}"
),
_ => format!("https://meta.fabricmc.net/v2/versions/loader/{vanilla_version}"),
})
.await
.map_err(|e| {
Expand All @@ -103,15 +97,15 @@ impl<R: Reporter> FabricDownloadExt for Downloader<R> {
)
.await
.unwrap_or_default();
r.set_message(format!("正在下载 Fabric 支持库 {}", name));
r.set_message(format!("正在下载 Fabric 支持库 {name}"));
r.add_max_progress(1.);
if std::path::Path::new(&full_path).is_file() {
if self.verify_data {
let mut file = inner_future::fs::OpenOptions::new()
.read(true)
.open(&full_path)
.await?;
r.set_message(format!("正在获取数据摘要以验证完整性 {}", name));
r.set_message(format!("正在获取数据摘要以验证完整性 {name}"));
r.add_max_progress(1.);
let sha1 = crate::http::retry_get_string(format!(
"{}.sha1",
Expand Down Expand Up @@ -155,8 +149,7 @@ impl<R: Reporter> FabricDownloadExt for Downloader<R> {
loader_version: &str,
) -> DynResult {
let mut loader_meta_res = crate::http::retry_get(format!(
"https://meta.fabricmc.net/v2/versions/loader/{}/{}/profile/json",
version_id, loader_version
"https://meta.fabricmc.net/v2/versions/loader/{version_id}/{loader_version}/profile/json"
))
.await
.map_err(|e| anyhow::anyhow!("获取 Fabric 版本元数据失败:{:?}", e))?;
Expand Down
Loading

0 comments on commit 161e54b

Please sign in to comment.