mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 18:24:09 +02:00
handle bots and old style steamid
This commit is contained in:
parent
b06f419a9a
commit
a30a3d3683
1 changed files with 29 additions and 7 deletions
|
|
@ -195,6 +195,7 @@ impl<T: PartialEq> PartialEq for ClassMap<T> {
|
||||||
pub enum SubjectId {
|
pub enum SubjectId {
|
||||||
Player(u32),
|
Player(u32),
|
||||||
Team(Team),
|
Team(Team),
|
||||||
|
Bot(u16),
|
||||||
System,
|
System,
|
||||||
World,
|
World,
|
||||||
Console,
|
Console,
|
||||||
|
|
@ -227,7 +228,13 @@ impl TryFrom<&RawSubject<'_>> for SubjectId {
|
||||||
.map_err(|_| SubjectError::InvalidSteamId)?,
|
.map_err(|_| SubjectError::InvalidSteamId)?,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return Err(SubjectError::InvalidSteamId);
|
let (_, user_id, steam_id, _) =
|
||||||
|
split_player_subject(raw).map_err(|_| SubjectError::InvalidSteamId)?;
|
||||||
|
if let Ok(steam_id) = SteamID::from_steam2(steam_id) {
|
||||||
|
SubjectId::Player(steam_id.account_id())
|
||||||
|
} else {
|
||||||
|
SubjectId::Bot(user_id.parse().map_err(|_| SubjectError::InvalidUserId)?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RawSubject::Team(team) => SubjectId::Team(*team),
|
RawSubject::Team(team) => SubjectId::Team(*team),
|
||||||
|
|
@ -248,6 +255,11 @@ pub enum SubjectData {
|
||||||
},
|
},
|
||||||
Team(Team),
|
Team(Team),
|
||||||
System(String),
|
System(String),
|
||||||
|
Bot {
|
||||||
|
name: String,
|
||||||
|
user_id: u16,
|
||||||
|
team: Team,
|
||||||
|
},
|
||||||
Console,
|
Console,
|
||||||
World,
|
World,
|
||||||
}
|
}
|
||||||
|
|
@ -258,6 +270,7 @@ impl SubjectData {
|
||||||
SubjectData::Player { steam_id, .. } => SubjectId::Player(steam_id.account_id()),
|
SubjectData::Player { steam_id, .. } => SubjectId::Player(steam_id.account_id()),
|
||||||
SubjectData::Team(team) => SubjectId::Team(*team),
|
SubjectData::Team(team) => SubjectId::Team(*team),
|
||||||
SubjectData::System(_) => SubjectId::System,
|
SubjectData::System(_) => SubjectId::System,
|
||||||
|
SubjectData::Bot { user_id, .. } => SubjectId::Bot(*user_id),
|
||||||
SubjectData::Console => SubjectId::Console,
|
SubjectData::Console => SubjectId::Console,
|
||||||
SubjectData::World => SubjectId::World,
|
SubjectData::World => SubjectId::World,
|
||||||
}
|
}
|
||||||
|
|
@ -282,13 +295,22 @@ impl TryFrom<&RawSubject<'_>> for SubjectData {
|
||||||
RawSubject::Player(raw) => {
|
RawSubject::Player(raw) => {
|
||||||
let (name, user_id, steam_id, team) =
|
let (name, user_id, steam_id, team) =
|
||||||
split_player_subject(raw).map_err(|_| SubjectError::InvalidUserId)?;
|
split_player_subject(raw).map_err(|_| SubjectError::InvalidUserId)?;
|
||||||
|
if let Ok(steam_id) =
|
||||||
|
SteamID::from_steam3(steam_id).or_else(|_| SteamID::from_steam2(steam_id))
|
||||||
|
{
|
||||||
SubjectData::Player {
|
SubjectData::Player {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
user_id: user_id.parse().map_err(|_| SubjectError::InvalidUserId)?,
|
user_id: user_id.parse().map_err(|_| SubjectError::InvalidUserId)?,
|
||||||
steam_id: SteamID::from_steam3(steam_id)
|
steam_id,
|
||||||
.map_err(|_| SubjectError::InvalidSteamId)?,
|
|
||||||
team: team.parse().unwrap_or_default(),
|
team: team.parse().unwrap_or_default(),
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
SubjectData::Bot {
|
||||||
|
name: name.to_string(),
|
||||||
|
user_id: user_id.parse().map_err(|_| SubjectError::InvalidUserId)?,
|
||||||
|
team: team.parse().unwrap_or_default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
RawSubject::Team(team) => SubjectData::Team(*team),
|
RawSubject::Team(team) => SubjectData::Team(*team),
|
||||||
RawSubject::System(name) => SubjectData::System(name.to_string()),
|
RawSubject::System(name) => SubjectData::System(name.to_string()),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue