diff --git a/belote.py b/belote.py index 34bc852..edbe4e3 100644 --- a/belote.py +++ b/belote.py @@ -323,18 +323,72 @@ def admin_games_new(): return flask.redirect(URL_DEFAULT) if flask.request.method=="POST": name = flask.request.form['name'] + login0 = flask.request.form['player0'] + login1 = flask.request.form['player1'] + login2 = flask.request.form['player2'] + login3 = flask.request.form['player3'] admin = flask.request.form['admin'] - admin = User.query.get(admin) - if admin is None: - flask.flash('Login inconnu') + if 'fixplayers' in flask.request.form: + start = True + else: + start = False + + try: + admin = int(admin) + except: + return 'Error' + if admin<0 or admin>3: + return 'Error' + + adminn = -1 + lusers = [] + + if login0 != '': + user0 = User.query.get(login0) + if user0 is None: + flask.flash('Utilisateur inconnu {}'.format(login0)) + else: + lusers.append(user0) + if admin==0: adminn = 0 + if login1 != '': + user1 = User.query.get(login1) + if user1 is None: + flask.flash('Utilisateur inconnu {}'.format(login1)) + else: + if admin==1: adminn = len(lusers) + lusers.append(user1) + if login2 != '': + user2 = User.query.get(login2) + if user2 is None: + flask.flash('Utilisateur inconnu {}'.format(login2)) + else: + if admin==2: adminn = len(lusers) + lusers.append(user2) + if login3 != '': + user3 = User.query.get(login3) + if user3 is None: + flask.flash('Utilisateur inconnu {}'.format(login3)) + else: + if admin==3: adminn = len(lusers) + lusers.append(user3) + + if adminn <0: + flask.flash('Vous devez définir un maitre du jeu (admin).') elif len(name)<2: flask.flash('Nom trop court !') else: - game = Game(name=name, admin=admin.login) + game = Game(name=name, admin=lusers[adminn].login) db.session.add(game) db.session.commit() - game.join(admin) + ordered_players = [] + for u in lusers: + ordered_players.append(u.login) + game.join(u) db.session.commit() + + if start and game.can_start(): + game.fix_players() + game.start_game(ordered_players) return flask.redirect('/admin/games') return flask.render_template('admin_game_add.html', user=fll.current_user) diff --git a/db.py b/db.py index 5e9de69..a272103 100644 --- a/db.py +++ b/db.py @@ -7,7 +7,7 @@ from belote_jeu import cards, N_PLAYERS, colors, winner, N_TURN db = SQLAlchemy() -levels_users = {'Inactive':0, 'Simple user':1, 'Can create games':2, 'Can manage simple users': 8, 'Can manage games':9, 'Admin':10} +levels_users = {'Inactive':0, 'Simple user':1, 'Can create games':2, 'Can manage games':8, 'Can manage simple users': 9, 'Admin':10} ####################################################################### # User class # @@ -117,6 +117,10 @@ class Game(db.Model): def serialize_state_anonymous(self): r = {} + r['players'] = self.get_ordered_players() + r['playersinfo'] = {} + for p in self.players: + r['playersinfo'][p.user] = User.query.get(p.user).name r['atout'] = self.atout r['preneur'] = self.preneur r['last_played'] = self.last_played.split(',') if self.last_played is not None else [] @@ -126,16 +130,12 @@ class Game(db.Model): r['points'] = [self.points_0, self.points_1] r['cumul'] = [self.cumul_0, self.cumul_1] r['partie'] = self.partie + r['admin'] = self.admin return r def serialize_state(self, user): r = self.serialize_state_anonymous() - r['players'] = self.get_ordered_players() - r['playersinfo'] = {} - for p in self.players: - r['playersinfo'][p.user] = User.query.get(p.user).name r['nr'] = self.get_nr(user) - r['admin'] = self.admin cards = self.get_player(user).cards r['cards'] = cards.split(',') if cards is not None else [] return r diff --git a/static/game_script.js b/static/game_script.js index 1ada05a..861c351 100644 --- a/static/game_script.js +++ b/static/game_script.js @@ -259,8 +259,7 @@ socket.on('play', function(data){ }); socket.on('disconnect', function() { - $('#chat').prepend('Souci technique : Vous avez été déconnecté
Une tentative de reconnexion va avoir lieu
'); - setTimeout(function(){window.location.reload()}, 5000); + $('#chat').prepend('Souci technique : Vous avez été déconnecté. Veuillez recharger la page.
'); }); $('#texte-msg').pressEnter(function(e){ diff --git a/templates/admin_game_add.html b/templates/admin_game_add.html index 5d22130..c1b2bd1 100644 --- a/templates/admin_game_add.html +++ b/templates/admin_game_add.html @@ -17,8 +17,34 @@ {% endfor %}
Nom du jeu :
- Maitre du jeu :
- + Démarrer le jeu (founir 4 joueurs)
+
+ Ajoutez au moins un joueur :

+ + + + + + + +
LoginMaitre jeu
+ Joueur 1* :
+
+ +
+ Joueur 2 :
+
+ +
+ Joueur 3 :
+
+ +
+ Joueur 4 :
+
+ +
+
diff --git a/templates/admin_games.html b/templates/admin_games.html index a489184..c243b20 100644 --- a/templates/admin_games.html +++ b/templates/admin_games.html @@ -17,7 +17,7 @@ IdNamePartieJoueursStatusActions {% for g in games %} - {{ g.id }}{{ g.name }}{{ g.partie }}{% for p in g.players %}{{ p.user }} {% endfor %} + {{ g.id }}{{ g.name }}{{ g.partie }}{% for p in g.players %}{{ p.user }} {% endfor %} {% if g.start %} Started {% elif g.fixplayers %}Players set{% else %}Join{% endif %} Voir Del {% endfor %} diff --git a/templates/base.html b/templates/base.html index cedcf73..5eefd51 100644 --- a/templates/base.html +++ b/templates/base.html @@ -30,10 +30,10 @@ - {% if user.level > 8 %} + {% if user.level >= 8 %} {% endif %} - {% if user.level > 9 %} + {% if user.level >= 9 %} {% endif %} {% else %}