mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
Implement FML2 mod list in server ping (#1184)
This commit is contained in:
parent
24b3dac2a3
commit
74151097ff
2 changed files with 83 additions and 16 deletions
|
|
@ -36,9 +36,13 @@ namespace MinecraftClient.Protocol.Handlers.Forge
|
|||
/// Create a new ForgeInfo from the given data.
|
||||
/// </summary>
|
||||
/// <param name="data">The modinfo JSON tag.</param>
|
||||
/// <exception cref="System.ArgumentException">Thrown on missing mod list in JSON data</exception>
|
||||
internal ForgeInfo(Json.JSONData data)
|
||||
{
|
||||
// Example ModInfo (with spacing):
|
||||
this.Mods = new List<ForgeMod>();
|
||||
bool listFound = false;
|
||||
|
||||
// Example ModInfo for Minecraft 1.12 and lower (FML)
|
||||
|
||||
// "modinfo": {
|
||||
// "type": "FML",
|
||||
|
|
@ -57,7 +61,10 @@ namespace MinecraftClient.Protocol.Handlers.Forge
|
|||
// }]
|
||||
// }
|
||||
|
||||
this.Mods = new List<ForgeMod>();
|
||||
if (data.Properties.ContainsKey("modList") && data.Properties["modList"].Type == Json.JSONData.DataType.Array)
|
||||
{
|
||||
listFound = true;
|
||||
|
||||
foreach (Json.JSONData mod in data.Properties["modList"].DataArray)
|
||||
{
|
||||
String modid = mod.Properties["modid"].StringValue;
|
||||
|
|
@ -66,5 +73,50 @@ namespace MinecraftClient.Protocol.Handlers.Forge
|
|||
this.Mods.Add(new ForgeMod(modid, version));
|
||||
}
|
||||
}
|
||||
|
||||
// Example ModInfo for Minecraft 1.13 and greater (FML2)
|
||||
|
||||
// "forgeData": {
|
||||
// "channels": [{
|
||||
// "res": "minecraft:unregister",
|
||||
// "version": "FML2",
|
||||
// "required": true
|
||||
// }, {
|
||||
// "res": "minecraft:register",
|
||||
// "version": "FML2",
|
||||
// "required": true
|
||||
// }],
|
||||
// "mods": [{
|
||||
// "modId": "minecraft",
|
||||
// "modmarker": "1.15.2"
|
||||
// }, {
|
||||
// "modId": "forge",
|
||||
// "modmarker": "ANY"
|
||||
// }, {
|
||||
// "modId": "rats",
|
||||
// "modmarker": "5.3.2"
|
||||
// }, {
|
||||
// "modId": "citadel",
|
||||
// "modmarker": "1.1.11"
|
||||
// }],
|
||||
// "fmlNetworkVersion": 2
|
||||
// }
|
||||
|
||||
if (data.Properties.ContainsKey("mods") && data.Properties["mods"].Type == Json.JSONData.DataType.Array)
|
||||
{
|
||||
listFound = true;
|
||||
|
||||
foreach (Json.JSONData mod in data.Properties["mods"].DataArray)
|
||||
{
|
||||
String modid = mod.Properties["modId"].StringValue;
|
||||
String version = mod.Properties["modmarker"].StringValue;
|
||||
|
||||
this.Mods.Add(new ForgeMod(modid, version));
|
||||
}
|
||||
}
|
||||
|
||||
if (!listFound)
|
||||
throw new ArgumentException("Missing mod list", "data");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -248,30 +248,45 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// </summary>
|
||||
/// <param name="jsonData">JSON data returned by the server</param>
|
||||
/// <param name="forgeInfo">ForgeInfo to populate</param>
|
||||
public static void ServerInfoCheckForge(Json.JSONData jsonData, ref ForgeInfo forgeInfo)
|
||||
/// <returns>True if the server is running Forge</returns>
|
||||
public static bool ServerInfoCheckForge(Json.JSONData jsonData, ref ForgeInfo forgeInfo)
|
||||
{
|
||||
if (jsonData.Properties.ContainsKey("modinfo") && jsonData.Properties["modinfo"].Type == Json.JSONData.DataType.Object)
|
||||
return ServerInfoCheckForgeSub(jsonData, ref forgeInfo, "modinfo", "type", "FML") // MC 1.12 and lower
|
||||
|| ServerInfoCheckForgeSub(jsonData, ref forgeInfo, "forgeData", "fmlNetworkVersion", "2"); // MC 1.13 and greater
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Server Info: Check for For Forge on a Minecraft server Ping result
|
||||
/// </summary>
|
||||
/// <param name="jsonData">JSON data returned by the server</param>
|
||||
/// <param name="forgeInfo">ForgeInfo to populate</param>
|
||||
/// <param name="forgeDataTag">ForgeData JSON field, e.g. "modinfo"</param>
|
||||
/// <param name="versionField">ForgeData version field, e.g. "type"</param>
|
||||
/// <param name="versionString">ForgeData version value, e.g. "FML"</param>
|
||||
/// <returns>True if the server is running Forge</returns>
|
||||
private static bool ServerInfoCheckForgeSub(Json.JSONData jsonData, ref ForgeInfo forgeInfo, string forgeDataTag, string versionField, string versionString)
|
||||
{
|
||||
Json.JSONData modData = jsonData.Properties["modinfo"];
|
||||
if (modData.Properties.ContainsKey("type") && modData.Properties["type"].StringValue == "FML")
|
||||
if (jsonData.Properties.ContainsKey(forgeDataTag) && jsonData.Properties[forgeDataTag].Type == Json.JSONData.DataType.Object)
|
||||
{
|
||||
Json.JSONData modData = jsonData.Properties[forgeDataTag];
|
||||
if (modData.Properties.ContainsKey(versionField) && modData.Properties[versionField].StringValue == versionString)
|
||||
{
|
||||
forgeInfo = new ForgeInfo(modData);
|
||||
|
||||
if (forgeInfo.Mods.Any())
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted(String.Format("§8Server is running Forge with {0} mods.", forgeInfo.Mods.Count));
|
||||
if (Settings.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8Server is running Forge. Mod list:");
|
||||
ConsoleIO.WriteLineFormatted("§8Mod list:");
|
||||
foreach (ForgeInfo.ForgeMod mod in forgeInfo.Mods)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8 " + mod.ToString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else ConsoleIO.WriteLineFormatted("§8Server is running Forge.");
|
||||
}
|
||||
else forgeInfo = null;
|
||||
}
|
||||
else ConsoleIO.WriteLineFormatted("§8Server is running Forge without mods.");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue