Ajout de la precampagne

This commit is contained in:
guimoz 2017-01-29 19:54:55 +01:00
parent b421d7b83f
commit 0acf16f411
4 changed files with 94 additions and 66 deletions

View file

@ -28,20 +28,10 @@ MYSQL_DB = 'rezo_admin'
BAN_DURATION = 30. * 60. BAN_DURATION = 30. * 60.
IMMUNITY_FILE = '/var/roulette/immunity' IMMUNITY_FILE = '/var/roulette/immunity'
ASSHOLES_FILE = '/var/www/roulette/assholes' ASSHOLES_FILE = '/var/roulette/assholes'
STATE_FILE = '/var/roulette/state'
IMMUNITY = [ STATE = 'precampagne'
'Lazare Olivry',
'Brieuc Lacroix',
'Elliot Butty',
'Jean-Christophe Carli',
'Juliette Tibayrenc',
'Elise Laurent',
'Goulven Kermarec',
'Siqi Liu',
]
ASSHOLES = []
app = Flask(__name__) app = Flask(__name__)
app.config.from_object(__name__) app.config.from_object(__name__)
@ -313,6 +303,9 @@ def banned():
@app.route('/banned_ip') @app.route('/banned_ip')
def 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 # Liste des ip pour récupération par babel et plop
if not DEBUG: if not DEBUG:
if get_ip() not in ['10.7.0.254']: if get_ip() not in ['10.7.0.254']:
@ -334,74 +327,79 @@ def banned_ip():
@playable_required @playable_required
def home(): def home():
player = get_player_from_ip(get_ip()) 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']: bans = sorted(get_bans(player['id']), \
# abort(403) key=lambda ban: ban['time'], \
reverse=True)
if DEBUG: bans_hist = []
print(player, 'arrived') 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']), \ if target['id'] == player['id']:
key=lambda ban: ban['time'], \ if ban['success']:
reverse=True) entry = ('ban', u'%s : %s %s a réussi à t\'avoir.' \
% (date, source['firstname'], source['name']))
bans_hist = [] else:
for ban in bans: entry = ('warn', u'%s : %s %s a essayé de te trancher, en vain.' \
date = strftime('%Hh%M (%A)', localtime(ban['time'])) % (date, source['firstname'], source['name']))
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']))
else: else:
entry = ('warn', u'%s : %s %s a essayé de te trancher, en vain.' \ if ban['success']:
% (date, source['firstname'], source['name'])) entry = ('ok', u'%s : Tu as tranché %s %s avec succès.' \
else: % (date, target['firstname'], target['name']))
if ban['success']: else:
entry = ('ok', u'%s : Tu as tranché %s %s avec succès.' \ entry = ('ban', u'%s : Tu as échoué en voulant trancher %s %s.' \
% (date, target['firstname'], target['name'])) % (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']) @app.route('/jouer', methods=['GET', 'POST'])
@playable_required @playable_required
def play(): def play():
ip = get_ip() ip = get_ip()
player = get_player_from_ip(ip) player = get_player_from_ip(ip)
if STATE == "down":
# Traitement de la requête de bannissement return render_template('down.html', user=player)
if request.method == 'POST': elif STATE == "launched":
target_id = request.form['target_id'] # Traitement de la requête de bannissement
if target_id != 'none': if request.method == 'POST':
if is_banned(target_id): target_id = request.form['target_id']
flash(u'Utilisateur déjà tranché, il faut en choisir un autre.') if target_id != 'none':
else: if is_banned(target_id):
success = cheat(player['id'], target_id) flash(u'Utilisateur déjà tranché, il faut en choisir un autre.')
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: else:
ban(player['id'], target_id, False) success = cheat(player['id'], target_id)
return banned() 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 # Liste des joueurs non bannis, triée dans l'ordre croissant ou décroissant
players = sorted(get_players_not_banned(), \ players = sorted(get_players_not_banned(), \
key=lambda player: player['firstname'], \ key=lambda player: player['firstname'], \
reverse = random.choice([True, False])) reverse = random.choice([True, False]))
# sans le joueur actuel # sans le joueur actuel
players = filter(lambda p: p['id'] != player['id'], players) 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__': if __name__ == '__main__':
app.run() app.run()

View file

@ -1,4 +1,4 @@
import sys import sys
sys.path.insert(0, '/var/www/roulette') sys.path.insert(0, '/var/roulette')
from roulette import app as application from roulette import app as application

22
templates/down.html Normal file
View file

@ -0,0 +1,22 @@
{% extends "layout.html" %}
{% block content %}
<h2>Toi aussi, joue au rézoman !</h2>
<p>
La rezo-roulette metzquetaire vous offre un répit temporaire. Profite bien {{ user['firstname']+' '+user['name'] }} ;-)
</p>
<h2>Historique personnel</h2>
{% if bans_hist != [] %}
<ul id="history">
{% for entry in bans_hist %}
<li class="{{ entry[0] }}" class="events">
<span class="normal"> {{ entry[1] }}</span>
</li>
{% endfor %}
</ul>
{% else %}
<p>
Rien pour l'instant
</p>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,8 @@
{% extends "layout.html" %}
{% block content %}
<h2>Pas de précampagne!</h2>
<p>
Reviens bientôt {{ user['firstname']+' '+user['name'] }} pour jouer à la rezo-roulette
</p>
{% endif %}
{% endblock %}