Git Product home page Git Product logo

node-gbxremote's Introduction

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.

node-gbxremote's People

Contributors

agnat avatar baalexander avatar datakurre avatar hugobuddel avatar minigod avatar nw avatar projectmoon avatar scottgonzalez avatar tlray avatar tootallnate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-gbxremote's Issues

Pipelining

ManiaPlanet Server does not support pipelining.
Ie: The server will close the connection (no errors) if a query is sent before the response for the previous query is received. Sending too many queries (too fast) will therefore not work.

Solution?
Stack up queries. Then on process.nextTick(), do a system.multicall, and empty the stack. If it's only one query in the stack, do a normal query (to minimize overhead).

EDIT:
That solution will only work if the response for the previous query is received. After this, you can still use the stack, but instead of doing the multicall and emptying of the stack on nextTick, it has to be on data. (all data loaded, or just something?)

EDIT 01.04.2013:
I think I was wrong about ManiaPlanet not supporting pipelining. However, stacking up queries, and sending them on next tick with system.multicall would most likely improve performance.
@Gissues:{"order":50,"status":"backlog"}

Problems with floats.

Floats from scripted modes are converted to number, this will loose the decimal notation (with zero after it.).
Will be a problem when using ScriptModeSettings:

receiving from gbx:

{ S_AutoManageAFK: false,
  S_AFKIdleTimeLimit: 90000,
  S_UseScriptCallbacks: true,
  S_NeutralEmblemUrl: '',
  S_ScoresTableStylePath: '',
  S_MatchmakingAPIUrl: 'https://matchmaking.maniaplanet.com/v8',
  S_MatchmakingMode: 0,
  S_MatchmakingRematchRatio: -1,
  S_MatchmakingRematchNbMax: 2,
  S_MatchmakingVoteForMap: false,
  S_MatchmakingProgressive: false,
  S_LobbyRoundPerMap: 60,
  S_LobbyMatchmakerPerRound: 6,
  S_LobbyMatchmakerWait: 2,
  S_LobbyMatchmakerTime: 8,
  S_LobbyInstagib: false,
  S_LobbyDisplayMasters: true,
  S_LobbyDisableUI: false,
  S_MatchmakingErrorMessage: '�An error occured in the matchmaking API. If the problem persist please try to contact this server administrator.',
  S_MatchmakingLogAPIError: false,
  S_MatchmakingLogAPIDebug: false,
  S_MatchmakingLogMiscDebug: false,
  S_ProgressiveActivation_WaitingTime: 180000,
  S_ProgressiveActivation_PlayersNbRatio: 1,
  S_Mode: 0,
  S_TimeLimit: 60,
  S_TimePole: 15,
  S_TimeCapture: 1.5,
  S_WarmUpDuration: 90,
  S_MapWin: 2,
  S_TurnGap: 2,
  S_TurnLimit: 15,
  S_DeciderTurnLimit: 20,
  S_QuickMode: false,
  S_UseLegacyCallback: false,
  S_WarnWhenSpectating: false,
  S_UsePlayerClublinks: false,
  S_ForceClublinkTeam1: '',
  S_ForceClublinkTeam2: '',
  S_DisplaySponsors: true,
  S_RestartMatchOnTeamChange: false,
  S_Practice: false,
  S_PracticeRoundLimit: 3,
  S_TurnWin: 9,
  S_UseDraft: false,
  S_DraftBanNb: 4,
  S_DraftPickNb: 3,
  S_NbPlayersPerTeamMax: 3,
  S_NbPlayersPerTeamMin: 2,
  S_DisplayRulesReminder: true }

Error when changing one value and query the SetModeScriptSettings:

XML-RPC fault: Wrong setting type for 'S_MatchmakingRematchRatio'
    Error: XML-RPC fault: Wrong setting type for 'S_MatchmakingRematchRatio'

Type according to ManiaPlanet Docs:
http://doc.maniaplanet.com/dedicated-server/matchmaking.html#Dedicated-server-configuration

Multicall support

Would be great to have some kind of multicall support. Currently it doesn't right?

UnhandledPromiseRejectionWarning

Hi,

I'm facing with what I will call an issue with your gbxremote's lib.

First of all, I'd like to say that I'm not familiar with promises. I understand the theory but never coded with it.

I have this code :

const gbx = require("gbxremote");

module.exports = {
    setServerName: setServerName
};

/*
 * - EXPORTED FUNCTION -
 * Set the server's name to a server
 * @param {string} host
 * @param {integer} xmlrpc_port
 * @param {string} admin_password
 * @param {string} server_name
 * @param {function} cb
 * @returns {callback}
 */

function setServerName(host, xmlrpc_port, admin_password, server_name, cb) {
    const client = gbx.createClient(xmlrpc_port, host);

    client.on('connect', function () {
        client.query('Authenticate', ['Admin', admin_password]).then(function (res) {
            if (res === true) {
                // Set the name of the server
                client.query('SetServerName', server_name).then(function (res) {
                    if (typeof cb === 'undefined') {
                        return cb(null, true);
                    }
                }).catch(function (err) {
                    if (typeof cb === 'undefined') {
                        return cb("Can't change the server name", true);
                    }
                });
            }
        }).catch(function (err) {
            if (typeof cb === 'undefined') {
                return cb("Authent err: " + err, true);
            }
        });
    }).on("error", function (err) {
        if (typeof cb === 'undefined') {
            return cb("Err: " + err, true);
        }
    });
}

When I execute it here is what I have :

Err: Error: getaddrinfo ENOTFOUND trackmania_1 trackmania_1:undefined ## --- console message display with my code
(node:2298) UnhandledPromiseRejectionWarning: undefined
(node:2298) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2298) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My server is not launch. I wanted to test this case (it can be for another reason, like the "xmlrpc_allowremote" parameter set to 'false') and it is not what I expected.

Did I miss something in my code or is it really an issue ?

Thanks !

Seb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.