Fix connection to vanilla servers. Generate a default mod server config
for mods connecting to servers. Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
parent
e248503b0a
commit
e47fa70279
5 changed files with 40 additions and 8 deletions
|
@ -1,6 +1,14 @@
|
|||
--- a/net/minecraft/client/network/NetHandlerLoginClient.java
|
||||
+++ b/net/minecraft/client/network/NetHandlerLoginClient.java
|
||||
@@ -122,6 +122,7 @@
|
||||
@@ -98,6 +98,7 @@
|
||||
this.field_209525_d.accept(new TextComponentTranslation("connect.joining"));
|
||||
this.field_175091_e = p_147390_1_.func_179730_a();
|
||||
this.field_147393_d.func_150723_a(EnumConnectionState.PLAY);
|
||||
+ net.minecraftforge.fml.network.NetworkHooks.handleClientLoginSuccess(this.field_147393_d);
|
||||
this.field_147393_d.func_150719_a(new NetHandlerPlayClient(this.field_147394_b, this.field_147395_c, this.field_147393_d, this.field_175091_e));
|
||||
}
|
||||
|
||||
@@ -122,6 +123,7 @@
|
||||
}
|
||||
|
||||
public void func_209521_a(SPacketCustomPayloadLogin p_209521_1_) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package net.minecraftforge.fml.config;
|
||||
|
||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
||||
import com.electronwill.nightconfig.toml.TomlFormat;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -98,4 +99,12 @@ public class ConfigTracker {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void loadDefaultServerConfigs() {
|
||||
configSets.get(ModConfig.Type.SERVER).forEach(modConfig -> {
|
||||
final CommentedConfig commentedConfig = CommentedConfig.inMemory();
|
||||
modConfig.getSpec().correct(commentedConfig);
|
||||
modConfig.setConfigData(commentedConfig);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,6 +197,8 @@ public class FMLHandshakeHandler {
|
|||
final FMLHandshakeMessages.C2SModListReply reply = new FMLHandshakeMessages.C2SModListReply();
|
||||
channel.reply(reply, c.get());
|
||||
LOGGER.debug(FMLHSMARKER, "Accepted server connection");
|
||||
// Set the modded marker on the channel so we know we got packets
|
||||
c.get().getNetworkManager().channel().attr(FMLNetworking.FML_MARKER).set(NetworkHooks.NETVERSION);
|
||||
}
|
||||
|
||||
private <MSG extends FMLHandshakeMessages.LoginIndexedMessage> void handleIndexedMessage(MSG message, Supplier<NetworkEvent.Context> c)
|
||||
|
|
|
@ -23,7 +23,6 @@ import io.netty.buffer.Unpooled;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
@ -33,13 +32,17 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraft.world.IInteractionObject;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
||||
import net.minecraftforge.fml.config.ConfigTracker;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class NetworkHooks
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final String NETVERSION = "FML1";
|
||||
public static final String NOVERSION = "NONE";
|
||||
|
||||
|
@ -53,9 +56,9 @@ public class NetworkHooks
|
|||
return Objects.equals(packet.getFMLVersion(), NETVERSION) || NetworkRegistry.acceptsVanillaConnections();
|
||||
}
|
||||
|
||||
public static ConnectionType getConnectionType(final NetHandlerPlayServer connection)
|
||||
public static ConnectionType getConnectionType(final Supplier<NetworkManager> connection)
|
||||
{
|
||||
return ConnectionType.forVersionFlag(connection.netManager.channel().attr(FMLNetworking.FML_MARKER).get());
|
||||
return ConnectionType.forVersionFlag(connection.get().channel().attr(FMLNetworking.FML_MARKER).get());
|
||||
}
|
||||
|
||||
public static Packet<?> getEntitySpawningPacket(Entity entity)
|
||||
|
@ -80,11 +83,21 @@ public class NetworkHooks
|
|||
|
||||
public static void registerClientLoginChannel(NetworkManager manager)
|
||||
{
|
||||
if (manager == null) return;
|
||||
manager.channel().attr(FMLNetworking.FML_MARKER).set(NETVERSION);
|
||||
if (manager == null || manager.channel() == null) return;
|
||||
manager.channel().attr(FMLNetworking.FML_MARKER).set(NOVERSION);
|
||||
FMLHandshakeHandler.registerHandshake(manager, NetworkDirection.LOGIN_TO_SERVER);
|
||||
}
|
||||
|
||||
public static void handleClientLoginSuccess(NetworkManager manager) {
|
||||
if (manager == null || manager.channel() == null) return;
|
||||
if (getConnectionType(()->manager) == ConnectionType.VANILLA) {
|
||||
LOGGER.info("Connected to a vanilla server. Catching up missing behaviour.");
|
||||
ConfigTracker.INSTANCE.loadDefaultServerConfigs();
|
||||
} else {
|
||||
LOGGER.info("Connected to a modded server.");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean tickNegotiation(NetHandlerLoginServer netHandlerLoginServer, NetworkManager networkManager, EntityPlayerMP player)
|
||||
{
|
||||
return FMLHandshakeHandler.tickLogin(networkManager);
|
||||
|
|
|
@ -52,7 +52,7 @@ public class TextComponentHelper
|
|||
{
|
||||
EntityPlayerMP playerMP = (EntityPlayerMP) sender;
|
||||
NetHandlerPlayServer channel = playerMP.connection;
|
||||
return NetworkHooks.getConnectionType(channel) == ConnectionType.VANILLA;
|
||||
return NetworkHooks.getConnectionType(()->channel.netManager) == ConnectionType.VANILLA;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue