diff --git a/misc/hosting-flask.md b/misc/hosting-flask.md new file mode 100644 index 000000000..17bb1a055 --- /dev/null +++ b/misc/hosting-flask.md @@ -0,0 +1,238 @@ +The website will be structured like so: + +``` +websrv.py +templates/tmpl.html +templates/tmpl_lite.html +templates/play.html +static/classisphere.js +static/default.zip +static/style.css +static/jquery.js +``` + +## Content +#### websrv.py +```Python +from flask import Flask, render_template, request +app = Flask(__name__) + +@app.route("/") +def index(): + return '

Welcome!

Click here to play' + +@app.route("/play") +@app.route("/play/") +def play(): + user = request.args.get('user') or 'Singleplayer' + ver = request.args.get('mppass') or '' + addr = request.args.get('ip') + port = request.args.get('port') or '25565' + + if addr: + args = "['%s', '%s', '%s', '%s']" % (user, ver, addr, port) + else: + args = "['%s']" % user + return render_template('play.html', game_args=args) + +if __name__ == "__main__": + app.run() +``` + +#### templates/tmpl.html +```HTML + + + + + + + + + +
+ {% block main %} {% endblock %} +
+ + +``` + +#### templates/tmpl_lite.html +```HTML + + + + + + + +
+ {% block main %} {% endblock %} +
+ + +``` + +#### templates/play.html +```HTML +{% set mobile_mode = request.user_agent.platform in ('android', 'iphone', 'ipad') %} +{% if mobile_mode %} +{% extends 'tmpl_lite.html' %} +{% else %} +{% extends 'tmpl.html' %} +{% endif %} +{% block main %} + +
+
+ + +
+
+ + + +{% if mobile_mode %} + +{% else %} +{% endif %} +{% endblock %} +``` + +#### static/classisphere.js +Download `classicube.s3.amazonaws.com/client/latest/ClassiCube.js` for this + +#### static/default.zip +Download `classicube.net/static/default.zip` for this + +#### static/style.css +```CSS +.row:before, .row:after { + content: " "; + display: table; +} + +.row:after { clear: both; } + +body { margin: 0; } + +.row { + margin-left: auto; + margin-right: auto; + max-width: 62.5em; +} + +a { text-decoration: none; } + +.columns { + position: relative; + float: left; +} + +.sec { + background:#f1ecfa; + padding:10px 0 5px; +} + +#header { background-color:#5870b0; } + +#header h1 { + color:#fff; + margin:0px 10px 0px 10px; +} +``` + +#### static/jquery.js +Download some version of jQuery for this. Version 2.1.1 is known to work. + +## Results + +* If you don't want the game to resize to fit different resolutions, remove the `resizeGameCanvas` code. + +* tmpl_lite.html and + +## Results + +After all this setup, you need to install the flask package for python. + +Then in command prompt/terminal enter: `python websrv.py` + +Then navigate to `http://127.0.0.1:5000/play` in your web browser. If all goes well you should see the web client start in singleplayer. + +To start in multiplayer instead, navigate to `http://127.0.0.1:5000/play?user=test&ip=127.0.0.1&port=25565`