diff options
| author | Nakidai <nakidai@disroot.org> | 2026-02-01 19:01:04 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2026-02-01 19:05:43 +0300 |
| commit | ac52bbe3427cda3bd2098ee35e06163885b21836 (patch) | |
| tree | 51387c4d5f8ebd56c19a345b2e34361c979579c8 | |
| parent | 32e81cb7a0d4f4b1b24674439e5a948b39725f2e (diff) | |
| download | libreircd-ac52bbe3427cda3bd2098ee35e06163885b21836.tar.gz libreircd-ac52bbe3427cda3bd2098ee35e06163885b21836.zip | |
Refactor QUIT message sending
After seeing same announcing code second time I decided it should be done before an actual quit in loop.c. Plus, channel exiting is now done in user_remove().
| -rw-r--r-- | config.h | 1 | ||||
| -rw-r--r-- | handle.c | 13 | ||||
| -rw-r--r-- | ircd.h | 1 | ||||
| -rw-r--r-- | loop.c | 30 |
4 files changed, 24 insertions, 21 deletions
diff --git a/config.h b/config.h index a1a8c4a..cf86c7d 100644 --- a/config.h +++ b/config.h @@ -13,6 +13,7 @@ #define PEER_USER_MAX 16 #define PEER_REAL_MAX 32 #define PEER_HOST_MAX 64 +#define PEER_QUIT_MAX 64 #define PEER_PINGTIMEOUT 120 #define PEER_PONGTIMEOUT 20 diff --git a/handle.c b/handle.c index 2f4d0b8..698e8a9 100644 --- a/handle.c +++ b/handle.c @@ -246,20 +246,9 @@ privmsg(struct Message *msg, struct Peer *peer) static int quit(struct Message *msg, struct Peer *peer) { - size_t i; - ensure(peer->type, (void)0, 1) - announce( - peer, - ":%s!%s@%s QUIT :%s", - getnick(peer), - peer->user, - peer->host, - msg->params[0] ? msg->params[0] : "Client Quit" - ); - for (i = 0; i < peer->channels_c; ++i) - channel_exit(peer->channels[i], peer); + strlcpy(peer->quit, msg->params[0] ? msg->params[0] : "Client Quit", PEER_QUIT_MAX); return 1; } diff --git a/ircd.h b/ircd.h index fcc6ddc..0cde9e0 100644 --- a/ircd.h +++ b/ircd.h @@ -55,6 +55,7 @@ struct Peer BIT(SNOTICE), } modes; char buf[MESSAGE_MAX]; + char quit[PEER_QUIT_MAX]; size_t recvd, channels_c; time_t last, ping; }; diff --git a/loop.c b/loop.c index 46c585c..c568c6f 100644 --- a/loop.c +++ b/loop.c @@ -16,11 +16,11 @@ #include "ircd.h" -#include <string.h> - #include <err.h> #include <poll.h> #include <signal.h> +#include <stdio.h> +#include <string.h> #include <time.h> #include <unistd.h> @@ -131,19 +131,31 @@ loop: } if (peers[i].ping && now - peers[i].ping > PEER_PONGTIMEOUT) { - announce( - &peers[i], - ":%s!%s@%s QUIT :Ping Timeout (%llu seconds)", - getnick(&peers[i]), - peers[i].user, - peers[i].host, + snprintf( + peers[i].quit, + sizeof(PEER_QUIT_MAX), + "Ping Timeout (%llu seconds)", now - peers[i].ping ); peers[i].flags |= DELETE; } if (peers[i].flags & DELETE) { - writef(peers[i].fd, "ERROR :Closing Link: %s", peers[i].host); + if (peers[i].type) + announce( + &peers[i], + ":%s!%s@%s QUIT :%s", + getnick(&peers[i]), + peers[i].user, + peers[i].host, + peers[i].quit + ); + writef( + peers[i].fd, + "ERROR :Closing Link: %s (%s)", + peers[i].host, + peers[i].quit + ); close(peers[i].fd); user_remove(i); --i; |