New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gbxremote

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gbxremote - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

142

lib/client.js
var net = require('net')
, barse = require('barse')
, Serializer = require('./serializer')

@@ -115,87 +116,38 @@ , Deserializer = require('./deserializer')

});
var doHandshake = function(data) {
if (this.hsdata == null) {
this.hsdata = new Buffer(data.length);
data.copy(this.hsdata);
} else {
var tmp = new Buffer(this.hsdata.length + data.length);
this.hsdata.copy(tmp);
data.copy(tmp, this.hsdata.length);
this.hsdata = tmp;
}
// Need moar buffer
if (this.hsdata.length <= 4)
return;
var size = this.hsdata.readUInt32LE(0);
if (size > 64) {
var err = new Error('transport error - wrong lowlevel protocol header');
callback(err);
self.emit('error', err);
return false;
}
// Handshake
var handshake = this.hsdata.toString('utf8', 4, 4 + size);
if (handshake == 'GBXRemote 1') {
// We dont support v1
self.protocol = 1;
// TODO: Fix error?
var handshakeParser = barse()
.readUInt32LE('length')
.string('handshake', 'length')
;
var dataParser = barse()
.readUInt32LE('length')
.readUInt32LE('reqhandle')
.string('xml', 'length')
;
// Pipe data to handshakeParser
this.socket.pipe(handshakeParser);
// Then switch to dataParser once handshakeParser is done
handshakeParser.once('data', function() {
self.socket.unpipe(handshakeParser);
self.socket.pipe(dataParser);
})
// HANDSHAKE
handshakeParser.once('data', function(data) {
if (data.handshake != 'GBXRemote 2') {
var err = new Error('transport error - wrong lowlevel protocol version');
callback(err);
self.emit('error', err);
return false;
} else if (handshake == 'GBXRemote 2') {
self.protocol = 2;
} else {
var err = new Error('transport error - wrong lowlevel protocol version');
callback(err);
self.emit('error', err);
return false;
return;
}
// Handshake successfull
self.protocol = 2;
self.isReady = true;
callback();
self.emit('connect');
};
var onData = function(data) {
if (data == null)
data = new Buffer(0);
if (this.buff == null) {
this.buff = new Buffer(data.length);
data.copy(this.buff);
} else {
// TODO: Use Buffer.concat()? - requires node v0.8!
var tmp = new Buffer(this.buff.length + data.length);
this.buff.copy(tmp);
data.copy(tmp, this.buff.length);
this.buff = tmp;
}
// Need moar buffer to read size
if (this.buff.length < 4)
return;
var targetSize = this.buff.readUInt32LE(0);
// headerSize = targetSize + reqhandle = 8
var headerSize = 8;
// Need moar buffer to read data
if (this.buff.length < headerSize + targetSize)
return;
var response = this.buff.toString('utf8', headerSize, headerSize + targetSize);
var reqhandle = this.buff.readUInt32LE(4);
});
dataParser.on('data', function(data) {
var deserializer = new Deserializer();

@@ -205,6 +157,6 @@

// Reponse
if (self.callbacks.hasOwnProperty(reqhandle)) {
deserializer.deserializeMethodResponse(response, function(a, b) {
self.callbacks[reqhandle].apply(this, arguments);
delete self.callbacks[reqhandle];
if (self.callbacks.hasOwnProperty(data.reqhandle)) {
deserializer.deserializeMethodResponse(data.xml, function(a, b) {
self.callbacks[data.reqhandle].apply(this, arguments);
delete self.callbacks[data.reqhandle];
});

@@ -214,3 +166,3 @@ }

else {
deserializer.deserializeMethodCall(response, function(err, method, res) {
deserializer.deserializeMethodCall(data.xml, function(err, method, res) {
if (err) {

@@ -221,3 +173,3 @@ // This should never happen....

//console.log(err);
console.warn('Not a response, nor a callback! (reqhandle: 0x%s)', reqhandle.toString(16));
console.warn('Not a response, nor a callback! (reqhandle: 0x%s)', data.reqhandle.toString(16));
return;

@@ -231,24 +183,2 @@ } else {

}
// Cut away this message...
var tmp = new Buffer(this.buff.length - headerSize - targetSize);
this.buff.copy(tmp, 0, headerSize + targetSize);
this.buff = tmp;
// ... and fake an onData call if more data left
if (this.buff.length) {
process.nextTick(function(){
onData()
});
}
};
// TODO: Fix the ondata callback, and its functions (kinda messy)
this.socket.on('data', function(data) {
// TODO: Do buffering here
if (!self.isReady)
doHandshake(data);
else
onData(data);
});

@@ -255,0 +185,0 @@ };

{ "name" : "gbxremote"
, "description" : "A pure JavaScript GBXRemote client."
, "keywords" : [ "xml-rpc", "xmlrpc", "xml", "rpc", "gbxremote", "maniaplanet", "trackmania", "shootmania", "questmania", "nadeo" ]
, "version" : "0.1.3"
, "version" : "0.1.4"
, "preferGlobal" : false

@@ -22,2 +22,3 @@ , "homepage" : "https://github.com/MiniGod/node-gbxremote"

, "xmlbuilder" : "0.3.1"
, "barse" : "~0.4.2"
}

@@ -24,0 +25,0 @@ , "devDependencies" : {

@@ -63,3 +63,3 @@ Node-GbxRemote

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

@@ -66,0 +66,0 @@ [See the full list of methods.](http://methods.xaseco.org/methodstmc.php)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc