fix null deref and auto rejoin channels

This commit is contained in:
Green Sky 2024-06-18 17:43:08 +02:00
parent 3cb37e33a2
commit ae817987c6
No known key found for this signature in database
4 changed files with 38 additions and 5 deletions

View File

@ -63,9 +63,7 @@ SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) {
} }
SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) { SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) {
g_ircc->iterate(delta); // TODO: return interval, respect dcc etc return g_ircc->iterate(delta);
return 1.f; // expect atleast once per sec
} }
} // extern C } // extern C

View File

@ -109,6 +109,8 @@ float IRCClient1::iterate(float delta) {
} }
} else { } else {
std::cerr << "IRCC error: not connected, trying to reconnect\n"; std::cerr << "IRCC error: not connected, trying to reconnect\n";
dispatch(IRCClient_Event::DISCONNECT, IRCClient::Events::Disconnect{});
connectSession(); // potentially enters trying phase connectSession(); // potentially enters trying phase
} }
return 0.5f; return 0.5f;
@ -167,6 +169,10 @@ const std::string_view IRCClient1::getServerName(void) const {
return _server_name; return _server_name;
} }
void IRCClient1::join(std::string_view channel) {
assert(false && "implement me");
}
void IRCClient1::connectSession(void) { void IRCClient1::connectSession(void) {
_try_connecting_state = true; _try_connecting_state = true;
_try_connecting_cooldown = 20.f; _try_connecting_cooldown = 20.f;

View File

@ -110,6 +110,11 @@ namespace IRCClient::Events {
std::vector<std::string_view> params; std::vector<std::string_view> params;
}; };
struct Disconnect {
// TODO: reason
// this is not a libircclient event (bad lib)
};
} // Events } // Events
enum class IRCClient_Event : uint32_t { enum class IRCClient_Event : uint32_t {
@ -135,6 +140,8 @@ enum class IRCClient_Event : uint32_t {
UNKNOWN, UNKNOWN,
DISCONNECT,
MAX MAX
}; };
@ -162,6 +169,7 @@ struct IRCClientEventI {
virtual bool onEvent(const IRCClient::Events::CTCP_Rep&) { return false; } virtual bool onEvent(const IRCClient::Events::CTCP_Rep&) { return false; }
virtual bool onEvent(const IRCClient::Events::CTCP_Action&) { return false; } virtual bool onEvent(const IRCClient::Events::CTCP_Action&) { return false; }
virtual bool onEvent(const IRCClient::Events::Unknown&) { return false; } virtual bool onEvent(const IRCClient::Events::Unknown&) { return false; }
virtual bool onEvent(const IRCClient::Events::Disconnect&) { return false; }
}; };
using IRCClientEventProviderI = EventProviderI<IRCClientEventI>; using IRCClientEventProviderI = EventProviderI<IRCClientEventI>;
@ -207,12 +215,14 @@ class IRCClient1 : public IRCClientEventProviderI {
template<IRCClient_Event event_type_enum, typename EventType> template<IRCClient_Event event_type_enum, typename EventType>
static void on_event_generic_new(irc_session_t* session, const char* event, const char* origin, const char** params, unsigned int count) { static void on_event_generic_new(irc_session_t* session, const char* event, const char* origin, const char** params, unsigned int count) {
assert(session != nullptr);
std::vector<std::string_view> params_view; std::vector<std::string_view> params_view;
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
params_view.push_back(params[i]); params_view.push_back(params[i]);
} }
std::cout << "IRC: event " << event << " " << origin << "\n"; std::cout << "IRC: event '" << (event?event:"<nullptr>") << "' o:" << (origin?origin:"<nullptr>") << "\n";
#if 0 #if 0
if (std::string_view{event} == "ACTION") { if (std::string_view{event} == "ACTION") {
@ -228,7 +238,8 @@ class IRCClient1 : public IRCClientEventProviderI {
auto* ircc = static_cast<IRCClient1*>(irc_get_ctx(session)); auto* ircc = static_cast<IRCClient1*>(irc_get_ctx(session));
assert(ircc != nullptr); assert(ircc != nullptr);
ircc->dispatch(event_type_enum, EventType{origin, params_view}); // hack if origin is null
ircc->dispatch(event_type_enum, EventType{origin?origin:"<nullptr>", params_view});
ircc->_event_fired = true; ircc->_event_fired = true;
} }
}; };

View File

@ -207,8 +207,26 @@ bool IRCClientContactModel::onEvent(const IRCClient::Events::Connect& e) {
_cr.emplace_or_replace<Contact::Components::Self>(_server, _self); _cr.emplace_or_replace<Contact::Components::Self>(_server, _self);
} }
// check for preexisting channels,
// since this might be a reconnect
// and reissue joins
_cr.view<Contact::Components::IRC::ServerName, Contact::Components::IRC::ChannelName>().each([this](const auto c, const auto& sn_c, const auto& cn_c) {
if (sn_c.name != _ircc.getServerName()) {
return;
}
// TODO: implement join lol
irc_cmd_join(
_ircc.getSession(),
cn_c.name.c_str(),
""
);
});
// join queued // join queued
// TODO: merge with above
while (!_join_queue.empty()) { while (!_join_queue.empty()) {
// TODO: implement join lol
irc_cmd_join( irc_cmd_join(
_ircc.getSession(), _ircc.getSession(),
_join_queue.front().c_str(), _join_queue.front().c_str(),