mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Merge branch 'dev' into tweak/player-scroll-bar
This commit is contained in:
commit
52533c6dfc
@ -1,11 +1,14 @@
|
||||
# Changelog
|
||||
## --- [4.2.3] - 2023/TBD
|
||||
### New features
|
||||
TBD
|
||||
- Use Papermc Group's API for `paper` & `folia` builds in server builder ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/688))
|
||||
- Allow omission of player count from Dashboard (e.g. for proxy servers) ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/692))
|
||||
### Bug fixes
|
||||
TBD
|
||||
- Fix bukkit and downstream fork MOTD crash ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/686))
|
||||
- Fix bug where invalid server Id leads to stack ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/690))
|
||||
- Fix indent on public status check box ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/691))
|
||||
### Tweaks
|
||||
TBD
|
||||
- Refactor Forge server initialisation flow for newer versions ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/687))
|
||||
### Lang
|
||||
TBD
|
||||
<br><br>
|
||||
|
@ -462,7 +462,10 @@ class ServersController(metaclass=Singleton):
|
||||
|
||||
@staticmethod
|
||||
def server_id_exists(server_id):
|
||||
srv = ServersController().get_server_instance_by_id(server_id)
|
||||
try:
|
||||
srv = ServersController().get_server_instance_by_id(server_id)
|
||||
except ValueError:
|
||||
return False
|
||||
return srv.stats_helper.server_id_exists()
|
||||
|
||||
@staticmethod
|
||||
|
@ -12,6 +12,7 @@ from app.classes.minecraft.bedrock_ping import BedrockPing
|
||||
from app.classes.shared.console import Console
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
MOTD_CODES = ["bold", "italic", "underlined", "strikethrough"]
|
||||
|
||||
|
||||
class Server:
|
||||
@ -34,26 +35,27 @@ class Server:
|
||||
lines = []
|
||||
|
||||
description = self.description
|
||||
if "text" in description.keys():
|
||||
lines.append(description["text"])
|
||||
if "extra" in description.keys():
|
||||
for e in description["extra"]:
|
||||
# Conversion format code needed only for Java Version
|
||||
lines.append(get_code_format("reset"))
|
||||
if "bold" in e.keys():
|
||||
lines.append(get_code_format("bold"))
|
||||
if "italic" in e.keys():
|
||||
lines.append(get_code_format("italic"))
|
||||
if "underlined" in e.keys():
|
||||
lines.append(get_code_format("underlined"))
|
||||
if "strikethrough" in e.keys():
|
||||
lines.append(get_code_format("strikethrough"))
|
||||
if "color" in e.keys():
|
||||
lines.append(get_code_format(e["color"]))
|
||||
# Then append the text
|
||||
if "text" in e.keys():
|
||||
if e["text"] == "\n":
|
||||
lines.append("§§")
|
||||
else:
|
||||
lines.append(e["text"])
|
||||
if isinstance(description["extra"], list):
|
||||
for e in description["extra"]:
|
||||
if not isinstance(e, dict):
|
||||
lines.append(e)
|
||||
continue
|
||||
# Conversion format code needed only for Java Version
|
||||
lines.append(get_code_format("reset"))
|
||||
for item in MOTD_CODES:
|
||||
if e.get(item, False):
|
||||
lines.append(get_code_format(item))
|
||||
if "color" in e.keys():
|
||||
lines.append(get_code_format(e["color"]))
|
||||
# Then append the text
|
||||
if "text" in e.keys():
|
||||
if e["text"] == "\n":
|
||||
lines.append("§§")
|
||||
else:
|
||||
lines.append(e["text"])
|
||||
|
||||
total_text = " ".join(lines)
|
||||
self.description = total_text
|
||||
|
@ -11,12 +11,18 @@ from app.classes.models.server_permissions import PermissionsServers
|
||||
from app.classes.shared.websocket_manager import WebSocketManager
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
PAPERJARS = ["paper", "folia"]
|
||||
|
||||
|
||||
class ServerJars:
|
||||
def __init__(self, helper):
|
||||
self.helper = helper
|
||||
self.base_url = "https://serverjars.com"
|
||||
self.paper_base = "https://api.papermc.io"
|
||||
|
||||
@staticmethod
|
||||
def get_paper_jars():
|
||||
return PAPERJARS
|
||||
|
||||
def _get_api_result(self, call_url: str):
|
||||
full_url = f"{self.base_url}{call_url}"
|
||||
@ -38,6 +44,40 @@ class ServerJars:
|
||||
|
||||
return api_response
|
||||
|
||||
def get_paper_versions(self, project):
|
||||
try:
|
||||
response = requests.get(
|
||||
f"{self.paper_base}/v2/projects/{project}/", timeout=2
|
||||
)
|
||||
response.raise_for_status()
|
||||
api_data = json.loads(response.content)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Unable to load https://api.papermc.io/v2/projects/{project}/"
|
||||
f"api due to error: {e}"
|
||||
)
|
||||
return {}
|
||||
versions = api_data.get("versions", [])
|
||||
versions.reverse()
|
||||
return versions
|
||||
|
||||
def get_paper_build(self, project, version):
|
||||
try:
|
||||
response = requests.get(
|
||||
f"{self.paper_base}/v2/projects/{project}/versions/{version}/builds/",
|
||||
timeout=2,
|
||||
)
|
||||
response.raise_for_status()
|
||||
api_data = json.loads(response.content)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Unable to load https://api.papermc.io/v2/projects/{project}/"
|
||||
f"api due to error: {e}"
|
||||
)
|
||||
return {}
|
||||
build = api_data.get("builds", [])[-1]
|
||||
return build
|
||||
|
||||
def _read_cache(self):
|
||||
cache_file = self.helper.serverjar_cache
|
||||
cache = {}
|
||||
@ -95,6 +135,8 @@ class ServerJars:
|
||||
for j in data["types"].get(s):
|
||||
versions = self._get_jar_details(j, s)
|
||||
data["types"][s].update({j: versions})
|
||||
for item in PAPERJARS:
|
||||
data["types"]["servers"][item] = self.get_paper_versions(item)
|
||||
# save our cache
|
||||
try:
|
||||
with open(cache_file, "w", encoding="utf-8") as f:
|
||||
@ -133,6 +175,8 @@ class ServerJars:
|
||||
for j in data["types"].get(s):
|
||||
versions = self._get_jar_details(j, s)
|
||||
data["types"][s].update({j: versions})
|
||||
for item in PAPERJARS:
|
||||
data["types"]["servers"][item] = self.get_paper_versions(item)
|
||||
# save our cache
|
||||
try:
|
||||
with open(cache_file, "w", encoding="utf-8") as f:
|
||||
@ -171,7 +215,17 @@ class ServerJars:
|
||||
def a_download_jar(self, jar, server, version, path, server_id):
|
||||
# delaying download for server register to finish
|
||||
time.sleep(3)
|
||||
fetch_url = f"{self.base_url}/api/fetchJar/{jar}/{server}/{version}"
|
||||
if server not in PAPERJARS:
|
||||
fetch_url = f"{self.base_url}/api/fetchJar/{jar}/{server}/{version}"
|
||||
else:
|
||||
build = self.get_paper_build(server, version).get("build", None)
|
||||
if not build:
|
||||
return
|
||||
fetch_url = (
|
||||
f"{self.paper_base}/v2/projects"
|
||||
f"/{server}/versions/{version}/builds/{build}/downloads/"
|
||||
f"{server}-{version}-{build}.jar"
|
||||
)
|
||||
server_users = PermissionsServers.get_server_user_list(server_id)
|
||||
|
||||
# We need to make sure the server is registered before
|
||||
|
@ -42,6 +42,7 @@ class Servers(BaseModel):
|
||||
created_by = IntegerField(default=-100)
|
||||
shutdown_timeout = IntegerField(default=60)
|
||||
ignored_exits = CharField(default="0")
|
||||
count_players = BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
table_name = "servers"
|
||||
|
@ -536,10 +536,14 @@ class Controller:
|
||||
if data["create_type"] == "minecraft_java":
|
||||
if root_create_data["create_type"] == "download_jar":
|
||||
# modded update urls from server jars will only update the installer
|
||||
if create_data["category"] != "modded":
|
||||
if (
|
||||
create_data["category"] != "modded"
|
||||
and create_data["type"] not in ServerJars.get_paper_jars()
|
||||
):
|
||||
server_obj = self.servers.get_server_obj(new_server_id)
|
||||
url = (
|
||||
f"https://serverjars.com/api/fetchJar/{create_data['category']}"
|
||||
"https://serverjars.com/api/fetchJar/"
|
||||
f"{create_data['category']}"
|
||||
f"/{create_data['type']}/{create_data['version']}"
|
||||
)
|
||||
server_obj.executable_update_url = url
|
||||
|
@ -43,6 +43,7 @@ with redirect_stderr(NullWriter()):
|
||||
from psutil import NoSuchProcess
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
SUCCESSMSG = "SUCCESS! Forge install completed"
|
||||
|
||||
|
||||
def callback(called_func):
|
||||
@ -723,10 +724,11 @@ class ServerInstance:
|
||||
f' -jar "{file_name}" nogui'
|
||||
)
|
||||
server_obj.execution_command = execution_command
|
||||
Console.debug("SUCCESS! Forge install completed")
|
||||
Console.debug(SUCCESSMSG)
|
||||
|
||||
else:
|
||||
# NEW VERSION >= 1.17
|
||||
elif version_major <= 1 and version_minor < 20:
|
||||
# NEW VERSION >= 1.17 and <= 1.20
|
||||
# (no jar file in server dir, only run.bat and run.sh)
|
||||
|
||||
run_file_path = ""
|
||||
if self.helper.is_os_windows():
|
||||
@ -770,7 +772,38 @@ class ServerInstance:
|
||||
f" {server_command[4]}"
|
||||
)
|
||||
server_obj.execution_command = execution_command
|
||||
Console.debug("SUCCESS! Forge install completed")
|
||||
Console.debug(SUCCESSMSG)
|
||||
else:
|
||||
# NEW VERSION >= 1.20
|
||||
# (executable jar is back in server dir)
|
||||
|
||||
# Retrieving the executable jar filename
|
||||
file_path = glob.glob(
|
||||
f"{server_obj.path}/forge-{version[0][0]}*.jar"
|
||||
)[0]
|
||||
file_name = re.findall(
|
||||
r"(forge-[\-0-9.]+-shim.jar)",
|
||||
file_path,
|
||||
)[0]
|
||||
|
||||
# Let's set the proper server executable
|
||||
server_obj.executable = os.path.join(file_name)
|
||||
|
||||
# Get memory values
|
||||
memory_values = re.findall(
|
||||
r"-Xms([A-Z0-9\.]+) -Xmx([A-Z0-9\.]+)",
|
||||
server_obj.execution_command,
|
||||
)
|
||||
|
||||
# Now lets set up the new run command.
|
||||
# This is based off the run.sh/bat that
|
||||
# Forge uses in 1.17 and <
|
||||
execution_command = (
|
||||
f"java -Xms{memory_values[0][0]} -Xmx{memory_values[0][1]}"
|
||||
f' -jar "{file_name}" nogui'
|
||||
)
|
||||
server_obj.execution_command = execution_command
|
||||
Console.debug(SUCCESSMSG)
|
||||
except:
|
||||
logger.debug("Could not find run file.")
|
||||
# TODO Use regex to get version and rebuild simple execution
|
||||
@ -1560,6 +1593,7 @@ class ServerInstance:
|
||||
"version": raw_ping_result.get("version"),
|
||||
"icon": raw_ping_result.get("icon"),
|
||||
"crashed": self.is_crashed,
|
||||
"count_players": self.server_object.count_players,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -29,6 +29,7 @@ server_patch_schema = {
|
||||
"logs_delete_after": {"type": "integer", "minimum": 0},
|
||||
"ignored_exits": {"type": "string"},
|
||||
"show_status": {"type": "boolean"},
|
||||
"count_players": {"type": "boolean"},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"minProperties": 1,
|
||||
@ -46,6 +47,7 @@ basic_server_patch_schema = {
|
||||
"shutdown_timeout": {"type": "integer"},
|
||||
"logs_delete_after": {"type": "integer", "minimum": 0},
|
||||
"ignored_exits": {"type": "string"},
|
||||
"count_players": {"type": "boolean"},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"minProperties": 1,
|
||||
|
@ -315,7 +315,7 @@
|
||||
<br />
|
||||
<br />
|
||||
</td>
|
||||
<span class="server-player-totals" id="server_players_{{server['server_data']['server_id']}}" data-players="{{ server['stats']['online']}}" data-max="{{ server['stats']['max'] }}"></span>
|
||||
<span class="server-player-totals" id="server_players_{{server['server_data']['server_id']}}" data-serverId="{{server['server_data']['server_id']}}" data-players="{{ server['stats']['online']}}" data-max="{{ server['stats']['max'] }}" data-count="{{server['server_data']['count_players']}}"></span>
|
||||
</tr>
|
||||
{% end %}
|
||||
</div>
|
||||
@ -554,6 +554,9 @@
|
||||
display: none;
|
||||
/* for Chrome, Safari, and Opera */
|
||||
}
|
||||
.gray {
|
||||
color: gray !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@ -724,15 +727,20 @@
|
||||
|
||||
server_players.setAttribute('data-players', server.online);
|
||||
server_players.setAttribute('data-max', server.max);
|
||||
server_players.setAttribute('data-count', server.count_players)
|
||||
let servers = Array.from(document.getElementsByClassName("server-player-totals"));
|
||||
let all_total_players = 0;
|
||||
let all_total_max_players = 0;
|
||||
|
||||
servers.forEach(server => {
|
||||
try {
|
||||
all_total_players += parseInt(server.getAttribute('data-players'));
|
||||
all_total_max_players += parseInt(server.getAttribute('data-max'));
|
||||
} catch {
|
||||
console.log(`#server_desc_${server.getAttribute("data-serverId")}`)
|
||||
$(`#server_desc_${server.getAttribute("data-serverId")}`).toggleClass("gray", server.getAttribute('data-count') === 'false')
|
||||
if (server.getAttribute('data-count') === 'true'){
|
||||
all_total_players += parseInt(server.getAttribute('data-players'));
|
||||
all_total_max_players += parseInt(server.getAttribute('data-max'));
|
||||
}
|
||||
} catch {
|
||||
console.log("Player totals are not of type int");
|
||||
}
|
||||
})
|
||||
|
@ -188,6 +188,17 @@
|
||||
{% end %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="custom-control custom-switch">
|
||||
{% if data['server_stats']['server_id']['count_players'] %}
|
||||
<input type="checkbox" class="custom-control-input" id="count_players" name="count_players" checked="" value="1">
|
||||
<label class="custom-control-label" for="count_players"> {{ translate('serverConfig', 'countPlayers', data['lang']) }}</label>
|
||||
{% else %}
|
||||
<input type="checkbox" class="custom-control-input" id="count_players" name="count_players" value="1">
|
||||
<label class="custom-control-label" for="count_players"> {{ translate('serverConfig', 'countPlayers', data['lang']) }}</label>
|
||||
{% end %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="custom-control custom-switch">
|
||||
{% if data['super_user'] %}
|
||||
@ -195,7 +206,7 @@
|
||||
<input type="checkbox" class="custom-control-input" id="show_status" name="show_status" checked="" value="1">
|
||||
<label class="custom-control-label" for="show_status"> {{ translate('serverConfig', 'showStatus', data['lang']) }}</label>
|
||||
{% else %}
|
||||
<input type="checkbox" class="custom-control-input" id="show_status" name="show_status" value="1">
|
||||
<input type="checkbox" class="custom-control-input" id="show_status" name="show_status" value="1">
|
||||
<label class="custom-control-label" for="show_status"> {{ translate('serverConfig', 'showStatus', data['lang']) }}</label>
|
||||
{% end %}
|
||||
{% end %}
|
||||
@ -559,6 +570,7 @@
|
||||
formDataObject.show_status = $("#show_status").prop('checked');
|
||||
formDataObject.crash_detection = $("#crash_detection").prop('checked');
|
||||
formDataObject.auto_start = $("#auto_start").prop('checked');
|
||||
formDataObject.count_players = $("#count_players").prop('checked');
|
||||
console.log(formDataObject);
|
||||
// Format the plain form data as JSON
|
||||
let formDataJsonString = JSON.stringify(formDataObject, replacer);
|
||||
|
16
app/migrations/20231229_player_count.py
Normal file
16
app/migrations/20231229_player_count.py
Normal file
@ -0,0 +1,16 @@
|
||||
# Generated by database migrator
|
||||
import peewee
|
||||
|
||||
|
||||
def migrate(migrator, database, **kwargs):
|
||||
migrator.add_columns("servers", count_players=peewee.BooleanField(default=True))
|
||||
"""
|
||||
Write your migrations here.
|
||||
"""
|
||||
|
||||
|
||||
def rollback(migrator, database, **kwargs):
|
||||
migrator.drop_columns("servers", ["count_players"])
|
||||
"""
|
||||
Write your rollback migrations here.
|
||||
"""
|
@ -377,7 +377,8 @@
|
||||
"timeoutExplain2": "command before it forces the process down.",
|
||||
"update": "Update Executable",
|
||||
"yesDelete": "Yes, delete",
|
||||
"yesDeleteFiles": "Yes, delete files"
|
||||
"yesDeleteFiles": "Yes, delete files",
|
||||
"countPlayers": "Include server in total player count"
|
||||
},
|
||||
"serverConfigHelp": {
|
||||
"desc": "Here is where you can change the configuration of your server",
|
||||
@ -665,4 +666,4 @@
|
||||
"webhook_body": "Webhook Body",
|
||||
"webhooks": "Webhooks"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user