diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc index 83cf9ad..a0e5acb 100644 Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ diff --git a/__pycache__/settings.cpython-312.pyc b/__pycache__/settings.cpython-312.pyc new file mode 100644 index 0000000..222a210 Binary files /dev/null and b/__pycache__/settings.cpython-312.pyc differ diff --git a/app.py b/app.py index 8e72395..79980bb 100644 --- a/app.py +++ b/app.py @@ -1,52 +1,59 @@ from flask import * +from main import launchserver import libtmux + app = Flask("Terradash") server = libtmux.Server() session = None + + def initialize_tmux_session(): global session # Versuche, die bestehende Session zu finden if server.has_session("terradash"): session = server.sessions.get(session_name="terradash") + def get_term(): - print(session) - try: - if not session: - print(session) - return ["No Terminal is running"] - window = session.active_window - #rpane = window.panes[1] - lpane = window.panes[0] - return lpane.capture_pane() - except Exception as e: - return f"Error: {e}" + lpane = getlpane() + return lpane.capture_pane(), lpane.pane_current_command -def enter_command(command): - print(session) - try: - if not session: - print(session) - return ["No Terminal is running"] - window = session.active_window - #rpane = window.panes[1] - lpane = window.panes[0] - lpane.send_keys(command) - except Exception as e: - return f"Error: {e}" -@app.route('/term', methods=['GET',"POST"]) +def getlpane() -> libtmux.Pane: + print(session) + if not session: + print(session) + return ["No Terminal is running"] + window = session.active_window + lpane = window.panes[0] + return lpane + + +@app.route("/term", methods=["GET", "POST"]) def get_terminal_output(): if request.method == "POST": - data = list(request.data.decode()) - print(type(data),data,len(data)) + data = request.data.decode() + print(data) + if data == "bla": print("test") - enter_command("bla") + getlpane().send_keys("test") + elif data == "start": + launchserver(getlpane()) + + elif data == "stop": + getlpane().send_keys("exit") + return ["sucessful"] elif request.method == "GET": - return get_term() + term = get_term() + if term[1] == "mono": + return term[0] + else: + return ["Server not running."] + + @app.route("/") def root(): return render_template("index.html") @@ -54,4 +61,4 @@ def root(): if __name__ == "__main__": initialize_tmux_session() - app.run(host="0.0.0.0",debug=True) \ No newline at end of file + app.run(host="0.0.0.0", debug=True) diff --git a/main.py b/main.py index cec885e..025b609 100644 --- a/main.py +++ b/main.py @@ -1,27 +1,37 @@ import libtmux -from os import path +import settings import libtmux.constants -path = path.dirname(__file__)+"/" + +def launchserver(lpane: libtmux.Pane): + lpane.send_keys(settings.RUN_SERVER_COMMAND) + lpane.enter() + lpane.send_keys(settings.LAUNCH_WORLD) + lpane.send_keys(settings.MAX_PLAYERS) + lpane.send_keys(settings.PORT) + lpane.send_keys(settings.FORWARD_PORT) + lpane.send_keys(settings.PASSWORD) + if __name__ == "__main__": try: server = libtmux.Server() - session = server.new_session("terradash",start_directory=path) + session = server.new_session("terradash", start_directory=settings.SERVER_PATH) window = session.active_window rpane = window.active_pane - lpane = window.split(direction=libtmux.constants.PaneDirection.Right,start_directory=path) + lpane = window.split( + direction=libtmux.constants.PaneDirection.Right, + start_directory=settings.path, + ) rpane.send_keys("clear") lpane.send_keys("clear") - #rpane.send_keys("cd TerrariaServer") - #rpane.send_keys("mono --server --gc=sgen -O=all ./TerrariaServer.exe") - rpane.send_keys("cowsay huhu") + launchserver(rpane) lpane.send_keys("python3 app.py") - + server.attach_session("terradash") except Exception as e: - print(f"Error: {e}") \ No newline at end of file + print(f"Error: {e}") diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..cae7f93 --- /dev/null +++ b/settings.py @@ -0,0 +1,17 @@ +from os import path + +path = ( + path.dirname(__file__) + "/" +) # Path ist das Verzeichnis wo Terradash lokalisiert ist. + + +## Settings +LAUNCH_WORLD = "1" +MAX_PLAYERS = "" +PORT = "" +FORWARD_PORT = "y" +PASSWORD = "" + + +RUN_SERVER_COMMAND = "clear & mono --server --gc=sgen -O=all ./TerrariaServer.exe" +SERVER_PATH = path + "/TerrariaServer" diff --git a/static/Script.js b/static/Script.js deleted file mode 100644 index e69de29..0000000 diff --git a/static/background.png b/static/background.png new file mode 100644 index 0000000..6e68933 Binary files /dev/null and b/static/background.png differ diff --git a/static/logo.png b/static/logo.png new file mode 100644 index 0000000..32818b7 Binary files /dev/null and b/static/logo.png differ diff --git a/static/style.css b/static/style.css index 6f39f8d..92e01ac 100644 --- a/static/style.css +++ b/static/style.css @@ -3,9 +3,9 @@ a { } body { - background-color: black; color: chartreuse; } + #dash { display: flex; align-content: center; @@ -18,7 +18,16 @@ body { border-color: chartreuse; padding: 10px; border-radius: 20px; + border-style:hidden; + margin-bottom: 10px; + } +#buttons { + display: flex; + flex-direction: column; + padding: 10px; +} + .input { color: chartreuse; @@ -31,16 +40,21 @@ body { } #terminal { - background-color: #000; /* Schwarzer Hintergrund für das Terminal */ - color: chartreuse; /* Grüne Schriftfarbe */ + background-color: #0001002a; + color: chartreuse; border-style: solid; - border-color: chartreuse; /* Grüne Umrandung */ - border-radius: 20px; /* Abgerundete Ecken */ - padding: 15px; /* Innenabstand */ - font-family: 'Courier New', Courier, monospace; /* Monospace-Schriftart */ - font-size: 16px; /* Schriftgröße */ + border-color: chartreuse; + border-radius: 20px; + padding: 15px; + font-family: 'Courier New', Courier, monospace; + font-size: 16px; width: 100%; - height: 100%; /* Höhe des Terminalfensters */ - overflow-y: auto; /* Scrollen bei zu viel Inhalt */ - box-shadow: 0 0 10px rgba(0, 255, 0, 0.5); /* Glüheffekt der grünen Umrandung */ + height: 100%; + overflow-y: auto; + box-shadow: 0 0 10px rgba(0, 255, 0, 0.5); + flex-grow: 1; +} +#dash { + display: flex; + height: 100vh; } diff --git a/templates/index.html b/templates/index.html index 6780e4b..acbbef5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,27 +4,30 @@