Implement FML2 mod list in server ping (#1184)

This commit is contained in:
ORelio 2020-08-08 22:08:37 +02:00
parent 24b3dac2a3
commit 74151097ff
2 changed files with 83 additions and 16 deletions

View file

@ -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,14 +61,62 @@ namespace MinecraftClient.Protocol.Handlers.Forge
// }]
// }
this.Mods = new List<ForgeMod>();
foreach (Json.JSONData mod in data.Properties["modList"].DataArray)
if (data.Properties.ContainsKey("modList") && data.Properties["modList"].Type == Json.JSONData.DataType.Array)
{
String modid = mod.Properties["modid"].StringValue;
String version = mod.Properties["version"].StringValue;
listFound = true;
this.Mods.Add(new ForgeMod(modid, version));
foreach (Json.JSONData mod in data.Properties["modList"].DataArray)
{
String modid = mod.Properties["modid"].StringValue;
String version = mod.Properties["version"].StringValue;
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");
}
}
}