Files
MinecraftChat/app/server/bot/events/players.js
T
2015-04-30 00:28:48 -05:00

33 lines
706 B
JavaScript

module.exports = function(socket) {
var interval;
// send the player list as soon as the bot spawns
socket.mcbot.on('spawn', function() {
socket.emit('bot:players', socket.mcbot.players);
// update the client with the player list every 5 seconds
interval = setInterval(function() {
if (socket.mcbot && socket.mcbot.entity) {
socket.emit('bot:players', socket.mcbot.players);
} else {
console.error('leaked interval!');
}
}, 5000);
});
socket.mcbot.on('end', function() {
if (interval) {
clearInterval(interval);
}
});
socket.on('disconnect', function() {
if (interval) {
clearInterval(interval);
}
});
};