more steamid fixes

This commit is contained in:
Robin Appelman 2023-03-16 23:16:53 +01:00
commit 1b9addbb4f

View file

@ -228,21 +228,18 @@ impl TryFrom<&RawSubject<'_>> for SubjectId {
Ok(match raw { Ok(match raw {
RawSubject::Player(raw) => { RawSubject::Player(raw) => {
if let Some(raw_account_id) = find_between_end(raw, b':', b']') { if let Some(raw_account_id) = find_between_end(raw, b':', b']') {
SubjectId::Player( if let Ok(account_id) = raw_account_id.parse() {
raw_account_id return Ok(SubjectId::Player(account_id));
.parse() }
.map_err(|_| SubjectError::InvalidSteamId)?, }
) let (_, user_id, steam_id, _) = split_player_subject(raw)
} else { .map_err(|_| SubjectError::InvalidSteamId(raw.to_string()))?;
let (_, user_id, steam_id, _) =
split_player_subject(raw).map_err(|_| SubjectError::InvalidSteamId)?;
if let Ok(steam_id) = SteamID::from_steam2(steam_id) { if let Ok(steam_id) = SteamID::from_steam2(steam_id) {
SubjectId::Player(steam_id.account_id()) SubjectId::Player(steam_id.account_id())
} else { } else {
SubjectId::Bot(user_id.parse().map_err(|_| SubjectError::InvalidUserId)?) SubjectId::Bot(user_id.parse().map_err(|_| SubjectError::InvalidUserId)?)
} }
} }
}
RawSubject::Team(team) => SubjectId::Team(*team), RawSubject::Team(team) => SubjectId::Team(*team),
RawSubject::System(_) => SubjectId::System, RawSubject::System(_) => SubjectId::System,
RawSubject::Console => SubjectId::Console, RawSubject::Console => SubjectId::Console,
@ -287,8 +284,8 @@ impl SubjectData {
pub enum SubjectError { pub enum SubjectError {
#[error("Invalid user id")] #[error("Invalid user id")]
InvalidUserId, InvalidUserId,
#[error("Invalid steam id")] #[error("Invalid steam id for \"{0}\"")]
InvalidSteamId, InvalidSteamId(String),
#[error("Invalid team name")] #[error("Invalid team name")]
InvalidTeam, InvalidTeam,
} }