Beispiel #1
0
        public static void addnewitem(Friend.Friend friend)
        {
            ListViewItem lvi = new ListViewItem();

            lvi.Name = friend.ID;

            //lvi.ToolTipText = getToolTip(friend.State);
            if (friend.IsNet)
            {
                lvi.SubItems.AddRange(new string[] { " ", "", "", "", "", "" });
                lvi.SubItems[0].Text = friend.ID;
                lvi.SubItems[1].Text = friend.GroupName;
                lvi.SubItems[2].Text = friend.Name;
                lvi.SubItems[3].Text = getToolTip(friend.State);
                lvi.SubItems[4].Text = serverHelper.getIP(friend.Ip);
                lvi.SubItems[5].Text = friend.Port.ToString();
                lvi.SubItems[6].Text = friend.Ver;
                serverHelper.MainForm.lvnet.Items.Add(lvi);
            }
            else
            {
                lvi.SubItems.AddRange(new string[] { " ", "", "", "", "", "" });
                lvi.SubItems[0].Text = friend.ID;
                lvi.SubItems[1].Text = friend.GroupName;
                lvi.SubItems[2].Text = friend.Name;
                lvi.SubItems[3].Text = getToolTip(friend.State);
                lvi.SubItems[4].Text = serverHelper.getIP(friend.Ip);
                lvi.SubItems[5].Text = friend.Port.ToString();
                lvi.SubItems[6].Text = friend.Ver;
                serverHelper.MainForm.lvlan.Items.Add(lvi);
            }
        }
Beispiel #2
0
 /// <summary>
 /// 重设或添回好友
 /// </summary>
 /// <param name="friend"></param>
 public static void resetFriend(Friend.Friend myfriend)
 {
     Friend.Friend friended = findFriend(myfriend.ID);
     if (friended != null)
     {
         myfriend.Messages = friended.Messages;
     }
     _friends.Remove(friended);
     _friends.Add(myfriend);
 }
Beispiel #3
0
 /// <summary>
 /// 检查用户是否已是好友
 /// </summary>
 /// <param name="friend"></param>
 public static void addUIFriend(Friend.Friend friend, System.Net.IPEndPoint iep)
 {
     Friend.Friend f = _poolFactory.findFriend(friend.ID);
     if (f == null)
     {
         addnewitem(friend);
     }
     else
     {
         if (friend.IsNet)
         {
             ListViewItem lvi = findNetItemByID(friend.ID);
             if (lvi == null)
             {
                 addnewitem(friend);
             }
             else
             {
                 lvi.SubItems[0].Text = friend.ID;
                 lvi.SubItems[2].Text = friend.Name;
                 lvi.SubItems[3].Text = getToolTip(friend.State);
                 lvi.SubItems[4].Text = serverHelper.getIP(friend.Ip);
                 lvi.SubItems[5].Text = friend.Port.ToString();
                 lvi.SubItems[6].Text = friend.Ver;
                 if (lvi.SubItems[1].Text != friend.GroupName)
                 {
                     lvi.SubItems[1].Text = friend.GroupName;
                     //sortItemByGroupName(friend.IsNet);
                 }
             }
         }
         else
         {
             ListViewItem lvi = findLanItemByID(friend.ID);
             if (lvi == null)
             {
                 addnewitem(friend);
             }
             else
             {
                 lvi.SubItems[0].Text = friend.ID;
                 lvi.SubItems[2].Text = friend.Name;
                 lvi.SubItems[3].Text = getToolTip(friend.State);
                 lvi.SubItems[4].Text = serverHelper.getIP(friend.Ip);
                 lvi.SubItems[5].Text = friend.Port.ToString();
                 lvi.SubItems[6].Text = friend.Ver;
                 if (lvi.SubItems[1].Text != friend.GroupName)
                 {
                     lvi.SubItems[1].Text = friend.GroupName;
                     //sortItemByGroupName(friend.IsNet);
                 }
             }
         }
     }
 }
Beispiel #4
0
 private static bool findCurFrind(Friend.Friend friend)
 {
     try
     {
         return(friend.ID.Equals(_curFriendID) || (friend.Ip[0].Equals(_curFriendIP[0]) && friend.Ip[1].Equals(_curFriendIP[1]) && friend.Ip[2].Equals(_curFriendIP[2]) && friend.Ip[3].Equals(_curFriendIP[3])));
     }
     catch
     {
         return(false);
     }
 }
Beispiel #5
0
 private static bool delegetefindfriendbyserveridandfriendid(Friend.Friend friend)
 {
     try
     {
         return(friend.ID.Equals(findfriendbyserveridandfriendidfriendid) && friend.ServerID.Equals(findfriendbyserveridandfriendidserverid));
     }
     catch
     {
         return(false);
     }
 }
Beispiel #6
0
 /// <summary>
 /// 登出好友
 /// </summary>
 /// <param name="friend"></param>
 public static void outUIFriend(Friend.Friend friend)
 {
     try
     {
         if (friend.IsNet)
         {
             serverHelper.MainForm.lvnet.Items.RemoveByKey(friend.ID);
         }
         else
         {
             serverHelper.MainForm.lvlan.Items.RemoveByKey(friend.ID);
         }
     }
     catch
     { }
 }
Beispiel #7
0
 /// <summary>
 /// 处理要发送的消息线程
 /// </summary>
 private static void THREADSENDMSG()
 {
     while (serverHelper.Iflag == 0)
     {
         try
         {
             if (_poolFactory.SendmsgINFO.Count > 0)
             {
                 for (int i = 0; i < _poolFactory.SendmsgINFO.Count; i++)
                 {
                     try
                     {
                         if (_poolFactory.SendmsgINFO[i].Sendto == null || _poolFactory.SendmsgINFO[i].Sendto.Length == 0)
                         {
                             continue;
                         }
                         foreach (string sendto in _poolFactory.SendmsgINFO[i].Sendto)
                         {
                             Friend.Friend friend = _poolFactory.findFriend(sendto);
                             if (!string.IsNullOrEmpty(sendto) && sendto.Contains("."))//IP用户
                             {
                                 if (_poolFactory.SendmsgINFO[i].IsNET)
                                 {
                                     if (serverHelper.islevelserver)
                                     {
                                         sendMsg(_poolFactory.SendmsgINFO[i].LantalkMsg, serverHelper.mainserveraddr, serverHelper.mainserverport);
                                         lastconnecttoserver = DateTime.Now;
                                     }
                                     else
                                     {
                                         if (friend != null && !string.IsNullOrEmpty(friend.ServerID))//如果此用户为次级服务器的用户
                                         {
                                             Friend.SERVER erver = _poolFactory.findServerByID(friend.ServerID);
                                             if (erver != null)
                                             {
                                                 ServersendMsg(_poolFactory.SendmsgINFO[i].LantalkMsg, erver.ADDR, erver.PORT);
                                                 continue;
                                             }
                                         }
                                         ServersendMsg(_poolFactory.SendmsgINFO[i].LantalkMsg, sendto, _poolFactory.SendmsgINFO[i].SendPort);
                                     }
                                 }
                                 else
                                 {
                                     if (serverHelper.islevelserver && friend != null && friend.IsNet)
                                     {
                                         sendMsg(_poolFactory.SendmsgINFO[i].LantalkMsg, serverHelper.mainserveraddr, serverHelper.mainserverport);
                                         continue;
                                     }
                                     sendMsg(_poolFactory.SendmsgINFO[i].LantalkMsg, sendto);
                                 }
                             }
                             else if (!string.IsNullOrEmpty(sendto))//ID用户
                             {
                                 if (friend != null)
                                 {
                                     if (serverHelper.islevelserver && serverHelper.isloginedlevelserver)
                                     {
                                         sendMsg(_poolFactory.SendmsgINFO[i].LantalkMsg, serverHelper.mainserveraddr, serverHelper.mainserverport);
                                         lastconnecttoserver = DateTime.Now;
                                     }
                                     else
                                     {
                                         ServersendMsg(_poolFactory.SendmsgINFO[i].LantalkMsg, serverHelper.getIP(friend.Ip), friend.Port);
                                     }
                                 }
                             }
                             Thread.Sleep(20);
                         }
                     }
                     catch (Exception ex)
                     {
                         serverHelper.writeLog("发送消息时出错" + ex.Message);
                     }
                     finally
                     {
                         _poolFactory.SendmsgINFO[i].Sendto = null;
                     }
                 }
                 _poolFactory.clearSendMsgInfo();//清除已发送的消息
             }
             else
             {
                 if (serverHelper.islevelserver && lastconnecttoserver < DateTime.Now.AddSeconds(-30))
                 {
                     sendMsg(sayHelloToServer(), serverHelper.mainserveraddr, serverHelper.mainserverport);
                     lastconnecttoserver = DateTime.Now;
                 }
                 Thread.Sleep(20);
             }
         }
         catch (Exception ex)
         {
             serverHelper.writeLog("msghelper.THREADSENDMSG " + ex.Message);
             _poolFactory.clearSendMsgInfo();//清除已发送的消息
         }
     }
 }
Beispiel #8
0
 private static void addGroupNode(out TreeNode group, Friend.Friend friend)
 {
     group = null;
 }
Beispiel #9
0
 private static bool findfriendsbygroupname(Friend.Friend f)
 {
     return(f.GroupName.Equals(_curgroupname));
 }
Beispiel #10
0
 private static bool findnetfriend(Friend.Friend friend)
 {
     return(friend.IsNet);
 }
Beispiel #11
0
 /// <summary>
 /// 移除好友
 /// </summary>
 /// <param name="friend"></param>
 public static void removeFriend(Friend.Friend friend)
 {
     //_curFriendID = friend.ID;
     _friends.Remove(findFriend(friend.Ip));
 }