mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 22:23:21 -04:00
use minecraft-wrap : get the vanilla server wrapping out of node-minecraft-protocol
This commit is contained in:
parent
74e4d415fb
commit
eeed7b643c
@ -5,7 +5,8 @@ machine:
|
|||||||
version: 0.10.28
|
version: 0.10.28
|
||||||
java:
|
java:
|
||||||
version: openjdk7
|
version: openjdk7
|
||||||
dependencies:
|
test:
|
||||||
pre:
|
override:
|
||||||
- mkdir minecraft-server
|
- mkdir -p /home/ubuntu/node-minecraft-protocol/minecraft-server/
|
||||||
- node downloadServer.js $MC_SERVER_JAR
|
- node_modules/.bin/downloadMinecraft `node -e 'console.log(require("./src/version").minecraftVersion)'` $MC_SERVER_JAR
|
||||||
|
- npm test
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
var https = require('https');
|
|
||||||
var fs = require('fs');
|
|
||||||
var version = require("./src/version");
|
|
||||||
|
|
||||||
var request = https.get("https://s3.amazonaws.com/Minecraft.Download/versions/"+version.minecraftVersion+"/minecraft_server."+version.minecraftVersion+".jar", function(response) {
|
|
||||||
if(response.statusCode==200) {
|
|
||||||
var file = fs.createWriteStream(process.argv[2]);
|
|
||||||
response.pipe(file);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
@ -28,19 +28,17 @@
|
|||||||
},
|
},
|
||||||
"browser": "browser.js",
|
"browser": "browser.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"batch": "~0.3.1",
|
|
||||||
"chai": "^2.3.0",
|
"chai": "^2.3.0",
|
||||||
"gulp": "^3.8.11",
|
"gulp": "^3.8.11",
|
||||||
"gulp-babel": "^5.1.0",
|
"gulp-babel": "^5.1.0",
|
||||||
"gulp-plumber": "^1.0.1",
|
"gulp-plumber": "^1.0.1",
|
||||||
"gulp-sourcemaps": "^1.3.0",
|
"gulp-sourcemaps": "^1.3.0",
|
||||||
"intelli-espower-loader": "^1.0.0",
|
"intelli-espower-loader": "^1.0.0",
|
||||||
"mkdirp": "~0.3.4",
|
|
||||||
"mocha": "~1.8.2",
|
"mocha": "~1.8.2",
|
||||||
"power-assert": "^1.0.0",
|
"power-assert": "^1.0.0",
|
||||||
"rimraf": "~2.1.1",
|
|
||||||
"source-map-support": "^0.3.2",
|
"source-map-support": "^0.3.2",
|
||||||
"zfill": "0.0.1"
|
"zfill": "0.0.1",
|
||||||
|
"minecraft-wrap": "0.5.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-runtime": "^5.4.4",
|
"babel-runtime": "^5.4.4",
|
||||||
|
153
test/test.js
153
test/test.js
@ -2,14 +2,10 @@ var mc = require('../')
|
|||||||
, states = mc.states
|
, states = mc.states
|
||||||
, Client = mc.Client
|
, Client = mc.Client
|
||||||
, Server = mc.Server
|
, Server = mc.Server
|
||||||
, spawn = require('child_process').spawn
|
|
||||||
, path = require('path')
|
, path = require('path')
|
||||||
, fs = require('fs')
|
, fs = require('fs')
|
||||||
, net = require('net')
|
, net = require('net')
|
||||||
, assert = require('power-assert')
|
, assert = require('power-assert')
|
||||||
, mkdirp = require('mkdirp')
|
|
||||||
, rimraf = require('rimraf')
|
|
||||||
, Batch = require('batch')
|
|
||||||
, zfill = require('zfill')
|
, zfill = require('zfill')
|
||||||
, MC_SERVER_JAR = process.env.MC_SERVER_JAR
|
, MC_SERVER_JAR = process.env.MC_SERVER_JAR
|
||||||
, SURVIVE_TIME = 10000
|
, SURVIVE_TIME = 10000
|
||||||
@ -18,40 +14,8 @@ var mc = require('../')
|
|||||||
, getField = require('../dist/utils').getField
|
, getField = require('../dist/utils').getField
|
||||||
;
|
;
|
||||||
|
|
||||||
var defaultServerProps = {
|
var Wrap = require('minecraft-wrap').Wrap;
|
||||||
'generator-settings': "",
|
var wrap=new Wrap(MC_SERVER_JAR,MC_SERVER_PATH);
|
||||||
'op-permission-level': '4',
|
|
||||||
'allow-nether': 'true',
|
|
||||||
'level-name': 'world',
|
|
||||||
'enable-query': 'false',
|
|
||||||
'allow-flight': 'false',
|
|
||||||
'announce-player-achievements': true,
|
|
||||||
'server-port': '25565',
|
|
||||||
'level-type': 'DEFAULT',
|
|
||||||
'enable-rcon': 'false',
|
|
||||||
'force-gamemode': 'false',
|
|
||||||
'level-seed': "",
|
|
||||||
'server-ip': "",
|
|
||||||
'max-build-height': '256',
|
|
||||||
'spawn-npcs': 'true',
|
|
||||||
'white-list': 'false',
|
|
||||||
'spawn-animals': 'true',
|
|
||||||
'hardcore': 'false',
|
|
||||||
'snooper-enabled': 'true',
|
|
||||||
'online-mode': 'true',
|
|
||||||
'resource-pack': '',
|
|
||||||
'pvp': 'true',
|
|
||||||
'difficulty': '1',
|
|
||||||
'enable-command-block': 'false',
|
|
||||||
'gamemode': '0',
|
|
||||||
'player-idle-timeout': '0',
|
|
||||||
'max-players': '20',
|
|
||||||
'spawn-monsters': 'true',
|
|
||||||
'generate-structures': 'true',
|
|
||||||
'view-distance': '10',
|
|
||||||
'spawn-protection': '16',
|
|
||||||
'motd': 'A Minecraft Server',
|
|
||||||
};
|
|
||||||
|
|
||||||
function evalCount(count, fields) {
|
function evalCount(count, fields) {
|
||||||
if(fields[count["field"]] in count["map"])
|
if(fields[count["field"]] in count["map"])
|
||||||
@ -243,97 +207,22 @@ describe("packets", function() {
|
|||||||
describe("client", function() {
|
describe("client", function() {
|
||||||
this.timeout(10 * 60 * 1000);
|
this.timeout(10 * 60 * 1000);
|
||||||
|
|
||||||
var mcServer;
|
|
||||||
|
|
||||||
function startServer(propOverrides, done) {
|
|
||||||
var props = {};
|
|
||||||
var prop;
|
|
||||||
for(prop in defaultServerProps) {
|
|
||||||
if(!defaultServerProps.hasOwnProperty(prop)) continue;
|
|
||||||
|
|
||||||
props[prop] = defaultServerProps[prop];
|
|
||||||
}
|
|
||||||
for(prop in propOverrides) {
|
|
||||||
if(!propOverrides.hasOwnProperty(prop)) continue;
|
|
||||||
|
|
||||||
props[prop] = propOverrides[prop];
|
|
||||||
}
|
|
||||||
var batch = new Batch();
|
|
||||||
batch.push(function(cb) {
|
|
||||||
mkdirp(MC_SERVER_PATH, cb);
|
|
||||||
});
|
|
||||||
batch.push(function(cb) {
|
|
||||||
var str = "";
|
|
||||||
for(var prop in props) {
|
|
||||||
if(!props.hasOwnProperty(prop)) continue;
|
|
||||||
|
|
||||||
str += prop + "=" + props[prop] + "\n";
|
|
||||||
}
|
|
||||||
fs.writeFile(path.join(MC_SERVER_PATH, "server.properties"), str, cb);
|
|
||||||
});
|
|
||||||
batch.push(function(cb) {
|
|
||||||
fs.writeFile(path.join(MC_SERVER_PATH, "eula.txt"), "eula=true", cb);
|
|
||||||
});
|
|
||||||
batch.end(function(err) {
|
|
||||||
if(err) return done(err);
|
|
||||||
if(!fs.existsSync(MC_SERVER_JAR)) {
|
|
||||||
return done(new Error("The file " + MC_SERVER_JAR + " doesn't exist."));
|
|
||||||
}
|
|
||||||
|
|
||||||
mcServer = spawn('java', ['-Dlog4j.configurationFile=server/server_debug.xml', '-jar', MC_SERVER_JAR, 'nogui'], {
|
|
||||||
stdio: 'pipe',
|
|
||||||
cwd: MC_SERVER_PATH,
|
|
||||||
});
|
|
||||||
mcServer.stdin.setEncoding('utf8');
|
|
||||||
mcServer.stdout.setEncoding('utf8');
|
|
||||||
mcServer.stderr.setEncoding('utf8');
|
|
||||||
var buffer = "";
|
|
||||||
mcServer.stdout.on('data', onData);
|
|
||||||
mcServer.stderr.on('data', onData);
|
|
||||||
function onData(data) {
|
|
||||||
buffer += data;
|
|
||||||
var lines = buffer.split("\n");
|
|
||||||
var len = lines.length - 1;
|
|
||||||
for(var i = 0; i < len; ++i) {
|
|
||||||
mcServer.emit('line', lines[i]);
|
|
||||||
}
|
|
||||||
buffer = lines[lines.length - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
mcServer.on('line', onLine);
|
|
||||||
mcServer.on('line', function(line) {
|
|
||||||
process.stderr.write('.');
|
|
||||||
// uncomment this line when debugging for more insight as to what is
|
|
||||||
// happening on the minecraft server
|
|
||||||
//console.error("[MC]", line);
|
|
||||||
});
|
|
||||||
function onLine(line) {
|
|
||||||
if(/\[Server thread\/INFO\]: Done/.test(line)) {
|
|
||||||
mcServer.removeListener('line', onLine);
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
//else
|
|
||||||
// console.log(line);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
afterEach(function(done) {
|
afterEach(function(done) {
|
||||||
if(mcServer) {
|
wrap.stopServer(function(err){
|
||||||
mcServer.stdin.write("stop\n");
|
if(err)
|
||||||
mcServer.on('exit', function() {
|
console.log(err);
|
||||||
mcServer = null;
|
done(err);
|
||||||
done();
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
after(function(done) {
|
after(function(done) {
|
||||||
rimraf(MC_SERVER_PATH, done);
|
wrap.deleteServerData(function(err){
|
||||||
|
if(err)
|
||||||
|
console.log(err);
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it("pings the server", function(done) {
|
it("pings the server", function(done) {
|
||||||
startServer({
|
wrap.startServer({
|
||||||
motd: 'test1234',
|
motd: 'test1234',
|
||||||
'max-players': 120,
|
'max-players': 120,
|
||||||
}, function() {
|
}, function() {
|
||||||
@ -355,17 +244,17 @@ describe("client", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it.skip("connects successfully - online mode (STUBBED)", function(done) {
|
it.skip("connects successfully - online mode (STUBBED)", function(done) {
|
||||||
startServer({'online-mode': 'true'}, function() {
|
wrap.startServer({'online-mode': 'true'}, function() {
|
||||||
var client = mc.createClient({
|
var client = mc.createClient({
|
||||||
username: process.env.MC_USERNAME,
|
username: process.env.MC_USERNAME,
|
||||||
password: process.env.MC_PASSWORD,
|
password: process.env.MC_PASSWORD,
|
||||||
});
|
});
|
||||||
mcServer.on('line', function(line) {
|
wrap.on('line', function(line) {
|
||||||
var match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/);
|
var match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/);
|
||||||
if(!match) return;
|
if(!match) return;
|
||||||
assert.strictEqual(match[1], client.session.username);
|
assert.strictEqual(match[1], client.session.username);
|
||||||
assert.strictEqual(match[2], "hello everyone; I have logged in.");
|
assert.strictEqual(match[2], "hello everyone; I have logged in.");
|
||||||
mcServer.stdin.write("say hello\n");
|
wrap.writeServer("say hello\n");
|
||||||
});
|
});
|
||||||
var chatCount = 0;
|
var chatCount = 0;
|
||||||
client.on('login', function(packet) {
|
client.on('login', function(packet) {
|
||||||
@ -384,16 +273,16 @@ describe("client", function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
it.skip("connects successfully - offline mode (STUBBED)", function(done) {
|
it.skip("connects successfully - offline mode (STUBBED)", function(done) {
|
||||||
startServer({'online-mode': 'false'}, function() {
|
wrap.startServer({'online-mode': 'false'}, function() {
|
||||||
var client = mc.createClient({
|
var client = mc.createClient({
|
||||||
username: 'Player',
|
username: 'Player',
|
||||||
});
|
});
|
||||||
mcServer.on('line', function(line) {
|
wrap.on('line', function(line) {
|
||||||
var match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/);
|
var 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.");
|
||||||
mcServer.stdin.write("say hello\n");
|
wrap.writeServer("say hello\n");
|
||||||
});
|
});
|
||||||
var chatCount = 0;
|
var chatCount = 0;
|
||||||
client.on('login', function(packet) {
|
client.on('login', function(packet) {
|
||||||
@ -433,7 +322,7 @@ describe("client", function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
it("gets kicked when no credentials supplied in online mode", function(done) {
|
it("gets kicked when no credentials supplied in online mode", function(done) {
|
||||||
startServer({'online-mode': 'true'}, function() {
|
wrap.startServer({'online-mode': 'true'}, function() {
|
||||||
var client = mc.createClient({
|
var client = mc.createClient({
|
||||||
username: 'Player',
|
username: 'Player',
|
||||||
});
|
});
|
||||||
@ -449,7 +338,7 @@ describe("client", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("does not crash for " + SURVIVE_TIME + "ms", function(done) {
|
it("does not crash for " + SURVIVE_TIME + "ms", function(done) {
|
||||||
startServer({'online-mode': 'false'}, function() {
|
wrap.startServer({'online-mode': 'false'}, function() {
|
||||||
var client = mc.createClient({
|
var client = mc.createClient({
|
||||||
username: 'Player',
|
username: 'Player',
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user