Exemplo n.º 1
0
        /// <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"));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Server Info: Check for For Forge on a Minecraft server Ping result (Handles FML and FML2
        /// </summary>
        /// <param name="jsonData">JSON data returned by the server</param>
        /// <param name="forgeInfo">ForgeInfo to populate</param>
        /// <param name="fmlVersion">Forge protocol version</param>
        /// <returns>True if the server is running Forge</returns>
        private static bool ServerInfoCheckForgeSub(Json.JSONData jsonData, ref ForgeInfo forgeInfo, FMLVersion fmlVersion)
        {
            string forgeDataTag;
            string versionField;
            string versionString;

            switch (fmlVersion)
            {
            case FMLVersion.FML:
                forgeDataTag  = "modinfo";
                versionField  = "type";
                versionString = "FML";
                break;

            case FMLVersion.FML2:
                forgeDataTag  = "forgeData";
                versionField  = "fmlNetworkVersion";
                versionString = "2";
                break;

            default:
                throw new NotImplementedException("FMLVersion '" + fmlVersion + "' not implemented!");
            }

            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, fmlVersion);
                    if (forgeInfo.Mods.Any())
                    {
                        ConsoleIO.WriteLineFormatted(Translations.Get("forge.with_mod", forgeInfo.Mods.Count));
                        if (Settings.DebugMessages)
                        {
                            Translations.WriteLineFormatted("forge.mod_list");
                            foreach (ForgeInfo.ForgeMod mod in forgeInfo.Mods)
                            {
                                ConsoleIO.WriteLineFormatted("§8  " + mod.ToString());
                            }
                        }
                        return(true);
                    }
                    else
                    {
                        Translations.WriteLineFormatted("forge.no_mod");
                        forgeInfo = null;
                    }
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a new ForgeInfo from the given data.
        /// </summary>
        /// <param name="data">The modinfo JSON tag.</param>
        /// <param name="fmlVersion">Forge protocol version</param>
        internal ForgeInfo(Json.JSONData data, FMLVersion fmlVersion)
        {
            this.Mods    = new List <ForgeMod>();
            this.Version = fmlVersion;

            switch (fmlVersion)
            {
            case FMLVersion.FML:

                // Example ModInfo for Minecraft 1.12 and lower (FML)

                // "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"
                //     }]
                // }

                foreach (Json.JSONData mod in data.Properties["modList"].DataArray)
                {
                    String modid      = mod.Properties["modid"].StringValue;
                    String modversion = mod.Properties["version"].StringValue;

                    this.Mods.Add(new ForgeMod(modid, modversion));
                }

                break;

            case FMLVersion.FML2:

                // 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
                // }

                foreach (Json.JSONData mod in data.Properties["mods"].DataArray)
                {
                    String modid     = mod.Properties["modId"].StringValue;
                    String modmarker = mod.Properties["modmarker"].StringValue;

                    this.Mods.Add(new ForgeMod(modid, modmarker));
                }

                break;

            default:
                throw new NotImplementedException("FMLVersion '" + fmlVersion + "' not implemented!");
            }
        }