Merge branch 'tweak/remove_prop_requirement' into 'dev'

Remove server.props requirement

See merge request crafty-controller/crafty-4!403
This commit is contained in:
Iain Powrie 2022-07-18 20:48:12 +00:00
commit 61703d66a4
5 changed files with 29 additions and 100 deletions

View File

@ -11,7 +11,7 @@
- Fix issue with API Server Instance is not serializable ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/401))
- Fix an issue where the motd were not displayed properly one small screens ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/402))
### Tweaks
None
- Remove server.props requirement ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/403))
### Lang
None
<br><br>

View File

@ -13,7 +13,6 @@ from app.classes.shared.console import Console
from app.classes.shared.helpers import Helpers
from app.classes.shared.main_models import DatabaseShortcuts
from app.classes.minecraft.server_props import ServerProps
from app.classes.minecraft.stats import Stats
from app.classes.models.servers import HelperServers
@ -171,18 +170,6 @@ class ServersController(metaclass=Singleton):
)
continue
settings_file = os.path.join(
Helpers.get_os_understandable_path(server["path"]), "server.properties"
)
# if the properties file isn't there, let's warn
if not Helpers.check_file_exists(settings_file):
logger.error(f"Unable to find {settings_file}. Skipping this server.")
Console.error(f"Unable to find {settings_file}. Skipping this server.")
continue
settings = ServerProps(settings_file)
temp_server_dict = {
"server_id": server.get("server_id"),
"server_data_obj": server,
@ -193,7 +180,6 @@ class ServersController(metaclass=Singleton):
self.stats,
self.file_helper,
),
"server_settings": settings.props,
}
# setup the server, do the auto start and all that jazz
@ -350,14 +336,6 @@ class ServersController(metaclass=Singleton):
def get_server_friendly_name(server_id):
return HelperServers.get_server_friendly_name(server_id)
def get_server_settings(self, server_id):
for server in self.servers_list:
if int(server["server_id"]) == int(server_id):
return server["server_settings"]
logger.warning(f"Unable to find server object for server id {server_id}")
return False
def crash_detection(self, server_obj):
svr = self.get_server_instance_by_id(server_obj.server_id)
# start or stop crash detection depending upon user preference

View File

@ -1,66 +0,0 @@
import pprint
import os
class ServerProps:
def __init__(self, filepath):
self.filepath = filepath
self.props = self._parse()
def _parse(self):
# Loads and parses the file specified in self.filepath
with open(self.filepath, encoding="utf-8") as full_path:
line = full_path.readline()
dictionary = {}
if os.path.exists(".header"):
os.remove(".header")
while line:
if "#" != line[0]:
string = line
string1 = string[: string.find("=")]
if "\n" in string:
string2 = string[string.find("=") + 1 : string.find("\n")]
else:
string2 = string[string.find("=") + 1 :]
dictionary[string1] = string2
else:
with open(".header", "a+", encoding="utf-8") as header:
header.write(line)
line = full_path.readline()
return dictionary
def print(self):
# Prints the properties dictionary (using pprint)
pprint.pprint(self.props)
def get(self):
# Returns the properties dictionary
return self.props
def update(self, key, val):
# Updates property in the properties dictionary [ update("pvp", "true") ]
# and returns boolean condition
if key in self.props.keys():
self.props[key] = val
return True
return False
def save(self):
# Writes to the new file
with open(self.filepath, "a+", encoding="utf-8") as f:
f.truncate(0)
with open(".header", encoding="utf-8") as header:
line = header.readline()
while line:
f.write(line)
line = header.readline()
header.close()
for key, value in self.props.items():
f.write(key + "=" + value + "\n")
if os.path.exists(".header"):
os.remove(".header")
@staticmethod
def cleanup():
if os.path.exists(".header"):
os.remove(".header")

View File

@ -6,8 +6,10 @@ import datetime
import base64
import typing as t
from app.classes.shared.null_writer import NullWriter
from app.classes.minecraft.mc_ping import ping
from app.classes.models.management import HostStats
from app.classes.models.servers import HelperServers
from app.classes.shared.null_writer import NullWriter
from app.classes.shared.helpers import Helpers
with redirect_stderr(NullWriter()):
@ -218,6 +220,27 @@ class Stats:
return level_total_size
def get_server_players(self, server_id):
server = HelperServers.get_server_data_by_id(server_id)
logger.info(f"Getting players for server {server}")
internal_ip = server["server_ip"]
server_port = server["server_port"]
logger.debug(f"Pinging {internal_ip} on port {server_port}")
if HelperServers.get_server_type_by_id(server_id) != "minecraft-bedrock":
int_mc_ping = ping(internal_ip, int(server_port))
ping_data = {}
# if we got a good ping return, let's parse it
if int_mc_ping:
ping_data = Stats.parse_server_ping(int_mc_ping)
return ping_data["players"]
return []
@staticmethod
def parse_server_ping(ping_obj: object):
online_stats = {}

View File

@ -1244,7 +1244,6 @@ class ServerInstance:
# process stats
p_stats = Stats._try_get_process_stats(self.process, self.check_running())
# TODO: search server properties file for possible override of 127.0.0.1
internal_ip = server["server_ip"]
server_port = server["server_port"]
server_name = server.get("server_name", f"ID#{server_id}")
@ -1253,7 +1252,10 @@ class ServerInstance:
if HelperServers.get_server_type_by_id(server_id) == "minecraft-bedrock":
int_mc_ping = ping_bedrock(internal_ip, int(server_port))
else:
int_mc_ping = ping(internal_ip, int(server_port))
try:
int_mc_ping = ping(internal_ip, int(server_port))
except:
int_mc_ping = False
int_data = False
ping_data = {}
@ -1315,11 +1317,6 @@ class ServerInstance:
logger.info(f"Getting players for server {server}")
# get our settings and data dictionaries
# server_settings = server.get('server_settings', {})
# server_data = server.get('server_data_obj', {})
# TODO: search server properties file for possible override of 127.0.0.1
internal_ip = server["server_ip"]
server_port = server["server_port"]
@ -1377,9 +1374,6 @@ class ServerInstance:
# process stats
p_stats = Stats._try_get_process_stats(self.process, self.check_running())
# TODO: search server properties file for possible override of 127.0.0.1
# internal_ip = server['server_ip']
# server_port = server['server_port']
internal_ip = server_dt["server_ip"]
server_port = server_dt["server_port"]