Example #1
0
        public void GetAddresses(Region region, IpFilter filter, int maxResults, MasterIpCallback callback)
        {
            var master = masterServerEndPoint.Port == 0 ? (MasterServer) new MasterServerWebApi() : new MasterServerUdp(masterServerEndPoint);

            master.GetAddressesLimit = maxResults;
            master.GetAddresses(region, callback, filter);
        }
        private void RefreshServerInfo()
        {
            try
            {
                if (splitContainer1.Panel2Collapsed || lvHistory.SelectedItems.Count <= 0)
                {
                    return;
                }
                var server = (HistoryServer)lvHistory.SelectedItems[0].Tag;

                SetServerInfo();

                lbServerInfo2.ForeColor = Color.Red;
                lbServerInfo2.Text      = "connecting...";

                var masterServer = MasterQuery.GetMasterServerInstance(EngineType.Source);
                var ipfilter     = new IpFilter {
                    GameAddr = server.IPEndPoint.ToString(), App = Game.DayZ
                };

                masterServer.GetAddresses(QueryMaster.Region.Rest_of_the_world, MasterIpCallback, ipfilter);
            }
            catch (Exception ex)
            {
                SetServerInfo();
                MessageBox.Show(ex.ToString());
            }
        }
Example #3
0
 /// <summary>
 /// Starts receiving socket addresses of servers.
 /// </summary>
 /// <param name="region">The region of the world that you wish to find servers in.</param>
 /// <param name="callback">Called when a batch of Socket addresses are received.</param>
 /// <param name="filter">Used to set filter on the type of server required.</param>
 /// <param name="batchCount">Number of batches to fetch.-1 would return all addressess.(1 batch = 1 udppacket = 231 addressess).</param>
 /// <param name="errorCallback">Invoked in case of error.</param>
 public void GetAddresses(Region region, BatchReceivedCallback callback, IpFilter filter = null, int batchCount = 1, ErrorCallback errorCallback = null)
 {
     ThrowIfDisposed();
     StopReceiving();
     this.region   = region;
     Callback      = callback;
     ErrorCallback = errorCallback;
     BatchCount    = batchCount == -1 ? int.MaxValue : batchCount;
     this.filter   = filter;
     lastEndPoint  = null;
     Initialize();
     TaskList.First().Start();
 }
        private void Create()
        {
            _ipFilter = IpFilter.Create(
                Session.Dynamic(),
                new DisplayData {
                Name = "Proton Technologies AG", Description = "ProtonVPN Split Tunnel provider"
            });

            _subLayer = _ipFilter.CreateSublayer(
                new DisplayData {
                Name = "ProtonVPN Split Tunnel filters"
            },
                WfpSubLayerWeight);
        }
        private void Create()
        {
            _ipFilter = IpFilter.Create(
                Session.Dynamic(),
                new DisplayData {
                Name = "Time4VPS VPN Split Tunnel redirect app", Description = "Time4VPS VPN Split Tunnel provider"
            });

            _subLayer = _ipFilter.CreateSublayer(
                new DisplayData {
                Name = "Time4VPS VPN Split Tunnel filters"
            },
                WfpSubLayerWeight);
        }
        public override void CustomizeServerFilter(IpFilter filter)
        {
            // Valve's matchmaking servers don't respond to A2S_PLAYER queries, can't be joined from outside a lobby
            // and the Valve network throttles clients to 100 requests per minute across all their servers and there are thousands of them.
            // They can be identified by the tag "valve_ds", which we use to filter them out on the server side.

            // skip over user's filter and append our own
            while (filter.Nor != null)
            {
                filter = filter.Nor;
            }

            filter.Nor         = new IpFilter();
            filter.Nor.Sv_Tags = "valve_ds";
        }
Example #7
0
        internal static byte[] BuildPacket(string endPoint, Region region, IpFilter filter)
        {
            List <byte> msg = new List <byte>();

            msg.Add(Header);
            msg.Add((byte)region);
            msg.AddRange(Util.StringToBytes(endPoint));
            msg.Add(0x00);
            if (filter != null)
            {
                msg.AddRange(Util.StringToBytes(ProcessFilter(filter)));
            }
            msg.Add(0x00);
            return(msg.ToArray());
        }
        public void GetAddresses(Region region, IpFilter filter, int maxResults, MasterIpCallback callback)
        {
            try
            {
                using (var client = new XWebClient())
                {
                    var text = client.DownloadString(this.url);
                    if (text == null)
                    {
                        callback(null, null, false);
                        return;
                    }

                    var lines     = text.Split('\n');
                    var endpoints = new List <Tuple <IPEndPoint, ServerInfo> >(lines.Length);
                    int i         = 0;
                    foreach (var line in lines)
                    {
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }
                        var parts = line.Split(':');
                        if (parts.Length != 2)
                        {
                            continue;
                        }

                        IPAddress addr;
                        int       port;
                        if (IPAddress.TryParse(parts[0], out addr) && int.TryParse(parts[1].TrimEnd(), out port))
                        {
                            endpoints.Add(new Tuple <IPEndPoint, ServerInfo>(new IPEndPoint(addr, port), null));
                            if (++i == maxResults)
                            {
                                break;
                            }
                        }
                    }
                    callback(new ReadOnlyCollection <Tuple <IPEndPoint, ServerInfo> >(endpoints), null, false);
                }
            }
            catch (Exception ex)
            {
                callback(null, ex, false);
            }
        }
Example #9
0
        public async Task <IpFilter> AddCategory(string name)
        {
            if (await IsCategoryDuplicate(name))
            {
                throw new Exception($"'{name}' already exists. Please choose a different name.");
            }
            IpFilter maxRecord = await _dbContext.IpFilters.OrderByDescending(x => x.Id).FirstOrDefaultAsync();

            var      maxId    = maxRecord.Id;
            IpFilter category = new IpFilter
            {
                Name = name,
                Type = FilterType.Category,
                Code = "Cat-" + maxId
            };
            await _dbContext.IpFilters.AddAsync(category);

            await _dbContext.SaveChangesAsync();

            return(category);
        }
Example #10
0
        public async Task GetListTest()
        {
            var server = MasterQuery.GetServerInstance(MasterQuery.SourceServerEndPoint);
            var method = new BatchReceivedCallback(info =>
            {
                Console.WriteLine(info.Source);
                Console.WriteLine(info.IsLastBatch);
                Console.WriteLine(info.Region);
                Console.WriteLine(info.ReceivedEndpoints.Count);
                foreach (var endPoint in info.ReceivedEndpoints)
                {
                    Console.WriteLine($@"{endPoint.Address}:{endPoint.Port}");
                }
            });
            var filter = new IpFilter
            {
                AppId = Game.Left_4_Dead_2
            };

            server.GetAddresses(Region.Asia, method, filter);
            await Task.Delay(5000);
        }
 /// <summary>
 /// This method is called before a server source (e.g. master server) is queried and allows to add game specific filters.
 /// In particular servers which are only accessible through lobbies should be filtered out by adding a "Nor" filter.
 /// </summary>
 public virtual void CustomizeServerFilter(IpFilter filter)
 {
 }
 private void Remove()
 {
     _ipFilter?.Session.Close();
     _ipFilter = null;
     _subLayer = null;
 }
Example #13
0
        internal static string ProcessFilter(IpFilter filter, bool isSubFilter = false)
        {
            StringBuilder filterStr = new StringBuilder();

            if (filter.IsDedicated)
            {
                filterStr.Append(@"\type\d");
            }
            if (filter.IsSecure)
            {
                filterStr.Append(@"\secure\1");
            }
            if (!string.IsNullOrEmpty(filter.GameDirectory))
            {
                filterStr.Append(@"\gamedir\" + filter.GameDirectory);
            }
            if (!string.IsNullOrEmpty(filter.Map))
            {
                filterStr.Append(@"\map\" + filter.Map);
            }
            if (filter.IsLinux)
            {
                filterStr.Append(@"\linux\1");
            }
            if (filter.IsNotEmpty)
            {
                filterStr.Append(@"\empty\1");
            }
            if (filter.IsNotFull)
            {
                filterStr.Append(@"\full\1");
            }
            if (filter.IsProxy)
            {
                filterStr.Append(@"\proxy\1");
            }
            if (filter.NAppId != 0)
            {
                filterStr.Append(@"\napp\" + (ulong)filter.NAppId);
            }
            if (filter.IsNoPlayers)
            {
                filterStr.Append(@"\noplayers\1");
            }
            if (filter.IsWhiteListed)
            {
                filterStr.Append(@"\white\1");
            }
            if (!string.IsNullOrEmpty(filter.Tags))
            {
                filterStr.Append(@"\gametype\" + filter.Tags);
            }
            if (!string.IsNullOrEmpty(filter.HiddenTagsAll))
            {
                filterStr.Append(@"\gamedata\" + filter.HiddenTagsAll);
            }
            if (!string.IsNullOrEmpty(filter.HiddenTagsAny))
            {
                filterStr.Append(@"\gamedataor\" + filter.HiddenTagsAny);
            }
            if (filter.AppId != 0)
            {
                filterStr.Append(@"\appid\" + (ulong)filter.AppId);
            }
            if (!string.IsNullOrEmpty(filter.HostName))
            {
                filterStr.Append(@"\name_match\" + filter.HostName);
            }
            if (!string.IsNullOrEmpty(filter.Version))
            {
                filterStr.Append(@"\version_match\" + filter.Version);
            }
            if (filter.IsUniqueIPAddress)
            {
                filterStr.Append(@"\collapse_addr_hash\1");
            }
            if (!string.IsNullOrEmpty(filter.IPAddress))
            {
                filterStr.Append(@"\gameaddr\" + filter.IPAddress);
            }
            if (filter.ExcludeAny != null)
            {
                filterStr.Append("\0nor");
                filterStr.Append(ProcessFilter(filter.ExcludeAny, true));
            }
            if (filter.ExcludeAll != null)
            {
                filterStr.Append("\0nand");
                filterStr.Append(ProcessFilter(filter.ExcludeAll, true));
            }
            if (!isSubFilter)
            {
                string[] Parts = null;
                string   norStr = string.Empty, nandStr = string.Empty;
                Parts     = filterStr.ToString().Split('\0');
                filterStr = new StringBuilder(Parts[0]);
                for (int i = 1; i < Parts.Length; i++)
                {
                    if (Parts[i].StartsWith("nor", StringComparison.OrdinalIgnoreCase))
                    {
                        norStr += Parts[i].Substring(3);
                    }
                    if (Parts[i].StartsWith("nand", StringComparison.OrdinalIgnoreCase))
                    {
                        nandStr += Parts[i].Substring(4);
                    }
                }
                if (!String.IsNullOrEmpty(norStr))
                {
                    filterStr.Append(@"\nor\");
                    filterStr.Append(norStr.Count(x => x == '\\') / 2);
                    filterStr.Append(norStr);
                }
                if (!String.IsNullOrEmpty(nandStr))
                {
                    filterStr.Append(@"\nand\");
                    filterStr.Append(nandStr.Count(x => x == '\\') / 2);
                    filterStr.Append(nandStr);
                }
            }
            return(filterStr.ToString());
        }
        // reload server list

        #region ReloadServerList()
        public void ReloadServerList(IServerSource serverSource, int timeout, int maxResults, Region region, IpFilter filter)
        {
            this.currentRequest.IsCancelled = true;

            var extension = this.gameExtensions.Get(filter.App);
            var request   = new UpdateRequest(filter.App, maxResults, timeout, extension, false); // use local var for thread safety

            this.currentRequest = request;
            serverSource.GetAddresses(region, filter, maxResults, (endpoints, error, partial) => OnMasterServerReceive(request, endpoints, error, partial));
        }