commit 207701cb6042c3ee20bc5b69119a4483932d6e1c
parent dd35f0d9285731bee01ebbf610824fab0f468b6a
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Sat, 21 Feb 2015 12:31:22 +0100
support OPER
Diffstat:
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/README b/README
@@ -254,6 +254,7 @@ The supported commands are:
/kick USER [REASON] (kick user from current inferred destination)
/me MSG (/me message)
/notice MSG (say as a notice)
+ /oper USER [PASS] (obtain operator privileges)
/say MSG (escape)
/ MSG (escape)
/notice MSG (like /say but use NOTICE)
diff --git a/irctk.c b/irctk.c
@@ -1101,9 +1101,15 @@ void revert_password(char *chan, int pos) {
}
+int my_irc_cmd_oper(irc_session_t *s, char *user, char *pass)
+{
+ return irc_send_raw(s, "OPER %s %s\n", user, pass);
+}
+
+
/* Send a message or do a command */
/* Return value is 0 if OK, >0 if error, -1 if correctly exited */
-int do_cmd_msg(irc_session_t *s, char *chan, char* line)
+int do_cmd_msg(irc_session_t *s, char *chan, char *line)
{
int rsl = 0;
int pw_pos = get_password(chan);
@@ -1174,6 +1180,14 @@ int do_cmd_msg(irc_session_t *s, char *chan, char* line)
rsl = irc_cmd_invite(s, inick, chan);
}
free(inick);
+ } else if ((arg = MATCH_CMD(line, "oper"))) {
+ char *ouser = consume_word(&arg);
+ if (!IS_END(*arg)) {
+ rsl = my_irc_cmd_oper(s, ouser, arg);
+ } else {
+ rsl = my_irc_cmd_oper(s, ouser, "");
+ }
+ free(ouser);
} else if ((arg = MATCH_CMD(line, "kick"))) {
char *knick = consume_word(&arg);
rsl = irc_cmd_kick(s, knick, chan, arg);
@@ -1415,7 +1429,14 @@ void manage_event (irc_session_t *session, const char *event, const char *origin
}
}
} else if (atoi(event) == LIBIRC_RFC_ERR_PASSWDMISMATCH) {
- die(E_PASSWORD, "Invalid or missing password when connecting to server.\n");
+ irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx (session);
+ if (ctx->ready) {
+ // this could be about a wrong password for /oper, so make it non-fatal
+ info("Invalid or missing password.\n");
+ } else {
+ // assuming this is about trying to connect to the server
+ die(E_PASSWORD, "Invalid or missing password when connecting to server.\n");
+ }
} else if (atoi(event) == LIBIRC_RFC_ERR_BADCHANNELKEY) {
info("Cannot join %s: bad password.\n", params[1]);
} else if (atoi(event) == LIBIRC_RFC_ERR_NOSUCHCHANNEL) {