mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2025-05-06 03:11:05 -04:00
added debug() method for NODE_DEBUG=mc-proto
This commit is contained in:
parent
0ff49078ff
commit
b699d5506a
2 changed files with 17 additions and 0 deletions
|
@ -4,6 +4,7 @@ var net = require('net')
|
|||
, protocol = require('./protocol')
|
||||
, createPacketBuffer = protocol.createPacketBuffer
|
||||
, parsePacket = protocol.parsePacket
|
||||
, debug = protocol.debug
|
||||
|
||||
module.exports = Client;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var assert = require('assert');
|
||||
var util = require('util');
|
||||
|
||||
var STRING_MAX_LENGTH = 240;
|
||||
|
||||
|
@ -500,6 +501,20 @@ var types = {
|
|||
'stringArray': [readStringArray, writeStringArray, sizeOfStringArray],
|
||||
};
|
||||
|
||||
var debug;
|
||||
if (process.env.NODE_DEBUG && /(minecraft-protocol|mc-proto)/.test(process.env.NODE_DEBUG)) {
|
||||
var pid = process.pid;
|
||||
debug = function(x) {
|
||||
// if console is not set up yet, then skip this.
|
||||
if (!console.error)
|
||||
return;
|
||||
console.error('MC-PROTO: %d', pid,
|
||||
util.format.apply(util, arguments).slice(0, 500));
|
||||
};
|
||||
} else {
|
||||
debug = function() { };
|
||||
}
|
||||
|
||||
function sizeOfByteArray32(value) {
|
||||
return 4 + value.length;
|
||||
}
|
||||
|
@ -1273,4 +1288,5 @@ module.exports = {
|
|||
STRING_MAX_LENGTH: STRING_MAX_LENGTH,
|
||||
packets: packets,
|
||||
get: get,
|
||||
debug: debug,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue