Add EULA confirm message on server startup if EULA is not found.

This commit is contained in:
Andrew 2021-11-23 16:11:23 -05:00
parent 0e942311fb
commit dc83dc8fc8
7 changed files with 109 additions and 14 deletions

View File

@ -193,6 +193,35 @@ class Server:
logger.info("Launching Server {} with command {}".format(self.name, self.server_command))
console.info("Launching Server {} with command {}".format(self.name, self.server_command))
e_flag = False
if helper.check_file_exists(os.path.join(self.settings['path'], 'eula.txt')):
f = open(os.path.join(self.settings['path'], 'eula.txt'), 'r')
line = f.readline().lower()
if line == 'eula=true':
e_flag = True
elif line == 'eula = true':
e_flag = True
elif line == 'eula= true':
e_flag = True
elif line == 'eula =true':
e_flag = True
else:
e_flag = False
else:
e_flag = False
if e_flag == False:
websocket_helper.broadcast('send_eula_bootbox', {
'id': self.server_id
})
return False
f.close()
if os.name == "nt":
logger.info("Windows Detected")
creationflags=subprocess.CREATE_NEW_CONSOLE
@ -346,7 +375,7 @@ class Server:
if self.settings['crash_detection']:
logger.warning("The server {} has crashed and will be restarted. Restarting server".format(name))
console.warning("The server {} has crashed and will be restarted. Restarting server".format(name))
self.run_threaded_server()
self.run_threaded_server('en_EN')
return True
else:
logger.critical(
@ -420,6 +449,13 @@ class Server:
console.info("Removing old crash detection watcher thread")
schedule.clear(self.name)
def agree_eula(self, user_lang):
file = os.path.join(self.server_path, 'eula.txt')
f = open(file, 'w')
f.write('eula=true')
f.close
self.run_threaded_server(user_lang)
def is_backup_running(self):
if self.is_backingup:
return True

View File

@ -207,6 +207,10 @@ class AjaxHandler(BaseHandler):
except Exception as e:
logger.error("Could not find PID for requested termsig. Full error: {}".format(e))
return
elif page == "eula":
server_id = self.get_argument('id', None)
svr = self.controller.get_server_obj(server_id)
svr.agree_eula(self.controller.users.get_user_lang_by_id(user_data['user_id']))
@tornado.web.authenticated
def delete(self, page):

View File

@ -237,6 +237,57 @@ if (webSocket) {
});
}
if (webSocket) {
webSocket.on('send_eula_bootbox', function (server_id) {
var x = document.querySelector('.bootbox');
if(x){
x.remove()}
var x = document.querySelector('.modal-backdrop');
if(x){
x.remove()}
bootbox.confirm({
title: '{% raw translate("error", "eulaTitle", data['lang']) %}',
message: '{% raw translate("error", "eulaMsg", data['lang']) %} <br><br><a href="https://account.mojang.com/documents/minecraft_eula" target="_blank">EULA</a><br><br>{% raw translate("error", "eulaAgree", data['lang']) %}',
buttons: {
confirm: {
label: 'Yes',
className: 'btn-info'
},
cancel: {
label: 'No',
className: 'btn-secondary'
}
},
callback: function (result) {
if(result == true){
eulaAgree(server_id.id)
}
else {
location.reload()
}
}
})
});
}
function eulaAgree (server_id, command){
<!-- this getCookie function is in base.html-->
var token = getCookie("_xsrf");
$.ajax({
type: "POST",
headers: {'X-XSRFToken': token},
url: '/ajax/eula?id='+ server_id,
success: function(data){
console.log("got response:");
console.log(data);
location.reload();
}
});
}
function warn(message) {
var closeEl = document.createElement('span');

View File

@ -94,7 +94,7 @@
<br>
<h7>{{ translate('dashboard', 'no-servers', data['lang']) }} {{ translate('dashboard', 'newServer', data['lang']) }}.</h7>
</div>
{% end %}
{% if len(data['servers']) > 0 %}
<table class="table table-hover">
@ -180,7 +180,7 @@
{{ server['stats']['online'] }} / {{ server['stats']['max'] }} {{ translate('dashboard', 'max', data['lang']) }}<br />
{% if server['stats']['desc'] != 'False' %}
<span id="input_motd_{{ server['stats']['server_id']['server_id'] }}" class="input_motd">{{ server['stats']['desc'] }}</span> <br />
{{ server['stats']['desc'] }} <br />
{% end %}
{% if server['stats']['version'] != 'False' %}
@ -221,18 +221,13 @@
{% end %}
{% block js %}
<script src="/static/assets/js/motd.js"></script>
<script>
$(document).ready(function(){
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
if($(window).width() < 1000){
$('.too_small').popover("show");
}
var all_motds = Array.from(document.getElementsByClassName('input_motd'));
for (element of all_motds) {
initParser(element.id, element.id);
};
});
$(window).ready(function(){
$('body').click(function(){
@ -345,7 +340,7 @@ $( document ).ready(function() {
title: '{% raw translate("dashboard", "killing", data['lang']) %}',
message: '<p><i class="fa fa-spin fa-spinner"></i> Loading...</p>'
});
dialog.init(function(){
setTimeout(function(){
location.reload();

View File

@ -13,7 +13,10 @@
"error": "Error!",
"start-error": "Server {} failed to start with error code: {}",
"closedPort": "We have detected port {} may not be open on the host network or a firewall is blocking it. Remote client connections to the server may be limited.",
"internet": "We have detected the machine running Crafty has no connection to the internet. Client connections to the server may be limited."
"internet": "We have detected the machine running Crafty has no connection to the internet. Client connections to the server may be limited.",
"eulaTitle": "Agree To EULA",
"eulaMsg": "You must agree to the EULA. A copy of the Mojang EULA is linked under this message.",
"eulaAgree": "Do you agree?"
},
"404": {
"contact": "Contact Crafty Control Support via Discord",

View File

@ -13,7 +13,10 @@
"error": "Virhe!",
"start-error": "Palvelin {} ei käynnistynyt virhekoodilla: {}",
"closedPort": "Olemme havainneet, että portti {} ei ehkä ole auki isäntäverkossa tai palomuuri estää sen. Etäasiakkaan yhteydet palvelimeen voivat olla rajallisia.",
"internet": "Olemme havainneet, että Crafty -koneella ei ole Internet -yhteyttä. Asiakasyhteydet palvelimelle voivat olla rajalliset."
"internet": "Olemme havainneet, että Crafty -koneella ei ole Internet -yhteyttä. Asiakasyhteydet palvelimelle voivat olla rajalliset.",
"eulaTitle": "Hyväksy EULA",
"eulaMsg": "Sinun on hyväksyttävä EULA. Kopio Mojang EULA:sta on linkitetty tämän viestin alla.",
"eulaAgree": "Oletko samaa mieltä?"
},
"404": {
"contact": "Ota yhteyttä Crafty Control -tukeen Discordin kautta",

View File

@ -13,7 +13,10 @@
"error": "Erreur !",
"start-error": "Le serveur {} n'a pas pu démarrer avec le code d'erreur : {}",
"closedPort": "Nous avons détecté que le port {} n'est peut-être pas ouvert sur le réseau hôte ou qu'un pare-feu le bloque. Les connexions des clients distants au serveur peuvent être limitées.",
"internet": "Nous avons détecté que la machine exécutant Crafty n'a pas de connexion à Internet. Les connexions client au serveur peuvent être limitées."
"internet": "Nous avons détecté que la machine exécutant Crafty n'a pas de connexion à Internet. Les connexions client au serveur peuvent être limitées.",
"eulaTitle": "Accepter le EULA",
"eulaMsg": "Vous devez accepter le EULA. Une copie du CLUF de Mojang est liée sous ce message.",
"eulaAgree": "Êtes-vous d'accord?"
},
"404": {
"contact": "Contacter le Support de Crafty Control via Discord",