Skip to content

Instantly share code, notes, and snippets.

@sorae42
Created March 10, 2021 17:20
Show Gist options
  • Select an option

  • Save sorae42/75ead50361575361aa1b1d08391fae21 to your computer and use it in GitHub Desktop.

Select an option

Save sorae42/75ead50361575361aa1b1d08391fae21 to your computer and use it in GitHub Desktop.
Chat and Command logger for BDSX2
// Enable the ability to log chat and commands, just like Java server.
// soraboken / Rosetta Emerson (c) 2021
// YOUR SERVER NEED TO BE RUNNING BDSX2: https://github.com/bdsx/bdsx
console.log("[LOGGER] Prepare logging, please wait...!");
import { command, nethook, MinecraftPacketIds } from 'bdsx';
nethook.before(MinecraftPacketIds.Text).on((packet, networkIdentifier) => {
const name = packet.name;
const message = packet.message;
console.log(`[LOGGER] <${name}> ${message}`);
});
nethook.after(MinecraftPacketIds.Login).on((ptr, networkIdentifier, packetId) => {
const ip = networkIdentifier.getAddress();
const cert = ptr.connreq.cert;
const name = cert.getId();
console.log(`[INFO] ${name} @ ${ip} connecting...`);
});
command.hook.on((commandText, origin) => {
console.log(`[LOGGER] ${origin} executed: ${commandText}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment