internal void HandleMessage(Guid clientId, Container container) { if (!_connections.TryGetValue(clientId, out WsConnection connection)) { return; } _connections.RefreshLifeClient(clientId); switch (container.Identifier) { case DispatchType.Login: if (((JObject)container.Payload).ToObject(typeof(LoginRequestContainer)) is LoginRequestContainer loginRequest) { LoginResponseContainer loginResponse; bool isEnter = true; DispatchType stage; if (UserOnlineList.Contains(loginRequest.Content)) { loginResponse = new LoginResponseContainer( new Response(ResponseType.Failure, $"Client with name '{loginRequest.Content}' yet connect."), null, null, null, null); connection.Send(loginResponse.GetContainer()); connection.Login = $"pseudo-{loginRequest.Content}"; stage = DispatchType.Connection; } else { isEnter = UserOfflineList.Contains(loginRequest.Content); loginResponse = new LoginResponseContainer(new Response(ResponseType.Ok, "Connected"), null, null, null, null); connection.Login = loginRequest.Content; stage = DispatchType.Login; } var eventLogMessage = new EventLogMessage { IsSuccessfully = loginResponse.Content.Result == ResponseType.Ok == isEnter, SenderName = _name, Text = loginResponse.Content.Reason, Time = DateTime.Now, Type = stage }; ConnectionStateChanged?.Invoke(this, new ConnectionStateChangedEventArgs(connection.Login, true, eventLogMessage)); } break; case DispatchType.Message: MessageReceivedEventArgs message = MessageSorter.GetSortedMessage((JObject)container.Payload); MessageReceived?.Invoke(this, message); Send(MessageSorter.GetSortedMessage(message.Author, message.Message, InterfaceType.WebSocket, message.Agenda), message.Agenda); break; } }
/// <summary> /// 插入用户 /// </summary> /// <param name="username">用户名</param> public void InsertOnlineUser(string username) { UserOnlineList.Remove(Common.GetSessionID); OnlineUser <string> us = new OnlineUser <string>(); us.U_Guid = Common.GetSessionID; us.U_Name = username; us.U_Type = true; us.U_LastUrl = Common.GetScriptUrl; UserOnlineList.InsertUser(us.U_Guid, us); }
protected void Page_Load(object sender, EventArgs e) { DisplayAds = false; DisplaySideAds = false; Title = HostProfile.SiteTitle + " : Kick Spy!"; PageName = UrlFactory.PageName.KickSpy; UserOnlineList.DataBind(UserCache.GetOnlineUsers(30, HostProfile.HostID, KickUserProfile)); Shoutbox.DataBind((ShoutCache.GetLatestShouts(HostProfile.HostID))); }
/// <summary> /// 检测当前用户是否在线 /// </summary> /// <param name="username">用户名</param> /// <param name="sessionid">用户唯一标识</param> /// <returns>是/否</returns> public bool CheckUserInOnline(string username, string sessionid) { return(UserOnlineList.CheckKeyOnline(sessionid)); }
/// <summary> /// 删除在线用户 /// </summary> /// <param name="username">用户名</param> /// <param name="sessionid">用户sessionid</param> public void OnlineRemove(string username, string sessionid) { UserOnlineList.Remove(sessionid); }
public bool IsContains(string user) { return(UserOnlineList.Contains(user) || UserOfflineList.Contains(user)); }
internal void HandlePacket(IPEndPoint remoteEndpoint, byte[] packet) { string serializedMessages = GetStringPacket(packet); var container = JsonConvert.DeserializeObject <Container>(serializedMessages); if (!_connections.TryGetValue(remoteEndpoint, out TcpConnection connection)) { return; } _connections.RefreshLifeClient(remoteEndpoint); switch (container.Identifier) { case DispatchType.Login: if (((JObject)container.Payload).ToObject(typeof(LoginRequestContainer)) is LoginRequestContainer loginRequest) { LoginResponseContainer loginResponse; bool isEnter = true; DispatchType stage; if (UserOnlineList.Contains(loginRequest.Content)) { loginResponse = new LoginResponseContainer( new Response(ResponseType.Failure, $"Client with name '{loginRequest.Content}' yet connect."), null, null, null, null); connection.Send(ConvertToBytes(loginResponse.GetContainer())); connection.Login = $"pseudo-{loginRequest.Content}"; stage = DispatchType.Connection; } else { isEnter = UserOfflineList.Contains(loginRequest.Content); loginResponse = new LoginResponseContainer(new Response(ResponseType.Ok, "Connected"), null, null, null, null); connection.Login = loginRequest.Content; stage = DispatchType.Login; } var eventLogMessage = new EventLogMessage { IsSuccessfully = loginResponse.Content.Result == ResponseType.Ok == isEnter, SenderName = _name, Text = loginResponse.Content.Reason, Time = DateTime.Now, Type = stage }; ConnectionStateChanged?.Invoke(this, new ConnectionStateChangedEventArgs(connection.Login, true, eventLogMessage)); } break; case DispatchType.Message: MessageReceivedEventArgs message = MessageSorter.GetSortedMessage((JObject)container.Payload); MessageReceived?.Invoke(this, message); Send(MessageSorter.GetSortedMessage(message.Author, message.Message, InterfaceType.Tcp, message.Agenda), message.Agenda); break; } }