summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2022-11-25 00:03:17 +0000
committerLuke Bratch <luke@bratch.co.uk>2022-11-25 00:03:17 +0000
commitae1390b2bef4dc6a1a113cddaee37d745b559b1f (patch)
treea5f3894e616ae387c079ae03048461afe0854994 /functions.c
parent2e665e03b6175b3f31f0ef1e058183417df1456e (diff)
Implement fake QUIT handling via a NOTICE when doing a replay.
Since user QUIT messages don't contain channel names, clients that didn't know which channels a nick was in when receiving a quit message for that nick can't show a per-channel QUIT notification. Some clients just display the QUIT message in the server status window, others silently ignore it. Cater for those clients by sending a NOTICE about the QUIT rather than replaying it - assuming the nick isn't still in any of our channels.
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/functions.c b/functions.c
index 6d85d8e..6f8d131 100644
--- a/functions.c
+++ b/functions.c
@@ -1446,6 +1446,38 @@ int updatenickinallchannels(char *nickuserhost, char *newnick, struct channel *c
return 1;
}
+// Check if "nick" is in any channel or not.
+// Return 1 if it is, or 0 if not.
+int isnickinanychannel(struct channel *channels, int maxchannelcount, char *nick) {
+ debugprint(DEBUG_FULL, "isnickinanychannel(): given '%s'.\n", nick);
+
+ // Make sure the nick has a length of at least one
+ if (strlen(nick) < 1) {
+ debugprint(DEBUG_CRIT, "isnickinanychannel(): nick has no length, returning 0!\n");
+ return 0;
+ }
+
+ // Go through all channels and see if nick is present
+ for (int i = 0; i < maxchannelcount; i++) {
+ // Don't bother checking this channel index if it isn't used
+ if (!channels[i].name[0]) {
+ continue;
+ }
+ // Go through all nicks in channel
+ for (int j = 0; j < MAXCHANNICKS; j++) {
+ // See if the nick is here
+ if (strlen(channels[i].nicks[j]) == strlen(nick) && !strcmp(channels[i].nicks[j], nick)) {
+ // Found it!
+ debugprint(DEBUG_FULL, "isnickinanychannel(): nick '%s' found in channel '%s', returning 1.\n", nick, channels[i].name);
+ return 1;
+ }
+ }
+ }
+
+ debugprint(DEBUG_FULL, "isnickinanychannel(): nick '%s' not found in any channel '%s', returning 0.\n", nick);
+ return 0;
+}
+
// Populate our channels struct with all nicks in a RPL_NAMREPLY
// Returns 1 on success or 0 on failure
int addnamereplytochannel(char *namereply, struct channel *channels, int maxchannelcount) {