61 lines
1.2 KiB
Python
61 lines
1.2 KiB
Python
import json
|
|
import unrealsdk
|
|
|
|
from Mods.ModMenu import Mods
|
|
from Mods.ModUtils import Player
|
|
from traceback import format_exc
|
|
|
|
from .server import Response, route
|
|
|
|
|
|
@route('/')
|
|
def home(request):
|
|
return Response('UvU')
|
|
|
|
|
|
@route('/api/v1/mods')
|
|
def mods(request):
|
|
data = []
|
|
|
|
for mod in sorted(Mods, key=lambda mod: mod.Name):
|
|
data.append({
|
|
'name': mod.Name,
|
|
'author': mod.Author,
|
|
'description': mod.Description,
|
|
'enabled': mod.IsEnabled
|
|
})
|
|
|
|
return Response(data)
|
|
|
|
|
|
@route('/api/v1/console', 'POST')
|
|
def console(request):
|
|
data = request.read().decode('utf-8')
|
|
player = Player.default()
|
|
player.console_command(data)
|
|
|
|
return Response({'msg': 'Command executed'})
|
|
|
|
|
|
@route('/api/v1/eval', 'POST')
|
|
def eval_python(request):
|
|
data = request.read()
|
|
|
|
if data:
|
|
try:
|
|
exec(data, globals(), locals())
|
|
resp_data = globals().pop('resp_data')
|
|
|
|
if isinstance(resp_data, Response):
|
|
return resp_data
|
|
|
|
elif isinstance(resp_data, (list, set, tuple, dict)):
|
|
resp_data = json.dumps(resp_data, indent=4)
|
|
|
|
return Response(resp_data if resp_data != None else 'UvU')
|
|
|
|
except Exception:
|
|
return Response(format_exc())
|
|
|
|
return Response('Failed to provide python code', status=400)
|