예제 #1
0
 public void Disconnect(IUser user, UserDisconnectReason reason = UserDisconnectReason.Unknown)
 {
     if (user == null)
     {
         return;
     }
     Dispatcher.DispatchEvent(this, new UserDisconnectEvent(user, reason));
 }
예제 #2
0
 public ChannelUserLeaveEvent(IChannel channel, IUser user, UserDisconnectReason reason)
     : base(
         channel ?? throw new ArgumentNullException(nameof(channel)),
         user ?? throw new ArgumentNullException(nameof(user))
         )
 {
     Reason = reason;
 }
예제 #3
0
        public void LeaveChannel(IChannel channel, IUser user, UserDisconnectReason reason = UserDisconnectReason.Unknown)
        {
            if (channel == null)
            {
                throw new ArgumentNullException(nameof(channel));
            }
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (HasUser(channel, user))
            {
                Dispatcher.DispatchEvent(this, new ChannelUserLeaveEvent(channel, user, reason));
            }
        }
예제 #4
0
        // should this be moved to UserManager?
        public void BanUser(
            IUser user,
            TimeSpan duration,
            UserDisconnectReason reason = UserDisconnectReason.Kicked,
            bool isPermanent            = false,
            IUser modUser     = null,
            string textReason = null
            )
        {
            ForceDisconnectPacket packet;

            if (duration != TimeSpan.Zero || isPermanent)
            {
                if (string.IsNullOrWhiteSpace(textReason))
                {
                    textReason = reason switch {
                        UserDisconnectReason.Kicked => @"User was banned.",
                        UserDisconnectReason.Flood => @"User was kicked for flood protection.",
                        _ => @"Unknown reason given.",
                    }
                }
                ;

                DataProvider.BanClient.CreateBan(user.UserId, modUser?.UserId ?? -1, isPermanent, duration, textReason);

                packet = new ForceDisconnectPacket(ForceDisconnectReason.Banned, duration, isPermanent);
            }
            else
            {
                packet = new ForceDisconnectPacket(ForceDisconnectReason.Kicked);
            }

            // handle in users
            //user.SendPacket(packet);

            // channel users
            ChannelUsers.GetChannels(user, c => {
                foreach (IChannel chan in c)
                {
                    ChannelUsers.LeaveChannel(chan, user, reason);
                }
            });

            // a disconnect with Flood, Kicked or Banned should probably cause this
            // maybe forced disconnects should be their own event?
            Users.Disconnect(user, reason);
        }
예제 #5
0
        public void HandleLeave(SockChatChannel chan, SockChatUser user, string type = Constants.LEAVE_NORMAL)
        {
            UserDisconnectReason reason = UserDisconnectReason.Leave;

            switch (type)
            {
            case Constants.LEAVE_TIMEOUT:
                reason = UserDisconnectReason.TimeOut;
                break;

            case Constants.LEAVE_KICK:
                reason = UserDisconnectReason.Kicked;
                break;

            case Constants.LEAVE_FLOOD:
                reason = UserDisconnectReason.Flood;
                break;
            }

            chan.Send(new UserDisconnectPacket(DateTimeOffset.Now, user, reason));
        }
예제 #6
0
 public UserDisconnectPacket(DateTimeOffset disconnected, SockChatUser user, UserDisconnectReason reason)
 {
     Disconnected = disconnected;
     User         = user ?? throw new ArgumentNullException(nameof(user));
     Reason       = reason;
 }
예제 #7
0
 public ServerPartCommand(IChannel channel, IUser user, UserDisconnectReason reason)
 {
     Channel = channel ?? throw new ArgumentNullException(nameof(channel));
     Sender  = user ?? throw new ArgumentNullException(nameof(user));
     Reason  = reason;
 }
예제 #8
0
 public UserDisconnectEvent(IUser user, UserDisconnectReason reason)
     : base(null, user ?? throw new ArgumentNullException(nameof(user)))
 {
     Reason = reason;
 }
예제 #9
0
 public void UserLeave(IChannel chan, IUser user, UserDisconnectReason reason = UserDisconnectReason.Leave)
 {
     // handle in channelusers
     //chan.SendPacket(new UserDisconnectPacket(DateTimeOffset.Now, user, reason));
 }
예제 #10
0
 public ChannelUserLeaveEvent(IUser user, IChannel channel, UserDisconnectReason reason)
     : base(user, channel)
 {
     Reason = reason;
 }