private void SendGroupMessage(string text) { var msg = new ChattingMessage(); foreach (var id in GroupIDList) { if (id == MyID) { continue; } //check online var temp = "q" + id; var resp = CSCore_instance.Query(temp); if (resp == "n") { //MessageBox.Show("当前好友不在线!"); //this.Close(); continue; } else { friendIP = resp; } msg.CMType = MessageType.Text; msg.Content = text; msg.DstID = id; msg.SrcID = MyID; msg.SendTime = DateTime.Now.ToString(); //P2P发送 MyDataGram mdg = new MyDataGram(); mdg.SrcID = MyID; mdg.Text = text; mdg.DstID = id; mdg.GroupID = friendID; mdg.Type = MessageType.Text; P2PCore_instance.SendData(MyDataGram.EncodeMessage(mdg), friendIP, SendDataPort); } if (msg.Content == "__init__") { return; } //回显 msg.Content = "我: " + msg.Content; msg.hori = HorizontalAlignment.Right; ChattingMessageList.Add(msg); ChattingWindowListBox.ScrollIntoView(msg); //遍历所有的group_id 给所有其他人发一个奇怪的message }
private void SendAck(byte[] data) { //发送ACK报文 MyDataGram pro = MyDataGram.DecodeMessage(data); MyDataGram ack = new MyDataGram(); ack.DstID = pro.SrcID; ack.SrcID = pro.DstID; ack.Text = "__ack__" + pro.Text; ack.Type = MessageType.Text; string tempIP = ""; var resp = CSCore_instance.Query("q" + pro.SrcID); if (resp == "n") { MessageBox.Show("当前好友不在线!"); return; } else { tempIP = resp; } SendUDPData(MyDataGram.EncodeMessage(ack), tempIP, ttPort);//danger! }
private void LoginBtn_Click(object sender, RoutedEventArgs e) { var account = Account.Text; var password = Password.Password; G_Account = account; var merge = account + "_" + password; var receive = CSCore_instance.Query(merge); if (receive == "lol") { //跳转逻辑 StartChat(); } else { MessageBox.Show("登陆不成功,请检查网络."); } }
private void Enter_Click(object sender, RoutedEventArgs e) { var temp = FriendAccount.Text; var merged = "q" + temp; var receive = CSCore_instance.Query(merged); if (receive == "n" || receive.Contains("1")) { newaccount = FriendAccount.Text; if (receive.Contains("1")) { newIP = receive; } } else { MessageBox.Show("输入有误或账号不存在."); newaccount = ""; FriendAccount.Text = ""; return; } newname = FriendName.Text; if (newname.Contains("_") || newname == "") { MessageBox.Show("昵称不合法,请不要包含'_'字符或者为空"); newname = ""; FriendName.Text = ""; return; } else { if (FriendAccount.Text == myaccount) { MessageBox.Show("请不要添加你自己!"); return; } newname = FriendName.Text; } //MessageBox.Show(receive); HaveFindFriend = 1; Close(); CloseEvent(); }
private void StartChatWindow() { MilessFriend friend = new MilessFriend(); friend = listFriends.SelectedItem as MilessFriend; if (friend == null) { MessageBox.Show("请先选择聊天的朋友!"); return; } if (friend.FriendID[0] == ' ') { foreach (var friID in ChattingIDList) { if (GroupIDMatch(friend.FriendID, friID)) { MessageBox.Show("已有聊天窗口!"); return; } } } else { string friendIP = ""; var resp = CSCore_instance.Query("q" + friend.FriendID); if (resp == "n") { MessageBox.Show("好友不在线!"); return; } else if (friend.FriendID == account) { MessageBox.Show("别自言自语,和别人聊天吧!"); return; } else { // Danger friendIP = resp; } friend.FriendIP = friendIP; foreach (var friID in ChattingIDList) { if (friend.FriendID == friID) { MessageBox.Show("已有聊天窗口!"); return; } } } ChattingIDList.Add(friend.FriendID); ChatWindow cw = new ChatWindow(); cw.SetMyID(account); cw.SetFriendInfo(friend.FriendID + "_" + friend.FriendAlias); ChatWindowList.Add(cw); cw.Show(); cw.CloseEvent += new cwEventHandler(cwClose); void cwClose() { foreach (var cww in ChatWindowList) { if (cww.GetWindowInfo() == cw.GetWindowInfo()) { ChatWindowList.Remove(cww); break; } } foreach (var id in ChattingIDList) { if (cw.GetWindowInfo() == id) { ChattingIDList.Remove(id); break; } } } }