add .corrupt logic just like with the py version

This commit is contained in:
Mystikfluu 2023-05-31 19:01:10 +02:00
parent bd118b3164
commit 6a6b453953

View File

@ -225,8 +225,13 @@ fn main() {
for i in 0..packets.len() { for i in 0..packets.len() {
crc32.update(&packets[i]); crc32.update(&packets[i]);
if packet_hashes[i] != crc32.clone().finalize() { if packet_hashes[i] != crc32.clone().finalize() {
println!("Packet {} hash does not match", i); println!("Packet {} crc does not match, writing .corrupt", i);
todo!("Request packets again") //TODO: Request packets again
let mut file = std::fs::File::create("received/".to_string()+filename+".corrupt").expect("Failed to create file");
for i in 0..packets.len() {
file.write_all(&packets[i]).expect("Failed to write to file");
}
return;
} }
} }
@ -239,7 +244,12 @@ fn main() {
let client_hash = hasher.finalize(); let client_hash = hasher.finalize();
if client_hash[..64] != server_hash { if client_hash[..64] != server_hash {
panic!("Hashes do not match, correct hash: {:?}, client hash: {:?}", server_hash, client_hash); println!("Hashes do not match, correct hash: {:?}, client hash: {:?}", server_hash, client_hash);
let mut file = std::fs::File::create("received/".to_string()+filename+".corrupt").expect("Failed to create file");
for i in 0..packets.len() {
file.write_all(&packets[i]).expect("Failed to write to file");
}
return;
} }