bl2mods/Mods/WebPanel/__init__.py
2023-03-22 12:57:56 -04:00

73 lines
1.5 KiB
Python

from Mods.ModMenu import EnabledSaveType
from Mods.ModUtils import SdkMod
from unrealsdk import Log
from . import routes
from .server import Server
class WebPanel(SdkMod):
'Web-based control panel and API for borderlands'
Name = 'Web Panel'
Description = 'Web-based control panel for Borderlands'
Author = 'Izalia Mae'
Version = '0.1'
def __init__(self):
self.set_enable_state('settings')
self.set_games('BL2', 'TPS', 'AoDK')
self.set_types('Utility')
self._server = Server(self)
self.Options.new_boolean(
'Localhost', 'Only listen on localhost',
default = False,
id = 'localhost'
)
self.Options.new_boolean(
'AccessLog', 'Log server accesses to the conolse',
default = False,
id = 'access_log'
)
def __getattr__(self, key):
if key == 'host':
localhost = object.__getattribute__(self, 'Options')[0].CurrentValue
return '127.0.0.1' if localhost else '0.0.0.0'
elif key == 'port':
return 8100
elif key == 'server':
return self._server
elif key == 'access_log':
access_log = object.__getattribute__(self, 'Options')[1]
return access_log.CurrentValue
return SdkMod.__getattr__(self, key)
def handle_enable(self):
self.server.start()
def handle_disable(self):
self.server.stop()
def handle_option_change(self, option, new_value):
localhost = self.Options.get('localhost')
if option == localhost and localhost.CurrentValue != new_value and self.server.running:
self.server.stop()
self.server.start()
WebPanel().register()