Пример #1
0
        void rapidPassiveEngine_MessageReceived(string sourceUserID, int informationType, byte[] info, string tag)
        {
            if (!this.initialized)
            {
                return;
            }

            if (informationType == InformationTypes.Chat)
            {
                sourceUserID = tag;
                byte[] bChatBoxContent = info;
                if (bChatBoxContent != null)
                {
                    ChatMessageRecord record = new ChatMessageRecord(sourceUserID, this.rapidPassiveEngine.CurrentUserID, bChatBoxContent, false);
                    GlobalResourceManager.ChatMessageRecordPersister.InsertChatMessageRecord(record);
                }

                byte[] decrypted = info;
                if (GlobalResourceManager.Des3Encryption != null)
                {
                    decrypted = GlobalResourceManager.Des3Encryption.Decrypt(info);
                }

                ChatBoxContent content = CompactPropertySerializer.Default.Deserialize <ChatBoxContent>(decrypted, 0);
                GGUser         user    = this.globalUserCache.GetUser(sourceUserID);
                this.notifyIcon.PushFriendMessage(sourceUserID, informationType, info, content);
                return;
            }
        }
Пример #2
0
        void ContactsOutter_BroadcastReceived(string broadcasterID, string groupID, int broadcastType, byte[] content, string tag)
        {
            if (!this.initialized)
            {
                return;
            }

            if (this.InvokeRequired)
            {
                this.BeginInvoke(new CbGeneric <string, string, int, byte[], string>(this.ContactsOutter_BroadcastReceived), broadcasterID, groupID, broadcastType, content, tag);
            }
            else
            {
                try
                {
                    if (broadcastType == BroadcastTypes.BroadcastChat)
                    {
                        GGGroup group = this.globalUserCache.GetGroup(groupID);

                        byte[] decrypted = content;
                        if (GlobalResourceManager.Des3Encryption != null)
                        {
                            decrypted = GlobalResourceManager.Des3Encryption.Decrypt(content);
                        }

                        this.notifyIcon.PushGroupMessage(broadcasterID, groupID, broadcastType, decrypted);
                        ChatMessageRecord record = new ChatMessageRecord(broadcasterID, groupID, decrypted, true);
                        GlobalResourceManager.ChatMessageRecordPersister.InsertChatMessageRecord(record);
                        return;
                    }

                    if (broadcastType == BroadcastTypes.SomeoneJoinGroup)
                    {
                        string userID = System.Text.Encoding.UTF8.GetString(content);
                        this.globalUserCache.OnSomeoneJoinGroup(groupID, userID);
                        return;
                    }

                    if (broadcastType == BroadcastTypes.SomeoneQuitGroup)
                    {
                        string userID = System.Text.Encoding.UTF8.GetString(content);
                        this.globalUserCache.OnSomeoneQuitGroup(groupID, userID);
                        return;
                    }

                    if (broadcastType == BroadcastTypes.GroupDeleted)
                    {
                        string userID = System.Text.Encoding.UTF8.GetString(content);
                        this.globalUserCache.OnGroupDeleted(groupID, userID);
                        return;
                    }
                }
                catch (Exception ee)
                {
                    GlobalResourceManager.Logger.Log(ee, "MainForm.GroupOutter_BroadcastReceived", ESBasic.Loggers.ErrorLevel.Standard);
                    MessageBox.Show(ee.Message);
                }
            }
        }
Пример #3
0
        //发送
        private void btnSend_Click(object sender, EventArgs e)
        {
            if (this.globalUserCache.GetGroup(currentGroup.ID).NoSpeakList != null)
            {
                if (this.globalUserCache.GetGroup(currentGroup.ID).NoSpeakList.Contains(this.mine.UserID))

                {
                    this.AppendSysMessage("您已经被禁言!");
                    return;
                }
            }



            ChatBoxContent content = this.chatBoxSend.GetContent();

            if (content.IsEmpty())
            {
                return;
            }

            try
            {
                byte[] buff      = CompactPropertySerializer.Default.Serialize(content);
                byte[] encrypted = buff;
                if (GlobalResourceManager.Des3Encryption != null)
                {
                    encrypted = GlobalResourceManager.Des3Encryption.Encrypt(buff);
                }

                ++this.sendingCount;
                this.gifBox_wait.Visible = true;
                UIResultHandler handler = new UIResultHandler(this, this.HandleSentResult);
                this.rapidPassiveEngine.ContactsOutter.BroadcastBlob(this.currentGroup.GroupID, BroadcastTypes.BroadcastChat, encrypted, null, 2048, handler.Create(), null);

                this.AppendChatBoxContent(string.Format("{0}({1})", this.mine.Name, this.mine.UserID), null, content, Color.Green);
                ChatMessageRecord record = new ChatMessageRecord(this.mine.UserID, this.currentGroup.GroupID, buff, true, false);
                GlobalResourceManager.ChatMessageRecordPersister.InsertChatMessageRecord(record);



                //清空输入框
                this.chatBoxSend.Text = string.Empty;
                this.chatBoxSend.Focus();

                if (this.LastWordChanged != null)
                {
                    LastWordsRecord lastWordsRecord = new LastWordsRecord(this.mine.ID, this.mine.Name, true, content);
                    this.LastWordChanged(true, this.currentGroup.GroupID, lastWordsRecord);
                }
            }
            catch
            {
                this.AppendSysMessage("发送消息失败!");
            }
        }
        public async Task <string> Create(string message, int orderid, int memberid, byte grouptype)
        {
            var memberphoto = _context.Members.Where(n => n.MemberId == memberid).Select(n => n.ProfileImagePath).FirstOrDefault();
            ChatMessageRecord chatMessageRecord = new ChatMessageRecord
            {
                GroupType    = grouptype,
                GroupId      = orderid,
                SentTime     = DateTime.Now,
                SentMemberId = memberid,
                Message      = message
            };

            _context.Add(chatMessageRecord);
            await _context.SaveChangesAsync();

            return(JsonConvert.SerializeObject(new Tuple <DateTime, string>(chatMessageRecord.SentTime, memberphoto)));
        }
Пример #5
0
        private ObjectManager <string, List <ChatMessageRecord> > groupChatRecordTable = new ObjectManager <string, List <ChatMessageRecord> >();                                              //groupID - guestID - msgRtf。


        #region InsertChatMessageRecord
        public void InsertChatMessageRecord(ChatMessageRecord chatMessage)
        {
            if (!chatMessage.IsGroupChat)
            {
                //owner 为Sender
                if (!this.chatRecordTable.Contains(chatMessage.SpeakerID))
                {
                    this.chatRecordTable.Add(chatMessage.SpeakerID, new ObjectManager <string, List <ChatMessageRecord> >());
                }
                var guests = this.chatRecordTable.Get(chatMessage.SpeakerID);
                if (!guests.Contains(chatMessage.AudienceID))
                {
                    guests.Add(chatMessage.AudienceID, new List <ChatMessageRecord>());
                }
                var records = guests.Get(chatMessage.AudienceID);
                records.Add(chatMessage);

                //owner 为chatMessage.AudienceID
                if (!this.chatRecordTable.Contains(chatMessage.AudienceID))
                {
                    this.chatRecordTable.Add(chatMessage.AudienceID, new ObjectManager <string, List <ChatMessageRecord> >());
                }
                var guests2 = this.chatRecordTable.Get(chatMessage.AudienceID);
                if (!guests2.Contains(chatMessage.SpeakerID))
                {
                    guests2.Add(chatMessage.SpeakerID, new List <ChatMessageRecord>());
                }
                var records2 = guests2.Get(chatMessage.SpeakerID);
                records2.Add(chatMessage);
            }
            else
            {
                if (!this.groupChatRecordTable.Contains(chatMessage.AudienceID))
                {
                    this.groupChatRecordTable.Add(chatMessage.AudienceID, new List <ChatMessageRecord>());
                }
                var records = this.groupChatRecordTable.Get(chatMessage.AudienceID);
                records.Add(chatMessage);
            }
        }
Пример #6
0
        private void ShowRecord(int pageIndex, bool allowCache)
        {
            if (this.remotePersister == null) //还未完成构造
            {
                return;
            }

            if (pageIndex != int.MaxValue)
            {
                if (pageIndex + 1 > this.totalPageCount)
                {
                    pageIndex = this.totalPageCount - 1;
                }

                if (pageIndex < 0)
                {
                    pageIndex = 0;
                }
                if (this.currentPageIndex == pageIndex && allowCache)
                {
                    this.toolStripTextBox_pageIndex.Text = (pageIndex + 1).ToString();
                    return;
                }
            }

            this.Cursor = Cursors.WaitCursor;
            try
            {
                ChatRecordTimeScope timeScope = ChatRecordTimeScope.All;
                DateTime            now       = DateTime.Now;
                if (this.skinComboBox1.SelectedIndex == 0) //一周
                {
                    timeScope = ChatRecordTimeScope.RecentWeek;
                }
                else if (this.skinComboBox1.SelectedIndex == 1)//一月
                {
                    timeScope = ChatRecordTimeScope.RecentMonth;
                }
                else if (this.skinComboBox1.SelectedIndex == 2)//三月
                {
                    timeScope = ChatRecordTimeScope.Recent3Month;
                }
                else //全部
                {
                }


                ChatRecordPage page = null;
                if (this.isGroupChat)
                {
                    page = this.CurrentPersister.GetGroupNoticeRecordPage(timeScope, this.group.Arg1, this.pageSize, pageIndex);
                }
                else
                {
                    page = this.CurrentPersister.GetChatRecordPage(timeScope, my.Arg1, friend.Arg1, this.pageSize, pageIndex);
                }
                this.chatBox_history.Clear();

                if (page == null || page.Content.Count == 0)
                {
                    MessageBoxEx.Show("没有消息记录!");
                    return;
                }

                this.currentPageIndex = page.PageIndex;
                this.toolStripTextBox_pageIndex.Text = (this.currentPageIndex + 1).ToString();
                for (int i = 0; i < page.Content.Count; i++)
                {
                    ChatMessageRecord record    = page.Content[i];
                    byte[]            decrypted = record.Content;
                    if (this.skinRadioButton_Server.Checked)
                    {
                        if (GlobalResourceManager.Des3Encryption != null)
                        {
                            decrypted = GlobalResourceManager.Des3Encryption.Decrypt(decrypted);
                        }
                    }

                    // ChatBoxContent content = CompactPropertySerializer.Default.Deserialize<ChatBoxContent>(decrypted, 0);

                    ChatBoxContent content = null;
                    if (content == null)
                    {
                        content      = new ChatBoxContent();
                        content.Text = System.Text.Encoding.UTF8.GetString(decrypted);
                    }

                    if (this.isGroupChat)
                    {
                        if (record.SpeakerID == this.my.Arg1)
                        {
                            this.AppendChatBoxContent(record.OccureTime, string.Format("{0}({1})", this.my.Arg2, record.SpeakerID), content, Color.Green);
                        }
                        else
                        {
                            string name = this.userNameGetter.GetUserName(record.SpeakerID) ?? record.SpeakerID;
                            this.AppendChatBoxContent(record.OccureTime, string.Format("{0}({1})", name, record.SpeakerID), content, Color.Blue);
                        }
                    }
                    else
                    {
                        if (record.SpeakerID == this.my.Arg1)
                        {
                            this.AppendChatBoxContent(record.OccureTime, this.my.Arg2, content, Color.Green);
                        }
                        else
                        {
                            this.AppendChatBoxContent(record.OccureTime, this.friend.Arg2, content, Color.Blue);
                        }
                    }
                }

                this.chatBox_history.SelectionStart = 0;
                this.chatBox_history.ScrollToCaret();

                int pageCount = page.TotalCount / this.pageSize;
                if (page.TotalCount % this.pageSize > 0)
                {
                    ++pageCount;
                }
                this.totalPageCount = pageCount;
                this.toolStripLabel_totalCount.Text = string.Format("/ {0}页", this.totalPageCount);
                this.toolStripTextBox_pageIndex.Focus();
            }
            catch (Exception ee)
            {
                MessageBoxEx.Show(ee.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Пример #7
0
        public void HandleInformation(string sourceUserID, int informationType, byte[] info)
        {
            if (!this.initialized)
            {
                return;
            }

            #region 需要twinkle的消息
            if (informationType == InformationTypes.Chat || informationType == InformationTypes.OfflineMessage || informationType == InformationTypes.OfflineFileResultNotify ||
                informationType == InformationTypes.Vibration || informationType == InformationTypes.VideoRequest || informationType == InformationTypes.AgreeVideo ||
                informationType == InformationTypes.RejectVideo || informationType == InformationTypes.HungUpVideo || informationType == InformationTypes.DiskRequest ||
                informationType == InformationTypes.AgreeDisk || informationType == InformationTypes.RejectDisk || informationType == InformationTypes.RemoteHelpRequest ||
                informationType == InformationTypes.AgreeRemoteHelp || informationType == InformationTypes.RejectRemoteHelp || informationType == InformationTypes.CloseRemoteHelp ||
                informationType == InformationTypes.TerminateRemoteHelp ||
                informationType == InformationTypes.AudioRequest || informationType == InformationTypes.RejectAudio || informationType == InformationTypes.AgreeAudio ||
                informationType == InformationTypes.HungupAudio ||
                informationType == InformationTypes.FriendAddedNotify)
            {
                if (informationType == InformationTypes.FriendAddedNotify)
                {
                    GGUser owner = CompactPropertySerializer.Default.Deserialize <GGUser>(info, 0); // 0922
                    this.globalUserCache.CurrentUser.AddFriend(owner.ID, this.globalUserCache.CurrentUser.DefaultFriendCatalog);
                    this.globalUserCache.OnFriendAdded(owner);                                      //自然会添加 好友条目
                    sourceUserID = owner.UserID;
                }

                object tag = null;
                if (informationType == InformationTypes.OfflineMessage)
                {
                    byte[]         bChatBoxContent = null;
                    OfflineMessage msg             = CompactPropertySerializer.Default.Deserialize <OfflineMessage>(info, 0);
                    if (msg.InformationType == InformationTypes.Chat) //目前只处理离线的聊天消息
                    {
                        sourceUserID    = msg.SourceUserID;
                        bChatBoxContent = msg.Information;
                        byte[] decrypted = bChatBoxContent;
                        if (GlobalResourceManager.Des3Encryption != null)
                        {
                            decrypted = GlobalResourceManager.Des3Encryption.Decrypt(bChatBoxContent);
                        }

                        ChatMessageRecord record = new ChatMessageRecord(sourceUserID, this.rapidPassiveEngine.CurrentUserID, decrypted, false);
                        GlobalResourceManager.ChatMessageRecordPersister.InsertChatMessageRecord(record);
                        ChatBoxContent content = CompactPropertySerializer.Default.Deserialize <ChatBoxContent>(decrypted, 0);
                        tag = new Parameter <ChatBoxContent, DateTime>(content, msg.Time);
                    }
                }

                if (informationType == InformationTypes.OfflineFileResultNotify)
                {
                    OfflineFileResultNotifyContract contract = CompactPropertySerializer.Default.Deserialize <OfflineFileResultNotifyContract>(info, 0);
                    sourceUserID = contract.AccepterID;
                }

                GGUser user = this.globalUserCache.GetUser(sourceUserID);
                this.notifyIcon.PushFriendMessage(sourceUserID, informationType, info, tag);
                return;
            }
            #endregion

            if (this.InvokeRequired)
            {
                this.BeginInvoke(new CbGeneric <string, int, byte[]>(this.HandleInformation), sourceUserID, informationType, info);
            }
            else
            {
                try
                {
                    if (informationType == InformationTypes.InputingNotify)
                    {
                        ChatForm form = this.chatFormManager.GetForm(sourceUserID);
                        if (form != null)
                        {
                            form.OnInptingNotify();
                        }
                        return;
                    }

                    if (informationType == InformationTypes.FriendRemovedNotify)
                    {
                        string friendID = System.Text.Encoding.UTF8.GetString(info);
                        this.globalUserCache.RemovedFriend(friendID);
                        return;
                    }

                    if (informationType == InformationTypes.UserInforChanged)
                    {
                        GGUser user = ESPlus.Serialization.CompactPropertySerializer.Default.Deserialize <GGUser>(info, 0);
                        this.globalUserCache.AddOrUpdateUser(user);
                        return;
                    }

                    if (informationType == InformationTypes.UserStatusChanged)
                    {
                        UserStatusChangedContract contract = ESPlus.Serialization.CompactPropertySerializer.Default.Deserialize <UserStatusChangedContract>(info, 0);
                        this.globalUserCache.ChangeUserStatus(contract.UserID, (UserStatus)contract.NewStatus);
                    }

                    if (informationType == InformationTypes.SystemNotify4AllOnline)
                    {
                        SystemNotifyContract contract = CompactPropertySerializer.Default.Deserialize <SystemNotifyContract>(info, 0);
                        SystemNotifyForm     form     = new SystemNotifyForm(contract.Title, contract.Content);
                        form.Show();
                        return;
                    }

                    if (informationType == InformationTypes.SystemNotify4Group)
                    {
                        SystemNotifyContract contract = CompactPropertySerializer.Default.Deserialize <SystemNotifyContract>(info, 0);
                        SystemNotifyForm     form     = new SystemNotifyForm(contract.Title, contract.Content);
                        form.Show();
                        return;
                    }
                }
                catch (Exception ee)
                {
                    GlobalResourceManager.Logger.Log(ee, "MainForm.HandleInformation", ESBasic.Loggers.ErrorLevel.Standard);
                    MessageBox.Show(ee.Message);
                }
            }
        }
Пример #8
0
 public void InsertChatMessageRecord(ChatMessageRecord record)
 {
     //目前没有通过remoting插入数据库
 }