コード例 #1
0
        public static byte[] MakeResponse(ClientRequestInfo ps)

        {
            IPAddress client  = IPAddress.Parse("90.178.44.86");
            var       servers = new[]
            {
                new IPEndPoint(IPAddress.Parse("176.9.148.187"), 7788),
                //new IPEndPoint(IPAddress.Parse("208.100.45.13"), 7778),
                //new IPEndPoint(IPAddress.Parse("208.94.242.194"), 8889),
                //new IPEndPoint(IPAddress.Parse("94.23.249.178"), 7778),
                new IPEndPoint(IPAddress.Parse("72.54.15.202"), 7778),
            };

            using (var ms = new MemoryStream())
            {
                ms.Write(client.GetAddressBytes(), 0, 4);

                ms.WriteByte(0);                      //idk what this is, port maybe?
                ms.WriteByte(0);                      //idk what this is, port maybe?

                ms.WriteByte((byte)ps.Params.Length); // numparams
                ms.WriteByte(0);

                foreach (var param in ps.Params)
                {
                    var bytes = Encoding.ASCII.GetBytes(param);
                    ms.Write(bytes, 0, bytes.Length);
                    ms.WriteByte(0);
                    ms.WriteByte(0);
                }

                foreach (var server in servers)
                {
                    ms.WriteByte(21); // something tribes sent
                    ms.Write(server.Address.GetAddressBytes(), 0, 4);
                    ms.Write(BitConverterBE.GetBytes((ushort)server.Port), 0, 2);
                }

                ms.WriteByte(0); // end servers array

                return(ms.ToArray());
            }


            // genuine response from master
            return(new byte[]
            {
                90, 178, 44, 86, 30, 98, 14, 0, 109, 97, 112, 110, 97, 109, 101, 0, 0, 110, 117, 109, 112, 108, 97, 121, 101, 114, 115, 0, 0, 109, 97, 120, 112, 108, 97, 121, 101, 114, 115, 0, 0, 104, 111, 115, 116, 110, 97, 109, 101, 0, 0, 104, 111, 115, 116, 112, 111, 114, 116, 0, 0, 103, 97, 109, 101, 116, 121, 112, 101, 0, 0, 103, 97, 109, 101, 118, 101, 114, 0, 0, 112, 97, 115, 115, 119, 111, 114, 100, 0, 0, 103, 97, 109, 101, 110, 97, 109, 101, 0, 0, 103, 97, 109, 101, 109, 111, 100, 101, 0, 0, 103, 97, 109, 101, 118, 97, 114, 105, 97, 110, 116, 0, 0, 116, 114, 97, 99, 107, 105, 110, 103, 115, 116, 97, 116, 115, 0, 0, 100, 101, 100, 105, 99, 97, 116, 101, 100, 0, 0, 109, 105, 110, 118, 101, 114, 0, 0, 21, 208, 100, 45, 13, 30, 98, 21, 208, 94, 242, 194, 34, 185, 21, 176, 9, 148, 187, 30, 108, 21, 94, 23, 249, 178, 30, 98, 21, 72, 54, 15, 202, 30, 98, 0, 255, 255, 255, 255
            });
        }
コード例 #2
0
        static public ClientRequestInfo Decode(byte[] data)
        {
            var ps = new ClientRequestInfo();
            var i  = 0;

            var len = BitConverterBE.ToUInt16(data, i);

            i += 2;

            var magicBytes = data.Skip(i).Take(4).ToArray();

            if (magicBytes[0] != 0 || magicBytes[1] != 1 || magicBytes[2] != 3 || magicBytes[3] != 0)
            {
                return(null); // this shit aint tribes
            }
            i += 4;

            i += 3; // idk what this is

            while (true)
            {
                ps.Game1 += Encoding.ASCII.GetString(data, i, 1);
                i++;

                if (i >= data.Length)
                {
                    return(null); // no terminating nullbyte
                }

                if (data[i] == 0)
                {
                    i++;
                    break;
                }
            }

            while (true)
            {
                ps.Game2 += Encoding.ASCII.GetString(data, i, 1);
                i++;

                if (i >= data.Length)
                {
                    return(null); // no terminating nullbyte
                }

                if (data[i] == 0)
                {
                    i++;
                    break;
                }
            }

            while (true)
            {
                ps.Validate = ps.Validate.Concat(new byte[] { data[i] }).ToArray();
                i++;

                if (i >= data.Length)
                {
                    return(null); // no terminating nullbyte
                }

                if (data[i] == 0)
                {
                    i++;
                    break;
                }
            }

            while (true)
            {
                ps.Query += Encoding.ASCII.GetString(data, i, 1);
                i++;

                if (i >= data.Length)
                {
                    return(null); // no terminating nullbyte
                }

                if (data[i] == 0)
                {
                    i++;
                    break;
                }
            }

            return(ps);
        }