mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-10-04 00:21:12 -04:00
var -> const/let in examples and tests
This commit is contained in:
parent
4a33bc7ac7
commit
79f82afb91
110
.jshintrc
110
.jshintrc
@ -1,110 +0,0 @@
|
|||||||
{
|
|
||||||
// Settings
|
|
||||||
"passfail": false,
|
|
||||||
// Stop on first error.
|
|
||||||
"maxerr": 100,
|
|
||||||
// Maximum errors before stopping.
|
|
||||||
|
|
||||||
|
|
||||||
// Predefined globals whom JSHint will ignore.
|
|
||||||
"browser": false,
|
|
||||||
// Standard browser globals e.g. `window`, `document`.
|
|
||||||
"predef": [
|
|
||||||
// extra globals
|
|
||||||
"describe",
|
|
||||||
"beforeEach",
|
|
||||||
"afterEach",
|
|
||||||
"before",
|
|
||||||
"after",
|
|
||||||
"it"
|
|
||||||
],
|
|
||||||
"node": true,
|
|
||||||
"rhino": false,
|
|
||||||
"couch": false,
|
|
||||||
"wsh": false,
|
|
||||||
// Windows Scripting Host.
|
|
||||||
|
|
||||||
"jquery": false,
|
|
||||||
"prototypejs": false,
|
|
||||||
"mootools": false,
|
|
||||||
"dojo": false,
|
|
||||||
// Development.
|
|
||||||
"debug": true,
|
|
||||||
// Allow debugger statements e.g. browser breakpoints.
|
|
||||||
"devel": true,
|
|
||||||
// Allow development statements e.g. `console.log();`.
|
|
||||||
|
|
||||||
|
|
||||||
// EcmaScript 5.
|
|
||||||
"es5": true,
|
|
||||||
// Allow EcmaScript 5 syntax.
|
|
||||||
"strict": false,
|
|
||||||
// Require `use strict` pragma in every file.
|
|
||||||
"globalstrict": true,
|
|
||||||
// Allow global "use strict" (also enables 'strict').
|
|
||||||
|
|
||||||
|
|
||||||
// The Good Parts.
|
|
||||||
"asi": true,
|
|
||||||
// Tolerate Automatic Semicolon Insertion (no semicolons).
|
|
||||||
"laxbreak": false,
|
|
||||||
// Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
|
|
||||||
"laxcomma": true,
|
|
||||||
"bitwise": false,
|
|
||||||
// Prohibit bitwise operators (&, |, ^, etc.).
|
|
||||||
"boss": true,
|
|
||||||
// Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
|
|
||||||
"curly": false,
|
|
||||||
// Require {} for every new block or scope.
|
|
||||||
"eqeqeq": true,
|
|
||||||
// Require triple equals i.e. `===`.
|
|
||||||
"eqnull": true,
|
|
||||||
// Tolerate use of `== null`.
|
|
||||||
"evil": false,
|
|
||||||
// Tolerate use of `eval`.
|
|
||||||
"expr": false,
|
|
||||||
// Tolerate `ExpressionStatement` as Programs.
|
|
||||||
"forin": false,
|
|
||||||
// Prohibt `for in` loops without `hasOwnProperty`.
|
|
||||||
"immed": true,
|
|
||||||
// Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
|
|
||||||
"latedef": false,
|
|
||||||
// Prohibit variable use before definition.
|
|
||||||
"loopfunc": false,
|
|
||||||
// Allow functions to be defined within loops.
|
|
||||||
"noarg": true,
|
|
||||||
// Prohibit use of `arguments.caller` and `arguments.callee`.
|
|
||||||
"regexp": false,
|
|
||||||
// Prohibit `.` and `[^...]` in regular expressions.
|
|
||||||
"regexdash": false,
|
|
||||||
// Tolerate unescaped last dash i.e. `[-...]`.
|
|
||||||
"scripturl": false,
|
|
||||||
// Tolerate script-targeted URLs.
|
|
||||||
"shadow": false,
|
|
||||||
// Allows re-define variables later in code e.g. `var x=1; x=2;`.
|
|
||||||
"supernew": false,
|
|
||||||
// Tolerate `new function () { ... };` and `new Object;`.
|
|
||||||
"undef": true,
|
|
||||||
// Require all non-global variables be declared before they are used.
|
|
||||||
|
|
||||||
|
|
||||||
// Persone styling prefrences.
|
|
||||||
"newcap": true,
|
|
||||||
// Require capitalization of all constructor functions e.g. `new F()`.
|
|
||||||
"noempty": true,
|
|
||||||
// Prohibit use of empty blocks.
|
|
||||||
"nonew": true,
|
|
||||||
// Prohibit use of constructors for side-effects.
|
|
||||||
"nomen": false,
|
|
||||||
// Prohibit use of initial or trailing underbars in names.
|
|
||||||
"onevar": false,
|
|
||||||
// Allow only one `var` statement per function.
|
|
||||||
"plusplus": false,
|
|
||||||
// Prohibit use of `++` & `--`.
|
|
||||||
"sub": false,
|
|
||||||
// Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
|
|
||||||
"trailing": true,
|
|
||||||
// Prohibit trailing whitespaces.
|
|
||||||
"white": false
|
|
||||||
// Check against strict whitespace and indentation rules.
|
|
||||||
}
|
|
@ -1,13 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var mc = require('minecraft-protocol');
|
const mc = require('minecraft-protocol');
|
||||||
|
|
||||||
if(process.argv.length < 4 || process.argv.length > 6) {
|
if(process.argv.length < 4 || process.argv.length > 6) {
|
||||||
console.log("Usage : node echo.js <host> <port> [<name>] [<password>]");
|
console.log("Usage : node echo.js <host> <port> [<name>] [<password>]");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
version: false,
|
version: false,
|
||||||
host: process.argv[2],
|
host: process.argv[2],
|
||||||
port: parseInt(process.argv[3]),
|
port: parseInt(process.argv[3]),
|
||||||
@ -22,10 +22,10 @@ client.on('disconnect', function(packet) {
|
|||||||
console.log('disconnected: '+ packet.reason);
|
console.log('disconnected: '+ packet.reason);
|
||||||
});
|
});
|
||||||
client.on('chat', function(packet) {
|
client.on('chat', function(packet) {
|
||||||
var jsonMsg = JSON.parse(packet.message);
|
const jsonMsg = JSON.parse(packet.message);
|
||||||
if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
|
if(jsonMsg.translate === 'chat.type.announcement' || jsonMsg.translate === 'chat.type.text') {
|
||||||
var username = jsonMsg.with[0].text;
|
const username = jsonMsg.with[0].text;
|
||||||
var msg = jsonMsg.with[1];
|
const msg = jsonMsg.with[1];
|
||||||
if(username === client.username) return;
|
if(username === client.username) return;
|
||||||
client.write('chat', {message: msg});
|
client.write('chat', {message: msg});
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
var ProtoDef = require('protodef').ProtoDef;
|
const mc = require('minecraft-protocol');
|
||||||
var mc = require('minecraft-protocol');
|
|
||||||
|
|
||||||
var proto = new ProtoDef();
|
|
||||||
|
|
||||||
if(process.argv.length < 4 || process.argv.length > 6) {
|
if(process.argv.length < 4 || process.argv.length > 6) {
|
||||||
console.log("Usage : node client_channel.js <host> <port> [<name>] [<password>]");
|
console.log("Usage : node client_channel.js <host> <port> [<name>] [<password>]");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var client = mc.createClient({version: false,
|
const client = mc.createClient({
|
||||||
|
version: false,
|
||||||
host: process.argv[2],
|
host: process.argv[2],
|
||||||
port: parseInt(process.argv[3]),
|
port: parseInt(process.argv[3]),
|
||||||
username: process.argv[4] ? process.argv[4] : "test",
|
username: process.argv[4] ? process.argv[4] : "test",
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
var readline = require('readline');
|
const readline = require('readline');
|
||||||
var color = require("ansi-color").set;
|
const color = require("ansi-color").set;
|
||||||
var mc = require('minecraft-protocol');
|
const mc = require('minecraft-protocol');
|
||||||
var states = mc.states;
|
const states = mc.states;
|
||||||
var util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
var colors = {
|
const colors = {
|
||||||
"black": 'black+white_bg',
|
"black": 'black+white_bg',
|
||||||
"dark_blue": 'blue',
|
"dark_blue": 'blue',
|
||||||
"dark_green": 'green',
|
"dark_green": 'green',
|
||||||
@ -29,7 +29,7 @@ var colors = {
|
|||||||
"reset": 'white+black_bg'
|
"reset": 'white+black_bg'
|
||||||
};
|
};
|
||||||
|
|
||||||
var dictionary = {
|
const dictionary = {
|
||||||
"chat.stream.emote": "(%s) * %s %s",
|
"chat.stream.emote": "(%s) * %s %s",
|
||||||
"chat.stream.text": "(%s) <%s> %s",
|
"chat.stream.text": "(%s) <%s> %s",
|
||||||
"chat.type.achievement": "%s has just earned the achievement %s",
|
"chat.type.achievement": "%s has just earned the achievement %s",
|
||||||
@ -39,7 +39,7 @@ var dictionary = {
|
|||||||
"chat.type.text": "<%s> %s"
|
"chat.type.text": "<%s> %s"
|
||||||
};
|
};
|
||||||
|
|
||||||
var rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout,
|
output: process.stdout,
|
||||||
terminal: false
|
terminal: false
|
||||||
@ -56,18 +56,18 @@ if(process.argv.length < 5) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process.argv.forEach(function(val) {
|
process.argv.forEach(function(val) {
|
||||||
if(val == "-h") {
|
if(val === "-h") {
|
||||||
print_help();
|
print_help();
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var host = process.argv[2];
|
let host = process.argv[2];
|
||||||
var port = parseInt(process.argv[3]);
|
let port = parseInt(process.argv[3]);
|
||||||
var user = process.argv[4];
|
const user = process.argv[4];
|
||||||
var passwd = process.argv[5];
|
const passwd = process.argv[5];
|
||||||
|
|
||||||
if(host.indexOf(':') != -1) {
|
if(host.indexOf(':') !== -1) {
|
||||||
port = host.substring(host.indexOf(':') + 1);
|
port = host.substring(host.indexOf(':') + 1);
|
||||||
host = host.substring(0, host.indexOf(':'));
|
host = host.substring(0, host.indexOf(':'));
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ if(host.indexOf(':') != -1) {
|
|||||||
console.log("connecting to " + host + ":" + port);
|
console.log("connecting to " + host + ":" + port);
|
||||||
console.log("user: " + user);
|
console.log("user: " + user);
|
||||||
|
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
host: host,
|
host: host,
|
||||||
port: port,
|
port: port,
|
||||||
username: user,
|
username: user,
|
||||||
@ -87,7 +87,7 @@ client.on('kick_disconnect', function(packet) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
var chats = [];
|
const chats = [];
|
||||||
|
|
||||||
client.on('connect', function() {
|
client.on('connect', function() {
|
||||||
console.info(color('Successfully connected to ' + host + ':' + port, "blink+green"));
|
console.info(color('Successfully connected to ' + host + ':' + port, "blink+green"));
|
||||||
@ -117,13 +117,13 @@ client.on('state', function(newState) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
rl.on('line', function(line) {
|
rl.on('line', function(line) {
|
||||||
if(line == '') {
|
if(line === '') {
|
||||||
return;
|
return;
|
||||||
} else if(line == '/quit') {
|
} else if(line === '/quit') {
|
||||||
console.info('Disconnected from ' + host + ':' + port);
|
console.info('Disconnected from ' + host + ':' + port);
|
||||||
client.end();
|
client.end();
|
||||||
return;
|
return;
|
||||||
} else if(line == '/end') {
|
} else if(line === '/end') {
|
||||||
console.info('Forcibly ended client');
|
console.info('Forcibly ended client');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
return;
|
return;
|
||||||
@ -134,14 +134,14 @@ rl.on('line', function(line) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.on('chat', function(packet) {
|
client.on('chat', function(packet) {
|
||||||
var j = JSON.parse(packet.message);
|
const j = JSON.parse(packet.message);
|
||||||
var chat = parseChat(j, {});
|
const chat = parseChat(j, {});
|
||||||
console.info(chat);
|
console.info(chat);
|
||||||
});
|
});
|
||||||
|
|
||||||
function parseChat(chatObj, parentState) {
|
function parseChat(chatObj, parentState) {
|
||||||
function getColorize(parentState) {
|
function getColorize(parentState) {
|
||||||
var myColor = "";
|
let myColor = "";
|
||||||
if('color' in parentState) myColor += colors[parentState.color] + "+";
|
if('color' in parentState) myColor += colors[parentState.color] + "+";
|
||||||
if(parentState.bold) myColor += "bold+";
|
if(parentState.bold) myColor += "bold+";
|
||||||
if(parentState.underlined) myColor += "underline+";
|
if(parentState.underlined) myColor += "underline+";
|
||||||
@ -153,7 +153,7 @@ function parseChat(chatObj, parentState) {
|
|||||||
if(typeof chatObj === "string") {
|
if(typeof chatObj === "string") {
|
||||||
return color(chatObj, getColorize(parentState));
|
return color(chatObj, getColorize(parentState));
|
||||||
} else {
|
} else {
|
||||||
var chat = "";
|
let chat = "";
|
||||||
if('color' in chatObj) parentState.color = chatObj['color'];
|
if('color' in chatObj) parentState.color = chatObj['color'];
|
||||||
if('bold' in chatObj) parentState.bold = chatObj['bold'];
|
if('bold' in chatObj) parentState.bold = chatObj['bold'];
|
||||||
if('italic' in chatObj) parentState.italic = chatObj['italic'];
|
if('italic' in chatObj) parentState.italic = chatObj['italic'];
|
||||||
@ -164,7 +164,7 @@ function parseChat(chatObj, parentState) {
|
|||||||
if('text' in chatObj) {
|
if('text' in chatObj) {
|
||||||
chat += color(chatObj.text, getColorize(parentState));
|
chat += color(chatObj.text, getColorize(parentState));
|
||||||
} else if('translate' in chatObj && dictionary.hasOwnProperty(chatObj.translate)) {
|
} else if('translate' in chatObj && dictionary.hasOwnProperty(chatObj.translate)) {
|
||||||
var args = [dictionary[chatObj.translate]];
|
const args = [dictionary[chatObj.translate]];
|
||||||
chatObj['with'].forEach(function(s) {
|
chatObj['with'].forEach(function(s) {
|
||||||
args.push(parseChat(s, parentState));
|
args.push(parseChat(s, parentState));
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
var mc = require('minecraft-protocol');
|
const mc = require('minecraft-protocol');
|
||||||
|
|
||||||
if(process.argv.length < 4 || process.argv.length > 6) {
|
if(process.argv.length < 4 || process.argv.length > 6) {
|
||||||
console.log("Usage : node client_channel.js <host> <port> [<name>] [<password>]");
|
console.log("Usage : node client_channel.js <host> <port> [<name>] [<password>]");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
host: process.argv[2],
|
host: process.argv[2],
|
||||||
port: parseInt(process.argv[3]),
|
port: parseInt(process.argv[3]),
|
||||||
username: process.argv[4] ? process.argv[4] : "test",
|
username: process.argv[4] ? process.argv[4] : "test",
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
var mc = require('minecraft-protocol');
|
const mc = require('minecraft-protocol');
|
||||||
|
|
||||||
if(process.argv.length < 4 || process.argv.length > 6) {
|
if(process.argv.length < 4 || process.argv.length > 6) {
|
||||||
console.log("Usage : node echo.js <host> <port> [<name>] [<password>]");
|
console.log("Usage : node echo.js <host> <port> [<name>] [<password>]");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var customPackets={
|
const customPackets = {
|
||||||
"1.8": {
|
"1.8": {
|
||||||
"play": {
|
"play": {
|
||||||
"toClient": {
|
"toClient": {
|
||||||
@ -57,7 +57,7 @@ var customPackets={
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
host: process.argv[2],
|
host: process.argv[2],
|
||||||
port: parseInt(process.argv[3]),
|
port: parseInt(process.argv[3]),
|
||||||
username: process.argv[4] ? process.argv[4] : "echo",
|
username: process.argv[4] ? process.argv[4] : "echo",
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
var mc = require('minecraft-protocol');
|
const mc = require('minecraft-protocol');
|
||||||
|
|
||||||
if(process.argv.length < 4 || process.argv.length > 6) {
|
if(process.argv.length < 4 || process.argv.length > 6) {
|
||||||
console.log("Usage : node echo.js <host> <port> [<name>] [<password>]");
|
console.log("Usage : node echo.js <host> <port> [<name>] [<password>]");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
host: process.argv[2],
|
host: process.argv[2],
|
||||||
port: parseInt(process.argv[3]),
|
port: parseInt(process.argv[3]),
|
||||||
username: process.argv[4] ? process.argv[4] : "echo",
|
username: process.argv[4] ? process.argv[4] : "echo",
|
||||||
@ -22,10 +22,10 @@ client.on('end', function(err) {
|
|||||||
console.log('Connection lost');
|
console.log('Connection lost');
|
||||||
});
|
});
|
||||||
client.on('chat', function(packet) {
|
client.on('chat', function(packet) {
|
||||||
var jsonMsg = JSON.parse(packet.message);
|
const jsonMsg = JSON.parse(packet.message);
|
||||||
if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
|
if(jsonMsg.translate === 'chat.type.announcement' || jsonMsg.translate === 'chat.type.text') {
|
||||||
var username = jsonMsg.with[0].text;
|
const username = jsonMsg.with[0].text;
|
||||||
var msg = jsonMsg.with[1];
|
const msg = jsonMsg.with[1];
|
||||||
if(username === client.username) return;
|
if(username === client.username) return;
|
||||||
client.write('chat', {message: msg});
|
client.write('chat', {message: msg});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
var mc = require('minecraft-protocol');
|
const mc = require('minecraft-protocol');
|
||||||
|
|
||||||
var states = mc.states;
|
const states = mc.states;
|
||||||
function printHelpAndExit(exitCode) {
|
function printHelpAndExit(exitCode) {
|
||||||
console.log("usage: node proxy.js [<options>...] <target_srv> <version>");
|
console.log("usage: node proxy.js [<options>...] <target_srv> <version>");
|
||||||
console.log("options:");
|
console.log("options:");
|
||||||
@ -32,24 +32,24 @@ process.argv.forEach(function(val) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
var host;
|
let host;
|
||||||
var port = 25565;
|
let port = 25565;
|
||||||
var version;
|
let version;
|
||||||
|
|
||||||
var printAllNames = false;
|
let printAllNames = false;
|
||||||
var printNameWhitelist = {};
|
const printNameWhitelist = {};
|
||||||
var printNameBlacklist = {};
|
const printNameBlacklist = {};
|
||||||
(function() {
|
(function() {
|
||||||
for(var i = 0; i < args.length; i++) {
|
for(let i = 0; i < args.length; i++) {
|
||||||
var option = args[i];
|
const option = args[i];
|
||||||
if(!/^-/.test(option)) break;
|
if(!/^-/.test(option)) break;
|
||||||
if(option === "--dump-all") {
|
if(option === "--dump-all") {
|
||||||
printAllNames = true;
|
printAllNames = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
var name = args[i];
|
const name = args[i];
|
||||||
if(option === "--dump") {
|
if(option === "--dump") {
|
||||||
printNameWhitelist[name] = "io";
|
printNameWhitelist[name] = "io";
|
||||||
} else if(option === "-x") {
|
} else if(option === "-x") {
|
||||||
@ -68,17 +68,17 @@ if(host.indexOf(':') !== -1) {
|
|||||||
host = host.substring(0, host.indexOf(':'));
|
host = host.substring(0, host.indexOf(':'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var srv = mc.createServer({
|
const srv = mc.createServer({
|
||||||
'online-mode': false,
|
'online-mode': false,
|
||||||
port: 25566,
|
port: 25566,
|
||||||
keepAlive: false,
|
keepAlive: false,
|
||||||
version:version
|
version:version
|
||||||
});
|
});
|
||||||
srv.on('login', function(client) {
|
srv.on('login', function(client) {
|
||||||
var addr = client.socket.remoteAddress;
|
const addr = client.socket.remoteAddress;
|
||||||
console.log('Incoming connection', '(' + addr + ')');
|
console.log('Incoming connection', '(' + addr + ')');
|
||||||
var endedClient = false;
|
let endedClient = false;
|
||||||
var endedTargetClient = false;
|
let endedTargetClient = false;
|
||||||
client.on('end', function() {
|
client.on('end', function() {
|
||||||
endedClient = true;
|
endedClient = true;
|
||||||
console.log('Connection closed by client', '(' + addr + ')');
|
console.log('Connection closed by client', '(' + addr + ')');
|
||||||
@ -92,7 +92,7 @@ srv.on('login', function(client) {
|
|||||||
if(!endedTargetClient)
|
if(!endedTargetClient)
|
||||||
targetClient.end("Error");
|
targetClient.end("Error");
|
||||||
});
|
});
|
||||||
var targetClient = mc.createClient({
|
const targetClient = mc.createClient({
|
||||||
host: host,
|
host: host,
|
||||||
port: port,
|
port: port,
|
||||||
username: client.username,
|
username: client.username,
|
||||||
@ -125,12 +125,12 @@ srv.on('login', function(client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var bufferEqual = require('buffer-equal');
|
const bufferEqual = require('buffer-equal');
|
||||||
targetClient.on('raw', function(buffer, meta) {
|
targetClient.on('raw', function(buffer, meta) {
|
||||||
if(client.state !== states.PLAY || meta.state !== states.PLAY)
|
if(client.state !== states.PLAY || meta.state !== states.PLAY)
|
||||||
return;
|
return;
|
||||||
var packetData = targetClient.deserializer.parsePacketBuffer(buffer).data.params;
|
const packetData = targetClient.deserializer.parsePacketBuffer(buffer).data.params;
|
||||||
var packetBuff = client.serializer.createPacketBuffer({name:meta.name, params:packetData});
|
const packetBuff = client.serializer.createPacketBuffer({name:meta.name, params:packetData});
|
||||||
if(!bufferEqual(buffer, packetBuff)) {
|
if(!bufferEqual(buffer, packetBuff)) {
|
||||||
console.log("client<-server: Error in packet " + meta.state + "." + meta.name);
|
console.log("client<-server: Error in packet " + meta.state + "." + meta.name);
|
||||||
console.log("received buffer",buffer.toString('hex'));
|
console.log("received buffer",buffer.toString('hex'));
|
||||||
@ -149,8 +149,8 @@ srv.on('login', function(client) {
|
|||||||
client.on('raw', function(buffer, meta) {
|
client.on('raw', function(buffer, meta) {
|
||||||
if(meta.state !== states.PLAY || targetClient.state !== states.PLAY)
|
if(meta.state !== states.PLAY || targetClient.state !== states.PLAY)
|
||||||
return;
|
return;
|
||||||
var packetData = client.deserializer.parsePacketBuffer(buffer).data.params;
|
const packetData = client.deserializer.parsePacketBuffer(buffer).data.params;
|
||||||
var packetBuff = targetClient.serializer.createPacketBuffer({name:meta.name, params:packetData});
|
const packetBuff = targetClient.serializer.createPacketBuffer({name:meta.name, params:packetData});
|
||||||
if(!bufferEqual(buffer, packetBuff)) {
|
if(!bufferEqual(buffer, packetBuff)) {
|
||||||
console.log("client->server: Error in packet " + meta.state + "." + meta.name);
|
console.log("client->server: Error in packet " + meta.state + "." + meta.name);
|
||||||
console.log("received buffer",buffer.toString('hex'));
|
console.log("received buffer",buffer.toString('hex'));
|
||||||
@ -180,6 +180,6 @@ function shouldDump(name, direction) {
|
|||||||
return matches(printNameWhitelist[name]);
|
return matches(printNameWhitelist[name]);
|
||||||
|
|
||||||
function matches(result) {
|
function matches(result) {
|
||||||
return result != null && result.indexOf(direction) !== -1;
|
return result !== null && result.indexOf(direction) !== -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
var mc = require('minecraft-protocol');
|
const mc = require('minecraft-protocol');
|
||||||
|
|
||||||
var options = {
|
const options = {
|
||||||
motd: 'Vox Industries',
|
motd: 'Vox Industries',
|
||||||
'max-players': 127,
|
'max-players': 127,
|
||||||
port: 25565,
|
port: 25565,
|
||||||
'online-mode': false
|
'online-mode': false
|
||||||
};
|
};
|
||||||
|
|
||||||
var server = mc.createServer(options);
|
const server = mc.createServer(options);
|
||||||
|
|
||||||
server.on('login', function(client) {
|
server.on('login', function(client) {
|
||||||
broadcast(client.username + ' joined the game.');
|
broadcast(client.username + ' joined the game.');
|
||||||
var addr = client.socket.remoteAddress + ':' + client.socket.remotePort;
|
const addr = client.socket.remoteAddress + ':' + client.socket.remotePort;
|
||||||
console.log(client.username + ' connected', '(' + addr + ')');
|
console.log(client.username + ' connected', '(' + addr + ')');
|
||||||
|
|
||||||
client.on('end', function() {
|
client.on('end', function() {
|
||||||
@ -39,7 +39,7 @@ server.on('login', function(client) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.on('chat', function(data) {
|
client.on('chat', function(data) {
|
||||||
var message = '<' + client.username + '>' + ' ' + data.message;
|
const message = '<' + client.username + '>' + ' ' + data.message;
|
||||||
broadcast(message, null, client.username);
|
broadcast(message, null, client.username);
|
||||||
console.log(message);
|
console.log(message);
|
||||||
});
|
});
|
||||||
@ -54,15 +54,15 @@ server.on('listening', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function broadcast(message, exclude, username) {
|
function broadcast(message, exclude, username) {
|
||||||
var client, translate;
|
let client, translate;
|
||||||
translate = username ? 'chat.type.announcement' : 'chat.type.text';
|
translate = username ? 'chat.type.announcement' : 'chat.type.text';
|
||||||
username = username || 'Server';
|
username = username || 'Server';
|
||||||
for(var clientId in server.clients) {
|
for(const clientId in server.clients) {
|
||||||
if(!server.clients.hasOwnProperty(clientId)) continue;
|
if(!server.clients.hasOwnProperty(clientId)) continue;
|
||||||
|
|
||||||
client = server.clients[clientId];
|
client = server.clients[clientId];
|
||||||
if(client !== exclude) {
|
if(client !== exclude) {
|
||||||
var msg = {
|
const msg = {
|
||||||
translate: translate,
|
translate: translate,
|
||||||
"with": [
|
"with": [
|
||||||
username,
|
username,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
var mc = require('minecraft-protocol');
|
const mc = require('minecraft-protocol');
|
||||||
|
|
||||||
var server = mc.createServer({
|
const server = mc.createServer({
|
||||||
'online-mode': false, // optional
|
'online-mode': false, // optional
|
||||||
encryption: false, // optional
|
encryption: false, // optional
|
||||||
host: '0.0.0.0', // optional
|
host: '0.0.0.0', // optional
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
var mc = require('minecraft-protocol');
|
const mc = require('minecraft-protocol');
|
||||||
|
|
||||||
var server = mc.createServer({
|
const server = mc.createServer({
|
||||||
'online-mode': false, // optional
|
'online-mode': false, // optional
|
||||||
encryption: false, // optional
|
encryption: false, // optional
|
||||||
host: '0.0.0.0', // optional
|
host: '0.0.0.0', // optional
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
var mc = require('minecraft-protocol');
|
const mc = require('minecraft-protocol');
|
||||||
|
|
||||||
var options = {
|
const options = {
|
||||||
'online-mode': true
|
'online-mode': true
|
||||||
};
|
};
|
||||||
|
|
||||||
var server = mc.createServer(options);
|
const server = mc.createServer(options);
|
||||||
|
|
||||||
server.on('login', function(client) {
|
server.on('login', function(client) {
|
||||||
var addr = client.socket.remoteAddress;
|
const addr = client.socket.remoteAddress;
|
||||||
console.log('Incoming connection', '(' + addr + ')');
|
console.log('Incoming connection', '(' + addr + ')');
|
||||||
|
|
||||||
client.on('end', function() {
|
client.on('end', function() {
|
||||||
@ -38,7 +38,7 @@ server.on('login', function(client) {
|
|||||||
flags: 0x00
|
flags: 0x00
|
||||||
});
|
});
|
||||||
|
|
||||||
var msg = {
|
const msg = {
|
||||||
translate: 'chat.type.announcement',
|
translate: 'chat.type.announcement',
|
||||||
"with": [
|
"with": [
|
||||||
'Server',
|
'Server',
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
var ITERATIONS = 10000;
|
const ITERATIONS = 10000;
|
||||||
|
|
||||||
var mc = require("../");
|
const mc = require("../");
|
||||||
var util = require('util');
|
const util = require('util');
|
||||||
var states = mc.states;
|
const states = mc.states;
|
||||||
|
|
||||||
var testDataWrite = [
|
const testDataWrite = [
|
||||||
{name: 'keep_alive', params: {keepAliveId: 957759560}},
|
{name: 'keep_alive', params: {keepAliveId: 957759560}},
|
||||||
{name: 'chat', params: {message: '<Bob> Hello World!'}},
|
{name: 'chat', params: {message: '<Bob> Hello World!'}},
|
||||||
{name: 'position_look', params: {x: 6.5, y: 65.62, stance: 67.24, z: 7.5, yaw: 0, pitch: 0, onGround: true}}
|
{name: 'position_look', params: {x: 6.5, y: 65.62, stance: 67.24, z: 7.5, yaw: 0, pitch: 0, onGround: true}}
|
||||||
@ -19,14 +19,14 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
if(!(i>=firstVersion && i<=lastVersion))
|
if(!(i>=firstVersion && i<=lastVersion))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var mcData=require("minecraft-data")(supportedVersion);
|
const mcData=require("minecraft-data")(supportedVersion);
|
||||||
var version=mcData.version;
|
const version=mcData.version;
|
||||||
describe("benchmark "+version.minecraftVersion,function(){
|
describe("benchmark "+version.minecraftVersion,function(){
|
||||||
this.timeout(60 * 1000);
|
this.timeout(60 * 1000);
|
||||||
var inputData = [];
|
const inputData = [];
|
||||||
it("bench serializing",function(done){
|
it("bench serializing",function(done){
|
||||||
var serializer=new mc.createSerializer({state:states.PLAY,isServer:false,version:version.minecraftVersion});
|
const serializer=new mc.createSerializer({state:states.PLAY,isServer:false,version:version.minecraftVersion});
|
||||||
var start, i, j;
|
let start, i, j;
|
||||||
console.log('Beginning write test');
|
console.log('Beginning write test');
|
||||||
start = Date.now();
|
start = Date.now();
|
||||||
for(i = 0; i < ITERATIONS; i++) {
|
for(i = 0; i < ITERATIONS; i++) {
|
||||||
@ -34,16 +34,16 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
inputData.push(serializer.createPacketBuffer(testDataWrite[j]));
|
inputData.push(serializer.createPacketBuffer(testDataWrite[j]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var result=(Date.now() - start) / 1000;
|
const result=(Date.now() - start) / 1000;
|
||||||
console.log('Finished write test in ' + result + ' seconds');
|
console.log('Finished write test in ' + result + ' seconds');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("bench parsing",function(done){
|
it("bench parsing",function(done){
|
||||||
var deserializer=new mc.createDeserializer({state:states.PLAY,isServer:true,version:version.minecraftVersion});
|
const deserializer=new mc.createDeserializer({state:states.PLAY,isServer:true,version:version.minecraftVersion});
|
||||||
console.log('Beginning read test');
|
console.log('Beginning read test');
|
||||||
start = Date.now();
|
start = Date.now();
|
||||||
for (var j = 0; j < inputData.length; j++) {
|
for (let j = 0; j < inputData.length; j++) {
|
||||||
deserializer.parsePacketBuffer(inputData[j]);
|
deserializer.parsePacketBuffer(inputData[j]);
|
||||||
}
|
}
|
||||||
console.log('Finished read test in ' + (Date.now() - start) / 1000 + ' seconds');
|
console.log('Finished read test in ' + (Date.now() - start) / 1000 + ' seconds');
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
var mc = require('../');
|
const mc = require('../');
|
||||||
var Server = mc.Server;
|
const Server = mc.Server;
|
||||||
var path = require('path');
|
const path = require('path');
|
||||||
var assert = require('power-assert');
|
const assert = require('power-assert');
|
||||||
var SURVIVE_TIME = 10000;
|
const SURVIVE_TIME = 10000;
|
||||||
var MC_SERVER_PATH = path.join(__dirname, 'server');
|
const MC_SERVER_PATH = path.join(__dirname, 'server');
|
||||||
|
|
||||||
var Wrap = require('minecraft-wrap').Wrap;
|
const Wrap = require('minecraft-wrap').Wrap;
|
||||||
|
|
||||||
const {firstVersion,lastVersion}=require("./common/parallel");
|
const {firstVersion,lastVersion}=require("./common/parallel");
|
||||||
|
|
||||||
|
|
||||||
var download = require('minecraft-wrap').download;
|
const download = require('minecraft-wrap').download;
|
||||||
|
|
||||||
mc.supportedVersions.forEach(function(supportedVersion,i) {
|
mc.supportedVersions.forEach(function(supportedVersion,i) {
|
||||||
if(!(i>=firstVersion && i<=lastVersion))
|
if(!(i>=firstVersion && i<=lastVersion))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var PORT=Math.round(30000+Math.random()*20000);
|
const PORT=Math.round(30000+Math.random()*20000);
|
||||||
var mcData = require("minecraft-data")(supportedVersion);
|
const mcData = require("minecraft-data")(supportedVersion);
|
||||||
var version = mcData.version;
|
const version = mcData.version;
|
||||||
var MC_SERVER_JAR_DIR = process.env.MC_SERVER_JAR_DIR;
|
const MC_SERVER_JAR_DIR = process.env.MC_SERVER_JAR_DIR;
|
||||||
var MC_SERVER_JAR = MC_SERVER_JAR_DIR + "/minecraft_server." + version.minecraftVersion + ".jar";
|
const MC_SERVER_JAR = MC_SERVER_JAR_DIR + "/minecraft_server." + version.minecraftVersion + ".jar";
|
||||||
var wrap = new Wrap(MC_SERVER_JAR, MC_SERVER_PATH+"_"+supportedVersion);
|
const wrap = new Wrap(MC_SERVER_JAR, MC_SERVER_PATH+"_"+supportedVersion);
|
||||||
wrap.on('line', function(line) {
|
wrap.on('line', function(line) {
|
||||||
console.log(line);
|
console.log(line);
|
||||||
});
|
});
|
||||||
@ -85,20 +85,20 @@ mc.supportedVersions.forEach(function(supportedVersion,i) {
|
|||||||
|
|
||||||
|
|
||||||
it("connects successfully - offline mode", function (done) {
|
it("connects successfully - offline mode", function (done) {
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
username: 'Player',
|
username: 'Player',
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
port: PORT
|
port: PORT
|
||||||
});
|
});
|
||||||
var lineListener = function (line) {
|
const lineListener = function (line) {
|
||||||
var match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/);
|
const match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/);
|
||||||
if (!match) return;
|
if (!match) return;
|
||||||
assert.strictEqual(match[1], 'Player');
|
assert.strictEqual(match[1], 'Player');
|
||||||
assert.strictEqual(match[2], "hello everyone; I have logged in.");
|
assert.strictEqual(match[2], "hello everyone; I have logged in.");
|
||||||
wrap.writeServer("say hello\n");
|
wrap.writeServer("say hello\n");
|
||||||
};
|
};
|
||||||
wrap.on('line', lineListener);
|
wrap.on('line', lineListener);
|
||||||
var chatCount = 0;
|
let chatCount = 0;
|
||||||
client.on('login', function (packet) {
|
client.on('login', function (packet) {
|
||||||
assert.strictEqual(packet.levelType, 'default');
|
assert.strictEqual(packet.levelType, 'default');
|
||||||
assert.strictEqual(packet.difficulty, 1);
|
assert.strictEqual(packet.difficulty, 1);
|
||||||
@ -111,7 +111,7 @@ mc.supportedVersions.forEach(function(supportedVersion,i) {
|
|||||||
client.on('chat', function (packet) {
|
client.on('chat', function (packet) {
|
||||||
chatCount += 1;
|
chatCount += 1;
|
||||||
assert.ok(chatCount <= 2);
|
assert.ok(chatCount <= 2);
|
||||||
var message = JSON.parse(packet.message);
|
const message = JSON.parse(packet.message);
|
||||||
if (chatCount === 1) {
|
if (chatCount === 1) {
|
||||||
assert.strictEqual(message.translate, "chat.type.text");
|
assert.strictEqual(message.translate, "chat.type.text");
|
||||||
assert.deepEqual(message["with"][0].clickEvent, {
|
assert.deepEqual(message["with"][0].clickEvent, {
|
||||||
@ -134,7 +134,7 @@ mc.supportedVersions.forEach(function(supportedVersion,i) {
|
|||||||
|
|
||||||
|
|
||||||
it("does not crash for " + SURVIVE_TIME + "ms", function (done) {
|
it("does not crash for " + SURVIVE_TIME + "ms", function (done) {
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
username: 'Player',
|
username: 'Player',
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
port: PORT
|
port: PORT
|
||||||
@ -145,7 +145,7 @@ mc.supportedVersions.forEach(function(supportedVersion,i) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
client.on("chat", function (packet) {
|
client.on("chat", function (packet) {
|
||||||
var message = JSON.parse(packet.message);
|
const message = JSON.parse(packet.message);
|
||||||
assert.strictEqual(message.translate, "chat.type.text");
|
assert.strictEqual(message.translate, "chat.type.text");
|
||||||
/*assert.deepEqual(message["with"][0], {
|
/*assert.deepEqual(message["with"][0], {
|
||||||
clickEvent: {
|
clickEvent: {
|
||||||
@ -163,9 +163,9 @@ mc.supportedVersions.forEach(function(supportedVersion,i) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("produce a decent error when connecting with the wrong version", function (done) {
|
it("produce a decent error when connecting with the wrong version", function (done) {
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
username: 'Player',
|
username: 'Player',
|
||||||
version: version.minecraftVersion == "1.8.8" ? "1.11.2" : "1.8.8",
|
version: version.minecraftVersion === "1.8.8" ? "1.11.2" : "1.8.8",
|
||||||
port: PORT
|
port: PORT
|
||||||
});
|
});
|
||||||
client.once("error", function (err) {
|
client.once("error", function (err) {
|
||||||
@ -202,14 +202,14 @@ mc.supportedVersions.forEach(function(supportedVersion,i) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it.skip("connects successfully - online mode", function (done) {
|
it.skip("connects successfully - online mode", function (done) {
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
username: process.env.MC_USERNAME,
|
username: process.env.MC_USERNAME,
|
||||||
password: process.env.MC_PASSWORD,
|
password: process.env.MC_PASSWORD,
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
port: PORT
|
port: PORT
|
||||||
});
|
});
|
||||||
var lineListener = function (line) {
|
const lineListener = function (line) {
|
||||||
var match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/);
|
const match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/);
|
||||||
if (!match) return;
|
if (!match) return;
|
||||||
assert.strictEqual(match[1], client.username);
|
assert.strictEqual(match[1], client.username);
|
||||||
assert.strictEqual(match[2], "hello everyone; I have logged in.");
|
assert.strictEqual(match[2], "hello everyone; I have logged in.");
|
||||||
@ -225,11 +225,11 @@ mc.supportedVersions.forEach(function(supportedVersion,i) {
|
|||||||
message: "hello everyone; I have logged in."
|
message: "hello everyone; I have logged in."
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
var chatCount = 0;
|
let chatCount = 0;
|
||||||
client.on('chat', function (packet) {
|
client.on('chat', function (packet) {
|
||||||
chatCount += 1;
|
chatCount += 1;
|
||||||
assert.ok(chatCount <= 2);
|
assert.ok(chatCount <= 2);
|
||||||
if (chatCount == 2) {
|
if (chatCount === 2) {
|
||||||
client.removeAllListeners('chat');
|
client.removeAllListeners('chat');
|
||||||
wrap.removeListener('line', lineListener);
|
wrap.removeListener('line', lineListener);
|
||||||
client.end();
|
client.end();
|
||||||
@ -239,14 +239,14 @@ mc.supportedVersions.forEach(function(supportedVersion,i) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("gets kicked when no credentials supplied in online mode", function (done) {
|
it("gets kicked when no credentials supplied in online mode", function (done) {
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
username: 'Player',
|
username: 'Player',
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
port: PORT
|
port: PORT
|
||||||
});
|
});
|
||||||
var gotKicked = false;
|
let gotKicked = false;
|
||||||
client.on('disconnect', function (packet) {
|
client.on('disconnect', function (packet) {
|
||||||
assert.ok(packet.reason.indexOf('"Failed to verify username!"') != -1 || packet.reason.indexOf('multiplayer.disconnect.unverified_username') != -1);
|
assert.ok(packet.reason.indexOf('"Failed to verify username!"') !== -1 || packet.reason.indexOf('multiplayer.disconnect.unverified_username') !== -1);
|
||||||
gotKicked = true;
|
gotKicked = true;
|
||||||
});
|
});
|
||||||
client.on('end', function () {
|
client.on('end', function () {
|
||||||
|
@ -11,7 +11,7 @@ const mc = require("../../");
|
|||||||
// (3,4,10) -> (9,9)
|
// (3,4,10) -> (9,9)
|
||||||
function testedRange(nodeIndex,nodeTotal,numberOfVersions) {
|
function testedRange(nodeIndex,nodeTotal,numberOfVersions) {
|
||||||
const nbFirsts=Math.ceil(numberOfVersions/nodeTotal);
|
const nbFirsts=Math.ceil(numberOfVersions/nodeTotal);
|
||||||
if(nodeIndex==(nodeTotal-1))
|
if(nodeIndex===(nodeTotal-1))
|
||||||
return {firstVersion:nbFirsts*nodeIndex,lastVersion:numberOfVersions-1};
|
return {firstVersion:nbFirsts*nodeIndex,lastVersion:numberOfVersions-1};
|
||||||
|
|
||||||
return {firstVersion:nodeIndex*nbFirsts,lastVersion:(nodeIndex+1)*nbFirsts-1};
|
return {firstVersion:nodeIndex*nbFirsts,lastVersion:(nodeIndex+1)*nbFirsts-1};
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
var mc = require('../');
|
const mc = require('../');
|
||||||
var states = mc.states;
|
const states = mc.states;
|
||||||
var Client = mc.Client;
|
const Client = mc.Client;
|
||||||
var Server = mc.Server;
|
const Server = mc.Server;
|
||||||
var net = require('net');
|
const net = require('net');
|
||||||
var assert = require('power-assert');
|
const assert = require('power-assert');
|
||||||
var getFieldInfo = require('protodef').utils.getFieldInfo;
|
const getFieldInfo = require('protodef').utils.getFieldInfo;
|
||||||
var getField = require('protodef').utils.getField;
|
const getField = require('protodef').utils.getField;
|
||||||
|
|
||||||
function evalCount(count, fields) {
|
function evalCount(count, fields) {
|
||||||
if(fields[count["field"]] in count["map"])
|
if(fields[count["field"]] in count["map"])
|
||||||
@ -13,7 +13,7 @@ function evalCount(count, fields) {
|
|||||||
return count["default"];
|
return count["default"];
|
||||||
}
|
}
|
||||||
|
|
||||||
var values = {
|
const values = {
|
||||||
'i32': 123456,
|
'i32': 123456,
|
||||||
'i16': -123,
|
'i16': -123,
|
||||||
'u16': 123,
|
'u16': 123,
|
||||||
@ -23,14 +23,14 @@ var values = {
|
|||||||
'string': "hi hi this is my client string",
|
'string': "hi hi this is my client string",
|
||||||
'buffer': new Buffer(8),
|
'buffer': new Buffer(8),
|
||||||
'array': function(typeArgs, context) {
|
'array': function(typeArgs, context) {
|
||||||
var count;
|
let count;
|
||||||
if (typeof typeArgs.count === "object")
|
if (typeof typeArgs.count === "object")
|
||||||
count = evalCount(typeArgs.count, context);
|
count = evalCount(typeArgs.count, context);
|
||||||
else if (typeof typeArgs.count !== "undefined")
|
else if (typeof typeArgs.count !== "undefined")
|
||||||
count = getField(typeArgs.count, context);
|
count = getField(typeArgs.count, context);
|
||||||
else if (typeof typeArgs.countType !== "undefined")
|
else if (typeof typeArgs.countType !== "undefined")
|
||||||
count = 1;
|
count = 1;
|
||||||
var arr = [];
|
const arr = [];
|
||||||
while (count > 0) {
|
while (count > 0) {
|
||||||
arr.push(getValue(typeArgs.type, context));
|
arr.push(getValue(typeArgs.type, context));
|
||||||
count--;
|
count--;
|
||||||
@ -38,7 +38,7 @@ var values = {
|
|||||||
return arr;
|
return arr;
|
||||||
},
|
},
|
||||||
'container': function(typeArgs, context) {
|
'container': function(typeArgs, context) {
|
||||||
var results = {
|
const results = {
|
||||||
"..": context
|
"..": context
|
||||||
};
|
};
|
||||||
Object.keys(typeArgs).forEach(function(index){
|
Object.keys(typeArgs).forEach(function(index){
|
||||||
@ -129,7 +129,7 @@ var values = {
|
|||||||
'position_iii': {x: 12, y: 100, z: 4382821},
|
'position_iii': {x: 12, y: 100, z: 4382821},
|
||||||
'restBuffer': new Buffer(0),
|
'restBuffer': new Buffer(0),
|
||||||
'switch': function(typeArgs, context) {
|
'switch': function(typeArgs, context) {
|
||||||
var i = typeArgs.fields[getField(typeArgs.compareTo, context)];
|
const i = typeArgs.fields[getField(typeArgs.compareTo, context)];
|
||||||
if (typeof i === "undefined")
|
if (typeof i === "undefined")
|
||||||
return getValue(typeArgs.default, context);
|
return getValue(typeArgs.default, context);
|
||||||
else
|
else
|
||||||
@ -139,7 +139,7 @@ var values = {
|
|||||||
return getValue(typeArgs, context);
|
return getValue(typeArgs, context);
|
||||||
},
|
},
|
||||||
'bitfield': function(typeArgs) {
|
'bitfield': function(typeArgs) {
|
||||||
var results={};
|
const results={};
|
||||||
Object.keys(typeArgs).forEach(function(index){
|
Object.keys(typeArgs).forEach(function(index){
|
||||||
results[typeArgs[index].name] = 1;
|
results[typeArgs[index].name] = 1;
|
||||||
});
|
});
|
||||||
@ -148,7 +148,7 @@ var values = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function getValue(_type, packet) {
|
function getValue(_type, packet) {
|
||||||
var fieldInfo = getFieldInfo(_type);
|
const fieldInfo = getFieldInfo(_type);
|
||||||
if (typeof values[fieldInfo.type] === "function")
|
if (typeof values[fieldInfo.type] === "function")
|
||||||
return values[fieldInfo.type](fieldInfo.typeArgs, packet);
|
return values[fieldInfo.type](fieldInfo.typeArgs, packet);
|
||||||
else if (values[fieldInfo.type] !== "undefined")
|
else if (values[fieldInfo.type] !== "undefined")
|
||||||
@ -163,13 +163,13 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
if(!(i>=firstVersion && i<=lastVersion))
|
if(!(i>=firstVersion && i<=lastVersion))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var PORT=Math.round(30000+Math.random()*20000);
|
const PORT=Math.round(30000+Math.random()*20000);
|
||||||
var mcData=require("minecraft-data")(supportedVersion);
|
const mcData=require("minecraft-data")(supportedVersion);
|
||||||
var version=mcData.version;
|
const version=mcData.version;
|
||||||
var packets = mcData.protocol;
|
const packets = mcData.protocol;
|
||||||
|
|
||||||
describe("packets "+version.minecraftVersion, function() {
|
describe("packets "+version.minecraftVersion, function() {
|
||||||
var client, server, serverClient;
|
let client, server, serverClient;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
server = new Server(version.minecraftVersion);
|
server = new Server(version.minecraftVersion);
|
||||||
server.once('listening', function() {
|
server.once('listening', function() {
|
||||||
@ -189,14 +189,14 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
});
|
});
|
||||||
client.end();
|
client.end();
|
||||||
});
|
});
|
||||||
var packetInfo, field;
|
let packetInfo, field;
|
||||||
Object.keys(packets).filter(function(state){return state!="types"}).forEach(function(state){
|
Object.keys(packets).filter(function(state){return state!=="types"}).forEach(function(state){
|
||||||
Object.keys(packets[state]).forEach(function(direction){
|
Object.keys(packets[state]).forEach(function(direction){
|
||||||
Object.keys(packets[state][direction].types).filter(function(packetName){return packetName!="packet"}).forEach(function(packetName){
|
Object.keys(packets[state][direction].types).filter(function(packetName){return packetName!=="packet"}).forEach(function(packetName){
|
||||||
packetInfo = packets[state][direction].types[packetName];
|
packetInfo = packets[state][direction].types[packetName];
|
||||||
packetInfo=packetInfo ? packetInfo : null;
|
packetInfo=packetInfo ? packetInfo : null;
|
||||||
it(state + ","+(direction=="toServer" ? "Server" : "Client")+"Bound," + packetName,
|
it(state + ","+(direction==="toServer" ? "Server" : "Client")+"Bound," + packetName,
|
||||||
callTestPacket(packetName.substr(7), packetInfo, state, direction=="toServer" ));
|
callTestPacket(packetName.substr(7), packetInfo, state, direction==="toServer" ));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -210,7 +210,7 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
|
|
||||||
function testPacket(packetName, packetInfo, state, toServer, done) {
|
function testPacket(packetName, packetInfo, state, toServer, done) {
|
||||||
// empty object uses default values
|
// empty object uses default values
|
||||||
var packet = getValue(packetInfo, {});
|
const packet = getValue(packetInfo, {});
|
||||||
if(toServer) {
|
if(toServer) {
|
||||||
serverClient.once(packetName, function(receivedPacket) {
|
serverClient.once(packetName, function(receivedPacket) {
|
||||||
try {
|
try {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
var mc = require('../');
|
const mc = require('../');
|
||||||
var assert = require('power-assert');
|
const assert = require('power-assert');
|
||||||
|
|
||||||
const {firstVersion,lastVersion}=require("./common/parallel");
|
const {firstVersion,lastVersion}=require("./common/parallel");
|
||||||
|
|
||||||
@ -7,18 +7,18 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
if(!(i>=firstVersion && i<=lastVersion))
|
if(!(i>=firstVersion && i<=lastVersion))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var PORT=Math.round(30000+Math.random()*20000);
|
const PORT=Math.round(30000+Math.random()*20000);
|
||||||
var mcData=require("minecraft-data")(supportedVersion);
|
const mcData=require("minecraft-data")(supportedVersion);
|
||||||
var version=mcData.version;
|
const version=mcData.version;
|
||||||
|
|
||||||
describe("mc-server "+version.minecraftVersion, function() {
|
describe("mc-server "+version.minecraftVersion, function() {
|
||||||
it("starts listening and shuts down cleanly", function(done) {
|
it("starts listening and shuts down cleanly", function(done) {
|
||||||
var server = mc.createServer({
|
const server = mc.createServer({
|
||||||
'online-mode': false,
|
'online-mode': false,
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
port:PORT
|
port:PORT
|
||||||
});
|
});
|
||||||
var listening = false;
|
let listening = false;
|
||||||
server.on('listening', function() {
|
server.on('listening', function() {
|
||||||
listening = true;
|
listening = true;
|
||||||
server.close();
|
server.close();
|
||||||
@ -29,14 +29,14 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("kicks clients that do not log in", function(done) {
|
it("kicks clients that do not log in", function(done) {
|
||||||
var server = mc.createServer({
|
const server = mc.createServer({
|
||||||
'online-mode': false,
|
'online-mode': false,
|
||||||
kickTimeout: 100,
|
kickTimeout: 100,
|
||||||
checkTimeoutInterval: 10,
|
checkTimeoutInterval: 10,
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
port:PORT
|
port:PORT
|
||||||
});
|
});
|
||||||
var count = 2;
|
let count = 2;
|
||||||
server.on('connection', function(client) {
|
server.on('connection', function(client) {
|
||||||
client.on('end', function(reason) {
|
client.on('end', function(reason) {
|
||||||
assert.strictEqual(reason, '{"text":"LoginTimeout"}');
|
assert.strictEqual(reason, '{"text":"LoginTimeout"}');
|
||||||
@ -47,7 +47,7 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
server.on('listening', function() {
|
server.on('listening', function() {
|
||||||
var client = new mc.Client(false,version.minecraftVersion);
|
const client = new mc.Client(false,version.minecraftVersion);
|
||||||
client.on('end', function() {
|
client.on('end', function() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
@ -60,14 +60,14 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
it("kicks clients that do not send keepalive packets", function(done) {
|
it("kicks clients that do not send keepalive packets", function(done) {
|
||||||
var server = mc.createServer({
|
const server = mc.createServer({
|
||||||
'online-mode': false,
|
'online-mode': false,
|
||||||
kickTimeout: 100,
|
kickTimeout: 100,
|
||||||
checkTimeoutInterval: 10,
|
checkTimeoutInterval: 10,
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
port:PORT
|
port:PORT
|
||||||
});
|
});
|
||||||
var count = 2;
|
let count = 2;
|
||||||
server.on('connection', function(client) {
|
server.on('connection', function(client) {
|
||||||
client.on('end', function(reason) {
|
client.on('end', function(reason) {
|
||||||
assert.strictEqual(reason, '{"text":"KeepAliveTimeout"}');
|
assert.strictEqual(reason, '{"text":"KeepAliveTimeout"}');
|
||||||
@ -78,7 +78,7 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
server.on('listening', function() {
|
server.on('listening', function() {
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
username: 'superpants',
|
username: 'superpants',
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
port: PORT,
|
port: PORT,
|
||||||
@ -95,7 +95,7 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
it("responds to ping requests", function(done) {
|
it("responds to ping requests", function(done) {
|
||||||
var server = mc.createServer({
|
const server = mc.createServer({
|
||||||
'online-mode': false,
|
'online-mode': false,
|
||||||
motd: 'test1234',
|
motd: 'test1234',
|
||||||
'max-players': 120,
|
'max-players': 120,
|
||||||
@ -130,13 +130,13 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
server.on('close', done);
|
server.on('close', done);
|
||||||
});
|
});
|
||||||
it("clients can log in and chat", function(done) {
|
it("clients can log in and chat", function(done) {
|
||||||
var server = mc.createServer({
|
const server = mc.createServer({
|
||||||
'online-mode': false,
|
'online-mode': false,
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
port:PORT
|
port:PORT
|
||||||
});
|
});
|
||||||
var username = ['player1', 'player2'];
|
const username = ['player1', 'player2'];
|
||||||
var index = 0;
|
let index = 0;
|
||||||
server.on('login', function(client) {
|
server.on('login', function(client) {
|
||||||
assert.notEqual(client.id, null);
|
assert.notEqual(client.id, null);
|
||||||
assert.strictEqual(client.username, username[index++]);
|
assert.strictEqual(client.username, username[index++]);
|
||||||
@ -155,13 +155,13 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
reducedDebugInfo: 0
|
reducedDebugInfo: 0
|
||||||
});
|
});
|
||||||
client.on('chat', function(packet) {
|
client.on('chat', function(packet) {
|
||||||
var message = '<' + client.username + '>' + ' ' + packet.message;
|
const message = '<' + client.username + '>' + ' ' + packet.message;
|
||||||
broadcast(message);
|
broadcast(message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
server.on('close', done);
|
server.on('close', done);
|
||||||
server.on('listening', function() {
|
server.on('listening', function() {
|
||||||
var player1 = mc.createClient({
|
const player1 = mc.createClient({
|
||||||
username: 'player1',
|
username: 'player1',
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
@ -194,7 +194,7 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
});
|
});
|
||||||
player2.write('chat', {message: "hi"});
|
player2.write('chat', {message: "hi"});
|
||||||
});
|
});
|
||||||
var player2 = mc.createClient({
|
const player2 = mc.createClient({
|
||||||
username: 'player2',
|
username: 'player2',
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
@ -204,8 +204,8 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
});
|
});
|
||||||
|
|
||||||
function broadcast(message, exclude) {
|
function broadcast(message, exclude) {
|
||||||
var client;
|
let client;
|
||||||
for(var clientId in server.clients) {
|
for(const clientId in server.clients) {
|
||||||
if(!server.clients.hasOwnProperty(clientId)) continue;
|
if(!server.clients.hasOwnProperty(clientId)) continue;
|
||||||
|
|
||||||
client = server.clients[clientId];
|
client = server.clients[clientId];
|
||||||
@ -215,11 +215,11 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
});
|
});
|
||||||
it("kicks clients when invalid credentials", function(done) {
|
it("kicks clients when invalid credentials", function(done) {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
var server = mc.createServer({
|
const server = mc.createServer({
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
port:PORT
|
port:PORT
|
||||||
});
|
});
|
||||||
var count = 4;
|
let count = 4;
|
||||||
server.on('connection', function(client) {
|
server.on('connection', function(client) {
|
||||||
client.on('end', function(reason) {
|
client.on('end', function(reason) {
|
||||||
resolve();
|
resolve();
|
||||||
@ -231,7 +231,7 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
});
|
});
|
||||||
server.on('listening', function() {
|
server.on('listening', function() {
|
||||||
resolve();
|
resolve();
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
username: 'lalalal',
|
username: 'lalalal',
|
||||||
host: "127.0.0.1",
|
host: "127.0.0.1",
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
@ -247,12 +247,12 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
it("gives correct reason for kicking clients when shutting down", function(done) {
|
it("gives correct reason for kicking clients when shutting down", function(done) {
|
||||||
var server = mc.createServer({
|
const server = mc.createServer({
|
||||||
'online-mode': false,
|
'online-mode': false,
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
port:PORT
|
port:PORT
|
||||||
});
|
});
|
||||||
var count = 2;
|
let count = 2;
|
||||||
server.on('login', function(client) {
|
server.on('login', function(client) {
|
||||||
client.on('end', function(reason) {
|
client.on('end', function(reason) {
|
||||||
assert.strictEqual(reason, '{"text":"ServerShutdown"}');
|
assert.strictEqual(reason, '{"text":"ServerShutdown"}');
|
||||||
@ -272,7 +272,7 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
server.on('listening', function() {
|
server.on('listening', function() {
|
||||||
var client = mc.createClient({
|
const client = mc.createClient({
|
||||||
username: 'lalalal',
|
username: 'lalalal',
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
version: version.minecraftVersion,
|
version: version.minecraftVersion,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user