This commit is contained in:
Daniella / Tove 2023-02-05 07:49:18 +01:00
parent 58bb1d58c6
commit 3181706ef3
3 changed files with 8 additions and 9 deletions

View file

@ -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])

View file

@ -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();

View file

@ -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);