mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
add cli option to parse all messages for easier debugging
This commit is contained in:
parent
baad66bc0c
commit
e6e32b292b
5 changed files with 57 additions and 16 deletions
|
|
@ -204,14 +204,13 @@ impl MessageHandler for Analyser {
|
|||
|
||||
fn handle_string_entry(&mut self, table: &String, _index: usize, entry: &StringTableEntry) {
|
||||
match table.as_str() {
|
||||
"userinfo" => match (&entry.text, &entry.extra_data) {
|
||||
(Some(text), Some(data)) => {
|
||||
"userinfo" => {
|
||||
if let (Some(text), Some(data)) = (&entry.text, &entry.extra_data) {
|
||||
if data.byte_len > 32 {
|
||||
let _ = self.parse_user_info(text, data.data.clone());
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,17 @@ impl DemoHandler<Analyser> {
|
|||
|
||||
impl<T: MessageHandler> DemoHandler<T> {
|
||||
pub fn with_analyser(analyser: T) -> Self {
|
||||
let state_handler = ParserState::new(T::does_handle);
|
||||
let state_handler = ParserState::new(T::does_handle, false);
|
||||
|
||||
DemoHandler {
|
||||
tick: 0,
|
||||
string_table_names: Vec::new(),
|
||||
analyser,
|
||||
state_handler,
|
||||
}
|
||||
}
|
||||
pub fn parse_all_with_analyser(analyser: T) -> Self {
|
||||
let state_handler = ParserState::new(T::does_handle, true);
|
||||
|
||||
DemoHandler {
|
||||
tick: 0,
|
||||
|
|
|
|||
|
|
@ -183,11 +183,34 @@ impl DemoParser {
|
|||
Self::parse_with_analyser(stream, Analyser::new())
|
||||
}
|
||||
|
||||
pub fn parse_all(stream: Stream) -> Result<(Header, MatchState)> {
|
||||
Self::parse_all_with_analyser(stream, Analyser::new())
|
||||
}
|
||||
|
||||
pub fn parse_with_analyser<T: MessageHandler>(
|
||||
mut stream: Stream,
|
||||
stream: Stream,
|
||||
analyser: T,
|
||||
) -> Result<(Header, T::Output)> {
|
||||
let mut handler = DemoHandler::with_analyser(analyser);
|
||||
Self::parse(stream, analyser, false)
|
||||
}
|
||||
|
||||
pub fn parse_all_with_analyser<T: MessageHandler>(
|
||||
stream: Stream,
|
||||
analyser: T,
|
||||
) -> Result<(Header, T::Output)> {
|
||||
Self::parse(stream, analyser, true)
|
||||
}
|
||||
|
||||
fn parse<T: MessageHandler>(
|
||||
mut stream: Stream,
|
||||
analyser: T,
|
||||
all: bool,
|
||||
) -> Result<(Header, T::Output)> {
|
||||
let mut handler = if all {
|
||||
DemoHandler::parse_all_with_analyser(analyser)
|
||||
} else {
|
||||
DemoHandler::with_analyser(analyser)
|
||||
};
|
||||
let header = Header::read(&mut stream)?;
|
||||
loop {
|
||||
let packet = Packet::parse(&mut stream, handler.get_parser_state())?;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ pub struct ParserState {
|
|||
pub demo_meta: DemoMeta,
|
||||
analyser_handles: fn(message_type: MessageType) -> bool,
|
||||
handle_entities: bool,
|
||||
parse_all: bool,
|
||||
}
|
||||
|
||||
pub struct StaticBaseline {
|
||||
|
|
@ -56,7 +57,7 @@ impl StaticBaseline {
|
|||
}
|
||||
|
||||
impl ParserState {
|
||||
pub fn new(analyser_handles: fn(message_type: MessageType) -> bool) -> Self {
|
||||
pub fn new(analyser_handles: fn(message_type: MessageType) -> bool, parse_all: bool) -> Self {
|
||||
ParserState {
|
||||
static_baselines: HashMap::with_hasher(NullHasherBuilder),
|
||||
parsed_static_baselines: RefCell::new(HashMap::with_hasher(NullHasherBuilder)),
|
||||
|
|
@ -71,7 +72,8 @@ impl ParserState {
|
|||
],
|
||||
demo_meta: DemoMeta::default(),
|
||||
analyser_handles,
|
||||
handle_entities: analyser_handles(MessageType::PacketEntities),
|
||||
handle_entities: analyser_handles(MessageType::PacketEntities) || parse_all,
|
||||
parse_all,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -137,11 +139,12 @@ impl ParserState {
|
|||
}
|
||||
|
||||
pub fn should_parse_message(&self, message_type: MessageType) -> bool {
|
||||
if message_type == MessageType::PacketEntities {
|
||||
(self.analyser_handles)(message_type)
|
||||
} else {
|
||||
Self::does_handle(message_type) || (self.analyser_handles)(message_type)
|
||||
}
|
||||
self.parse_all
|
||||
|| if message_type == MessageType::PacketEntities {
|
||||
self.handle_entities
|
||||
} else {
|
||||
Self::does_handle(message_type) || (self.analyser_handles)(message_type)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn does_handle(message_type: MessageType) -> bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue