/// <summary> /// Returns session with given id, or null if it doesn't exist. /// </summary> /// <param name="sessionId"></param> /// <returns></returns> public ChatSession Get(long sessionId) { ChatSession result = null; lock (_sessions) _sessions.TryGetValue(sessionId, out result); return(result); }
/// <summary> /// Removes session from manager. /// </summary> /// <param name="session"></param> public void Remove(ChatSession session) { lock (_sessions) _sessions.Remove(session.Id); }
/// <summary> /// Adds session to manager. /// </summary> /// <param name="session"></param> public void Add(ChatSession session) { lock (_sessions) _sessions[session.Id] = session; }
/// <summary> /// Removes session from manager. /// </summary> /// <param name="session"></param> public void Remove(ChatSession session) { lock (_sessions) _sessions.Remove(session.Id); }
/// <summary> /// Adds session to manager. /// </summary> /// <param name="session"></param> public void Add(ChatSession session) { lock (_sessions) _sessions[session.Id] = session; }
/// <summary> /// Notifies session user about user closing chat window. /// </summary> /// <param name="session"></param> /// <param name="user"></param> public static void ChatLeave(ChatSession session, User user) { var packet = new Packet(Op.Msgr.ChatLeave, 0); packet.PutLong(session.Id); packet.PutInt(user.Id); session.Broadcast(packet); }
/// <summary> /// Sends initial chat session information to user. /// </summary> /// <param name="user"></param> /// <param name="session"></param> public static void ChatJoin(User user, ChatSession session) { var users = session.GetUsers(); var packet = new Packet(Op.Msgr.ChatJoin, 0); packet.PutLong(session.Id); packet.PutInt(users.Length); foreach (var sessionUser in users) { packet.PutInt(sessionUser.Id); packet.PutString(sessionUser.FullName); } user.Client.Send(packet); }
/// <summary> /// Broadcasts chat message in session. /// </summary> /// <param name="session"></param> /// <param name="contactId"></param> /// <param name="message"></param> public static void ChatR(ChatSession session, int contactId, string message) { var packet = new Packet(Op.Msgr.ChatR, 0); packet.PutLong(session.Id); packet.PutInt(contactId); packet.PutString(message); session.Broadcast(packet); }
/// <summary> /// Notifies users about someone joining the chat. /// </summary> /// <param name="session"></param> /// <param name="user"></param> public static void ChatInviteR(ChatSession session, User user) { var packet = new Packet(Op.Msgr.ChatInviteR, 0); packet.PutLong(session.Id); packet.PutInt(user.Id); packet.PutString(user.FullName); packet.PutString(user.Nickname); session.Broadcast(packet); }