Beispiel #1
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 #2
0
        public void HandleJoin(SockChatUser user, SockChatChannel chan, SockChatConn conn)
        {
            if (!chan.HasUser(user))
            {
                chan.Send(new UserConnectPacket(DateTimeOffset.Now, user), SockChatMessage.NextMessageId);
            }

            conn.Send(new AuthSuccessPacket(user, chan));
            conn.Send(new ContextUsersPacket(chan.GetUsers(new[] { user })));

            IChatMessage[] msgs = GetChannelBacklog(chan);

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

            lock (Channels)
                conn.Send(new ContextChannelsPacket(Channels.Where(x => user.Hierarchy >= x.Hierarchy)));

            if (!chan.HasUser(user))
            {
                chan.UserJoin(user);
            }

            if (!Users.Contains(user))
            {
                Users.Add(user);
            }
        }