fix null deref and auto rejoin channels
This commit is contained in:
parent
3cb37e33a2
commit
ae817987c6
@ -63,9 +63,7 @@ SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) {
|
||||
}
|
||||
|
||||
SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) {
|
||||
g_ircc->iterate(delta); // TODO: return interval, respect dcc etc
|
||||
|
||||
return 1.f; // expect atleast once per sec
|
||||
return g_ircc->iterate(delta);
|
||||
}
|
||||
|
||||
} // extern C
|
||||
|
@ -109,6 +109,8 @@ float IRCClient1::iterate(float delta) {
|
||||
}
|
||||
} else {
|
||||
std::cerr << "IRCC error: not connected, trying to reconnect\n";
|
||||
|
||||
dispatch(IRCClient_Event::DISCONNECT, IRCClient::Events::Disconnect{});
|
||||
connectSession(); // potentially enters trying phase
|
||||
}
|
||||
return 0.5f;
|
||||
@ -167,6 +169,10 @@ const std::string_view IRCClient1::getServerName(void) const {
|
||||
return _server_name;
|
||||
}
|
||||
|
||||
void IRCClient1::join(std::string_view channel) {
|
||||
assert(false && "implement me");
|
||||
}
|
||||
|
||||
void IRCClient1::connectSession(void) {
|
||||
_try_connecting_state = true;
|
||||
_try_connecting_cooldown = 20.f;
|
||||
|
@ -110,6 +110,11 @@ namespace IRCClient::Events {
|
||||
std::vector<std::string_view> params;
|
||||
};
|
||||
|
||||
struct Disconnect {
|
||||
// TODO: reason
|
||||
// this is not a libircclient event (bad lib)
|
||||
};
|
||||
|
||||
} // Events
|
||||
|
||||
enum class IRCClient_Event : uint32_t {
|
||||
@ -135,6 +140,8 @@ enum class IRCClient_Event : uint32_t {
|
||||
|
||||
UNKNOWN,
|
||||
|
||||
DISCONNECT,
|
||||
|
||||
MAX
|
||||
};
|
||||
|
||||
@ -162,6 +169,7 @@ struct IRCClientEventI {
|
||||
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::Unknown&) { return false; }
|
||||
virtual bool onEvent(const IRCClient::Events::Disconnect&) { return false; }
|
||||
};
|
||||
|
||||
using IRCClientEventProviderI = EventProviderI<IRCClientEventI>;
|
||||
@ -207,12 +215,14 @@ class IRCClient1 : public IRCClientEventProviderI {
|
||||
|
||||
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) {
|
||||
assert(session != nullptr);
|
||||
|
||||
std::vector<std::string_view> params_view;
|
||||
for (size_t i = 0; i < count; 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 (std::string_view{event} == "ACTION") {
|
||||
@ -228,7 +238,8 @@ class IRCClient1 : public IRCClientEventProviderI {
|
||||
auto* ircc = static_cast<IRCClient1*>(irc_get_ctx(session));
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
@ -207,8 +207,26 @@ bool IRCClientContactModel::onEvent(const IRCClient::Events::Connect& e) {
|
||||
_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
|
||||
// TODO: merge with above
|
||||
while (!_join_queue.empty()) {
|
||||
// TODO: implement join lol
|
||||
irc_cmd_join(
|
||||
_ircc.getSession(),
|
||||
_join_queue.front().c_str(),
|
||||
|
Loading…
Reference in New Issue
Block a user