Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add server_message game event #197

Merged
merged 2 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/parser/src/second_pass/game_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use csgoproto::cstrike15_usermessages::CCSUsrMsg_ServerRankUpdate;
use csgoproto::networkbasetypes::csvcmsg_game_event::Key_t;
use csgoproto::networkbasetypes::CNETMsg_SetConVar;
use csgoproto::networkbasetypes::CSVCMsg_GameEvent;
use csgoproto::usermessages::CUserMessageSayText;
use csgoproto::usermessages::CUserMessageSayText2;
use itertools::Itertools;
use protobuf::Message;
use serde::ser::SerializeMap;
Expand Down Expand Up @@ -855,7 +857,6 @@ impl<'a> SecondPassParser<'a> {
None
}
pub fn create_custom_event_chat_message(&mut self, msg_bytes: &[u8]) -> Result<(), DemoParserError> {
use csgoproto::usermessages::CUserMessageSayText2;
self.game_events_counter.insert("chat_message".to_string());
if !self.wanted_events.contains(&"chat_message".to_string()) && self.wanted_events.first() != Some(&"all".to_string()) {
return Ok(());
Expand All @@ -864,7 +865,6 @@ impl<'a> SecondPassParser<'a> {
Ok(msg) => msg,
Err(_) => return Err(DemoParserError::MalformedMessage),
};

let mut fields = vec![];
let controller_id = chat_msg.entityindex();
let res = self.find_user_by_controller_id(controller_id);
Expand All @@ -887,6 +887,32 @@ impl<'a> SecondPassParser<'a> {
self.game_events.push(ge);
Ok(())
}
pub fn create_custom_event_server_message(&mut self, msg_bytes: &[u8]) -> Result<(), DemoParserError> {
self.game_events_counter.insert("server_message".to_string());
if !self.wanted_events.contains(&"server_message".to_string()) && self.wanted_events.first() != Some(&"all".to_string()) {
return Ok(());
}
let chat_msg: CUserMessageSayText = match Message::parse_from_bytes(&msg_bytes) {
Ok(msg) => msg,
Err(_) => return Err(DemoParserError::MalformedMessage),
};
let mut fields = vec![];
fields.push(EventField {
data: Some(Variant::String(chat_msg.text().to_owned())),
name: "server_message".to_string(),
});
fields.push(EventField {
data: Some(Variant::I32(self.tick)),
name: "tick".to_string(),
});
let ge = GameEvent {
name: "server_message".to_string(),
fields: fields,
tick: self.tick,
};
self.game_events.push(ge);
Ok(())
}

pub fn create_custom_event_round_start(&mut self, _events: &[GameEventInfo]) -> Result<(), DemoParserError> {
self.game_events_counter.insert("round_start".to_string());
Expand All @@ -895,7 +921,6 @@ impl<'a> SecondPassParser<'a> {
}
let mut fields = vec![];
fields.extend(self.find_non_player_props());

fields.push(EventField {
data: self.find_current_round(),
name: "round".to_string(),
Expand All @@ -910,7 +935,6 @@ impl<'a> SecondPassParser<'a> {
tick: self.tick,
};
self.game_events.push(ge);

Ok(())
}

Expand Down
7 changes: 1 addition & 6 deletions src/parser/src/second_pass/other_netmessages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ use crate::first_pass::read_bits::DemoParserError;
use crate::first_pass::sendtables::Serializer;
use crate::maps::PAINTKITS;
use crate::maps::WEAPINDICIES;
use crate::second_pass::parser_settings::ChatMessageRecord;
use crate::second_pass::parser_settings::EconItem;
use crate::second_pass::parser_settings::PlayerEndMetaData;
use crate::second_pass::parser_settings::SecondPassParser;
use csgoproto::cstrike15_usermessages::CCSUsrMsg_EndOfMatchAllPlayersData;
use csgoproto::cstrike15_usermessages::CCSUsrMsg_SendPlayerItemDrops;
use csgoproto::networkbasetypes::CNETMsg_SetConVar;
use csgoproto::usermessages::CUserMessageSayText2;
use protobuf::Message;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -55,10 +53,7 @@ impl<'a> SecondPassParser<'a> {
}
Ok(())
}
pub fn parse_chat_messages(&mut self, bytes: &[u8]) -> Result<(), DemoParserError> {
self.create_custom_event_chat_message(bytes)?;
Ok(())
}

pub fn parse_convars(&mut self, bytes: &[u8]) -> Result<(), DemoParserError> {
let convar: CNETMsg_SetConVar = match Message::parse_from_bytes(&bytes) {
Ok(msg) => msg,
Expand Down
6 changes: 4 additions & 2 deletions src/parser/src/second_pass/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ impl<'a> SecondPassParser<'a> {
svc_ServerInfo => self.parse_server_info(msg_bytes),
CS_UM_SendPlayerItemDrops => self.parse_item_drops(msg_bytes),
CS_UM_EndOfMatchAllPlayersData => self.parse_player_end_msg(msg_bytes),
UM_SayText2 => self.parse_chat_messages(msg_bytes),
UM_SayText2 => self.create_custom_event_chat_message(msg_bytes),
UM_SayText => self.create_custom_event_server_message(msg_bytes),
net_SetConVar => self.create_custom_event_parse_convars(msg_bytes),
CS_UM_PlayerStatsUpdate => self.parse_player_stats_update(msg_bytes),
CS_UM_ServerRankUpdate => self.create_custom_event_rank_update(msg_bytes),
Expand Down Expand Up @@ -219,7 +220,8 @@ impl<'a> SecondPassParser<'a> {
svc_UpdateStringTable => self.update_string_table(&msg_bytes),
CS_UM_SendPlayerItemDrops => self.parse_item_drops(&msg_bytes),
CS_UM_EndOfMatchAllPlayersData => self.parse_player_end_msg(&msg_bytes),
UM_SayText2 => self.parse_chat_messages(&msg_bytes),
UM_SayText2 => self.create_custom_event_chat_message(&msg_bytes),
UM_SayText => self.create_custom_event_server_message(bytes),
net_SetConVar => self.create_custom_event_parse_convars(&msg_bytes),
CS_UM_PlayerStatsUpdate => self.parse_player_stats_update(&msg_bytes),
svc_ServerInfo => self.parse_server_info(&msg_bytes),
Expand Down
Loading