commit 0888cb898fe7ac7e9b98d05be6f952a503716bd1
parent f310b0e9f6891999f596e92a96ee1770773ed943
Author: hhvn <dev@hhvn.uk>
Date: Wed, 17 Nov 2021 17:33:45 +0000
handle.c hirc.h: handle TOPIC and RPL_NOTOPIC
Diffstat:
2 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/handle.c b/handle.c
@@ -13,10 +13,12 @@ struct Handler handlers[] = {
{ "PART", handle_PART },
{ "QUIT", handle_QUIT },
{ "NICK", handle_NICK },
+ { "TOPIC", handle_TOPIC },
{ "PRIVMSG", handle_PRIVMSG },
{ "NOTICE", handle_PRIVMSG },
{ "001", handle_RPL_WELCOME },
{ "005", handle_RPL_ISUPPORT },
+ { "331", handle_RPL_NOTOPIC },
{ "332", handle_RPL_TOPIC },
{ "333", handle_RPL_TOPICWHOTIME },
{ "353", handle_RPL_NAMREPLY },
@@ -339,6 +341,42 @@ handle_NICK(char *msg, char **params, struct Server *server, time_t timestamp) {
}
void
+handle_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp) {
+ struct Channel *chan;
+
+ if (param_len(params) < 4 || **params != ':')
+ return;
+
+
+ if ((chan = chan_get(&server->channels, *(params+2), -1)) != NULL) {
+ hist_add(chan->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL);
+ free(chan->topic);
+ chan->topic = *(params+3) ? strdup(*(params+3)) : NULL;
+ }
+}
+
+void
+handle_RPL_NOTOPIC(char *msg, char **params, struct Server *server, time_t timestamp) {
+ struct Channel *chan;
+ char *target;
+
+ if (param_len(params) < 5 || **params != ':')
+ return;
+
+ target = *(params+3);
+
+ if ((chan = chan_get(&server->channels, target, -1)) == NULL)
+ return;
+
+ if (strcmp_n(target, handle_expect_get(server, Expect_topic)) == 0) {
+ hist_add(chan->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL);
+ handle_expect(server, Expect_topic, NULL);
+ } else {
+ hist_add(chan->history, NULL, msg, params, Activity_status, timestamp, HIST_LOG);
+ }
+}
+
+void
handle_RPL_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp) {
struct Channel *chan;
char *target, *topic;
diff --git a/hirc.h b/hirc.h
@@ -93,9 +93,11 @@ void handle_JOIN(char *msg, char **params, struct Server *server, time_t timest
void handle_PART(char *msg, char **params, struct Server *server, time_t timestamp);
void handle_QUIT(char *msg, char **params, struct Server *server, time_t timestamp);
void handle_NICK(char *msg, char **params, struct Server *server, time_t timestamp);
+void handle_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp);
void handle_PRIVMSG(char *msg, char **params, struct Server *server, time_t timestamp);
void handle_RPL_WELCOME(char *msg, char **params, struct Server *server, time_t timestamp);
void handle_RPL_ISUPPORT(char *msg, char **params, struct Server *server, time_t timestamp);
+void handle_RPL_NOTOPIC(char *msg, char **params, struct Server *server, time_t timestamp);
void handle_RPL_TOPIC(char *msg, char **params, struct Server *server, time_t timestamp);
void handle_RPL_TOPICWHOTIME(char *msg, char **params, struct Server *server, time_t timestamp);
void handle_RPL_NAMREPLY(char *msg, char **params, struct Server *server, time_t timestamp);