summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-08-01 00:29:17 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-08-01 00:29:17 +0200
commita4e18d306ed1f21a8b40edbea982684dea6039de (patch)
tree7d020e8ed723e7e769f82ef548a65bb432900c32 /src
parent2b90aa097ee5049e9f40262476de078dfe02f45f (diff)
downloadxK-a4e18d306ed1f21a8b40edbea982684dea6039de.tar.gz
xK-a4e18d306ed1f21a8b40edbea982684dea6039de.tar.xz
xK-a4e18d306ed1f21a8b40edbea982684dea6039de.zip
Fix plugin autoload
I was trying to be too smart about holding up IRC messages coming from plugins while the bot is disconnected.
Diffstat (limited to 'src')
-rw-r--r--src/zyklonb.c18
1 files 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