2020-06-13 08:37:05 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import os
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-27 05:04:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import uuid
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import base64
							 | 
						
					
						
							
								
									
										
										
										
											2020-12-05 00:43:18 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import socket
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 08:37:05 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-14 19:35:02 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import jinja2.exceptions
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from pony.flask import Pony
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-01 02:32:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from flask import Flask, request, redirect, url_for, render_template, Response, session, abort, send_from_directory
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-21 15:32:31 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from flask_caching import Cache
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-30 07:32:05 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from flask_compress import Compress
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-31 17:28:46 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from worlds.AutoWorld import AutoWorldRegister
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-16 11:26:54 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from .models import *
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-16 11:26:54 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-14 09:45:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								UPLOAD_FOLDER = os.path.relpath('uploads')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								LOGS_FOLDER = os.path.relpath('logs')
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 10:16:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								os.makedirs(LOGS_FOLDER, exist_ok=True)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 08:37:05 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app = Flask(__name__)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Pony(app)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-21 15:32:31 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-25 22:40:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.jinja_env.filters['any'] = any
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.jinja_env.filters['all'] = all
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-10 17:42:22 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.config["SELFHOST"] = True
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-18 01:18:37 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.config["GENERATORS"] = 8  # maximum concurrent world gens
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-10 17:42:22 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.config["SELFLAUNCH"] = True
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-10 15:32:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.config["DEBUG"] = False
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.config["PORT"] = 80
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 08:37:05 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-16 20:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.config['MAX_CONTENT_LENGTH'] = 64 * 1024 * 1024  # 64 megabyte limit
							 | 
						
					
						
							
								
									
										
										
										
											2020-12-05 00:43:18 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# if you want to deploy, make sure you have a non-guessable secret key
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.config["SECRET_KEY"] = bytes(socket.gethostname(), encoding="utf-8")
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-09 01:41:37 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# at what amount of worlds should scheduling be used, instead of rolling in the webthread
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.config["JOB_THRESHOLD"] = 2
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.config['SESSION_PERMANENT'] = True
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-27 04:05:42 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# waitress uses one thread for I/O, these are for processing of views that then get sent
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-03 14:32:32 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# archipelago.gg uses gunicorn + nginx; ignoring this option
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-27 04:05:42 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.config["WAITRESS_THREADS"] = 10
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-03 14:32:32 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# a default that just works. archipelago.gg runs on mariadb
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-14 07:44:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.config["PONY"] = {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    'provider': 'sqlite',
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-13 23:36:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    'filename': os.path.abspath('ap.db3'),
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-14 07:44:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    'create_db': True
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-02 22:11:52 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.config["MAX_ROLL"] = 20
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-21 15:32:31 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.config["CACHE_TYPE"] = "simple"
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-03 05:26:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.config["JSON_AS_ASCII"] = False
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-10 15:26:30 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.config["PATCH_TARGET"] = "archipelago.gg"
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-03 05:26:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-21 15:32:31 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								cache = Cache(app)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-30 07:32:05 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Compress(app)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 08:37:05 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-27 05:04:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from werkzeug.routing import BaseConverter
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								class B64UUIDConverter(BaseConverter):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    def to_python(self, value):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return uuid.UUID(bytes=base64.urlsafe_b64decode(value + '=='))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    def to_url(self, value):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return base64.urlsafe_b64encode(value.bytes).rstrip(b'=').decode('ascii')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# short UUID
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.url_map.converters["suuid"] = B64UUIDConverter
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.jinja_env.filters['suuid'] = lambda value: base64.urlsafe_b64encode(value.bytes).rstrip(b'=').decode('ascii')
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 08:37:05 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 22:48:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@app.before_request
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def register_session():
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    session.permanent = True  # technically 31 days after the last visit
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if not session.get("_id", None):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        session["_id"] = uuid4()  # uniquely identify each session without needing a login
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 10:16:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-14 19:35:02 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@app.errorhandler(404)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								@app.errorhandler(jinja2.exceptions.TemplateNotFound)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								def page_not_found(err):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return render_template('404.html'), 404
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-11 20:52:30 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# Start Playing Page
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								@app.route('/start-playing')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								def start_playing():
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return render_template(f"startPlaying.html")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-24 23:09:34 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# Player settings pages
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								@app.route('/games/<string:game>/player-settings')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								def player_settings(game):
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-25 15:49:51 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return render_template(f"player-settings.html", game=game)
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-24 23:09:34 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-09-17 18:41:26 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# Game Info Pages
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								@app.route('/games/<string:game>/info/<string:lang>')
							 | 
						
					
						
							
								
									
										
										
										
											2021-09-17 20:35:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def game_info(game, lang):
							 | 
						
					
						
							
								
									
										
										
										
											2021-09-17 18:41:26 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return render_template('gameInfo.html', game=game, lang=lang)
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-14 22:27:43 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-14 19:35:02 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-14 22:27:43 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# List of supported games
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								@app.route('/games')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								def games():
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-31 17:28:46 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    worlds = {}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for game, world in AutoWorldRegister.world_types.items():
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if not world.hidden:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            worlds[game] = world.__doc__ if world.__doc__ else "No description provided."
							 | 
						
					
						
							
								
									
										
										
										
											2021-09-17 18:41:26 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return render_template("supportedGames.html", worlds=worlds)
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-14 19:35:02 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-03 17:46:47 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@app.route('/tutorial/<string:game>/<string:file>/<string:lang>')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								def tutorial(game, file, lang):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return render_template("tutorial.html", game=game, file=file, lang=lang)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-20 22:41:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@app.route('/tutorial/')
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-03 17:46:47 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def tutorial_landing():
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return render_template("tutorialLanding.html")
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-31 19:59:33 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-22 20:01:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@app.route('/faq/<string:lang>/')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								def faq(lang):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return render_template("faq.html", lang=lang)
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-14 23:45:23 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-27 05:04:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@app.route('/seed/<suuid:seed>')
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-30 21:15:47 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def viewSeed(seed: UUID):
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    seed = Seed.get(id=seed)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-26 19:29:33 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if not seed:
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-21 15:32:31 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        abort(404)
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-24 14:46:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return render_template("viewSeed.html", seed=seed,
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-26 19:29:33 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                           rooms=[room for room in seed.rooms if room.owner == session["_id"]])
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-27 05:04:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@app.route('/new_room/<suuid:seed>')
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-26 19:29:33 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def new_room(seed: UUID):
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    seed = Seed.get(id=seed)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-26 19:29:33 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if not seed:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        abort(404)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    room = Room(seed=seed, owner=session["_id"], tracker=uuid4())
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    commit()
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-30 21:15:47 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return redirect(url_for("hostRoom", room=room.id))
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 10:16:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def _read_log(path: str):
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-14 08:11:56 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if os.path.exists(path):
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-22 03:53:00 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        with open(path, encoding="utf-8-sig") as log:
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-14 08:11:56 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            yield from log
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    else:
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-14 09:45:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        yield f"Logfile {path} does not exist. " \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              f"Likely a crash during spinup of multiworld instance or it is still spinning up."
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 10:16:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-27 05:04:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@app.route('/log/<suuid:room>')
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-26 19:29:33 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def display_log(room: UUID):
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return Response(_read_log(os.path.join("logs", str(room) + ".txt")), mimetype="text/plain;charset=UTF-8")
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 10:16:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-24 14:08:45 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@app.route('/room/<suuid:room>', methods=['GET', 'POST'])
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-30 21:15:47 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def hostRoom(room: UUID):
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    room = Room.get(id=room)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-23 02:50:07 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if room is None:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return abort(404)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-20 20:03:06 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if request.method == "POST":
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if room.owner == session["_id"]:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            cmd = request.form["cmd"]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            Command(room=room, commandtext=cmd)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            commit()
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-14 07:44:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-10 17:42:22 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    with db_session:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        room.last_activity = datetime.utcnow()  # will trigger a spinup, if it's not already running
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 10:16:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-30 21:15:47 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return render_template("hostRoom.html", room=room)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 08:37:05 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-09-03 12:50:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-25 16:07:36 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@app.route('/hosted/<suuid:room>', methods=['GET', 'POST'])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								def hostRoomRedirect(room: UUID):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return redirect(url_for("hostRoom", room=room))
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-13 08:37:05 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-09-03 12:50:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-01 02:32:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@app.route('/favicon.ico')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								def favicon():
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-02 19:10:42 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return send_from_directory(os.path.join(app.root_path, 'static/static'),
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-01 02:32:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                               'favicon.ico', mimetype='image/vnd.microsoft.icon')
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-31 19:59:33 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-10 21:52:45 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@app.route('/discord')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								def discord():
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return redirect("https://discord.gg/archipelago")
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-02 22:11:52 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-11 16:59:37 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from WebHostLib.customserver import run_server_process
							 | 
						
					
						
							
								
									
										
										
										
											2020-12-01 01:33:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from . import tracker, upload, landing, check, generate, downloads, api  # to trigger app routing picking up on it
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-24 23:09:34 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.register_blueprint(api.api_endpoints)
							 |