From 00ac7960e092230e77695fcbedb550867b7424d1 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 5 Aug 2024 17:32:03 -0700 Subject: [PATCH] please don't fill my hard drive --- src/bot.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bot.rs b/src/bot.rs index 45c58c1..b1b1355 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -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)->Result<(),binrw::Error>{ - match TryInto::::try_into(ins){ + let ret=match TryInto::::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