From a4e18d306ed1f21a8b40edbea982684dea6039de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Fri, 1 Aug 2014 00:29:17 +0200 Subject: [PATCH] Fix plugin autoload I was trying to be too smart about holding up IRC messages coming from plugins while the bot is disconnected. --- src/zyklonb.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/zyklonb.c b/src/zyklonb.c index 919bf1d..9874961 100644 --- a/src/zyklonb.c +++ b/src/zyklonb.c @@ -810,9 +810,19 @@ plugin_process_message (const struct irc_message *msg, printf ("%s\n", msg->params.vector[1]); } } - else if (plugin->initialized) + else if (plugin->initialized && ctx->irc_ready) { // Pass everything else through to the IRC server + // XXX: when the server isn't ready yet, these messages get silently + // discarded, which shouldn't pose a problem most of the time. + // Perhaps we could send a "connected" notification on `register' + // if `irc_ready' is true, or after it becomes true later, so that + // plugins know when to start sending unprovoked IRC messages. + // XXX: another case is when the connection gets interrupted and the + // plugin tries to send something back while we're reconnecting. + // For that we might set up a global buffer that gets flushed out + // after `irc_ready' becomes true. Note that there is always some + // chance of messages getting lost without us even noticing it. irc_send (ctx, "%s", raw); } } @@ -872,10 +882,7 @@ on_plugin_readable (const struct pollfd *fd, struct plugin_data *plugin) } } - // Hold it in the buffer while we're disconnected - struct bot_context *ctx = plugin->ctx; - if (ctx->irc_fd != -1 && ctx->irc_ready) - irc_process_buffer (buf, plugin_process_message, plugin); + irc_process_buffer (buf, plugin_process_message, plugin); } static bool @@ -1434,6 +1441,7 @@ on_irc_disconnected (struct bot_context *ctx) xclose (ctx->irc_fd); ctx->irc_fd = -1; + ctx->irc_ready = false; // TODO: inform plugins about the disconnect event