Esempio n. 1
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);
        }