Skip to content

Instantly share code, notes, and snippets.

@invokr
Created July 16, 2014 00:14
Show Gist options
  • Save invokr/9adc0b98254c58570eca to your computer and use it in GitHub Desktop.
Save invokr/9adc0b98254c58570eca to your computer and use it in GitHub Desktop.
#include <iostream>
#include <exception>
#include <alice/alice.hpp>
using namespace dota;
/** This handler prints all global chat messages to the console. */
class handler_chat {
private:
/** Pointer to the parser */
parser* p;
/** Pointer to the handler */
handler_t* h;
public:
/** Constructor, takes the handler */
handler_chat(parser* p) : p(p), h(p->getHandler()) {
handlerRegisterCallback(h, msgDem, DEM_FileInfo, handler_chat, handleChat)
}
/** Prints chat message to console */
void handleChat(handlerCbType(msgDem) msg) {
CDemoFileInfo *m = msg->get<CDemoFileInfo>();
// print a protobuf debug string containing the game summary
std::cout << m->DebugString() << std::endl;
}
};
int main(int argc, char **argv) {
if (argc != 2) {
std::cerr << "Usage: alice-chat <file>" << std::endl;
return 1;
}
try {
// settings for the parser
settings s{
true, // forward_dem - We don't handle them so we don't need to listen to them
true, // forward_net - Yes for user messages
true, // forward_net_internal - Not required
true, // forward_user - Yes please.
false, // parse_stringtables - No required, information is available soely in user messages
std::set<std::string>{}, // blocked stringtables - Names say all
false, // parse_entities - Nope
false, // track_entities - Nope
false, // forward entities - Nope
true, // skip unused - Yes cause we don't request them via the parser
std::set<uint32_t>{}, // blocked ones - All except the forwarded with skip_unused=true
false // we dont handle events
};
// create a parser and open the replay
parser p(s, new dem_stream_file);
p.open(argv[1]);
// create handler and attach parser
handler_chat h(&p);
// parse all messages
p.handle();
} catch (boost::exception &e) {
std::cout << boost::diagnostic_information(e) << std::endl;
} catch (std::exception &e) {
std::cout << e.what() << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment