summaryrefslogtreecommitdiff
path: root/message.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2022-02-10 21:21:07 +0000
committerLuke Bratch <luke@bratch.co.uk>2022-02-10 21:21:07 +0000
commit4375415b9228c0537d1d18b1f1ba263d286f7f3a (patch)
treea50f04dfc70b45e2d35dc9cd2d1fd189fe794ac9 /message.c
parentc1799538e9bba02ac188c262f051e9bae6e612f8 (diff)
Relay server PINGs to all clients in case they rely on PINGs to stay alive.
Diffstat (limited to 'message.c')
-rw-r--r--message.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/message.c b/message.c
index 5f0c2fe..9c07a83 100644
--- a/message.c
+++ b/message.c
@@ -39,6 +39,14 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
// sourcefd = 0 as this is a trusted response
sendtoserver(server_ssl, outgoingmsg, strlen(outgoingmsg), 0, clients, settings);
+ // Also relay the request to all clients in case they were expecting PINGs to keep themselves alive
+ if (!snprintf(outgoingmsg, MAXDATASIZE, "PING %s", tokens[1])) { // TODO - Make sure tokens[1] actually has a token
+ fprintf(stderr, "Error while preparing PING relay!\n");
+ debugprint(DEBUG_CRIT, "Error while preparing PING relay!\n");
+ outgoingmsg[0] = '\0';
+ }
+ sendtoallclients(clients, outgoingmsg, EXCEPT_NONE, settings);
+
// We processed something so return true
return 1;
}
@@ -1091,6 +1099,13 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
return 1;
}
+ // Client PONG received? This is almost certainly in response to a relayed server PING from us.
+ // We can ignore it since we don't actively PING clients, instead relying on the server's PING frequency.
+ if (strncasecmp(tokens[0], "PONG", strlen(tokens[0])) == 0) {
+ debugprint(DEBUG_FULL, "Client PONG found and it is: %s with length %zd! Ignoring since we don't track client PONGs.\n", tokens[0], strlen(tokens[0]));
+ return 1;
+ }
+
// TODO - Ignoring CAP for now so as not to confuse other clients, but we should probably query the server then relay the response to the client
if (strncasecmp(tokens[0], "CAP", strlen(tokens[0])) == 0) {
debugprint(DEBUG_FULL, "Client CAP found and it is: %s with length %zd! Ignoring completely for now - TODO - do something useful!\n", tokens[0], strlen(tokens[0]));