Fix LAN world support
This commit is contained in:
@@ -25,6 +25,7 @@ import baritone.bot.spec.BotMinecraft;
|
||||
import baritone.bot.spec.BotWorld;
|
||||
import baritone.bot.spec.EntityBot;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||
import net.minecraft.util.Session;
|
||||
@@ -51,8 +52,9 @@ public class BaritoneUser implements IBaritoneUser {
|
||||
|
||||
private final Baritone baritone;
|
||||
|
||||
BaritoneUser(UserManager manager, NetworkManager networkManager, Session session) {
|
||||
BaritoneUser(UserManager manager, NetworkManager networkManager, Session session, ServerData serverData) {
|
||||
this.mc = BotMinecraft.allocate(this);
|
||||
this.mc.setServerData(serverData);
|
||||
this.manager = manager;
|
||||
this.networkManager = networkManager;
|
||||
this.session = session;
|
||||
|
||||
@@ -93,6 +93,7 @@ public final class UserManager implements IUserManager, Helper {
|
||||
public final IConnectionResult connect(Session session) {
|
||||
if (mc.getIntegratedServer() != null && mc.getIntegratedServer().getPublic()) {
|
||||
try {
|
||||
// TODO: (bot-system) Fix compatibility in production
|
||||
Field fLanServerPing = IntegratedServer.class.getDeclaredField("lanServerPing");
|
||||
fLanServerPing.setAccessible(true);
|
||||
ThreadLanServerPing lanServerPing = (ThreadLanServerPing) fLanServerPing.get(mc.getIntegratedServer());
|
||||
@@ -102,7 +103,7 @@ public final class UserManager implements IUserManager, Helper {
|
||||
int port = Integer.parseInt(fAddress.get(lanServerPing).toString());
|
||||
|
||||
// Connect to the server from the parsed server data
|
||||
return connect0(session, ServerAddress.fromString("localhost:" + port));
|
||||
return connect0(session, new ServerData("", "localhost:" + port, true));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ConnectionResult.failed(CANT_RESOLVE_HOST);
|
||||
@@ -115,7 +116,7 @@ public final class UserManager implements IUserManager, Helper {
|
||||
}
|
||||
|
||||
// Connect to the server from the parsed server data
|
||||
return connect0(session, ServerAddress.fromString(data.serverIP));
|
||||
return connect0(session, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,10 +125,11 @@ public final class UserManager implements IUserManager, Helper {
|
||||
* Hi Mickey :)
|
||||
*
|
||||
* @param session The user session
|
||||
* @param address The address of the server to connect to
|
||||
* @param data The address of the server to connect to
|
||||
* @return The result of the attempted connection
|
||||
*/
|
||||
private IConnectionResult connect0(Session session, ServerAddress address) {
|
||||
private IConnectionResult connect0(Session session, ServerData data) {
|
||||
ServerAddress address = ServerAddress.fromString(data.serverIP);
|
||||
InetAddress inetAddress;
|
||||
|
||||
try {
|
||||
@@ -145,7 +147,7 @@ public final class UserManager implements IUserManager, Helper {
|
||||
);
|
||||
|
||||
// Create User
|
||||
BaritoneUser user = new BaritoneUser(this, networkManager, session);
|
||||
BaritoneUser user = new BaritoneUser(this, networkManager, session, data);
|
||||
this.users.add(user);
|
||||
|
||||
// Setup login handler and send connection packets
|
||||
|
||||
@@ -18,25 +18,14 @@
|
||||
package baritone.bot.handler;
|
||||
|
||||
import baritone.bot.BaritoneUser;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.exceptions.AuthenticationException;
|
||||
import com.mojang.authlib.exceptions.AuthenticationUnavailableException;
|
||||
import com.mojang.authlib.exceptions.InvalidCredentialsException;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.network.NetHandlerLoginClient;
|
||||
import net.minecraft.network.EnumConnectionState;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.login.client.CPacketEncryptionResponse;
|
||||
import net.minecraft.network.login.server.SPacketEncryptionRequest;
|
||||
import net.minecraft.network.login.server.SPacketLoginSuccess;
|
||||
import net.minecraft.util.CryptManager;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.crypto.SecretKey;
|
||||
import java.math.BigInteger;
|
||||
import java.security.PublicKey;
|
||||
|
||||
/**
|
||||
* Handles the login stage when connecting to a server.
|
||||
|
||||
@@ -54,12 +54,6 @@ public final class BotMinecraft extends Minecraft implements Helper {
|
||||
return this.user.getSession();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ServerData getCurrentServerData() {
|
||||
return mc.getCurrentServerData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftSessionService getSessionService() {
|
||||
return mc.getSessionService();
|
||||
|
||||
Reference in New Issue
Block a user