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 onlyvar client = gbxremote;client; // Connect with port and hostnamevar client = gbxremote;client; // Connect with port and ipvar client = gbxremote;client; // Create client and connect explicitlyvar client = 5000 'localhost';client;
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!
var client = gbxremote; client;
Disconnecting:
client.terminate();
Events:
Event: connect()
Emitted when connection to the server is successfull.
Ready to receive queries!
var client = gbxremote; client;
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; client;
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; client; client;
Event: <method>(params)
Callbacks will also emit separate events for each method. It's hard to explain. Learn from example:
var client = gbxremote; client; // ManiaPlanet.PlayerConnect(string Login, bool IsSpectator);client; // ManiaPlanet.PlayerDisconnect(string Login); client;
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; client; client;
The License (MIT)
Released under the MIT license. See the LICENSE file for the complete wording.