-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rewrite test structure, support some forge versions * pylint * pylint * lazily start output thread
- Loading branch information
Showing
19 changed files
with
449 additions
and
149 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"""Module containing all McServerWrapper-related errors""" | ||
|
||
class McServerWrapperError(Exception): | ||
"""The base exception, can be used to catch all other McServerWrapper-related errors""" | ||
|
||
class ServerExitedError(McServerWrapperError): | ||
"""An error occuring if the minecraft server unexpectedly crashed""" |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""Module containing the ForgeServer class""" | ||
|
||
from __future__ import annotations | ||
|
||
import json | ||
import os | ||
import re | ||
from zipfile import ZipFile | ||
from .base_server import BaseServer | ||
from ..mcversion import McVersion, McVersionType | ||
|
||
class ForgeServer(BaseServer): | ||
""" | ||
Class representing a Forge server | ||
More info about Forge: https://minecraftforge.net/ | ||
""" | ||
|
||
VERSION_TYPE = McVersionType.FORGE | ||
|
||
def execute_command(self, command: str): | ||
if not command.startswith("/"): | ||
command = "/" + command | ||
|
||
super().execute_command(command) | ||
|
||
if command == "/stop": | ||
self._stopping() | ||
|
||
@classmethod | ||
def _check_jar(cls, jar_file: str) -> McVersion | None: | ||
"""Search the given jar file to find the version""" | ||
|
||
with ZipFile(jar_file, "r") as zf: | ||
# for Minecraft 1.14+ | ||
version_json = None | ||
for zip_fileinfo in zf.filelist: | ||
if zip_fileinfo.filename == "version.json": | ||
version_json = json.loads(zf.read(zip_fileinfo)) | ||
if version_json is not None: | ||
# regex for old forge versions | ||
pattern = r"^1\.[1-2]{0,1}[0-9](\.[0-9]{1,2})?\-[fF]orge" | ||
if re.search(pattern, version_json["id"]) is not None: | ||
vers = [x.group() for x in re.finditer(pattern, version_json["id"])] | ||
return McVersion(vers[0].split("-", maxsplit=1)[0], cls.VERSION_TYPE) | ||
|
||
# no version was found | ||
return None | ||
|
||
@classmethod | ||
def _check_jar_name(cls, jar_file: str) -> McVersion | None: | ||
"""Search the name of the given jar file to find the version""" | ||
|
||
jar_filename = jar_file.rsplit(os.sep, maxsplit=1)[1] | ||
|
||
# common filename pattern | ||
pattern = r"^forge-1\.[1-2]{0,1}[0-9](\.[0-9]{1,2})?\-.*.jar$" | ||
if re.search(pattern, jar_filename) is not None: | ||
vers = [x.group() for x in re.finditer(pattern, jar_filename)] | ||
return McVersion(vers[0].split("-", maxsplit=2)[1], cls.VERSION_TYPE) | ||
|
||
# no version was found | ||
return None |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.