mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
userinfo encode
This commit is contained in:
parent
875dc7120c
commit
d3cbe134bc
1 changed files with 29 additions and 1 deletions
|
|
@ -1,12 +1,18 @@
|
|||
use crate::demo::message::packetentities::EntityId;
|
||||
use crate::demo::packet::stringtable::{ExtraData, StringTableEntry};
|
||||
use crate::demo::parser::gamestateanalyser::UserId;
|
||||
use crate::{ReadResult, Stream};
|
||||
use bitbuffer::{
|
||||
BitReadBuffer, BitReadStream, BitWrite, BitWriteSized, BitWriteStream, LittleEndian,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UserInfo {
|
||||
pub steam_id: String,
|
||||
pub user_id: UserId,
|
||||
pub entity_id: EntityId,
|
||||
pub name: String,
|
||||
pub rest_data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl UserInfo {
|
||||
|
|
@ -19,7 +25,9 @@ impl UserInfo {
|
|||
.read_sized(32)
|
||||
.unwrap_or_else(|_| "Malformed Name".into());
|
||||
let user_id: UserId = data.read::<u32>()?.into();
|
||||
let steam_id: String = data.read()?;
|
||||
let steam_id: String = data.read_sized(32)?;
|
||||
|
||||
let rest_data = data.read_sized(data.bits_left() / 8)?;
|
||||
|
||||
match text
|
||||
.map(|text| text.parse::<u32>().map(|id| (id + 1).into()))
|
||||
|
|
@ -30,6 +38,7 @@ impl UserInfo {
|
|||
user_id,
|
||||
entity_id,
|
||||
name,
|
||||
rest_data,
|
||||
})),
|
||||
_ => Ok(None),
|
||||
}
|
||||
|
|
@ -37,4 +46,23 @@ impl UserInfo {
|
|||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn encode_to_string_table(&self) -> ReadResult<StringTableEntry<'static>> {
|
||||
let text = format!("{}", self.entity_id);
|
||||
let mut extra_data = Vec::with_capacity(128);
|
||||
{
|
||||
let mut stream = BitWriteStream::new(&mut extra_data, LittleEndian);
|
||||
self.name.write_sized(&mut stream, 32)?;
|
||||
(self.user_id.0 as u32).write(&mut stream)?;
|
||||
self.steam_id.write_sized(&mut stream, 32)?;
|
||||
self.rest_data.write(&mut stream)?;
|
||||
}
|
||||
|
||||
Ok(StringTableEntry {
|
||||
text: Some(text.into()),
|
||||
extra_data: Some(ExtraData::new(BitReadStream::new(
|
||||
BitReadBuffer::new_owned(extra_data, LittleEndian),
|
||||
))),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue