Update Webhost for generation on-site
uploads and tracker do not work yet
This commit is contained in:
parent
4de64eab84
commit
4dc84e1dac
|
@ -48,6 +48,8 @@ app.config["PONY"] = {
|
||||||
app.config["MAX_ROLL"] = 20
|
app.config["MAX_ROLL"] = 20
|
||||||
app.config["CACHE_TYPE"] = "simple"
|
app.config["CACHE_TYPE"] = "simple"
|
||||||
app.autoversion = True
|
app.autoversion = True
|
||||||
|
app.config["HOSTNAME"] = "berserkermulti.world"
|
||||||
|
|
||||||
av = Autoversion(app)
|
av = Autoversion(app)
|
||||||
cache = Cache(app)
|
cache = Cache(app)
|
||||||
Compress(app)
|
Compress(app)
|
||||||
|
|
|
@ -9,12 +9,13 @@ import socket
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
|
import zlib
|
||||||
|
|
||||||
|
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
from MultiServer import Context, server, auto_shutdown, ServerCommandProcessor, ClientMessageProcessor
|
from MultiServer import Context, server, auto_shutdown, ServerCommandProcessor, ClientMessageProcessor
|
||||||
from Utils import get_public_ipv4, get_public_ipv6
|
from Utils import get_public_ipv4, get_public_ipv6, restricted_loads
|
||||||
|
|
||||||
|
|
||||||
class CustomClientMessageProcessor(ClientMessageProcessor):
|
class CustomClientMessageProcessor(ClientMessageProcessor):
|
||||||
|
@ -73,7 +74,8 @@ class WebHostContext(Context):
|
||||||
self.port = room.last_port
|
self.port = room.last_port
|
||||||
else:
|
else:
|
||||||
self.port = get_random_port()
|
self.port = get_random_port()
|
||||||
return self._load(room.seed.multidata, True)
|
|
||||||
|
return self._load(restricted_loads(zlib.decompress(room.seed.multidata)), True)
|
||||||
|
|
||||||
@db_session
|
@db_session
|
||||||
def init_save(self, enabled: bool = True):
|
def init_save(self, enabled: bool = True):
|
||||||
|
|
|
@ -15,12 +15,11 @@ def download_patch(room_id, patch_id):
|
||||||
|
|
||||||
room = Room.get(id=room_id)
|
room = Room.get(id=room_id)
|
||||||
last_port = room.last_port
|
last_port = room.last_port
|
||||||
pname = room.seed.multidata["names"][0][patch.player - 1]
|
|
||||||
|
|
||||||
patch_data = update_patch_data(patch.data, server="berserkermulti.world:" + str(last_port))
|
patch_data = update_patch_data(patch.data, server=f"{app.config['HOSTNAME']}:{last_port}")
|
||||||
patch_data = io.BytesIO(patch_data)
|
patch_data = io.BytesIO(patch_data)
|
||||||
|
|
||||||
fname = f"P{patch.player}_{pname}_{app.jinja_env.filters['suuid'](room_id)}.apbp"
|
fname = f"P{patch.player_id}_{patch.player_name}_{app.jinja_env.filters['suuid'](room_id)}.apbp"
|
||||||
return send_file(patch_data, as_attachment=True, attachment_filename=fname)
|
return send_file(patch_data, as_attachment=True, attachment_filename=fname)
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,17 +30,15 @@ def download_spoiler(seed_id):
|
||||||
|
|
||||||
@app.route("/dl_raw_patch/<suuid:seed_id>/<int:player_id>")
|
@app.route("/dl_raw_patch/<suuid:seed_id>/<int:player_id>")
|
||||||
def download_raw_patch(seed_id, player_id):
|
def download_raw_patch(seed_id, player_id):
|
||||||
patch = select(patch for patch in Patch if patch.player == player_id and patch.seed.id == seed_id).first()
|
patch = select(patch for patch in Patch if patch.player_id == player_id and patch.seed.id == seed_id).first()
|
||||||
|
|
||||||
if not patch:
|
if not patch:
|
||||||
return "Patch not found"
|
return "Patch not found"
|
||||||
else:
|
else:
|
||||||
import io
|
import io
|
||||||
|
|
||||||
pname = patch.seed.multidata["names"][0][patch.player - 1]
|
|
||||||
|
|
||||||
patch_data = update_patch_data(patch.data, server="")
|
patch_data = update_patch_data(patch.data, server="")
|
||||||
patch_data = io.BytesIO(patch_data)
|
patch_data = io.BytesIO(patch_data)
|
||||||
|
|
||||||
fname = f"P{patch.player}_{pname}_{app.jinja_env.filters['suuid'](seed_id)}.apbp"
|
fname = f"P{patch.player_id}_{patch.player_name}_{app.jinja_env.filters['suuid'](seed_id)}.apbp"
|
||||||
return send_file(patch_data, as_attachment=True, attachment_filename=fname)
|
return send_file(patch_data, as_attachment=True, attachment_filename=fname)
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import random
|
import random
|
||||||
import zlib
|
|
||||||
import json
|
|
||||||
|
|
||||||
from flask import request, flash, redirect, url_for, session, render_template
|
from flask import request, flash, redirect, url_for, session, render_template
|
||||||
|
|
||||||
|
@ -124,21 +122,23 @@ def upload_to_db(folder, owner, sid):
|
||||||
for file in os.listdir(folder):
|
for file in os.listdir(folder):
|
||||||
file = os.path.join(folder, file)
|
file = os.path.join(folder, file)
|
||||||
if file.endswith(".apbp"):
|
if file.endswith(".apbp"):
|
||||||
player = int(file.split("P")[1].split(".")[0].split("_")[0])
|
player_text = file.split("_P", 1)[1]
|
||||||
patches.add(Patch(data=open(file, "rb").read(), player=player))
|
player_name = player_text.split("_", 1)[1].split(".", 1)[0]
|
||||||
|
player_id = int(player_text.split(".", 1)[0].split("_", 1)[0])
|
||||||
|
patches.add(Patch(data=open(file, "rb").read(),
|
||||||
|
player_id=player_id, player_name = player_name))
|
||||||
elif file.endswith(".txt"):
|
elif file.endswith(".txt"):
|
||||||
spoiler = open(file, "rt").read()
|
spoiler = open(file, "rt", encoding="utf-8-sig").read()
|
||||||
elif file.endswith("multidata"):
|
elif file.endswith(".multidata"):
|
||||||
try:
|
multidata = open(file, "rb").read()
|
||||||
multidata = json.loads(zlib.decompress(open(file, "rb").read()))
|
|
||||||
except Exception as e:
|
|
||||||
flash(e)
|
|
||||||
if multidata:
|
if multidata:
|
||||||
with db_session:
|
with db_session:
|
||||||
if sid:
|
if sid:
|
||||||
seed = Seed(multidata=multidata, spoiler=spoiler, patches=patches, owner=owner, id=sid)
|
seed = Seed(multidata=multidata, spoiler=spoiler, patches=patches, owner=owner,
|
||||||
|
id=sid, meta={"tags": ["generated"]})
|
||||||
else:
|
else:
|
||||||
seed = Seed(multidata=multidata, spoiler=spoiler, patches=patches, owner=owner)
|
seed = Seed(multidata=multidata, spoiler=spoiler, patches=patches, owner=owner,
|
||||||
|
meta={"tags": ["generated"]})
|
||||||
for patch in patches:
|
for patch in patches:
|
||||||
patch.seed = seed
|
patch.seed = seed
|
||||||
if sid:
|
if sid:
|
||||||
|
@ -146,3 +146,5 @@ def upload_to_db(folder, owner, sid):
|
||||||
if gen is not None:
|
if gen is not None:
|
||||||
gen.delete()
|
gen.delete()
|
||||||
return seed.id
|
return seed.id
|
||||||
|
else:
|
||||||
|
raise Exception("Multidata required, but not found.")
|
||||||
|
|
|
@ -11,8 +11,9 @@ STATE_ERROR = -1
|
||||||
|
|
||||||
class Patch(db.Entity):
|
class Patch(db.Entity):
|
||||||
id = PrimaryKey(int, auto=True)
|
id = PrimaryKey(int, auto=True)
|
||||||
player = Required(int)
|
player_id = Required(int)
|
||||||
data = Required(buffer, lazy=True)
|
player_name = Required(str, 16)
|
||||||
|
data = Required(bytes, lazy=True)
|
||||||
seed = Optional('Seed')
|
seed = Optional('Seed')
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ class Room(db.Entity):
|
||||||
owner = Required(UUID, index=True)
|
owner = Required(UUID, index=True)
|
||||||
commands = Set('Command')
|
commands = Set('Command')
|
||||||
seed = Required('Seed', index=True)
|
seed = Required('Seed', index=True)
|
||||||
multisave = Optional(Json, lazy=True)
|
multisave = Optional(buffer, lazy=True)
|
||||||
show_spoiler = Required(int, default=0) # 0 -> never, 1 -> after completion, -> 2 always
|
show_spoiler = Required(int, default=0) # 0 -> never, 1 -> after completion, -> 2 always
|
||||||
timeout = Required(int, default=lambda: 6 * 60 * 60) # seconds since last activity to shutdown
|
timeout = Required(int, default=lambda: 6 * 60 * 60) # seconds since last activity to shutdown
|
||||||
tracker = Optional(UUID, index=True)
|
tracker = Optional(UUID, index=True)
|
||||||
|
@ -33,11 +34,12 @@ class Room(db.Entity):
|
||||||
class Seed(db.Entity):
|
class Seed(db.Entity):
|
||||||
id = PrimaryKey(UUID, default=uuid4)
|
id = PrimaryKey(UUID, default=uuid4)
|
||||||
rooms = Set(Room)
|
rooms = Set(Room)
|
||||||
multidata = Optional(Json, lazy=True)
|
multidata = Required(bytes, lazy=True)
|
||||||
owner = Required(UUID, index=True)
|
owner = Required(UUID, index=True)
|
||||||
creation_time = Required(datetime, default=lambda: datetime.utcnow())
|
creation_time = Required(datetime, default=lambda: datetime.utcnow())
|
||||||
patches = Set(Patch)
|
patches = Set(Patch)
|
||||||
spoiler = Optional(LongStr, lazy=True)
|
spoiler = Optional(LongStr, lazy=True)
|
||||||
|
meta = Required(Json, lazy=True, default=lambda: {}) # additional meta information/tags
|
||||||
|
|
||||||
|
|
||||||
class Command(db.Entity):
|
class Command(db.Entity):
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<ul>
|
<ul>
|
||||||
{% for patch in patches|list|sort(attribute="player") %}
|
{% for patch in patches|list|sort(attribute="player") %}
|
||||||
<li><a href="{{ url_for("download_patch", patch_id=patch.id, room_id=room.id) }}">
|
<li><a href="{{ url_for("download_patch", patch_id=patch.id, room_id=room.id) }}">
|
||||||
Patch for player {{ patch.player }} - {{ room.seed.multidata["names"][0][patch.player-1] }}</a></li>
|
Patch for player {{ patch.player_id }} - {{ patch.player_name }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in New Issue