mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
clippy fixes
This commit is contained in:
parent
44c560713a
commit
a561cbaf64
12 changed files with 345 additions and 398 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -90,9 +90,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "bitbuffer_derive"
|
||||
version = "0.10.0"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4090254bfbc71442ff4a426ddba663346e26fd14b55b259281f763e350d7f621"
|
||||
checksum = "052a5a614540ae9bb7de25c2c86a94b6de7374cb7e3230f3128955bdaea62c3f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ use std::env;
|
|||
use std::fs;
|
||||
|
||||
use main_error::MainError;
|
||||
pub use tf_demo_parser::{Demo, DemoParser, Parse, ParseError, ParserState, Stream};
|
||||
use tf_demo_parser::demo::parser::player_summary_analyzer::PlayerSummaryAnalyzer;
|
||||
|
||||
pub use tf_demo_parser::{Demo, DemoParser, Parse, ParseError, ParserState, Stream};
|
||||
|
||||
#[cfg(feature = "jemallocator")]
|
||||
#[global_allocator]
|
||||
|
|
@ -50,9 +49,7 @@ fn main() -> Result<(), MainError> {
|
|||
|
||||
for (user_id, user_data) in state.users {
|
||||
let player_name = user_data.name;
|
||||
let summary = state.player_summaries.get(&user_id);
|
||||
match summary {
|
||||
Some(s) => {
|
||||
if let Some(s) = state.player_summaries.get(&user_id) {
|
||||
let (color_code_start, color_code_end) = if player_name == header.nick {
|
||||
// Give the line for the player a green background with white text
|
||||
// ANSI color codes are in hex, since rust doesn't support octal literals in strings
|
||||
|
|
@ -87,10 +84,6 @@ fn main() -> Result<(), MainError> {
|
|||
|
||||
color_code_end,
|
||||
);
|
||||
},
|
||||
None => {
|
||||
// No summary for this player - they likely joined at the end of the match, or left before they did anything noteworthy
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,9 +92,9 @@ impl<E: Endianness> BitWrite<E> for MaybeUtf8String {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<String> for MaybeUtf8String {
|
||||
fn into(self) -> String {
|
||||
match self {
|
||||
impl From<MaybeUtf8String> for String {
|
||||
fn from(str: MaybeUtf8String) -> String {
|
||||
match str {
|
||||
MaybeUtf8String::Valid(s) => s,
|
||||
MaybeUtf8String::Invalid(_) => "-- Malformed utf8 --".into(),
|
||||
}
|
||||
|
|
@ -150,7 +150,7 @@ pub struct ServerTick(u32);
|
|||
|
||||
impl ServerTick {
|
||||
pub fn range_inclusive(&self, till: Self) -> impl Iterator<Item = Self> {
|
||||
(self.0..=till.0).into_iter().map(Self::from)
|
||||
(self.0..=till.0).map(Self::from)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +242,7 @@ pub struct DemoTick(u32);
|
|||
|
||||
impl DemoTick {
|
||||
pub fn range_inclusive(&self, till: Self) -> impl Iterator<Item = Self> {
|
||||
(self.0..=till.0).into_iter().map(Self::from)
|
||||
(self.0..=till.0).map(Self::from)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -161,6 +161,7 @@ impl PacketEntity {
|
|||
if self.update_type == UpdateType::Enter {
|
||||
let mut found_props = HashSet::<SendPropIdentifier>::new();
|
||||
let props = self.props.iter().cloned();
|
||||
#[allow(clippy::unnecessary_to_owned)]
|
||||
let baseline_props = self
|
||||
.get_baseline_props(parser_state)
|
||||
.into_owned()
|
||||
|
|
|
|||
|
|
@ -428,8 +428,8 @@ pub fn parse_string_table_update<'a>(
|
|||
Ok(entries.into_entries())
|
||||
}
|
||||
|
||||
pub fn write_string_table_update<'a>(
|
||||
entries: &[(u16, StringTableEntry<'a>)],
|
||||
pub fn write_string_table_update(
|
||||
entries: &[(u16, StringTableEntry)],
|
||||
stream: &mut BitWriteStream<LittleEndian>,
|
||||
table_meta: &StringTableMeta,
|
||||
) -> ReadResult<()> {
|
||||
|
|
|
|||
|
|
@ -41,10 +41,13 @@ impl ChatMessage {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Copy, PartialEq, Eq, Hash, TryFromPrimitive)]
|
||||
#[derive(
|
||||
Debug, Clone, Serialize, Deserialize, Copy, PartialEq, Eq, Hash, TryFromPrimitive, Default,
|
||||
)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[repr(u8)]
|
||||
pub enum Team {
|
||||
#[default]
|
||||
Other = 0,
|
||||
Spectator = 1,
|
||||
Red = 2,
|
||||
|
|
@ -64,19 +67,14 @@ impl Team {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for Team {
|
||||
fn default() -> Self {
|
||||
Team::Other
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Clone, Serialize, Copy, PartialEq, Eq, Hash, TryFromPrimitive, Display, FromStr,
|
||||
Debug, Clone, Serialize, Copy, PartialEq, Eq, Hash, TryFromPrimitive, Display, FromStr, Default,
|
||||
)]
|
||||
#[display(style = "lowercase")]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[repr(u8)]
|
||||
pub enum Class {
|
||||
#[default]
|
||||
Other = 0,
|
||||
Scout = 1,
|
||||
Sniper = 2,
|
||||
|
|
@ -129,12 +127,6 @@ impl Class {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for Class {
|
||||
fn default() -> Self {
|
||||
Class::Other
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Eq, PartialEq, Deserialize, Clone)]
|
||||
#[serde(from = "HashMap<Class, u8>")]
|
||||
pub struct ClassList([u8; 10]);
|
||||
|
|
@ -476,7 +468,7 @@ impl Analyser {
|
|||
{
|
||||
self.state
|
||||
.users
|
||||
.entry(user_info.player_info.user_id.into())
|
||||
.entry(user_info.player_info.user_id)
|
||||
.and_modify(|info| {
|
||||
info.entity_id = user_info.entity_id;
|
||||
})
|
||||
|
|
|
|||
|
|
@ -21,8 +21,9 @@ use std::str::FromStr;
|
|||
|
||||
pub struct CachedEntities {}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Default)]
|
||||
pub enum PlayerState {
|
||||
#[default]
|
||||
Alive = 0,
|
||||
Dying = 1,
|
||||
Death = 2,
|
||||
|
|
@ -40,12 +41,6 @@ impl PlayerState {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for PlayerState {
|
||||
fn default() -> Self {
|
||||
PlayerState::Alive
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
||||
pub struct Player {
|
||||
entity: EntityId,
|
||||
|
|
@ -554,8 +549,7 @@ impl GameStateAnalyser {
|
|||
.state
|
||||
.get_or_create_building(entity.entity_index, BuildingClass::Sentry);
|
||||
|
||||
match building {
|
||||
Building::Sentry(sentry) => {
|
||||
if let Building::Sentry(sentry) = building {
|
||||
for prop in entity.props(parser_state) {
|
||||
match prop.identifier {
|
||||
ANGLE => sentry.angle = f32::try_from(&prop.value).unwrap_or_default(),
|
||||
|
|
@ -568,9 +562,7 @@ impl GameStateAnalyser {
|
|||
sentry.auto_aim_target =
|
||||
UserId::from(i64::try_from(&prop.value).unwrap_or_default() as u16)
|
||||
}
|
||||
SHELLS => {
|
||||
sentry.shells = i64::try_from(&prop.value).unwrap_or_default() as u16
|
||||
}
|
||||
SHELLS => sentry.shells = i64::try_from(&prop.value).unwrap_or_default() as u16,
|
||||
ROCKETS => {
|
||||
sentry.rockets = i64::try_from(&prop.value).unwrap_or_default() as u16
|
||||
}
|
||||
|
|
@ -578,8 +570,6 @@ impl GameStateAnalyser {
|
|||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_teleporter_entity(&mut self, entity: &PacketEntity, parser_state: &ParserState) {
|
||||
|
|
@ -607,13 +597,11 @@ impl GameStateAnalyser {
|
|||
.state
|
||||
.get_or_create_building(entity.entity_index, BuildingClass::Teleporter);
|
||||
|
||||
match building {
|
||||
Building::Teleporter(teleporter) => {
|
||||
if let Building::Teleporter(teleporter) = building {
|
||||
for prop in entity.props(parser_state) {
|
||||
match prop.identifier {
|
||||
RECHARGE_TIME => {
|
||||
teleporter.recharge_time =
|
||||
f32::try_from(&prop.value).unwrap_or_default()
|
||||
teleporter.recharge_time = f32::try_from(&prop.value).unwrap_or_default()
|
||||
}
|
||||
RECHARGE_DURATION => {
|
||||
teleporter.recharge_duration =
|
||||
|
|
@ -624,23 +612,19 @@ impl GameStateAnalyser {
|
|||
i64::try_from(&prop.value).unwrap_or_default() as u16
|
||||
}
|
||||
OTHER_END => {
|
||||
teleporter.other_end = EntityId::from(
|
||||
i64::try_from(&prop.value).unwrap_or_default() as u32,
|
||||
)
|
||||
teleporter.other_end =
|
||||
EntityId::from(i64::try_from(&prop.value).unwrap_or_default() as u32)
|
||||
}
|
||||
YAW_TO_EXIT => {
|
||||
teleporter.yaw_to_exit = f32::try_from(&prop.value).unwrap_or_default()
|
||||
}
|
||||
IS_ENTRANCE => {
|
||||
teleporter.is_entrance =
|
||||
i64::try_from(&prop.value).unwrap_or_default() == 0
|
||||
teleporter.is_entrance = i64::try_from(&prop.value).unwrap_or_default() == 0
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_dispenser_entity(&mut self, entity: &PacketEntity, parser_state: &ParserState) {
|
||||
|
|
@ -660,13 +644,10 @@ impl GameStateAnalyser {
|
|||
.state
|
||||
.get_or_create_building(entity.entity_index, BuildingClass::Dispenser);
|
||||
|
||||
match building {
|
||||
Building::Dispenser(dispenser) => {
|
||||
if let Building::Dispenser(dispenser) = building {
|
||||
for prop in entity.props(parser_state) {
|
||||
match prop.identifier {
|
||||
AMMO => {
|
||||
dispenser.metal = i64::try_from(&prop.value).unwrap_or_default() as u16
|
||||
}
|
||||
AMMO => dispenser.metal = i64::try_from(&prop.value).unwrap_or_default() as u16,
|
||||
HEALING => {
|
||||
let values = match &prop.value {
|
||||
SendPropValue::Array(vec) => vec.as_slice(),
|
||||
|
|
@ -675,17 +656,13 @@ impl GameStateAnalyser {
|
|||
|
||||
dispenser.healing = values
|
||||
.iter()
|
||||
.map(|val| {
|
||||
UserId::from(i64::try_from(val).unwrap_or_default() as u16)
|
||||
})
|
||||
.map(|val| UserId::from(i64::try_from(val).unwrap_or_default() as u16))
|
||||
.collect()
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_building(
|
||||
|
|
|
|||
|
|
@ -189,6 +189,7 @@ impl<'a, A: MessageHandler + BorrowMessageHandler> DemoTicker<'a, A> {
|
|||
}
|
||||
|
||||
/// Process the next packet
|
||||
#[allow(clippy::should_implement_trait)]
|
||||
pub fn next(&mut self) -> Result<Option<Tick<A::Output>>> {
|
||||
Ok(
|
||||
if let Some(packet) = self.packets.next(&self.handler.state_handler)? {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use crate::demo::packet::stringtable::StringTableEntry;
|
|||
use crate::demo::parser::analyser::UserInfo;
|
||||
use crate::demo::parser::gamestateanalyser::UserId;
|
||||
use crate::demo::parser::handler::{BorrowMessageHandler, MessageHandler};
|
||||
use crate::demo::sendprop::SendProp;
|
||||
use crate::{ParserState, ReadResult, Stream};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
|
@ -58,14 +59,11 @@ impl MessageHandler for PlayerSummaryAnalyzer {
|
|||
}
|
||||
|
||||
fn handle_message(&mut self, message: &Message, _tick: DemoTick, parser_state: &ParserState) {
|
||||
match message {
|
||||
Message::PacketEntities(message) => {
|
||||
if let Message::PacketEntities(message) = message {
|
||||
for entity in message.entities.iter() {
|
||||
self.handle_packet_entity(&entity, parser_state);
|
||||
self.handle_packet_entity(entity, parser_state);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn into_output(self, _parser_state: &ParserState) -> <Self as MessageHandler>::Output {
|
||||
|
|
@ -111,14 +109,12 @@ fn parse_integer_prop<F>(
|
|||
{
|
||||
use crate::demo::sendprop::SendPropValue;
|
||||
|
||||
match packet.get_prop_by_name(table, name, parser_state) {
|
||||
Some(prop) => {
|
||||
match prop.value {
|
||||
SendPropValue::Integer(val) => handler(val as u32),
|
||||
_ => {} // not an integer, ignore
|
||||
}
|
||||
}
|
||||
None => {} // the packet doesn't have this property
|
||||
if let Some(SendProp {
|
||||
value: SendPropValue::Integer(val),
|
||||
..
|
||||
}) = packet.get_prop_by_name(table, name, parser_state)
|
||||
{
|
||||
handler(val as u32);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -139,8 +135,7 @@ impl PlayerSummaryAnalyzer {
|
|||
// println!("Got a {} data packet: {:?}", class.name, packet);
|
||||
match class.name.as_str() {
|
||||
"CTFPlayer" => {
|
||||
match self.user_id_map.get(&packet.entity_index) {
|
||||
Some(user_id) => {
|
||||
if let Some(user_id) = self.user_id_map.get(&packet.entity_index) {
|
||||
let summaries = &mut self.state.player_summaries;
|
||||
let player_summary = summaries.entry(*user_id).or_default();
|
||||
|
||||
|
|
@ -358,11 +353,6 @@ impl PlayerSummaryAnalyzer {
|
|||
},
|
||||
);
|
||||
}
|
||||
None => {
|
||||
// Player entity likely spawned before the player was assigned to it?
|
||||
// This can rarely happen, but doesn't seem to affect the end result
|
||||
}
|
||||
}
|
||||
}
|
||||
"CTFPlayerResource" => {
|
||||
// Player summaries - including entity IDs!
|
||||
|
|
@ -370,25 +360,18 @@ impl PlayerSummaryAnalyzer {
|
|||
// for example, `m_iUserID.024 = 2523` means entity 24 is user 2523
|
||||
for i in 0..33 {
|
||||
// 0 to 32, inclusive (1..33 might also work, not sure if there's a user 0 or not). Not exhaustive and doesn't work for servers with > 32 players
|
||||
match packet.get_prop_by_name(
|
||||
if let Some(SendProp {
|
||||
value: SendPropValue::Integer(x),
|
||||
..
|
||||
}) = packet.get_prop_by_name(
|
||||
"m_iUserID",
|
||||
format!("{:0>3}", i).as_str(),
|
||||
parser_state,
|
||||
) {
|
||||
Some(prop) => {
|
||||
match prop.value {
|
||||
SendPropValue::Integer(x) => {
|
||||
let entity_id = EntityId::from(i as u32);
|
||||
let user_id = UserId::from(x as u32);
|
||||
self.user_id_map.insert(entity_id, user_id);
|
||||
}
|
||||
_ => {
|
||||
// These properties should all be integers...
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {} // ignore, no property for this entity was included
|
||||
}
|
||||
}
|
||||
}
|
||||
_other => {
|
||||
|
|
@ -409,7 +392,7 @@ impl PlayerSummaryAnalyzer {
|
|||
{
|
||||
self.state
|
||||
.users
|
||||
.entry(user_info.player_info.user_id.into())
|
||||
.entry(user_info.player_info.user_id)
|
||||
.and_modify(|info| {
|
||||
info.entity_id = user_info.entity_id;
|
||||
})
|
||||
|
|
|
|||
|
|
@ -329,7 +329,7 @@ impl Baseline {
|
|||
self.instances[usize::from(index)] = Some(entity);
|
||||
}
|
||||
|
||||
pub fn keys<'a>(&'a self) -> impl Iterator<Item = EntityId> + 'a {
|
||||
pub fn keys(&self) -> impl Iterator<Item = EntityId> + '_ {
|
||||
self.instances
|
||||
.iter()
|
||||
.filter_map(|entity| entity.as_ref().map(|entity| entity.entity_id))
|
||||
|
|
|
|||
|
|
@ -1185,7 +1185,7 @@ impl<'de> Deserialize<'de> for SendPropIdentifier {
|
|||
Ok(match raw {
|
||||
Options::Num(num) => SendPropIdentifier(num),
|
||||
Options::Str(s) => {
|
||||
let num: u64 = s.parse().map_err(|e| D::Error::custom(e))?;
|
||||
let num: u64 = s.parse().map_err(D::Error::custom)?;
|
||||
SendPropIdentifier(num)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ fn re_encode_test(input_file: &str) {
|
|||
}
|
||||
let mut re_read = BitReadStream::new(BitReadBuffer::new(&out_buffer, LittleEndian));
|
||||
let re_decoded = Packet::parse(&mut re_read, &handler.state_handler)
|
||||
.expect(&format!("while parsing {:?}", packet.packet_type()));
|
||||
.unwrap_or_else(|_| panic!("while parsing {:?}", packet.packet_type()));
|
||||
assert_eq!(packet.packet_type(), re_decoded.packet_type());
|
||||
match (&packet, &re_decoded) {
|
||||
(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue