diff --git a/chat/minecraft-chat.ini b/chat/minecraft-chat.ini new file mode 100644 index 0000000..dccc3e8 --- /dev/null +++ b/chat/minecraft-chat.ini @@ -0,0 +1,11 @@ +[uwsgi] +module = wsgi:application + +master = true +processes = 2 + +socket = minecraft-chat.sock +chmod-socket = 664 +vacuum = true + +die-on-term = true diff --git a/chat/server.py b/chat/server.py new file mode 100644 index 0000000..cd86e2d --- /dev/null +++ b/chat/server.py @@ -0,0 +1,34 @@ +import logging +import subprocess + +from flask import Flask, request + +app = Flask(__name__) + + +@app.before_first_request +def setup_logging(): + app.logger.addHandler(logging.StreamHandler()) + app.logger.setLevel(logging.INFO) + + +@app.route('/chat/', methods=['GET', 'POST']) +def send_chat(): + if request.method == 'POST': + if request.form.get('email', None): + return 'Text was entered into honeypot!', 200 + if not request.form.get('say-text', None): + return 'No message to send!', 422 + if request.form.get('say-username', None): + subprocess.call(['/usr/bin/screen', '-S', 'mc-panic-shack', '-p', '0', '-X', 'stuff', + '/say [{}]: {}\015'.format(request.form['say-username'], request.form['say-text'])]) + else: + subprocess.call(['/usr/bin/screen', '-S', 'mc-panic-shack', '-p', '0', '-X', 'stuff', + '/say {}\015'.format(request.form['say-text'])]) + return 'Sending chat: ' + request.form.get('say-username', '') + ': ' + request.form['say-text'] + else: + app.logger.info('Hello, world!') + return 'Hello, world!' + +if __name__ == "__main__": + app.run(host='0.0.0.0', port="8888") diff --git a/css/styles.css b/css/styles.css index dd32bb2..732ddde 100644 --- a/css/styles.css +++ b/css/styles.css @@ -81,3 +81,52 @@ ol li code { max-height: 600px; overflow: scroll; } + +#say-header { + margin-top: 15px; + margin-bottom: 10px; +} + +#say-form { + border: 1px dashed darkgray; + padding: 10px; +} + +#say-form label { + width: 100%; +} + +#say-form, #say-send { + margin-top: 5px; +} + +#say-username, #say-text { + margin-bottom: 5px; + margin-right: 5px; +} + +#say-text { + width: 100%; +} + +#say-dnf { + position: absolute; + left: -2000px; +} + +#say-sending { + display: none; +} + +#say-error { + color: darkred; +} + +#say-success { + display: none; +} + +#say-notice { + margin-top: 5px; + margin-bottom: 0; +} diff --git a/index.html b/index.html index 02b2dde..d2d127a 100644 --- a/index.html +++ b/index.html @@ -85,10 +85,30 @@
Updated every 10 seconds.
+