diff options
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | src/agent.rs | 17 |
2 files changed, 19 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 512fa23..9b916e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ All notable changes to this project will be documented in this file. - Boss and encounter definitions for the training golems (`StandardKittyGolem`, `MediumKittyGolem`, `LargeKittyGolem`) +### Fixed +- `evtclib` will no longer choke on WvW logs where player names might not contain the expected + information. + ## 0.5.0 - 2020-10-07 ### Added - `Boss::Ai` to represent Ai, Keeper of the Peak in the Sunqua Peak fractal. diff --git a/src/agent.rs b/src/agent.rs index 60c16e3..4dece3e 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -39,6 +39,8 @@ pub struct Player { impl Player { /// The player's character name. + /// + /// **Note**: Hostile WvW agents will have a randomly generated player name. pub fn character_name(&self) -> &str { &self.character_name } @@ -46,6 +48,8 @@ impl Player { /// The player's account name. /// /// This includes the leading colon and the 4-digit denominator. + /// + /// **Note**: Hostile WvW agents will have an empty account name. pub fn account_name(&self) -> &str { &self.account_name } @@ -158,10 +162,19 @@ impl AgentKind { let character_name = raw::cstr_up_to_nul(&raw_agent.name) .ok_or(EvtcError::InvalidData)? .to_str()?; - let account_name = raw::cstr_up_to_nul(&raw_agent.name[character_name.len() + 1..]) + let remainder = &raw_agent.name[character_name.len() + 1..]; + let account_name = raw::cstr_up_to_nul(remainder) + .ok_or(EvtcError::InvalidData)? + .to_str()?; + let remainder = &remainder[account_name.len() + 1..]; + let subgroup = raw::cstr_up_to_nul(remainder) .ok_or(EvtcError::InvalidData)? .to_str()?; - let subgroup = raw_agent.name[character_name.len() + account_name.len() + 2] - b'0'; + let subgroup = if subgroup.is_empty() { + 0 + } else { + subgroup.parse().map_err(|_| EvtcError::InvalidData)? + }; let elite = if raw_agent.is_elite == 0 { None } else { |