-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Just-Chaldea/general-fixes
General fixes
- Loading branch information
Showing
13 changed files
with
246 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
forge/src/main/java/gg/chaldea/client/reset/packet/mixin/MixinFMLHandshakeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package gg.chaldea.client.reset.packet.mixin; | ||
|
||
import com.google.common.collect.Maps; | ||
import net.minecraft.network.login.server.SDisconnectLoginPacket; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.util.text.StringTextComponent; | ||
import net.minecraftforge.fml.network.*; | ||
import net.minecraftforge.registries.ForgeRegistry; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.Marker; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
import static net.minecraftforge.registries.ForgeRegistry.REGISTRIES; | ||
|
||
@Mixin(FMLHandshakeHandler.class) | ||
public class MixinFMLHandshakeHandler { | ||
|
||
|
||
@Shadow(remap = false) @Final static Marker FMLHSMARKER; | ||
@Shadow(remap = false) @Final private static Logger LOGGER; | ||
|
||
@Shadow(remap = false) private Set<ResourceLocation> registriesToReceive; | ||
@Shadow(remap = false) private Map<ResourceLocation, ForgeRegistry.Snapshot> registrySnapshots; | ||
|
||
/** | ||
* @author | ||
* @reason | ||
*/ | ||
@Overwrite(remap = false) | ||
void handleServerModListOnClient(FMLHandshakeMessages.S2CModList serverModList, Supplier<NetworkEvent.Context> c) { | ||
LOGGER.debug(FMLHSMARKER, "Logging into server with mod list [{}]", String.join(", ", serverModList.getModList())); | ||
c.get().setPacketHandled(true); | ||
FMLNetworkConstants.handshakeChannel.reply(new FMLHandshakeMessages.C2SModListReply(), 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(FMLNetworkConstants.FML_NETVERSION).set(FMLNetworkConstants.NETVERSION); | ||
c.get().getNetworkManager().channel().attr(FMLNetworkConstants.FML_CONNECTION_DATA) | ||
.set(new FMLConnectionData(serverModList.getModList(), serverModList.getChannels())); | ||
|
||
this.registriesToReceive = new HashSet<>(serverModList.getRegistries()); | ||
this.registrySnapshots = Maps.newHashMap(); | ||
LOGGER.debug(REGISTRIES, "Expecting {} registries: {}", ()->this.registriesToReceive.size(), ()->this.registriesToReceive); | ||
} | ||
|
||
/** | ||
* @author | ||
* @reason | ||
*/ | ||
@Overwrite(remap = false) | ||
void handleClientModListOnServer(FMLHandshakeMessages.C2SModListReply clientModList, Supplier<NetworkEvent.Context> c) { | ||
LOGGER.debug(FMLHSMARKER, "Received client connection with modlist [{}]", String.join(", ", clientModList.getModList())); | ||
boolean accepted = NetworkRegistry.validateServerChannels(clientModList.getChannels()); | ||
((NetworkEvent.Context)c.get()).getNetworkManager().channel().attr(FMLNetworkConstants.FML_CONNECTION_DATA).set(new FMLConnectionData(clientModList.getModList(), clientModList.getChannels())); | ||
((NetworkEvent.Context)c.get()).setPacketHandled(true); | ||
if (!accepted) { | ||
LOGGER.error(FMLHSMARKER, "Terminating connection with client, mismatched mod list"); | ||
c.get().getNetworkManager().send(new SDisconnectLoginPacket(new StringTextComponent("Connection closed - mismatched mod channel list"))); | ||
((NetworkEvent.Context)c.get()).getNetworkManager().disconnect(new StringTextComponent("Connection closed - mismatched mod channel list")); | ||
} else { | ||
LOGGER.debug(FMLHSMARKER, "Accepted client connection mod list"); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
forge/src/main/java/gg/chaldea/client/reset/packet/mixin/MixinNetworkFilters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package gg.chaldea.client.reset.packet.mixin; | ||
|
||
import net.minecraft.network.NetworkManager; | ||
import net.minecraftforge.network.NetworkFilters; | ||
import net.minecraftforge.network.VanillaPacketFilter; | ||
import org.apache.logging.log4j.Logger; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
@Mixin(NetworkFilters.class) | ||
public class MixinNetworkFilters { | ||
|
||
@Shadow(remap = false) @Final private static Map<String, Function<NetworkManager, VanillaPacketFilter>> instances; | ||
@Shadow(remap = false) @Final private static Logger LOGGER; | ||
|
||
/** | ||
* @author danorris709 | ||
* @reason Prevent error | ||
*/ | ||
@Overwrite(remap = false) | ||
public static void injectIfNecessary(NetworkManager manager) | ||
{ | ||
instances.forEach((key, filterFactory) -> { | ||
if (manager.channel().pipeline().get(key) != null) { | ||
return; | ||
} | ||
|
||
try { | ||
VanillaPacketFilter filter = filterFactory.apply(manager); | ||
if (((VanillaPacketFilterAccessor)filter).invokeIsNecessary(manager)) { | ||
manager.channel().pipeline().addBefore("packet_handler", key, filter); | ||
LOGGER.debug("Injected {} into {}", filter, manager); | ||
} | ||
} catch (Exception e) { | ||
|
||
} | ||
}); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
forge/src/main/java/gg/chaldea/client/reset/packet/mixin/MixinNetworkManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package gg.chaldea.client.reset.packet.mixin; | ||
|
||
import io.netty.channel.Channel; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.screen.DirtMessageScreen; | ||
import net.minecraft.client.gui.screen.DisconnectedScreen; | ||
import net.minecraft.client.gui.screen.MainMenuScreen; | ||
import net.minecraft.client.gui.screen.MultiplayerScreen; | ||
import net.minecraft.network.NetworkManager; | ||
import net.minecraft.util.text.ITextComponent; | ||
import net.minecraft.util.text.StringTextComponent; | ||
import net.minecraft.util.text.TranslationTextComponent; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
@Mixin(NetworkManager.class) | ||
public class MixinNetworkManager { | ||
|
||
@Shadow private Channel channel; | ||
@Shadow private ITextComponent disconnectedReason; | ||
|
||
/** | ||
* @author | ||
* @reason | ||
*/ | ||
@Overwrite | ||
@OnlyIn(Dist.CLIENT) | ||
public void disconnect(ITextComponent p_150718_1_) { | ||
if (this.channel.isOpen()) { | ||
this.channel.close().awaitUninterruptibly(); | ||
this.disconnectedReason = p_150718_1_; | ||
|
||
if (Minecraft.getInstance().screen instanceof DirtMessageScreen) { | ||
ITextComponent title = ((DirtMessageScreen)Minecraft.getInstance().screen).getTitle(); | ||
|
||
if (title instanceof TranslationTextComponent && | ||
((TranslationTextComponent) title).getKey().equals("connect.negotiating")) { | ||
Minecraft.getInstance().setScreen(new DisconnectedScreen(new MultiplayerScreen(new MainMenuScreen()), new StringTextComponent(""), this.disconnectedReason)); | ||
} | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
forge/src/main/java/gg/chaldea/client/reset/packet/mixin/VanillaPacketFilterAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package gg.chaldea.client.reset.packet.mixin; | ||
|
||
import net.minecraft.network.NetworkManager; | ||
import net.minecraftforge.network.VanillaPacketFilter; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(VanillaPacketFilter.class) | ||
public interface VanillaPacketFilterAccessor { | ||
|
||
@Invoker("isNecessary") | ||
boolean invokeIsNecessary(NetworkManager manager); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"required": true, | ||
"minVersion": "0.7.10", | ||
"package": "gg.chaldea.client.reset.packet.mixin", | ||
"refmap": "mixins.clientresetpacket.refmap.json", | ||
"target": "@env(DEFAULT)", | ||
"compatibilityLevel": "JAVA_8", | ||
"mixins": [ | ||
"MixinFMLHandshakeHandler", | ||
"MixinNetworkFilters", | ||
"MixinNetworkManager", | ||
"VanillaPacketFilterAccessor" | ||
], | ||
"client": [] | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.