Exemple #1
0
        public void TryMergeWithList_AddsToHead_AndMovesExisting()
        {
            serverList.GetAllEndPoints();

            var seedList = new[]
            {
                ServerRecord.CreateSocketServer(new IPEndPoint(IPAddress.Loopback, 27025)),
                ServerRecord.CreateSocketServer(new IPEndPoint(IPAddress.Loopback, 27035)),
                ServerRecord.CreateSocketServer(new IPEndPoint(IPAddress.Loopback, 27045)),
                ServerRecord.CreateSocketServer(new IPEndPoint(IPAddress.Loopback, 27105)),
            };

            serverList.ReplaceList(seedList);
            Assert.Equal(4, seedList.Length);

            var listToReplace = new[]
            {
                ServerRecord.CreateSocketServer(new IPEndPoint(IPAddress.Loopback, 27015)),
                ServerRecord.CreateSocketServer(new IPEndPoint(IPAddress.Loopback, 27035)),
                ServerRecord.CreateSocketServer(new IPEndPoint(IPAddress.Loopback, 27105)),
            };

            serverList.ReplaceList(listToReplace);

            var addresses = serverList.GetAllEndPoints();

            Assert.Equal(3, addresses.Length);
            Assert.Equal(listToReplace[0], addresses[0]);
            Assert.Equal(listToReplace[1], addresses[1]);
            Assert.Equal(listToReplace[2], addresses[2]);
        }
        public static ServerRecord GetServerRecord()
        {
            var validRecord = _servers
                              .FirstOrDefault(t => t.Value < CountForChange && !BadRecords.Contains(t.Key)).Key;

            if (validRecord == null)
            {
                var serverList = new SmartCMServerList(SteamConfiguration.Create(b => b.WithProtocolTypes(ProtocolTypes.Tcp)));
                _servers = serverList.GetAllEndPoints()
                           .Where(t => t.ProtocolTypes.HasFlag(ProtocolTypes.Tcp))
                           .ToDictionary(t => t, t => 0);
                BadRecords.Clear();
                return(GetServerRecord());
            }
            _servers[validRecord] = _servers[validRecord] + 1;

            return(validRecord);
        }
Exemple #3
0
        public void TryAdd_ReturnsTrue_WhenAdded()
        {
            var endPoint = new IPEndPoint(IPAddress.Loopback, 27015);
            var added    = serverList.TryAdd(endPoint);

            Assert.True(added, "TryAdd should have added the IPEndPoint to the list.");

            var addresses = serverList.GetAllEndPoints();

            Assert.Equal(1, addresses.Length);
            Assert.Equal(endPoint, addresses[0]);
        }
        static SteamServerList()
        {
            var serverList = new SmartCMServerList(SteamConfiguration.Create(b => b.WithProtocolTypes(ProtocolTypes.Tcp)));

            _servers = serverList.GetAllEndPoints().Where(t => t.ProtocolTypes.HasFlag(ProtocolTypes.Tcp)).ToDictionary(t => t, t => 0);
        }