Skip to content

Commit

Permalink
代码重构,修正多个问题
Browse files Browse the repository at this point in the history
  • Loading branch information
kressety committed Nov 12, 2023
1 parent 312fda3 commit 61ca31d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
22 changes: 14 additions & 8 deletions api/curseforge_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ def get_modpack_meta(
api_key: str
):
raw_data = _get_mod_info(modpack_id, api_key)
game_versions = raw_data['data']['latestFiles'][0]['gameVersions']
game_version = ''
mod_loader = ''
for version in game_versions:
if fullmatch(r'1\.[1-9][0-9]?(\.[1-9][0-9]?)?', version):
game_version = version
elif version.lower() in ['fabric', 'forge', 'quilt', 'neoforge']:
mod_loader = version.lower()
game_version = None
mod_loader = None
for latest_file in raw_data['data']['latestFiles']:
if 'gameVersions' in latest_file:
game_versions = latest_file['gameVersions']
for version in game_versions:
if game_version is None:
if fullmatch(r'1\.[1-9][0-9]?(\.[1-9][0-9]?)?', version):
game_version = version
if mod_loader is None:
if version.lower() in ['fabric', 'forge', 'quilt', 'neoforge']:
mod_loader = version.lower()
if (game_version is not None) and (mod_loader is not None):
break
return {
'name': raw_data['data']['name'],
'logo': raw_data['data']['logo']['url'],
Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
'server': {
'enable': 'True',
'server_path': '%(Enter server path here, etc. /root/mc)s',
'memory_limit': '20'
'memory_limit': '18'
}
})
with open('config.ini', 'w') as config_file:
Expand All @@ -49,6 +49,7 @@
prep_server(
config['server']['server_path'],
server_meta['game_version'],
server_meta['mod_loader'],
config['server']['memory_limit'],
server_meta['name']
)
21 changes: 21 additions & 0 deletions server/bluemap_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from os import makedirs
from os.path import join

from api.modrinth_api import download_mod


def download_bluemap(
server_path: str,
loader: str,
game_version: str
):
download_mod(join(server_path, 'mods'), loader, game_version, 'swbUV1cr')


def config_bluemap(
server_path: str
):
config_path = join(server_path, 'config/bluemap')
makedirs(config_path, True)
with open(join(config_path, 'core.conf'), 'w', encoding='UTF-8') as config_file:
config_file.write('accept-download: true\nrender-thread-count: -2')
10 changes: 1 addition & 9 deletions server/jre_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,4 @@ def add_jre_args(
memory_limit: str
):
with open(join(server_path, 'user_jvm_args.txt'), 'w') as file:
file.write(f'-Xms{memory_limit}G -Xmx{memory_limit}G -XX:+UseG1GC -XX:+ParallelRefProcEnabled '
f'-XX:MaxGCPauseMillis=200 '
'-XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch '
'-XX:G1NewSizePercent=40 -XX:G1MaxNewSizePercent=50 -XX:G1HeapRegionSize=16M '
'-XX:G1ReservePercent=15 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 '
'-XX:InitiatingHeapOccupancyPercent=20 -XX:G1MixedGCLiveThresholdPercent=90 '
'-XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem '
'-XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true '
'-javaagent:authlib-injector.jar=https://skin.mealuet.com/api/yggdrasil')
file.write(f'-Xms{memory_limit}G -Xmx{memory_limit}G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=40 -XX:G1MaxNewSizePercent=50 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=15 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=20 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -javaagent:authlib-injector.jar=https://skin.mealuet.com/api/yggdrasil')
5 changes: 5 additions & 0 deletions server/prep_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from jproperties import Properties

from server.bluemap_config import download_bluemap, config_bluemap
from server.jre_config import check_lib_exist, download_lib, add_jre_args
from utils.server_icon import server_icon

Expand Down Expand Up @@ -50,6 +51,7 @@ def _config_server_icon(
def prep_server(
server_path: str,
game_version: str,
loader: str,
memory_limit: str,
pack_name: str
):
Expand All @@ -67,3 +69,6 @@ def prep_server(
log.info('jre args added. ')
_config_server_icon(server_path)
log.info('server-icon added. ')
download_bluemap(server_path, loader, game_version)
config_bluemap(server_path)
log.info('bluemap configs added. ')

0 comments on commit 61ca31d

Please sign in to comment.