npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gbxremote

v0.2.1

Published

A pure JavaScript GBXRemote client.

Downloads

218,368

Readme

Node-GbxRemote

JavaScript (node.js) port of GbxRemote by Nadeo, which is built on Incutio XML-RPC Library.

Used to communicate with ManiaPlanet servers.

Note: The API may, or may not change!

Install

npm install gbxremote

To Use

Look in /examples/ for all examples.


The following examples expects that var gbxremote = require('gbxremote').

Connecting:

To connect to a server, use var client = gbxremote.createClient(port, [host]);

Examples of ways to connect to the server:

// Connect with port only
var client = gbxremote.createClient(5000);
client.on('connect', onConnect);

// Connect with port and hostname
var client = gbxremote.createClient(5000, 'localhost');
client.on('connect', onConnect);

// Connect with port and ip
var client = gbxremote.createClient(5000, '127.0.0.1');
client.on('connect', onConnect);

// Create client and connect explicitly
var client = new gbxremote.Client(5000, 'localhost');
client.connect().then(onConnect);

Querying:

Queries are sent to the server by calling client.query(method, [params]);
client.query returns a promise.

Queries before the connect event has been emitted will be queued and sent on connect!

See the full list of methods.

var client = gbxremote.createClient(5000);

client.on('connect', function() {

	// GetVersion does not take any params.
	client.query('GetVersion').then(function (res) {
		console.log('Server version:', res.join(', '));
	}).catch(function(err) {
		console.error('Error when querying server:', err);
	});
	
	// GetPlayerInfo takes 2 parameters, 1 optional.
	// GetPlayerInfo(string login, [int compatibility])
	client.query('GetPlayerInfo', ['minigod']).then(function (res) {
		console.log('Player info:');
		console.log(res);
	}).catch(function (err) {
		console.error('Error getting player info:', err);
	});
});

Disconnecting:

client.terminate();

Events:

Event: connect()

Emitted when connection to the server is successfull.
Ready to receive queries!

var client = gbxremote.createClient(5000);

client.on('connect', function() {
	console.log('Connection successfull! Lets do some queries!');
	client.query('EnableCallbacks', true);
});

If there is a problem connecting, the 'connect' event will not be emitted, the 'error' event will be emitted with the exception.

Event: error(err)

Emitted when:

  • Socket errors (host is not listening on that port, loose connection, etc.)
  • Handshake fails (host is listening on that port, but its not a ManiaPlanet (GbxRemote 2) server)
var client = gbxremote.createClient(5000);

client.on('error', function(err) {
	console.error('Connection failed: ' + err);
});

Event: callback(method, params)

After sending EnableCallbacks(true) to the server, it will send you callbacks when stuff happend on the server.
Eg:

  • ManiaPlanet.ServerStart
  • ManiaPlanet.ServerStop
  • ManiaPlanet.PlayerConnect
  • ManiaPlanet.PlayerChat

See the full list of callbacks

var client = gbxremote.createClient(5000);

client.on('connect', function() {
	client.query('SetApiVersion', ['2012-06-19']);
	client.query('EnableCallbacks', [true]);
});

client.on('callback', function(method, params) {
	console.log("Callback from server: %s - %d params", method, params.length);
	
	// This would be the typical place to have a switch statement. Please dont do that. Use the events, as shown below.
});

Event: <method>(params)

Callbacks will also emit separate events for each method. It's hard to explain. Learn from example:

var client = gbxremote.createClient(5000);

client.on('connect', function() {
	// Before enabling callbacks, make sure you set the latest API.
	client.query('SetApiVersion', ['2012-06-19']);
	client.query('EnableCallbacks', [true]);
});

// ManiaPlanet.PlayerConnect(string Login, bool IsSpectator);
client.on('ManiaPlanet.PlayerConnect', function(params) {
	console.log('%s just joined as a %s', params[0], params[1] ? 'spectator' : 'player');
});

// ManiaPlanet.PlayerDisconnect(string Login); 
client.on('ManiaPlanet.PlayerDisconnect', function(params) {
	console.log('%s left the server', params[0]);
});

These events can basically take over the big switch statements that is normal in todays server controllers.

Event: close(had_error)

Emitted once the socket is fully closed. The argument had_error is a boolean which says if the socket was closed due to a transmission error.

var client = gbxremote.createClient(5000);

client.on('connect', function() {
	// Connected...
	
	// Do stuff?
	
	// Disconnect
	client.terminate();
});

client.on('close', function(had_error) {
	console.log('Connection to the server has been closed');
});

The License (MIT)

Released under the MIT license. See the LICENSE file for the complete wording.