mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-06 11:40:46 +00:00
fix player.kick (just use player._client.end), add serv.quit(reason), wait for login messages in mineflayer test
This commit is contained in:
parent
72c91c50e0
commit
f5884caf1f
5 changed files with 68 additions and 27 deletions
|
|
@ -25,7 +25,7 @@
|
||||||
"babel-runtime": "^5.4.4",
|
"babel-runtime": "^5.4.4",
|
||||||
"emit-then": "^1.0.2",
|
"emit-then": "^1.0.2",
|
||||||
"minecraft-data": "0.7.0",
|
"minecraft-data": "0.7.0",
|
||||||
"minecraft-protocol": "0.16.2",
|
"minecraft-protocol": "0.16.3",
|
||||||
"mkdirp": "0.5.1",
|
"mkdirp": "0.5.1",
|
||||||
"moment": "^2.10.6",
|
"moment": "^2.10.6",
|
||||||
"node-dir": "~0.1.9",
|
"node-dir": "~0.1.9",
|
||||||
|
|
@ -41,7 +41,8 @@
|
||||||
"request-promise": "^0.4.3",
|
"request-promise": "^0.4.3",
|
||||||
"requireindex": "~1.0.0",
|
"requireindex": "~1.0.0",
|
||||||
"spiralloop": "1.0.2",
|
"spiralloop": "1.0.2",
|
||||||
"vec3": "0.1.3"
|
"vec3": "0.1.3",
|
||||||
|
"event-promise": "0.0.1"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
@ -55,7 +56,6 @@
|
||||||
"babel": "5.8.23",
|
"babel": "5.8.23",
|
||||||
"chai": "~3.2.0",
|
"chai": "~3.2.0",
|
||||||
"doctoc": "^0.15.0",
|
"doctoc": "^0.15.0",
|
||||||
"event-promise": "0.0.1",
|
|
||||||
"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",
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ module.exports.player=function(player,serv)
|
||||||
player.login = async () =>
|
player.login = async () =>
|
||||||
{
|
{
|
||||||
if (serv.uuidToPlayer[player._client.uuid]) {
|
if (serv.uuidToPlayer[player._client.uuid]) {
|
||||||
player._client.end("You are already connected");
|
player.kick("You are already connected");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (serv.bannedPlayers[player._client.uuid]) {
|
if (serv.bannedPlayers[player._client.uuid]) {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,17 @@
|
||||||
|
var once = require('event-promise');
|
||||||
|
|
||||||
|
module.exports.server=function(serv)
|
||||||
|
{
|
||||||
|
serv.quit=async(reason="Going down") => {
|
||||||
|
await Promise.all(serv.players.map((player) => {
|
||||||
|
player.kick(reason);
|
||||||
|
return once(player,'disconnected');
|
||||||
|
}));
|
||||||
|
serv._server.close();
|
||||||
|
await once(serv._server,"close");
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.player=function(player,serv)
|
module.exports.player=function(player,serv)
|
||||||
{
|
{
|
||||||
player.despawnEntities = entities => player._client.write('entity_destroy', {
|
player.despawnEntities = entities => player._client.write('entity_destroy', {
|
||||||
|
|
|
||||||
|
|
@ -65,12 +65,8 @@ module.exports.server=function(serv)
|
||||||
|
|
||||||
module.exports.player=function(player,serv)
|
module.exports.player=function(player,serv)
|
||||||
{
|
{
|
||||||
player.kick = reason =>
|
player.kick = (reason="You were kicked!") =>
|
||||||
{
|
player._client.end(reason);
|
||||||
player._client.write('kick_disconnect', {
|
|
||||||
reason: reason ? JSON.stringify(reason) : '"You were kicked!"'
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
player.ban = reason => {
|
player.ban = reason => {
|
||||||
reason = reason || "You were banned!";
|
reason = reason || "You were banned!";
|
||||||
|
|
@ -82,7 +78,7 @@ module.exports.player=function(player,serv)
|
||||||
reason = reason || "You were IP banned!"
|
reason = reason || "You were IP banned!"
|
||||||
player.kick(reason)
|
player.kick(reason)
|
||||||
serv.banIP(player._client.socket.remoteAddress)
|
serv.banIP(player._client.socket.remoteAddress)
|
||||||
}
|
};
|
||||||
|
|
||||||
player.pardon = () => serv.pardon(player._client.uuid);
|
player.pardon = () => serv.pardon(player._client.uuid);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,45 @@ describe("Server with mineflayer connection", function() {
|
||||||
async function onGround(bot)
|
async function onGround(bot)
|
||||||
{
|
{
|
||||||
await new Promise((cb) => {
|
await new Promise((cb) => {
|
||||||
var l=() => {
|
var l=() => {
|
||||||
if(bot.entity.onGround) {
|
if(bot.entity.onGround) {
|
||||||
bot.removeListener("move",l);
|
bot.removeListener("move",l);
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
bot.on("move",l);
|
bot.on("move",l);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitMessage(bot,message) {
|
||||||
|
let msg1=await once(bot,'message');
|
||||||
|
assert.equal(msg1.text,message);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitMessages(bot,messages) {
|
||||||
|
var toReceive=messages.reduce((acc,message) => {
|
||||||
|
acc[message]=1;
|
||||||
|
return acc;
|
||||||
|
},{});
|
||||||
|
var received={};
|
||||||
|
return new Promise(cb => {
|
||||||
|
var listener=msg => {
|
||||||
|
var message=msg.text;
|
||||||
|
if(!toReceive[message]) throw new Error("Received "+message+" , expected to receive one of "+messages);
|
||||||
|
if(received[message]) throw new Error("Received "+message+" two times");
|
||||||
|
received[message]=1;
|
||||||
|
if(Object.keys(received).length==messages.length)
|
||||||
|
{
|
||||||
|
bot.removeListener('message',listener);
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
bot.on('message',listener);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitLoginMessage(bot) {
|
||||||
|
return Promise.all([waitMessages(bot,['bot joined the game.','bot2 joined the game.'])]);
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
|
|
@ -50,12 +81,11 @@ describe("Server with mineflayer connection", function() {
|
||||||
username: "bot2"
|
username: "bot2"
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all([once(bot,'login'),once(bot2,'login')]);
|
await Promise.all([once(bot,'login'),once(bot2,'login')]);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(async () => {
|
||||||
serv._server.close();
|
await serv.quit();
|
||||||
return once(serv._server,"close");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -94,7 +124,9 @@ describe("Server with mineflayer connection", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("commands",() => {
|
describe("commands",() => {
|
||||||
|
|
||||||
it("has an help command", async () => {
|
it("has an help command", async () => {
|
||||||
|
await waitLoginMessage(bot);
|
||||||
bot.chat("/help");
|
bot.chat("/help");
|
||||||
await once(bot,"message");
|
await once(bot,"message");
|
||||||
});
|
});
|
||||||
|
|
@ -162,12 +194,11 @@ describe("Server with mineflayer connection", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("can use /deop",async () => {
|
it("can use /deop",async () => {
|
||||||
|
await waitLoginMessage(bot);
|
||||||
bot.chat('/deop bot');
|
bot.chat('/deop bot');
|
||||||
let msg1=await once(bot,'message');
|
await waitMessage(bot,'bot is deopped');
|
||||||
assert.equal(msg1.text,'bot is deopped');
|
|
||||||
bot.chat('/op bot');
|
bot.chat('/op bot');
|
||||||
let msg2=await once(bot,'message');
|
await waitMessage(bot,'You do not have permission to use this command');
|
||||||
assert.equal(msg2.text,'You do not have permission to use this command');
|
|
||||||
serv.getPlayer("bot").op=true;
|
serv.getPlayer("bot").op=true;
|
||||||
});
|
});
|
||||||
it("can use /setblock",async() => {
|
it("can use /setblock",async() => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue