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; } }
public LastWordsRecord(string _speakerID, string _speakerName, bool me, ChatBoxContent content) { this.speakerID = _speakerID; this.speakerName = _speakerName; this.isMe = me; this.chatBoxContent = content; }
//发送 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("发送消息失败!"); } }
private void AppendChatBoxContent(DateTime showTime, string userName, ChatBoxContent content, Color color) { this.chatBox_history.AppendRichText(string.Format("{0} {1}\n", userName, showTime), new Font(this.Font, FontStyle.Regular), color); this.chatBox_history.AppendText(" "); this.chatBox_history.AppendChatBoxContent(content); this.chatBox_history.AppendText("\n"); this.chatBox_history.Select(this.chatBox_history.Text.Length, 0); this.chatBox_history.ScrollToCaret(); }
private void AppendChatBoxContent(string userName, DateTime?speakTime, ChatBoxContent content, Color color) { string showTime = speakTime == null?DateTime.Now.ToLongTimeString() : speakTime.ToString(); this.chatBox_history.AppendRichText(string.Format("{0} {1}\n", userName, showTime), new Font(this.Font, FontStyle.Regular), color); this.chatBox_history.AppendText(" "); this.chatBox_history.AppendChatBoxContent(content); this.chatBox_history.AppendText("\n"); this.chatBox_history.Select(this.chatBox_history.Text.Length, 0); this.chatBox_history.ScrollToCaret(); }
private void DoHandleReceivedMessage(string broadcasterID, int broadcastType, byte[] content, bool flash) { if (broadcastType == BroadcastTypes.BroadcastChat) { ChatBoxContent chatBoxContent = CompactPropertySerializer.Default.Deserialize <ChatBoxContent>(content, 0); GGUser user = this.globalUserCache.GetUser(broadcasterID); string talker = string.Format("{0}({1})", broadcasterID, broadcasterID); if (user != null) { talker = string.Format("{0}({1})", user.Name, user.UserID); } this.AppendChatBoxContent(talker, null, chatBoxContent, Color.Blue); this.FlashChatWindow(flash); if (this.LastWordChanged != null) { LastWordsRecord lastWordsRecord = new LastWordsRecord(broadcasterID, user == null ? broadcasterID : user.Name, false, chatBoxContent); this.LastWordChanged(true, this.currentGroup.GroupID, lastWordsRecord); } return; } else { string c = System.Text.Encoding.UTF8.GetString(content); //ChatBoxContent chatBoxContent = CompactPropertySerializer.Default.Deserialize<ChatBoxContent>(content, 0); ChatBoxContent chatBoxContent = new ChatBoxContent(); chatBoxContent.Text = c; GGUser user = this.globalUserCache.GetUser(broadcasterID); string talker = string.Format("{0}({1})", broadcasterID, broadcasterID); if (user != null) { talker = string.Format("{0}({1})", user.Name, user.UserID); } this.AppendChatBoxContent(talker, null, chatBoxContent, Color.Blue); this.FlashChatWindow(flash); if (this.LastWordChanged != null) { LastWordsRecord lastWordsRecord = new LastWordsRecord(broadcasterID, user == null ? broadcasterID : user.Name, false, chatBoxContent); this.LastWordChanged(true, this.currentGroup.GroupID, lastWordsRecord); } return; } }
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; } }
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); } } }