mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-11-30 12:50:49 +01:00
updates
This commit is contained in:
parent
2a02abf982
commit
b03d328ab9
19 changed files with 1081 additions and 978 deletions
|
|
@ -12,7 +12,7 @@ use std::fmt::{Debug, Display, Formatter};
|
|||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::str::FromStr;
|
||||
use steamid_ng::{AccountType, Instance, SteamID, Universe};
|
||||
use steamid_ng::{AccountType, Instance, InstanceFlags, InstanceType, SteamID, Universe};
|
||||
|
||||
#[derive(Serialize, Copy, Clone, Eq, PartialEq, Debug, Ord, PartialOrd, Hash, Default)]
|
||||
pub enum Team {
|
||||
|
|
@ -207,7 +207,7 @@ impl SubjectId {
|
|||
match self {
|
||||
SubjectId::Player(account_id) => Some(SteamID::new(
|
||||
*account_id,
|
||||
Instance::Desktop,
|
||||
Instance::new(InstanceType::Desktop, InstanceFlags::None),
|
||||
AccountType::Individual,
|
||||
Universe::Public,
|
||||
)),
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ pub fn parse(
|
|||
parse_with_handler::<LogHandler>(log)
|
||||
}
|
||||
|
||||
pub fn raw_events(log: &str) -> impl Iterator<Item = Result<RawEvent>> {
|
||||
pub fn raw_events(log: &str) -> impl Iterator<Item = Result<RawEvent<'_>>> {
|
||||
LineSplit::new(log).map(RawEvent::parse)
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ pub fn parse_with_handler<Handler: EventHandler>(
|
|||
Err(e) => return Err(e),
|
||||
};
|
||||
let should_handle = Handler::does_handle(raw_event.ty);
|
||||
if should_handle && start_time.is_none() {
|
||||
if should_handle {
|
||||
let event = match GameEvent::parse(&raw_event) {
|
||||
Ok(event) => event,
|
||||
Err(e) => {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ struct BareChatMessage {
|
|||
pub struct ChatMessage {
|
||||
pub time: u32,
|
||||
pub name: String,
|
||||
#[serde(with = "super::serde_steamid")]
|
||||
pub steam_id: SteamID,
|
||||
pub message: String,
|
||||
pub chat_type: ChatType,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@ impl FromStr for Location {
|
|||
#[derive(Debug, Default, Serialize, PartialEq)]
|
||||
pub struct LobbyLeader {
|
||||
name: String,
|
||||
steam_id: SteamID,
|
||||
#[serde(with = "super::serde_steamid::opt")]
|
||||
steam_id: Option<SteamID>,
|
||||
}
|
||||
|
||||
impl FromStr for LobbyLeader {
|
||||
|
|
@ -60,7 +61,7 @@ impl FromStr for LobbyLeader {
|
|||
if let Ok(steam_id) = steam_id.trim_end_matches(')').parse::<u64>() {
|
||||
Ok(LobbyLeader {
|
||||
name: name.into(),
|
||||
steam_id: steam_id.into(),
|
||||
steam_id: SteamID::from_steam64(steam_id).ok(),
|
||||
})
|
||||
} else {
|
||||
Err(LobbySettingsError::MalformedLeader(s.into()))
|
||||
|
|
|
|||
|
|
@ -304,3 +304,59 @@ impl<T: PlayerSpecificData + Default> EventHandler for PlayerHandler<T> {
|
|||
data.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
mod serde_steamid {
|
||||
use std::{borrow::Cow, str::FromStr};
|
||||
|
||||
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use steamid_ng::SteamID;
|
||||
|
||||
pub(crate) fn serialize<S>(value: &SteamID, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let id = format!("{}", value.steam64());
|
||||
id.serialize(serializer)
|
||||
}
|
||||
|
||||
pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<SteamID, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let s = Cow::<str>::deserialize(deserializer)?;
|
||||
SteamID::from_str(&s).map_err(D::Error::custom)
|
||||
}
|
||||
|
||||
pub mod opt {
|
||||
use std::{borrow::Cow, str::FromStr};
|
||||
|
||||
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use steamid_ng::SteamID;
|
||||
|
||||
pub(crate) fn serialize<S>(
|
||||
value: &Option<SteamID>,
|
||||
serializer: S,
|
||||
) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
match value {
|
||||
Some(id) => {
|
||||
let id = format!("{}", id.steam64());
|
||||
id.serialize(serializer)
|
||||
}
|
||||
None => None::<String>.serialize(serializer),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<Option<SteamID>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let s = Option::<Cow<str>>::deserialize(deserializer)?;
|
||||
s.map(|s| SteamID::from_str(&s).map_err(D::Error::custom))
|
||||
.transpose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ impl<'a> RawEvent<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn event_parser(input: &str) -> Result<RawEvent> {
|
||||
fn event_parser(input: &str) -> Result<RawEvent<'_>> {
|
||||
// println!("{}", input);
|
||||
if input.len() < 24 {
|
||||
return Err(Error::Skip);
|
||||
|
|
@ -136,7 +136,7 @@ fn test_split_player_subject() {
|
|||
);
|
||||
}
|
||||
|
||||
pub fn against_subject_parser(input: &str) -> Result<RawSubject> {
|
||||
pub fn against_subject_parser(input: &str) -> Result<RawSubject<'_>> {
|
||||
// "against" fields are always players, and unquoted
|
||||
if input.ends_with("le>") {
|
||||
Ok(RawSubject::Console)
|
||||
|
|
@ -145,7 +145,7 @@ pub fn against_subject_parser(input: &str) -> Result<RawSubject> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn subject_parser(input: &str) -> Result<(&str, RawSubject)> {
|
||||
pub fn subject_parser(input: &str) -> Result<(&str, RawSubject<'_>)> {
|
||||
let full = input;
|
||||
if let Some(input) = input.strip_prefix('"') {
|
||||
let Ok((player, input)) = split_subject_end(input, 1) else {
|
||||
|
|
@ -313,13 +313,15 @@ pub enum RawEventType {
|
|||
FlagEvent,
|
||||
#[token(r#"cvars "#)]
|
||||
CVars,
|
||||
#[error]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
fn event_type_parser(input: &str) -> Result<(&str, RawEventType)> {
|
||||
let mut lexer = Lexer::new(input);
|
||||
let ty = lexer.next().unwrap_or(RawEventType::Unknown);
|
||||
let ty = lexer
|
||||
.next()
|
||||
.ok_or(Error::Incomplete)?
|
||||
.unwrap_or(RawEventType::Unknown);
|
||||
Ok((lexer.remainder(), ty))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue