-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
132 lines (94 loc) · 3.7 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import time
from flask import Flask, render_template, request, redirect
from flask_socketio import SocketIO
from src.Main.Controler.Event.QuestionControler import getQuestion
from src.Main.Controler.Event.StartGmeControler import startGameContoroler
from src.Main.Model.Question import question,QuestionText
from src.Main.Controler.Event.PartyNewPlayerControler import partyNewPlayerControler
from src.Main.Controler.JoinControler import JoinControler
from src.Main.Controler.LobbyControler import lobbyControler
from src.Main.Model.Game import Game
from src.Main.Model.Party import Party
import atexit
from apscheduler.schedulers.background import BackgroundScheduler
import json as jsonlib
from src.Main.Scheduler import nextQuestionParty
app = Flask(__name__)
app.config['SECRET_KEY'] = 'tmpKey'
socketio = SocketIO(app)
clients = []
game = Game()
Game.curentGame = game
t=Party(3, [QuestionText.QuestionText('Qui Mange des Pomme', 'Chirac').get_json(), QuestionText.QuestionText('Qui Mange des Pomme2', 'Chirac').get_json(), QuestionText.QuestionText('Qui Mange des Pomme3', 'Chirac').get_json()])
@socketio.event
def connect():
print('connection established')
print(request.sid)
clients.append(request.namespace)
@app.route('/')
def hello_world():
return render_template('index.html')
@app.route('/join')
def join():
return render_template('join.html')
@app.route('/party/<party_id>')
def party(party_id):
return lobbyControler(request,party_id);
#Lorsque une perssone rejoin une game
#@app.route('/joinGame',methods=["GET", "POST"])
@socketio.on('Evt_join_game')
def join_game(json):
return JoinControler(request,json,game,socketio,messageReceived);
#Event lorsque un joeur rejoin une partie deja existant
@socketio.on('Evt_party_join')
def ckEvt_party_join(json):
#On rentre dans le controler qui envois une reponce
partyNewPlayerControler(request,json,game,socketio,messageReceived);
def messageReceived(methods=['GET', 'POST']):
print('message was received!!!')
@socketio.on('my event')
def handle_my_custom_event(json, methods=['GET', 'POST']):
print('received my event: ' + str(json))
socketio.emit('my response', json, callback=messageReceived)
#Envoyer un message a un seul uttilisateur (grasse a sa session id)
socketio.emit('boy', "GG boy you send a message from serveur", callback=messageReceived,room=request.sid)
@app.route('/test')
def QuestionTemplate():
return render_template('testQuestion.html')
@socketio.on('question')
def questionEvent(methods=['GET', 'POST']):
getQuestion(request,None,game,socketio,messageReceived)
''' if t.compteur-1 < 0 :
print('fin')
else :
socketio.emit('my question',t.questionList[t.compteur-1], callback=messageReceived)
t.compteurDown()
'''
@socketio.on('reponse')
def reponseEvent(json, methods=['GET', 'POST']):
#print(json)
Propa=jsonlib.loads(jsonlib.dumps(json))
print(Propa['reponse'])
@app.route('/setting')
def configureParty():
return render_template('configure.html')
@socketio.on('setting')
def reponseEvent(json, methods=['GET', 'POST']):
Propa=jsonlib.loads(jsonlib.dumps(json))
print(str(Propa))
@socketio.on('TypeList')
def TypeList():
socketio.emit('repTypeList',str(['test','tesr2']))
#Action au start
@socketio.on('startGame')
def startGame(json):
startGameContoroler(request,json,game,socketio,messageReceived)
#Cette fonction vas s'execute tout les seconde
def goToNextQuestion():
nextQuestionParty(game,socketio)
scheduler = BackgroundScheduler()
scheduler.add_job(func=goToNextQuestion, trigger="interval", seconds=1)
scheduler.start()
atexit.register(lambda: scheduler.shutdown())
if __name__ == '__main__':
socketio.run(app, debug=True)