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