Fix crash when hostname is changed in lockNetwork mode

Fixes #2040
This commit is contained in:
Pavel Djundik 2018-02-07 11:56:49 +02:00
parent 99ee31d795
commit aee1ec2739
3 changed files with 18 additions and 3 deletions

View File

@ -224,7 +224,7 @@ Client.prototype.connect = function(args) {
if (config.lockNetwork) {
// This check is needed to prevent invalid user configurations
if (args.host && args.host.length > 0 && args.host !== config.defaults.host) {
if (!Helper.config.public && args.host && args.host.length > 0 && args.host !== config.defaults.host) {
network.channels[0].pushMessage(client, new Msg({
type: Msg.Type.ERROR,
text: "Hostname you specified is not allowed.",

View File

@ -98,6 +98,12 @@ Chan.prototype.dereferencePreviews = function(messages) {
};
Chan.prototype.getSortedUsers = function(irc) {
const users = Array.from(this.users.values());
if (!irc || !irc.network || !irc.network.options || !irc.network.options.PREFIX) {
return users;
}
var userModeSortPriority = {};
irc.network.options.PREFIX.forEach((prefix, index) => {
userModeSortPriority[prefix.symbol] = index;
@ -105,8 +111,6 @@ Chan.prototype.getSortedUsers = function(irc) {
userModeSortPriority[""] = 99; // No mode is lowest
const users = Array.from(this.users.values());
return users.sort(function(a, b) {
if (a.mode === b.mode) {
return a.nick.toLowerCase() < b.nick.toLowerCase() ? -1 : 1;

View File

@ -86,6 +86,17 @@ describe("Chan", function() {
return chan.getSortedUsers(network).map((u) => u.nick);
};
it("returns unsorted list on null irc object", function() {
const chan = new Chan();
[
"JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P",
].forEach((nick) => chan.setUser(new User({nick: nick})));
expect(chan.getSortedUsers().map((u) => u.nick)).to.deep.equal([
"JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P",
]);
});
it("should sort a simple user list", function() {
const chan = new Chan();
[