mirror of
https://github.com/Threnklyn/MinecraftChat.git
synced 2026-05-28 08:48:30 +02:00
My Servers Feature
Store your favorite servers to easily select them when connecting
This commit is contained in:
@@ -46,7 +46,6 @@ module.exports = function(socket, sound) {
|
||||
socket.on('disconnect', function() {
|
||||
$('#buffer').append('<span style="color:#D62D18;">> Connection to chat server has been lost. Reconnecting...</span><br>');
|
||||
$('#buffer').scrollTop($('#buffer').prop('scrollHeight'));
|
||||
sound.error();
|
||||
});
|
||||
|
||||
socket.on('bot:disconnect', function() {
|
||||
|
||||
@@ -5,12 +5,15 @@
|
||||
exports.register = function(app) {
|
||||
|
||||
// socket factory
|
||||
app.factory('socket', require('./socket'));
|
||||
app.factory('socket', require('./socket'));
|
||||
|
||||
// buffer factory
|
||||
app.factory('buffer', require('./buffer'));
|
||||
app.factory('buffer', require('./buffer'));
|
||||
|
||||
// sound factory
|
||||
app.factory('sound', require('./sound'));
|
||||
app.factory('sound', require('./sound'));
|
||||
|
||||
// servers factory
|
||||
app.factory('servers', require('./servers'));
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
module.exports = function() {
|
||||
|
||||
// function to save servers into localStorage
|
||||
function save() {
|
||||
localStorage.servers = JSON.stringify(servers);
|
||||
}
|
||||
|
||||
|
||||
// default servers
|
||||
var defaultServers = [
|
||||
{name: 'LattyCraft', ip: 'us.latty.info', port: 25565}
|
||||
];
|
||||
|
||||
|
||||
// load servers from localstorage
|
||||
var servers = JSON.parse(localStorage.servers);
|
||||
|
||||
if (!servers || servers.length === 0) {
|
||||
servers = defaultServers;
|
||||
save();
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
get: function() {
|
||||
return servers;
|
||||
},
|
||||
select: function(id) {
|
||||
return servers[id];
|
||||
},
|
||||
add: function(server) {
|
||||
servers.push(server);
|
||||
save();
|
||||
},
|
||||
delete: function(index) {
|
||||
servers.splice(index, 1);
|
||||
save();
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user