From 6aa90a1852d857dbd3a86e9cce9b9880a8b3870c Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sun, 12 Jan 2025 13:37:35 +0100 Subject: [PATCH] make forwarding configurable --- src/factorio.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/factorio.hpp | 1 + 2 files changed, 37 insertions(+) diff --git a/src/factorio.cpp b/src/factorio.cpp index 99dbc89..2652dd8 100644 --- a/src/factorio.cpp +++ b/src/factorio.cpp @@ -17,6 +17,7 @@ void Factorio::sendToLinked(const std::string& message) { } Factorio::Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModelI& rmm, FactorioLogParser& flp) : + _conf(conf), _cr(cr), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), @@ -72,6 +73,10 @@ 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"; + if (!_conf.get_bool("Factorio", "forward", "join").value_or(true)) { + return false; + } + std::string message{e.player_name}; message += " joined"; @@ -83,6 +88,10 @@ bool Factorio::onEvent(const FactorioLog::Events::Join& e) { bool Factorio::onEvent(const FactorioLog::Events::Leave& e) { std::cout << "Factorio: event leave " << e.player_name << " " << e.reason << "\n"; + if (!_conf.get_bool("Factorio", "forward", "leave").value_or(true)) { + return false; + } + std::string message{e.player_name}; message += " left"; @@ -94,6 +103,10 @@ bool Factorio::onEvent(const FactorioLog::Events::Leave& e) { bool Factorio::onEvent(const FactorioLog::Events::Chat& e) { std::cout << "Factorio: event chat " << e.player_name << ": " << e.message << "\n"; + if (!_conf.get_bool("Factorio", "forward", "chat").value_or(true)) { + return false; + } + // ignore pings constexpr std::string_view ping_prefix{"[gps="}; if (e.message.size() > ping_prefix.size() && e.message.substr(0, ping_prefix.size()) == ping_prefix) { @@ -113,6 +126,10 @@ bool Factorio::onEvent(const FactorioLog::Events::Chat& e) { bool Factorio::onEvent(const FactorioLog::Events::Died& e) { std::cout << "Factorio: event died " << e.player_name << ": " << e.reason << "\n"; + if (!_conf.get_bool("Factorio", "forward", "died").value_or(true)) { + return false; + } + std::string message{e.player_name}; message += " died from "; message += e.reason; @@ -124,17 +141,31 @@ bool Factorio::onEvent(const FactorioLog::Events::Died& e) { bool Factorio::onEvent(const FactorioLog::Events::Evolution& e) { std::cout << "Factorio: event evolution " << e.evo << "\n"; + + //if (!_conf.get_bool("Factorio", "forward", "evolution").value_or(true)) { + // return false; + //} + return false; } bool Factorio::onEvent(const FactorioLog::Events::ResearchStarted& e) { std::cout << "Factorio: event research started " << e.name << "\n"; + + //if (!_conf.get_bool("Factorio", "forward", "research_started").value_or(true)) { + // return false; + //} + return false; } bool Factorio::onEvent(const FactorioLog::Events::ResearchFinished& e) { std::cout << "Factorio: event research finished " << e.name << "\n"; + if (!_conf.get_bool("Factorio", "forward", "research_finished").value_or(true)) { + return false; + } + std::string message{"Research "}; message += e.name; message += " finished!"; @@ -146,6 +177,11 @@ bool Factorio::onEvent(const FactorioLog::Events::ResearchFinished& e) { bool Factorio::onEvent(const FactorioLog::Events::ResearchCancelled& e) { std::cout << "Factorio: event research cancelled " << e.name << "\n"; + + //if (!_conf.get_bool("Factorio", "forward", "research_cancelled").value_or(true)) { + // return false; + //} + return false; } diff --git a/src/factorio.hpp b/src/factorio.hpp index a65d729..280a825 100644 --- a/src/factorio.hpp +++ b/src/factorio.hpp @@ -10,6 +10,7 @@ struct ConfigModelI; class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEventI { + ConfigModelI& _conf; Contact3Registry& _cr; RegistryMessageModelI& _rmm; RegistryMessageModelI::SubscriptionReference _rmm_sr;