1 var ChannelModule
= require("./module");
2 var Flags
= require("../flags");
4 function AccessControlModule(_channel
) {
5 ChannelModule
.apply(this, arguments
);
8 AccessControlModule
.prototype = Object
.create(ChannelModule
.prototype);
10 AccessControlModule
.prototype.onUserPreJoin = function (user
, data
, cb
) {
11 var chan
= this.channel
,
12 opts
= this.channel
.modules
.options
;
13 if (user
.socket
.disconnected
) {
14 return cb("User disconnected", ChannelModule
.DENY
);
17 if (opts
.get("password") !== false && data
.pw
!== opts
.get("password")) {
18 user
.socket
.on("disconnect", function () {
19 if (!user
.is(Flags
.U_IN_CHANNEL
)) {
20 cb("User disconnected", ChannelModule
.DENY
);
24 if (user
.is(Flags
.U_LOGGED_IN
) && user
.account
.effectiveRank
>= 2) {
25 cb(null, ChannelModule
.PASSTHROUGH
);
26 user
.socket
.emit("cancelNeedPassword");
28 user
.socket
.emit("needPassword", typeof data
.pw
!== "undefined");
29 /* Option 1: log in as a moderator */
30 user
.waitFlag(Flags
.U_HAS_CHANNEL_RANK
, function () {
31 if (user
.is(Flags
.U_IN_CHANNEL
)) {
35 if (user
.account
.effectiveRank
>= 2) {
36 cb(null, ChannelModule
.PASSTHROUGH
);
37 user
.socket
.emit("cancelNeedPassword");
41 /* Option 2: Enter correct password */
42 var pwListener = function (pw
) {
43 if (chan
.dead
|| user
.is(Flags
.U_IN_CHANNEL
)) {
47 if (pw
!== opts
.get("password")) {
48 user
.socket
.emit("needPassword", true);
52 user
.socket
.emit("cancelNeedPassword");
53 cb(null, ChannelModule
.PASSTHROUGH
);
56 user
.socket
.on("channelPassword", pwListener
);
59 cb(null, ChannelModule
.PASSTHROUGH
);
63 module
.exports
= AccessControlModule
;