mirror of
https://github.com/Threnklyn/MinecraftChat.git
synced 2026-05-19 04:43:28 +02:00
Working connect/disconnect handlers and status indicator
This commit is contained in:
@@ -13,9 +13,4 @@ module.exports = function($scope, socket, buffer) {
|
||||
buffer.append('---');
|
||||
buffer.append('<br>');
|
||||
|
||||
// buffer errors when received
|
||||
socket.on('bot:error', function(error) {
|
||||
buffer.error(error);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
@@ -7,5 +7,6 @@ exports.register = function(app) {
|
||||
app.controller('connectController', require('./connectController'));
|
||||
app.controller('bufferController', require('./bufferController'));
|
||||
app.controller('chatController', require('./chatController'));
|
||||
app.controller('navController', require('./navController'));
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Connect Controller
|
||||
*/
|
||||
|
||||
module.exports = function($scope, socket) {
|
||||
|
||||
$scope.connected = false;
|
||||
|
||||
socket.on('bot:connect', function(data) {
|
||||
$scope.$apply(function() {
|
||||
$scope.host = data.host;
|
||||
$scope.port = data.port;
|
||||
$scope.username = data.username;
|
||||
$scope.connected = true;
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('bot:disconnect', function() {
|
||||
$scope.$apply(function() {
|
||||
$scope.connected = false;
|
||||
});
|
||||
})
|
||||
|
||||
socket.on('disconnect', function() {
|
||||
$scope.$apply(function() {
|
||||
$scope.connected = false;
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
@@ -15,7 +15,7 @@ module.exports = function(socket) {
|
||||
});
|
||||
|
||||
socket.on('buffer:error', function(string) {
|
||||
$('#buffer').append('<span style="color:#D62D18;">[i] ' + error + '</span><br>')
|
||||
$('#buffer').append('<span style="color:#D62D18;">[i] ' + string + '</span><br>')
|
||||
$('#buffer').scrollTop($('#buffer').prop('scrollHeight'));
|
||||
});
|
||||
|
||||
|
||||
@@ -30,7 +30,11 @@ module.exports = function(socket) {
|
||||
// login event
|
||||
bot.on('login', function() {
|
||||
socket.emit('buffer:success', 'Successfully logged in as ' + bot.username + ' with entity id ' + bot.entity.id);
|
||||
socket.emit('bot:login')
|
||||
socket.emit('bot:connect', {
|
||||
host: socket.connectionParams.hostname,
|
||||
port: socket.connectionParams.port,
|
||||
username: socket.connectionParams.username
|
||||
});
|
||||
});
|
||||
|
||||
// spawn event
|
||||
@@ -69,7 +73,7 @@ module.exports = function(socket) {
|
||||
|
||||
// format the buffer with the correct coloring
|
||||
buffer = buffer.replace(/§([0-9abcdef])([^§]*)/ig, function replace(regex, color, msg) {
|
||||
return '<span class="color-'+color+'">'+msg+'</span>';
|
||||
return '<span class="color-'+color+'">'+msg.replace(' ', ' ')+'</span>';
|
||||
});
|
||||
|
||||
// send line back to the client
|
||||
@@ -77,4 +81,14 @@ module.exports = function(socket) {
|
||||
|
||||
});
|
||||
|
||||
bot.on('end', function() {
|
||||
socket.emit('buffer:error', 'Connection lost...');
|
||||
socket.emit('bot:disconnect');
|
||||
});
|
||||
|
||||
bot.on('kick', function(reason) {
|
||||
console.log(reason);
|
||||
socket.emit('buffer:error', 'Kicked for: ' + reason);
|
||||
});
|
||||
|
||||
};
|
||||
@@ -16,9 +16,13 @@ module.exports = function(socket) {
|
||||
password: data.password
|
||||
});
|
||||
|
||||
// store connection params in socket
|
||||
socket.connectionParams = data;
|
||||
|
||||
// prepare for errors
|
||||
socket.mcbot.on('error', function(error) {
|
||||
socket.emit('buffer:error', error);
|
||||
socket.mcbot = null;
|
||||
});
|
||||
|
||||
// bind bot events
|
||||
|
||||
Reference in New Issue
Block a user