mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-25 09:21:10 +00:00
form added for minetest
This commit is contained in:
parent
7c8b1235e7
commit
df662e6899
@ -71,28 +71,24 @@ def subcommand_configure(arguments):
|
||||
|
||||
def set_max_players(max_players):
|
||||
"""Sets the number of max players"""
|
||||
|
||||
aug.set(AUG_PATH + '/max_users', max_players)
|
||||
|
||||
aug.save()
|
||||
|
||||
def enable_pvp(choice):
|
||||
"""Enables pvp"""
|
||||
|
||||
aug.set(AUG_PATH + '/enable_pvp', choice)
|
||||
|
||||
aug.save()
|
||||
|
||||
def set_creative_mode(choice):
|
||||
"""Enables or disables creative mode"""
|
||||
|
||||
aug.set(AUG_PATH + '/creative_mode', choice)
|
||||
|
||||
aug.save()
|
||||
|
||||
def enable_damage(choice):
|
||||
"""Enables damage"""
|
||||
|
||||
aug.set(AUG_PATH + '/enable_damage', choice)
|
||||
|
||||
aug.save()
|
||||
|
||||
@ -19,6 +19,8 @@
|
||||
Plinth module for minetest.
|
||||
"""
|
||||
|
||||
import augeas
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@ -28,7 +30,6 @@ from plinth import cfg
|
||||
from plinth import frontpage
|
||||
from plinth import service as service_module
|
||||
from plinth.utils import format_lazy
|
||||
from plinth.views import ServiceView
|
||||
|
||||
|
||||
version = 2
|
||||
@ -57,6 +58,18 @@ description = [
|
||||
'is needed.'), box_name=_(cfg.box_name)),
|
||||
]
|
||||
|
||||
CONFIG_FILE = '/etc/minetest/minetest.conf'
|
||||
AUG_PATH = '/files' + CONFIG_FILE + '/.anon'
|
||||
|
||||
def load_augeas():
|
||||
"""Initialize Augeas."""
|
||||
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||
augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
aug.set('/augeas/load/Php/lens', 'Php.lns')
|
||||
aug.set('/augeas/load/Php/incl[last() + 1]', CONFIG_FILE)
|
||||
aug.load()
|
||||
return aug
|
||||
|
||||
|
||||
def init():
|
||||
"""Initialize the module."""
|
||||
@ -107,13 +120,6 @@ def disable():
|
||||
frontpage.remove_shortcut('minetest')
|
||||
|
||||
|
||||
class MinetestServiceView(ServiceView):
|
||||
service_id = managed_services[0]
|
||||
diagnostics_module_name = "minetest"
|
||||
description = description
|
||||
show_status_block = True
|
||||
|
||||
|
||||
def diagnose():
|
||||
"""Run diagnostics and return the results."""
|
||||
results = []
|
||||
@ -121,3 +127,40 @@ def diagnose():
|
||||
results.append(action_utils.diagnose_port_listening(30000, 'udp4'))
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def get_max_players_value():
|
||||
"""Return the current Max Players value."""
|
||||
aug = load_augeas()
|
||||
value = aug.get(AUG_PATH + '/max_users')
|
||||
if value:
|
||||
return int(value)
|
||||
|
||||
|
||||
def get_creative_mode_value():
|
||||
"""Return the current Creative mode value."""
|
||||
aug = load_augeas()
|
||||
value = aug.get(AUG_PATH + '/creative_mode')
|
||||
if value == "true":
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def get_enable_pvp_value():
|
||||
"""Return the current Enable pvp value."""
|
||||
aug = load_augeas()
|
||||
value = aug.get(AUG_PATH + '/enable_pvp')
|
||||
if value == "true":
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def get_enable_damage_value():
|
||||
"""Return the current Enable damage value."""
|
||||
aug = load_augeas()
|
||||
value = aug.get(AUG_PATH + '/enable_damage')
|
||||
if value == "true":
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
50
plinth/modules/minetest/forms.py
Normal file
50
plinth/modules/minetest/forms.py
Normal file
@ -0,0 +1,50 @@
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Forms for miinetest module.
|
||||
"""
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from plinth.forms import ServiceForm
|
||||
|
||||
class MinetestForm(ServiceForm):
|
||||
"""Minetest configuration form"""
|
||||
max_players = forms.IntegerField(
|
||||
label=_('Maximum number of players'),
|
||||
required=True,
|
||||
help_text=_('You can change the maximum number of players playing \
|
||||
minetest at a single instance of time'))
|
||||
|
||||
creative_mode = forms.BooleanField(
|
||||
label=_('Enable creative mode'),
|
||||
required=False,
|
||||
help_text=_('Creative Mode changes the rules of the game to make it\
|
||||
more suitable for creative gameplay, rather than challenging\
|
||||
“survival” gameplay.'))
|
||||
|
||||
enable_pvp = forms.BooleanField(
|
||||
label=_('Enable pvp'),
|
||||
required=False,
|
||||
help_text=_('Enabling Player Vs Player will cause players to damage \
|
||||
other players'))
|
||||
|
||||
enable_damage = forms.BooleanField(
|
||||
label=_('Enable damage'),
|
||||
required=False)
|
||||
@ -21,7 +21,7 @@ URLs for the minetest module.
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from plinth.modules.minetest import MinetestServiceView
|
||||
from plinth.modules.minetest.views import MinetestServiceView
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
|
||||
102
plinth/modules/minetest/views.py
Normal file
102
plinth/modules/minetest/views.py
Normal file
@ -0,0 +1,102 @@
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Views for minetest module.
|
||||
"""
|
||||
|
||||
from django.contrib import messages
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from plinth import actions
|
||||
from plinth.views import ServiceView
|
||||
from plinth import action_utils
|
||||
|
||||
|
||||
from . import description, managed_services, get_max_players_value,\
|
||||
get_enable_pvp_value, get_creative_mode_value,\
|
||||
get_enable_damage_value
|
||||
from .forms import MinetestForm
|
||||
|
||||
|
||||
class MinetestServiceView(ServiceView): # pylint: disable=too-many-ancestors
|
||||
"""A specialized view for configuring minetest."""
|
||||
service_id = managed_services[0]
|
||||
diagnostics_module_name = "minetest"
|
||||
description = description
|
||||
show_status_block = True
|
||||
form_class = MinetestForm
|
||||
|
||||
def get_initial(self):
|
||||
"""Return the values to fill in the form."""
|
||||
initial = super().get_initial()
|
||||
|
||||
initial['max_players'] = get_max_players_value()
|
||||
initial['creative_mode'] = get_creative_mode_value()
|
||||
initial['enable_pvp'] = get_enable_pvp_value()
|
||||
initial['enable_damage'] = get_enable_damage_value()
|
||||
return initial
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Change the configurations of Minetest service."""
|
||||
data = form.cleaned_data
|
||||
|
||||
if get_max_players_value() != data['max_players'] and data['max_players'] != None:
|
||||
actions.superuser_run(
|
||||
'minetest',
|
||||
['configure', '--max_players', str(data['max_players'])])
|
||||
messages.success(self.request,
|
||||
_('Maximum players configuration updated'))
|
||||
|
||||
if data['creative_mode'] is True:
|
||||
value = "true"
|
||||
else:
|
||||
value = "false"
|
||||
|
||||
if get_creative_mode_value() != data['creative_mode']:
|
||||
actions.superuser_run(
|
||||
'minetest',
|
||||
['configure', '--creative_mode', value])
|
||||
messages.success(self.request,
|
||||
_('Creative mode configuration updated'))
|
||||
|
||||
if data['enable_pvp'] is True:
|
||||
value = "true"
|
||||
else:
|
||||
value = "false"
|
||||
|
||||
if get_enable_pvp_value() != data['enable_pvp']:
|
||||
actions.superuser_run(
|
||||
'minetest',
|
||||
['configure', '--enable_pvp', value])
|
||||
messages.success(self.request,
|
||||
_('PvP configuration updated'))
|
||||
|
||||
if data['enable_damage'] is True:
|
||||
value = "true"
|
||||
else:
|
||||
value = "false"
|
||||
|
||||
if get_enable_damage_value() != data['enable_damage']:
|
||||
actions.superuser_run(
|
||||
'minetest',
|
||||
['configure', '--enable_damage', value])
|
||||
messages.success(self.request,
|
||||
_('Damage configuration updated'))
|
||||
|
||||
|
||||
return super().form_valid(form)
|
||||
Loading…
x
Reference in New Issue
Block a user