Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bukkit-stats

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bukkit-stats - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

lib/colors.js

64

lib/bukkit-stats.js
// module dependencies
var events = require("events")
var colors = require("./colors")
, sanitize = require("sanitize-arguments")
, events = require("events")
, net = require("net")

@@ -17,21 +19,11 @@ , util = require("util");

// constructor
function Stats(host, port, cb) {
function Stats(host, port, colorize, cb) {
// ensure that the object is instanciated with the new operator
if(!(this instanceof Stats)) return new Stats(host, port, cb);
if(!(this instanceof Stats)) return new Stats(host, port, colorize, cb);
// parse the arguments
if(typeof host == "string" && ~host.indexOf(":")) {
host = host.split(":");
this.config = { host: host[0], port: host[1] };
} else {
this.config = {
host: typeof host == "string" ? host : CONNECTION.defaultHost,
port: typeof port == "number" ? port : CONNECTION.defaultPort
};
}
this.config = sanitize(arguments, Stats, [
[CONNECTION.defaultHost], [CONNECTION.defaultPort], [false], [function() {}]
]);
if(typeof host == "function") cb = host;
else if(typeof port == "function") cb = port;
else if(typeof cb != "function") cb = function() {};
// start the event listener

@@ -41,3 +33,3 @@ events.EventEmitter.call(this);

// register the callback
this.on("stats", cb);
this.on("stats", this.config.cb);

@@ -60,8 +52,8 @@ // fire the request

// listen on the response
socket.once("data", wrap(this.handleResponse, this, socket, startTime));
socket.once("data", this.handleResponse.bind(this, socket, startTime));
// listen on errors
socket.once("error", wrap(this.handleError, this, "error"));
socket.once("timeout", wrap(this.handleError, this, "timeout"));
socket.once("close", wrap(this.handleError, this, "close"));
socket.once("error", this.handleError.bind(this, "error"));
socket.once("timeout", this.handleError.bind(this, "timeout"));
socket.once("close", this.handleError.bind(this, "close"));

@@ -75,9 +67,10 @@ // send the magic packet

switch(type) {
case "timeout": this.emit("error", new Error(ERRORS.timeout)); break;
case "close": this.emit("error", new Error(ERRORS.close)); break;
case "format": this.emit("error", new Error(ERRORS.format)); break;
case "error":
default:
error.message = ERRORS.unknown + error.message;
this.emit("error", error);
break;
case "timeout": this.emit("error", new Error(ERRORS.timeout)); break;
case "close": this.emit("error", new Error(ERRORS.close)); break;
case "format": this.emit("error", new Error(ERRORS.format)); break;
}

@@ -110,3 +103,3 @@ };

// append a 0x00 to the buffer, because Bukkit forget it
// append a 0x00 to the buffer, because Bukkit forgot it
buffer = Buffer.concat([buffer, new Buffer([CTRL.missingByte])]);

@@ -117,15 +110,12 @@

// find the subparts
var maxPlayers = parseInt(res.pop())
, onlinePlayers = parseInt(res.pop())
, motd = res.join(String.fromCharCode(CTRL.color));
return {
motd: res[0],
onlinePlayers: parseInt(res[1]),
maxPlayers: parseInt(res[2])
motd: this.config.colorize ? colors(motd) : motd,
onlinePlayers: onlinePlayers,
maxPlayers: maxPlayers
};
};
// helper function
function wrap(fn, ref) {
var args = Array.prototype.slice.call(arguments, 2);
return function() {
fn.apply(ref, args.concat(Array.prototype.slice.call(arguments)));
};
}
};

@@ -83,2 +83,3 @@ exports.PACKETS = {

delimeter: 0xA7,
color: 0xA7,
missingByte: 0x00

@@ -97,2 +98,28 @@ };

format: "Server returned an invalid response!"
};
exports.COLORS = {
"0": "black",
"1": "blue",
"2": "green",
"3": "cyan",
"4": "red",
"5": "magenta",
"5": "yellow",
"7": "grey",
"8": "grey",
"9": "blue",
"a": "green",
"b": "cyan",
"c": "red",
"d": "magenta",
"e": "yellow",
"f": "white",
"k": "inverse",
"l": "bold",
"m": "inverse",
"n": "underline",
"o": "italic",
"r": "reset",
"reset": "r"
};
{
"name": "bukkit-stats",
"version": "1.0.1",
"version": "1.1.0",
"description": "Gets a server's stats displayed in the client serverlist",

@@ -19,3 +19,7 @@ "main": "index.js",

"author": "Jan Buschtöns <buschtoens@gmail.com>",
"license": "MIT"
"license": "MIT",
"dependencies": {
"colors": "*",
"sanitize-arguments": "*"
}
}
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