mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Merge branch 'bedrock-fixes' into 'dev'
Added translation for backup start/end messages. Finalize bedrock support.... See merge request crafty-controller/crafty-commander!175
This commit is contained in:
commit
bbe9321516
107
app/classes/minecraft/bedrock_ping.py
Normal file
107
app/classes/minecraft/bedrock_ping.py
Normal file
@ -0,0 +1,107 @@
|
||||
import os
|
||||
import socket
|
||||
import time
|
||||
import psutil
|
||||
|
||||
class BedrockPing:
|
||||
magic = b'\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78'
|
||||
fields = { # (len, signed)
|
||||
"byte": (1, False),
|
||||
"long": (8, True),
|
||||
"ulong": (8, False),
|
||||
"magic": (16, False),
|
||||
"short": (2, True),
|
||||
"ushort": (2, False), #unsigned short
|
||||
"string": (2, False), #strlen is ushort
|
||||
"bool": (1, False),
|
||||
"address": (7, False),
|
||||
"uint24le": (3, False)
|
||||
}
|
||||
byte_order = 'big'
|
||||
|
||||
def __init__(self, bedrock_addr, bedrock_port, client_guid=0, timeout=5):
|
||||
self.addr = bedrock_addr
|
||||
self.port = bedrock_port
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
self.sock.settimeout(timeout)
|
||||
self.proc = psutil.Process(os.getpid())
|
||||
self.guid = client_guid
|
||||
self.guid_bytes = self.guid.to_bytes(8, BedrockPing.byte_order)
|
||||
|
||||
@staticmethod
|
||||
def __byter(in_val, to_type):
|
||||
f = BedrockPing.fields[to_type]
|
||||
return in_val.to_bytes(f[0], BedrockPing.byte_order, signed=f[1])
|
||||
|
||||
@staticmethod
|
||||
def __slice(in_bytes, pattern):
|
||||
ret = []
|
||||
bi = 0 # bytes index
|
||||
pi = 0 # pattern index
|
||||
while bi < len(in_bytes):
|
||||
try:
|
||||
f = BedrockPing.fields[pattern[pi]]
|
||||
except IndexError as index_error:
|
||||
raise IndexError("Ran out of pattern with additional bytes remaining") from index_error
|
||||
if pattern[pi] == "string":
|
||||
shl = f[0] # string header length
|
||||
sl = int.from_bytes(in_bytes[bi:bi+shl], BedrockPing.byte_order, signed=f[1]) # string length
|
||||
l = shl+sl
|
||||
ret.append(in_bytes[bi+shl:bi+shl+sl].decode('ascii'))
|
||||
elif pattern[pi] == "magic":
|
||||
l = f[0] # length of field
|
||||
ret.append(in_bytes[bi:bi+l])
|
||||
else:
|
||||
l = f[0] # length of field
|
||||
ret.append(int.from_bytes(in_bytes[bi:bi+l], BedrockPing.byte_order, signed=f[1]))
|
||||
bi+=l
|
||||
pi+=1
|
||||
return ret
|
||||
|
||||
@staticmethod
|
||||
def __get_time():
|
||||
#return time.time_ns() // 1000000
|
||||
return time.perf_counter_ns() // 1000000
|
||||
|
||||
def __sendping(self):
|
||||
pack_id = BedrockPing.__byter(0x01, 'byte')
|
||||
now = BedrockPing.__byter(BedrockPing.__get_time(), 'ulong')
|
||||
guid = self.guid_bytes
|
||||
d2s = pack_id+now+BedrockPing.magic+guid
|
||||
#print("S:", d2s)
|
||||
self.sock.sendto(d2s, (self.addr, self.port))
|
||||
|
||||
def __recvpong(self):
|
||||
data = self.sock.recv(4096)
|
||||
if data[0] == 0x1c:
|
||||
ret = {}
|
||||
sliced = BedrockPing.__slice(data,["byte","ulong","ulong","magic","string"])
|
||||
if sliced[3] != BedrockPing.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]
|
||||
return ret
|
||||
else:
|
||||
raise ValueError(f"Incorrect packet type ({data[0]} detected")
|
||||
|
||||
def ping(self, retries=3):
|
||||
rtr = retries
|
||||
while rtr > 0:
|
||||
try:
|
||||
self.__sendping()
|
||||
return self.__recvpong()
|
||||
except ValueError as e:
|
||||
print(f"E: {e}, checking next packet. Retries remaining: {rtr}/{retries}")
|
||||
rtr -= 1
|
@ -3,9 +3,13 @@ import socket
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import logging.config
|
||||
import uuid
|
||||
import random
|
||||
|
||||
from app.classes.shared.console import console
|
||||
from app.classes.minecraft.bedrock_ping import BedrockPing
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -168,63 +172,15 @@ def ping(ip, port):
|
||||
|
||||
# For the rest of requests see wiki.vg/Protocol
|
||||
def ping_bedrock(ip, port):
|
||||
def read_var_int():
|
||||
i = 0
|
||||
j = 0
|
||||
while True:
|
||||
try:
|
||||
k = sock.recvfrom(1024)
|
||||
except:
|
||||
return False
|
||||
if not k:
|
||||
return 0
|
||||
k = k[0]
|
||||
i |= (k & 0x7f) << (j * 7)
|
||||
j += 1
|
||||
if j > 5:
|
||||
raise ValueError('var_int too big')
|
||||
if not k & 0x80:
|
||||
return i
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.settimeout(2)
|
||||
rd = random.Random()
|
||||
try:
|
||||
sock.connect((ip, port))
|
||||
|
||||
#pylint: disable=consider-using-f-string
|
||||
rd.seed(''.join(re.findall('..', '%012x' % uuid.getnode())))
|
||||
client_guid = uuid.UUID(int=rd.getrandbits(32)).int
|
||||
except:
|
||||
print("in first except")
|
||||
return False
|
||||
|
||||
client_guid = 0
|
||||
try:
|
||||
host = ip.encode('utf-8')
|
||||
data = b'' # wiki.vg/Server_List_Ping
|
||||
data += b'\x00' # packet ID
|
||||
data += b'\x04' # protocol variant
|
||||
data += struct.pack('>b', len(host)) + host
|
||||
data += struct.pack('>H', port)
|
||||
data += b'\x01' # next state
|
||||
data = struct.pack('>b', len(data)) + data
|
||||
sock.sendall(data + b'\x01\x00') # handshake + status ping
|
||||
length = read_var_int() # full packet length
|
||||
if length < 10:
|
||||
if length < 0:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
sock.recvfrom(1024) # packet type, 0 for pings
|
||||
except:
|
||||
return False
|
||||
length = read_var_int() # string length
|
||||
data = b''
|
||||
while len(data) != length:
|
||||
print("in while")
|
||||
chunk = sock.recv(length - len(data))
|
||||
if not chunk:
|
||||
return False
|
||||
|
||||
data += chunk
|
||||
logger.debug(f"Server reports this data on ping: {data}")
|
||||
return Server(json.loads(data))
|
||||
finally:
|
||||
sock.close()
|
||||
brp = BedrockPing(ip, port, client_guid)
|
||||
return brp.ping()
|
||||
except socket.timeout:
|
||||
logger.debug("Unable to get RakNet stats")
|
||||
|
@ -159,6 +159,26 @@ class Stats:
|
||||
'server_icon': server_icon
|
||||
}
|
||||
|
||||
return ping_data
|
||||
|
||||
@staticmethod
|
||||
def parse_server_RakNet_ping(ping_obj: object):
|
||||
|
||||
try:
|
||||
server_icon = base64.encodebytes(ping_obj['icon'])
|
||||
except Exception as e:
|
||||
server_icon = False
|
||||
logger.info(f"Unable to read the server icon : {e}")
|
||||
ping_data = {
|
||||
'online': ping_obj['server_player_count'],
|
||||
'max': ping_obj['server_player_max'],
|
||||
'players': [],
|
||||
'server_description': ping_obj['server_edition'],
|
||||
'server_version': ping_obj['server_version_name'],
|
||||
'server_icon': server_icon
|
||||
}
|
||||
|
||||
|
||||
return ping_data
|
||||
|
||||
def get_server_players(self, server_id):
|
||||
@ -177,17 +197,16 @@ class Stats:
|
||||
server_port = server['server_port']
|
||||
|
||||
logger.debug("Pinging {internal_ip} on port {server_port}")
|
||||
if servers_helper.get_server_type_by_id(server_id) == 'minecraft-bedrock':
|
||||
int_mc_ping = ping_bedrock(internal_ip, int(server_port))
|
||||
else:
|
||||
if servers_helper.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 = self.parse_server_ping(int_mc_ping)
|
||||
return ping_data['players']
|
||||
ping_data = {}
|
||||
|
||||
# if we got a good ping return, let's parse it
|
||||
if int_mc_ping:
|
||||
ping_data = self.parse_server_ping(int_mc_ping)
|
||||
return ping_data['players']
|
||||
return []
|
||||
|
||||
def get_servers_stats(self):
|
||||
@ -237,25 +256,47 @@ class Stats:
|
||||
# if we got a good ping return, let's parse it
|
||||
if int_mc_ping:
|
||||
int_data = True
|
||||
ping_data = self.parse_server_ping(int_mc_ping)
|
||||
|
||||
server_stats = {
|
||||
'id': server_id,
|
||||
'started': server_obj.get_start_time(),
|
||||
'running': server_obj.check_running(),
|
||||
'cpu': p_stats.get('cpu_usage', 0),
|
||||
'mem': p_stats.get('memory_usage', 0),
|
||||
"mem_percent": p_stats.get('mem_percentage', 0),
|
||||
'world_name': world_name,
|
||||
'world_size': self.get_world_size(world_path),
|
||||
'server_port': server_port,
|
||||
'int_ping_results': int_data,
|
||||
'online': ping_data.get("online", False),
|
||||
"max": ping_data.get("max", False),
|
||||
'players': ping_data.get("players", False),
|
||||
'desc': ping_data.get("server_description", False),
|
||||
'version': ping_data.get("server_version", False)
|
||||
}
|
||||
if servers_helper.get_server_type_by_id(s['server_id']) == 'minecraft-bedrock':
|
||||
ping_data = self.parse_server_RakNet_ping(int_mc_ping)
|
||||
else:
|
||||
ping_data = self.parse_server_ping(int_mc_ping)
|
||||
#Makes sure we only show stats when a server is online otherwise people have gotten confused.
|
||||
if server_obj.check_running():
|
||||
server_stats = {
|
||||
'id': server_id,
|
||||
'started': server_obj.get_start_time(),
|
||||
'running': server_obj.check_running(),
|
||||
'cpu': p_stats.get('cpu_usage', 0),
|
||||
'mem': p_stats.get('memory_usage', 0),
|
||||
"mem_percent": p_stats.get('mem_percentage', 0),
|
||||
'world_name': world_name,
|
||||
'world_size': self.get_world_size(world_path),
|
||||
'server_port': server_port,
|
||||
'int_ping_results': int_data,
|
||||
'online': ping_data.get("online", False),
|
||||
"max": ping_data.get("max", False),
|
||||
'players': ping_data.get("players", False),
|
||||
'desc': ping_data.get("server_description", False),
|
||||
'version': ping_data.get("server_version", False)
|
||||
}
|
||||
else:
|
||||
server_stats = {
|
||||
'id': server_id,
|
||||
'started': server_obj.get_start_time(),
|
||||
'running': server_obj.check_running(),
|
||||
'cpu': p_stats.get('cpu_usage', 0),
|
||||
'mem': p_stats.get('memory_usage', 0),
|
||||
"mem_percent": p_stats.get('mem_percentage', 0),
|
||||
'world_name': world_name,
|
||||
'world_size': self.get_world_size(world_path),
|
||||
'server_port': server_port,
|
||||
'int_ping_results': int_data,
|
||||
'online': False,
|
||||
"max": False,
|
||||
'players': False,
|
||||
'desc': False,
|
||||
'version': False
|
||||
}
|
||||
|
||||
# add this servers data to the stack
|
||||
server_stats_list.append(server_stats)
|
||||
@ -264,8 +305,30 @@ class Stats:
|
||||
|
||||
def get_raw_server_stats(self, server_id):
|
||||
|
||||
try:
|
||||
self.controller.get_server_obj(server_id)
|
||||
except:
|
||||
return { 'id': server_id,
|
||||
'started': False,
|
||||
'running': False,
|
||||
'cpu': 0,
|
||||
'mem': 0,
|
||||
"mem_percent": 0,
|
||||
'world_name': None,
|
||||
'world_size': None,
|
||||
'server_port': None,
|
||||
'int_ping_results': False,
|
||||
'online': False,
|
||||
'max': False,
|
||||
'players': False,
|
||||
'desc': False,
|
||||
'version': False,
|
||||
'icon': False}
|
||||
|
||||
server_stats = {}
|
||||
server = self.controller.get_server_obj(server_id)
|
||||
if not server:
|
||||
return {}
|
||||
server_dt = servers_helper.get_server_data_by_id(server_id)
|
||||
|
||||
|
||||
@ -299,30 +362,98 @@ class Stats:
|
||||
|
||||
int_data = False
|
||||
ping_data = {}
|
||||
#Makes sure we only show stats when a server is online otherwise people have gotten confused.
|
||||
if server_obj.check_running():
|
||||
# if we got a good ping return, let's parse it
|
||||
if servers_helper.get_server_type_by_id(server_id) != 'minecraft-bedrock':
|
||||
if int_mc_ping:
|
||||
int_data = True
|
||||
ping_data = self.parse_server_ping(int_mc_ping)
|
||||
|
||||
# if we got a good ping return, let's parse it
|
||||
if int_mc_ping:
|
||||
int_data = True
|
||||
ping_data = self.parse_server_ping(int_mc_ping)
|
||||
server_stats = {
|
||||
'id': server_id,
|
||||
'started': server_obj.get_start_time(),
|
||||
'running': server_obj.check_running(),
|
||||
'cpu': p_stats.get('cpu_usage', 0),
|
||||
'mem': p_stats.get('memory_usage', 0),
|
||||
"mem_percent": p_stats.get('mem_percentage', 0),
|
||||
'world_name': world_name,
|
||||
'world_size': self.get_world_size(world_path),
|
||||
'server_port': server_port,
|
||||
'int_ping_results': int_data,
|
||||
'online': ping_data.get("online", False),
|
||||
"max": ping_data.get("max", False),
|
||||
'players': ping_data.get("players", False),
|
||||
'desc': ping_data.get("server_description", False),
|
||||
'version': ping_data.get("server_version", False),
|
||||
'icon': ping_data.get("server_icon", False)
|
||||
}
|
||||
|
||||
server_stats = {
|
||||
'id': server_id,
|
||||
'started': server_obj.get_start_time(),
|
||||
'running': server_obj.check_running(),
|
||||
'cpu': p_stats.get('cpu_usage', 0),
|
||||
'mem': p_stats.get('memory_usage', 0),
|
||||
"mem_percent": p_stats.get('mem_percentage', 0),
|
||||
'world_name': world_name,
|
||||
'world_size': self.get_world_size(world_path),
|
||||
'server_port': server_port,
|
||||
'int_ping_results': int_data,
|
||||
'online': ping_data.get("online", False),
|
||||
"max": ping_data.get("max", False),
|
||||
'players': ping_data.get("players", False),
|
||||
'desc': ping_data.get("server_description", False),
|
||||
'version': ping_data.get("server_version", False),
|
||||
'icon': ping_data.get("server_icon", False)
|
||||
}
|
||||
else:
|
||||
if int_mc_ping:
|
||||
int_data = True
|
||||
ping_data = self.parse_server_RakNet_ping(int_mc_ping)
|
||||
try:
|
||||
server_icon = base64.encodebytes(ping_data['icon'])
|
||||
except Exception as e:
|
||||
server_icon = False
|
||||
logger.info(f"Unable to read the server icon : {e}")
|
||||
|
||||
server_stats = {
|
||||
'id': server_id,
|
||||
'started': server_obj.get_start_time(),
|
||||
'running': server_obj.check_running(),
|
||||
'cpu': p_stats.get('cpu_usage', 0),
|
||||
'mem': p_stats.get('memory_usage', 0),
|
||||
"mem_percent": p_stats.get('mem_percentage', 0),
|
||||
'world_name': world_name,
|
||||
'world_size': self.get_world_size(world_path),
|
||||
'server_port': server_port,
|
||||
'int_ping_results': int_data,
|
||||
'online': ping_data['online'],
|
||||
'max': ping_data['max'],
|
||||
'players': [],
|
||||
'desc': ping_data['server_description'],
|
||||
'version': ping_data['server_version'],
|
||||
'icon': server_icon
|
||||
}
|
||||
else:
|
||||
server_stats = {
|
||||
'id': server_id,
|
||||
'started': server_obj.get_start_time(),
|
||||
'running': server_obj.check_running(),
|
||||
'cpu': p_stats.get('cpu_usage', 0),
|
||||
'mem': p_stats.get('memory_usage', 0),
|
||||
"mem_percent": p_stats.get('mem_percentage', 0),
|
||||
'world_name': world_name,
|
||||
'world_size': self.get_world_size(world_path),
|
||||
'server_port': server_port,
|
||||
'int_ping_results': int_data,
|
||||
'online': False,
|
||||
'max': False,
|
||||
'players': False,
|
||||
'desc': False,
|
||||
'version': False,
|
||||
'icon': False
|
||||
}
|
||||
else:
|
||||
server_stats = {
|
||||
'id': server_id,
|
||||
'started': server_obj.get_start_time(),
|
||||
'running': server_obj.check_running(),
|
||||
'cpu': p_stats.get('cpu_usage', 0),
|
||||
'mem': p_stats.get('memory_usage', 0),
|
||||
"mem_percent": p_stats.get('mem_percentage', 0),
|
||||
'world_name': world_name,
|
||||
'world_size': self.get_world_size(world_path),
|
||||
'server_port': server_port,
|
||||
'int_ping_results': int_data,
|
||||
'online': False,
|
||||
"max": False,
|
||||
'players': False,
|
||||
'desc': False,
|
||||
'version': False
|
||||
}
|
||||
|
||||
return server_stats
|
||||
|
||||
|
@ -652,8 +652,15 @@ class Helpers:
|
||||
|
||||
@staticmethod
|
||||
def generate_tree(folder, output=""):
|
||||
dir_list = []
|
||||
unsorted_files = []
|
||||
file_list = os.listdir(folder)
|
||||
file_list = sorted(file_list, key=str.casefold)
|
||||
for item in file_list:
|
||||
if os.path.isdir(os.path.join(folder, item)):
|
||||
dir_list.append(item)
|
||||
else:
|
||||
unsorted_files.append(item)
|
||||
file_list = sorted(dir_list, key=str.casefold) + sorted(unsorted_files, key=str.casefold)
|
||||
for raw_filename in file_list:
|
||||
filename = html.escape(raw_filename)
|
||||
rel = os.path.join(folder, raw_filename)
|
||||
@ -673,7 +680,7 @@ class Helpers:
|
||||
else:
|
||||
if filename != "crafty_managed.txt":
|
||||
output += f"""<li
|
||||
class="tree-item tree-ctx-item tree-file"
|
||||
class="tree-nested d-block tree-ctx-item tree-file"
|
||||
data-path="{dpath}"
|
||||
data-name="{filename}"
|
||||
onclick="clickOnFile(event)"><span style="margin-right: 6px;"><i class="far fa-file"></i></span>{filename}</li>"""
|
||||
@ -681,8 +688,15 @@ class Helpers:
|
||||
|
||||
@staticmethod
|
||||
def generate_dir(folder, output=""):
|
||||
dir_list = []
|
||||
unsorted_files = []
|
||||
file_list = os.listdir(folder)
|
||||
file_list = sorted(file_list, key=str.casefold)
|
||||
for item in file_list:
|
||||
if os.path.isdir(os.path.join(folder, item)):
|
||||
dir_list.append(item)
|
||||
else:
|
||||
unsorted_files.append(item)
|
||||
file_list = sorted(dir_list, key=str.casefold) + sorted(unsorted_files, key=str.casefold)
|
||||
output += \
|
||||
f"""<ul class="tree-nested d-block" id="{folder}ul">"""\
|
||||
|
||||
@ -704,7 +718,7 @@ class Helpers:
|
||||
else:
|
||||
if filename != "crafty_managed.txt":
|
||||
output += f"""<li
|
||||
class="tree-item tree-ctx-item tree-file"
|
||||
class="tree-nested d-block tree-ctx-item tree-file"
|
||||
data-path="{dpath}"
|
||||
data-name="{filename}"
|
||||
onclick="clickOnFile(event)"><span style="margin-right: 6px;"><i class="far fa-file"></i></span>{filename}</li>"""
|
||||
|
@ -1,9 +1,9 @@
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import time
|
||||
import logging
|
||||
import tempfile
|
||||
from distutils import dir_util
|
||||
from typing import Union
|
||||
from peewee import DoesNotExist
|
||||
|
||||
@ -329,7 +329,10 @@ class Controller:
|
||||
helper.ensure_dir_exists(new_server_dir)
|
||||
helper.ensure_dir_exists(backup_path)
|
||||
server_path = helper.get_os_understandable_path(server_path)
|
||||
dir_util.copy_tree(server_path, new_server_dir)
|
||||
try:
|
||||
file_helper.copy_dir(server_path, new_server_dir, True)
|
||||
except shutil.Error as ex:
|
||||
logger.error(f"Server import failed with error: {ex}")
|
||||
|
||||
has_properties = False
|
||||
for item in os.listdir(new_server_dir):
|
||||
@ -374,7 +377,10 @@ class Controller:
|
||||
if str(item) == 'server.properties':
|
||||
has_properties = True
|
||||
try:
|
||||
file_helper.move_file(os.path.join(tempDir, item), os.path.join(new_server_dir, item))
|
||||
if not os.path.isdir(os.path.join(tempDir, item)):
|
||||
file_helper.move_file(os.path.join(tempDir, item), os.path.join(new_server_dir, item))
|
||||
else:
|
||||
file_helper.move_dir(os.path.join(tempDir, item), os.path.join(new_server_dir, item))
|
||||
except Exception as ex:
|
||||
logger.error(f'ERROR IN ZIP IMPORT: {ex}')
|
||||
if not has_properties:
|
||||
@ -415,7 +421,10 @@ class Controller:
|
||||
helper.ensure_dir_exists(new_server_dir)
|
||||
helper.ensure_dir_exists(backup_path)
|
||||
server_path = helper.get_os_understandable_path(server_path)
|
||||
dir_util.copy_tree(server_path, new_server_dir)
|
||||
try:
|
||||
file_helper.copy_dir(server_path, new_server_dir, True)
|
||||
except shutil.Error as ex:
|
||||
logger.error(f"Server import failed with error: {ex}")
|
||||
|
||||
has_properties = False
|
||||
for item in os.listdir(new_server_dir):
|
||||
@ -440,7 +449,9 @@ class Controller:
|
||||
|
||||
new_id = self.register_server(server_name, server_id, new_server_dir, backup_path, server_command, server_exe,
|
||||
server_log_file, server_stop, port, server_type='minecraft-bedrock')
|
||||
os.chmod(full_jar_path, 2775)
|
||||
if os.name != "nt":
|
||||
if helper.check_file_exists(full_jar_path):
|
||||
os.chmod(full_jar_path, 2775)
|
||||
return new_id
|
||||
|
||||
def import_bedrock_zip_server(self, server_name: str, zip_path: str, server_exe: str, port: int):
|
||||
@ -457,12 +468,16 @@ class Controller:
|
||||
helper.ensure_dir_exists(new_server_dir)
|
||||
helper.ensure_dir_exists(backup_path)
|
||||
has_properties = False
|
||||
print(os.listdir(tempDir))
|
||||
#extracts archive to temp directory
|
||||
for item in os.listdir(tempDir):
|
||||
if str(item) == 'server.properties':
|
||||
has_properties = True
|
||||
try:
|
||||
file_helper.move_file(os.path.join(tempDir, item), os.path.join(new_server_dir, item))
|
||||
if not os.path.isdir(os.path.join(tempDir, item)):
|
||||
file_helper.move_file(os.path.join(tempDir, item), os.path.join(new_server_dir, item))
|
||||
else:
|
||||
file_helper.move_dir(os.path.join(tempDir, item), os.path.join(new_server_dir, item))
|
||||
except Exception as ex:
|
||||
logger.error(f'ERROR IN ZIP IMPORT: {ex}')
|
||||
if not has_properties:
|
||||
@ -484,7 +499,10 @@ class Controller:
|
||||
|
||||
new_id = self.register_server(server_name, server_id, new_server_dir, backup_path, server_command, server_exe,
|
||||
server_log_file, server_stop, port, server_type='minecraft-bedrock')
|
||||
os.chmod(full_jar_path, 2775)
|
||||
if os.name != "nt":
|
||||
if helper.check_file_exists(full_jar_path):
|
||||
os.chmod(full_jar_path, 2775)
|
||||
|
||||
return new_id
|
||||
|
||||
#************************************************************************************************
|
||||
|
@ -575,6 +575,11 @@ class Server:
|
||||
|
||||
def a_backup_server(self):
|
||||
logger.info(f"Starting server {self.name} (ID {self.server_id}) backup")
|
||||
server_users = server_permissions.get_server_user_list(self.server_id)
|
||||
for user in server_users:
|
||||
websocket_helper.broadcast_user(user, 'notification', translation.translate('notify',
|
||||
'backupStarted', users_helper.get_user_lang_by_id(user)) + self.name)
|
||||
time.sleep(3)
|
||||
self.is_backingup = True
|
||||
conf = management_helper.get_backup_config(self.server_id)
|
||||
try:
|
||||
@ -611,6 +616,11 @@ class Server:
|
||||
self.is_backingup = False
|
||||
file_helper.del_dirs(tempDir)
|
||||
logger.info(f"Backup of server: {self.name} completed")
|
||||
server_users = server_permissions.get_server_user_list(self.server_id)
|
||||
for user in server_users:
|
||||
websocket_helper.broadcast_user(user, 'notification', translation.translate('notify', 'backupComplete',
|
||||
users_helper.get_user_lang_by_id(user)) + self.name)
|
||||
time.sleep(3)
|
||||
return
|
||||
except:
|
||||
logger.exception(f"Failed to create backup of server {self.name} (ID {self.server_id})")
|
||||
|
@ -2,12 +2,15 @@ import os
|
||||
import html
|
||||
import re
|
||||
import logging
|
||||
import time
|
||||
import tornado.web
|
||||
import tornado.escape
|
||||
import bleach
|
||||
|
||||
from app.classes.shared.console import console
|
||||
from app.classes.shared.helpers import helper
|
||||
from app.classes.web.websocket_helper import websocket_helper
|
||||
from app.classes.shared.translation import translation
|
||||
from app.classes.shared.server import ServerOutBuf
|
||||
|
||||
from app.classes.web.base_handler import BaseHandler
|
||||
@ -105,8 +108,15 @@ class AjaxHandler(BaseHandler):
|
||||
|
||||
output = ""
|
||||
|
||||
dir_list = []
|
||||
unsorted_files = []
|
||||
file_list = os.listdir(folder)
|
||||
file_list = sorted(file_list, key=str.casefold)
|
||||
for item in file_list:
|
||||
if os.path.isdir(os.path.join(folder, item)):
|
||||
dir_list.append(item)
|
||||
else:
|
||||
unsorted_files.append(item)
|
||||
file_list = sorted(dir_list, key=str.casefold) + sorted(unsorted_files, key=str.casefold)
|
||||
output += \
|
||||
f"""<ul class="tree-nested d-block" id="{folder}ul">"""\
|
||||
|
||||
@ -130,7 +140,7 @@ class AjaxHandler(BaseHandler):
|
||||
|
||||
else:
|
||||
output += f"""<li
|
||||
class="tree-item tree-ctx-item tree-file"
|
||||
class="tree-nested d-block tree-ctx-item tree-file"
|
||||
data-path="{dpath}"
|
||||
data-name="{filename}"
|
||||
onclick=""><input type='checkbox' class="checkBoxClass" name='root_path' value="{dpath}" checked><span style="margin-right: 6px;">
|
||||
@ -152,7 +162,7 @@ class AjaxHandler(BaseHandler):
|
||||
|
||||
else:
|
||||
output += f"""<li
|
||||
class="tree-item tree-ctx-item tree-file"
|
||||
class="tree-nested d-block tree-ctx-item tree-file"
|
||||
data-path="{dpath}"
|
||||
data-name="{filename}"
|
||||
onclick=""><input type='checkbox' class="checkBoxClass" name='root_path' value="{dpath}">
|
||||
@ -166,8 +176,15 @@ class AjaxHandler(BaseHandler):
|
||||
folder = self.get_argument('path', None)
|
||||
output = ""
|
||||
|
||||
dir_list = []
|
||||
unsorted_files = []
|
||||
file_list = os.listdir(folder)
|
||||
file_list = sorted(file_list, key=str.casefold)
|
||||
for item in file_list:
|
||||
if os.path.isdir(os.path.join(folder, item)):
|
||||
dir_list.append(item)
|
||||
else:
|
||||
unsorted_files.append(item)
|
||||
file_list = sorted(dir_list, key=str.casefold) + sorted(unsorted_files, key=str.casefold)
|
||||
output += \
|
||||
f"""<ul class="tree-nested d-block" id="{folder}ul">"""\
|
||||
|
||||
@ -331,7 +348,16 @@ class AjaxHandler(BaseHandler):
|
||||
|
||||
elif page == "unzip_server":
|
||||
path = self.get_argument('path', None)
|
||||
helper.unzipServer(path, exec_user['user_id'])
|
||||
if helper.check_file_exists(path):
|
||||
helper.unzipServer(path, exec_user['user_id'])
|
||||
else:
|
||||
user_id = exec_user['user_id']
|
||||
if user_id:
|
||||
time.sleep(5)
|
||||
user_lang = self.controller.users.get_user_lang_by_id(user_id)
|
||||
websocket_helper.broadcast_user(user_id, 'send_start_error',{
|
||||
'error': translation.translate('error', 'no-file', user_lang)
|
||||
})
|
||||
return
|
||||
|
||||
elif page == "backup_select":
|
||||
|
@ -304,7 +304,7 @@ class ServerHandler(BaseHandler):
|
||||
return
|
||||
|
||||
if import_type == 'import_jar':
|
||||
good_path = self.controller.verify_jar_server(import_server_path, import_server_jar)
|
||||
good_path = self.controller.verify_jar_server(import_server_path, import_server_exe)
|
||||
|
||||
if not good_path:
|
||||
self.redirect("/panel/error?error=Server path or Server Jar not found!")
|
||||
|
@ -36,7 +36,7 @@
|
||||
<i class="fas fa-cogs"></i>{{ translate('serverDetails', 'config', data['lang']) }}</a>
|
||||
</li>
|
||||
{% end %}
|
||||
{% if data['permissions']['Players'] in data['user_permissions'] %}
|
||||
{% if data['permissions']['Players'] in data['user_permissions'] and data['server_data']['type'] != 'minecraft-bedrock' %}
|
||||
<li class="nav-item term-nav-item">
|
||||
<a class="nav-link {% if data['active_link'] == 'admin_controls' %}active{% end %}" href="/panel/server_detail?id={{ data['server_stats']['server_id']['server_id'] }}&subpage=admin_controls" role="tab" aria-selected="true">
|
||||
<i class="fas fa-users"></i>{{ translate('serverDetails', 'playerControls', data['lang']) }}</a>
|
||||
|
@ -18,7 +18,8 @@
|
||||
"eulaMsg": "You must agree to the EULA. A copy of the Mojang EULA is linked under this message.",
|
||||
"eulaAgree": "Do you agree?",
|
||||
"noJava": "Server {} failed to start with error code: We have detected Java is not installed. Please install java then start the server.",
|
||||
"not-downloaded": "We can't seem to find your executable file. Has it finished downloading? Are the permissions set to executable?"
|
||||
"not-downloaded": "We can't seem to find your executable file. Has it finished downloading? Are the permissions set to executable?",
|
||||
"no-file": "We can't seem to locate the requested file. Double check the path. Does Crafty have proper permissions?"
|
||||
},
|
||||
"404": {
|
||||
"contact": "Contact Crafty Control Support via Discord",
|
||||
@ -213,7 +214,9 @@
|
||||
"logout": "Logout",
|
||||
"preparingLogs": " Please wait while we prepare your logs... We`ll send a notification when they`re ready. This may take a while for large deployments.",
|
||||
"downloadLogs": "Download Support Logs?",
|
||||
"finishedPreparing": "We've finished preparing your support logs. Please click download to download"
|
||||
"finishedPreparing": "We've finished preparing your support logs. Please click download to download",
|
||||
"backupComplete": "Backup completed successfully for server ",
|
||||
"backupStarted": "Backup started for server "
|
||||
},
|
||||
"serverBackups": {
|
||||
"backupNow": "Backup Now!",
|
||||
|
Loading…
Reference in New Issue
Block a user