コード例 #1
0
        void UpdateUserInfoList(UserNameInfoData fetchedUser)
        {
            var userNameInfo = fetchedUser;

            var userInfoIndex = UserNameInfoList.FindIndex(m => m.IPAddress == userNameInfo.IPAddress &&
                                                           m.BeginPort == userNameInfo.BeginPort && m.EndPort == userNameInfo.EndPort);

            if (userInfoIndex == -1)
            {
                UserNameInfoList.Add(new UserNameInfoData()
                {
                    IPAddress = userNameInfo.IPAddress,
                    BeginPort = userNameInfo.BeginPort,
                    EndPort   = userNameInfo.EndPort,
                    UserName  = userNameInfo.UserName
                });
            }
            else
            {
                UserNameInfoList[userInfoIndex] = new UserNameInfoData()
                {
                    IPAddress = userNameInfo.IPAddress,
                    BeginPort = userNameInfo.BeginPort,
                    EndPort   = userNameInfo.EndPort,
                    UserName  = userNameInfo.UserName
                };
            }
        }
コード例 #2
0
        void UpdateUserInfoList()
        {
            var clientIpConnectList = mUDPBoxContainer.ClientIPConnectList;

            for (int i = 0, iMax = clientIpConnectList.Count; i < iMax; i++)
            {
                var item = clientIpConnectList[i];

                if (!item.Valid)
                {
                    continue;
                }
                if (!item.IsClientEstablished)
                {
                    continue;
                }

                var address           = item.IPEndPoint.Address.ToString();
                var port              = item.IPEndPoint.Port;
                var userNameInfoIndex = UserNameInfoList.FindIndex(m => m.IPAddress == address &&
                                                                   m.BeginPort <= port && m.EndPort > port);

                if (userNameInfoIndex == -1)
                {
                    mTemplate.Op = UserNameListPackage.EOperate.Fetch;
                    mTemplate.UserNameInfoList.Clear();
                    mUDPBoxContainer.SendUDPMessage(mTemplate.Serialize(), item.IPEndPoint);
                }
            }

            for (int i = UserNameInfoList.Count - 1; i >= 0; i--)
            {
                var marked_userNameInfo = UserNameInfoList[i];

                if (marked_userNameInfo.UserName == SelfUserName)
                {
                    continue;
                }

                var foundClientObject = clientIpConnectList.Find(m => m.Valid &&
                                                                 m.IPEndPoint.Address.ToString() == marked_userNameInfo.IPAddress &&
                                                                 m.IPEndPoint.Port >= marked_userNameInfo.BeginPort &&
                                                                 m.IPEndPoint.Port < marked_userNameInfo.EndPort);

                if (!foundClientObject.Valid)
                {
                    UserNameInfoList.RemoveAt(i);
                }
            }
            var selfIPAddress = mUDPBoxContainer.SelfIPAddress.ToString();
            var selfBeginPort = mUDPBoxContainer.UdpBoxBeginPort;
            var selfEndPort   = mUDPBoxContainer.UdpBoxEndPort;

            var selfUserNameInfoIndex = UserNameInfoList
                                        .FindIndex(m => m.IPAddress == selfIPAddress &&
                                                   m.BeginPort == selfBeginPort && m.EndPort == selfEndPort);

            if (selfUserNameInfoIndex == -1)
            {
                UserNameInfoList.Add(new UserNameInfoData()
                {
                    IPAddress = selfIPAddress,
                    BeginPort = selfBeginPort,
                    EndPort   = selfEndPort,
                    UserName  = SelfUserName,
                });
            }
            else
            {
                UserNameInfoList[selfUserNameInfoIndex] = new UserNameInfoData()
                {
                    IPAddress = selfIPAddress,
                    BeginPort = selfBeginPort,
                    EndPort   = selfEndPort,
                    UserName  = SelfUserName,
                };
            }
        }