Example #1
0
        public SKGroupMsgWindow new_g_window(List <SKFriend> _friends)
        {
            bool find_me = false;

            if (_friends == null || _friends.Count == 0)
            {
                return(null);
            }
            for (int i = 0; i < g_window_list.Count; i++)
            {
                if (g_window_list[i] == null || g_window_list[i].Visible == false)
                {
                    g_window_list.Remove(g_window_list[i]);
                    i--;
                }
                else if (compare_friends(_friends, g_window_list[i].friends))
                {
                    return(g_window_list[i]);
                }
            }
            foreach (SKFriend f in _friends)
            {
                if (f.stu_num == my_stu_num)
                {
                    find_me = true;
                }
            }
            if (!find_me)
            {
                _friends.Add(me);
            }
            SKGroupMsgWindow newg = new SKGroupMsgWindow(_friends, this);

            g_window_list.Add(newg);
            return(newg);
        }
Example #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
        }