Permalink
Browse files

Fieldnames, documentation and examples

* Changed some fieldnames in the returned object for full_stat.
* Link to protocol documentation in README
* Added Example
  • Loading branch information...
1 parent c87ff03 commit b6ff3e6363db933391b904c601ec5fe86bb87d69 @kmpm committed Nov 21, 2011
Showing with 44 additions and 6 deletions.
  1. +4 −0 README.md
  2. +23 −0 examples/app.js
  3. +15 −3 mcquery.js
  4. +2 −3 test/base-test.js
View
@@ -1,3 +1,7 @@
# Node-MCQuery
A library for accessing a Minecraft server using the Query protocol
+
+## References ##
+* http://wiki.vg/Query
+
View
@@ -0,0 +1,23 @@
+var Query = require('../mcquery');
+
+var query = new Query();
+
+query.startSession('localhost', 25565, function(err, session){
+ if(err){
+ console.error(err);
+ }
+ else{
+ query.full_stat(session, statCallback);
+ }
+});
+
+
+function statCallback(err, stat){
+ if(err){
+ console.error(err);
+ }
+ else{
+ console.log(stat);
+ }
+ query.close();
+};
View
@@ -64,7 +64,7 @@ function readPacket(data){
else {
var offset=r.offset;
res.splitnum = r.text;
- res.extra1 = data.readUInt16LE(offset);offset+=2;
+ res.key_val_start = data.readUInt16LE(offset);offset+=2;
var key;
var value;
while(data.readUInt16LE(offset) !== 256){
@@ -74,7 +74,7 @@ function readPacket(data){
value = r.text;
res[key]=value;
}
- res.extra2 = data.readUInt16LE(offset);offset+=2;
+ res.key_val_end = data.readUInt16LE(offset);offset+=2;
r = readString(data, offset); offset=r.offset;
key = r.text;
@@ -189,7 +189,15 @@ var Query = module.exports = function Query(){
this.full_stat = function(session, callback){
var b = new Buffer(4);
b.fill(0);
- this.send(session, STAT_TYPE, b, callback );
+ this.send(session, STAT_TYPE, b, function(err, res){
+ if(err)callback(err);
+ else{
+ delete res.type;
+ delete res.idToken;
+ delete res.rinfo;
+ callback(null, res);
+ }
+ });
}
this.send = function(session, type, payloadBuffer, callback){
@@ -206,6 +214,10 @@ var Query = module.exports = function Query(){
}
});
};
+
+ this.close = function(){
+ socket.close();
+ }
View
@@ -79,18 +79,17 @@ vows.describe('GS4 Query').addBatch({
},
'returns a full stat object':function(err, stat){
assert.isObject(stat);
- var props = ['splitnum', 'extra1'
+ var props = ['splitnum', 'key_val_start'
, 'hostname', 'gametype'
, 'game_id', 'version'
, 'plugins', 'map'
, 'numplayers', 'maxplayers'
, 'hostport', 'hostip'
- , 'extra2', 'player_'];
+ , 'key_val_end', 'player_'];
for(var i=0; i<props.length;i++){
assert.include(stat, props[i]);
}
assert.isArray(stat.player_);
-
}
}//topic full_stat
}//topic startSession

0 comments on commit b6ff3e6

Please sign in to comment.