summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
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) {