Compare commits

..

2 Commits

Author SHA1 Message Date
161f605b20 port to contact4
Some checks failed
ContinuousDelivery / linux-ubuntu (push) Has been cancelled
ContinuousDelivery / windows (push) Has been cancelled
ContinuousIntegration / linux (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled
2025-03-10 22:57:15 +01:00
6aa90a1852 make forwarding configurable
Some checks failed
ContinuousDelivery / linux-ubuntu (push) Has been cancelled
ContinuousDelivery / windows (push) Has been cancelled
ContinuousIntegration / linux (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled
2025-01-12 13:37:35 +01:00
3 changed files with 50 additions and 17 deletions

View File

@ -34,13 +34,13 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
try {
auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI);
auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
auto* cs = PLUG_RESOLVE_INSTANCE(ContactStore4I);
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI);
// static store, could be anywhere tho
// construct with fetched dependencies
g_flp = std::make_unique<FactorioLogParser>(*conf);
g_f = std::make_unique<Factorio>(*conf, *cr, *rmm, *g_flp);
g_f = std::make_unique<Factorio>(*conf, *cs, *rmm, *g_flp);
// register types
PLUG_PROVIDE_INSTANCE(FactorioLogParser, plugin_name, g_flp.get());

View File

@ -3,6 +3,8 @@
#include <solanaceae/util/config_model.hpp>
#include <solanaceae/util/utils.hpp>
#include <solanaceae/contact/contact_store_i.hpp>
#include <solanaceae/message3/components.hpp>
#include <solanaceae/contact/components.hpp>
@ -16,8 +18,9 @@ void Factorio::sendToLinked(const std::string& message) {
}
}
Factorio::Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModelI& rmm, FactorioLogParser& flp) :
_cr(cr),
Factorio::Factorio(ConfigModelI& conf, ContactStore4I& cs, RegistryMessageModelI& rmm, FactorioLogParser& flp) :
_conf(conf),
_cs(cs),
_rmm(rmm),
_rmm_sr(_rmm.newSubRef(this)),
_flp(flp),
@ -30,19 +33,12 @@ Factorio::Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageMode
const auto id_vec = hex2bin(contact_id);
// search
Contact3Handle h;
auto view = _cr.view<Contact::Components::ID>();
for (const auto c : view) {
if (view.get<Contact::Components::ID>(c).data == id_vec) {
h = Contact3Handle{_cr, c};
std::cout << "Factorio: found contact for link.\n";
break;
}
}
ContactHandle4 h = _cs.getOneContactByID(ByteSpan{id_vec});
if (!static_cast<bool>(h)) {
// not found, create thin contact with just id
h = {_cr, _cr.create()};
h = _cs.contactHandle(_cs.registry().create());
h.emplace<Contact::Components::ID>(id_vec);
_cs.throwEventConstruct(h);
std::cout << "Factorio: contact not found, created thin contact from ID. (" << contact_id << ")\n";
}
_linked_contacts.push_back(h);
@ -72,6 +68,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 +83,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 +98,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 +121,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 +136,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 +172,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;
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <solanaceae/contact/fwd.hpp>
#include <solanaceae/message3/registry_message_model.hpp>
#include "./factorio_log_parser.hpp"
@ -10,18 +11,19 @@
struct ConfigModelI;
class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEventI {
Contact3Registry& _cr;
ConfigModelI& _conf;
ContactStore4I& _cs;
RegistryMessageModelI& _rmm;
RegistryMessageModelI::SubscriptionReference _rmm_sr;
FactorioLogParser& _flp;
FactorioLogParser::SubscriptionReference _flp_sr;
std::vector<Contact3Handle> _linked_contacts;
std::vector<ContactHandle4> _linked_contacts;
void sendToLinked(const std::string& message);
public:
Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModelI& rmm, FactorioLogParser& flp);
Factorio(ConfigModelI& conf, ContactStore4I& cs, RegistryMessageModelI& rmm, FactorioLogParser& flp);
virtual ~Factorio(void);
protected: // rmm