Inheritance: EndianBitConverter
Ejemplo n.º 1
0
        public AgarClient(DefaultPacketManager pm)
        {
            world = new AgarWorld();
            bc = new LittleEndianBitConverter();
            wait_useraction = new AutoResetEvent(false);

            pacman = pm;

            userActions_l = new object();
            userActions = new Queue<AgarPacket>();
        }
 public DatabaseBinaryWriter(LittleEndianBitConverter bitConverter, Stream stream)
     : base(bitConverter, stream)
 {
 }
 public CtfBinaryWriter(LittleEndianBitConverter bitConverter, System.IO.Stream stream)
     : base(bitConverter, stream)
 {
 }
Ejemplo n.º 4
0
 public JpkBinaryReader(LittleEndianBitConverter bitConverter, System.IO.Stream stream)
     : base(bitConverter, stream)
 {
 }
Ejemplo n.º 5
0
        public DefaultPacketManager()
        {
            this_lock = new object();

            websock = new ClientWebSocket();

            bc = new LittleEndianBitConverter();

            in_packets_l = new object();
            in_packets = new Queue<AgarPacket>();
            packet_received = new AutoResetEvent(false);

            out_packets_l = new object();
            out_packets = new Queue<AgarPacket>();
            packet_sent = new AutoResetEvent(false);

            hasStarted = false;
        }
Ejemplo n.º 6
0
        private void Work(object arg)
        {
            CalculationOptions opt = arg as CalculationOptions;
            NetworkStream ns = null;
            Success = false;
            try
            {
                ns = TcpHelper.OpenStream(Host, 1);

                byte[] magic = new byte[4];
                ns.Read(magic, 0, 4);
                uint v = BitConverter.ToUInt32(magic, 0);

                bool be = (v == 0xAFDE0000); // Renderer sends 00 00 DE AF, if its reversed all is in big endian

                EndianBitConverter ec;
                if (be) ec = new BigEndianBitConverter();
                else ec = new LittleEndianBitConverter();

                using (EndianBinaryWriter bw = new EndianBinaryWriter(ec, ns))
                using (EndianBinaryReader br = new EndianBinaryReader(ec, ns))
                {
                    bw.Write((uint)0x0000FEED);

                    // Write rational coordinates
                    foreach (BigRational r in new[] { opt.MinRe, opt.MaxRe, opt.MinIm, opt.MaxIm })
                    {
                        int sign = r.Numerator.Sign;
                        byte[] num = BigInteger.Abs(r.Numerator).ToByteArray();
                        bw.Write(sign);
                        bw.Write(num.Length);
                        bw.Write(num);

                        num = BigInteger.Abs(r.Denominator).ToByteArray();
                        bw.Write(num.Length);
                        bw.Write(num);
                    }
                    bw.Write(opt.IterationCount);
                    bw.Write(opt.Width);
                    bw.Write(opt.Height);
                    bw.Write(opt.XOff);
                    bw.Write(opt.XSkip);
                    bw.Write(opt.XMax);
                    bw.Write(opt.YOff);
                    bw.Write(opt.YSkip);
                    bw.Write(opt.YMax);
                    bw.Write(opt.OrbitStart);
                    bw.Write(opt.OrbitLength);
                    bw.Write(opt.BulbChecking ? 1U : 0U);

                    int ok = br.ReadInt32();
                    if (ok != 200)
                        throw new InvalidOperationException();  // TODO Proper exception

                    // Sent parameters, now read all orbits
                    OrbitMap map = new OrbitMap();

                    int orbitsComing = 0;
                    while ((orbitsComing = br.ReadInt32()) >= 0)
                    {
                        for (int i = 0; i < orbitsComing; i++)
                        {
                            int o_x = br.ReadInt32();
                            int o_y = br.ReadInt32();

                            BigRational re, im;
                            re = ReadRational(br);
                            im = ReadRational(br);
                            BigComplex o_c = new BigComplex(re, im);

                            uint o_iter = br.ReadUInt32(); // Number of iterations before escape
                            uint o_orbs = br.ReadUInt32(); // Offset of the orbit
                            uint o_orbl = br.ReadUInt32(); // Length of the orbit

                            Orbit orbit = new Orbit(o_x, o_y, o_c, o_iter, o_orbs, o_orbl);

                            for (uint j = 0; j < o_orbl; j++)
                            {
                                re = ReadRational(br);
                                im = ReadRational(br);
                                orbit.Add(re, im);
                            }

                            map.AddOrbit(orbit);
                        }
                    }

                    Result = map; // Set the result so it can be combined with work from the other threads
                }

                ns.Close();
                Success = true;
            }
            catch (Exception) // TODO error handling ? Just log the message and be done
            {
                Success = false;
            }
            finally
            {
                if (ns != null)
                    ns.Close();

                (WaitHandle as ManualResetEvent).Set(); // Public signal that I'm done
            }
        }