Пример #1
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();
 }
Пример #2
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());
        }
Пример #3
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());
        }