1.0.2 • Published 9 months ago

pavlov-rcon v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

pavlov-rcon

A simple RCON client for Pavlov VR.

Installation

npm install pavlov-rcon

Usage

const PavlovRCON = require('pavlov-rcon');
const rcon = new PavlovRCON('0.0.0.0', 9100, 'password');

rcon.connect().then(() => {
    rcon.on('Authenticated', () => {
        console.log('Authenticated!');
        rcon.send('ServerInfo');
    });
    rcon.on('ServerInfo', (data) => {
        console.log("Map Label: " + data.MapLabel);
        console.log("Game Mode: " + data.GameMode);
        console.log("Server Name: " + data.ServerName);
        console.log("Teams: " + data.Teams);
        console.log("Round State: " + data.RoundState);
        console.log("Player Count: " + data.PlayerCount);
        rcon.close();
    });
});

The above code connects to the server, authenticates, and then sends the ServerInfo command. The response is then printed to the console.

Reminder

To save resources on the server, don't constantly close and open new connections, instead keep one open and send commands as needed.

Commands & Events

For every command, the event has the same name, just use:

rcon.on('CommandName', (data) => {
    // Do something with data
});

The data variable will always be JSON, but you can see the full response by using:

JSON.stringify(data);

Commands

You can find a list of commands here on Pavlov's official wiki.

For this example, we'll teleport Player1 to Player2:

rcon.send('Teleport Player1 Player2'); 
// Use the player's unique ID's
// You can get these from the PlayerList
// By using this:
rconn.send('RefreshList');

I hope this helps you get started with your own RCON client!