Open leighmacdonald opened 3 years ago
I've implemented functionality like this on my own community. Can be done in various of ways but the most efficient would using logaddress_add
to emit all logs to a UDP socket on the API.
I have a service on my API that opens a UDP port that receives all logs from our servers, I have then created a plugin called "LogActions" to log every action done by our moderators/admins using OnLogAction
This is the service that listens, is written in Node with typescript, could probably be easily implemented in Go I reckon.
import dgram from "dgram";
import Services from "./Services";
import Logger from "@dodgeball/logger";
import { Event } from "src/events/register.events";
const LOG = new Logger("dodgeball:bot:services:SourceService");
export default class SourceService {
constructor(private services: Services) {}
async start() {
const port = 12345; // Replace with your desired port number
const udpServer = dgram.createSocket("udp4");
udpServer.on("message", (message, rinfo) => {
const logLine = message.toString("utf-8", 5);
// We only want messages that has [LogActions] in it
// Can also have Console<0><Console><Console> doing actions, filter them out
if (!logLine.includes("[LogActions]") || logLine.includes("<Console><Console>")) {
return;
}
// Do something
});
udpServer.on("error", (err) => {
LOG.error("UDP Server error:", err);
});
udpServer.on("connect", () => {
LOG.info("UDP Server connected");
});
udpServer.on("listening", () => {
const address = udpServer.address();
LOG.info(`UDP server listening on ${address.address}:${address.port}`);
});
udpServer.bind(port);
}
}
This was actually meant to be more on the backend and not in-game, however its probably reasonable to include some of this on the frontend to round it out, thanks for the link.
And yes indeed it can be done in go, we use it quite a lot already, thanks for the example:
https://github.com/leighmacdonald/gbans/tree/master/pkg/logparse/udp_listener.go#L29 https://github.com/leighmacdonald/gbans/tree/master/pkg/logparse
Need to keep track of mod/admin actions.