Ejemplo n.º 1
0
        /// <summary>
        /// 只能被MainForm调用 否则会不同步
        /// </summary>
        /// <param name="add_stu_num"></param>
        /// <param name="add_stu_name"></param>
        /// <param name="add_stu_comment"></param>
        /// <returns></returns>
        public SKFriend add_friend(string add_stu_num, string add_stu_name = "", string add_stu_comment = "", Bitmap _image = null)
        {
            foreach (SKFriend ff in friend_list)
            {
                if (ff.stu_num == add_stu_num)
                {
                    return(ff);
                }
            }
            SKFriend f = new SKFriend(add_stu_num, add_stu_name, add_stu_comment, _image);

            friend_list.Add(f);
            if (!starting)
            {
                master.refresh();
            }
            return(f);
        }
Ejemplo n.º 2
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.º 3
0
 public void remove_friend(SKFriend f)
 {
     friend_list.Remove(f);
     master.refresh();
 }
Ejemplo n.º 4
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
        }