Allow force-enabling Forge support for 1.13+ (#1184)

Skip login step and join even when forge info is missing in server info.
However, this only works for 1.13+. Server info retrieval is required
for enabling Forge support on older Minecraft versions.
This commit is contained in:
ORelio 2020-10-18 13:09:46 +02:00
parent 9df255dd29
commit d3f150ba12
7 changed files with 101 additions and 7 deletions

View file

@ -33,6 +33,24 @@ namespace MinecraftClient.Protocol.Handlers.Forge
public List<ForgeMod> Mods;
internal FMLVersion Version;
/// <summary>
/// Create a new ForgeInfo with the given version.
/// </summary>
/// <param name="fmlVersion">FML version to use</param>
internal ForgeInfo(FMLVersion fmlVersion)
{
switch (fmlVersion)
{
case FMLVersion.FML2:
this.Mods = new List<ForgeMod>();
this.Mods.Add(new ForgeMod("forge", "ANY"));
this.Version = fmlVersion;
break;
default:
throw new InvalidOperationException(Translations.Get("error.forgeforce"));
}
}
/// <summary>
/// Create a new ForgeInfo from the given data.
/// </summary>

View file

@ -446,6 +446,30 @@ namespace MinecraftClient.Protocol.Handlers
|| ServerInfoCheckForgeSub(jsonData, ref forgeInfo, FMLVersion.FML2); // MC 1.13 and greater
}
/// <summary>
/// Server Info: Check if we can force-enable Forge support for this Minecraft version without using server Ping
/// </summary>
/// <param name="protocolVersion">Minecraft protocol version</param>
/// <returns>TRUE if we can force-enable Forge support without using server Ping</returns>
public static bool ServerMayForceForge(int protocolVersion)
{
return protocolVersion >= ProtocolHandler.MCVer2ProtocolVersion("1.13");
}
/// <summary>
/// Server Info: Consider Forge to be enabled regardless of server Ping
/// </summary>
/// <param name="protocolVersion">Minecraft protocol version</param>
/// <returns>ForgeInfo item stating that Forge is enabled</returns>
public static ForgeInfo ServerForceForge(int protocolVersion)
{
if (ServerMayForceForge(protocolVersion))
{
return new ForgeInfo(FMLVersion.FML2);
}
else throw new InvalidOperationException(Translations.Get("error.forgeforce"));
}
/// <summary>
/// Server Info: Check for For Forge on a Minecraft server Ping result (Handles FML and FML2
/// </summary>

View file

@ -305,6 +305,26 @@ namespace MinecraftClient.Protocol
}
}
/// <summary>
/// Check if we can force-enable Forge support for a Minecraft version without using server Ping
/// </summary>
/// <param name="protocolVersion">Minecraft protocol version</param>
/// <returns>TRUE if we can force-enable Forge support without using server Ping</returns>
public static bool ProtocolMayForceForge(int protocol)
{
return Protocol18Forge.ServerMayForceForge(protocol);
}
/// <summary>
/// Server Info: Consider Forge to be enabled regardless of server Ping
/// </summary>
/// <param name="protocolVersion">Minecraft protocol version</param>
/// <returns>ForgeInfo item stating that Forge is enabled</returns>
public static ForgeInfo ProtocolForceForge(int protocol)
{
return Protocol18Forge.ServerForceForge(protocol);
}
public enum LoginResult { OtherError, ServiceUnavailable, SSLError, Success, WrongPassword, AccountMigrated, NotPremium, LoginRequired, InvalidToken, InvalidResponse, NullError };
/// <summary>