Skip to content

Commit

Permalink
Also cleanup inline format args where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
zrax committed Jul 30, 2024
1 parent 3078f4c commit 28e0c13
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 39 deletions.
1 change: 0 additions & 1 deletion src/bin/mfs_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(clippy::uninlined_format_args)] // Added in Rust 1.66

use std::fs::File;
use std::io::{Cursor, BufReader, BufWriter};
Expand Down
19 changes: 9 additions & 10 deletions src/bin/moulars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(clippy::uninlined_format_args)] // Added in Rust 1.66

use std::ffi::OsStr;
use std::io::{self, Write};
Expand Down Expand Up @@ -84,8 +83,8 @@ fn main() -> ExitCode {
let key_x = key_g.to_biguint().unwrap().modpow(key_k, key_n);
let bytes_n = key_n.to_bytes_be();
let bytes_x = key_x.to_bytes_be();
println!("Server.{}.N \"{}\"", stype, BASE64_STANDARD.encode(bytes_n));
println!("Server.{}.X \"{}\"", stype, BASE64_STANDARD.encode(bytes_x));
println!("Server.{stype}.N \"{}\"", BASE64_STANDARD.encode(bytes_n));
println!("Server.{stype}.X \"{}\"", BASE64_STANDARD.encode(bytes_x));
}

return ExitCode::SUCCESS;
Expand Down Expand Up @@ -117,7 +116,7 @@ fn load_config() -> Result<ServerConfig, ExitCode> {
let exe_path = match std::env::current_exe() {
Ok(path) => path.parent().unwrap().to_owned(),
Err(err) => {
error!("Failed to get executable path: {}", err);
error!("Failed to get executable path: {err}");
return Err(ExitCode::FAILURE);
}
};
Expand Down Expand Up @@ -196,10 +195,10 @@ fn generate_keys() {

let stype_lower = stype.to_ascii_lowercase();
return (
format!("{}.n = \"{}\"", stype_lower, BASE64_STANDARD.encode(&bytes_n)),
format!("{}.k = \"{}\"", stype_lower, BASE64_STANDARD.encode(&bytes_k)),
format!("Server.{}.N \"{}\"", stype, BASE64_STANDARD.encode(&bytes_n)),
format!("Server.{}.X \"{}\"", stype, BASE64_STANDARD.encode(&bytes_x)),
format!("{stype_lower}.n = \"{}\"", BASE64_STANDARD.encode(&bytes_n)),
format!("{stype_lower}.k = \"{}\"", BASE64_STANDARD.encode(&bytes_k)),
format!("Server.{stype}.N \"{}\"", BASE64_STANDARD.encode(&bytes_n)),
format!("Server.{stype}.X \"{}\"", BASE64_STANDARD.encode(&bytes_x)),
);
}
}));
Expand All @@ -216,12 +215,12 @@ fn generate_keys() {
println!("----------------------------");
println!("[crypt_keys]");
for line in server_lines {
println!("{}", line);
println!("{line}");
}
println!("\n----------------------------");
println!("Client keys: (server.ini)");
println!("----------------------------");
for line in client_lines {
println!("{}", line);
println!("{line}");
}
}
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ pub struct ServerConfig {

fn decode_crypt_key(value: &str) -> Result<BigUint> {
let bytes = BASE64_STANDARD.decode(value)
.with_context(|| format!("Could not parse Base64 key '{}'", value))?;
.with_context(|| format!("Could not parse Base64 key '{value}'"))?;
if bytes.len() == 64 {
Ok(BigUint::from_bytes_be(&bytes))
} else {
Err(anyhow!("Invalid key length for key '{}'", value))
Err(anyhow!("Invalid key length for key '{value}'"))
}
}

Expand Down
23 changes: 10 additions & 13 deletions src/file_srv/data_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ pub fn cache_clients(data_root: &Path, python_exe: Option<&Path>) -> Result<()>
if src_dir.exists() && src_dir.is_dir() {
scan_dir(&src_dir, &mut game_data_files)?;
} else {
warn!("{} does not exist. Skipping {} files for manifests.",
src_dir.display(), data_dir);
warn!("{} does not exist. Skipping {data_dir} files for manifests.",
src_dir.display());
}
}

Expand All @@ -97,7 +97,7 @@ pub fn cache_clients(data_root: &Path, python_exe: Option<&Path>) -> Result<()>
let python_pak = python_dir.join("Python.pak");
if let Some(python_exe) = python_exe {
if let Err(err) = process_python(&python_dir, python_exe, &python_pak, &ntd_key) {
warn!("Failed to build Python.pak: {}", err);
warn!("Failed to build Python.pak: {err}");
}
} else {
warn!("No Python compiler specified. Skipping Python files.");
Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn cache_clients(data_root: &Path, python_exe: Option<&Path>) -> Result<()>
let mut has_relevance = false;
for page in age_info.pages() {
let page_path = data_root.join("dat")
.join(format!("{}_District_{}.prp", age_name, page.name()));
.join(format!("{age_name}_District_{}.prp", page.name()));
if page_path.exists() {
expected_files.insert(page_path.clone());

Expand Down Expand Up @@ -176,7 +176,7 @@ pub fn cache_clients(data_root: &Path, python_exe: Option<&Path>) -> Result<()>
expected_files.insert(csv_path);
}

let age_mfs_path = data_root.join(format!("{}.mfs_cache", age_name));
let age_mfs_path = data_root.join(format!("{age_name}.mfs_cache"));
let mut age_mfs = load_or_create_manifest(&age_mfs_path)?;
for file in age_mfs.files_mut() {
*file = update_cache_file(&mut data_cache, file, data_root).clone();
Expand Down Expand Up @@ -215,21 +215,18 @@ pub fn cache_clients(data_root: &Path, python_exe: Option<&Path>) -> Result<()>
for (build, suffix, client_data_dir) in client_types {
let src_dir = data_root.join(client_data_dir);
if !src_dir.exists() || !src_dir.is_dir() {
warn!("{} does not exist. Skipping manifest for {}{}",
client_data_dir.display(), build, suffix);
warn!("{} does not exist. Skipping manifest for {build}{suffix}",
client_data_dir.display());
continue;
}

// Fetch runtime files specific to this client configuration.
let mut client_files = game_data_files.clone();
scan_dir(&src_dir, &mut client_files)?;

let patcher_mfs_path = data_root.join(
format!("{}Patcher{}.mfs_cache", build, suffix));
let thin_mfs_path = data_root.join(
format!("Thin{}{}.mfs_cache", build, suffix));
let full_mfs_path = data_root.join(
format!("{}{}.mfs_cache", build, suffix));
let patcher_mfs_path = data_root.join(format!("{build}Patcher{suffix}.mfs_cache"));
let thin_mfs_path = data_root.join(format!("Thin{build}{suffix}.mfs_cache"));
let full_mfs_path = data_root.join(format!("{build}{suffix}.mfs_cache"));

let mut patcher_mfs = load_or_create_manifest(&patcher_mfs_path)?;
let mut thin_mfs = load_or_create_manifest(&thin_mfs_path)?;
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(clippy::uninlined_format_args)] // Added in Rust 1.66

// TODO: Clean up some or all of these exceptions
#![allow(clippy::if_not_else)]
Expand Down
4 changes: 2 additions & 2 deletions src/lobby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn connection_type_name(conn_type: u8) -> String {
CONN_CLI_TO_FILE => "Cli2File".to_string(),
CONN_CLI_TO_CSR => "Cli2Csr".to_string(),
CONN_CLI_TO_GATE_KEEPER => "Cli2GateKeeper".to_string(),
_ => format!("Unknown ({})", conn_type)
_ => format!("Unknown ({conn_type})")
}
}

Expand All @@ -107,7 +107,7 @@ impl LobbyServer {
tokio::spawn(async move {
match tokio::signal::ctrl_c().await {
Ok(()) => (),
Err(err) => panic!("Failed to wait for Ctrl+C signal: {}", err),
Err(err) => panic!("Failed to wait for Ctrl+C signal: {err}"),
}
info!("Shutdown initiated by Ctrl+C");
let _ = ctrl_c_send.send(());
Expand Down
2 changes: 1 addition & 1 deletion src/plasma/unified_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl UnifiedTime {
Ok(Self {
// Warning: This will fail in Feb 2106
secs: u32::try_from(now.as_secs())
.with_context(|| format!("Can't encode timestamp {:?}", now))?,
.with_context(|| format!("Can't encode timestamp {now:?}"))?,
micros: now.subsec_micros()
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/sdl/state_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl Variable {
}
VarValues::StateDesc(states)
} else {
panic!("Unknown state descriptor '{}'", name);
panic!("Unknown state descriptor '{name}'");
}
}
};
Expand Down
13 changes: 5 additions & 8 deletions src/vault/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,13 @@ impl VaultServer {
-> NetResult<T>
{
if let Err(err) = self.msg_send.send(msg).await {
panic!("Failed to send message to vault: {}", err);
panic!("Failed to send message to vault: {err}");
}

match recv.await {
Ok(response) => response,
Err(err) => {
warn!("Failed to recieve response from Vault: {}", err);
Err(NetResultCode::NetInternalError)
}
}
recv.await.unwrap_or_else(|err| {
warn!("Failed to recieve response from Vault: {err}");
Err(NetResultCode::NetInternalError)
})
}

pub async fn get_account(&self, account_name: &str) -> NetResult<Option<AccountInfo>> {
Expand Down

0 comments on commit 28e0c13

Please sign in to comment.