Skip to content

Commit

Permalink
make forwarding configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky committed Jan 12, 2025
1 parent f69923c commit 6aa90a1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/factorio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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";

Expand All @@ -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";

Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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!";
Expand All @@ -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;
}

1 change: 1 addition & 0 deletions src/factorio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
struct ConfigModelI;

class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEventI {
ConfigModelI& _conf;
Contact3Registry& _cr;
RegistryMessageModelI& _rmm;
RegistryMessageModelI::SubscriptionReference _rmm_sr;
Expand Down

0 comments on commit 6aa90a1

Please sign in to comment.