mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add download server option for bedrock servers
This commit is contained in:
parent
14c0065124
commit
4f7d18362c
@ -352,11 +352,12 @@ class Controller:
|
||||
elif root_create_data["create_type"] == "import_zip":
|
||||
# TODO: Copy files from the zip file to the new server directory
|
||||
server_file = create_data["jarfile"]
|
||||
self.import_zip_server()
|
||||
raise NotImplementedError("Not yet implemented")
|
||||
_create_server_properties_if_needed(
|
||||
create_data["server_properties_port"],
|
||||
)
|
||||
self.import_helper.import_java_zip_server()
|
||||
if create_data["minecraft_java"]:
|
||||
_create_server_properties_if_needed(
|
||||
create_data["server_properties_port"],
|
||||
)
|
||||
|
||||
min_mem = create_data["mem_min"]
|
||||
max_mem = create_data["mem_max"]
|
||||
@ -419,13 +420,21 @@ class Controller:
|
||||
elif root_create_data["create_type"] == "import_zip":
|
||||
# TODO: Copy files from the zip file to the new server directory
|
||||
raise NotImplementedError("Not yet implemented")
|
||||
else:
|
||||
server_file = "bedrock_server"
|
||||
if Helpers.is_os_windows():
|
||||
# if this is windows we will override the linux bedrock server name.
|
||||
server_file = "bedrock_server.exe"
|
||||
|
||||
full_jar_path = os.path.join(new_server_path, server_file)
|
||||
|
||||
if self.helper.is_os_windows():
|
||||
create_data["command"] = f'"{full_jar_path}"'
|
||||
else:
|
||||
create_data["command"] = f"./{server_file}"
|
||||
_create_server_properties_if_needed(0, True)
|
||||
|
||||
server_command = create_data["command"]
|
||||
server_file = (
|
||||
"./bedrock_server" # HACK: This is a hack to make the server start
|
||||
)
|
||||
elif data["create_type"] == "custom":
|
||||
# TODO: working_directory, executable_update
|
||||
if root_create_data["create_type"] == "raw_exec":
|
||||
@ -518,8 +527,8 @@ class Controller:
|
||||
elif root_create_data["create_type"] == "import_zip":
|
||||
ServersController.set_import(new_server_id)
|
||||
|
||||
elif data["create_type"] == "minecraft-bedrock":
|
||||
if root_create_data["create_type"] == "download_executable":
|
||||
elif data["create_type"] == "minecraft_bedrock":
|
||||
if root_create_data["create_type"] == "download_exe":
|
||||
ServersController.set_import(new_server_id)
|
||||
self.import_helper.download_bedrock_server(
|
||||
new_server_path, new_server_id
|
||||
|
@ -340,7 +340,13 @@ new_server_schema = {
|
||||
"title": "Creation type",
|
||||
"type": "string",
|
||||
"default": "import_server",
|
||||
"enum": ["import_server", "import_zip"],
|
||||
"enum": ["download_exe", "import_server", "import_zip"],
|
||||
},
|
||||
"download_exe_create_data": {
|
||||
"title": "Import server data",
|
||||
"type": "object",
|
||||
"required": [],
|
||||
"properties": {},
|
||||
},
|
||||
"import_server_create_data": {
|
||||
"title": "Import server data",
|
||||
@ -359,7 +365,7 @@ new_server_schema = {
|
||||
"description": "File Crafty should execute"
|
||||
"on server launch",
|
||||
"type": "string",
|
||||
"examples": "bedrock_server.exe",
|
||||
"examples": ["bedrock_server.exe"],
|
||||
"minlength": 1,
|
||||
},
|
||||
"command": {
|
||||
@ -388,7 +394,7 @@ new_server_schema = {
|
||||
"description": "File Crafty should execute"
|
||||
"on server launch",
|
||||
"type": "string",
|
||||
"examples": "bedrock_server.exe",
|
||||
"examples": ["bedrock_server.exe"],
|
||||
"minlength": 1,
|
||||
},
|
||||
"zip_root": {
|
||||
@ -424,11 +430,18 @@ new_server_schema = {
|
||||
},
|
||||
"then": {"required": ["import_zip_create_data"]},
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {"create_type": {"const": "download_exe"}}
|
||||
},
|
||||
"then": {"required": []},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"title": "Only one creation data",
|
||||
"oneOf": [
|
||||
{"required": []},
|
||||
{"required": ["import_server_create_data"]},
|
||||
{"required": ["import_zip_create_data"]},
|
||||
],
|
||||
@ -671,7 +684,7 @@ class ApiServersIndexHandler(BaseApiHandler):
|
||||
return self.finish_json(
|
||||
400, {"status": "error", "error": "INVALID_JSON", "error_data": str(e)}
|
||||
)
|
||||
|
||||
print(data)
|
||||
try:
|
||||
validate(data, new_server_schema)
|
||||
except ValidationError as e:
|
||||
|
@ -24,7 +24,7 @@
|
||||
<h4>{{ translate('serverWizard', 'newServer', data['lang']) }}</h4>
|
||||
<br />
|
||||
|
||||
<form method="post" name="create_server" class="server-wizard" onSubmit="wait_msg()">
|
||||
<form method="post" id="download_exe" name="create_server" class="server-wizard">
|
||||
{% if data["server_api"] and data["online"] %}
|
||||
<fieldset>
|
||||
{% else %}
|
||||
@ -54,10 +54,9 @@
|
||||
}
|
||||
</style>
|
||||
{% end %}
|
||||
{% raw xsrf_form_html() %}
|
||||
<div class="form-group">
|
||||
<label for="server_name">{{ translate('serverWizard', 'serverName', data['lang']) }}</label>
|
||||
<input type="text" class="form-control" id="server_name" name="server_name" placeholder="{{ translate('serverWizard', 'myNewServer', data['lang']) }}" required>
|
||||
<input type="text" class="form-control" id="server_name" name="name" placeholder="{{ translate('serverWizard', 'myNewServer', data['lang']) }}" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@ -110,12 +109,10 @@
|
||||
<h4>{{ translate('serverWizard', 'importServer', data['lang']) }}</h4>
|
||||
<br />
|
||||
|
||||
<form method="post" class="server-wizard" onSubmit="wait_msg(true)">
|
||||
{% raw xsrf_form_html() %}
|
||||
<input type="hidden" value="import_jar" name="create_type">
|
||||
<form method="post" id="import-jar" class="server-wizard">
|
||||
<div class="form-group">
|
||||
<label for="server_name">{{ translate('serverWizard', 'serverName', data['lang']) }}</label>
|
||||
<input type="text" class="form-control" id="server_name" name="server_name" value="" placeholder="{{ translate('serverWizard', 'myNewServer', data['lang']) }}" required>
|
||||
<input type="text" class="form-control" id="server_name" name="name" value="" placeholder="{{ translate('serverWizard', 'myNewServer', data['lang']) }}" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="server">{{ translate('serverWizard', 'serverPath', data['lang']) }} <small>{{
|
||||
@ -172,13 +169,11 @@
|
||||
|
||||
<h4>{{ translate('serverWizard', 'importZip', data['lang']) }}</h4>
|
||||
<br />
|
||||
<form name="zip" method="post" class="server-wizard" onSubmit="wait_msg(true)">
|
||||
{% raw xsrf_form_html() %}
|
||||
<input type="hidden" value="import_zip" name="create_type">
|
||||
<form name="zip" id="import-zip" method="post" class="server-wizard">\
|
||||
|
||||
<div class="form-group">
|
||||
<label for="server_name">{{ translate('serverWizard', 'serverName', data['lang']) }}</label>
|
||||
<input type="text" class="form-control" id="server_name" name="server_name" value="" placeholder="{{ translate('serverWizard', 'myNewServer', data['lang']) }}" required>
|
||||
<input type="text" class="form-control" id="server_name" name="name" value="" placeholder="{{ translate('serverWizard', 'myNewServer', data['lang']) }}" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@ -281,13 +276,11 @@
|
||||
<br />
|
||||
<p class="card-description">
|
||||
|
||||
<form name="zip" method="post" class="server-wizard" onSubmit="wait_msg(true)">
|
||||
{% raw xsrf_form_html() %}
|
||||
<input type="hidden" value="import_zip" name="create_type">
|
||||
<form name="zip" id="import-upload" method="post" class="server-wizard">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="server_name">{{ translate('serverWizard', 'serverName', data['lang']) }}</label>
|
||||
<input type="text" class="form-control" id="server_name" name="server_name" value="" placeholder="{{ translate('serverWizard', 'myNewServer', data['lang']) }}" required>
|
||||
<input type="text" class="form-control" id="server_name" name="name" value="" placeholder="{{ translate('serverWizard', 'myNewServer', data['lang']) }}" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@ -587,7 +580,7 @@
|
||||
},
|
||||
callback: function (result) {
|
||||
if (result == true) {
|
||||
document.create_server.submit();
|
||||
$("#download_exe").submit();
|
||||
}
|
||||
else {
|
||||
return;
|
||||
@ -781,6 +774,186 @@
|
||||
console.log("File changed good");
|
||||
}
|
||||
});
|
||||
function replacer(key, value) {
|
||||
if (key === "roles"){
|
||||
return value
|
||||
}
|
||||
if (key != "ignored_exits") {
|
||||
if (typeof value == "boolean" || key === "host" || key === "version") {
|
||||
return value
|
||||
} else {
|
||||
return (isNaN(value) ? value : +value);
|
||||
}
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
function calcRoles() {
|
||||
let role_ids = $('.roles').map(function() {
|
||||
if ($(this).is(':checked')){
|
||||
return $(this).val();
|
||||
}
|
||||
}).get();
|
||||
console.log(role_ids)
|
||||
return role_ids
|
||||
}
|
||||
async function send_server(data){
|
||||
let token = getCookie("_xsrf")
|
||||
console.log(token)
|
||||
let res = await fetch(`/api/v2/servers/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-XSRFToken': token
|
||||
},
|
||||
body: data,
|
||||
});
|
||||
let responseData = await res.json();
|
||||
if (responseData.status === "ok") {
|
||||
window.location.href = '/panel/dashboard';
|
||||
} else {
|
||||
|
||||
bootbox.alert({
|
||||
title: responseData.error,
|
||||
message: responseData.error_data
|
||||
});
|
||||
}
|
||||
}
|
||||
$(document).ready(function () {
|
||||
|
||||
$("#download_exe").on("submit", async function (e) {
|
||||
wait_msg();
|
||||
e.preventDefault();
|
||||
let jarForm = document.getElementById("download_exe");
|
||||
|
||||
let formData = new FormData(jarForm);
|
||||
//Create an object from the form data entries
|
||||
let formDataObject = Object.fromEntries(formData.entries());
|
||||
console.log(formDataObject);
|
||||
let send_data = {
|
||||
"name": formDataObject.name,
|
||||
"roles": calcRoles(),
|
||||
"monitoring_type": "minecraft_bedrock",
|
||||
"minecraft_bedrock_monitoring_data": {
|
||||
"host": "127.0.0.1",
|
||||
"port": 19132
|
||||
},
|
||||
"create_type": "minecraft_bedrock",
|
||||
"minecraft_bedrock_create_data": {
|
||||
"create_type": "download_exe",
|
||||
"download_exe_create_data": {}
|
||||
}
|
||||
}
|
||||
console.log(send_data);
|
||||
// Format the plain form data as JSON
|
||||
let formDataJsonString = JSON.stringify(send_data, replacer);
|
||||
|
||||
|
||||
console.log(formDataJsonString);
|
||||
|
||||
send_server(formDataJsonString);
|
||||
});
|
||||
|
||||
$("#import-jar").on("submit", async function (e) {
|
||||
wait_msg(true);
|
||||
e.preventDefault();
|
||||
let jarForm = document.getElementById("import-jar");
|
||||
|
||||
let formData = new FormData(jarForm);
|
||||
//Create an object from the form data entries
|
||||
let formDataObject = Object.fromEntries(formData.entries());
|
||||
console.log(formDataObject);
|
||||
let send_data = {
|
||||
"name": formDataObject.name,
|
||||
"roles": calcRoles(),
|
||||
"monitoring_type": "minecraft_bedrock",
|
||||
"minecraft_bedrock_monitoring_data": {
|
||||
"host": "127.0.0.1",
|
||||
"port": formDataObject.port
|
||||
},
|
||||
"create_type": "minecraft_bedrock",
|
||||
"minecraft_bedrock_create_data": {
|
||||
"create_type": "import_server",
|
||||
"import_server_create_data": {
|
||||
"existing_server_path": formDataObject.server_path,
|
||||
"executable": formDataObject.server_jar,
|
||||
"server_properties_port": formDataObject.port
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(send_data);
|
||||
// Format the plain form data as JSON
|
||||
let formDataJsonString = JSON.stringify(send_data, replacer);
|
||||
|
||||
send_server(formDataJsonString);
|
||||
});
|
||||
|
||||
$("#import-zip").on("submit", async function (e) {
|
||||
wait_msg(true);
|
||||
e.preventDefault();
|
||||
let jarForm = document.getElementById("import-zip");
|
||||
|
||||
let formData = new FormData(jarForm);
|
||||
//Create an object from the form data entries
|
||||
let formDataObject = Object.fromEntries(formData.entries());
|
||||
console.log(formDataObject);
|
||||
let send_data = {
|
||||
"name": formDataObject.name,
|
||||
"roles": calcRoles(),
|
||||
"monitoring_type": "minecraft_bedrock",
|
||||
"minecraft_bedrock_monitoring_data": {
|
||||
"host": "127.0.0.1",
|
||||
"port": formDataObject.port
|
||||
},
|
||||
"create_type": "minecraft_bedrock",
|
||||
"minecraft_bedrock_create_data": {
|
||||
"create_type": "import_server",
|
||||
"import_server_create_data": {
|
||||
"existing_server_path": formDataObject.root_path,
|
||||
"executable": formDataObject.server_jar,
|
||||
"server_properties_port": formDataObject.port
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(send_data);
|
||||
// Format the plain form data as JSON
|
||||
let formDataJsonString = JSON.stringify(send_data, replacer);
|
||||
|
||||
send_server(formDataJsonString);
|
||||
});
|
||||
|
||||
$("#import-upload").on("submit", async function (e) {
|
||||
wait_msg(true);
|
||||
e.preventDefault();
|
||||
let jarForm = document.getElementById("import-upload");
|
||||
|
||||
let formData = new FormData(jarForm);
|
||||
//Create an object from the form data entries
|
||||
let formDataObject = Object.fromEntries(formData.entries());
|
||||
console.log(formDataObject);
|
||||
let send_data = {
|
||||
"name": formDataObject.name,
|
||||
"roles": calcRoles(),
|
||||
"monitoring_type": "minecraft_bedrock",
|
||||
"minecraft_bedrock_monitoring_data": {
|
||||
"host": "127.0.0.1",
|
||||
"port": formDataObject.port
|
||||
},
|
||||
"create_type": "minecraft_bedrock",
|
||||
"minecraft_bedrock_create_data": {
|
||||
"create_type": "import_server",
|
||||
"import_server_create_data": {
|
||||
"existing_server_path": formDataObject.root_path,
|
||||
"executable": formDataObject.server_jar,
|
||||
"server_properties_port": formDataObject.port
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(send_data);
|
||||
// Format the plain form data as JSON
|
||||
let formDataJsonString = JSON.stringify(send_data, replacer);
|
||||
send_server(formDataJsonString);
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
{% end %}
|
Loading…
Reference in New Issue
Block a user