summaryrefslogtreecommitdiff
path: root/blabouncer.c
diff options
context:
space:
mode:
Diffstat (limited to 'blabouncer.c')
-rw-r--r--blabouncer.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/blabouncer.c b/blabouncer.c
index 571ff79..3198026 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -410,14 +410,14 @@ int removechannel(struct channel *channels, char *name) {
}
// Check if we have the NAMES for the channel 'name' already.
-// Return the index in the channel array if so, or 0 if not.
+// Return the 1 if we do, 0 if we don't, or -1 if there's an error.
int channelgotnames(struct channel *channels, char *name) {
printf("channelgotnames(): given '%s'.\n", name);
for (int i = 0; i < MAXCHANNELS; i++) {
if (strncmp(channels[i].name, name, strlen(name)) == 0) {
if (channels[i].gotnames) {
printf("channelgotnames(): channel '%s' gotnames was set, returning '%d'.\n", channels[i].name, channels[i].gotnames);
- return i;
+ return 1;
} else {
printf("channelgotnames(): channel '%s' gotnames was not set, returning '%d'.\n", channels[i].name, channels[i].gotnames);
return 0;
@@ -426,8 +426,8 @@ int channelgotnames(struct channel *channels, char *name) {
}
// We didn't find the channel, this isn't good! TODO - Do something if this happens.
- printf("channelgotnames(): channel '%s' not found, this is bad, returning 0.\n", name);
- return 0;
+ printf("channelgotnames(): channel '%s' not found, this is bad, returning -1.\n", name);
+ return -1;
}
// Check if we are in a channel named "name" or not.
@@ -453,6 +453,22 @@ int inchannel(struct channel *channels, char *name) {
return 0;
}
+// Returns the array index in the 'channels' array of the channel
+// named 'channel'.
+// Returns -1 if there was an error.
+int channelindex(struct channel *channels, char *name) {
+ printf("channelindex(): given '%s'.\n", name);
+ for (int i = 0; i < MAXCHANNELS; i++) {
+ if (strncmp(channels[i].name, name, strlen(name)) == 0) {
+ return i;
+ }
+ }
+
+ // We didn't find the channel, this isn't good! TODO - Do something if this happens.
+ printf("channelindex(): channel '%s' not found, this is bad, returning -1.\n", name);
+ return -1;
+}
+
// Send the requested number of lines of replay log to the requested client
// 'sourcefd' is the client to send to, and replayseconds is the number of
// seconds of replay to replay.
@@ -806,13 +822,13 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli
// Server 353 (RPL_NAMREPLY), relay to all clients if we've just JOINed the channel, or relay to any clients
// who were pending RPL_NAMREPLYs if it's an existing channel.
} else if (strncmp(tokens[1], "353", strlen(tokens[1])) == 0) {
- // We were already in the channel and have the NAMES
+ // It must be a new channel and we don't have the NAMES
if (!channelgotnames(channels, tokens[4])) {
printf("Server 353 received for a new channel, sending to all clients.\n");
// Relay to all clients
sendtoallclients(clients, str, sourcefd, settings);
} else {
- // It must be a new channel and we don't have the NAMES
+ // We were already in the channel and have the NAMES
printf("Server 353 received for an existing channel, sending to all clients who were pending RPL_NAMREPLYs.\n");
// If any clients were pending RPL_NAMREPLYs, send this on to them
// TODO - Make sure clients only get the ones they were waiting on in case there are multiple conflicting requests going on at once
@@ -829,13 +845,15 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli
// and decrement from any clients who were waiting on RPL_NAMREPLY if it's an existing channel.
} else if (strncmp(tokens[1], "366", strlen(tokens[1])) == 0) {
int channelelement;
- // We were already in the channel and have the NAMES
+ // It must be a new channel and we don't have the NAMES
if (!(channelelement = channelgotnames(channels, tokens[3]))) {
printf("Server 366 received for a new channel, sending to all clients and set as got names.\n");
- channels[channelelement].gotnames = 1;
+ // We have the names now!
+ channels[channelindex(channels, tokens[3])].gotnames = 1;
// Relay to all clients
sendtoallclients(clients, str, sourcefd, settings);
} else {
+ // We were already in the channel and have the NAMES
// TODO - Make sure clients only get the ones they were waiting on in case there are multiple conflicting requests going on at once
printf("Server 366 received for an existing channel, sending to all clients who were pending RPL_NAMREPLYs and decrementing their pendingnames count.\n");
for (int i = 0; i < MAXCLIENTS; i++) {