Skip to main content

Built and signed on GitHub Actions

SRCDS Log Receiver for listening for UDP logs on Source Dedicated Servers

This package works with Node.js, Deno, Bun
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
100%
Published
3 months ago (1.1.4)
class LogReceiver
extends EventEmitter

An event emitter that will emit a message event when a valid UDP log is created on the server

When a log is sent, there will be a message event published that you can extract the data from. This is a valid payload. It is important to check the IP or password of the content to ensure it came from a trusted source

You can listen on socket events such as error and close by listening to those events. All default events of the Socket will be forwarded. If you need to close the socket at any time, provide an AbortSignal. Aborting will automatically call Socket.close for you on the socket and emits a close event

Examples

Simple receiver that logs to console every message

import { LogReceiver} from "@c43721/srcds-log-receiver";

const receiver = new LogReceiver({
  address: "0.0.0.0",
  port: 9871,
});

receiver.on("event", (message) => console.log(message));

On every log generated by the srcds server, it will log that message out to console

Passing in an abort controller to close the socket

import { LogReceiver} from "@c43721/srcds-log-receiver";

const controller = new AbortController();
const { signal } = controller;

const receiver = new LogReceiver({
  address: "0.0.0.0",
  port: 9871,
});

receiver.on("event", (message) => console.log(message));
receiver.on("close", () => console.log("Closed the socket"));

controller.abort();

While not required, there may be times where you have short-lived receivers. Since each instance creates a socket, closing those sockets becomes a problem. Abort controllers help with that by providing a way to explicitly close the resources for you

Using the password and IP to verify the source of the data

import { LogReceiver} from "@c43721/srcds-log-receiver";

const receiver = new LogReceiver({
  address: "0.0.0.0",
  port: 9871,
});

receiver.on("event", (message) => {
   if (message.password === null) {
     return;
   }

   if (message.password === "mysuperdupersecretlogpassword") {
     await doSomethingWithTheMessage(message);
   }
});

For security reasons, you should always use a log secret to prevent evaluation of potentially malicious messages. Do this by looking at the password field. In order to set up the log secret, you can use the sv_logsecret command

Constructors

new
LogReceiver(options?: LogReceiverOptions)

Creates a new receiver

Add Package

deno add jsr:@c43721/srcds-log-receiver

Import symbol

import { LogReceiver } from "@c43721/srcds-log-receiver";

---- OR ----

Import directly with a jsr specifier

import { LogReceiver } from "jsr:@c43721/srcds-log-receiver";

Add Package

npx jsr add @c43721/srcds-log-receiver

Import symbol

import { LogReceiver } from "@c43721/srcds-log-receiver";

Add Package

yarn dlx jsr add @c43721/srcds-log-receiver

Import symbol

import { LogReceiver } from "@c43721/srcds-log-receiver";

Add Package

pnpm dlx jsr add @c43721/srcds-log-receiver

Import symbol

import { LogReceiver } from "@c43721/srcds-log-receiver";

Add Package

bunx jsr add @c43721/srcds-log-receiver

Import symbol

import { LogReceiver } from "@c43721/srcds-log-receiver";