Ejemplo n.º 1
0
        public void Connect(IPEndPoint endpoint, string username = "******")
        {
            var client = new MiNetClient(endpoint, username, new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));

            client.WS = this;
            client.StartClient();

            Task.Run(BotHelpers.DoWaitForSpawn(client))
            .ContinueWith(t => CommandResponse("Client spawned successfully"));

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

            Client = client;
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "log4net.xml")));

            Log.Info(MiNET);
            Console.WriteLine(MiNET);
            Console.WriteLine("Starting client...");

            var client = new MiNetClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 19132), "TheGrey");

            //var client = new MiNetClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 19132), "TheGrey");
            //var client = new MiNetClient(new IPEndPoint(Dns.GetHostEntry("test.pmmp.io").AddressList[0], 19132), "TheGrey", new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));
            //var client = new MiNetClient(new IPEndPoint(IPAddress.Parse("192.168.0.4"), 19162), "TheGrey", new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));
            //var client = new MiNetClient(new IPEndPoint(IPAddress.Parse("213.89.103.206"), 19132), "TheGrey", new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));
            //var client = new MiNetClient(new IPEndPoint(Dns.GetHostEntry("yodamine.com").AddressList[0], 19132), "TheGrey");
            //var client = new MiNetClient(new IPEndPoint(IPAddress.Loopback, 19132), "TheGrey", new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));

            client.MessageHandler = new BedrockTraceHandler(client);

            client.StartClient();
            Log.Warn("Client listening for connecting on: " + client.ClientEndpoint);

            Console.WriteLine("Looking for server...");

            if (!client.Connection.TryLocate(client.ServerEndPoint, out (IPEndPoint serverEndPoint, string serverName)info))
            {
                Console.WriteLine($"Failed to locate server at {client.ServerEndPoint}");
                return;
            }

            Console.WriteLine($"... YEAH! FOUND SERVER! It's at {info.serverEndPoint}, \"{info.serverName}\"");

            if (!client.Connection.TryConnect(info.serverEndPoint))
            {
                Console.WriteLine($"Failed to connect to server at {info.serverEndPoint}");
                return;
            }

            Console.WriteLine("Waiting for spawn...");
            client.PlayerStatusChangedWaitHandle.WaitOne();
            Console.WriteLine("... spawned");

            client.HasSpawned = true;

            Action <Task, PlayerLocation> doMoveTo = BotHelpers.DoMoveTo(client);

            Action <Task, string> doSendCommand = BotHelpers.DoSendCommand(client);

            Task.Run(BotHelpers.DoWaitForSpawn(client))
            .ContinueWith(t => doSendCommand(t, $"/me says \"I spawned at {client.CurrentLocation}\""))
            //.ContinueWith(task =>
            //{
            //	var request = new McpeCommandRequest();
            //	request.command = "/setblock ~ ~-1 ~ log 0 replace";
            //	request.unknownUuid = new UUID(Guid.NewGuid().ToString());
            //	client.SendPacket(request);

            //	var coord =  (BlockCoordinates) client.CurrentLocation;
            //	var pick = McpeBlockPickRequest.CreateObject();
            //	pick.x = coord.X;
            //	pick.y = coord.Y;
            //	pick.z = coord.Z;
            //	client.SendPacket(request);
            //})

            //.ContinueWith(t => BotHelpers.DoMobEquipment(client)(t, new ItemBlock(new Cobblestone(), 0) {Count = 64}, 0))
            //.ContinueWith(t => BotHelpers.DoMoveTo(client)(t, new PlayerLocation(client.CurrentLocation.ToVector3() - new Vector3(0, 1, 0), 180, 180, 180)))
            //.ContinueWith(t => doMoveTo(t, new PlayerLocation(40, 5.62f, -20, 180, 180, 180)))
            //.ContinueWith(t => doMoveTo(t, new PlayerLocation(0, 5.62, 0, 180 + 45, 180 + 45, 180)))
            //.ContinueWith(t => doMoveTo(t, new PlayerLocation(0, 5.62, 0, 180 + 45, 180 + 45, 180)))
            //.ContinueWith(t => doMoveTo(t, new PlayerLocation(22, 5.62, 40, 180 + 45, 180 + 45, 180)))
            //.ContinueWith(t => doMoveTo(t, new PlayerLocation(50, 5.62f, 17, 180, 180, 180)))
            .ContinueWith(t => doSendCommand(t, "/me says \"Hi guys! It is I!!\""))
            //.ContinueWith(t => Task.Delay(500).Wait())
            //.ContinueWith(t => doSendCommand(t, "/summon sheep"))
            //.ContinueWith(t => Task.Delay(500).Wait())
            //.ContinueWith(t => doSendCommand(t, "/kill @e[type=sheep]"))
            .ContinueWith(t => Task.Delay(5000).Wait())
            //.ContinueWith(t =>
            //{
            //	Random rnd = new Random();
            //	while (true)
            //	{
            //		doMoveTo(t, new PlayerLocation(rnd.Next(10, 40), 5.62f, rnd.Next(-50, -10), 180, 180, 180));
            //		//doMoveTo(t, new PlayerLocation(50, 5.62f, 17, 180, 180, 180));
            //		doMoveTo(t, new PlayerLocation(rnd.Next(40, 50), 5.62f, rnd.Next(0, 20), 180, 180, 180));
            //	}
            //})
            ;

            //string fileName = Path.GetTempPath() + "MobSpawns_" + Guid.NewGuid() + ".txt";
            //FileStream file = File.OpenWrite(fileName);
            //Log.Info($"Writing mob spawns to file:\n{fileName}");
            //_mobWriter = new IndentedTextWriter(new StreamWriter(file));
            //Task.Run(BotHelpers.DoWaitForSpawn(client))
            //	.ContinueWith(task =>
            //	{
            //		foreach (EntityType entityType in Enum.GetValues(typeof(EntityType)))
            //		{
            //			if (entityType == EntityType.Wither) continue;
            //			if (entityType == EntityType.Dragon) continue;
            //			if (entityType == EntityType.Slime) continue;

            //			string entityName = entityType.ToString();
            //			entityName = Regex.Replace(entityName, "([A-Z])", "_$1").TrimStart('_').ToLower();
            //			{
            //				string command = $"/summon {entityName}";
            //				McpeCommandRequest request = new McpeCommandRequest();
            //				request.command = command;
            //				request.unknownUuid = new UUID(Guid.NewGuid().ToString());
            //				client.SendPackage(request);
            //			}

            //			Task.Delay(500).Wait();

            //			{
            //				McpeCommandRequest request = new McpeCommandRequest();
            //				request.command = $"/kill @e[type={entityName}]";
            //				request.unknownUuid = new UUID(Guid.NewGuid().ToString());
            //				client.SendPackage(request);
            //			}
            //		}

            //		{
            //			McpeCommandRequest request = new McpeCommandRequest();
            //			request.command = $"/kill @e[type=!player]";
            //			request.unknownUuid = new UUID(Guid.NewGuid().ToString());
            //			client.SendPackage(request);
            //		}

            //	});

            Console.WriteLine("<Enter> to exit!");
            Console.ReadLine();
            if (client.IsConnected)
            {
                client.SendDisconnectionNotification();
            }
            Thread.Sleep(50);
            client.StopClient();
        }
Ejemplo n.º 3
0
        public override void HandleMcpeAddEntity(McpeAddEntity message)
        {
            if (Client.IsEmulator)
            {
                return;
            }

            if (!Client.Entities.ContainsKey(message.entityIdSelf))
            {
                var entity = new Entity(message.entityType, null);
                entity.EntityId      = message.runtimeEntityId;
                entity.KnownPosition = new PlayerLocation(message.x, message.y, message.z, message.yaw, message.yaw, message.pitch);
                entity.Velocity      = new Vector3(message.speedX, message.speedY, message.speedZ);
                Client.Entities.TryAdd(entity.EntityId, entity);
            }

            Log.DebugFormat("McpeAddEntity Entity ID: {0}", message.entityIdSelf);
            Log.DebugFormat("McpeAddEntity Runtime Entity ID: {0}", message.runtimeEntityId);
            Log.DebugFormat("Entity Type: {0}", message.entityType);
            Log.DebugFormat("X: {0}", message.x);
            Log.DebugFormat("Y: {0}", message.y);
            Log.DebugFormat("Z: {0}", message.z);
            Log.DebugFormat("Yaw: {0}", message.yaw);
            Log.DebugFormat("Pitch: {0}", message.pitch);
            Log.DebugFormat("Velocity X: {0}", message.speedX);
            Log.DebugFormat("Velocity Y: {0}", message.speedY);
            Log.DebugFormat("Velocity Z: {0}", message.speedZ);
            Log.DebugFormat("Metadata: {0}", Client.MetadataToCode(message.metadata));
            Log.DebugFormat("Links count: {0}", message.links?.Count);

            if (message.metadata.Contains(0))
            {
                long?value = ((MetadataLong)message.metadata[0])?.Value;
                if (value != null)
                {
                    long dataValue = (long)value;
                    Log.Debug($"Bit-array datavalue: dec={dataValue} hex=0x{dataValue:x2}, bin={Convert.ToString(dataValue, 2)}b ");
                }
            }

            if (Log.IsDebugEnabled)
            {
                foreach (var attribute in message.attributes)
                {
                    Log.Debug($"Entity attribute {attribute}");
                }
            }

            Log.DebugFormat("Links count: {0}", message.links);

            if (Log.IsDebugEnabled && Client._mobWriter != null)
            {
                Client._mobWriter.WriteLine("Entity Type: {0}", message.entityType);
                Client._mobWriter.Indent++;
                Client._mobWriter.WriteLine("Metadata: {0}", Client.MetadataToCode(message.metadata));
                Client._mobWriter.Indent--;
                Client._mobWriter.WriteLine();
                Client._mobWriter.Flush();
            }

            if (message.entityType == "minecraft:horse")
            {
                var     id  = message.runtimeEntityId;
                Vector3 pos = new Vector3(message.x, message.y, message.z);
                Task.Run(BotHelpers.DoWaitForSpawn(Client))
                .ContinueWith(t => Task.Delay(3000).Wait())
                //.ContinueWith(task =>
                //{
                //	Log.Warn("Sending jump for player");

                //	McpeInteract action = McpeInteract.CreateObject();
                //	action.targetRuntimeEntityId = id;
                //	action.actionId = (int) 3;
                //	SendPackage(action);
                //})
                //.ContinueWith(t => Task.Delay(2000).Wait())
                //.ContinueWith(task =>
                //{
                //	for (int i = 0; i < 10; i++)
                //	{
                //		Log.Warn("Mounting horse");

                //		McpeInventoryTransaction transaction = McpeInventoryTransaction.CreateObject();
                //		transaction.transaction = new Transaction()
                //		{
                //			TransactionType = McpeInventoryTransaction.TransactionType.ItemUseOnEntity,
                //			TransactionRecords = new List<TransactionRecord>(),
                //			EntityId = id,
                //			ActionType = 0,
                //			Slot = 0,
                //			Item = new ItemAir(),
                //			//Item = new ItemBlock(new Cobblestone()) { Count = 64 },
                //			Position = BlockCoordinates.Zero,
                //			FromPosition = CurrentLocation,
                //			ClickPosition = pos,
                //		};

                //		SendPackage(transaction);
                //		Thread.Sleep(4000);
                //	}

                //})
                .ContinueWith(task =>
                {
                    Log.Warn("Sending sneak for player");

                    McpePlayerAction action = McpePlayerAction.CreateObject();
                    action.runtimeEntityId  = Client.EntityId;
                    action.actionId         = (int)PlayerAction.StartSneak;
                    Client.SendPacket(action);
                })
                .ContinueWith(t => Task.Delay(2000).Wait())
                .ContinueWith(task =>
                {
                    Log.Warn("Sending transaction for horse");

                    var transaction         = McpeInventoryTransaction.CreateObject();
                    transaction.transaction = new ItemUseOnEntityTransaction()
                    {
                        TransactionRecords = new List <TransactionRecord>(),
                        EntityId           = id,
                        ActionType         = 0,
                        Slot          = 0,
                        Item          = new ItemAir(),
                        FromPosition  = Client.CurrentLocation,
                        ClickPosition = pos,
                    };

                    Client.SendPacket(transaction);
                });
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "log4net.xml")));

            Log.Info(MiNET);
            Console.WriteLine(MiNET);
            Console.WriteLine("Starting client...");

            var client = new MiNetClient(new IPEndPoint(Dns.GetHostEntry("yodamine.com").AddressList[0], 19132), "TheGrey", new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));

            //var client = new MiNetClient(new IPEndPoint(IPAddress.Loopback, 19132), "TheGrey", new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));

            client.StartClient();
            Log.Warn("Client listening for connecting on: " + client.ClientEndpoint);
            Console.WriteLine("Started!");

            //client.SendOpenConnectionRequest1();

            Console.WriteLine("Looking for server...");
            if (client.ServerEndpoint != null)
            {
                while (!client.HaveServer)
                {
                    Console.WriteLine("... still looking ...");
                    client.SendUnconnectedPing();
                    Thread.Sleep(500);
                }
            }

            Console.WriteLine($"... YEAH! FOUND SERVER! It's at {client.ServerEndpoint?.Address}, port {client.ServerEndpoint?.Port}");

            Action <Task, PlayerLocation> doMoveTo      = BotHelpers.DoMoveTo(client);
            Action <Task, string>         doSendCommand = BotHelpers.DoSendCommand(client);

            Task.Run(BotHelpers.DoWaitForSpawn(client))
            .ContinueWith(t => doSendCommand(t, $"/me says \"I spawned at {client.CurrentLocation}\""))
            //.ContinueWith(t => BotHelpers.DoMobEquipment(client)(t, new ItemBlock(new Cobblestone(), 0) {Count = 64}, 0))
            //.ContinueWith(t => BotHelpers.DoMoveTo(client)(t, new PlayerLocation(client.CurrentLocation.ToVector3() - new Vector3(0, 1, 0), 180, 180, 180)))
            //.ContinueWith(t => doMoveTo(t, new PlayerLocation(40, 5.62f, -20, 180, 180, 180)))
            .ContinueWith(t => doMoveTo(t, new PlayerLocation(0, 5.62, 0, 180 + 45, 180 + 45, 180)))
            //.ContinueWith(t => doMoveTo(t, new PlayerLocation(0, 5.62, 0, 180 + 45, 180 + 45, 180)))
            //.ContinueWith(t => doMoveTo(t, new PlayerLocation(22, 5.62, 40, 180 + 45, 180 + 45, 180)))
            //.ContinueWith(t => doMoveTo(t, new PlayerLocation(50, 5.62f, 17, 180, 180, 180)))
            .ContinueWith(t => doSendCommand(t, "/me says \"Hi guys! It is I!!\""))
            //.ContinueWith(t => Task.Delay(500).Wait())
            //.ContinueWith(t => doSendCommand(t, "/summon sheep"))
            //.ContinueWith(t => Task.Delay(500).Wait())
            //.ContinueWith(t => doSendCommand(t, "/kill @e[type=sheep]"))
            .ContinueWith(t => Task.Delay(5000).Wait())
            //.ContinueWith(t =>
            //{
            //	Random rnd = new Random();
            //	while (true)
            //	{
            //		doMoveTo(t, new PlayerLocation(rnd.Next(10, 40), 5.62f, rnd.Next(-50, -10), 180, 180, 180));
            //		//doMoveTo(t, new PlayerLocation(50, 5.62f, 17, 180, 180, 180));
            //		doMoveTo(t, new PlayerLocation(rnd.Next(40, 50), 5.62f, rnd.Next(0, 20), 180, 180, 180));
            //	}
            //})
            ;

            //string fileName = Path.GetTempPath() + "MobSpawns_" + Guid.NewGuid() + ".txt";
            //FileStream file = File.OpenWrite(fileName);
            //Log.Info($"Writing mob spawns to file:\n{fileName}");
            //_mobWriter = new IndentedTextWriter(new StreamWriter(file));
            //Task.Run(BotHelpers.DoWaitForSpawn(client))
            //	.ContinueWith(task =>
            //	{
            //		foreach (EntityType entityType in Enum.GetValues(typeof(EntityType)))
            //		{
            //			if (entityType == EntityType.Wither) continue;
            //			if (entityType == EntityType.Dragon) continue;
            //			if (entityType == EntityType.Slime) continue;

            //			string entityName = entityType.ToString();
            //			entityName = Regex.Replace(entityName, "([A-Z])", "_$1").TrimStart('_').ToLower();
            //			{
            //				string command = $"/summon {entityName}";
            //				McpeCommandRequest request = new McpeCommandRequest();
            //				request.command = command;
            //				request.unknownUuid = new UUID(Guid.NewGuid().ToString());
            //				client.SendPackage(request);
            //			}

            //			Task.Delay(500).Wait();

            //			{
            //				McpeCommandRequest request = new McpeCommandRequest();
            //				request.command = $"/kill @e[type={entityName}]";
            //				request.unknownUuid = new UUID(Guid.NewGuid().ToString());
            //				client.SendPackage(request);
            //			}
            //		}

            //		{
            //			McpeCommandRequest request = new McpeCommandRequest();
            //			request.command = $"/kill @e[type=!player]";
            //			request.unknownUuid = new UUID(Guid.NewGuid().ToString());
            //			client.SendPackage(request);
            //		}

            //	});

            Console.WriteLine("<Enter> to exit!");
            Console.ReadLine();
            client.SendDisconnectionNotification();
            Thread.Sleep(2000);
            client.StopClient();
        }