Beispiel #1
0
        public void BanUser(SockChatUser user, DateTimeOffset?until = null, bool banIPs = false, string type = Constants.LEAVE_KICK)
        {
            if (until.HasValue && until.Value <= DateTimeOffset.UtcNow)
            {
                until = null;
            }

            if (until.HasValue)
            {
                user.Send(new ForceDisconnectPacket(ForceDisconnectReason.Banned, until.Value));
                user.BannedUntil = until.Value;

                if (banIPs)
                {
                    lock (user.Connections)
                        foreach (string ip in user.RemoteAddresses)
                        {
                            if (IPAddress.TryParse(ip, out IPAddress ipAddr))
                            {
                                IPBans[ipAddr] = until.Value;
                            }
                        }
                }
            }
            else
            {
                user.Send(new ForceDisconnectPacket(ForceDisconnectReason.Kicked));
            }

            user.Close();
            UserLeave(user.Channel, user, type);
        }
Beispiel #2
0
        public void SwitchChannel(SockChatUser user, SockChatChannel chan, string password)
        {
            if (user.Channel == chan)
            {
                //user.Send(true, @"samechan", chan.Name);
                user.ForceChannel();
                return;
            }

            if (!user.IsModerator && chan.Owner != user)
            {
                if (chan.Hierarchy > user.Hierarchy)
                {
                    user.Send(true, @"ipchan", chan.Name);
                    user.ForceChannel();
                    return;
                }

                if (chan.Password != password)
                {
                    user.Send(true, @"ipwchan", chan.Name);
                    user.ForceChannel();
                    return;
                }
            }

            ForceChannelSwitch(user, chan);
        }
Beispiel #3
0
        public void ForceChannelSwitch(SockChatUser user, SockChatChannel chan)
        {
            if (!Channels.Contains(chan))
            {
                return;
            }

            int             messageId = SockChatMessage.NextMessageId;
            SockChatChannel oldChan   = user.Channel;

            oldChan.Send(new UserChannelLeavePacket(user), messageId);
            chan.Send(new UserChannelJoinPacket(user), messageId);

            user.Send(new ContextClearPacket(ContextClearMode.MessagesUsers));
            user.Send(new ContextUsersPacket(chan.GetUsers(new[] { user })));

            IChatMessage[] msgs = GetChannelBacklog(chan);

            foreach (IChatMessage msg in msgs)
            {
                user.Send(new ContextMessagePacket(msg));
            }

            user.ForceChannel(chan);
            oldChan.UserLeave(user);
            chan.UserJoin(user);

            if (oldChan.IsTemporary && oldChan.Owner == user)
            {
                DeleteChannel(oldChan);
            }
        }
Beispiel #4
0
        public void SwitchChannel(SockChatUser user, string chanName, string password)
        {
            SockChatChannel chan = FindChannelByName(chanName);

            if (chan == null)
            {
                user.Send(true, @"nochan", chanName);
                user.ForceChannel();
                return;
            }

            SwitchChannel(user, chan, password);
        }