please don't fill my hard drive
This commit is contained in:
parent
f2e9f81fe4
commit
00ac7960e0
10
src/bot.rs
10
src/bot.rs
@ -1,3 +1,5 @@
|
|||||||
|
use std::io::Seek;
|
||||||
|
|
||||||
use binrw::{binrw,BinReaderExt,BinWriterExt};
|
use binrw::{binrw,BinReaderExt,BinWriterExt};
|
||||||
use crate::newtypes::instruction::TimedPhysicsInstruction;
|
use crate::newtypes::instruction::TimedPhysicsInstruction;
|
||||||
|
|
||||||
@ -28,10 +30,16 @@ impl BotDebug{
|
|||||||
std::fs::remove_file(self.name)
|
std::fs::remove_file(self.name)
|
||||||
}
|
}
|
||||||
pub fn push(&mut self,ins:strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>)->Result<(),binrw::Error>{
|
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),
|
Ok(ins)=>self.file.write_le(&ins),
|
||||||
Err(crate::newtypes::physics::PhysicsInputInstructionError::DropInstruction)=>Ok(()),
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user