hirc

IRC client
Log | Files | Refs

commit 9245cc5b6d102f0b92c3edb8af3778b9330b454d
parent 1c9df161195d77311909582b44edb5f6701ab34a
Author: hhvn <dev@hhvn.uk>
Date:   Wed,  1 Dec 2021 22:31:43 +0000

config.c handle.c ui.c: modes

Diffstat:
Mconfig.c | 15+++++++++++++++
Mhandle.c | 38++++++++++++++++++++++++++++++++++++++
Mui.c | 31+++++++++++++++++++++++++++----
3 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/config.c b/config.c @@ -247,6 +247,21 @@ struct Config config[] = { .strhandle = config_redraws, .description = { "Format of PART messages", NULL}}, + {"format.mode.nick.self", 1, Val_string, + .str = "${1} set %{c:94}${2-}%{o}", + .strhandle = config_redraws, + .description = { + "Format of modes being set on self by server/self", NULL}}, + {"format.mode.nick", 1, Val_string, + .str = "${1} set %{c:94}${2-}%{o} by ${nick} (${ident}@${host})", + .strhandle = config_redraws, + .description = { + "Format of modes being on nicks", NULL}}, + {"format.mode.channel", 1, Val_string, + .str = "mode%{=}%{c:94}${2-}%{o} by ${nick}", + .strhandle = config_redraws, + .description = { + "Format of modes being set on channels", NULL}}, {"format.other", 1, Val_string, .str = "${raw}", .strhandle = config_redraws, diff --git a/handle.c b/handle.c @@ -13,10 +13,12 @@ static void handle_PART(char *msg, char **params, struct Server *server, time_t static void handle_KICK(char *msg, char **params, struct Server *server, time_t timestamp); static void handle_QUIT(char *msg, char **params, struct Server *server, time_t timestamp); static void handle_NICK(char *msg, char **params, struct Server *server, time_t timestamp); +static void handle_MODE(char *msg, char **params, struct Server *server, time_t timestamp); static void handle_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp); static void handle_PRIVMSG(char *msg, char **params, struct Server *server, time_t timestamp); static void handle_RPL_WELCOME(char *msg, char **params, struct Server *server, time_t timestamp); static void handle_RPL_ISUPPORT(char *msg, char **params, struct Server *server, time_t timestamp); +static void handle_RPL_CHANNELMODEIS(char *msg, char **params, struct Server *server, time_t timestamp); static void handle_RPL_NOTOPIC(char *msg, char **params, struct Server *server, time_t timestamp); static void handle_RPL_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp); static void handle_RPL_TOPICWHOTIME(char *msg, char **params, struct Server *server, time_t timestamp); @@ -33,11 +35,13 @@ struct Handler handlers[] = { { "KICK", handle_KICK }, { "QUIT", handle_QUIT }, { "NICK", handle_NICK }, + { "MODE", handle_MODE }, { "TOPIC", handle_TOPIC }, { "PRIVMSG", handle_PRIVMSG }, { "NOTICE", handle_PRIVMSG }, { "001", handle_RPL_WELCOME }, { "005", handle_RPL_ISUPPORT }, + { "324", handle_RPL_CHANNELMODEIS }, { "331", handle_RPL_NOTOPIC }, { "332", handle_RPL_TOPIC }, { "333", handle_RPL_TOPICWHOTIME }, @@ -204,6 +208,26 @@ handle_QUIT(char *msg, char **params, struct Server *server, time_t timestamp) { } static void +handle_MODE(char *msg, char **params, struct Server *server, time_t timestamp) { + struct Channel *chan; + + if (**params != ':' || param_len(params) < 4) + return; + + if (strchr(support_get(server, "CHANTYPES"), **(params+2))) { + if ((chan = chan_get(&server->channels, *(params+2), -1)) == NULL) + chan = chan_add(server, &server->channels, *(params+2)); + + hist_add(chan->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL); + ircprintf(server, "MODE %s\r\n", chan->name); /* Get full mode via RPL_CHANNELMODEIS + * instead of concatenating manually */ + ircprintf(server, "NAMES %s\r\n", chan->name); /* Also get updated priviledges */ + } else { + hist_add(server->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL); + } +} + +static void handle_PRIVMSG(char *msg, char **params, struct Server *server, time_t timestamp) { int act_direct = Activity_hilight, act_regular = Activity_message; struct Channel *chan; @@ -276,6 +300,20 @@ handle_RPL_ISUPPORT(char *msg, char **params, struct Server *server, time_t time } static void +handle_RPL_CHANNELMODEIS(char *msg, char **params, struct Server *server, time_t timestamp) { + struct Channel *chan; + + if (**params != ':' && param_len(params) < 5) + return; + + if ((chan = chan_get(&server->channels, *(params+3), -1)) == NULL) + chan = chan_add(server, &server->channels, *(params+3)); + + free(chan->mode); + chan->mode = strdup(*(params+4)); +} + +static void handle_RPL_NAMREPLY(char *msg, char **params, struct Server *server, time_t timestamp) { struct Channel *chan; struct Nick *oldnick; diff --git a/ui.c b/ui.c @@ -46,6 +46,7 @@ struct { char *cmd; char *format; } formatmap[] = { + /* SELF_ commands from UI */ {"SELF_ERROR", "format.ui.error"}, {"SELF_UI", "format.ui.misc"}, {"SELF_CONNECTLOST", "format.ui.connectlost"}, @@ -56,12 +57,17 @@ struct { #ifndef TLS {"SELF_TLSNOTCOMPILED", "format.ui.tlsnotcompiled"}, #endif /* TLS */ + /* Real commands from server */ {"PRIVMSG", "format.privmsg"}, {"JOIN", "format.join"}, {"PART", "format.part"}, {"KICK", "format.kick"}, {"QUIT", "format.quit"}, - {NULL, NULL}, + /* Pseudo commands for specific formatting */ + {"MODE-NICK-SELF", "format.mode.nick.self"}, + {"MODE-NICK", "format.mode.nick"}, + {"MODE-CHANNEL", "format.mode.channel"}, + {NULL, NULL}, }; struct { @@ -713,7 +719,7 @@ ui_wclear(struct Window *window) { int ui_hist_print(struct Window *window, int lines, struct History *hist) { - char *cmd; + char *cmd, *p1, *chantypes; int i; if (!hist) @@ -722,10 +728,27 @@ ui_hist_print(struct Window *window, int lines, struct History *hist) { if (!hist->params || !*(hist->params+1)) goto raw; - if (**(hist->params) == ':') + if (**(hist->params) == ':') { cmd = *(hist->params+1); - else + p1 = *(hist->params+2); + } else { cmd = *(hist->params); + p1 = *(hist->params+1); + } + + if (strcmp_n(cmd, "MODE") == 0) { + if (hist->origin && hist->origin->server) + chantypes = support_get(hist->origin->server, "CHANTYPES"); + else + chantypes = config_gets("def.chantypes"); + + if (p1 && strchr(chantypes, *p1)) + cmd = "MODE-CHANNEL"; + else if (hist->from && nick_isself(hist->from) && strcmp_n(hist->from->nick, p1) == 0) + cmd = "MODE-NICK-SELF"; + else + cmd = "MODE-NICK"; + } for (i=0; formatmap[i].cmd; i++) if (formatmap[i].format && strcmp_n(formatmap[i].cmd, cmd) == 0)