public static Action <Task, string> DoSendCommand(MiNetClient client) { Action <Task, string> doUseItem = (t, command) => { McpeCommandStep commandStep = McpeCommandStep.CreateObject(); commandStep.commandName = "help"; commandStep.commandOverload = "byPage"; commandStep.unknown1 = 0; commandStep.currentStep = 0; commandStep.isOutput = false; commandStep.clientId = -1; //commandStep.commandJson = @"{}"; //commandStep.unkown6 = @"{}"; commandStep.commandInputJson = "null\n"; commandStep.commandOutputJson = "null\n"; commandStep.unknown7 = 0; commandStep.unknown8 = 0; commandStep.entityIdSelf = client.NetworkEntityId; Log.Error($"Entity ID used={client.EntityId}\n{Package.HexDump(commandStep.Encode())}"); client.SendPackage(commandStep); }; return(doUseItem); }
private static void Main(string[] args) { Console.WriteLine("Starting client..."); var client = new MiNetClient(new IPEndPoint(Dns.GetHostEntry("test.bladestorm.net").AddressList[0], 19132), "TheGrey"); //var client = new MiNetClient(new IPEndPoint(IPAddress.Parse("83.249.65.92"), 19132), "TheGrey"); //var client = new MiNetClient(new IPEndPoint(IPAddress.Loopback, 19132), "TheGrey"); client.StartClient(); Console.WriteLine("Server started."); //while (!client.HaveServer) //{ // Thread.Sleep(500); // Console.WriteLine("Sending ping..."); // client.SendUnconnectedPing(); //} Console.WriteLine("<Enter> to connect!"); Console.ReadLine(); client.HaveServer = true; client.SendOpenConnectionRequest1(); Console.WriteLine("<Enter> to exit!"); Console.ReadLine(); client.StopClient(); }
private static void Main(string[] args) { Console.WriteLine("Starting client..."); //var client = new MiNetClient(new IPEndPoint(Dns.GetHostEntry("test.bladestorm.net").AddressList[0], 19132), "TheGrey"); var client = new MiNetClient(new IPEndPoint(IPAddress.Parse("192.168.0.9"), 19132), "TheGrey"); //var client = new MiNetClient(new IPEndPoint(IPAddress.Parse("83.249.65.92"), 19132), "TheGrey"); //var client = new MiNetClient(new IPEndPoint(IPAddress.Loopback, 19132), "TheGrey"); client.StartClient(); Console.WriteLine("Server started."); //while (!client.HaveServer) //{ // Thread.Sleep(500); // Console.WriteLine("Sending ping..."); // client.SendUnconnectedPing(); //} Console.WriteLine("<Enter> to connect!"); Console.ReadLine(); client.HaveServer = true; client.SendOpenConnectionRequest1(); Console.WriteLine("<Enter> to exit!"); Console.ReadLine(); client.StopClient(); }
protected override void OnClose(CloseEventArgs e) { base.OnClose(e); Client?.SendDisconnectionNotification(); Client?.StopClient(); Client = null; }
public static Action <Task, string> DoSendCommand(MiNetClient client) { Action <Task, string> doUseItem = (t, command) => { McpeCommandRequest commandStep = McpeCommandRequest.CreateObject(); commandStep.commandName = "fill"; commandStep.commandOverload = "replace"; commandStep.unknown1 = 0; commandStep.currentStep = 0; commandStep.isOutput = false; commandStep.clientId = client.ClientId; //commandStep.commandInputJson = "{\n \"tileName\" : \"dirt\",\n \"from\" : {\n \"x\" : 0,\n \"xrelative\" : false,\n \"y\" : 10,\n \"yrelative\" : false,\n \"z\" : 0,\n \"zrelative\" : false\n },\n \"to\" : {\n \"x\" : 10,\n \"xrelative\" : false,\n \"y\" : 10,\n \"yrelative\" : false,\n \"z\" : 10,\n \"zrelative\" : false\n }\n}\n"; commandStep.commandInputJson = "{\n \"from\" : {\n \"x\" : 0,\n \"xrelative\" : false,\n \"y\" : 10,\n \"yrelative\" : false,\n \"z\" : 0,\n \"zrelative\" : false\n },\n \"tileName\" : \"dirt\",\n \"to\" : {\n \"x\" : 10,\n \"xrelative\" : false,\n \"y\" : 10,\n \"yrelative\" : false,\n \"z\" : 10,\n \"zrelative\" : false\n }\n}\n"; // "commandInputJson": "{\n \"from\" : {\n \"x\" : 0,\n \"xrelative\" : false,\n \"y\" : 10,\n \"yrelative\" : false,\n \"z\" : 0,\n \"zrelative\" : false\n },\n \"tileName\" : \"dirt\",\n \"to\" : {\n \"x\" : 10,\n \"xrelative\" : false,\n \"y\" : 10,\n \"yrelative\" : false,\n \"z\" : 10,\n \"zrelative\" : false\n }\n}\n", //commandStep.commandInputJson = "null\n"; commandStep.commandOutputJson = "null\n"; commandStep.unknown7 = 0; commandStep.unknown8 = 0; commandStep.entityIdSelf = client.NetworkEntityId; //Log.Error($"Entity ID used={commandStep.entityIdSelf}\n{Package.HexDump(commandStep.Encode())}"); client.SendPackage(commandStep); }; return(doUseItem); }
public static Action DoWaitForSpawn(MiNetClient client) { return(() => { while (!client.HasSpawned) { Thread.Sleep(50); } }); }
public static Action <Task, int, Item, int> DoContainerSetSlot(MiNetClient client) { Action <Task, int, Item, int> doMobEquipmentTask = (t, windowId, item, selectedSlot) => { McpeContainerSetSlot message = new McpeContainerSetSlot(); message.windowId = (byte)windowId; message.slot = selectedSlot; message.item = item; client.SendPackage(message); }; return(doMobEquipmentTask); }
public static Action <Task, Item, int> DoMobEquipment(MiNetClient client) { Action <Task, Item, int> doMobEquipmentTask = (t, item, selectedSlot) => { McpeMobEquipment message = new McpeMobEquipment(); message.runtimeEntityId = client.EntityId; message.item = item; message.selectedSlot = (byte)selectedSlot; message.slot = (byte)(selectedSlot + 9); client.SendPackage(message); }; return(doMobEquipmentTask); }
public static Action <Task, Item, BlockCoordinates> DoUseItem(MiNetClient client) { Action <Task, Item, BlockCoordinates> doUseItem = (t, item, coords) => { McpeUseItem message = new McpeUseItem(); message.blockcoordinates = coords /* - new BlockCoordinates(0, 1, 0)*/; message.face = 4; message.facecoordinates = new Vector3(0.1f, 0.1f, 0.1f); message.playerposition = client.CurrentLocation.ToVector3(); message.item = item; client.SendPackage(message); }; return(doUseItem); }
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; }
public static void Connect() { //var client = new MiNetRealClient(new IPEndPoint(IPAddress.Loopback, 19132)); var client = new MiNetClient(new IPEndPoint(IPAddress.Parse("192.168.0.2"), 19132)); client.StartServer(); Console.WriteLine("Server started."); Thread.Sleep(2000); Console.WriteLine("Sending ping..."); client.SendUnconnectedPing(); //client.SendUnconnectedPing(); //client.SendUnconnectedPing(); Console.WriteLine("<Enter> to exit!"); Console.ReadLine(); client.StopServer(); }
public static void Connect() { 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.Loopback, 19132)); //var client = new MiNetClient(new IPEndPoint(IPAddress.Parse("192.168.0.3"), 19132)); client.StartServer(); Console.WriteLine("Server started."); Thread.Sleep(2000); Console.WriteLine("Sending ping..."); client.SendUnconnectedPing(); //client.SendUnconnectedPing(); //client.SendUnconnectedPing(); Console.WriteLine("<Enter> to exit!"); Console.ReadLine(); client.StopServer(); }
private static void Main(string[] args) { Console.WriteLine("Starting client..."); var client = new MiNetClient(new IPEndPoint(Dns.GetHostEntry("test.inpvp.net").AddressList[0], 19132), "TheGrey"); //var client = new MiNetClient(new IPEndPoint(IPAddress.Parse("192.168.0.3"), 19132), "TheGrey"); //var client = new MiNetClient(new IPEndPoint(IPAddress.Loopback, 19132), "TheGrey"); client.StartClient(); Console.WriteLine("Server started."); Thread.Sleep(2000); Console.WriteLine("Sending ping..."); client.SendUnconnectedPing(); Console.WriteLine("<Enter> to exit!"); Console.ReadLine(); client.StopClient(); }
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(); }
public static Action <Task, PlayerLocation> DoMoveTo(MiNetClient client) { Action <Task, PlayerLocation> doMoveTo = (t, loc) => { Vector3 originalPosition = client.CurrentLocation.ToVector3(); Vector3 targetPosition = loc.ToVector3(); PlayerLocation lookAtPos = LookAt(originalPosition + new Vector3(0, 1.62f, 0), targetPosition); { // First just rotate towards target pos McpeMovePlayer movePlayerPacket = McpeMovePlayer.CreateObject(); movePlayerPacket.runtimeEntityId = client.EntityId; movePlayerPacket.x = client.CurrentLocation.X; movePlayerPacket.y = client.CurrentLocation.Y; movePlayerPacket.z = client.CurrentLocation.Z; movePlayerPacket.yaw = lookAtPos.Yaw; movePlayerPacket.pitch = lookAtPos.Pitch; movePlayerPacket.headYaw = lookAtPos.HeadYaw; } float lenght = Math.Abs((originalPosition - targetPosition).Length()); float stepLen = 0.5f; float weight; while (true) { if (Math.Abs((targetPosition - client.CurrentLocation.ToVector3()).Length()) > stepLen) { float lenLeft = Math.Abs((client.CurrentLocation.ToVector3() - targetPosition).Length()); weight = Math.Abs((float)((lenLeft - stepLen) / lenght)); client.CurrentLocation = new PlayerLocation(Vector3.Lerp(originalPosition, targetPosition, 1 - weight)); McpeMovePlayer movePlayerPacket = McpeMovePlayer.CreateObject(); movePlayerPacket.runtimeEntityId = client.EntityId; movePlayerPacket.x = client.CurrentLocation.X; movePlayerPacket.y = client.CurrentLocation.Y; movePlayerPacket.z = client.CurrentLocation.Z; movePlayerPacket.yaw = lookAtPos.Yaw; movePlayerPacket.pitch = lookAtPos.Pitch; movePlayerPacket.headYaw = lookAtPos.HeadYaw; client.SendPackage(movePlayerPacket); Thread.Sleep(50); continue; } { client.CurrentLocation = new PlayerLocation(targetPosition); McpeMovePlayer movePlayerPacket = McpeMovePlayer.CreateObject(); movePlayerPacket.runtimeEntityId = client.EntityId; movePlayerPacket.x = client.CurrentLocation.X; movePlayerPacket.y = client.CurrentLocation.Y; movePlayerPacket.z = client.CurrentLocation.Z; movePlayerPacket.yaw = lookAtPos.Yaw; movePlayerPacket.pitch = lookAtPos.Pitch; movePlayerPacket.headYaw = lookAtPos.HeadYaw; client.SendPackage(movePlayerPacket); } break; } }; return(doMoveTo); }
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(); }
public DefaultMessageHandler(MiNetClient client) : base(client) { }
public McpeClientMessageHandlerBase(MiNetClient client) { Client = client; }
public BedrockTraceHandler(MiNetClient client) : base(client) { }