summaryrefslogtreecommitdiff
path: root/blabouncer.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-11 19:49:27 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-11 19:49:27 +0100
commit231656bf59da65036b171ce5ccc06eeadd64a05a (patch)
tree350e2c0fdbf1e368b26e90a59331e48044f4387d /blabouncer.c
parent0559bff00a6be2054194632c3543bf62af1fb56f (diff)
Implement relay log writing.
Diffstat (limited to 'blabouncer.c')
-rw-r--r--blabouncer.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/blabouncer.c b/blabouncer.c
index 2e1f414..29b90ae 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -514,7 +514,7 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc
}
}
- // Server TOPIC received? Update our local channel topic info then relay to clients
+ // Server TOPIC received? Update our local channel topic info then relay to clients.
if (strncmp(tokens[1], "TOPIC", strlen(tokens[1])) == 0) {
printf("Server TOPIC found and it is: %s with length %zd! Next token is '%s'. Updating our local channel topic info.\n", tokens[0], strlen(tokens[0]), tokens[2]);
@@ -547,6 +547,18 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc
return 1;
}
+ // Server PRIVMSG received? Relay to all clients and write to replay log.
+ if (strncmp(tokens[1], "PRIVMSG", strlen(tokens[1])) == 0) {
+ printf("Server PRIVMSG found and it is: %s with length %zd! Next token is '%s'. Relaying to all clients.\n", tokens[0], strlen(tokens[0]), tokens[2]);
+
+ sendtoallclients(clientsockfd, fdmax, arr_clients, str, sourcefd);
+
+ // Write to relay log
+ writerelayline(str);
+
+ return 1;
+ }
+
// Don't return if we got here because this means we didn't process something above
}
@@ -701,7 +713,7 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc
return 1;
}
- // If PRIVMSG received, send to server, but also reformat and send to all other clients
+ // If PRIVMSG received, send to server, but also reformat and send to all other clients and log to replay file.
if (strncmp(tokens[0], "PRIVMSG", strlen(tokens[0])) == 0) {
printf("Client PRIVMSG found and it is: %s with length %zd! Sending to server then back to other clients...\n", tokens[0], strlen(tokens[0]));
// Send original request straight to server
@@ -717,6 +729,9 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc
// Send to all except source client
sendtoallclients(clientsockfd, fdmax, arr_clients, outgoingmsg, sourcefd);
+ // Write to relay log
+ writerelayline(outgoingmsg);
+
return 1;
}