commit 7b772128d90fb94568267fbf994e2c056c403bc0
parent 270c09a56a4fbdb1117c45615ac7c71f84a86474
Author: hhvn <dev@hhvn.uk>
Date: Wed, 1 Dec 2021 16:38:38 +0000
commands.c config.c handle.c ui.c: KICK
Diffstat:
4 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/commands.c b/commands.c
@@ -11,6 +11,7 @@
static void command_quit(struct Server *server, char *str);
static void command_join(struct Server *server, char *str);
static void command_part(struct Server *server, char *str);
+static void command_kick(struct Server *server, char *str);
static void command_ping(struct Server *server, char *str);
static void command_quote(struct Server *server, char *str);
static void command_connect(struct Server *server, char *str);
@@ -43,6 +44,9 @@ struct Command commands[] = {
{"part", command_part, {
"usage: /part <channel>",
"Part channel", NULL}},
+ {"kick", command_kick, {
+ "usage: /kick [channel] <nick> [reason]",
+ "Kick nick from channel", NULL}},
{"ping", command_ping, {
"usage: /ping message...",
"Send a PING to server.",
@@ -133,6 +137,37 @@ command_part(struct Server *server, char *str) {
}
static void
+command_kick(struct Server *server, char *str) {
+ char *channel, *nick, *reason;
+ char *s;
+
+ if (!str) {
+ ui_error("/kick requires argument", NULL);
+ return;
+ }
+
+ s = strtok_r(str, " ", &reason);
+
+ if (s && strchr(support_get(server, "CHANTYPES"), *s)) {
+ channel = s;
+ nick = strtok_r(NULL, " ", &reason);
+ } else {
+ if (selected.channel == NULL) {
+ ui_error("no channel selected", NULL);
+ return;
+ }
+
+ channel = selected.channel->name;
+ nick = s;
+ }
+
+ if (reason)
+ ircprintf(server, "KICK %s %s :%s\r\n", channel, nick, reason);
+ else
+ ircprintf(server, "KICK %s %s\r\n", channel, nick);
+}
+
+static void
command_ping(struct Server *server, char *str) {
if (!str) {
ui_error("/ping requires argument", NULL);
diff --git a/config.c b/config.c
@@ -242,6 +242,11 @@ struct Config config[] = {
.strhandle = config_redraws,
.description = {
"Format of PART messages", NULL}},
+ {"format.kick", 1, Val_string,
+ .str = "%{b}%{c:40}!%{o}%{=}${2} by ${nick} (${ident}@${host}): ${3}",
+ .strhandle = config_redraws,
+ .description = {
+ "Format of PART messages", NULL}},
{"format.other", 1, Val_string,
.str = "${raw}",
.strhandle = config_redraws,
diff --git a/handle.c b/handle.c
@@ -10,6 +10,7 @@ static void handle_PING(char *msg, char **params, struct Server *server, time_t
static void handle_PONG(char *msg, char **params, struct Server *server, time_t timestamp);
static void handle_JOIN(char *msg, char **params, struct Server *server, time_t timestamp);
static void handle_PART(char *msg, char **params, struct Server *server, time_t timestamp);
+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_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp);
@@ -29,6 +30,7 @@ struct Handler handlers[] = {
{ "PONG", handle_PONG },
{ "JOIN", handle_JOIN },
{ "PART", handle_PART },
+ { "KICK", handle_KICK },
{ "QUIT", handle_QUIT },
{ "NICK", handle_NICK },
{ "TOPIC", handle_TOPIC },
@@ -144,6 +146,37 @@ handle_PART(char *msg, char **params, struct Server *server, time_t timestamp) {
}
static void
+handle_KICK(char *msg, char **params, struct Server *server, time_t timestamp) {
+ struct Channel *chan;
+ struct Nick *nick;
+ char *target;
+
+ if (**params != ':' || param_len(params) < 4)
+ return;
+
+ target = *(params+2);
+ if ((chan = chan_get(&server->channels, target, -1)) == NULL)
+ chan = chan_add(server, &server->channels, target);
+
+ nick = nick_create(*(params+3), ' ', server);
+ if (nick_isself(nick)) {
+ chan_setold(chan, 1);
+ nick_free_list(&chan->nicks);
+ if (chan == selected.channel)
+ ui_select(selected.server, NULL);
+ windows[Win_buflist].refresh = 1;
+ } else {
+ nick_remove(&chan->nicks, nick->nick);
+ if (chan == selected.channel)
+ windows[Win_nicklist].refresh = 1;
+ }
+
+ hist_add(server->history, NULL, msg, params, Activity_status, timestamp, HIST_LOG);
+ hist_add(chan->history, NULL, msg, params, Activity_status, timestamp, HIST_SHOW);
+ nick_free(nick);
+}
+
+static void
handle_QUIT(char *msg, char **params, struct Server *server, time_t timestamp) {
struct Channel *chan;
struct Nick *nick;
diff --git a/ui.c b/ui.c
@@ -59,6 +59,7 @@ struct {
{"PRIVMSG", "format.privmsg"},
{"JOIN", "format.join"},
{"PART", "format.part"},
+ {"KICK", "format.kick"},
{"QUIT", "format.quit"},
{NULL, NULL},
};