AmendHub

Download:

jcs

/

wallops

/

amendments

/

79

irc: Implement /mode and /umode


jcs made amendment 79 2 months ago
--- irc.c Tue Sep 10 09:16:30 2024 +++ irc.c Tue Sep 10 21:55:38 2024 @@ -706,6 +706,12 @@ irc_process_server(struct irc_connection *conn) case 266: /* server stats, unhelpful */ return true; + case 221: + /* user mode */ + chatter_printf(conn->chatter, conn, NULL, + "$B***$0 Mode for $B%s$0:$/ %s", + msg.arg[0], msg.arg[1]); + return true; case 307: /* WHOIS regnick */ chatter_printf(conn->chatter, conn, conn->current_whois, @@ -785,9 +791,10 @@ irc_process_server(struct irc_connection *conn) return true; case 333: /* TOPIC creator */ + user = irc_parse_user(msg.arg[2]); chatter_printf(conn->chatter, conn, msg.arg[1], "$B***$0 Topic set by $B%s$0", - msg.arg[1]); + user->nick); return true; case 338: case 378: @@ -861,6 +868,12 @@ irc_process_server(struct irc_connection *conn) "$B***$0 Cannot join $B%s$0$/: %s", msg.arg[1], msg.msg); return true; + case 502: + /* error */ + chatter_printf(conn->chatter, conn, NULL, + "$B***$0$/ %s", + msg.msg); + return true; case 671: /* WHOIS server */ chatter_printf(conn->chatter, conn, conn->current_whois, @@ -976,6 +989,18 @@ irc_process_input(struct irc_connection *conn, struct channel ? channel->name : query_nick, str); return; } + if (strcasecmp(arg0, "mode") == 0) { + if (conn == NULL) + goto not_connected; + if (channel) { + if (str) + irc_printf(conn, "MODE %s %s\r\n", channel->name, str); + else + irc_printf(conn, "MODE %s\r\n", channel->name); + } else + goto not_in_channel; + return; + } if (strcasecmp(arg0, "msg") == 0) { if (conn == NULL) goto not_connected; @@ -1045,6 +1070,15 @@ irc_process_input(struct irc_connection *conn, struct goto not_in_channel; return; } + if (strcasecmp(arg0, "umode") == 0) { + if (conn == NULL) + goto not_connected; + if (str) + irc_printf(conn, "MODE %s %s\r\n", conn->nick, str); + else + irc_printf(conn, "MODE %s\r\n", conn->nick); + return; + } if (strcasecmp(arg0, "who") == 0) { if (conn == NULL) goto not_connected; @@ -1124,7 +1158,8 @@ irc_quit_with_message(struct irc_connection *conn, cha void irc_part_channel(struct irc_connection *conn, struct irc_channel *channel) { - irc_printf(conn, "PART %s\r\n", channel->name); + if (conn->state >= IRC_STATE_CONNECTED) + irc_printf(conn, "PART %s\r\n", channel->name); } void