mirror of
https://github.com/timvisee/lazymc.git
synced 2025-05-19 04:40:22 -07:00
Resolve clippy suggestions
This commit is contained in:
parent
e6e2e7fab8
commit
51ab0c610b
@ -15,16 +15,16 @@ pub fn invoke(matches: &ArgMatches) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Confirm to overwrite if it exists
|
// Confirm to overwrite if it exists
|
||||||
if path.is_file() {
|
if path.is_file()
|
||||||
if !prompt_yes(
|
&& !prompt_yes(
|
||||||
&format!(
|
&format!(
|
||||||
"Config file already exists, overwrite?\nPath: {}",
|
"Config file already exists, overwrite?\nPath: {}",
|
||||||
path.to_str().unwrap_or("?")
|
path.to_str().unwrap_or("?")
|
||||||
),
|
),
|
||||||
Some(true),
|
Some(true),
|
||||||
) {
|
)
|
||||||
quit();
|
{
|
||||||
}
|
quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate file
|
// Generate file
|
||||||
|
@ -53,17 +53,17 @@ fn init_log() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Invoke an action.
|
/// Invoke an action.
|
||||||
fn invoke_action<'a>(app: App<'a>) -> Result<(), ()> {
|
fn invoke_action(app: App) -> Result<(), ()> {
|
||||||
let matches = app.get_matches();
|
let matches = app.get_matches();
|
||||||
|
|
||||||
// Config operations
|
// Config operations
|
||||||
if let Some(ref matches) = matches.subcommand_matches("config") {
|
if let Some(matches) = matches.subcommand_matches("config") {
|
||||||
if let Some(ref matches) = matches.subcommand_matches("generate") {
|
if let Some(matches) = matches.subcommand_matches("generate") {
|
||||||
action::config_generate::invoke(matches);
|
action::config_generate::invoke(matches);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref matches) = matches.subcommand_matches("test") {
|
if let Some(matches) = matches.subcommand_matches("test") {
|
||||||
action::config_test::invoke(matches);
|
action::config_test::invoke(matches);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,6 @@ pub fn rewrite_file(file: &Path, changes: HashMap<&str, String>) {
|
|||||||
FILE,
|
FILE,
|
||||||
err,
|
err,
|
||||||
);
|
);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -110,7 +109,7 @@ fn rewrite_contents(contents: String, mut changes: HashMap<&str, String>) -> Opt
|
|||||||
|
|
||||||
// Skip comments or empty lines
|
// Skip comments or empty lines
|
||||||
let trim = line.trim();
|
let trim = line.trim();
|
||||||
if trim.starts_with("#") || trim.is_empty() {
|
if trim.starts_with('#') || trim.is_empty() {
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ pub async fn poll_server(
|
|||||||
async fn fetch_status(config: &Config, addr: SocketAddr) -> Result<ServerStatus, ()> {
|
async fn fetch_status(config: &Config, addr: SocketAddr) -> Result<ServerStatus, ()> {
|
||||||
let mut stream = TcpStream::connect(addr).await.map_err(|_| ())?;
|
let mut stream = TcpStream::connect(addr).await.map_err(|_| ())?;
|
||||||
|
|
||||||
send_handshake(&mut stream, &config, addr).await?;
|
send_handshake(&mut stream, config, addr).await?;
|
||||||
request_status(&mut stream).await?;
|
request_status(&mut stream).await?;
|
||||||
wait_for_status_timeout(&mut stream).await
|
wait_for_status_timeout(&mut stream).await
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ async fn fetch_status(config: &Config, addr: SocketAddr) -> Result<ServerStatus,
|
|||||||
async fn do_ping(config: &Config, addr: SocketAddr) -> Result<(), ()> {
|
async fn do_ping(config: &Config, addr: SocketAddr) -> Result<(), ()> {
|
||||||
let mut stream = TcpStream::connect(addr).await.map_err(|_| ())?;
|
let mut stream = TcpStream::connect(addr).await.map_err(|_| ())?;
|
||||||
|
|
||||||
send_handshake(&mut stream, &config, addr).await?;
|
send_handshake(&mut stream, config, addr).await?;
|
||||||
let token = send_ping(&mut stream).await?;
|
let token = send_ping(&mut stream).await?;
|
||||||
wait_for_ping_timeout(&mut stream, token).await
|
wait_for_ping_timeout(&mut stream, token).await
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ impl RawPacket {
|
|||||||
let mut packet = types::encode_var_int(len)?;
|
let mut packet = types::encode_var_int(len)?;
|
||||||
packet.append(&mut data);
|
packet.append(&mut data);
|
||||||
|
|
||||||
return Ok(packet);
|
Ok(packet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,9 +142,9 @@ impl RawPacket {
|
|||||||
/// Note: this does not support reading compressed/encrypted packets.
|
/// Note: this does not support reading compressed/encrypted packets.
|
||||||
/// We should never need this though, as we're done reading user packets before any of this is
|
/// We should never need this though, as we're done reading user packets before any of this is
|
||||||
/// enabled. See: https://wiki.vg/Protocol#Packet_format
|
/// enabled. See: https://wiki.vg/Protocol#Packet_format
|
||||||
pub async fn read_packet<'a>(
|
pub async fn read_packet(
|
||||||
buf: &mut BytesMut,
|
buf: &mut BytesMut,
|
||||||
stream: &mut ReadHalf<'a>,
|
stream: &mut ReadHalf<'_>,
|
||||||
) -> Result<Option<(RawPacket, Vec<u8>)>, ()> {
|
) -> Result<Option<(RawPacket, Vec<u8>)>, ()> {
|
||||||
// Keep reading until we have at least 2 bytes
|
// Keep reading until we have at least 2 bytes
|
||||||
while buf.len() < 2 {
|
while buf.len() < 2 {
|
||||||
@ -166,7 +166,7 @@ pub async fn read_packet<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to read packet length
|
// Attempt to read packet length
|
||||||
let (consumed, len) = match types::read_var_int(&buf) {
|
let (consumed, len) = match types::read_var_int(buf) {
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(target: "lazymc", "Malformed packet, could not read packet length");
|
error!(target: "lazymc", "Malformed packet, could not read packet length");
|
||||||
|
@ -29,7 +29,7 @@ pub async fn proxy_with_queue(
|
|||||||
if !queue.is_empty() {
|
if !queue.is_empty() {
|
||||||
wo.writable().await?;
|
wo.writable().await?;
|
||||||
trace!(target: "lazymc", "Relaying {} queued bytes to server", queue.len());
|
trace!(target: "lazymc", "Relaying {} queued bytes to server", queue.len());
|
||||||
wo.write_all(&queue).await?;
|
wo.write_all(queue).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let client_to_server = async {
|
let client_to_server = async {
|
||||||
|
@ -210,13 +210,13 @@ impl Server {
|
|||||||
|
|
||||||
// Try to stop through RCON if started
|
// Try to stop through RCON if started
|
||||||
#[cfg(feature = "rcon")]
|
#[cfg(feature = "rcon")]
|
||||||
if self.state() == State::Started && stop_server_rcon(config, &self).await {
|
if self.state() == State::Started && stop_server_rcon(config, self).await {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to stop through signal
|
// Try to stop through signal
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
if stop_server_signal(config, &self) {
|
if stop_server_signal(config, self) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ async fn stop_server_rcon(config: &Config, server: &Server) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RCON address
|
// RCON address
|
||||||
let mut addr = config.server.address.clone();
|
let mut addr = config.server.address;
|
||||||
addr.set_port(config.rcon.port);
|
addr.set_port(config.rcon.port);
|
||||||
let addr = addr.to_string();
|
let addr = addr.to_string();
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ fn route(inbound: TcpStream, config: Arc<Config>, server: Arc<Server>) {
|
|||||||
fn route_status(inbound: TcpStream, config: Arc<Config>, server: Arc<Server>) {
|
fn route_status(inbound: TcpStream, config: Arc<Config>, server: Arc<Server>) {
|
||||||
// When server is not online, spawn a status server
|
// When server is not online, spawn a status server
|
||||||
let client = Client::default();
|
let client = Client::default();
|
||||||
let service = status::serve(client, inbound, config.clone(), server.clone()).map(|r| {
|
let service = status::serve(client, inbound, config, server).map(|r| {
|
||||||
if let Err(err) = r {
|
if let Err(err) = r {
|
||||||
warn!(target: "lazymc", "Failed to serve status: {:?}", err);
|
warn!(target: "lazymc", "Failed to serve status: {:?}", err);
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ fn route_proxy(inbound: TcpStream, config: Arc<Config>) {
|
|||||||
|
|
||||||
/// Route inbound TCP stream to proxy with queued data, spawning a new task.
|
/// Route inbound TCP stream to proxy with queued data, spawning a new task.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn route_proxy_queue<'a>(inbound: TcpStream, config: Arc<Config>, queue: BytesMut) {
|
pub fn route_proxy_queue(inbound: TcpStream, config: Arc<Config>, queue: BytesMut) {
|
||||||
// When server is online, proxy all
|
// When server is online, proxy all
|
||||||
let service = async move {
|
let service = async move {
|
||||||
proxy::proxy_with_queue(inbound, config.server.address, &queue)
|
proxy::proxy_with_queue(inbound, config.server.address, &queue)
|
||||||
|
@ -217,7 +217,7 @@ pub async fn hold<'a>(
|
|||||||
/// Kick client with a message.
|
/// Kick client with a message.
|
||||||
///
|
///
|
||||||
/// Should close connection afterwards.
|
/// Should close connection afterwards.
|
||||||
async fn kick<'a>(msg: &str, writer: &mut WriteHalf<'a>) -> Result<(), ()> {
|
async fn kick(msg: &str, writer: &mut WriteHalf<'_>) -> Result<(), ()> {
|
||||||
let packet = LoginDisconnect {
|
let packet = LoginDisconnect {
|
||||||
reason: Message::new(Payload::text(msg)),
|
reason: Message::new(Payload::text(msg)),
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,7 @@ pub fn read_var_int(buf: &[u8]) -> Result<(usize, i32), ()> {
|
|||||||
let buf = &buf[..len];
|
let buf = &buf[..len];
|
||||||
|
|
||||||
// Parse var-int, return result
|
// Parse var-int, return result
|
||||||
return match minecraft_protocol::decoder::var_int::decode(&mut buf.as_ref()) {
|
return match minecraft_protocol::decoder::var_int::decode(&mut &*buf) {
|
||||||
Ok(val) => Ok((len, val)),
|
Ok(val) => Ok((len, val)),
|
||||||
Err(_) => Err(()),
|
Err(_) => Err(()),
|
||||||
};
|
};
|
||||||
|
@ -52,8 +52,10 @@ pub fn prompt_yes(msg: &str, def: Option<bool>) -> bool {
|
|||||||
let answer = prompt(&format!("{} {}", msg, options));
|
let answer = prompt(&format!("{} {}", msg, options));
|
||||||
|
|
||||||
// Assume the default if the answer is empty
|
// Assume the default if the answer is empty
|
||||||
if answer.is_empty() && def.is_some() {
|
if answer.is_empty() {
|
||||||
return def.unwrap();
|
if let Some(def) = def {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Derive a boolean and return
|
// Derive a boolean and return
|
||||||
|
@ -30,11 +30,7 @@ pub fn print_error(err: anyhow::Error) {
|
|||||||
|
|
||||||
// Fall back to a basic message
|
// Fall back to a basic message
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
eprintln!(
|
eprintln!("{} an undefined error occurred", highlight_error("error:"),);
|
||||||
"{} {}",
|
|
||||||
highlight_error("error:"),
|
|
||||||
"an undefined error occurred"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +119,7 @@ impl ErrorHints {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
eprint!("\n");
|
eprintln!();
|
||||||
|
|
||||||
// Print hints
|
// Print hints
|
||||||
let bin = crate::util::bin_name();
|
let bin = crate::util::bin_name();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user