Ejemplo n.º 1
0
 private void lv_group_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     if (this.lv_group.SelectedItems.Count > 0)
     {
         ListViewItem lvitem    = this.lv_group.SelectedItems[0];
         string       GID       = lvitem.Text;
         string       Groupname = lvitem.SubItems[1].Text;
         string       auth      = lvitem.Tag.ToString();
         mutualTalk   mt        = isHavemutualTalk(GID);
         if (mt != null)
         {
             mt.Focus();
         }
         else
         {
             this.lv_group.SelectedItems[0].SubItems[0].BackColor = Color.Transparent;
             mutualTalk mtalk = new mutualTalk();
             mtalk.UID       = UID;
             mtalk.GID       = GID;
             mtalk.GroupName = Groupname;
             mtalk.UserName  = Username;
             mtalk.auth      = auth;
             mtalk.Br        = Br;
             mtalk.Bw        = Bw;
             mutualTalkList.Add(mtalk);
             mtalk.Show();
         }
     }
 }
Ejemplo n.º 2
0
 public static void RemovemutualTalking(mutualTalk _mtalk)
 {
     foreach (mutualTalk mtk in mutualTalkList)
     {
         if (mtk.GID == _mtalk.GID)
         {
             mutualTalkList.Remove(_mtalk);
             return;
         }
     }
 }
Ejemplo n.º 3
0
        //监听服务器端发来的消息
        private void TcpListen()
        {
            while (iswork)
            {
                string receiveMsg = null;
                try
                {
                    receiveMsg = Br.ReadString();
                }
                catch (Exception)
                {
                }
                if (receiveMsg != null)
                {
                    string   command      = string.Empty;
                    string[] splitStrings = receiveMsg.Split('#');
                    command = splitStrings[0];
                    switch (command)
                    {
                    case "friends":
                        string[] frienditem = splitStrings[1].Split('/');
                        lockList.Clear();
                        foreach (string s in frienditem)
                        {
                            if (s != ".ed")
                            {
                                string[]     _index = s.Split(';');
                                ListViewItem lvitem = new ListViewItem();
                                lvitem.ImageIndex = 0;
                                lvitem.Text       = _index[0];
                                lvitem.SubItems.Add(_index[1]);
                                lvitem.SubItems.Add(_index[2]);
                                lvitem.SubItems.Add(_index[4]);
                                lvitem.Tag = _index[3];
                                lv_friends.Items.Add(lvitem);
                                reqlock n_lock = new reqlock(_index[0]);
                                lockList.Add(n_lock);
                            }
                        }
                        break;

                    case "newmsg":
                        foreach (reqlock l in lockList)
                        {
                            if (l.UID == splitStrings[1])
                            {
                                lock (l.newmsglock)
                                {
                                    l.newmsg++;
                                    noread reader = new noread(splitStrings[1], splitStrings[2], splitStrings[3], splitStrings[4]);
                                    readList.Add(reader);
                                    remind(splitStrings[1]);
                                    Monitor.Pulse(l.newmsglock);
                                }
                            }
                        }
                        break;

                    case "friendreq":
                        //格式:friendreq#UID1;username1/UID2;username2/.ed
                        string[] reqitem = splitStrings[1].Split('/');
                        frdreqList.Clear();
                        foreach (string s in reqitem)
                        {
                            if (s != ".ed")
                            {
                                string[] frdr   = s.Split(';');
                                User     newusr = new User(frdr[0], frdr[1]);
                                frdreqList.Add(newusr);
                            }
                        }
                        if (isHaveFrdrq() != null)
                        {
                            isHaveFrdrq().reloadreqitem();
                        }
                        break;

                    case "putreq":
                        //格式:friendreq#UID1;username1/UID2;username2/.ed
                        string[] putreqitem = splitStrings[1].Split('/');
                        putfrdreqList.Clear();
                        foreach (string s in putreqitem)
                        {
                            if (s != ".ed")
                            {
                                string[] pfrdr   = s.Split(';');
                                User     pnewusr = new User(pfrdr[0], pfrdr[1]);
                                putfrdreqList.Add(pnewusr);
                            }
                        }
                        if (isHaveFrdrq() != null)
                        {
                            isHaveFrdrq().reloadputreqitem();
                        }
                        break;

                    case "mureq":
                        //格式:mureq#GID1;groupname;UID1;username/GID2;groupname;UID2;username/.ed
                        string[] mureqitem = splitStrings[1].Split('/');
                        mureqList.Clear();
                        foreach (string s in mureqitem)
                        {
                            if (s != ".ed")
                            {
                                string[] pfrdr = s.Split(';');
                                Mureq    newmu = new Mureq(pfrdr[2], pfrdr[3], pfrdr[0], pfrdr[1]);
                                mureqList.Add(newmu);
                            }
                        }
                        if (isHaveFrdrq() != null)
                        {
                            isHaveFrdrq().reloadmureqitem();
                        }
                        break;

                    case "putmureq":
                        //格式:putmureq#GID1;groupname1/GID2;groupname2/.ed
                        string[] putmureqitem = splitStrings[1].Split('/');
                        putmureqList.Clear();
                        foreach (string s in putmureqitem)
                        {
                            if (s != ".ed")
                            {
                                string[] pfrdr = s.Split(';');
                                Mureq    newmu = new Mureq("", "", pfrdr[0], pfrdr[1]);
                                putmureqList.Add(newmu);
                            }
                        }
                        if (isHaveFrdrq() != null)
                        {
                            isHaveFrdrq().reloadputmureqitem();
                        }
                        break;

                    case "groups":
                        string[] groupitem = splitStrings[1].Split(';');
                        foreach (string s in groupitem)
                        {
                            if (s != ".ed")
                            {
                                GroupList.Add(s);
                            }
                        }
                        break;

                    case "mugroups":
                        string[] mugroupitem = splitStrings[1].Split(';');
                        foreach (string s in mugroupitem)
                        {
                            if (s != ".ed")
                            {
                                muGroupList.Add(s);
                            }
                        }
                        break;

                    case "reloadlist":
                        lv_friends.Items.Clear();
                        lv_group.Items.Clear();
                        Get_Friend();
                        Get_mutualchat();
                        foreach (mutualTalk mt in mutualTalkList)
                        {
                            mt.get_member();
                        }
                        Get_Friendreq();
                        Get_Putreq();
                        Get_Mureq();
                        Get_Putmureq();
                        break;

                    case "addreturn":
                        switch (splitStrings[1])
                        {
                        case "msg":
                            if (isHaveAddfrd() != null)
                            {
                                isHaveAddfrd().get_msg(splitStrings[2]);
                            }
                            break;

                        case "true":
                            if (isHaveAddfrd() != null)
                            {
                                isHaveAddfrd().get_true();
                            }
                            break;

                        case "mumsg":
                            if (isHaveAddfrd() != null)
                            {
                                isHaveAddfrd().get_mumsg(splitStrings[2]);
                            }
                            break;

                        case "mutrue":
                            if (isHaveAddfrd() != null)
                            {
                                isHaveAddfrd().get_mutrue();
                            }
                            break;

                        default:
                            if (isHaveAddfrd() != null)
                            {
                                isHaveAddfrd().get_msg(receiveMsg);
                            }
                            break;
                        }
                        break;

                    case "addmureturn":
                        switch (splitStrings[1])
                        {
                        case "msg":
                            if (isHaveAddfrd() != null)
                            {
                                isHaveAddfrd().get_msg(splitStrings[2]);
                            }
                            break;

                        case "true":
                            if (isHaveAddfrd() != null)
                            {
                                isHaveAddfrd().get_true();
                            }
                            break;

                        default:
                            if (isHaveAddfrd() != null)
                            {
                                isHaveAddfrd().get_msg(receiveMsg);
                            }
                            break;
                        }
                        break;

                    case "mutualname":
                        //格式:mutualname#GID1;Groupname1;权限;分组/GID2;Groupname;权限;分组/.ed
                        string[] mutualitem = splitStrings[1].Split('/');
                        grplockList.Clear();
                        foreach (string s in mutualitem)
                        {
                            if (s != ".ed")
                            {
                                string[]     _index = s.Split(';');
                                ListViewItem lvitem = new ListViewItem();
                                lvitem.ImageIndex = 0;
                                lvitem.Text       = _index[0];
                                lvitem.SubItems.Add(_index[1]);
                                lvitem.SubItems.Add(_index[3]);
                                lvitem.Tag = _index[2];
                                lvitem.SubItems.Add(_index[4]);
                                lv_group.Items.Add(lvitem);
                                Grouplock glock = new Grouplock(_index[0]);
                                grplockList.Add(glock);
                            }
                        }
                        break;

                    case "member":
                        string[] mem = splitStrings[2].Split('/');
                        foreach (string s in mem)
                        {
                            mutualTalk mtk = isHavemutualTalk(splitStrings[1]);
                            if (mtk == null)
                            {
                                break;
                            }
                            else
                            {
                                if (s != ".ed")
                                {
                                    string[]     _index = s.Split(';');
                                    ListViewItem lvitem = new ListViewItem();
                                    lvitem.ImageIndex = 0;
                                    lvitem.Text       = _index[0];
                                    lvitem.SubItems.Add(_index[1]);
                                    lvitem.SubItems.Add(_index[2]);
                                    lvitem.Tag = _index[2];
                                    mtk.addmemberitem(lvitem);
                                }
                            }
                        }
                        break;

                    case "munewmsg":
                        foreach (Grouplock l in grplockList)
                        {
                            if (l.GID == splitStrings[1])
                            {
                                lock (l.newmsglock)
                                {
                                    l.newmsg++;
                                    Groupnoread reader = new Groupnoread(splitStrings[1], splitStrings[2], splitStrings[3], splitStrings[4], splitStrings[5]);
                                    grpreadList.Add(reader);
                                    muremind(splitStrings[1]);
                                    Monitor.Pulse(l.newmsglock);
                                }
                            }
                        }
                        break;

                    case "userstate":
                        Username         = splitStrings[1];
                        sign             = splitStrings[2];
                        lb_Username.Text = Username;
                        break;

                    /*case "mustate":
                     *  mustate(splitStrings[1], splitStrings[2], splitStrings[3]);
                     *  break;*/
                    default:
                        MessageBox.Show(receiveMsg);
                        break;
                    }
                }
            }
        }