mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
better fallback for player entityid
This commit is contained in:
parent
6367b19473
commit
c3ea161928
3 changed files with 22 additions and 19 deletions
|
|
@ -68,6 +68,7 @@ pub struct UserInfo {
|
|||
|
||||
impl UserInfo {
|
||||
pub fn parse_from_string_table(
|
||||
index: u16,
|
||||
text: Option<&str>,
|
||||
data: Option<Stream>,
|
||||
) -> ReadResult<Option<Self>> {
|
||||
|
|
@ -77,7 +78,7 @@ impl UserInfo {
|
|||
|
||||
match text
|
||||
.map(|text| text.parse::<u32>().map(|id| (id + 1).into()))
|
||||
.unwrap_or_else(|| Ok((raw_info.user_id).into()))
|
||||
.unwrap_or_else(|| Ok((index as u32 + 1).into()))
|
||||
{
|
||||
Ok(entity_id) if !raw_info.steam_id.is_empty() => Ok(Some(UserInfo {
|
||||
player_info: raw_info.into(),
|
||||
|
|
|
|||
|
|
@ -395,12 +395,13 @@ impl MessageHandler for Analyser {
|
|||
fn handle_string_entry(
|
||||
&mut self,
|
||||
table: &str,
|
||||
_index: usize,
|
||||
index: usize,
|
||||
entry: &StringTableEntry,
|
||||
_parser_state: &ParserState,
|
||||
) {
|
||||
if table == "userinfo" {
|
||||
let _ = self.parse_user_info(
|
||||
index,
|
||||
entry.text.as_ref().map(|s| s.as_ref()),
|
||||
entry.extra_data.as_ref().map(|data| data.data.clone()),
|
||||
);
|
||||
|
|
@ -464,8 +465,8 @@ impl Analyser {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_user_info(&mut self, text: Option<&str>, data: Option<Stream>) -> ReadResult<()> {
|
||||
if let Some(user_info) = crate::demo::data::UserInfo::parse_from_string_table(text, data)? {
|
||||
fn parse_user_info(&mut self, index: usize, text: Option<&str>, data: Option<Stream>) -> ReadResult<()> {
|
||||
if let Some(user_info) = crate::demo::data::UserInfo::parse_from_string_table(index as u16, text, data)? {
|
||||
self.state
|
||||
.users
|
||||
.entry(user_info.player_info.user_id.into())
|
||||
|
|
|
|||
|
|
@ -193,12 +193,13 @@ impl MessageHandler for GameStateAnalyser {
|
|||
fn handle_string_entry(
|
||||
&mut self,
|
||||
table: &str,
|
||||
_index: usize,
|
||||
index: usize,
|
||||
entry: &StringTableEntry,
|
||||
_parser_state: &ParserState,
|
||||
) {
|
||||
if table == "userinfo" {
|
||||
let _ = self.parse_user_info(
|
||||
index,
|
||||
entry.text.as_ref().map(|s| s.as_ref()),
|
||||
entry.extra_data.as_ref().map(|data| data.data.clone()),
|
||||
);
|
||||
|
|
@ -345,8 +346,8 @@ impl GameStateAnalyser {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_user_info(&mut self, text: Option<&str>, data: Option<Stream>) -> ReadResult<()> {
|
||||
if let Some(user_info) = crate::demo::data::UserInfo::parse_from_string_table(text, data)? {
|
||||
fn parse_user_info(&mut self, index: usize, text: Option<&str>, data: Option<Stream>) -> ReadResult<()> {
|
||||
if let Some(user_info) = crate::demo::data::UserInfo::parse_from_string_table(index as u16, text, data)? {
|
||||
let id = user_info.entity_id;
|
||||
self.state.get_or_create_player(id).info = Some(user_info.into());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue