Example #1
0
        private void ParseInfoKeyString(Player player, String s)
        {
            String[] infoKeyTokens = s.Split('\\');

            for (int i = 0; i < infoKeyTokens.Length; i += 2)
            {
                if (i + 1 >= infoKeyTokens.Length)
                {
                    // Must be an odd number of strings - a key without a value - ignore it.
                    break;
                }

                String key   = infoKeyTokens[i];
                String value = infoKeyTokens[i + 1];

                // find or create InfoKey object
                InfoKey infoKey = Common.FirstOrDefault <InfoKey>(player.InfoKeys, ik => ik.Key == key);

                if (infoKey == null)
                {
                    infoKey     = new InfoKey();
                    infoKey.Key = key;

                    // add new infokey
                    player.InfoKeys.Add(infoKey);
                }
                else
                {
                    // don't create a new value entry if the previous value is exactly the same
                    if (infoKey.NewestValueValue == value)
                    {
                        continue;
                    }
                }

                // create infokey value
                InfoKeyValue infoKeyValue = new InfoKeyValue();
                infoKeyValue.Value     = value;
                infoKeyValue.Timestamp = currentTimestamp;

                // add new value to infokey values
                infoKey.Values.Add(infoKeyValue);
            }

            // create a Steam ID key if the player isn't a HLTV proxy.
            InfoKey hltv = Common.FirstOrDefault(player.InfoKeys, ik => ik.Key == "*hltv");
            InfoKey sid  = Common.FirstOrDefault(player.InfoKeys, ik => ik.Key == "*sid");

            if (hltv == null && sid != null)
            {
                String steamId = Common.CalculateSteamId(sid.NewestValueValue);

                if (steamId != null)
                {
                    AddInfoKey(player, "SteamId", steamId);
                }
            }
        }
        public static (BEncodedDictionary torrent, RawInfoHashes infoHashes) DecodeTorrent(ref ReadOnlySpan <byte> buffer)
        {
            if (buffer[0] != 'd')
            {
                throw new BEncodingException($"The root value was not a BEncodedDictionary");
            }

            buffer = buffer.Slice(1);
            BEncodedString?     oldkey         = null;
            ReadOnlySpan <byte> infoBuffer     = default;
            Memory <byte>       infoHashSHA1   = default;
            Memory <byte>       infoHashSHA256 = default;
            var dictionary = new BEncodedDictionary();

            while (buffer.Length > 0)
            {
                if (buffer[0] == 'e')
                {
                    buffer = buffer.Slice(1);
                    return(dictionary, new RawInfoHashes(infoHashSHA1, infoHashSHA256));
                }

                var key = DecodeString(ref buffer);
                if (oldkey != null && oldkey.CompareTo(key) > 0)
                {
                    throw new BEncodingException($"Illegal BEncodedDictionary. The attributes are not ordered correctly. Old key: {oldkey}, New key: {key}");
                }

                if (InfoKey.Equals(key))
                {
                    infoBuffer = buffer;
                }

                oldkey = key;
                var value = Decode(ref buffer, false);
                dictionary.Add(key, value);

                if (InfoKey.Equals(key))
                {
                    using var hasher   = SHA1.Create();
                    using var hasherV2 = SHA256.Create();
                    infoHashSHA1       = new byte[hasher.HashSize / 8];
                    infoHashSHA256     = new byte[hasherV2.HashSize / 8];
                    if (!hasher.TryComputeHash(infoBuffer.Slice(0, infoBuffer.Length - buffer.Length), infoHashSHA1.Span, out int written) || written != infoHashSHA1.Length)
                    {
                        throw new BEncodingException("Could not compute infohash for torrent.");
                    }
                    if (!hasherV2.TryComputeHash(infoBuffer.Slice(0, infoBuffer.Length - buffer.Length), infoHashSHA256.Span, out written) || written != infoHashSHA256.Length)
                    {
                        throw new BEncodingException("Could not compute v2 infohash for torrent.");
                    }
                }
            }
            throw new BEncodingException("Invalid data found. Aborting");
        }
Example #3
0
 public Key(ContentManager Content, float X, float Y)
 {
     IK = new InfoKey()
     {
         Texture       = Content.Load <Texture2D>("Key"),
         WidthTexture  = 171f,
         HeightTexture = 363f,
         Scale         = 0.1f,
     };
     Position = new Vector2(X, Y);
 }
Example #4
0
        private void AddInfoKey(Player player, String key, String value)
        {
            InfoKey targetInfoKey = Common.FirstOrDefault <InfoKey>(player.InfoKeys, ik => ik.Key == key);

            if (targetInfoKey == null)
            {
                targetInfoKey     = new InfoKey();
                targetInfoKey.Key = key;
                player.InfoKeys.Add(targetInfoKey);
            }

            if (targetInfoKey.NewestValueValue != value)
            {
                InfoKeyValue ikv = new InfoKeyValue();
                ikv.Value     = value;
                ikv.Timestamp = currentTimestamp;
                targetInfoKey.Values.Add(ikv);
            }
        }
        private void ParseInfoKeyString(Player player, String s)
        {
            String[] infoKeyTokens = s.Split('\\');

            for (int i = 0; i < infoKeyTokens.Length; i += 2)
            {
                if (i + 1 >= infoKeyTokens.Length)
                {
                    // Must be an odd number of strings - a key without a value - ignore it.
                    break;
                }

                String key = infoKeyTokens[i];
                String value = infoKeyTokens[i + 1];

                // find or create InfoKey object
                InfoKey infoKey = Common.FirstOrDefault<InfoKey>(player.InfoKeys, ik => ik.Key == key);

                if (infoKey == null)
                {
                    infoKey = new InfoKey();
                    infoKey.Key = key;

                    // add new infokey
                    player.InfoKeys.Add(infoKey);
                }
                else
                {
                    // don't create a new value entry if the previous value is exactly the same
                    if (infoKey.NewestValueValue == value)
                    {
                        continue;
                    }
                }

                // create infokey value
                InfoKeyValue infoKeyValue = new InfoKeyValue();
                infoKeyValue.Value = value;
                infoKeyValue.Timestamp = currentTimestamp;

                // add new value to infokey values
                infoKey.Values.Add(infoKeyValue);
            }

            // create a Steam ID key if the player isn't a HLTV proxy.
            InfoKey hltv = Common.FirstOrDefault(player.InfoKeys, ik => ik.Key == "*hltv");
            InfoKey sid = Common.FirstOrDefault(player.InfoKeys, ik => ik.Key == "*sid");

            if (hltv == null && sid != null)
            {
                String steamId = Common.CalculateSteamId(sid.NewestValueValue);

                if (steamId != null)
                {
                    AddInfoKey(player, "SteamId", steamId);
                }
            }
        }
        private void AddInfoKey(Player player, String key, String value)
        {
            InfoKey targetInfoKey = Common.FirstOrDefault<InfoKey>(player.InfoKeys, ik => ik.Key == key);

            if (targetInfoKey == null)
            {
                targetInfoKey = new InfoKey();
                targetInfoKey.Key = key;
                player.InfoKeys.Add(targetInfoKey);
            }

            if (targetInfoKey.NewestValueValue != value)
            {
                InfoKeyValue ikv = new InfoKeyValue();
                ikv.Value = value;
                ikv.Timestamp = currentTimestamp;
                targetInfoKey.Values.Add(ikv);
            }
        }