private void Server_GetNewMessage(byte[] Content, MessageBase Message, System.Net.EndPoint FromIP) { if (Message.MessageType == SocketMessageType.BulletChat) { BulletChatModel msg = BulletChatModel.ToModel <BulletChatModel>(Content); ThreadPool.QueueUserWorkItem(a => { Dispatcher.Invoke(() => { //BulletBase form = new BulletBase(msg); BulletChatsForm.MainBulletChatsForm.ShowBulletChat(msg, TextBulletChat.Direction.Right, TextBulletChat.Direction.Left); }); }); } }
private void Server_GetNewMessage(byte[] Content, MessageBase Message, System.Net.EndPoint FromIP) { if (BlackMembers.Where(ip => FromIP == ip).Count() > 0) { return; //如果是黑名单就拒收 } String TagMessage = ""; if (Message.MessageType == SocketMessageType.IsOnLine) { IsOnLine onlin = IsOnLine.ToModel <IsOnLine>(Content); if (OnLineUsers.Keys.Where(k => k.Equals(FromIP)).Count() > 0) { OnLineUsers[FromIP] = DateTime.Now; } else { OnLineUsers.Add(FromIP, DateTime.Now); Dispatcher.Invoke(() => { LIST_OnlineUsers.Items.Add(new { IpAddress = FromIP, Content = onlin, }); }); } TagMessage = "在线确认消息"; } else if (Message.MessageType == SocketMessageType.SelectServer) { Server.SendTo(SelectServer.Server_Return(StaticResource.IPV4Address + ":" + StaticResource.ServerPort).ToByte(), FromIP); } else if (Message.MessageType == SocketMessageType.BulletChat) { BulletChatModel bullet = BulletChatModel.ToModel <BulletChatModel>(Content); TagMessage = $"{bullet.SendUser}发送的弹幕:{bullet.Message}"; foreach (EndPoint user in OnLineUsers.Keys) { if (BlackMembers.Where(ip => ip.Equals(user)).Count() > 0) { continue; } Server.SendTo(Content, user); } } Dispatcher.Invoke(() => { if (LIST_Messages.Items.Count >= 10) { LIST_Messages.Items.Clear(); } LIST_Messages.Items.Add(new { Tag = TagMessage, IpAddress = FromIP, MessageType = Message.MessageType, Length = Content.Length, }); }); }