diff options
author | Daniel Schadt <kingdread@gmx.de> | 2020-05-19 15:39:38 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2020-05-19 15:39:38 +0200 |
commit | 1e4eaeae1bfd794213f8eee09cb189e7c6fff4d6 (patch) | |
tree | 849f15017f178ece5158e29d1c8a12eab869148e /src | |
parent | a2c77bd2f8110c505464077c22d489d6a6d4c8c8 (diff) | |
download | evtclib-1e4eaeae1bfd794213f8eee09cb189e7c6fff4d6.tar.gz evtclib-1e4eaeae1bfd794213f8eee09cb189e7c6fff4d6.tar.bz2 evtclib-1e4eaeae1bfd794213f8eee09cb189e7c6fff4d6.zip |
implement Error statechange
Diffstat (limited to 'src')
-rw-r--r-- | src/event.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/event.rs b/src/event.rs index df0d5d3..a598d3d 100644 --- a/src/event.rs +++ b/src/event.rs @@ -19,6 +19,8 @@ pub enum FromRawEventError { UnknownStateChange(raw::CbtStateChange), #[error("event contains an unknown damage event")] UnknownDamageEvent, + #[error("the event contains invalid text")] + InvalidText, } /// A rusty enum for all possible combat events. @@ -177,6 +179,9 @@ pub enum EventKind { raw_bytes: [u8; 16], api_guild_id: Option<String>, }, + + /// An error was reported by arcdps. + Error { text: String }, } /// A higher-level representation of a combat event. @@ -354,6 +359,15 @@ impl TryFrom<&raw::CbtEvent> for Event { agent_addr: raw_event.src_agent, targetable: raw_event.dst_agent != 0, }, + CbtStateChange::Error => { + let data = get_error_bytes(&raw_event); + EventKind::Error { + text: raw::cstr_up_to_nul(&data) + .ok_or(FromRawEventError::InvalidText)? + .to_string_lossy() + .into_owned(), + } + } // XXX: implement proper handling of those events! CbtStateChange::BuffInitial | CbtStateChange::ReplInfo @@ -365,7 +379,6 @@ impl TryFrom<&raw::CbtEvent> for Event { | CbtStateChange::SkillTiming | CbtStateChange::BreakbarState | CbtStateChange::BreakbarPercent - | CbtStateChange::Error | CbtStateChange::Unknown => { return Err(FromRawEventError::UnknownStateChange( raw_event.is_statechange, @@ -490,6 +503,17 @@ fn get_api_guild_string(bytes: &[u8; 16]) -> Option<String> { Some(result) } +fn get_error_bytes(raw_event: &raw::CbtEvent) -> [u8; 32] { + let mut result = [0; 32]; + let mut cursor = io::Cursor::new(&mut result as &mut [u8]); + cursor.write_u64::<BigEndian>(raw_event.time).unwrap(); + cursor.write_u64::<BigEndian>(raw_event.src_agent).unwrap(); + cursor.write_u64::<BigEndian>(raw_event.dst_agent).unwrap(); + cursor.write_i32::<BigEndian>(raw_event.value).unwrap(); + cursor.write_i32::<BigEndian>(raw_event.buff_dmg).unwrap(); + result +} + /// The different weapon-sets in game. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum WeaponSet { |