Ajout de la precampagne
This commit is contained in:
parent
b421d7b83f
commit
0acf16f411
4 changed files with 94 additions and 66 deletions
128
roulette.py
128
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()
|
||||
|
|
|
@ -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
|
||||
|
|
22
templates/down.html
Normal file
22
templates/down.html
Normal 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 %}
|
8
templates/precampagne.html
Normal file
8
templates/precampagne.html
Normal 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 %}
|
Loading…
Reference in a new issue