please don't fill my hard drive

This commit is contained in:
Quaternions 2024-08-05 17:32:03 -07:00
parent f2e9f81fe4
commit 00ac7960e0

View File

@ -1,3 +1,5 @@
use std::io::Seek;
use binrw::{binrw,BinReaderExt,BinWriterExt};
use crate::newtypes::instruction::TimedPhysicsInstruction;
@ -28,10 +30,16 @@ impl BotDebug{
std::fs::remove_file(self.name)
}
pub fn push(&mut self,ins:strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>)->Result<(),binrw::Error>{
match TryInto::<TimedPhysicsInstruction>::try_into(ins){
let ret=match TryInto::<TimedPhysicsInstruction>::try_into(ins){
Ok(ins)=>self.file.write_le(&ins),
Err(crate::newtypes::physics::PhysicsInputInstructionError::DropInstruction)=>Ok(()),
};
//check if too much data has written to be reasonable
//avoid filling my hard drive on an infinite loop basically
if self.file.stream_position().is_ok_and(|pos|50*1024*1024<pos){
panic!();
}
ret
}
}