6 Commits

Author SHA1 Message Date
Joey Eamigh
e3ae3fe83d update 2023-06-21 23:17:17 -04:00
Joey Eamigh
9bea47ca50 Merge remote-tracking branch 'refs/remotes/origin/main' 2023-06-21 22:29:10 -04:00
Joey Eamigh
3707ff5551 downloader.jar not zip 2023-06-21 22:28:58 -04:00
Joey Eamigh
3cb9b47004 server 2023-06-22 02:27:21 +00:00
Joey Eamigh
8373c48de8 server start point 2023-06-21 22:06:33 -04:00
Joey Eamigh
b885e5e3b3 adding api key 2023-06-21 21:31:45 -04:00
6 changed files with 331 additions and 4 deletions

View File

@@ -56,16 +56,19 @@ def run_mmc():
def mods():
os.chdir(INSTANCE_DIR)
if not os.path.exists(os.path.join(INSTANCE_DIR, "downloader.zip")):
if not os.path.exists(os.path.join(INSTANCE_DIR, "downloader.jar")):
cprint("downloader.jar not found - downloading", "yellow")
r = requests.get(MOD_DOWNLOADER_URL, allow_redirects=True)
open("downloader.jar", "wb").write(r.content)
cprint("downloading mods. this may take a while, please wait.", "green")
my_env = os.environ.copy()
my_env["CURSEFORGE_API_KEY"] = "$2a$10$QbCxI6f4KxEs50QKwE2piu1t6oOA8ayOw27H9N/eaH3Sdp5NTWwvO"
os.makedirs(os.path.join(INSTANCE_DIR, "mods"))
if OS != "win32":
subprocess.run(["java", "-jar", "downloader.jar", ".", "mods"])
subprocess.run(["java", "-jar", "downloader.jar", ".", "mods"], env=my_env)
else:
subprocess.run(
[
@@ -74,11 +77,15 @@ def mods():
"downloader.jar",
".",
"mods",
]
],
env=my_env,
)
for file in glob.glob(os.path.join(INSTANCE_DIR, ".minecraft", "mods", "*")):
if os.path.basename(file) == "OptiFine_1.16.5_HD_U_G8.jar":
if (
os.path.basename(file) == "OptiFine_1.16.5_HD_U_G8.jar"
or os.path.basename(file) == "TrainerCommands-1.16.5-2.6.0.jar"
):
continue
os.remove(file)

View File

@@ -23,6 +23,34 @@
"name": "JourneyMap"
}
},
{
"projectID": 55438,
"fileID": 3346467,
"required": true,
"__meta": {
"name": "MrCrayfish's Furniture Mod"
}
},
{
"projectID": 74072,
"fileID": 3695126,
"required": true,
"__meta": {
"name": "Tinkers Construct",
"dependencies": [
74924
]
}
},
{
"projectID": 74924,
"fileID": 3631982,
"required": true,
"__meta": {
"name": "Mantle",
"explicit": false
}
},
{
"projectID": 223852,
"fileID": 3776277,
@@ -31,6 +59,22 @@
"name": "Storage Drawers"
}
},
{
"projectID": 225608,
"fileID": 3172951,
"required": true,
"__meta": {
"name": "WorldEdit"
}
},
{
"projectID": 228756,
"fileID": 3543538,
"required": true,
"__meta": {
"name": "Iron Chests"
}
},
{
"projectID": 233342,
"fileID": 3216206,
@@ -66,6 +110,14 @@
"name": "Just Enough Items (JEI)"
}
},
{
"projectID": 245755,
"fileID": 3515707,
"required": true,
"__meta": {
"name": "Waystones"
}
},
{
"projectID": 247560,
"fileID": 4024011,
@@ -98,6 +150,18 @@
"name": "Simple Storage Network"
}
},
{
"projectID": 314905,
"fileID": 3802698,
"required": true,
"__meta": {
"name": "FTB Ranks (Forge)",
"dependencies": [
404465,
419699
]
}
},
{
"projectID": 328085,
"fileID": 3536025,
@@ -117,6 +181,14 @@
"name": "Pam's HarvestCraft 2 - Crops"
}
},
{
"projectID": 361579,
"fileID": 3767277,
"required": true,
"__meta": {
"name": "spark"
}
},
{
"projectID": 365460,
"fileID": 3281234,
@@ -171,6 +243,18 @@
]
}
},
{
"projectID": 404465,
"fileID": 3553840,
"required": true,
"__meta": {
"name": "FTB Library (Forge)",
"explicit": false,
"dependencies": [
419699
]
}
},
{
"projectID": 410295,
"fileID": 4514901,
@@ -180,6 +264,26 @@
"explicit": false
}
},
{
"projectID": 410811,
"fileID": 3510643,
"required": true,
"__meta": {
"name": "FTB Essentials (Forge)",
"dependencies": [
404465
]
}
},
{
"projectID": 419699,
"fileID": 4521290,
"required": true,
"__meta": {
"name": "Architectury API (Fabric/Forge)",
"explicit": false
}
},
{
"projectID": 486392,
"fileID": 3535459,

1
server/.jabbarc Normal file
View File

@@ -0,0 +1 @@
openjdk@1.11.0-2

193
server/server.py Normal file
View File

@@ -0,0 +1,193 @@
#!/usr/bin/env python3
import os, sys, shutil, requests, tempfile, glob, subprocess
from termcolor import cprint
from typing import Any
OS = sys.platform
MOD_DOWNLOADER_URL = "https://github.com/Joshyx/ModpackDownloader/releases/download/v1.3/ModpackDownloader-1.3.jar"
FORGE_URL = (
"https://maven.minecraftforge.net/net/minecraftforge/forge/1.16.5-36.2.34/forge-1.16.5-36.2.34-installer.jar"
)
FORGE_JAR = "forge-1.16.5-36.2.34.jar"
MODPACK_RELEASES_URL = "https://git.233hfd.com/api/v1/repos/joey/FishPogPixelmon/releases?limit=1"
INSTANCE_DIR = os.path.join(str(os.getenv("HOME")), "pixelmon")
# main
def __main__():
header()
needs_mods = instance()
if needs_mods:
mods()
forge()
launch()
# launcher
def launch():
if input("launch server? [Y/n] ").lower() == "n":
exit(0)
os.chdir(f"{INSTANCE_DIR}/.minecraft")
subprocess.run(["java", "-Xmx30720M", "-Xms1024M", "-jar", FORGE_JAR, "--nogui"])
# forge
def forge():
os.makedirs(f"{INSTANCE_DIR}/.minecraft", exist_ok=True)
os.chdir(f"{INSTANCE_DIR}/.minecraft")
if os.path.exists(os.path.join(f"{INSTANCE_DIR}/.minecraft", "forge-installer.jar")):
return
cprint("forge-installer.jar not found - downloading", "yellow")
r = requests.get(FORGE_URL, allow_redirects=True)
open("forge-installer.jar", "wb").write(r.content)
cprint("installing forge", "green")
subprocess.run(["java", "-jar", "forge-installer.jar", "--installServer"])
f = open("eula.txt", "w")
f.write("eula=true")
f.close()
# mods
def mods():
os.chdir(INSTANCE_DIR)
if not os.path.exists(os.path.join(INSTANCE_DIR, "downloader.zip")):
cprint("downloader.jar not found - downloading", "yellow")
r = requests.get(MOD_DOWNLOADER_URL, allow_redirects=True)
open("downloader.jar", "wb").write(r.content)
cprint("downloading mods. this may take a while, please wait.", "green")
my_env = os.environ.copy()
my_env["CURSEFORGE_API_KEY"] = "$2a$10$QbCxI6f4KxEs50QKwE2piu1t6oOA8ayOw27H9N/eaH3Sdp5NTWwvO"
os.makedirs(os.path.join(INSTANCE_DIR, "mods"))
subprocess.run(["java", "-jar", "downloader.jar", ".", "mods"], env=my_env)
for file in glob.glob(os.path.join(INSTANCE_DIR, ".minecraft", "mods", "*")):
if os.path.basename(file) == "TrainerCommands-1.16.5-2.6.0.jar":
continue
os.remove(file)
for file in glob.glob(os.path.join(INSTANCE_DIR, "mods", "mods", "*")):
shutil.move(file, os.path.join(INSTANCE_DIR, ".minecraft", "mods", os.path.basename(file)))
shutil.rmtree(os.path.join(INSTANCE_DIR, "mods"))
cprint("mods downloaded successfully", "green")
# multimc
def instance():
unclean = False
release = most_recent_release()
if not os.path.exists(INSTANCE_DIR):
unclean = True
cprint("instance not found - downloading", "yellow")
download_instance(release)
version = ""
if os.path.exists(f"{INSTANCE_DIR}/.version"):
f = open(f"{INSTANCE_DIR}/.version", "r")
version = f.read()
if version != release["tag_name"]:
unclean = True
cprint("new update available! - downloading", "green")
download_instance(release)
cprint("instance is up to date", "green")
return unclean
def download_instance(release: dict[str, Any]):
os.makedirs(os.path.join(INSTANCE_DIR, ".minecraft"), exist_ok=True)
TMP = tempfile.mkdtemp()
os.chdir(TMP)
download_url = get_release_asset(release)
r = requests.get(download_url, allow_redirects=True)
open("instance.zip", "wb").write(r.content)
shutil.unpack_archive("instance.zip", ".")
os.remove("instance.zip")
for file in glob.glob(os.path.join(TMP, "overrides", "*")):
if file == os.path.join(TMP, "overrides", "options.txt") and os.path.exists(
os.path.join(INSTANCE_DIR, ".minecraft", "options.txt")
):
continue
if os.path.exists(os.path.join(INSTANCE_DIR, ".minecraft", os.path.basename(file))):
if os.path.isdir(os.path.join(INSTANCE_DIR, ".minecraft", os.path.basename(file))):
shutil.rmtree(os.path.join(INSTANCE_DIR, ".minecraft", os.path.basename(file)))
else:
os.remove(os.path.join(INSTANCE_DIR, ".minecraft", os.path.basename(file)))
shutil.move(file, os.path.join(INSTANCE_DIR, ".minecraft", os.path.basename(file)))
shutil.rmtree(os.path.join(TMP, "overrides"))
for file in glob.glob(os.path.join(TMP, "*")):
if os.path.exists(os.path.join(INSTANCE_DIR, os.path.basename(file))):
if os.path.isdir(os.path.join(INSTANCE_DIR, os.path.basename(file))):
shutil.rmtree(os.path.join(INSTANCE_DIR, os.path.basename(file)))
else:
os.remove(os.path.join(INSTANCE_DIR, os.path.basename(file)))
shutil.move(file, os.path.join(INSTANCE_DIR, os.path.basename(file)))
os.chdir(INSTANCE_DIR)
f = open(".version", "w")
f.write(release["tag_name"])
f.close()
# releases
def most_recent_release() -> dict[str, Any]:
r = requests.get(MODPACK_RELEASES_URL)
releases: list[dict[str, Any]] = r.json()
return releases[0]
def most_recent_version(release: dict[str, Any]) -> str:
return release["tag_name"]
def get_release_asset(release: dict[str, Any]):
return release["assets"][0]["browser_download_url"]
# ascii art lol
def header():
cprint(
"""
_______ __ __ _______
| _ ||__|.-----.| |--.| _ |.-----..-----.
|. 1___|| ||__ --|| ||. 1 || _ || _ |
|. __) |__||_____||__|__||. ____||_____||___ |
|: | |: | |_____|
|::.| |::.|
`---' `---'
_______ __ __
| _ ||__|.--.--..-----.| |.--------..-----..-----.
|. 1 || ||_ _|| -__|| || || _ || |
|. ____||__||__.__||_____||__||__|__|__||_____||__|__|
|: |
|::.|
`---'
""",
"green",
)
# run app
__main__()

22
server/server.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
# check that python is installed
if ! [ -x "$(command -v python)" ]; then
echo 'Error: python is not installed. Please install it to continue.' >&2
exit 1
fi
# check that java is installed
if ! [ -x "$(command -v java)" ]; then
echo 'Error: java is not installed. Please install it to continue.' >&2
exit 1
fi
if ! [ -d .venv ]; then python -m venv .venv; fi
source .venv/bin/activate &>/dev/null
python -m pip install --upgrade pip &>/dev/null
python -m pip install -r ../client/requirements.txt &>/dev/null
python ./server.py