Пример #1
0
        private void ProcessMemberQuery(Message message)
        {
            MemberQueryRequest request = SerializerUtil <MemberQueryRequest> .Deserialize(message.Content);

            //Filter
            HashSet <Membership> members = new HashSet <Membership>();
            var linq = members.Where(q => {
                bool name = string.IsNullOrEmpty(request.Name) || q.Name.IndexOf(request.Name) > 0;
                bool nick = string.IsNullOrEmpty(request.NickName) || q.NickName.IndexOf(request.NickName) > 0;
                bool dept = request.Department == null || request.Department.Count == 0;
                bool _ept = true;
                if (!dept)
                {
                    for (int i = 0; i < Math.Min(request.Department.Count, q.Department.Length); i++)
                    {
                        _ept = _ept && request.Department[i].IndexOf(q.Department[i]) >= 0;
                    }
                }
                return(name && nick && (dept || _ept));
            }).ToList();
            Message Reply = MessageFactory.CreateMemberQueryRespMessage(message.To, message.From, linq);

            byte[] b = SerializerUtil <Message> .Serialize(Reply);

            responseMsg.InitPool(b.Length); responseMsg.Put(b, 0, b.Length);
            server.Send(ref responseMsg, false);
        }
Пример #2
0
        private void ProcessMemberInfo(Message message)
        {
            MemberInfoRequest request = SerializerUtil <MemberInfoRequest> .Deserialize(message.Content);

            //Find Member
            Membership membership = new Membership()
            {
                ID             = new Guid(12, 34, 56, 78, 90, 13, 24, 25, 06, 77, 88),
                Name           = "未来的风", NickName = "没有风",
                LastLoginIP    = 0x7F_00_00_01, SuccessfullyLoginCount = 0,
                Department     = new string[] { "1", "2", "3", "4" },
                DepartmentInfo = "未见", DepartmentLevel = 4,
                PortraitID     = 1, CustomPortrait = null
            };
            Message Reply = MessageFactory.CreateMemberInfoRespMessage(message.To, message.From, membership);

            byte[] b = SerializerUtil <Message> .Serialize(Reply);

            responseMsg.InitPool(b.Length); responseMsg.Put(b, 0, b.Length);
            server.Send(ref responseMsg, false);
        }
Пример #3
0
        public OCForm()
        {
            sc = WindowsFormsSynchronizationContext.Current as WindowsFormsSynchronizationContext;

            InitializeComponent();

            flowLayoutPanelSysmenu.MouseDown   += MoveWindow;
            flowLayoutPanelSysmenu.DoubleClick += ResizeWindow;
            toolStripLeftPanel.MouseDown       += MoveWindow;
            toolStripLeftPanel.DoubleClick     += ResizeWindow;

            RegisterSysCommandBehavior();

            RegisterOwnerDraw();

            LoadLeftPanel();

            //Random randomGen = new Random();
            //KnownColor[] names = (KnownColor[])Enum.GetValues(typeof(KnownColor));

            lvConversations.Items.AddRange(new ListViewItem[] {
                new ListViewItem("1")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "姓名1", LastUpdate = DateTime.Now, PeekMessage = "Message1", IsMute = true
                    }
                },
                new ListViewItem("2")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name2", LastUpdate = DateTime.Now, PeekMessage = "\ue136", IsMute = true
                    }
                },
                new ListViewItem("3")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name3", LastUpdate = DateTime.Now, PeekMessage = "消息~3", IsMute = true
                    }
                },
                new ListViewItem("1")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "姓名1", LastUpdate = DateTime.Now, PeekMessage = "Message1", IsMute = true
                    }
                },
                new ListViewItem("2")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name2", LastUpdate = DateTime.Now, PeekMessage = "\ue137", IsMute = true
                    }
                },
                new ListViewItem("3")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name3", LastUpdate = DateTime.Now, PeekMessage = "消息~3", IsMute = true
                    }
                },
                new ListViewItem("1")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "姓名1", LastUpdate = DateTime.Now, PeekMessage = "Message1", IsMute = true
                    }
                },
                new ListViewItem("2")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name2", LastUpdate = DateTime.Now, PeekMessage = "Message2", IsMute = true
                    }
                },
                new ListViewItem("3")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name3", LastUpdate = DateTime.Now, PeekMessage = "消息~3", IsMute = true
                    }
                },
                new ListViewItem("1")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "姓名1", LastUpdate = DateTime.Now, PeekMessage = "\ue138", IsMute = true
                    }
                },
                new ListViewItem("2")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name2", LastUpdate = DateTime.Now, PeekMessage = "Message2", IsMute = true
                    }
                },
                new ListViewItem("3")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name3", LastUpdate = DateTime.Now, PeekMessage = "消息~3", IsMute = true
                    }
                },
                new ListViewItem("1")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "姓名1", LastUpdate = DateTime.Now, PeekMessage = "Message1", IsMute = true
                    }
                },
                new ListViewItem("2")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name2", LastUpdate = DateTime.Now, PeekMessage = "\ue139", IsMute = true
                    }
                },
                new ListViewItem("3")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name3", LastUpdate = DateTime.Now, PeekMessage = "消息~3", IsMute = true
                    }
                },
            });
            for (int i = 0; i < lvConversations.Items.Count; i++)
            {
                var shortcut = lvConversations.Items[i].Tag as ConversationShortcut;
                var chatUI   = GetChatUI(shortcut.Icon);
                chatrooms.AddOrUpdate(shortcut.Icon.ToString(), chatUI, (key, value) => chatUI);
                //chatUI.BackColor = Color.FromKnownColor(names[randomGen.Next(names.Length)]);
            }

            /*chatUI.AddMessage(Guid.Empty, "你好,祝你生日快乐!");
             * chatUI.AddMessage(Guid.Empty, "你是?", false);
             * chatUI.AddMessage(Guid.Empty, "我是你的小号啊");
             * chatUI.AddMessage(Guid.Empty, ":-( 伐开熏 ...", false);
             */
            Messaging.Message message = null;
            ThreadPool.QueueUserWorkItem(state => {
                //Get Message From 0MQ
                //Handle
                bool working = true;
                while (working)
                {
                    sendEvent.WaitOne();
                    //Validate Message;
                    if (message != null)
                    {
                        Guid guid = message.From; string Guid = guid.ToString();
                        ChatUI ui = null;
                        if (chatrooms.ContainsKey(Guid))
                        {
                            ui = chatrooms[Guid];
                        }
                        else
                        {
                            ui = new ChatUI(guid); chatrooms.TryAdd(Guid, ui);
                        }
                    }
                }
            });

            ThreadPool.QueueUserWorkItem(state => {
                using (SubscriberSocket subscriber = new SubscriberSocket()) {
                    subscriber.Bind($"tcp://localhost:12555");
                    //Handle Subscriber
                    subscriber.SubscribeToAnyTopic();
                    Msg msg = new Msg(); msg.InitEmpty();
                    while (true)
                    {
                        subscriber.TryReceive(ref msg, TimeSpan.MaxValue);
                        using (MemoryStream ms = new MemoryStream(msg.Data)) {
                            BinaryFormatter bf             = new BinaryFormatter();
                            Messaging.Message groupMessage = bf.Deserialize(ms) as Messaging.Message;
                            if (groupMessage == null)
                            {
                                continue;
                            }
                            if (!groupMessage.MessageType.HasFlag(Messaging.MessageType.MT_GROUP_FLAG))
                            {
                                continue;
                            }
                            Guid from = groupMessage.From;
                        }
                    }
                }
            });

            ThreadPool.QueueUserWorkItem(state => {
                new FakeServer().Init();
            });

            cmdSend.Click += (sender, @event) => {
                if (ActiveChatUI == null)
                {
                    return;
                }

                Guid TO = ActiveChatUI.Target; string to = TO.ToString();
                if (!members.ContainsKey(to))
                {
                    return;
                }
                using (var client = new RequestSocket()) {
                    Messaging.Membership membership = members[to];
                    client.Connect($">tcp://0x{membership.LastLoginIP:X}:12553");
                    string            ____ = "-------------------";
                    byte[]            data = Encoding.UTF8.GetBytes(____);
                    Messaging.Message m    = new Messaging.Message(1, from, TO, Guid.Empty,
                                                                   TimeSpan.FromMinutes(1D), false, new Guid(),
                                                                   Messaging.MessageType.MT_PLAINTEXT, data.Length, data);
                    using (MemoryStream ms = new MemoryStream()) {
                        BinaryFormatter bf = new BinaryFormatter();
                        bf.Serialize(ms, m); data = ms.ToArray();
                        msg.Put(data, 0, data.Length);
                    }
                    client.Send(ref msg, false);
                    //Clear Input
                    sendEvent.Set();
                }
            };

            lvConversations.Click += (sender, @event) => {
                if (lvConversations.SelectedIndices.Count == 0)
                {
                    return;
                }
                int selectedIndex = lvConversations.SelectedIndices[0];

                var shortcut = lvConversations.Items[selectedIndex].Tag as ConversationShortcut;
                if (shortcut == null)
                {
                    return;
                }

                ChatUI chatUI = GetChatUI(shortcut.Icon);

                for (int i = 0; i < splitContainerChat.Panel1.Controls.Count; i++)
                {
                    splitContainerChat.Panel1.Controls[i].Visible = (chatUI == splitContainerChat.Panel1.Controls[i]);
                }
                ActiveChatUI = chatUI;
                lblInfo.Text = shortcut.DisplayName;
            };

            lblInfo.Click += (sender, @event) => {
                Msg m = new Msg();// m.InitEmpty();
                Messaging.Message _message = MessageFactory.CreateMemberInfoMessage(new Guid(), new Guid(), new Guid());
                byte[]            b        = SerializerUtil <Messaging.Message> .Serialize(_message);

                m.InitPool(b.Length); m.Put(b, 0, b.Length);
                using (var client = new RequestSocket()) {
                    client.Connect("tcp://localhost:12553");
                    client.Send(ref m, false);
                    Msg mm = new Msg(); mm.InitEmpty();
                    client.Receive(ref mm);
                    var reply = SerializerUtil <Messaging.Message> .Deserialize(mm.Data);

                    var response = SerializerUtil <MemberInfoResponse> .Deserialize(reply.Content);

                    var membership = response.Membership;
                    MessageBox.Show($"{membership.ID}\n{membership.Name}\n{membership.NickName}\n0x{membership.LastLoginIP :X08}");
                }
            };
        }