commit aa73b8ee75fa653422c9f80d46e59108fae28cae Author: Boyan Date: Sun Aug 27 21:28:05 2023 +0200 Initial commit(Player add and list) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba0430d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..afcd70c --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# Leagalizer +Automatic league of legends tournament organizer. + + +Stages of a LoL tournament: +* [Sign-up](#sign-up) +* [Playoffs](#playoffs) + + +## Sign-up (Flask) +An arbitrary number of players walk up to a physical machine(either a tablet or a laptop) on which they register for the tournament by providing their IGN, real name and phone number. + +During submission of said data the following checks occur: +* Validity of phone number +* IGN Check + +## Playoffs (Flask) +When the tournament actually starts, players are called on their phones to arrive by the table that they're assigned within 10(arbitrary number) minutes. + +Tables are assigned randomly and have computers running the [Leagalizer Client](#leagalizer-client) on them. + +### Leagalizer client(LCU Python lib) +The Leagalizer client's job is to check if the players are: + * At their assigned table + * Logged in to the correct account + * In-game +And to report to the main server when a game is over and what the result was. + diff --git a/src/sign_play/app.py b/src/sign_play/app.py new file mode 100644 index 0000000..c47d6b7 --- /dev/null +++ b/src/sign_play/app.py @@ -0,0 +1,71 @@ +from flask import Flask, render_template, request, redirect, url_for, session +from config import api_key +from requests import get +from datetime import datetime +from json import dumps, loads +from subprocess import Popen +app = Flask(__name__) +app.secret_key = 'hejrwfkjewhrjewkrhewkjrhwjkdbs' + +MAX_PLAYERS = 100 + +def check_valid_phone_num(number:int): + if len(str(number)) == 10: + return True + return False + +def check_ign(ign:str): + player = get(f"https://eun1.api.riotgames.com/lol/summoner/v4/summoners/by-name/{ign}?api_key={api_key}") + if player.status_code == 200: + return True + return False + + +class Players: + def __init__(self) -> None: + with open('players.json', 'r') as f: + self.players = loads(f.read()) + + def check_if_player_exists(self, ign:str): + if ign in self.players.keys(): + return True + return False + + def add_player(self, ign:str, phone:int): + if not self.check_if_player_exists(ign): + self.players[ign] = phone + with open('players.json', 'w') as f: + f.write(dumps(self.players)) + return True + return False + + +@app.route('/', methods=['GET', 'POST']) +def index(): + return render_template('index.html', players=Players().players) + +@app.route('/success/') +def success(): + return render_template('success.html') + +@app.route('/create/', methods=['GET', 'POST']) +def create(): + if len(Players().players)>=MAX_PLAYERS: + return render_template('max_players.html') + if request.method == 'POST': + session['ign'] = request.form['ign'] + session['phone'] = request.form['phone'] + if check_valid_phone_num(session['phone']) and check_ign(session['ign']): + Players().add_player(session['ign'], session['phone']) + return redirect(url_for('success')) + else: + return redirect(url_for('index')) + return render_template('create.html') + + +def main(): + lol = Popen(['python','playoffs.py']) + app.run(debug=True, port=5000) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/src/sign_play/config.py b/src/sign_play/config.py new file mode 100644 index 0000000..8428f27 --- /dev/null +++ b/src/sign_play/config.py @@ -0,0 +1 @@ +api_key ="RGAPI-ace93d7a-1838-46ce-a222-4ffa66ad6dcc" \ No newline at end of file diff --git a/src/sign_play/templates/base.html b/src/sign_play/templates/base.html new file mode 100644 index 0000000..56ef55a --- /dev/null +++ b/src/sign_play/templates/base.html @@ -0,0 +1,30 @@ + + + + + {% block title %} {% endblock %} - FlaskApp + + + + +
+
+ {% block content %} {% endblock %} +
+ + \ No newline at end of file diff --git a/src/sign_play/templates/create.html b/src/sign_play/templates/create.html new file mode 100644 index 0000000..cd91cac --- /dev/null +++ b/src/sign_play/templates/create.html @@ -0,0 +1,21 @@ + {% extends 'base.html' %} + +{% block content %} +

{% block title %} Register player {% endblock %}

+
+ +
+ +
+ + +
+ +
+ +
+{% endblock %} diff --git a/src/sign_play/templates/index.html b/src/sign_play/templates/index.html new file mode 100644 index 0000000..84bc1f4 --- /dev/null +++ b/src/sign_play/templates/index.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} + +{% block content %} +

{% block title %} Players {% endblock %}

+ {% for player in players %} +
+

{{ player }}

+

{{ players[player] }}

+
+ {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/src/sign_play/templates/max_players.html b/src/sign_play/templates/max_players.html new file mode 100644 index 0000000..96c9d33 --- /dev/null +++ b/src/sign_play/templates/max_players.html @@ -0,0 +1,6 @@ +{% extends 'base.html' %} + +{% block content %} +

We have reached full capacity!

+

No more spots left for today!

+{% endblock %} \ No newline at end of file diff --git a/src/sign_play/templates/success.html b/src/sign_play/templates/success.html new file mode 100644 index 0000000..5ff3bff --- /dev/null +++ b/src/sign_play/templates/success.html @@ -0,0 +1,5 @@ +{% extends 'base.html' %} + +{% block content %} +

Success!

+{% endblock %} \ No newline at end of file