summaryrefslogtreecommitdiff
path: root/blabouncer.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-19 14:30:08 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-19 14:30:08 +0100
commit52d426544ce976f81cbd626fbba343c066ed88d0 (patch)
tree479ed51e3d96aef99d70a9807f76d93593e1c871 /blabouncer.c
parentc4de74dce0ada6bafd297222e85bfe170805d6fb (diff)
Handle server MODEs more intelligently, in particular so we can relay our user MODE to new clients correctly.
Diffstat (limited to 'blabouncer.c')
-rw-r--r--blabouncer.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/blabouncer.c b/blabouncer.c
index 2c210b1..f85e58c 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -903,14 +903,40 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli
return 1;
}
- // Server MODE received? Store in ircdstrings for when clients connect and relay to current clients.
+ // Server MODE received? See what sort it is and act accordingly.
if (strncmp(tokens[1], "MODE", strlen(tokens[1])) == 0) {
- printf("Server MODE found and it is: %s with length %zd! Mode is '%s'. Storing for later.\n", tokens[1], strlen(tokens[1]), tokens[3]);
+ printf("Server MODE found and it is: %s with length %zd! Next token is '%s'. Analysing...\n", tokens[1], strlen(tokens[1]), tokens[2]);
+
+ // 4 tokens could be either our initial mode or a channel mode (or something else - TODO - what else?)
+ if (counter == 4) {
+ // Might be our initial mode (e.g. ":nick MODE nick :+iwz")
+ char comparison[MAXDATASIZE];
+ snprintf(comparison, MAXDATASIZE, ":%s MODE %s :", ircdstrings->ircnick, ircdstrings->ircnick);
+ if (strncmp(str, comparison, strlen(comparison)) == 0) {
+ // Looks like it!
+ printf("Our initial MODE found (%s), storing for later.\n", tokens[3]);
+ // Store in ircdstrings for when clients connect and relay to current clients.
+ strcpy(ircdstrings->mode, tokens[3]);
+
+ // Relay to all current clients anyway - TODO - Necessary?
+ sendtoallclients(clients, str, sourcefd, settings);
+
+ free(strcopyPtr);
+ return 1;
+ }
+
+ // Might be a channel mode (e.g. ":nick!user@host MODE #channel +s")
+ if (tokens[2][0] == '#') {
+ // Looks like it! Tell all clients.
+ printf("Channel MODE found (%s %s), telling all clients.\n", tokens[2], tokens[3]);
+ sendtoallclients(clients, str, sourcefd, settings);
- // Store for new clients
- strcpy(ircdstrings->mode, tokens[3]);
+ free(strcopyPtr);
+ return 1;
+ }
+ }
- // Relay to all current clients
+ // Relay to all current clients if not processed by the above
sendtoallclients(clients, str, sourcefd, settings);
free(strcopyPtr);