|
@ -0,0 +1,39 @@ |
|
|
|
|
|
#!flask/bin/python |
|
|
|
|
|
import sqlite3 as sql |
|
|
|
|
|
from flask import Flask,abort,request,jsonify |
|
|
|
|
|
|
|
|
|
|
|
START_PORT = 8127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
with sql.connect("database.db") as con: |
|
|
|
|
|
cur = con.cursor() |
|
|
|
|
|
cur.execute('CREATE TABLE IF NOT EXISTS games (id INTEGER PRIMARY KEY, ip TEXT, running INTEGER, port INTEGER, player_count INTEGER)') |
|
|
|
|
|
con.commit() |
|
|
|
|
|
except: |
|
|
|
|
|
con.rollback() |
|
|
|
|
|
finally: |
|
|
|
|
|
con.close() |
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/create',methods = ['POST']) |
|
|
|
|
|
def create(): |
|
|
|
|
|
try: |
|
|
|
|
|
with sql.connect("database.db") as con: |
|
|
|
|
|
port = START_PORT |
|
|
|
|
|
cur = con.cursor() |
|
|
|
|
|
rows = True |
|
|
|
|
|
while rows: |
|
|
|
|
|
port += 1 |
|
|
|
|
|
cur.execute("SELECT * FROM games WHERE port = ?", (port,)) |
|
|
|
|
|
rows = cur.fetchall() |
|
|
|
|
|
cur.execute("INSERT INTO games (ip,port) VALUES (?,?)", (request.remote_addr, port)) |
|
|
|
|
|
except: |
|
|
|
|
|
con.rollback() |
|
|
|
|
|
finally: |
|
|
|
|
|
con.close() |
|
|
|
|
|
return jsonify({'ip' : request.remote_addr, 'port' : port}) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
|
app.run(debug=True) |