示例#1
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);
            }
        }
示例#2
0
 public bool HasConnection(SockChatConn conn)
 => Connections.Contains(conn);
示例#3
0
 public void RemoveConnection(SockChatConn conn)
 => Connections.Remove(conn);
示例#4
0
 public void AddConnection(SockChatConn conn)
 => Connections.Add(conn);
示例#5
0
 public SockChatUser FindUserBySock(SockChatConn conn)
 {
     lock (Users)
         return(Users.ToList().FirstOrDefault(x => x.Connections.Any(y => y == conn)));
 }