Ejemplo n.º 1
0
        public SKMsgWindow new_window(SKFriend listboxitem)
        {
            if (listboxitem == null)
            {
                return(null);
            }
            for (int i = 0; i < window_list.Count; i++)
            {
                SKMsgWindow msg_window = window_list[i];
                if (msg_window == null || msg_window.Visible == false)
                {
                    window_list.Remove(msg_window);
                    i--;
                }
                else if (msg_window.friend.stu_num == listboxitem.stu_num)
                {
                    return(msg_window);
                }
            }
            SKMsgWindow neww = new SKMsgWindow(listboxitem, this);

            window_list.Add(neww);
            return(neww);
        }
Ejemplo n.º 2
0
        public void receive_mes(object sender, SKMsgInfoBase _msg_info, byte[] file_piece = null)
        {
            Action <SKMsgInfoBase> receive_act = (msg_info) =>
            {
                #region TEXT
                if (msg_info.type == SKMsgInfoBase.mestype.TEXT)
                {
                    string   this_stu_num = "";
                    SKFriend ff           = null;
                    foreach (SKFriend f in friend_list)
                    {
                        if (f != null && f.ip != null && f.stu_num == msg_info.stu_num)
                        {
                            this_stu_num = f.stu_num;
                            f.name       = (msg_info as SKMsgInfoText).text_pack.name;
                            ff           = f;
                            break;
                        }
                    }
                    if (this_stu_num == "")
                    {
                        SKFriend    newf = master.add_friend(msg_info.stu_num, ((SKMsgInfoText)msg_info).text_pack.name, "", null);
                        SKMsgWindow neww = new_window(newf);
                        neww.rev_text((SKMsgInfoText)msg_info);
                    }
                    else
                    {
                        for (int i = 0; i < window_list.Count; i++)
                        {
                            SKMsgWindow msg_window = window_list[i];
                            if (msg_window == null || msg_window.Visible == false)
                            {
                                window_list.Remove(msg_window);
                                i--;
                            }
                            else if (msg_window.friend.stu_num == this_stu_num)
                            {
                                //找到了已经打开的窗口
                                msg_window.rev_text((SKMsgInfoText)msg_info);
                                return;
                            }
                        }
                        //未找到已打开的窗口
                        SKMsgWindow neww = new_window(ff);
                        neww.rev_text((SKMsgInfoText)msg_info);
                    }
                }
                #endregion
                #region RESPONSE
                else if (msg_info.type == SKMsgInfoBase.mestype.RESPONSE)
                {
                    string   this_stu_num = "";
                    SKFriend ff           = null;
                    foreach (SKFriend f in friend_list)
                    {
                        if (f != null && f.ip != null && f.stu_num == msg_info.stu_num)
                        {
                            this_stu_num = f.stu_num;
                            ff           = f;
                            break;
                        }
                    }
                    if (this_stu_num == "")
                    {
                        SKFriend    newf = master.add_friend(msg_info.stu_num, "", "", null);
                        SKMsgWindow neww = new_window(newf);
                        neww.rev_response(msg_info);
                    }
                    else
                    {
                        for (int i = 0; i < window_list.Count; i++)
                        {
                            SKMsgWindow msg_window = window_list[i];
                            if (msg_window == null || msg_window.Visible == false)
                            {
                                window_list.Remove(msg_window);
                                i--;
                            }
                            else if (msg_window.friend.stu_num == this_stu_num)
                            {
                                //找到了已经打开的窗口
                                msg_window.rev_response(msg_info);
                                return;
                            }
                        }
                        //未找到已打开的窗口
                        SKMsgWindow neww = new_window(ff);
                        neww.rev_response(msg_info);
                    }
                }
                #endregion
                #region FILE
                else if (msg_info.type == SKMsgInfoBase.mestype.FILE)
                {
                    string   this_stu_num = "";
                    SKFriend ff           = null;
                    foreach (SKFriend f in friend_list)
                    {
                        if (f != null && f.ip != null && f.stu_num == msg_info.stu_num)
                        {
                            this_stu_num = f.stu_num;
                            ff           = f;
                            break;
                        }
                    }
                    if (this_stu_num == "")
                    {
                    }
                    else
                    {
                        for (int i = 0; i < window_list.Count; i++)
                        {
                            SKMsgWindow msg_window = window_list[i];
                            if (msg_window == null || msg_window.Visible == false)
                            {
                                window_list.Remove(msg_window);
                                i--;
                            }
                            else if (msg_window.friend.stu_num == this_stu_num)
                            {
                                //找到了已经打开的窗口
                                msg_window.rev_file_piece((SKMsgInfoFile)msg_info, file_piece);
                                return;
                            }
                        }
                    }
                }
                #endregion
                #region FILE_INVITE
                else if (msg_info.type == SKMsgInfoBase.mestype.FILE_INVITE)
                {
                    string   this_stu_num = "";
                    SKFriend ff           = null;
                    foreach (SKFriend f in friend_list)
                    {
                        if (f != null && f.ip != null && f.stu_num == msg_info.stu_num)
                        {
                            this_stu_num = f.stu_num;
                            ff           = f;
                            break;
                        }
                    }
                    if (this_stu_num == "")
                    {
                        SKFriend    newf = master.add_friend(msg_info.stu_num, "", "", null);
                        SKMsgWindow neww = new_window(newf);
                        neww.rev_file_invite((SKMsgInfoFileInvite)msg_info);
                    }
                    else
                    {
                        for (int i = 0; i < window_list.Count; i++)
                        {
                            SKMsgWindow msg_window = window_list[i];
                            if (msg_window == null || msg_window.Visible == false)
                            {
                                window_list.Remove(msg_window);
                                i--;
                            }
                            else if (msg_window.friend.stu_num == this_stu_num)
                            {
                                //找到了已经打开的窗口
                                msg_window.rev_file_invite((SKMsgInfoFileInvite)msg_info);
                                return;
                            }
                        }
                        //未找到已打开的窗口
                        SKMsgWindow neww = new_window(ff);
                        neww.rev_file_invite((SKMsgInfoFileInvite)msg_info);
                    }
                }
                #endregion
                #region GROUP_TEXT
                else if (msg_info.type == SKMsgInfoBase.mestype.GROUP_TEXT)
                {
                    List <SKFriend> friend_list_new = new List <SKFriend>();//用于生成当前群聊的好友列表
                    //把群聊所有人加为好友,构造friendlist
                    foreach (string one_more in ((SKMsgInfoGroupText)msg_info).stu_num_list)
                    {
                        SKFriend is_new_friend = null;
                        foreach (SKFriend f in friend_list)
                        {
                            if (f != null && f.ip != null && f.stu_num == one_more)
                            {
                                is_new_friend = f;
                                friend_list_new.Add(f);
                                break;
                            }
                        }
                        if (is_new_friend == null && one_more != my_stu_num)
                        {
                            SKFriend newf = master.add_friend(one_more, "", "", null);
                            friend_list_new.Add(newf);
                        }
                    }
                    //更新发送方的姓名
                    foreach (SKFriend f in friend_list)
                    {
                        if (f != null && f.ip != null && f.stu_num == (msg_info as SKMsgInfoGroupText).stu_num)
                        {
                            f.name = (msg_info as SKMsgInfoGroupText).text_pack.name;
                        }
                    }
                    //查看群聊窗口是否存在
                    SKGroupMsgWindow sgmw = null;
                    foreach (SKGroupMsgWindow n in g_window_list)
                    {
                        if (n.Visible && compare_friends(friend_list_new, n.friends))
                        {
                            sgmw = n;
                            break;
                        }
                    }
                    if (sgmw == null)
                    {
                        sgmw = new_g_window(friend_list_new);
                    }
                    sgmw.add_text(msg_info as SKMsgInfoGroupText);
                }
                #endregion
                #region SYNC
                else if (msg_info.type == SKMsgInfoBase.mestype.SYNC)
                {
                    SKMsgInfoSync msg_sync     = (SKMsgInfoSync)msg_info;
                    string        this_stu_num = "";
                    SKFriend      ff           = null;
                    foreach (SKFriend f in friend_list)
                    {
                        if (f != null && f.ip != null && f.stu_num == msg_sync.stu_num)
                        {
                            this_stu_num = f.stu_num;
                            ff           = f;
                            break;
                        }
                    }
                    if (this_stu_num == "")
                    {
                        SKFriend newf = master.add_friend(msg_sync.stu_num, msg_sync.name, msg_sync.comment, msg_sync.head_60_60);
                    }
                    else
                    {
                        ff.name    = msg_sync.name;
                        ff.comment = msg_sync.comment;
                        ff.Img     = msg_sync.head_60_60;
                    }
                }
                #endregion
                master.refresh();
            };

            master.BeginInvoke(receive_act, _msg_info);
            #region no_invoke
            //if (msg_info.type == SKMsgInfoBase.mestype.TEXT)
            //{
            //    string this_stu_num = "";
            //    SKFriend ff = null;
            //    foreach (SKFriend f in friend_list)
            //    {
            //        if (f != null && f.ip != null && f.ip.ToString() == msg_info.ip.ToString())
            //        {
            //            this_stu_num = f.stu_num;
            //            f.name = (msg_info as SKMsgInfoText).text_pack.name;
            //            ff = f;
            //            break;
            //        }
            //    }
            //    if (this_stu_num == "")
            //    {
            //        SKFriend newf = master.add_friend(msg_info.stu_num,"","",null);
            //        SKMsgWindow neww = new_window(newf);
            //        neww.add_rev_text((SKMsgInfoText)msg_info);
            //    }
            //    else
            //    {
            //        for (int i = 0; i < window_list.Count; i++)
            //        {
            //            SKMsgWindow msg_window = window_list[i];
            //            if (msg_window == null || msg_window.Visible == false)
            //            {
            //                window_list.Remove(msg_window);
            //                i--;
            //            }
            //            else if (msg_window.friend.stu_num == this_stu_num)
            //            {
            //                //找到了已经打开的窗口
            //                msg_window.add_rev_text((SKMsgInfoText)msg_info);
            //                return;
            //            }
            //        }
            //        //未找到已打开的窗口
            //        SKMsgWindow neww = new_window(ff);
            //        neww.add_rev_text((SKMsgInfoText)msg_info);
            //    }
            //}
            #endregion
        }
Ejemplo n.º 3
0
 public void refresh()
 {
     //login_socket.Send(Encoding.Default.GetBytes(my_stu_num + "_net2015"));
     //try
     //{
     //    int tmp = login_socket.ReceiveTimeout;
     //    login_socket.ReceiveTimeout = 100;
     //    byte[] tmp2 = new byte[3];
     //    login_socket.Receive(tmp2);
     //    login_socket.ReceiveTimeout = tmp;
     //}
     //catch (Exception)
     //{
     //}
     for (int i = 0; i < window_list.Count; i++)
     {
         SKMsgWindow msg_window = window_list[i];
         if (msg_window == null || msg_window.Visible == false)
         {
             window_list.Remove(msg_window);
             i--;
         }
         else
         {
             msg_window.refresh_lable();
         }
     }
     foreach (SKFriend f in friend_list)
     {
         try
         {
             login_socket.Send(Encoding.Default.GetBytes("q" + f.stu_num));
             byte[] receive_buffer = new byte[100];
             int    len            = login_socket.Receive(receive_buffer);
             int    i = 0;
             for (i = 0; i < len; i++)
             {
                 if (receive_buffer[i] > ((byte)'0' - 1) && receive_buffer[i] < ((byte)'9' + 1))
                 {
                     break;
                 }
             }
             int j = i;
             for (j = i; j < len; j++)
             {
                 if ((receive_buffer[j] != (byte)'.') && (receive_buffer[i] <= ((byte)'0' - 1) || receive_buffer[i] >= ((byte)'9' + 1)))
                 {
                     break;
                 }
             }
             IPAddress ip = IPAddress.Parse(Encoding.Default.GetString(receive_buffer, i, j - i));
             f.ip     = ip;
             f.online = true;
             if (f.stu_num == my_stu_num)
             {
                 f.name    = master.get_name();
                 f.comment = master.get_comment();
             }
         }
         catch
         {
             f.ip     = null;
             f.online = false;
         }
     }
 }