Compare commits
4 Commits
117e40dc9e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2efbff5e8b | ||
|
|
6aa90a1852 | ||
|
|
f69923cbbb | ||
|
|
b62ab60366 |
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024-2025 Erik Scholz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -34,13 +34,13 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI);
|
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);
|
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI);
|
||||||
|
|
||||||
// static store, could be anywhere tho
|
// static store, could be anywhere tho
|
||||||
// construct with fetched dependencies
|
// construct with fetched dependencies
|
||||||
g_flp = std::make_unique<FactorioLogParser>(*conf);
|
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
|
// register types
|
||||||
PLUG_PROVIDE_INSTANCE(FactorioLogParser, plugin_name, g_flp.get());
|
PLUG_PROVIDE_INSTANCE(FactorioLogParser, plugin_name, g_flp.get());
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#include <solanaceae/util/config_model.hpp>
|
#include <solanaceae/util/config_model.hpp>
|
||||||
#include <solanaceae/util/utils.hpp>
|
#include <solanaceae/util/utils.hpp>
|
||||||
|
|
||||||
|
#include <solanaceae/contact/contact_store_i.hpp>
|
||||||
|
|
||||||
#include <solanaceae/message3/components.hpp>
|
#include <solanaceae/message3/components.hpp>
|
||||||
#include <solanaceae/contact/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) :
|
Factorio::Factorio(ConfigModelI& conf, ContactStore4I& cs, RegistryMessageModelI& rmm, FactorioLogParser& flp) :
|
||||||
_cr(cr),
|
_conf(conf),
|
||||||
|
_cs(cs),
|
||||||
_rmm(rmm),
|
_rmm(rmm),
|
||||||
_rmm_sr(_rmm.newSubRef(this)),
|
_rmm_sr(_rmm.newSubRef(this)),
|
||||||
_flp(flp),
|
_flp(flp),
|
||||||
@@ -30,19 +33,12 @@ Factorio::Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageMode
|
|||||||
const auto id_vec = hex2bin(contact_id);
|
const auto id_vec = hex2bin(contact_id);
|
||||||
|
|
||||||
// search
|
// search
|
||||||
Contact3Handle h;
|
ContactHandle4 h = _cs.getOneContactByID(ByteSpan{id_vec});
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!static_cast<bool>(h)) {
|
if (!static_cast<bool>(h)) {
|
||||||
// not found, create thin contact with just id
|
// 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);
|
h.emplace<Contact::Components::ID>(id_vec);
|
||||||
|
_cs.throwEventConstruct(h);
|
||||||
std::cout << "Factorio: contact not found, created thin contact from ID. (" << contact_id << ")\n";
|
std::cout << "Factorio: contact not found, created thin contact from ID. (" << contact_id << ")\n";
|
||||||
}
|
}
|
||||||
_linked_contacts.push_back(h);
|
_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) {
|
bool Factorio::onEvent(const FactorioLog::Events::Join& e) {
|
||||||
std::cout << "Factorio: event join " << e.player_name << "\n";
|
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};
|
std::string message{e.player_name};
|
||||||
message += " joined";
|
message += " joined";
|
||||||
|
|
||||||
@@ -83,6 +83,10 @@ bool Factorio::onEvent(const FactorioLog::Events::Join& e) {
|
|||||||
bool Factorio::onEvent(const FactorioLog::Events::Leave& e) {
|
bool Factorio::onEvent(const FactorioLog::Events::Leave& e) {
|
||||||
std::cout << "Factorio: event leave " << e.player_name << " " << e.reason << "\n";
|
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};
|
std::string message{e.player_name};
|
||||||
message += " left";
|
message += " left";
|
||||||
|
|
||||||
@@ -94,6 +98,16 @@ bool Factorio::onEvent(const FactorioLog::Events::Leave& e) {
|
|||||||
bool Factorio::onEvent(const FactorioLog::Events::Chat& e) {
|
bool Factorio::onEvent(const FactorioLog::Events::Chat& e) {
|
||||||
std::cout << "Factorio: event chat " << e.player_name << ": " << e.message << "\n";
|
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) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::string message{"<"};
|
std::string message{"<"};
|
||||||
message += e.player_name;
|
message += e.player_name;
|
||||||
message += ">: ";
|
message += ">: ";
|
||||||
@@ -107,6 +121,10 @@ bool Factorio::onEvent(const FactorioLog::Events::Chat& e) {
|
|||||||
bool Factorio::onEvent(const FactorioLog::Events::Died& e) {
|
bool Factorio::onEvent(const FactorioLog::Events::Died& e) {
|
||||||
std::cout << "Factorio: event died " << e.player_name << ": " << e.reason << "\n";
|
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};
|
std::string message{e.player_name};
|
||||||
message += " died from ";
|
message += " died from ";
|
||||||
message += e.reason;
|
message += e.reason;
|
||||||
@@ -118,17 +136,31 @@ bool Factorio::onEvent(const FactorioLog::Events::Died& e) {
|
|||||||
|
|
||||||
bool Factorio::onEvent(const FactorioLog::Events::Evolution& e) {
|
bool Factorio::onEvent(const FactorioLog::Events::Evolution& e) {
|
||||||
std::cout << "Factorio: event evolution " << e.evo << "\n";
|
std::cout << "Factorio: event evolution " << e.evo << "\n";
|
||||||
|
|
||||||
|
//if (!_conf.get_bool("Factorio", "forward", "evolution").value_or(true)) {
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Factorio::onEvent(const FactorioLog::Events::ResearchStarted& e) {
|
bool Factorio::onEvent(const FactorioLog::Events::ResearchStarted& e) {
|
||||||
std::cout << "Factorio: event research started " << e.name << "\n";
|
std::cout << "Factorio: event research started " << e.name << "\n";
|
||||||
|
|
||||||
|
//if (!_conf.get_bool("Factorio", "forward", "research_started").value_or(true)) {
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Factorio::onEvent(const FactorioLog::Events::ResearchFinished& e) {
|
bool Factorio::onEvent(const FactorioLog::Events::ResearchFinished& e) {
|
||||||
std::cout << "Factorio: event research finished " << e.name << "\n";
|
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 "};
|
std::string message{"Research "};
|
||||||
message += e.name;
|
message += e.name;
|
||||||
message += " finished!";
|
message += " finished!";
|
||||||
@@ -140,6 +172,11 @@ bool Factorio::onEvent(const FactorioLog::Events::ResearchFinished& e) {
|
|||||||
|
|
||||||
bool Factorio::onEvent(const FactorioLog::Events::ResearchCancelled& e) {
|
bool Factorio::onEvent(const FactorioLog::Events::ResearchCancelled& e) {
|
||||||
std::cout << "Factorio: event research cancelled " << e.name << "\n";
|
std::cout << "Factorio: event research cancelled " << e.name << "\n";
|
||||||
|
|
||||||
|
//if (!_conf.get_bool("Factorio", "forward", "research_cancelled").value_or(true)) {
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <solanaceae/contact/fwd.hpp>
|
||||||
#include <solanaceae/message3/registry_message_model.hpp>
|
#include <solanaceae/message3/registry_message_model.hpp>
|
||||||
|
|
||||||
#include "./factorio_log_parser.hpp"
|
#include "./factorio_log_parser.hpp"
|
||||||
@@ -10,18 +11,19 @@
|
|||||||
struct ConfigModelI;
|
struct ConfigModelI;
|
||||||
|
|
||||||
class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEventI {
|
class Factorio : public RegistryMessageModelEventI, public FactorioLogParserEventI {
|
||||||
Contact3Registry& _cr;
|
ConfigModelI& _conf;
|
||||||
|
ContactStore4I& _cs;
|
||||||
RegistryMessageModelI& _rmm;
|
RegistryMessageModelI& _rmm;
|
||||||
RegistryMessageModelI::SubscriptionReference _rmm_sr;
|
RegistryMessageModelI::SubscriptionReference _rmm_sr;
|
||||||
FactorioLogParser& _flp;
|
FactorioLogParser& _flp;
|
||||||
FactorioLogParser::SubscriptionReference _flp_sr;
|
FactorioLogParser::SubscriptionReference _flp_sr;
|
||||||
|
|
||||||
std::vector<Contact3Handle> _linked_contacts;
|
std::vector<ContactHandle4> _linked_contacts;
|
||||||
|
|
||||||
void sendToLinked(const std::string& message);
|
void sendToLinked(const std::string& message);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Factorio(ConfigModelI& conf, Contact3Registry& cr, RegistryMessageModelI& rmm, FactorioLogParser& flp);
|
Factorio(ConfigModelI& conf, ContactStore4I& cs, RegistryMessageModelI& rmm, FactorioLogParser& flp);
|
||||||
virtual ~Factorio(void);
|
virtual ~Factorio(void);
|
||||||
|
|
||||||
protected: // rmm
|
protected: // rmm
|
||||||
|
|||||||
Reference in New Issue
Block a user