mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Fix connection to vanilla servers. Generate a default mod server config
for mods connecting to servers. Signed-off-by: cpw <[email protected]>
This commit is contained in:
5 files changed
+40
-8
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user