diff --git a/WebHostLib/autolauncher.py b/WebHostLib/autolauncher.py
index 90838671200c..7254dd46e136 100644
--- a/WebHostLib/autolauncher.py
+++ b/WebHostLib/autolauncher.py
@@ -6,6 +6,7 @@
import threading
import time
import typing
+from uuid import UUID
from datetime import timedelta, datetime
from pony.orm import db_session, select, commit
@@ -62,6 +63,16 @@ def autohost(config: dict):
def keep_running():
try:
with Locker("autohost"):
+ # delete unowned user-content
+ with db_session:
+ # >>> bool(uuid.UUID(int=0))
+ # True
+ rooms = Room.select(lambda room: room.owner == UUID(int=0)).delete(bulk=True)
+ seeds = Seed.select(lambda seed: seed.owner == UUID(int=0) and not seed.rooms).delete(bulk=True)
+ slots = Slot.select(lambda slot: not slot.seed).delete(bulk=True)
+ # Command gets deleted by ponyorm Cascade Delete, as Room is Required
+ if rooms or seeds or slots:
+ logging.info(f"{rooms} Rooms, {seeds} Seeds and {slots} Slots have been deleted.")
run_guardian()
while 1:
time.sleep(0.1)
@@ -191,6 +202,6 @@ def guard():
guardian = threading.Thread(name="Guardian", target=guard)
-from .models import Room, Generation, STATE_QUEUED, STATE_STARTED, STATE_ERROR, db, Seed
+from .models import Room, Generation, STATE_QUEUED, STATE_STARTED, STATE_ERROR, db, Seed, Slot
from .customserver import run_server_process, get_static_server_data
from .generate import gen_game
diff --git a/WebHostLib/templates/userContent.html b/WebHostLib/templates/userContent.html
index c20d39f46d82..3603d4112d20 100644
--- a/WebHostLib/templates/userContent.html
+++ b/WebHostLib/templates/userContent.html
@@ -25,6 +25,7 @@
Your Rooms
Players |
Created (UTC) |
Last Activity (UTC) |
+ Mark for deletion |
@@ -35,6 +36,7 @@ Your Rooms
{{ room.seed.slots|length }} |
{{ room.creation_time.strftime("%Y-%m-%d %H:%M") }} |
{{ room.last_activity.strftime("%Y-%m-%d %H:%M") }} |
+ Delete next maintenance. |
{% endfor %}
@@ -51,6 +53,7 @@ Your Seeds
Seed |
Players |
Created (UTC) |
+ Mark for deletion |
@@ -60,6 +63,7 @@ Your Seeds
{% if seed.multidata %}{{ seed.slots|length }}{% else %}1{% endif %}
|
{{ seed.creation_time.strftime("%Y-%m-%d %H:%M") }} |
+ Delete next maintenance. |
{% endfor %}
diff --git a/WebHostLib/upload.py b/WebHostLib/upload.py
index af4ed264aacd..884c1913f8f9 100644
--- a/WebHostLib/upload.py
+++ b/WebHostLib/upload.py
@@ -7,7 +7,7 @@
import zlib
from io import BytesIO
-from flask import request, flash, redirect, url_for, session, render_template
+from flask import request, flash, redirect, url_for, session, render_template, abort
from markupsafe import Markup
from pony.orm import commit, flush, select, rollback
from pony.orm.core import TransactionIntegrityError
@@ -219,3 +219,29 @@ def user_content():
rooms = select(room for room in Room if room.owner == session["_id"])
seeds = select(seed for seed in Seed if seed.owner == session["_id"])
return render_template("userContent.html", rooms=rooms, seeds=seeds)
+
+
+@app.route("/disown_seed/", methods=["GET"])
+def disown_seed(seed):
+ seed = Seed.get(id=seed)
+ if not seed:
+ return abort(404)
+ if seed.owner != session["_id"]:
+ return abort(403)
+
+ seed.owner = 0
+
+ return redirect(url_for("user_content"))
+
+
+@app.route("/disown_room/", methods=["GET"])
+def disown_room(room):
+ room = Room.get(id=room)
+ if not room:
+ return abort(404)
+ if room.owner != session["_id"]:
+ return abort(403)
+
+ room.owner = 0
+
+ return redirect(url_for("user_content"))