diff --git a/.gitignore b/.gitignore
index 4166b0ae..ecd316cb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,17 +1,21 @@
 .idea
 .vscode
+
 *_Spoiler.txt
 *.bmbp
 *.pyc
+*.pyd
 *.sfc
 *.wixobj
+*.lck
+*multidata
+*multisave
+
 build
 bundle/components.wxs
 dist
 README.html
 .vs/
-*multidata
-*multisave
 EnemizerCLI/
 .mypy_cache/
 RaceRom.py
diff --git a/MultiServer.py b/MultiServer.py
index 6354a2d2..ce518614 100644
--- a/MultiServer.py
+++ b/MultiServer.py
@@ -104,6 +104,7 @@ class Context(Node):
         with open(multidatapath, 'rb') as f:
             self._load(json.loads(zlib.decompress(f.read()).decode("utf-8-sig")),
                        use_embedded_server_options)
+
         self.data_filename = multidatapath
 
     def _load(self, jsonobj: dict, use_embedded_server_options: bool):
@@ -1177,7 +1178,7 @@ def parse_args() -> argparse.Namespace:
 
 
 async def auto_shutdown(ctx, to_cancel=None):
-    await asyncio.sleep(ctx.auto_shutdown * 60)
+    await asyncio.sleep(ctx.auto_shutdown)
     while ctx.running:
         if not ctx.client_activity_timers.values():
             asyncio.create_task(ctx.server.ws_server._close())
@@ -1189,7 +1190,7 @@ async def auto_shutdown(ctx, to_cancel=None):
         else:
             newest_activity = max(ctx.client_activity_timers.values())
             delta = datetime.datetime.now(datetime.timezone.utc) - newest_activity
-            seconds = ctx.auto_shutdown * 60 - delta.total_seconds()
+            seconds = ctx.auto_shutdown - delta.total_seconds()
             if seconds < 0:
                 asyncio.create_task(ctx.server.ws_server._close())
                 ctx.running = False
diff --git a/WebHost.py b/WebHost.py
index 5e635ed3..88e994bf 100644
--- a/WebHost.py
+++ b/WebHost.py
@@ -2,41 +2,17 @@ import os
 import multiprocessing
 import logging
 
-from WebHost import app
+from WebHost import app as raw_app
 from waitress import serve
 
-from WebHost.models import db, Room, db_session, select
+from WebHost.models import db
+from WebHost.autolauncher import autohost
+
+configpath = "config.yaml"
 
 
-
-def autohost(config: dict):
-    return
-    # not implemented yet. https://github.com/ponyorm/pony/issues/527
-    import time
-    from datetime import timedelta, datetime
-
-    def keep_running():
-        # db.bind(**config["PONY"])
-        # db.generate_mapping(check_tables=False)
-        while 1:
-            time.sleep(3)
-            with db_session:
-                rooms = select(
-                    room for room in Room if
-                    room.last_activity >= datetime.utcnow() - timedelta(hours=room.timeout))
-                logging.info(rooms)
-
-    import threading
-    threading.Thread(target=keep_running).start()
-
-
-if __name__ == "__main__":
-    multiprocessing.freeze_support()
-    multiprocessing.set_start_method('spawn')
-    logging.basicConfig(format='[%(asctime)s] %(message)s', level=logging.INFO)
-
-    configpath = "config.yaml"
-
+def get_app():
+    app = raw_app
     if os.path.exists(configpath):
         import yaml
         with open(configpath) as c:
@@ -45,8 +21,19 @@ if __name__ == "__main__":
         logging.info(f"Updated config from {configpath}")
     db.bind(**app.config["PONY"])
     db.generate_mapping(create_tables=True)
-    if app.config["DEBUG"]:
+    return app
+
+
+if __name__ == "__main__":
+    multiprocessing.freeze_support()
+    multiprocessing.set_start_method('spawn')
+    logging.basicConfig(format='[%(asctime)s] %(message)s', level=logging.INFO)
+    app = get_app()
+    if app.config["SELFLAUNCH"]:
         autohost(app.config)
-        app.run(debug=True, port=app.config["PORT"])
-    else:
-        serve(app, port=app.config["PORT"], threads=app.config["WAITRESS_THREADS"])
+    if app.config["SELFHOST"]:  # using WSGI, you just want to run get_app()
+        if app.config["DEBUG"]:
+            autohost(app.config)
+            app.run(debug=True, port=app.config["PORT"])
+        else:
+            serve(app, port=app.config["PORT"], threads=app.config["WAITRESS_THREADS"])
diff --git a/WebHost/__init__.py b/WebHost/__init__.py
index 251e4fb8..be56d2f7 100644
--- a/WebHost/__init__.py
+++ b/WebHost/__init__.py
@@ -2,9 +2,6 @@
 So unless you're Berserker you need to include license information."""
 
 import os
-import logging
-import typing
-import multiprocessing
 import threading
 
 from pony.flask import Pony
@@ -23,9 +20,12 @@ os.makedirs(LOGS_FOLDER, exist_ok=True)
 def allowed_file(filename):
     return filename.endswith(('multidata', ".zip"))
 
+
 app = Flask(__name__)
 Pony(app)
 
+app.config["SELFHOST"] = True
+app.config["SELFLAUNCH"] = True
 app.config["DEBUG"] = False
 app.config["PORT"] = 80
 app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@@ -47,7 +47,6 @@ cache = Cache(app)
 Compress(app)
 
 # this local cache is risky business if app hosting is done with subprocesses as it will not sync. Waitress is fine though
-multiworlds = {}
 
 
 @app.before_request
@@ -57,29 +56,6 @@ def register_session():
         session["_id"] = uuid4()  # uniquely identify each session without needing a login
 
 
-class MultiworldInstance():
-    def __init__(self, room: Room):
-        self.room_id = room.id
-        self.process: typing.Optional[multiprocessing.Process] = None
-        multiworlds[self.room_id] = self
-
-    def start(self):
-        if self.process and self.process.is_alive():
-            return False
-
-        logging.info(f"Spinning up {self.room_id}")
-        with db_session:
-            self.process = multiprocessing.Process(group=None, target=run_server_process,
-                                                   args=(self.room_id, app.config["PONY"]),
-                                                   name="MultiHost")
-        self.process.start()
-
-    def stop(self):
-        if self.process:
-            self.process.terminate()
-            self.process = None
-
-
 @app.route('/seed/
     {% endif %}
-    This room will be closed after {{ room.timeout }} hours of inactivity. Should you wish to continue later,
+    This room will be closed after {{ room.timeout//60//60 }} hours of inactivity. Should you wish to continue later,
     you can simply refresh this page and the server will be started again.
     {% if room.owner == session["_id"] %}
         
This webpage is still under heavy construction. Database may be wiped as I see fit + and some stuff may be broken.
This is a randomizer for The Legend of Zelda: A Link to the Past.
It is a multiworld, meaning items get shuffled across multiple players' worlds which get exchanged on pickup through the internet.
diff --git a/host.yaml b/host.yaml index c5bf44af..748cdeaa 100644 --- a/host.yaml +++ b/host.yaml @@ -34,7 +34,7 @@ server_options: # "goal" -> client can ask for remaining items after goal completion # warning: only Berserker's Multiworld clients of version 2.1+ send game beaten information remaining_mode: "goal" - # automatically shut down the server after this many minutes without new location checks, 0 to keep running + # automatically shut down the server after this many seconds without new location checks, 0 to keep running auto_shutdown: 0 #options for MultiMystery.py multi_mystery_options: