Created
February 22, 2024 08:51
-
-
Save AdamG100/ac1906d53194796db44dd86234ff184c to your computer and use it in GitHub Desktop.
Minecraft bedrock Download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re, urllib2, json | |
import clr | |
clr.AddReference('TCAdmin.GameHosting.SDK') | |
from TCAdmin.GameHosting.SDK.Objects import GameUpdate, GameScript, ServiceEvent | |
gameID = 193 | |
scripts = [ | |
{ | |
"Name": "Backup server.properties", | |
"Event": ServiceEvent.BeforeUpdateInstall, | |
'Contents': "from os import path, rename, remove\nserverproperties = path.join(ThisService.RootDirectory, 'server.properties')\nif path.isfile(serverproperties):\n if path.isfile(serverproperties+'.backup'):\n remove(serverproperties+'.backup')\n rename(serverproperties, serverproperties+'.backup')" | |
}, | |
{ | |
"Name": "Delete new server.properties, use old file instead", | |
"Event": ServiceEvent.AfterUpdateInstall, | |
"Contents": "from os import path, rename, remove\nserverproperties = path.join(ThisService.RootDirectory, 'server.properties')\nif path.isfile(serverproperties):\n remove(serverproperties)\nrename(serverproperties+'.backup', serverproperties)" | |
} | |
] | |
updates = GameUpdate.GetUpdates(gameID) | |
version_page = urllib2.urlopen('https://minecraft.fandom.com/wiki/Bedrock_Dedicated_Server').read() | |
regex_pattern = '<a target=\"_self\" rel=\"nofollow\" class=\"external text\" href=\"https:\/\/minecraft\.azureedge\.net\/bin-win(\-preview)?\/bedrock-server-(?<Version>.*)\.zip\">Windows<\/a>' | |
matches = re.findall(regex_pattern, version_page) | |
if matches.Count > 0: | |
for version in matches: | |
release = version[0] # '' or '-preview' | |
version = version[1] | |
#Generate view order | |
parts = version.split('.') | |
for i in range(4): | |
parts[i] = parts[i].zfill(3) | |
view_order=-int(''.join(parts)) | |
#Skip if an update already exists with the same name | |
skip = False | |
for gameUpdate in updates: | |
if gameUpdate.Name == "Bedrock Edition "+version: | |
Script.WriteToConsole('Skipping version {}'.format(version)) | |
skip = True | |
if not skip: | |
update = GameUpdate() | |
update.Name = "Bedrock Edition "+version | |
update.Comments = "" | |
update.ImageUrl = "https://www.minecraft.net/etc.clientlibs/minecraft/clientlibs/main/resources/img/header/logo.png" | |
update.GameId = gameID | |
update.GroupName = "Minecraft: Bedrock Edition" if release == '' else "Minecraft: Bedrock Edition Preview" | |
update.ExtractPath = "/" | |
update.WindowsFileName = "https://minecraft.azureedge.net/bin-win{}/bedrock-server-{}.zip".format(release, version) | |
update.LinuxFileName = "https://minecraft.azureedge.net/bin-linux{}/bedrock-server-{}.zip".format(release, version) | |
update.Reinstallable = True | |
update.DefaultInstall = False | |
update.UserAccess = True | |
update.SubAdminAccess = True | |
update.ResellerAccess = True | |
update.ViewOrder = view_order | |
update.GenerateKey() | |
update.Save() | |
Script.WriteToConsole("Added update for Minecraft: Bedrock Edition v{}".format(version)) | |
#Add custom scripts | |
for script in scripts: | |
updateScript = GameScript() | |
updateScript.Description = script["Name"] | |
updateScript.ScriptContents = script["Contents"] | |
updateScript.ServiceEvent = script["Event"] | |
updateScript.ExecuteAsServiceUser = False | |
updateScript.ExecuteInPopup = False | |
updateScript.ExecutionOrder = 0 | |
updateScript.GameId = gameID | |
updateScript.IgnoreErrors = False | |
updateScript.OperatingSystem = 0 #0 = Any, 2 = Windows, 4 = Linux | |
updateScript.PromptVariables = False | |
updateScript.UserAccess = True | |
updateScript.SubAdminAccess = True | |
updateScript.ResellerAccess = True | |
updateScript.ScriptEngineId = 1 #IronPython | |
updateScript.UpdateId = update.UpdateId | |
updateScript.GenerateKey() | |
updateScript.Save() | |
#Change the links for the "Latest" update | |
gameUpdates = set(updates) | |
for update in gameUpdates: | |
if 'Latest Bedrock Update' in update.Notes: | |
Script.WriteToConsole('Changing the links for the latest Bedrock update') | |
update.WindowsFileName = "https://minecraft.azureedge.net/bin-win/bedrock-server-{}.zip".format(version) | |
update.LinuxFileName = "https://minecraft.azureedge.net/bin-linux/bedrock-server-{}.zip".format(version) | |
update.Save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fandom wiki is no longer regularly updated.
Unfortunately the other wiki blocks urllib2: https://minecraft.wiki/w/Bedrock_Dedicated_Server
You can use the official site and replace urllib2 with .NET HttpWebRequest