Mac's Basic Working SteamCMD Version, UNFINISHED, requires garbage

Notes:
 - Requires env.json in the server root dir
 - Requires bash exec for programs that don't root to the server dir
This commit is contained in:
computergeek125 2023-11-26 20:26:42 -06:00
parent 7765695943
commit 7ebe03a222
3 changed files with 90 additions and 23 deletions

View File

@ -106,19 +106,36 @@ class RaknetPing:
if sliced[3] != RaknetPing.magic:
raise ValueError(f"Incorrect magic received ({sliced[3]})")
ret["server_guid"] = sliced[2]
ret["server_string_raw"] = sliced[4]
server_info = sliced[4].split(";")
ret["server_edition"] = server_info[0]
ret["server_motd"] = (server_info[1], server_info[7])
ret["server_protocol_version"] = server_info[2]
ret["server_version_name"] = server_info[3]
ret["server_player_count"] = server_info[4]
ret["server_player_max"] = server_info[5]
ret["server_uuid"] = server_info[6]
ret["server_game_mode"] = server_info[8]
ret["server_game_mode_num"] = server_info[9]
ret["server_port_ipv4"] = server_info[10]
ret["server_port_ipv6"] = server_info[11]
try:
if len(sliced) >= 5:
ret["server_string_raw"] = sliced[4]
server_info = sliced[4].split(";")
ret["server_edition"] = server_info[0]
ret["server_motd"] = (server_info[1], server_info[7])
ret["server_protocol_version"] = server_info[2]
ret["server_version_name"] = server_info[3]
ret["server_player_count"] = server_info[4]
ret["server_player_max"] = server_info[5]
ret["server_uuid"] = server_info[6]
ret["server_game_mode"] = server_info[8]
ret["server_game_mode_num"] = server_info[9]
ret["server_port_ipv4"] = server_info[10]
ret["server_port_ipv6"] = server_info[11]
else:
ret["server_string_raw"] = ""
ret["server_edition"] = "Generic Raknet"
ret["server_motd"] = (None, None)
ret["server_protocol_version"] = None
ret["server_version_name"] = "Generic Raknet"
ret["server_player_count"] = -1
ret["server_player_max"] = -1
ret["server_uuid"] = None
ret["server_game_mode"] = None
ret["server_game_mode_num"] = 0
ret["server_port_ipv4"] = ""
ret["server_port_ipv6"] = ""
except:
raise ValueError(f"Received unexpected Raknet response: {sliced}")
return ret
raise ValueError(f"Incorrect packet type ({data[0]} detected")

View File

@ -470,7 +470,47 @@ class ServerInstance:
# STEAM SERVERS
# ***********************************************
# ***********************************************
elif HelperServers.get_server_type_by_id(self.server_id) == "steam":
elif HelperServers.get_server_type_by_id(self.server_id) == "raknet":
my_env = os.environ
env_mod = False
with open(
self.server_path + "/env.json",
) as env_file:
env_file_data = json.load(env_file)
for key, value in env_file_data.items():
if "path" in key.lower():
items_validated = []
for item in value["contents"]:
try:
p = Helpers.validate_traversal(self.server_path, item)
except ValueError:
logger.warning(
"Path traversal detected on server {self.server_id} for env {k} value {i}, skipping"
)
p = str(p).replace(":", "\:")
items_validated.append(p)
if my_env.get(key, None):
if value["mode"] == "append":
items_validated.insert(0, my_env[key])
elif value["mode"] == "prepend":
items_validated.append(my_env[key])
my_env[key] = ":".join(items_validated)
else:
items = value["contents"]
if value["mode"] == "append":
items.insert(0, my_env[key])
elif value["mode"] == "prepend":
items.append(my_env[key])
my_env[key] = ",".join(items)
env_mod = True
if env_mod:
logger.debug(
f"Launching process for server {self.server_id} with modified environment {my_env}"
)
else:
logger.debug(
f"Launching process for server {self.server_id} with un-modified environment"
)
try:
self.process = subprocess.Popen(
self.server_command,
@ -478,6 +518,7 @@ class ServerInstance:
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env=my_env,
)
except Exception as ex:
logger.error(
@ -496,6 +537,9 @@ class ServerInstance:
return
else:
logger.debug(
f"Starting server {self.server_id} with unknown type {HelperServers.get_server_type_by_id(self.server_id)}"
)
try:
self.process = subprocess.Popen(
self.server_command,
@ -1595,7 +1639,10 @@ class ServerInstance:
server_name = server.get("server_name", f"ID#{server_id}")
logger.debug(f"Pinging server '{server}' on {internal_ip}:{server_port}")
if HelperServers.get_server_type_by_id(server_id) == "minecraft-bedrock":
if (
HelperServers.get_server_type_by_id(server_id) == "minecraft-bedrock"
or HelperServers.get_server_type_by_id(server_id) == "raknet"
):
int_mc_ping = ping_raknet(internal_ip, int(server_port))
else:
try:
@ -1609,10 +1656,10 @@ class ServerInstance:
# if we got a good ping return, let's parse it
if int_mc_ping:
int_data = True
if HelperServers.get_server_type_by_id(
server["server_id"]
) == "minecraft-bedrock" or HelperServers.get_server_type_by_id(
server["server_id"] == "steam"
if (
HelperServers.get_server_type_by_id(server["server_id"])
== "minecraft-bedrock"
or HelperServers.get_server_type_by_id(server["server_id"]) == "raknet"
):
ping_data = Stats.parse_server_raknet_ping(int_mc_ping)
else:
@ -1722,7 +1769,10 @@ class ServerInstance:
server_port = server_dt["server_port"]
logger.debug(f"Pinging server '{self.name}' on {internal_ip}:{server_port}")
if HelperServers.get_server_type_by_id(server_id) == "minecraft-bedrock":
if (
HelperServers.get_server_type_by_id(server_id) == "minecraft-bedrock"
or HelperServers.get_server_type_by_id(server_id) == "raknet"
):
int_mc_ping = ping_raknet(internal_ip, int(server_port))
else:
int_mc_ping = ping(internal_ip, int(server_port))

View File

@ -107,7 +107,7 @@
<div class="form-group">
<label for="stop_command">{{ translate('serverConfig', 'serverStopCommand', data['lang']) }} <small class="text-muted ml-1"> - {{ translate('serverConfig', 'serverStopCommandDesc', data['lang'])
}}</small> </label>
<input type="text" class="form-control" name="stop_command" id="stop_command" value="{{ data['server_stats']['server_id']['stop_command'] }}" placeholder="{{ translate('serverConfig', 'serverStopCommand', data['lang']) }}" required>
<input type="text" class="form-control" name="stop_command" id="stop_command" value="{{ data['server_stats']['server_id']['stop_command'] }}" placeholder="{{ translate('serverConfig', 'serverStopCommand', data['lang']) }}">
</div>
<div class="form-group">
@ -532,7 +532,7 @@
}
function replacer(key, value) {
if (key != "ignored_exits") {
if (typeof value == "boolean" || key === "executable_update_url") {
if (typeof value == "boolean" || key === "executable_update_url" || value === '') {
return value
} else {
return (isNaN(value) ? value : +value);
@ -588,4 +588,4 @@
});
</script>
{% end %}
{% end %}