remove session cookie when server restarts
This commit is contained in:
parent
e8bf27d2ef
commit
6acc73abd2
23
app.py
23
app.py
|
@ -1,5 +1,6 @@
|
||||||
from flask import Flask, render_template, request, session
|
from flask import Flask, render_template, request, session, make_response
|
||||||
import random
|
import random
|
||||||
|
import socket
|
||||||
import time
|
import time
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
@ -12,7 +13,10 @@ moves = ['forward', 'forward x2', 'forward x3', 'backward', 'turn left', 'turn r
|
||||||
class Game:
|
class Game:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.action_stack = {}
|
self.action_stack = {}
|
||||||
self.processing_done = False
|
self.processing_done = False # indicates whether all commands in the current round have been processed
|
||||||
|
|
||||||
|
self.comm_socket = socket.socket() # socket for communicating with the program controlling the robots
|
||||||
|
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
# have all players chosen an action?
|
# have all players chosen an action?
|
||||||
|
@ -35,6 +39,9 @@ class Game:
|
||||||
current_actions += [(p, self.action_stack[p][i])]
|
current_actions += [(p, self.action_stack[p][i])]
|
||||||
print("actions in step {}: {}".format(i, ["robot {} action {}".format(c[0], c[1]) for c in current_actions]))
|
print("actions in step {}: {}".format(i, ["robot {} action {}".format(c[0], c[1]) for c in current_actions]))
|
||||||
|
|
||||||
|
#self.comm_socket.send()
|
||||||
|
|
||||||
|
|
||||||
# clear the action stack for the next round
|
# clear the action stack for the next round
|
||||||
self.action_stack = {}
|
self.action_stack = {}
|
||||||
|
|
||||||
|
@ -116,11 +123,19 @@ def hello_world():
|
||||||
p = Player()
|
p = Player()
|
||||||
session['player_id'] = p.id
|
session['player_id'] = p.id
|
||||||
players[p.id] = p
|
players[p.id] = p
|
||||||
|
player_id = session['player_id']
|
||||||
else:
|
else:
|
||||||
return "Sorry, maximum number of players reached!"
|
return "Sorry, maximum number of players reached!"
|
||||||
|
else:
|
||||||
player_id = session['player_id']
|
player_id = session['player_id']
|
||||||
|
if Player.player_counter < player_id + 1:
|
||||||
|
session.clear()
|
||||||
|
response = make_response('Please reload the page!')
|
||||||
|
#response.set_cookie('player_id', '', expires=0)
|
||||||
|
return response
|
||||||
player_hand = players[player_id].player_hand
|
player_hand = players[player_id].player_hand
|
||||||
|
|
||||||
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return render_template('drag_example.html', cmds=player_hand, player_id=player_id)
|
return render_template('drag_example.html', cmds=player_hand, player_id=player_id)
|
||||||
elif request.method == 'POST':
|
elif request.method == 'POST':
|
||||||
|
|
Loading…
Reference in New Issue
Block a user