hirc

IRC client
Log | Files | Refs

commit 2bbdf4b42b239e9d6715d09c2fecb59bc067efd7
parent c37ff485ddaa74c995413e81ef3acbfc3e65109e
Author: hhvn <dev@hhvn.uk>
Date:   Mon, 15 Nov 2021 19:32:10 +0000

commands.c handle.c hirc.h struct.h: /names command

Diffstat:
Mcommands.c | 23+++++++++++++++++++++++
Mhandle.c | 33++++++++++++++++++++++++++++++---
Mhirc.h | 2++
Mstruct.h | 1+
4 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/commands.c b/commands.c @@ -49,6 +49,9 @@ struct Command commands[] = { {"server", command_server, { "usage: /server <server> cmd....", "Run (non-raw) command with server as target.", NULL}}, + {"names", command_names, { + "usage: /names <channel>", + "List nicks in channel (pretty useless with nicklist.", NULL}}, {"help", command_help, { "usage: /help [command or variable]", "Print help information.", @@ -313,6 +316,26 @@ command_server(struct Server *server, char *str) { } void +command_names(struct Server *server, char *str) { + char *channel, *save = NULL; + + channel = strtok_r(str, " ", &save); + if (!channel) + channel = selected.channel ? selected.channel->name : NULL; + + if (!channel) { + ui_error("no channel selected or specified", NULL); + return; + } + + if (save && *save) + ui_error("ignoring extra argument", NULL); + + ircprintf(server, "NAMES %s\r\n", channel); + handle_expect(server, Expect_names, channel); +} + +void command_help(struct Server *server, char *str) { int cmdonly = 0; int i, j; diff --git a/handle.c b/handle.c @@ -18,7 +18,7 @@ struct Handler handlers[] = { { "001", handle_WELCOME }, { "005", handle_ISUPPORT }, { "353", handle_NAMREPLY }, - { "366", NULL /* end of names */ }, + { "366", handle_ENDOFNAMES }, { "376", handle_ENDOFMOTD }, { "433", handle_NICKNAMEINUSE }, { NULL, NULL }, @@ -224,6 +224,7 @@ void handle_NAMREPLY(char *msg, char **params, struct Server *server, time_t timestamp) { struct Channel *chan; struct Nick *oldnick; + char **bparams = params; char *nick, priv, *target; char **nicks, **nicksref; char *supportedprivs; @@ -235,12 +236,17 @@ handle_NAMREPLY(char *msg, char **params, struct Server *server, time_t timestam return; params += 3; - target = *params; + if ((chan = chan_get(&server->channels, target, -1)) == NULL) chan = chan_add(server, &server->channels, target); - params++; + if (strcmp_n(target, handle_expect_get(server, Expect_names)) == 0) + hist_add(chan->history, NULL, msg, bparams, Activity_status, timestamp, HIST_DFL); + else + hist_add(chan->history, NULL, msg, bparams, Activity_status, timestamp, HIST_LOG); + + params++; supportedprivs = strchr(support_get(server, "PREFIX"), ')'); if (supportedprivs == NULL || supportedprivs[0] == '\0') supportedprivs = ""; @@ -268,6 +274,22 @@ handle_NAMREPLY(char *msg, char **params, struct Server *server, time_t timestam } void +handle_ENDOFNAMES(char *msg, char **params, struct Server *server, time_t timestamp) { + char *target; + + hist_add(server->history, NULL, msg, params, Activity_status, timestamp, HIST_LOG); + if (params && *params && **params == ':') + params++; + + if (param_len(params) < 3) + return; + + target = *(params+2); + if (strcmp_n(target, handle_expect_get(server, Expect_names)) == 0) + handle_expect(server, Expect_names, NULL); +} + +void handle_NICKNAMEINUSE(char *msg, char **params, struct Server *server, time_t timestamp) { char nick[64]; /* should be limited to 9 chars, but newer servers *shrug*/ @@ -347,6 +369,11 @@ handle_expect_get(struct Server *server, enum Expect cmd) { } void +handle_logonly(char *msg, char **params, struct Server *server, time_t timestamp) { + hist_add(server->history, NULL, msg, params, Activity_status, timestamp, HIST_LOG); +} + +void handle(int rfd, struct Server *server) { time_t timestamp; char **params; diff --git a/hirc.h b/hirc.h @@ -96,6 +96,7 @@ void handle_PRIVMSG(char *msg, char **params, struct Server *server, time_t tim void handle_WELCOME(char *msg, char **params, struct Server *server, time_t timestamp); void handle_ISUPPORT(char *msg, char **params, struct Server *server, time_t timestamp); void handle_NAMREPLY(char *msg, char **params, struct Server *server, time_t timestamp); +void handle_ENDOFNAMES(char *msg, char **params, struct Server *server, time_t timestamp); void handle_ENDOFMOTD(char *msg, char **params, struct Server *server, time_t timestamp); void handle_NICKNAMEINUSE(char *msg, char **params, struct Server *server, time_t timestamp); void handle_NICK(char *msg, char **params, struct Server *server, time_t timestamp); @@ -143,6 +144,7 @@ void command_connect(struct Server *server, char *str); void command_select(struct Server *server, char *str); void command_set(struct Server *server, char *str); void command_server(struct Server *server, char *str); +void command_names(struct Server *server, char *str); void command_help(struct Server *server, char *str); /* config.c */ diff --git a/struct.h b/struct.h @@ -89,6 +89,7 @@ enum Expect { Expect_join, Expect_part, Expect_pong, + Expect_names, Expect_last, };