From 3181706ef3a6a1df2c230431a3c39d5d78d45426 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sun, 5 Feb 2023 07:49:18 +0100 Subject: [PATCH] format --- src/client.rs | 8 ++++---- src/server.rs | 5 ++--- src/socket_adapter.rs | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/client.rs b/src/client.rs index b37f7ca..d5ee3bd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,10 +1,11 @@ use std::{ + collections::HashMap, io::Read, io::Write, net::{Shutdown, TcpStream}, thread, time::{Duration, SystemTime}, - vec, collections::HashMap, + vec, }; use crate::{io_sync, PacketType, SocketAdapter}; @@ -17,15 +18,14 @@ pub fn client(ip: &str, port: u16, dest_ip: &str, dest_port: u16, key: &str, sle let mut buf = [0; 1024]; let mut tcp = TcpStream::connect((ip, port)).unwrap(); println!("Syncing..."); - tcp.write_all(&['R' as u8, 'P' as u8, 'F' as u8, 30]) - .unwrap(); + tcp.write_all(&[b'R', b'P', b'F', 30]).unwrap(); println!("Authenticating..."); tcp.write_all(&(key.len() as u32).to_be_bytes()).unwrap(); tcp.write_all(key.as_bytes()).unwrap(); println!("Syncing..."); tcp.read_exact(&mut buf4).unwrap(); - if buf4 != ['R' as u8, 'P' as u8, 'F' as u8, 30] { + if buf4 != [b'R', b'P', b'F', 30] { panic!("RPF30 header expected, but not found. Make sure the server is actually running revpfw3!"); } tcp.write_all(&[PacketType::KeepAlive.ordinal() as u8]) diff --git a/src/server.rs b/src/server.rs index 7ad7a53..c35bc09 100644 --- a/src/server.rs +++ b/src/server.rs @@ -23,7 +23,7 @@ pub fn server(port: u16, key: &str, sleep_delay_ms: u64) { tcp.0.shutdown(Shutdown::Both).unwrap(); continue; }; - if buf4 == ['R' as u8, 'P' as u8, 'F' as u8, 30] { + if buf4 == [b'R', b'P', b'F', 30] { println!("Compatible client connected."); if tcp.0.read_exact(&mut buf4).is_ok() && u32::from_be_bytes(buf4) == key.len() as u32 { println!("Key length matches."); @@ -38,8 +38,7 @@ pub fn server(port: u16, key: &str, sleep_delay_ms: u64) { } }; - tcp.write_all(&mut ['R' as u8, 'P' as u8, 'F' as u8, 30]) - .unwrap(); + tcp.write_all(&[b'R', b'P', b'F', 30]).unwrap(); tcpl.set_nonblocking(true).unwrap(); diff --git a/src/socket_adapter.rs b/src/socket_adapter.rs index 6f2ae5e..af66502 100644 --- a/src/socket_adapter.rs +++ b/src/socket_adapter.rs @@ -2,7 +2,7 @@ use std::{ io::{Error, Read}, io::{ErrorKind, Write}, net::TcpStream, - time::{SystemTime, Duration}, + time::SystemTime, }; use crate::io_sync; @@ -133,7 +133,7 @@ impl SocketAdapter { } pub fn punish(&mut self, time: u128) { - if self.ignore_until == None { + if self.ignore_until.is_none() { self.ignore_until = Some(SystemTime::UNIX_EPOCH.elapsed().unwrap().as_micros()); } self.ignore_until = self.ignore_until.map(|x| x + time);