diff --git a/lib/bgtask.js b/lib/bgtask.js index 5791d34e..5734bd09 100644 --- a/lib/bgtask.js +++ b/lib/bgtask.js @@ -73,7 +73,7 @@ function initChannelDumper(Server) { for (var i = 0; i < Server.channels.length; i++) { var chan = Server.channels[i]; if (!chan.dead && chan.users && chan.users.length > 0) { - chan.saveDump(); + chan.saveState(); } } }, CHANNEL_SAVE_INTERVAL); diff --git a/lib/channel-new.js b/lib/channel-new.js index 4d5c58e7..0660e59b 100644 --- a/lib/channel-new.js +++ b/lib/channel-new.js @@ -467,7 +467,7 @@ Channel.prototype.join = function (user, password) { user.whenLoggedIn(function () { var lname = user.name.toLowerCase(); for (var i = 0; i < self.users.length; i++) { - if (self.users[i] !== user) { + if (self.users[i].name.toLowerCase() === lname && self.users[i] !== user) { self.users[i].kick("Duplicate login"); } } @@ -485,6 +485,7 @@ Channel.prototype.join = function (user, password) { user.socket.emit("rank", user.rank); self.sendUserJoin(self.users, user); + self.sendUserlist([user]); }); }); @@ -994,34 +995,29 @@ Channel.prototype.sendDrinkCount = function (users) { */ Channel.prototype.sendUserlist = function (toUsers) { var self = this; - var users = []; - var detailedUsers = []; + var base = []; + var mod = []; + var sadmin = []; - for (var i = 0; i < this.users.length; i++) { - var u = this.users[i]; + for (var i = 0; i < self.users.length; i++) { + var u = self.users[i]; if (u.name === "") { continue; } - users.push({ - name: u.name, - rank: u.rank, - profile: u.profile - }); - - detailedUsers.push({ - name: u.name, - rank: u.rank, - meta: u.meta, - profile: u.profile - }); + var data = self.packUserData(self.users[i]); + base.push(data.base); + mod.push(data.mod); + sadmin.push(data.sadmin); } toUsers.forEach(function (u) { - if (u.rank >= 2) { - u.socket.emit("userlist", detailedUsers); + if (u.global_rank >= 255) { + u.socket.emit("userlist", sadmin); + } else if (u.rank >= 2) { + u.socket.emit("userlist", mod); } else { - u.socket.emit("userlist", users); + u.socket.emit("userlist", base); } if (self.leader != null) { @@ -1052,6 +1048,53 @@ Channel.prototype.sendRecentChat = function (users) { }); }; +/** + * Packs userdata for addUser or userlist + */ +Channel.prototype.packUserData = function (user) { + var base = { + name: user.name, + rank: user.rank, + profile: user.profile, + meta: { + afk: user.meta.afk, + muted: user.meta.muted && !user.meta.smuted + } + }; + + var mod = { + name: user.name, + rank: user.rank, + profile: user.profile, + meta: { + afk: user.meta.afk, + muted: user.meta.muted, + smuted: user.meta.smuted, + aliases: user.meta.aliases, + ip: util.maskIP(user.ip) + } + }; + + var sadmin = { + name: user.name, + rank: user.rank, + profile: user.profile, + meta: { + afk: user.meta.afk, + muted: user.meta.muted, + smuted: user.meta.smuted, + aliases: user.meta.aliases, + ip: user.ip + } + }; + + return { + base: base, + mod: mod, + sadmin: sadmin + }; +}; + /** * Send a user join notification */ @@ -1062,7 +1105,7 @@ Channel.prototype.sendUserJoin = function (users, user) { return; } - if (err) { + if (err || aliases.length === 0) { aliases = [user.name]; } @@ -1076,41 +1119,20 @@ Channel.prototype.sendUserJoin = function (users, user) { if (self.isShadowMuted(user.name)) { user.meta.muted = true; user.meta.shadowmuted = true; - user.meta.icon = "icon-volume-off"; } else if (self.isMuted(user.name)) { user.meta.muted = true; user.meta.shadowmuted = false; - user.meta.icon = "icon-volume-off"; } - var base = { - name: user.name, - rank: user.rank, - profile: user.profile, - meta: { - afk: user.meta.afk - } - }; - - if (user.meta.icon && !user.meta.shadowmuted) { - base.meta.icon = user.meta.icon; - } - - var mod = { - name: user.name, - rank: user.rank, - profile: user.profile, - meta: { - afk: user.meta.afk, - icon: user.meta.icon - } - }; + var data = self.packUserData(user); users.forEach(function (u) { - if (u.rank >= 2) { - u.socket.emit("addUser", mod); + if (u.global_rank >= 255) { + u.socket.emit("addUser", data.sadmin); + } else if (u.rank >= 2) { + u.socket.emit("addUser", data.mod); } else { - u.socket.emit("addUser", base); + u.socket.emit("addUser", data.base); } }); diff --git a/lib/user.js b/lib/user.js index d566b94f..79eedffd 100644 --- a/lib/user.js +++ b/lib/user.js @@ -126,6 +126,34 @@ User.prototype.kick = function (reason) { this.socket.disconnect(true); }; +/** + * Packs user metadata + */ +User.prototype.packMeta = function (opts) { + var meta = {}; + if (opts.afk) { + meta.afk = this.meta.afk; + } + + if (opts.aliases) { + meta.aliases = this.meta.aliases; + } + + if (opts.ip) { + meta.ip = this.ip; + } + + if (opts.muted) { + meta.muted = this.meta.muted; + } + + if (opts.smuted) { + meta.smuted = this.meta.smuted; + } + + return meta; +}; + /** * Initializes socket message callbacks for a channel user */ diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index b37ec3e7..8ac6af6c 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -713,7 +713,7 @@ Callbacks = { div.data("rank", data.rank); div.data("leader", Boolean(data.leader)); div.data("profile", data.profile); - div.data("icon", data.meta.icon); + div.data("meta", data.meta); div.data("afk", data.meta.afk); formatUserlistItem(div, data); addUserDropdown(div, data); @@ -721,6 +721,15 @@ Callbacks = { sortUserlist(); }, + setUserMeta: function (data) { + var user = findUserlistItem(data.name); + if (user == null) { + return; + } + + user.data("meta", data); + }, + setUserProfile: function (data) { var user = findUserlistItem(data.name); if (user === null) @@ -978,8 +987,8 @@ Callbacks = { handleMediaUpdate(data); }, - setPlaylistLocked: function(data) { - CHANNEL.openqueue = !data.locked; + setPlaylistLocked: function (locked) { + CHANNEL.openqueue = !locked; handlePermissionChange(); if(CHANNEL.openqueue) { $("#qlockbtn").removeClass("btn-danger") @@ -1191,7 +1200,7 @@ Callbacks = { } } -var SOCKET_DEBUG = false; +var SOCKET_DEBUG = true; setupCallbacks = function() { for(var key in Callbacks) { (function(key) { diff --git a/www/assets/js/util.js b/www/assets/js/util.js index 613f55f7..83b4c273 100644 --- a/www/assets/js/util.js +++ b/www/assets/js/util.js @@ -110,6 +110,15 @@ function formatUserlistItem(div) { .appendTo(profile); } $("").text(data.name).appendTo(profile); + + var meta = div.data("meta") || {}; + if (meta.ip) { + $("
").appendTo(profile); + $("").text(meta.ip).appendTo(profile); + } + if (meta.aliases) { + $("

").text("aliases: " + meta.aliases.join(", ")).appendTo(profile); + } $("

").text(data.profile.text).appendTo(profile); }); name.mousemove(function(ev) { @@ -555,7 +564,7 @@ function showUserOptions() { $("#us-chat-notice").prop("checked", USEROPTS.blink_title); $("#us-boop").prop("checked", USEROPTS.boop); $("#us-sendbtn").prop("checked", USEROPTS.chatbtn); - + $("#us-modflair").prop("checked", USEROPTS.modhat); $("#us-joinmessage").prop("checked", USEROPTS.joinmessage);