commit f6210bc9a3c5bab22f0aa89a30a57197b3f14956
parent 3a6cf63b47498d59f2c763ec162e655e3f5dafbe
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Sat, 16 Jun 2012 14:17:48 +0200
handle channel passwords
Diffstat:
irctk.c | | | 32 | ++++++++++++++++++++++++++++---- |
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/irctk.c b/irctk.c
@@ -437,6 +437,25 @@ char* first_chan()
else return args.nick;
}
+int join_channel(irc_session_t *s, char* chan) {
+ char *password = chan;
+ int pos = strlen(password);
+ int ret;
+ // find the password if the password indicates a chan (last ':')
+ while (pos >= 0 && password[pos] != ':')
+ pos--;
+ if (pos) {
+ password += pos + 1;
+ chan[pos] = 0;
+ } else {
+ password = NULL;
+ }
+ ret = irc_cmd_join (s, chan, password);
+ if (pos)
+ chan[pos] = ':';
+ return ret;
+}
+
int do_cmd_msg(irc_session_t *s, const char* chan, const char* line)
{
int rsl = -1;
@@ -445,7 +464,7 @@ int do_cmd_msg(irc_session_t *s, const char* chan, const char* line)
/* TODO2 find a way to get real host name (part after !) */
/* TODO2 only join channels we haven't joined yet */
- irc_cmd_join (s, chan, 0);
+ join_channel (s, chan);
// TODO also other commands (/kick, /topic...)
@@ -465,10 +484,10 @@ int do_cmd_msg(irc_session_t *s, const char* chan, const char* line)
if (!line[5] || line[5] == '\n')
{
debug("join %s", chan);
- rsl = irc_cmd_join(s, chan, NULL);
+ rsl = join_channel(s, chan);
} else if (line[5] == ' ') {
debug("join %s", line+6);
- rsl = irc_cmd_join(s, line + 6, NULL);
+ rsl = join_channel(s, line + 6);
}
} else if (strstr (line + 1, "topic ") == line + 1) {
debug("topic %s", line+6);
@@ -614,6 +633,11 @@ void dump_event (irc_session_t * session, const char * event, const char * origi
// TODO abort
die(E_BADNAME, "Nickname already in use!");
}
+ } else if (atoi(event) == LIBIRC_RFC_ERR_BADCHANNELKEY) {
+ // TODO report name of channel last joined, die if it was specified on cli
+ info("Cannot join channel: bad password.");
+ } else if (atoi(event) == LIBIRC_RFC_ERR_INVITEONLYCHAN) {
+ info("Cannot join channel: channel is invite-only.");
}
debug("Event \"%s\", origin: \"%s\", params: %d", event, origin ? origin : "NULL", cnt);
@@ -698,7 +722,7 @@ void event_connect (irc_session_t * session, const char * event, const char * or
for (i = 0; i < ctx->n_channels; i++)
{
debug("Attempt to join %s", ctx->channels[i]);
- irc_cmd_join (session, ctx->channels[i], 0);
+ join_channel (session, ctx->channels[i]);
}
}