コード例 #1
0
 public MockNetworkHandler(NodeClient nodeClient)
 {
     _nodeClient = nodeClient;
 }
コード例 #2
0
        public void EmulateClient()
        {
            try
            {
                int threads;
                int iothreads;
                ThreadPool.GetAvailableThreads(out threads, out iothreads);

                Console.WriteLine("Client {0} connecting... Worker: {1}, IOC: {2}", Name, threads, iothreads);

                var client = new NodeClient(EndPoint, Name, _threadPool)
                {
                    ChunkRadius = ChunkRadius,
                    ClientId    = ClientId
                };

                client.StartClient();

                Stopwatch watch = new Stopwatch();
                watch.Start();

                //Thread.Sleep(3000);
                Console.WriteLine($"{watch.ElapsedMilliseconds} Client started, running... {client.IsRunning}, {Emulator.Running}");

                while (client.IsRunning && Emulator.Running && watch.Elapsed < TimeToRun)
                {
                    float y      = Random.Next(7, 10) + /*24*/ 55;
                    float length = Random.Next(5, 20);

                    double       angle          = 0.0;
                    const double angleStepsize  = 0.05;
                    float        heightStepsize = (float)(Random.NextDouble() / 5);

                    while (angle < 2 * Math.PI && Emulator.Running && client.IsRunning)
                    {
                        float x = (float)(length * Math.Cos(angle));
                        float z = (float)(length * Math.Sin(angle));
                        y += heightStepsize;

                        x += client.SpawnX;
                        z += client.SpawnZ;

                        client.CurrentLocation = new PlayerLocation(x, y, z);
                        _threadPool.QueueUserWorkItem(() => { client.SendMcpeMovePlayer(); });

                        Thread.Sleep(Random.Next(RanMin, RanMax));
                        angle += angleStepsize;
                    }
                }

                if (client.IsRunning)
                {
                    client.SendDisconnectionNotification();
                }

                client.StopClient();
                Console.WriteLine($"{watch.ElapsedMilliseconds} Client stopped. {client.IsRunning}, {Emulator.Running}");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }