dnuhax

Untitled

Mar 27th, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. package protocolconnect;
  2.  
  3. import java.net.InetSocketAddress;
  4. import java.util.Collections;
  5.  
  6. import com.nukkitx.protocol.bedrock.BedrockClient;
  7. import com.nukkitx.protocol.bedrock.packet.LoginPacket;
  8. import com.nukkitx.protocol.bedrock.v389.Bedrock_v389;
  9.  
  10. import io.netty.util.AsciiString;
  11. import io.netty.util.internal.ThreadLocalRandom;
  12. import wode.PacketHandler;
  13. import wode.ProfileHelper;
  14.  
  15. public class Connector {
  16. public static void connect(String displayname,String ip,int port) {
  17. InetSocketAddress bindAddress = new InetSocketAddress("0.0.0.0", ThreadLocalRandom.current().nextInt(10000 - 1025) + 1025);
  18. BedrockClient client = new BedrockClient(bindAddress);
  19. client.bind().join();
  20. InetSocketAddress addressToConnect = new InetSocketAddress(ip, port);
  21. client.connect(addressToConnect).whenComplete((session, throwable) -> {
  22. if (throwable != null) {
  23. // Unable to establish connection
  24. return;
  25. }
  26. // Connection established
  27. // Make sure to set the packet codec version you wish to use before sending out packets
  28. session.setPacketCodec(Bedrock_v389.V389_CODEC);
  29. // Add disconnect handler
  30. session.setPacketHandler(new PacketHandler(session));
  31. // Now send packets...
  32. LoginPacket login = new LoginPacket();
  33. login.setProtocolVersion(389);
  34. AsciiString[] auth = ProfileHelper.randomAuthData(displayname, ip, port);
  35. login.setChainData(new AsciiString(auth[0]));
  36. login.setSkinData(new AsciiString(auth[1]));
  37. session.setLogging(true);
  38. //session.sendPacket(login);
  39. session.sendWrapped(Collections.singleton(login), false);
  40. }).join(); // Join if you do not want this to be handled asynchronously.
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment