Initial commit(Player add and list)

This commit is contained in:
Boyan 2023-08-27 21:28:05 +02:00
commit aa73b8ee75
9 changed files with 174 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__/

28
README.md Normal file
View File

@ -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.

71
src/sign_play/app.py Normal file
View File

@ -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()

1
src/sign_play/config.py Normal file
View File

@ -0,0 +1 @@
api_key ="RGAPI-ace93d7a-1838-46ce-a222-4ffa66ad6dcc"

View File

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %} {% endblock %} - FlaskApp</title>
<style>
.message {
padding: 10px;
margin: 5px;
background-color: #f3f3f3
}
nav a {
color: #47acf5;
font-size: 3em;
margin-left: 50px;
text-decoration: none;
}
</style>
</head>
<body>
<nav>
<a href="{{ url_for('index') }}">Leagalizer</a>
</nav>
<hr>
<div class="content">
{% block content %} {% endblock %}
</div>
</body>
</html>

View File

@ -0,0 +1,21 @@
{% extends 'base.html' %}
{% block content %}
<h1>{% block title %} Register player {% endblock %}</h1>
<form method="post">
<label for="ign">Username</label>
<br>
<input type="text" name="ign"
placeholder="leagueplayer"
value="{{ request.form['ign'] }}"></input>
<br>
<label for="phone">Phone</label>
<br>
<input type="text" name="phone"
placeholder="088888888"
value="{{ request.form['phone'] }}"></input>
<br>
<button type="submit">Submit</button>
</form>
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'base.html' %}
{% block content %}
<h1>{% block title %} Players {% endblock %}</h1>
{% for player in players %}
<div class='player'>
<h3>{{ player }}</h3>
<p>{{ players[player] }}</p>
</div>
{% endfor %}
{% endblock %}

View File

@ -0,0 +1,6 @@
{% extends 'base.html' %}
{% block content %}
<h1>We have reached full capacity!</h1>
<h2> No more spots left for today! </h2>
{% endblock %}

View File

@ -0,0 +1,5 @@
{% extends 'base.html' %}
{% block content %}
<h1>Success!</h1>
{% endblock %}