From 0acf16f411a7c4cb6582f4bf3b0281840d59f544 Mon Sep 17 00:00:00 2001 From: guimoz Date: Sun, 29 Jan 2017 19:54:55 +0100 Subject: [PATCH] Ajout de la precampagne --- roulette.py | 128 ++++++++++++++++++------------------- roulette.wsgi | 2 +- templates/down.html | 22 +++++++ templates/precampagne.html | 8 +++ 4 files changed, 94 insertions(+), 66 deletions(-) create mode 100644 templates/down.html create mode 100644 templates/precampagne.html diff --git a/roulette.py b/roulette.py index 0bcb005..014ea4e 100644 --- a/roulette.py +++ b/roulette.py @@ -28,20 +28,10 @@ MYSQL_DB = 'rezo_admin' BAN_DURATION = 30. * 60. IMMUNITY_FILE = '/var/roulette/immunity' -ASSHOLES_FILE = '/var/www/roulette/assholes' +ASSHOLES_FILE = '/var/roulette/assholes' +STATE_FILE = '/var/roulette/state' -IMMUNITY = [ - 'Lazare Olivry', - 'Brieuc Lacroix', - 'Elliot Butty', - 'Jean-Christophe Carli', - 'Juliette Tibayrenc', - 'Elise Laurent', - 'Goulven Kermarec', - 'Siqi Liu', - ] - -ASSHOLES = [] +STATE = 'precampagne' app = Flask(__name__) app.config.from_object(__name__) @@ -313,6 +303,9 @@ def banned(): @app.route('/banned_ip') def banned_ip(): + #Actualisation de l'etat de la roulette + with open(STATE_FILE, 'r') as f: + STATE = f.read() # Liste des ip pour récupération par babel et plop if not DEBUG: if get_ip() not in ['10.7.0.254']: @@ -334,74 +327,79 @@ def banned_ip(): @playable_required def home(): player = get_player_from_ip(get_ip()) + if STATE == "down": + return render_template('down.html', user=player) + elif STATE == "launched": + if DEBUG: + print(player, 'arrived') - #if ip not in ['10.69.8.5', '10.69.8.202']: - # abort(403) + bans = sorted(get_bans(player['id']), \ + key=lambda ban: ban['time'], \ + reverse=True) - if DEBUG: - print(player, 'arrived') + bans_hist = [] + for ban in bans: + date = strftime('%Hh%M (%A)', localtime(ban['time'])) + source = get_player(ban['player_id']) + target = get_player(ban['target_id']) - bans = sorted(get_bans(player['id']), \ - key=lambda ban: ban['time'], \ - reverse=True) - - bans_hist = [] - for ban in bans: - date = strftime('%Hh%M (%A)', localtime(ban['time'])) - source = get_player(ban['player_id']) - target = get_player(ban['target_id']) - - if target['id'] == player['id']: - if ban['success']: - entry = ('ban', u'%s : %s %s a réussi à t\'avoir.' \ - % (date, source['firstname'], source['name'])) + if target['id'] == player['id']: + if ban['success']: + entry = ('ban', u'%s : %s %s a réussi à t\'avoir.' \ + % (date, source['firstname'], source['name'])) + else: + entry = ('warn', u'%s : %s %s a essayé de te trancher, en vain.' \ + % (date, source['firstname'], source['name'])) else: - entry = ('warn', u'%s : %s %s a essayé de te trancher, en vain.' \ - % (date, source['firstname'], source['name'])) - else: - if ban['success']: - entry = ('ok', u'%s : Tu as tranché %s %s avec succès.' \ - % (date, target['firstname'], target['name'])) - else: - entry = ('ban', u'%s : Tu as échoué en voulant trancher %s %s.' \ - % (date, target['firstname'], target['name'])) + if ban['success']: + entry = ('ok', u'%s : Tu as tranché %s %s avec succès.' \ + % (date, target['firstname'], target['name'])) + else: + entry = ('ban', u'%s : Tu as échoué en voulant trancher %s %s.' \ + % (date, target['firstname'], target['name'])) - bans_hist.append(entry) + bans_hist.append(entry) - return render_template('home.html', bans_hist=bans_hist) + return render_template('home.html', bans_hist=bans_hist) + else STATE: + return render_template('precampagne.html', user=player) @app.route('/jouer', methods=['GET', 'POST']) @playable_required def play(): ip = get_ip() player = get_player_from_ip(ip) - - # Traitement de la requête de bannissement - if request.method == 'POST': - target_id = request.form['target_id'] - if target_id != 'none': - if is_banned(target_id): - flash(u'Utilisateur déjà tranché, il faut en choisir un autre.') - else: - success = cheat(player['id'], target_id) - if success: - target = get_player(target_id) - ban(player['id'], target_id, True) - flash(u'Trop cool, %s a été tranché pour un bon moment.' \ - % target['firstname']) + if STATE == "down": + return render_template('down.html', user=player) + elif STATE == "launched": + # Traitement de la requête de bannissement + if request.method == 'POST': + target_id = request.form['target_id'] + if target_id != 'none': + if is_banned(target_id): + flash(u'Utilisateur déjà tranché, il faut en choisir un autre.') else: - ban(player['id'], target_id, False) - return banned() + success = cheat(player['id'], target_id) + if success: + target = get_player(target_id) + ban(player['id'], target_id, True) + flash(u'Trop cool, %s a été tranché pour un bon moment.' \ + % target['firstname']) + else: + ban(player['id'], target_id, False) + return banned() - # Liste des joueurs non bannis, triée dans l'ordre croissant ou décroissant - players = sorted(get_players_not_banned(), \ - key=lambda player: player['firstname'], \ - reverse = random.choice([True, False])) + # Liste des joueurs non bannis, triée dans l'ordre croissant ou décroissant + players = sorted(get_players_not_banned(), \ + key=lambda player: player['firstname'], \ + reverse = random.choice([True, False])) - # sans le joueur actuel - players = filter(lambda p: p['id'] != player['id'], players) + # sans le joueur actuel + players = filter(lambda p: p['id'] != player['id'], players) - return render_template('play.html', players=players) + return render_template('play.html', players=players) + else STATE: + return render_template('precampagne.html', user=player) if __name__ == '__main__': app.run() diff --git a/roulette.wsgi b/roulette.wsgi index 608dad4..ab73a93 100644 --- a/roulette.wsgi +++ b/roulette.wsgi @@ -1,4 +1,4 @@ import sys -sys.path.insert(0, '/var/www/roulette') +sys.path.insert(0, '/var/roulette') from roulette import app as application diff --git a/templates/down.html b/templates/down.html new file mode 100644 index 0000000..4a41f65 --- /dev/null +++ b/templates/down.html @@ -0,0 +1,22 @@ +{% extends "layout.html" %} +{% block content %} +

Toi aussi, joue au rézoman !

+

+ La rezo-roulette metzquetaire vous offre un répit temporaire. Profite bien {{ user['firstname']+' '+user['name'] }} ;-) +

+

Historique personnel

+ +{% if bans_hist != [] %} + +{% else %} +

+ Rien pour l'instant +

+{% endif %} +{% endblock %} diff --git a/templates/precampagne.html b/templates/precampagne.html new file mode 100644 index 0000000..4d6d94d --- /dev/null +++ b/templates/precampagne.html @@ -0,0 +1,8 @@ +{% extends "layout.html" %} +{% block content %} +

Pas de précampagne!

+

+ Reviens bientôt {{ user['firstname']+' '+user['name'] }} pour jouer à la rezo-roulette +

+{% endif %} +{% endblock %}