mirror of https://github.com/calzoneman/sync.git
Reject joins for channels mapped to other partitions
This commit is contained in:
parent
77465e6b49
commit
a360cd8808
|
@ -71,6 +71,7 @@ var Server = function () {
|
||||||
initModule = new BackendModule();
|
initModule = new BackendModule();
|
||||||
} else if (Config.get('enable-partition')) {
|
} else if (Config.get('enable-partition')) {
|
||||||
initModule = new PartitionModule();
|
initModule = new PartitionModule();
|
||||||
|
self.partitionDecider = initModule.getPartitionDecider();
|
||||||
} else {
|
} else {
|
||||||
initModule = new LegacyModule();
|
initModule = new LegacyModule();
|
||||||
}
|
}
|
||||||
|
@ -186,8 +187,15 @@ Server.prototype.isChannelLoaded = function (name) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Server.prototype.getChannel = function (name) {
|
Server.prototype.getChannel = function (name) {
|
||||||
var self = this;
|
|
||||||
var cname = name.toLowerCase();
|
var cname = name.toLowerCase();
|
||||||
|
if (this.partitionDecider &&
|
||||||
|
!this.partitionDecider.isChannelOnThisPartition(cname)) {
|
||||||
|
const error = new Error(`Channel '${cname}' is mapped to a different partition`);
|
||||||
|
error.code = 'EWRONGPART';
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
for (var i = 0; i < self.channels.length; i++) {
|
for (var i = 0; i < self.channels.length; i++) {
|
||||||
if (self.channels[i].uniqueName === cname)
|
if (self.channels[i].uniqueName === cname)
|
||||||
return self.channels[i];
|
return self.channels[i];
|
||||||
|
|
15
src/user.js
15
src/user.js
|
@ -53,7 +53,20 @@ function User(socket) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.waitFlag(Flags.U_READY, function () {
|
self.waitFlag(Flags.U_READY, function () {
|
||||||
var chan = Server.getServer().getChannel(data.name);
|
var chan;
|
||||||
|
try {
|
||||||
|
chan = Server.getServer().getChannel(data.name);
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code !== 'EWRONGPART') {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.socket.emit("errorMsg", {
|
||||||
|
msg: "Channel '" + data.name + "' is hosted on another server. " +
|
||||||
|
"Try refreshing the page to update the connection URL."
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
chan.joinUser(self, data);
|
chan.joinUser(self, data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue