Compare commits

..

No commits in common. "344af9dc4b43f9efdbc25ef99ffb11ea8c4c7487" and "c5bf212ab98492779392518ea4bc8c958ee45e46" have entirely different histories.

4 changed files with 28 additions and 55 deletions

21
LICENSE
View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 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.

View File

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

View File

@ -3,7 +3,6 @@
#include <solanaceae/util/config_model.hpp> #include <solanaceae/util/config_model.hpp>
#include <solanaceae/util/utils.hpp> #include <solanaceae/util/utils.hpp>
#include <solanaceae/util/time.hpp> #include <solanaceae/util/time.hpp>
#include <solanaceae/contact/contact_store_i.hpp>
#include <solanaceae/contact/components.hpp> #include <solanaceae/contact/components.hpp>
#include <solanaceae/message3/components.hpp> #include <solanaceae/message3/components.hpp>
#include <solanaceae/message3/message_command_dispatcher.hpp> #include <solanaceae/message3/message_command_dispatcher.hpp>
@ -11,11 +10,11 @@
#include <iostream> #include <iostream>
Bridge::Bridge( Bridge::Bridge(
ContactStore4I& cs, Contact3Registry& cr,
RegistryMessageModelI& rmm, RegistryMessageModelI& rmm,
ConfigModelI& conf, ConfigModelI& conf,
MessageCommandDispatcher* mcd MessageCommandDispatcher* mcd
) : _cs(cs), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _conf(conf), _mcd(mcd) { ) : _cr(cr), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _conf(conf), _mcd(mcd) {
_rmm_sr.subscribe(RegistryMessageModel_Event::message_construct); _rmm_sr.subscribe(RegistryMessageModel_Event::message_construct);
if (!_conf.has_bool("Bridge", "username_angle_brackets")) { if (!_conf.has_bool("Bridge", "username_angle_brackets")) {
@ -39,8 +38,7 @@ Bridge::Bridge(
auto& v_group = _vgroups.at(tmp_name_to_id.at(tmp_vgroup_str)); auto& v_group = _vgroups.at(tmp_name_to_id.at(tmp_vgroup_str));
auto& new_vgc = v_group.contacts.emplace_back(); auto& new_vgc = v_group.contacts.emplace_back();
//new_vgc.c = {}; // TODO: does this work here? new_vgc.c = {_cr, entt::null}; // this is annoying af
new_vgc.c = _cs.contactHandle(entt::null);
new_vgc.id = hex2bin(contact_id); new_vgc.id = hex2bin(contact_id);
} }
@ -69,10 +67,10 @@ void Bridge::updateVGroups(void) {
if (!vgc.c.valid()) { if (!vgc.c.valid()) {
// search // search
auto view = _cs.registry().view<Contact::Components::TagBig, Contact::Components::ID>(); auto view = _cr.view<Contact::Components::TagBig, Contact::Components::ID>();
for (const auto c : view) { for (const auto c : view) {
if (view.get<Contact::Components::ID>(c).data == vgc.id) { if (view.get<Contact::Components::ID>(c).data == vgc.id) {
vgc.c = _cs.contactHandle(c); vgc.c = {_cr, c};
std::cout << "Bridge: found contact for vgroup\n"; std::cout << "Bridge: found contact for vgroup\n";
break; break;
} }
@ -98,7 +96,7 @@ void Bridge::registerCommands(void) {
const auto contact_from = m.get<Message::Components::ContactFrom>().c; const auto contact_from = m.get<Message::Components::ContactFrom>().c;
const auto contact_to = m.get<Message::Components::ContactTo>().c; const auto contact_to = m.get<Message::Components::ContactTo>().c;
ContactHandle4 group_contact; Contact3Handle group_contact;
const VirtualGroups* vg = nullptr; const VirtualGroups* vg = nullptr;
if (!params.empty()) { // vgroup_name supplied if (!params.empty()) { // vgroup_name supplied
@ -116,12 +114,12 @@ void Bridge::registerCommands(void) {
return true; return true;
} }
} else { } else {
if (/*is public ?*/ _c_to_vg.count(_cs.contactHandle(contact_to))) { if (/*is public ?*/ _c_to_vg.count({_cr, contact_to})) {
// message was sent public in group // message was sent public in group
group_contact = _cs.contactHandle(contact_to); group_contact = {_cr, contact_to};
} else if (_cs.registry().all_of<Contact::Components::Parent>(contact_from)) { } else if (_cr.all_of<Contact::Components::Parent>(contact_from)) {
// use parent of sender // use parent of sender
group_contact = _cs.contactHandle(_cs.registry().get<Contact::Components::Parent>(contact_from).parent); group_contact = {_cr, _cr.get<Contact::Components::Parent>(contact_from).parent};
} else if (false /* parent of contact_to ? */) { } else if (false /* parent of contact_to ? */) {
} }
@ -158,12 +156,10 @@ void Bridge::registerCommands(void) {
"' id:" + bin2hex(vgc.id) "' id:" + bin2hex(vgc.id)
); );
const auto& cr = _cs.registry();
// for each sub contact // for each sub contact
for (const auto& sub_c : vgc.c.get<Contact::Components::ParentOf>().subs) { for (const auto& sub_c : vgc.c.get<Contact::Components::ParentOf>().subs) {
if ( if (
const auto* sub_cs = cr.try_get<Contact::Components::ConnectionState>(sub_c); const auto* sub_cs = _cr.try_get<Contact::Components::ConnectionState>(sub_c);
sub_cs != nullptr && sub_cs->state == Contact::Components::ConnectionState::disconnected sub_cs != nullptr && sub_cs->state == Contact::Components::ConnectionState::disconnected
) { ) {
// skip offline // skip offline
@ -173,9 +169,9 @@ void Bridge::registerCommands(void) {
_rmm.sendText( _rmm.sendText(
contact_from, contact_from,
" '" + " '" +
(cr.all_of<Contact::Components::Name>(sub_c) ? cr.get<Contact::Components::Name>(sub_c).name : "<unk>") + (_cr.all_of<Contact::Components::Name>(sub_c) ? _cr.get<Contact::Components::Name>(sub_c).name : "<unk>") +
"'" + "'" +
(cr.all_of<Contact::Components::ID>(sub_c) ? " id:" + bin2hex(cr.get<Contact::Components::ID>(sub_c).data) : "") (_cr.all_of<Contact::Components::ID>(sub_c) ? " id:" + bin2hex(_cr.get<Contact::Components::ID>(sub_c).data) : "")
); );
} }
@ -197,7 +193,7 @@ void Bridge::registerCommands(void) {
std::cout << "Bridge: registered commands\n"; std::cout << "Bridge: registered commands\n";
} }
const Bridge::VirtualGroups* Bridge::findVGforContact(const ContactHandle4& c) { const Bridge::VirtualGroups* Bridge::findVGforContact(const Contact3Handle& c) {
return nullptr; return nullptr;
} }
@ -221,16 +217,14 @@ bool Bridge::onEvent(const Message::Events::MessageConstruct& e) {
} }
} }
const auto& cr = _cs.registry();
const auto contact_from = e.e.get<Message::Components::ContactFrom>().c; const auto contact_from = e.e.get<Message::Components::ContactFrom>().c;
if (cr.any_of<Contact::Components::TagSelfStrong, Contact::Components::TagSelfWeak>(contact_from)) { if (_cr.any_of<Contact::Components::TagSelfStrong, Contact::Components::TagSelfWeak>(contact_from)) {
return false; // skip own messages return false; // skip own messages
} }
const auto contact_to = e.e.get<Message::Components::ContactTo>().c; const auto contact_to = e.e.get<Message::Components::ContactTo>().c;
// if e.e <contact to> is in c to vg // if e.e <contact to> is in c to vg
const auto it = _c_to_vg.find(_cs.contactHandle(contact_to)); const auto it = _c_to_vg.find(Contact3Handle{_cr, contact_to});
if (it == _c_to_vg.cend()) { if (it == _c_to_vg.cend()) {
return false; // contact is not bridged return false; // contact is not bridged
} }
@ -245,8 +239,8 @@ bool Bridge::onEvent(const Message::Events::MessageConstruct& e) {
from_str += "<"; from_str += "<";
} }
if (cr.all_of<Contact::Components::Name>(contact_from)) { if (_cr.all_of<Contact::Components::Name>(contact_from)) {
const auto& name = cr.get<Contact::Components::Name>(contact_from).name; const auto& name = _cr.get<Contact::Components::Name>(contact_from).name;
if (name.empty()) { if (name.empty()) {
from_str += "UNK"; from_str += "UNK";
} else { } else {
@ -255,9 +249,9 @@ bool Bridge::onEvent(const Message::Events::MessageConstruct& e) {
} }
if (_conf.get_bool("Bridge", "username_id", vgroup.vg_name).value()) { if (_conf.get_bool("Bridge", "username_id", vgroup.vg_name).value()) {
if (cr.all_of<Contact::Components::ID>(contact_from)) { if (_cr.all_of<Contact::Components::ID>(contact_from)) {
// copy // copy
auto id = cr.get<Contact::Components::ID>(contact_from).data; auto id = _cr.get<Contact::Components::ID>(contact_from).data;
id.resize(3); // TODO:make size configurable id.resize(3); // TODO:make size configurable
// TODO: make seperator configurable // TODO: make seperator configurable

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <solanaceae/contact/fwd.hpp> #include <solanaceae/contact/contact_model3.hpp>
#include <solanaceae/message3/registry_message_model.hpp> #include <solanaceae/message3/registry_message_model.hpp>
#include <vector> #include <vector>
@ -13,7 +13,7 @@ struct ConfigModelI;
class MessageCommandDispatcher; class MessageCommandDispatcher;
class Bridge : public RegistryMessageModelEventI { class Bridge : public RegistryMessageModelEventI {
ContactStore4I& _cs; Contact3Registry& _cr;
RegistryMessageModelI& _rmm; RegistryMessageModelI& _rmm;
RegistryMessageModelI::SubscriptionReference _rmm_sr; RegistryMessageModelI::SubscriptionReference _rmm_sr;
ConfigModelI& _conf; ConfigModelI& _conf;
@ -21,7 +21,7 @@ class Bridge : public RegistryMessageModelEventI {
struct VirtualGroups { struct VirtualGroups {
struct VContact { struct VContact {
ContactHandle4 c; // might be null Contact3Handle c; // might be null
std::vector<uint8_t> id; // if contact appears, we check std::vector<uint8_t> id; // if contact appears, we check
}; };
std::vector<VContact> contacts; std::vector<VContact> contacts;
@ -30,7 +30,7 @@ class Bridge : public RegistryMessageModelEventI {
// TODO: cache settings here? // TODO: cache settings here?
}; };
std::vector<VirtualGroups> _vgroups; std::vector<VirtualGroups> _vgroups;
std::map<ContactHandle4, size_t> _c_to_vg; std::map<Contact3Handle, size_t> _c_to_vg;
float _iterate_timer {0.f}; float _iterate_timer {0.f};
@ -38,7 +38,7 @@ class Bridge : public RegistryMessageModelEventI {
static constexpr const char* version {"1"}; static constexpr const char* version {"1"};
Bridge( Bridge(
ContactStore4I& cs, Contact3Registry& cr,
RegistryMessageModelI& rmm, RegistryMessageModelI& rmm,
ConfigModelI& conf, ConfigModelI& conf,
MessageCommandDispatcher* mcd = nullptr MessageCommandDispatcher* mcd = nullptr
@ -50,7 +50,7 @@ class Bridge : public RegistryMessageModelEventI {
private: private:
void updateVGroups(void); void updateVGroups(void);
void registerCommands(void); void registerCommands(void);
const VirtualGroups* findVGforContact(const ContactHandle4& c); const VirtualGroups* findVGforContact(const Contact3Handle& c);
protected: // mm protected: // mm
bool onEvent(const Message::Events::MessageConstruct& e) override; bool onEvent(const Message::Events::MessageConstruct& e) override;