mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +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.
|
/// Create a new ForgeInfo from the given data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">The modinfo JSON tag.</param>
|
/// <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)
|
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": {
|
// "modinfo": {
|
||||||
// "type": "FML",
|
// "type": "FML",
|
||||||
|
|
@ -57,14 +61,62 @@ namespace MinecraftClient.Protocol.Handlers.Forge
|
||||||
// }]
|
// }]
|
||||||
// }
|
// }
|
||||||
|
|
||||||
this.Mods = new List<ForgeMod>();
|
if (data.Properties.ContainsKey("modList") && data.Properties["modList"].Type == Json.JSONData.DataType.Array)
|
||||||
foreach (Json.JSONData mod in data.Properties["modList"].DataArray)
|
|
||||||
{
|
{
|
||||||
String modid = mod.Properties["modid"].StringValue;
|
listFound = true;
|
||||||
String version = mod.Properties["version"].StringValue;
|
|
||||||
|
|
||||||
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -248,30 +248,45 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jsonData">JSON data returned by the server</param>
|
/// <param name="jsonData">JSON data returned by the server</param>
|
||||||
/// <param name="forgeInfo">ForgeInfo to populate</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)
|
||||||
|
{
|
||||||
|
if (jsonData.Properties.ContainsKey(forgeDataTag) && jsonData.Properties[forgeDataTag].Type == Json.JSONData.DataType.Object)
|
||||||
{
|
{
|
||||||
Json.JSONData modData = jsonData.Properties["modinfo"];
|
Json.JSONData modData = jsonData.Properties[forgeDataTag];
|
||||||
if (modData.Properties.ContainsKey("type") && modData.Properties["type"].StringValue == "FML")
|
if (modData.Properties.ContainsKey(versionField) && modData.Properties[versionField].StringValue == versionString)
|
||||||
{
|
{
|
||||||
forgeInfo = new ForgeInfo(modData);
|
forgeInfo = new ForgeInfo(modData);
|
||||||
|
|
||||||
if (forgeInfo.Mods.Any())
|
if (forgeInfo.Mods.Any())
|
||||||
{
|
{
|
||||||
|
ConsoleIO.WriteLineFormatted(String.Format("§8Server is running Forge with {0} mods.", forgeInfo.Mods.Count));
|
||||||
if (Settings.DebugMessages)
|
if (Settings.DebugMessages)
|
||||||
{
|
{
|
||||||
ConsoleIO.WriteLineFormatted("§8Server is running Forge. Mod list:");
|
ConsoleIO.WriteLineFormatted("§8Mod list:");
|
||||||
foreach (ForgeInfo.ForgeMod mod in forgeInfo.Mods)
|
foreach (ForgeInfo.ForgeMod mod in forgeInfo.Mods)
|
||||||
{
|
|
||||||
ConsoleIO.WriteLineFormatted("§8 " + mod.ToString());
|
ConsoleIO.WriteLineFormatted("§8 " + mod.ToString());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else ConsoleIO.WriteLineFormatted("§8Server is running Forge.");
|
return true;
|
||||||
}
|
}
|
||||||
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