Пример #1
0
        public void Initialize()
        {
            using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
            {
                socket.Bind(new IPEndPoint(IPAddress.Any, 19132));

                var startInfo = new ProcessStartInfo(@"C:\Development\Other\bedrock-server-1.14.1.4\bedrock_server.exe");
                startInfo.CreateNoWindow  = false;
                startInfo.WindowStyle     = ProcessWindowStyle.Normal;
                startInfo.UseShellExecute = false;

                _bedrock = Process.Start(startInfo);
                _client  = new MiNetClient(new IPEndPoint(IPAddress.Parse("192.168.0.4"), 19162), "TheGrey", new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));
                _client.MessageHandler = new ChunkGeneratorHandler(_client);
                _client.StartClient();

                if (_client.ServerEndPoint != null)
                {
                    while (!_client.FoundServer)
                    {
                        _client.SendUnconnectedPing();
                        Thread.Sleep(100);
                    }
                }
            }

            Log.Info("Found server, waiting for spawn");


            Task.Run(BotHelpers.DoWaitForSpawn(_client)).Wait();
            Log.Info("Spawned on bedrock server");
        }
Пример #2
0
        private static void SendCommand(MiNetClient client, string command)
        {
            var request = new McpeCommandRequest();

            request.command     = command;
            request.unknownUuid = new UUID(Guid.NewGuid().ToString());
            client.SendPacket(request);
        }
Пример #3
0
        public void Initialize(IWorldProvider worldProvider)
        {
            Process blocker;

            {
                // Block port!
                var startInfo = new ProcessStartInfo("MiNET.Console.exe", "listener");
                startInfo.CreateNoWindow  = false;
                startInfo.WindowStyle     = ProcessWindowStyle.Normal;
                startInfo.UseShellExecute = false;
                blocker = Process.Start(startInfo);
            }
            {
                var startInfo = new ProcessStartInfo(Path.Combine(Config.GetProperty("BDSPath", null), Config.GetProperty("BDSExe", null)));
                startInfo.WorkingDirectory      = Config.GetProperty("BDSPath", null);
                startInfo.CreateNoWindow        = false;
                startInfo.WindowStyle           = ProcessWindowStyle.Normal;
                startInfo.UseShellExecute       = false;
                startInfo.RedirectStandardInput = true;

                _bedrock = Process.Start(startInfo);

                _client = new MiNetClient(new IPEndPoint(IPAddress.Parse("192.168.10.178"), 19162), "TheGrey", new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));
                _client.MessageHandler = new ChunkGeneratorHandler(_client, worldProvider);
                //_client.UseBlobCache = true;
                _client.StartClient();

                if (_client.ServerEndPoint != null)
                {
                    while (!_client.FoundServer)
                    {
                        _client.SendUnconnectedPing();
                        Thread.Sleep(100);
                    }
                }
            }

            Log.Info("Found server, waiting for spawn");


            Task.Run(BotHelpers.DoWaitForSpawn(_client)).Wait();
            Log.Info("Spawned on bedrock server");

            blocker?.Kill();             // no need to block further once we have spawned our bot.

            // Shutdown hook. Must use to flush in memory log of LevelDB.
            AppDomain.CurrentDomain.ProcessExit += (sender, args) =>
            {
                Log.Warn("Closing bedrock dedicated server (BDS)");
                _bedrock.StandardInput.WriteLine("stop");
                _bedrock.WaitForExit(1000);
                _bedrock.Kill();
            };
        }
Пример #4
0
        public void GenerateBlockstates(string ip, int port, string username)
        {
            if (!IPAddress.TryParse(ip, out IPAddress address))
            {
                address = Dns.GetHostAddresses(ip).FirstOrDefault();
            }

            var endpoint = new IPEndPoint(address, port);

            var client  = new MiNetClient(endpoint, username, new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));
            var scraper = new DataScraperTraceHandler(client);

            client.MessageDispatcher = new McpeClientMessageDispatcher(scraper);

            client.StartClient();
            client.SendOpenConnectionRequest1();

            while (!scraper.Finished)
            {
                // waiting for data...
            }
        }
Пример #5
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 MiNetClient(EndPoint, Name, _threadPool);
                client.ChunkRadius = ChunkRadius;
                client.IsEmulator = true;
                client.ClientId = ClientId;

                client.StartClient();
                Console.WriteLine("Client started.");

                client.HaveServer = true;
                client.SendOpenConnectionRequest1();

                //client.FirstPacketWaitHandle.WaitOne();
                //client.FirstEncryptedPacketWaitHandle.WaitOne();
                client.PlayerStatusChangedWaitHandle.WaitOne();

                if (client.UdpClient != null) Console.WriteLine("\t\t\t\t\t\tClient {0} connected, emulating...", Name);

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

                Thread.Sleep(3000);

                //client.SendChat("/join bb");
                //client.SendChat("/join skywars");

                //Thread.Sleep(TimeToRun);

                //if (client.CurrentLocation != null)
                //{
                //	client.CurrentLocation = new PlayerLocation(client.CurrentLocation.X, -10, client.CurrentLocation.Z);
                //	client.SendMcpeMovePlayer();
                //	Thread.Sleep(3000);
                //}

                //client.SendChat("/hub");

                //Thread.Sleep(3000);

                for (int i = 0; /*i < 10 && */Emulator.Running && watch.Elapsed < TimeToRun; i++)
                {
                    if (client.UdpClient == null) break;

                    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)
                    {
                        if (client.UdpClient == null) break;

                        float x = (float) (length*Math.Cos(angle));
                        float z = (float) (length*Math.Sin(angle));
                        y += heightStepsize;

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

                        client.CurrentLocation = new PlayerLocation(x, y, z);
                        client.SendMcpeMovePlayer();
                        Thread.Sleep(Random.Next(RanMin, RanMax));
                        angle += angleStepsize;
                    }
                }

                if (client.UdpClient != null)
                {
                    //client.SendChat("Shadow gov agent BREXITING!");
                    client.SendDisconnectionNotification();
                }

                client.StopClient();
                Console.WriteLine($"{watch.ElapsedMilliseconds} Client stopped. {client.UdpClient == null}, {Emulator.Running}");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Пример #6
0
 public ChunkGeneratorHandler(MiNetClient client) : base(client)
 {
 }
Пример #7
0
        public void EmulateClient()
        {
            try
            {
                Console.WriteLine("Client {0} connecting...", Name);

                //var client = new MiNetClient(new IPEndPoint(Dns.GetHostEntry("play.lbsg.net").AddressList[0], 19132), new IPEndPoint(IPAddress.Any, 0));
                //var client = new MiNetClient(new IPEndPoint(Dns.GetHostEntry("test.inpvp.net").AddressList[0], 19132), new IPEndPoint(IPAddress.Any, 0));
                //var client = new MiNetClient(new IPEndPoint(IPAddress.Parse("188.165.235.161"), 19132), new IPEndPoint(IPAddress.Any, 0));
                var client = new MiNetClient(new IPEndPoint(IPAddress.Loopback, 19132), new IPEndPoint(IPAddress.Loopback, 0));

                client.Username = Name;
                client.ClientId = ClientId;

                client.StartServer();
                Console.WriteLine("Client started.");

                Thread.Sleep(3000);

                client.SendUnconnectedPing();

                Thread.Sleep(2000);

                //client.LoginSent = true;

                Stopwatch watch = new Stopwatch();
                watch.Start();
                if (client.Listener != null) Console.WriteLine("\t\t\t\t\t\tClient {0} moving...", Name);

                for (int i = 0; i < 10 && Emulator.Running && watch.ElapsedMilliseconds < TimeToRun; i++)
                {
                    if (client.Listener == null) break;

                    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)
                    {
                        if (client.Listener == null) break;

                        float x = (float) (length*Math.Cos(angle));
                        float z = (float) (length*Math.Sin(angle));
                        y += heightStepsize;

                        x += -2562;
                        z += 743;

                        client.CurrentLocation = new PlayerLocation(x, y, z);
                        client.SendMcpeMovePlayer();
                        Thread.Sleep(Random.Next(150, 450));
                        angle += angleStepsize;
                    }
                }

                if (client.Listener != null) client.SendDisconnectionNotification();

                client.StopServer();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Пример #8
0
 public DataScraperTraceHandler(MiNetClient client) : base(client)
 {
 }
Пример #9
0
 public ChunkGeneratorHandler(MiNetClient client, IWorldProvider worldProvider) : base(client)
 {
     _worldProvider = worldProvider;
 }