mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Detect and store the list of forge mods.
This commit is contained in:
parent
f67a3e3384
commit
7cc87d8e71
6 changed files with 119 additions and 21 deletions
70
MinecraftClient/Protocol/Handlers/Forge/ForgeInfo.cs
Executable file
70
MinecraftClient/Protocol/Handlers/Forge/ForgeInfo.cs
Executable file
|
|
@ -0,0 +1,70 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.Forge
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains information about a modded server install.
|
||||
/// </summary>
|
||||
public class ForgeInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an individual forge mod.
|
||||
/// </summary>
|
||||
public class ForgeMod
|
||||
{
|
||||
public ForgeMod(String ModID, String Version)
|
||||
{
|
||||
this.ModID = ModID;
|
||||
this.Version = Version;
|
||||
}
|
||||
|
||||
public readonly String ModID;
|
||||
public readonly String Version;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ModID + " v" + Version;
|
||||
}
|
||||
}
|
||||
|
||||
public List<ForgeMod> Mods;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new ForgeInfo from the given data.
|
||||
/// </summary>
|
||||
/// <param name="data">The modinfo JSON tag.</param>
|
||||
internal ForgeInfo(Json.JSONData data)
|
||||
{
|
||||
// Example ModInfo (with spacing):
|
||||
|
||||
// "modinfo": {
|
||||
// "type": "FML",
|
||||
// "modList": [{
|
||||
// "modid": "mcp",
|
||||
// "version": "9.05"
|
||||
// }, {
|
||||
// "modid": "FML",
|
||||
// "version": "8.0.99.99"
|
||||
// }, {
|
||||
// "modid": "Forge",
|
||||
// "version": "11.14.3.1512"
|
||||
// }, {
|
||||
// "modid": "rpcraft",
|
||||
// "version": "Beta 1.3 - 1.8.0"
|
||||
// }]
|
||||
// }
|
||||
|
||||
this.Mods = new List<ForgeMod>();
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ using System.Threading;
|
|||
using MinecraftClient.Crypto;
|
||||
using MinecraftClient.Proxy;
|
||||
using System.Security.Cryptography;
|
||||
using MinecraftClient.Protocol.Handlers.Forge;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers
|
||||
{
|
||||
|
|
@ -25,18 +26,22 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
private bool encrypted = false;
|
||||
private int protocolversion;
|
||||
|
||||
// Server forge info -- may be null.
|
||||
private ForgeInfo forgeInfo;
|
||||
|
||||
IMinecraftComHandler handler;
|
||||
Thread netRead;
|
||||
IAesStream s;
|
||||
TcpClient c;
|
||||
|
||||
public Protocol18Handler(TcpClient Client, int ProtocolVersion, IMinecraftComHandler Handler)
|
||||
public Protocol18Handler(TcpClient Client, int ProtocolVersion, IMinecraftComHandler Handler, ForgeInfo ForgeInfo)
|
||||
{
|
||||
ConsoleIO.SetAutoCompleteEngine(this);
|
||||
ChatParser.InitTranslations();
|
||||
this.c = Client;
|
||||
this.protocolversion = ProtocolVersion;
|
||||
this.handler = Handler;
|
||||
this.forgeInfo = ForgeInfo;
|
||||
}
|
||||
|
||||
private Protocol18Handler(TcpClient Client)
|
||||
|
|
@ -730,7 +735,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// </summary>
|
||||
/// <returns>True if ping was successful</returns>
|
||||
|
||||
public static bool doPing(string host, int port, ref int protocolversion)
|
||||
public static bool doPing(string host, int port, ref int protocolversion, ref ForgeInfo forgeInfo)
|
||||
{
|
||||
string version = "";
|
||||
TcpClient tcp = ProxyHandler.newTcpClient(host, port);
|
||||
|
|
@ -766,21 +771,37 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
Json.JSONData jsonData = Json.ParseJson(result);
|
||||
if (jsonData.Type == Json.JSONData.DataType.Object && jsonData.Properties.ContainsKey("version"))
|
||||
{
|
||||
jsonData = jsonData.Properties["version"];
|
||||
Json.JSONData versionData = jsonData.Properties["version"];
|
||||
|
||||
//Retrieve display name of the Minecraft version
|
||||
if (jsonData.Properties.ContainsKey("name"))
|
||||
version = jsonData.Properties["name"].StringValue;
|
||||
if (versionData.Properties.ContainsKey("name"))
|
||||
version = versionData.Properties["name"].StringValue;
|
||||
|
||||
//Retrieve protocol version number for handling this server
|
||||
if (jsonData.Properties.ContainsKey("protocol"))
|
||||
protocolversion = atoi(jsonData.Properties["protocol"].StringValue);
|
||||
if (versionData.Properties.ContainsKey("protocol"))
|
||||
protocolversion = atoi(versionData.Properties["protocol"].StringValue);
|
||||
|
||||
//Automatic fix for BungeeCord 1.8 reporting itself as 1.7...
|
||||
if (protocolversion < 47 && version.Split(' ', '/').Contains("1.8"))
|
||||
protocolversion = ProtocolHandler.MCVer2ProtocolVersion("1.8.0");
|
||||
|
||||
ConsoleIO.WriteLineFormatted("§8Server version : " + version + " (protocol v" + protocolversion + ").");
|
||||
|
||||
// Check for forge on the server.
|
||||
if (jsonData.Properties.ContainsKey("modinfo") && jsonData.Properties["modinfo"].Type == Json.JSONData.DataType.Object)
|
||||
{
|
||||
Json.JSONData modData = jsonData.Properties["modinfo"];
|
||||
if (modData.Properties.ContainsKey("type") && modData.Properties["type"].StringValue == "FML")
|
||||
{
|
||||
forgeInfo = new ForgeInfo(modData);
|
||||
|
||||
ConsoleIO.WriteLineFormatted("§8Server is running forge. Mod list:");
|
||||
foreach (ForgeInfo.ForgeMod mod in forgeInfo.Mods)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8 " + mod.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using MinecraftClient.Protocol.Handlers;
|
|||
using MinecraftClient.Proxy;
|
||||
using System.Net.Sockets;
|
||||
using System.Net.Security;
|
||||
using MinecraftClient.Protocol.Handlers.Forge;
|
||||
|
||||
namespace MinecraftClient.Protocol
|
||||
{
|
||||
|
|
@ -23,16 +24,17 @@ namespace MinecraftClient.Protocol
|
|||
/// <param name="protocolversion">Will contain protocol version, if ping successful</param>
|
||||
/// <returns>TRUE if ping was successful</returns>
|
||||
|
||||
public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion)
|
||||
public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion, ref ForgeInfo forgeInfo)
|
||||
{
|
||||
bool success = false;
|
||||
int protocolversionTmp = 0;
|
||||
ForgeInfo forgeInfoTmp = null;
|
||||
if (AutoTimeout.Perform(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Protocol16Handler.doPing(serverIP, serverPort, ref protocolversionTmp)
|
||||
|| Protocol18Handler.doPing(serverIP, serverPort, ref protocolversionTmp))
|
||||
|| Protocol18Handler.doPing(serverIP, serverPort, ref protocolversionTmp, ref forgeInfoTmp))
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
|
|
@ -40,11 +42,12 @@ namespace MinecraftClient.Protocol
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.Message);
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.ToString());
|
||||
}
|
||||
}, TimeSpan.FromSeconds(30)))
|
||||
{
|
||||
protocolversion = protocolversionTmp;
|
||||
forgeInfo = forgeInfoTmp;
|
||||
return success;
|
||||
}
|
||||
else
|
||||
|
|
@ -62,14 +65,14 @@ namespace MinecraftClient.Protocol
|
|||
/// <param name="Handler">Handler with the appropriate callbacks</param>
|
||||
/// <returns></returns>
|
||||
|
||||
public static IMinecraftCom getProtocolHandler(TcpClient Client, int ProtocolVersion, IMinecraftComHandler Handler)
|
||||
public static IMinecraftCom getProtocolHandler(TcpClient Client, int ProtocolVersion, ForgeInfo forgeInfo, IMinecraftComHandler Handler)
|
||||
{
|
||||
int[] supportedVersions_Protocol16 = { 51, 60, 61, 72, 73, 74, 78 };
|
||||
if (Array.IndexOf(supportedVersions_Protocol16, ProtocolVersion) > -1)
|
||||
return new Protocol16Handler(Client, ProtocolVersion, Handler);
|
||||
int[] supportedVersions_Protocol18 = { 4, 5, 47 };
|
||||
if (Array.IndexOf(supportedVersions_Protocol18, ProtocolVersion) > -1)
|
||||
return new Protocol18Handler(Client, ProtocolVersion, Handler);
|
||||
return new Protocol18Handler(Client, ProtocolVersion, Handler, forgeInfo);
|
||||
throw new NotSupportedException("The protocol version no." + ProtocolVersion + " is not supported.");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue