From a91b4d41dd0282be4dbc34220dad523877830d18 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 12 Jun 2024 21:30:51 +0200 Subject: [PATCH] hardcode some events (working) --- src/factorio.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/factorio.hpp | 2 ++ 2 files changed, 46 insertions(+) diff --git a/src/factorio.cpp b/src/factorio.cpp index b9f6f05..0630841 100644 --- a/src/factorio.cpp +++ b/src/factorio.cpp @@ -6,6 +6,16 @@ #include #include +void Factorio::sendToLinked(const std::string& message) { + for (const auto& h : _linked_contacts) { + if (!static_cast(h)) { + continue; + } + + _rmm.sendText(h, message); + } +} + Factorio::Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp) : _cr(cr), _rmm(rmm), @@ -57,21 +67,48 @@ bool Factorio::onEvent(const Message::Events::MessageConstruct& e) { bool Factorio::onEvent(const FactorioLog::Events::Join& e) { std::cout << "Factorio: event join " << e.player_name << "\n"; + + std::string message{e.player_name}; + message += " joined"; + + sendToLinked(message); + return false; } bool Factorio::onEvent(const FactorioLog::Events::Leave& e) { std::cout << "Factorio: event leave " << e.player_name << " " << e.reason << "\n"; + + std::string message{e.player_name}; + message += " left"; + + sendToLinked(message); + return false; } bool Factorio::onEvent(const FactorioLog::Events::Chat& e) { std::cout << "Factorio: event chat " << e.player_name << ": " << e.message << "\n"; + + std::string message{"<"}; + message += e.player_name; + message += ">: "; + message += e.message; + + sendToLinked(message); + return false; } bool Factorio::onEvent(const FactorioLog::Events::Died& e) { std::cout << "Factorio: event died " << e.player_name << ": " << e.reason << "\n"; + + std::string message{e.player_name}; + message += " died from "; + message += e.reason; + + sendToLinked(message); + return false; } @@ -87,6 +124,13 @@ bool Factorio::onEvent(const FactorioLog::Events::ResearchStarted& e) { bool Factorio::onEvent(const FactorioLog::Events::ResearchFinished& e) { std::cout << "Factorio: event research finished " << e.name << "\n"; + + std::string message{"Research "}; + message += e.name; + message += " finished!"; + + sendToLinked(message); + return false; } diff --git a/src/factorio.hpp b/src/factorio.hpp index e861198..cfca108 100644 --- a/src/factorio.hpp +++ b/src/factorio.hpp @@ -16,6 +16,8 @@ class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEven std::vector _linked_contacts; + void sendToLinked(const std::string& message); + public: Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModel& rmm, FactorioLogParser& flp); virtual ~Factorio(void);