mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
fix parsing demos that only set their user info in stringtable updates
This commit is contained in:
parent
a47336f709
commit
fd96ffaf47
4 changed files with 36 additions and 25 deletions
BIN
data/nousers.dem
Normal file
BIN
data/nousers.dem
Normal file
Binary file not shown.
1
data/nousers.json
Normal file
1
data/nousers.json
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -250,6 +250,7 @@ pub struct World {
|
||||||
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
|
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
|
||||||
pub struct Analyser {
|
pub struct Analyser {
|
||||||
state: MatchState,
|
state: MatchState,
|
||||||
|
user_id_map: HashMap<EntityId, UserId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageHandler for Analyser {
|
impl MessageHandler for Analyser {
|
||||||
|
|
@ -279,11 +280,10 @@ impl MessageHandler for Analyser {
|
||||||
fn handle_string_entry(&mut self, table: &str, _index: usize, entry: &StringTableEntry) {
|
fn handle_string_entry(&mut self, table: &str, _index: usize, entry: &StringTableEntry) {
|
||||||
match table {
|
match table {
|
||||||
"userinfo" => {
|
"userinfo" => {
|
||||||
if let (Some(text), Some(data)) = (&entry.text, &entry.extra_data) {
|
let _ = self.parse_user_info(
|
||||||
if data.byte_len > 32 {
|
entry.text.as_ref().map(|s| s.as_str()),
|
||||||
let _ = self.parse_user_info(text, data.data.clone());
|
entry.extra_data.as_ref().map(|data| data.data.clone()),
|
||||||
}
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
@ -346,28 +346,33 @@ impl Analyser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_user_info(&mut self, text: &str, mut data: Stream) -> ReadResult<()> {
|
fn parse_user_info(&mut self, text: Option<&str>, data: Option<Stream>) -> ReadResult<()> {
|
||||||
let name: String = data
|
if let Some(mut data) = data {
|
||||||
.read_sized(32)
|
let name: String = data
|
||||||
.unwrap_or_else(|_| "Malformed Name".into());
|
.read_sized(32)
|
||||||
let user_id = data.read::<u32>()?.into();
|
.unwrap_or_else(|_| "Malformed Name".into());
|
||||||
let steam_id: String = data.read()?;
|
let user_id: UserId = data.read::<u32>()?.into();
|
||||||
|
let steam_id: String = data.read()?;
|
||||||
|
|
||||||
match text.parse() {
|
match text
|
||||||
Ok(entity_id) if !steam_id.is_empty() => {
|
.map(|text| text.parse())
|
||||||
self.state.users.insert(
|
.unwrap_or_else(|| Ok((user_id.0 as u32).into()))
|
||||||
user_id,
|
{
|
||||||
UserInfo {
|
Ok(entity_id) if !steam_id.is_empty() => {
|
||||||
classes: ClassList::default(),
|
self.state.users.insert(
|
||||||
team: Team::Other,
|
|
||||||
steam_id,
|
|
||||||
user_id,
|
user_id,
|
||||||
name,
|
UserInfo {
|
||||||
entity_id,
|
classes: ClassList::default(),
|
||||||
},
|
team: Team::Other,
|
||||||
);
|
steam_id,
|
||||||
|
user_id,
|
||||||
|
name,
|
||||||
|
entity_id,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,11 @@ fn snapshot_test_malformed_cvar() {
|
||||||
snapshot_test("data/malformed_cvar.dem", "data/malformed_cvar.json");
|
snapshot_test("data/malformed_cvar.dem", "data/malformed_cvar.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn snapshot_test_player_in_update() {
|
||||||
|
snapshot_test("data/nousers.dem", "data/nousers.json");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn snapshot_test_decal() {
|
fn snapshot_test_decal() {
|
||||||
snapshot_test("data/decal.dem", "data/decal.json");
|
snapshot_test("data/decal.dem", "data/decal.json");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue