mcserver-cli 3.0.0__py3-none-any.whl → 4.0.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcserver/__init__.py +1 -1
- mcserver/app.py +13 -9
- mcserver/caching.py +16 -0
- mcserver/cli.py +117 -71
- mcserver/commands/__init__.py +1 -1
- mcserver/commands/add_projects.py +144 -3
- mcserver/commands/import_setup.py +7 -4
- mcserver/commands/initialize_server.py +17 -4
- mcserver/commands/list_projects.py +6 -4
- mcserver/commands/op_grant.py +6 -4
- mcserver/commands/op_list.py +4 -4
- mcserver/commands/op_revoke.py +6 -4
- mcserver/commands/remove_projects.py +6 -4
- mcserver/commands/search_projects.py +106 -4
- mcserver/commands/server_status.py +6 -4
- mcserver/commands/show_projects.py +20 -17
- mcserver/commands/start_server.py +22 -9
- mcserver/commands/stop_server.py +8 -24
- mcserver/commands/update_projects.py +6 -4
- mcserver/commands/whitelist_add.py +6 -4
- mcserver/commands/whitelist_list.py +4 -3
- mcserver/commands/whitelist_remove.py +30 -28
- mcserver/config.py +45 -16
- mcserver/constants.py +0 -2
- mcserver/mcserver_v2.0.0.py +1119 -0
- mcserver/metadata.py +2 -2
- mcserver/modrinth/api.py +158 -47
- mcserver/modrinth/apis/__init__.py +9 -0
- mcserver/modrinth/apis/get_project_informations.py +216 -0
- mcserver/modrinth/apis/get_project_versions.py +131 -0
- mcserver/modrinth/apis/search_projects.py +122 -0
- mcserver/modrinth/constants.py +1 -0
- mcserver/modrinth/paths.py +3 -0
- mcserver/modrinth/project_records/relationships.py +5 -3
- mcserver/modrinth/project_records/shared.py +1 -2
- mcserver/modrinth/project_records.py +104 -0
- mcserver/modrinth/shared.py +86 -6
- mcserver/modrinth/slug_index.py +105 -9
- mcserver/modrinth/typings/__init__.py +38 -0
- mcserver/modrinth/typings/project_informations.py +137 -0
- mcserver/modrinth/typings/search_projects.py +94 -0
- mcserver/modrinth/typings/shared.py +17 -0
- mcserver/mysterious.py +22 -2
- mcserver/networking.py +14 -7
- mcserver/paths.py +18 -0
- mcserver/resolver.py +63 -14
- mcserver/server_files/properties.py +8 -7
- mcserver/server_files/whitelist.py +60 -39
- mcserver/shared.py +59 -17
- mcserver/state.py +22 -14
- {mcserver_cli-3.0.0.dist-info → mcserver_cli-4.0.0.dev0.dist-info}/METADATA +22 -15
- mcserver_cli-4.0.0.dev0.dist-info/RECORD +73 -0
- {mcserver_cli-3.0.0.dist-info → mcserver_cli-4.0.0.dev0.dist-info}/WHEEL +1 -1
- mcserver_cli-4.0.0.dev0.dist-info/entry_points.txt +2 -0
- mcserver_cli-4.0.0.dev0.dist-info/licenses/LICENSE +9 -0
- mcserver/commandsa.py +0 -1297
- mcserver_cli-3.0.0.dist-info/RECORD +0 -61
- mcserver_cli-3.0.0.dist-info/entry_points.txt +0 -2
- mcserver_cli-3.0.0.dist-info/licenses/LICENSE +0 -9
|
@@ -1,7 +1,109 @@
|
|
|
1
|
-
import
|
|
1
|
+
from argparse import Namespace
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
def main(args:
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
def main(args: Namespace) -> int:
|
|
5
|
+
from ..modrinth.shared import SearchSortIndex
|
|
6
|
+
|
|
7
|
+
search_query: list[str] = args.search_query
|
|
8
|
+
search_limit: int = args.search_limit
|
|
9
|
+
page_number: int = args.page_number
|
|
10
|
+
sort_index: SearchSortIndex = args.sort_index
|
|
11
|
+
game_version: str = args.game_version
|
|
12
|
+
no_version: str = args.no_version
|
|
13
|
+
loader_name: str = args.loader_name
|
|
14
|
+
|
|
15
|
+
import logging as log
|
|
16
|
+
|
|
17
|
+
from .. import config, shared
|
|
18
|
+
from ..modrinth.apis import search_projects
|
|
19
|
+
from ..shared import (
|
|
20
|
+
format_number,
|
|
21
|
+
pluralize,
|
|
22
|
+
project_environment_name,
|
|
23
|
+
set_loader_context,
|
|
24
|
+
wrap_ansi,
|
|
25
|
+
wrap_string,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
# def search_projects(**kargs) -> SearchResult:
|
|
29
|
+
# return {
|
|
30
|
+
# "search_hits": [],
|
|
31
|
+
# "search_limit": 20,
|
|
32
|
+
# "result_offset": 0,
|
|
33
|
+
# "total_hits": 0,
|
|
34
|
+
# }
|
|
35
|
+
# # return {'search_hits': [{'project_id': '9qGn08Dr', 'project_type': 'mod', 'all_project_types': ['mod'], 'project_name': 'ThDilos Fox Origin', 'short_description': 'An over-complicated fox origin where I put too many fox-related powers inside.', 'author_username': 'ThDilos', 'categories': ['adventure', 'fabric', 'forge', 'game-mechanics', 'quilt'], 'display_categories': ['adventure', 'fabric', 'forge', 'game-mechanics', 'quilt'], 'minecraft_versions': ['1.18.2', '1.19', '1.19.1', '1.19.2', '1.19.3', '1.19.4', '1.20', '1.20.1', '1.20.2', '1.20.3', '1.20.4', '1.21', '1.21.1'], 'download_count': 96219, 'follow_count': 40, 'icon_url': 'https://cdn.modrinth.com/data/9qGn08Dr/432d8b7d6cda9227825f50443bff27461d0ff997_96.webp', 'created_time': '2023-12-13T20:03:02.822201+00:00', 'last_modified_time': '2026-07-27T10:35:41.317016+00:00', 'latest_version_id': 'I7O90meo', 'license_id': 'LicenseRef-All-Rights-Reserved', 'project_environments': ['client_and_server'], 'disclosure_types': [], 'gallery_image_urls': ['https://cdn.modrinth.com/data/9qGn08Dr/images/8a522d7f823371fd371533e5727c0f2b8acefe08_350.webp', 'https://cdn.modrinth.com/data/9qGn08Dr/images/19f8f676593908c0329542f6568a93d6824acf02_350.webp', 'https://cdn.modrinth.com/data/9qGn08Dr/images/87d44a9b3a0d464c9a41ee4faf1b83938dcd07d5_350.webp', 'https://cdn.modrinth.com/data/9qGn08Dr/images/714307e28d1ad5538ec71c51040c534d8d3637cf_350.webp', 'https://cdn.modrinth.com/data/9qGn08Dr/images/00bd3166b4130063b9fb946cacb014584b30a8fe_350.webp', 'https://cdn.modrinth.com/data/9qGn08Dr/images/1ff8871382c619b692da5438793ca615d57c7e16_350.webp', 'https://cdn.modrinth.com/data/9qGn08Dr/images/8f71592272423f512089b09424d6d0816605dca2_350.webp', 'https://cdn.modrinth.com/data/9qGn08Dr/images/b18e3146e9f6237838636b33fb76be4da0aa8979_350.webp'], 'client_side': 'required', 'server_side': 'required', 'project_slug': 'thdilos-fox-origin', 'author_id': 'Y84X5Qzc', 'organization_name': None, 'organization_id': None, 'featured_gallery': 'https://cdn.modrinth.com/data/9qGn08Dr/images/06569913c8dcd8575a2b45310292cd2afb37ef41_350.webp', 'icon_color': 4277028}, {'project_id': 'CbsRGXBx', 'project_type': 'mod', 'all_project_types': ['mod'], 'project_name': 'ThDilos Fox Origin Expanded', 'short_description': 'Provide evolutions for my basic fox origin', 'author_username': 'ThDilos', 'categories': ['adventure', 'fabric', 'forge', 'game-mechanics', 'magic', 'quilt'], 'display_categories': ['adventure', 'fabric', 'forge', 'game-mechanics', 'quilt'], 'minecraft_versions': ['1.19', '1.19.1', '1.19.2', '1.19.3', '1.19.4', '1.20', '1.20.1', '1.20.2', '1.20.3', '1.20.4', '1.21.1'], 'download_count': 13980, 'follow_count': 19, 'icon_url': 'https://cdn.modrinth.com/data/CbsRGXBx/444adda2d53796e13f79a16520301359dd980d4b_96.webp', 'created_time': '2024-02-25T07:09:12.596453+00:00', 'last_modified_time': '2026-07-27T10:38:17.959565+00:00', 'latest_version_id': 'bqzwnjIQ', 'license_id': 'LicenseRef-All-Rights-Reserved', 'project_environments': ['client_and_server'], 'disclosure_types': [], 'gallery_image_urls': ['https://cdn.modrinth.com/data/CbsRGXBx/images/2c80424f463775190b8a787927277e3ed3b24936_350.webp', 'https://cdn.modrinth.com/data/CbsRGXBx/images/0972a59ef0d1deb0fb4ffafb9301a4c2a89f0d5b_350.webp', 'https://cdn.modrinth.com/data/CbsRGXBx/images/771164dcaf4319ad3849f9fc952386e7dd5fb42a_350.webp', 'https://cdn.modrinth.com/data/CbsRGXBx/images/49e0f103391b3cf3d48ea213d01f640ef00867c7_350.webp', 'https://cdn.modrinth.com/data/CbsRGXBx/images/444adda2d53796e13f79a16520301359dd980d4b_350.webp', 'https://cdn.modrinth.com/data/CbsRGXBx/images/6ec190812e14d91b26a13e69204c0b67c3e3020c_350.webp'], 'client_side': 'required', 'server_side': 'required', 'project_slug': 'thdilos-fox-origin-expanded', 'author_id': 'Y84X5Qzc', 'organization_name': None, 'organization_id': None, 'featured_gallery': None, 'icon_color': 9268566}, {'project_id': '7Qe9Oj35', 'project_type': 'mod', 'all_project_types': ['mod'], 'project_name': 'DelTime', 'short_description': 'DelTime (Deletion Timer) is a client-side Minecraft mod that displays the remaining time before dropped items despawn.', 'author_username': 'THDev', 'categories': ['fabric', 'game-mechanics', 'utility'], 'display_categories': ['fabric', 'game-mechanics', 'utility'], 'minecraft_versions': ['1.21.8'], 'download_count': 270, 'follow_count': 3, 'icon_url': 'https://cdn.modrinth.com/data/7Qe9Oj35/c8b8cb15c6b77cbad10ecc4d5ef2ea1add393fc9_96.webp', 'created_time': '2025-09-07T04:09:18.167861+00:00', 'last_modified_time': '2025-09-03T21:20:46.467208+00:00', 'latest_version_id': 'iSPu4l6f', 'license_id': 'MIT', 'project_environments': ['client_only'], 'disclosure_types': [], 'gallery_image_urls': [], 'client_side': 'required', 'server_side': 'unsupported', 'project_slug': 'deltime', 'author_id': 'o2UCko8K', 'organization_name': None, 'organization_id': None, 'featured_gallery': None, 'icon_color': 12277025}, {'project_id': 'zfCCoCH5', 'project_type': 'mod', 'all_project_types': ['plugin'], 'project_name': 'tiny server', 'short_description': 'Simple web server for minecraft', 'author_username': 'THDev', 'categories': ['bukkit', 'paper', 'purpur', 'spigot', 'utility'], 'display_categories': ['bukkit', 'paper', 'purpur', 'spigot', 'utility'], 'minecraft_versions': ['1.21', '1.21.1', '1.21.2', '1.21.3', '1.21.4', '1.21.5', '1.21.6', '1.21.7', '1.21.8'], 'download_count': 208, 'follow_count': 5, 'icon_url': 'https://cdn.modrinth.com/data/zfCCoCH5/583244c1442c74e30e02fdafca8d2eaf9763b3d7_96.webp', 'created_time': '2025-04-13T01:40:13.906052+00:00', 'last_modified_time': '2025-08-11T23:21:10.564333+00:00', 'latest_version_id': 'j0s8cJU3', 'license_id': 'MIT', 'project_environments': [], 'disclosure_types': [], 'gallery_image_urls': [], 'client_side': 'unsupported', 'server_side': 'required', 'project_slug': 'tiny-server', 'author_id': 'o2UCko8K', 'organization_name': None, 'organization_id': None, 'featured_gallery': None, 'icon_color': 263172}, {'project_id': 'wSjVO4Pj', 'project_type': 'modpack', 'all_project_types': ['modpack'], 'project_name': 'Exploreaneer', 'short_description': 'exploreaneer aims to make minecraft exploration more fun and exsiting.', 'author_username': 'thDUCKlord', 'categories': ['adventure', 'challenging', 'combat', 'fabric'], 'display_categories': ['adventure', 'challenging', 'combat'], 'minecraft_versions': ['1.21.1'], 'download_count': 137, 'follow_count': 2, 'icon_url': 'https://cdn.modrinth.com/data/wSjVO4Pj/7fce13ae067565835ea3103704168194c486a73b_96.webp', 'created_time': '2025-04-24T09:09:39.548512+00:00', 'last_modified_time': '2025-04-17T01:21:56.365247+00:00', 'latest_version_id': '3Jy2Gusu', 'license_id': 'LicenseRef-All-Rights-Reserved', 'project_environments': ['client_and_server'], 'disclosure_types': [], 'gallery_image_urls': ['https://cdn.modrinth.com/data/wSjVO4Pj/images/102c2d5bb0244b12e9fc229662a3aef726e703e3_350.webp', 'https://cdn.modrinth.com/data/wSjVO4Pj/images/37feee9f350dcee5083a7cd1f311a29c3b6a610b.jpeg'], 'client_side': 'required', 'server_side': 'required', 'project_slug': 'exploreaneer', 'author_id': 'O9f75qK4', 'organization_name': None, 'organization_id': None, 'featured_gallery': None, 'icon_color': 9655861}, {'project_id': '2ZfChMmF', 'project_type': 'mod', 'all_project_types': ['mod'], 'project_name': 'Boop Utils', 'short_description': 'A Simple Collections of Boop Utilities for some Hypixel Sillies :3', 'author_username': 'ThDilos', 'categories': ['fabric', 'utility'], 'display_categories': ['fabric', 'utility'], 'minecraft_versions': ['1.21.5', '1.21.11'], 'download_count': 120, 'follow_count': 0, 'icon_url': 'https://cdn.modrinth.com/data/2ZfChMmF/05c41decf80b191eb5136057d1c9a2fa6c9fa3b7_96.webp', 'created_time': '2025-08-21T06:24:24.524391+00:00', 'last_modified_time': '2025-08-25T09:44:16.346497+00:00', 'latest_version_id': 'UfNBiuVS', 'license_id': 'LicenseRef-All-Rights-Reserved', 'project_environments': ['client_only'], 'disclosure_types': [], 'gallery_image_urls': [], 'client_side': 'required', 'server_side': 'unsupported', 'project_slug': 'boop-utils', 'author_id': 'Y84X5Qzc', 'organization_name': None, 'organization_id': None, 'featured_gallery': 'https://cdn.modrinth.com/data/2ZfChMmF/images/05c41decf80b191eb5136057d1c9a2fa6c9fa3b7_350.webp', 'icon_color': 16569452}, {'project_id': '6ucW7Iwn', 'project_type': 'mod', 'all_project_types': ['mod'], 'project_name': 'LongScoreStat', 'short_description': 'This mod modifies the statistics and scoreboards of minecraft to use 64bit values instead of 32bit values', 'author_username': 'thdaele', 'categories': ['fabric', 'ornithe'], 'display_categories': ['fabric', 'ornithe'], 'minecraft_versions': ['1.12.2', '1.17.1'], 'download_count': 112, 'follow_count': 0, 'icon_url': '', 'created_time': '2025-10-22T04:41:53.013045+00:00', 'last_modified_time': '2025-10-21T11:05:10.240614+00:00', 'latest_version_id': '2Dr7XDeR', 'license_id': 'LGPL-3.0-or-later', 'project_environments': ['server_only_client_optional'], 'disclosure_types': [], 'gallery_image_urls': [], 'client_side': 'optional', 'server_side': 'required', 'project_slug': 'longscorestat', 'author_id': 'JRzhIykz', 'organization_name': 'Bismuth', 'organization_id': '3qbrStjh', 'featured_gallery': None, 'icon_color': None}, {'project_id': 'B38Erf5M', 'project_type': 'mod', 'all_project_types': ['plugin'], 'project_name': 'TME', 'short_description': 'TMEPlugin — TNT Minecart Explosion Timer Control', 'author_username': 'THDev', 'categories': ['paper', 'purpur', 'spigot', 'utility'], 'display_categories': ['paper', 'purpur', 'spigot', 'utility'], 'minecraft_versions': ['1.18', '1.18.1', '1.18.2', '1.19', '1.19.1', '1.19.2', '1.19.3', '1.19.4', '1.20', '1.20.1', '1.20.2', '1.20.3', '1.20.4', '1.20.5', '1.20.6', '1.21', '1.21.1', '1.21.2', '1.21.3', '1.21.4', '1.21.5', '1.21.6', '1.21.7'], 'download_count': 74, 'follow_count': 0, 'icon_url': '', 'created_time': '2025-07-11T04:00:37.343892+00:00', 'last_modified_time': '2025-07-04T19:44:42.915833+00:00', 'latest_version_id': 'FzHLdP3J', 'license_id': 'MIT', 'project_environments': [], 'disclosure_types': [], 'gallery_image_urls': [], 'client_side': 'unsupported', 'server_side': 'required', 'project_slug': 'tme-plugin', 'author_id': 'o2UCko8K', 'organization_name': None, 'organization_id': None, 'featured_gallery': None, 'icon_color': None}], 'result_offset': 0, 'search_limit': 10, 'total_hits': 8}
|
|
36
|
+
|
|
37
|
+
server_config = {}
|
|
38
|
+
|
|
39
|
+
if not (loader_name and game_version):
|
|
40
|
+
try:
|
|
41
|
+
server_config = config.load_config("server")
|
|
42
|
+
except FileNotFoundError:
|
|
43
|
+
pass # ignore because it doesn't really need the config. just as "personalization" per server
|
|
44
|
+
|
|
45
|
+
game_version = game_version or server_config.get("game_version", "")
|
|
46
|
+
loader_name = loader_name or server_config.get("loader", {}).get("name", "")
|
|
47
|
+
|
|
48
|
+
if no_version:
|
|
49
|
+
game_version = ""
|
|
50
|
+
|
|
51
|
+
if not loader_name:
|
|
52
|
+
loader_name = "vanilla"
|
|
53
|
+
elif loader_name != "vanilla":
|
|
54
|
+
set_loader_context(loader_name)
|
|
55
|
+
|
|
56
|
+
search_offset = search_limit * (page_number - 1)
|
|
57
|
+
|
|
58
|
+
search_info = f"Searching {pluralize(shared.loader_context['project_label'])}"
|
|
59
|
+
|
|
60
|
+
if search_query:
|
|
61
|
+
search_info += f" with '{' '.join(search_query)}'"
|
|
62
|
+
|
|
63
|
+
search_info += f" for {loader_name.capitalize()}"
|
|
64
|
+
|
|
65
|
+
if game_version:
|
|
66
|
+
search_info += f", Minecraft {game_version}"
|
|
67
|
+
|
|
68
|
+
search_info += f", sorted by {sort_index}"
|
|
69
|
+
|
|
70
|
+
log.info(search_info + "...")
|
|
71
|
+
search_result = search_projects(
|
|
72
|
+
search_query=search_query,
|
|
73
|
+
sort_index=sort_index,
|
|
74
|
+
search_limit=search_limit,
|
|
75
|
+
search_offset=search_offset,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
search_hits = search_result["search_hits"]
|
|
79
|
+
if len(search_hits) == 0:
|
|
80
|
+
log.error(f"No {shared.loader_context['project_label']} found.")
|
|
81
|
+
|
|
82
|
+
for count, hit in enumerate(search_hits):
|
|
83
|
+
slug_or_id = hit["project_slug"] if "project_slug" in hit else hit["project_id"]
|
|
84
|
+
project_author = wrap_ansi(f"by {hit['author_username']}", "gray")
|
|
85
|
+
|
|
86
|
+
project_environments = []
|
|
87
|
+
if len(hit["project_environments"]) == 0:
|
|
88
|
+
project_environments.append("No environment")
|
|
89
|
+
else:
|
|
90
|
+
for project_environment in hit["project_environments"]:
|
|
91
|
+
project_environments.append(
|
|
92
|
+
project_environment_name(project_environment)
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
print(
|
|
96
|
+
f"{wrap_ansi(hit['project_name'], 'bold')} ({slug_or_id}) {project_author}"
|
|
97
|
+
)
|
|
98
|
+
print(
|
|
99
|
+
f"> {', '.join(project_environments)} | Downloads: {format_number(hit['download_count'])} | Follows: {format_number(hit['follow_count'])}"
|
|
100
|
+
)
|
|
101
|
+
print(f"> https://modrinth.com/{hit['project_type']}/{slug_or_id}")
|
|
102
|
+
print(
|
|
103
|
+
wrap_string(hit["short_description"], initial_indent=2, subsequent_indent=1)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
if (count + 1) < len(search_hits):
|
|
107
|
+
print() # Print newline for readability
|
|
108
|
+
|
|
7
109
|
return 0
|
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
from argparse import Namespace
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
def main(args:
|
|
4
|
+
def main(args: Namespace) -> int:
|
|
5
5
|
projects: list[str] = args.projects
|
|
6
|
+
import logging as log
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
from ..shared import format_number
|
|
8
|
+
log.error("Command is not implemented yet.")
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if "project_title" in project and "project_slug" in project:
|
|
13
|
-
print(f"Name: {project['project_title']} ({project['project_slug']})")
|
|
10
|
+
# from ..modrinth import api as modrinth_api
|
|
11
|
+
# from ..shared import format_number
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
# project_information = modrinth_api.get_project_information(projects)
|
|
14
|
+
# for project in project_information:
|
|
15
|
+
# if "project_title" in project and "project_slug" in project:
|
|
16
|
+
# print(f"Name: {project['project_title']} ({project['project_slug']})")
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
# if "download_count" in project:
|
|
19
|
+
# print(f"Downloads: {format_number(project['download_count'])}")
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
f"Homepage: https://modrinth.com/{project['project_type']}/{project['project_slug']}"
|
|
24
|
-
)
|
|
21
|
+
# if "follower_count" in project:
|
|
22
|
+
# print(f"Followers: {format_number(project["follower_count"])}")
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
# if "project_slug" in project:
|
|
25
|
+
# print(
|
|
26
|
+
# f"Homepage: https://modrinth.com/{project['project_type']}/{project['project_slug']}"
|
|
27
|
+
# )
|
|
28
|
+
|
|
29
|
+
return 1
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
from argparse import Namespace
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
def main(args:
|
|
4
|
+
def main(args: Namespace) -> int:
|
|
5
5
|
import logging as log
|
|
6
6
|
|
|
7
7
|
from .. import state
|
|
8
8
|
|
|
9
9
|
# Check MCServer status
|
|
10
|
+
if not state.state_file.parent.exists():
|
|
11
|
+
log.error("State file not exist, is MCServer initialized?")
|
|
12
|
+
return 1
|
|
13
|
+
|
|
10
14
|
current_state = state.get_state()
|
|
11
15
|
if current_state["is_active"]:
|
|
12
16
|
log.error(
|
|
13
|
-
f"There's another active MCServer process ({current_state[
|
|
17
|
+
f"There's another active MCServer process ({current_state['action']}) running with process ID: {current_state['process_id']}"
|
|
14
18
|
)
|
|
15
19
|
return 1
|
|
16
20
|
|
|
@@ -45,7 +49,7 @@ def main(args: argparse.Namespace) -> int:
|
|
|
45
49
|
loader_version = server_loader["version"]
|
|
46
50
|
|
|
47
51
|
if loader_name != "vanilla" and loader_version is None:
|
|
48
|
-
log.error(
|
|
52
|
+
log.error("Loader version cannot be null")
|
|
49
53
|
return 1
|
|
50
54
|
|
|
51
55
|
match loader_name:
|
|
@@ -79,16 +83,24 @@ def main(args: argparse.Namespace) -> int:
|
|
|
79
83
|
download_prop = papermc_api.get_project_build(
|
|
80
84
|
"paper", game_version, loader_version
|
|
81
85
|
)["download_props"]["server:default"]
|
|
82
|
-
networking.download(
|
|
86
|
+
networking.download(
|
|
87
|
+
download_prop["download_url"],
|
|
88
|
+
jarfile,
|
|
89
|
+
hashes=download_prop["file_hashes"],
|
|
90
|
+
)
|
|
83
91
|
case "purpur":
|
|
84
92
|
from ..purpurmc import api as purpurmc_api
|
|
85
93
|
|
|
86
94
|
log.info(
|
|
87
95
|
f"Downloading Purpur build {loader_version} for Minecraft version {game_version}..."
|
|
88
96
|
)
|
|
97
|
+
project_build = purpurmc_api.get_project_build(
|
|
98
|
+
"purpur", game_version, loader_version
|
|
99
|
+
)
|
|
89
100
|
networking.download(
|
|
90
101
|
purpurmc_api.download_url("purpur", game_version, loader_version),
|
|
91
102
|
jarfile,
|
|
103
|
+
hashes={"md5": project_build["artifact_md5"]},
|
|
92
104
|
)
|
|
93
105
|
|
|
94
106
|
# Vanilla
|
|
@@ -120,11 +132,14 @@ def main(args: argparse.Namespace) -> int:
|
|
|
120
132
|
hashes={"sha1": version_download["sha1"]},
|
|
121
133
|
)
|
|
122
134
|
case _:
|
|
123
|
-
log.error(
|
|
135
|
+
log.error(
|
|
136
|
+
f"Loader is not supported ({loader_name}), you may have to edit '.mcserver/configs/server.json' to fix it."
|
|
137
|
+
)
|
|
138
|
+
return 1
|
|
124
139
|
|
|
125
140
|
# Check stuff
|
|
126
141
|
if not shutil.which("java"):
|
|
127
|
-
log.error("
|
|
142
|
+
log.error("'java' not found")
|
|
128
143
|
return 1
|
|
129
144
|
|
|
130
145
|
if memory_config["min"] > memory_config["max"]:
|
|
@@ -145,6 +160,4 @@ def main(args: argparse.Namespace) -> int:
|
|
|
145
160
|
|
|
146
161
|
# Execute java
|
|
147
162
|
log.debug(f"Executing command: {' '.join(java_command_argv)}")
|
|
148
|
-
|
|
149
|
-
state.set_state("server_running")
|
|
150
163
|
os.execvp(java_command_argv[0], java_command_argv)
|
mcserver/commands/stop_server.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
from argparse import Namespace
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
def main(args:
|
|
4
|
+
def main(args: Namespace) -> int:
|
|
5
5
|
# CLI arguments
|
|
6
6
|
force_stop: bool = args.force_stop
|
|
7
7
|
|
|
8
8
|
import logging as log
|
|
9
9
|
import os
|
|
10
|
-
from signal import
|
|
10
|
+
from signal import SIGTERM
|
|
11
11
|
|
|
12
12
|
from .. import state
|
|
13
13
|
|
|
@@ -21,26 +21,10 @@ def main(args: argparse.Namespace) -> int:
|
|
|
21
21
|
log.error("Server is not running.")
|
|
22
22
|
return 1
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
current_state = state.get_state()
|
|
28
|
-
if current_state["is_active"]:
|
|
29
|
-
return 0
|
|
30
|
-
|
|
31
|
-
if not force_stop:
|
|
32
|
-
log.warning(
|
|
33
|
-
"Server appears to still be running, you may stop the server manually."
|
|
34
|
-
)
|
|
24
|
+
if "process_id" not in current_state:
|
|
25
|
+
log.info("Process ID is not in state file")
|
|
35
26
|
return 1
|
|
36
27
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
launcher_config = config.load_config("launcher")
|
|
42
|
-
time.sleep(launcher_config["force_stop"])
|
|
43
|
-
|
|
44
|
-
log.warning("Server process is still running, force stopping the server...")
|
|
45
|
-
os.kill(current_state["process_id"], SIGKILL)
|
|
46
|
-
return 1
|
|
28
|
+
log.info(f"Sending Sigterm to prpcess ID {current_state['process_id']}")
|
|
29
|
+
os.kill(current_state["process_id"], SIGTERM)
|
|
30
|
+
return 0
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
from argparse import Namespace
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
def main(args:
|
|
4
|
+
def main(args: Namespace) -> int:
|
|
5
5
|
players: list[str] = args.players
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import logging as log
|
|
7
|
+
|
|
8
|
+
log.error("Command is not implemented yet.")
|
|
9
|
+
return 1
|
|
@@ -7,11 +7,12 @@ def main(args: argparse.Namespace) -> int:
|
|
|
7
7
|
from ..server_files import whitelist
|
|
8
8
|
from ..shared import pluralize
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
whitelist_file = whitelist.whitelist_file
|
|
11
|
+
if not whitelist_file.exists():
|
|
12
|
+
log.error(f"Whitelist file ({whitelist_file}) does not exist!")
|
|
12
13
|
return 1
|
|
13
14
|
|
|
14
|
-
whitelisted_players = whitelist.
|
|
15
|
+
whitelisted_players = whitelist.list_entries()
|
|
15
16
|
|
|
16
17
|
player_list: list[str] = []
|
|
17
18
|
for player in whitelisted_players:
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
from uuid import UUID
|
|
3
|
-
from ..server_files.whitelist import remove_players
|
|
4
|
-
from ..minecraft.player_identity import PlayerID
|
|
1
|
+
from argparse import Namespace
|
|
5
2
|
|
|
6
|
-
import logging as log
|
|
7
3
|
|
|
8
|
-
|
|
9
|
-
def main(args: argparse.Namespace) -> int:
|
|
4
|
+
def main(args: Namespace) -> int:
|
|
10
5
|
players: list[str] = args.players
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
6
|
+
import logging as log
|
|
7
|
+
|
|
8
|
+
# from uuid import UUID
|
|
9
|
+
# from ..server_files.whitelist import remove_players
|
|
10
|
+
# from ..minecraft.player_identity import PlayerID
|
|
11
|
+
|
|
12
|
+
log.error("Command is not implemented yet.")
|
|
13
|
+
# player_ids: list[PlayerID] = []
|
|
14
|
+
# for player in players:
|
|
15
|
+
# try:
|
|
16
|
+
# UUID(player)
|
|
17
|
+
# log.debug(f"{player} is likely an UUID")
|
|
18
|
+
# player_id: PlayerID = {"player_uuid": player}
|
|
19
|
+
|
|
20
|
+
# player_ids.append(player_id)
|
|
21
|
+
# except ValueError:
|
|
22
|
+
# log.debug(f"{player} is likely a name")
|
|
23
|
+
# player_id: PlayerID = {"player_name": player}
|
|
24
|
+
|
|
25
|
+
# player_ids.append(player_id)
|
|
26
|
+
|
|
27
|
+
# try:
|
|
28
|
+
# remove_players(player_ids)
|
|
29
|
+
# except FileNotFoundError as error:
|
|
30
|
+
# log.error(error)
|
|
31
|
+
# return 1
|
|
32
|
+
|
|
33
|
+
return 1
|
mcserver/config.py
CHANGED
|
@@ -4,34 +4,63 @@ import json
|
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
6
|
# MCServer
|
|
7
|
-
from .
|
|
7
|
+
from .paths import configs_dir
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
|
|
10
|
+
class ConfigVersionError(Exception):
|
|
11
|
+
pass
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
# Functions
|
|
14
|
-
def
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
def write_config(
|
|
16
|
+
config_name: str, format_version: int, config_data: dict[str, Any]
|
|
17
|
+
) -> None:
|
|
18
|
+
"""Write the configuration data to a file
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
Args:
|
|
21
|
+
config_name: The name of the configuration
|
|
22
|
+
format_version: The format version of this configuration data
|
|
23
|
+
config_data: The configuration data
|
|
20
24
|
|
|
25
|
+
Raises:
|
|
26
|
+
FileNotFoundError: The configuration directory does not exist
|
|
27
|
+
"""
|
|
28
|
+
if not configs_dir.exists():
|
|
29
|
+
raise FileNotFoundError(
|
|
30
|
+
f"COnfiguration directory '{configs_dir}' does not exist"
|
|
31
|
+
)
|
|
21
32
|
|
|
22
|
-
def load_config(config_name: str) -> dict[str, Any]:
|
|
23
33
|
config_filename = f"{config_name}.json"
|
|
24
34
|
config_path = configs_dir / config_filename
|
|
35
|
+
config_data["format_version"] = format_version
|
|
36
|
+
|
|
37
|
+
config_json = json.dumps(config_data)
|
|
38
|
+
config_path.write_text(config_json)
|
|
39
|
+
|
|
25
40
|
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
def read_config(config_name: str, current_format_version: int) -> dict[str, Any]:
|
|
42
|
+
"""Read a configuration file
|
|
28
43
|
|
|
44
|
+
Args:
|
|
45
|
+
config_name: The name of the configuration
|
|
46
|
+
current_format_version: The current format version for the configuration
|
|
47
|
+
|
|
48
|
+
Raises:
|
|
49
|
+
FileNotFoundError: The configuration file does not exist
|
|
50
|
+
"""
|
|
29
51
|
|
|
30
|
-
def update_config(config_name: str, new_data: dict[str, Any]) -> None:
|
|
31
52
|
config_filename = f"{config_name}.json"
|
|
32
53
|
config_path = configs_dir / config_filename
|
|
33
54
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
55
|
+
if not config_path.exists():
|
|
56
|
+
raise FileNotFoundError(
|
|
57
|
+
f"Configuration file for '{config_name}' does not exist"
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
config_json = config_path.read_text()
|
|
61
|
+
config_data = json.loads(config_json)
|
|
62
|
+
|
|
63
|
+
if config_data["format_version"] > current_format_version:
|
|
64
|
+
raise ConfigVersionError("")
|
|
65
|
+
|
|
66
|
+
return config_data
|