01
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
|||||||
venv/
|
venv/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
data/
|
||||||
.env
|
.env
|
||||||
|
makefile
|
||||||
|
logs/django.log
|
||||||
|
|||||||
@ -219,6 +219,10 @@ volumes:
|
|||||||
o: bind
|
o: bind
|
||||||
pong_django_logs:
|
pong_django_logs:
|
||||||
driver: local
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
type: none
|
||||||
|
device: ${DJANGO_LOGS}
|
||||||
|
o: bind
|
||||||
pong_pg_data:
|
pong_pg_data:
|
||||||
driver: local
|
driver: local
|
||||||
pong_es_data_01:
|
pong_es_data_01:
|
||||||
|
|||||||
@ -6,7 +6,7 @@ DJANGO_ALLOWED_HOSTS=['*']
|
|||||||
# PostgreSQL settings
|
# PostgreSQL settings
|
||||||
POSTGRES_DB=players_db
|
POSTGRES_DB=players_db
|
||||||
POSTGRES_USER=42student
|
POSTGRES_USER=42student
|
||||||
POSTGRES_PASSWORD=postgre_pass
|
POSTGRES_PASSWORD=
|
||||||
|
|
||||||
# Django settings
|
# Django settings
|
||||||
DB_HOST=db
|
DB_HOST=db
|
||||||
@ -20,11 +20,11 @@ CLUSTER_NAME=docker-cluster
|
|||||||
LICENSE=basic
|
LICENSE=basic
|
||||||
|
|
||||||
ELASTIC_USERNAME=elastic
|
ELASTIC_USERNAME=elastic
|
||||||
ELASTIC_PASSWORD=elastic_pass
|
ELASTIC_PASSWORD=
|
||||||
|
|
||||||
# Kibana settings
|
# Kibana settings
|
||||||
KIBANA_PORT=5601
|
KIBANA_PORT=5601
|
||||||
KIBANA_USERNAME=kibana_system
|
KIBANA_USERNAME=
|
||||||
KIBANA_PASSWORD=kibana_pass
|
KIBANA_PASSWORD=
|
||||||
|
|
||||||
ENCRYPTION_KEY=c34d38b3a14956121ff2170e5030b471551370178f43e5626eec58b04a30fae2
|
ENCRYPTION_KEY=c34d38b3a14956121ff2170e5030b471551370178f43e5626eec58b04a30fae2
|
||||||
|
|||||||
56
logs/172.20.2.60-1726141292617.log
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
:8080/:1 The Cross-Origin-Opener-Policy header has been ignored, because the URL's origin was untrustworthy. It was defined either in the final response or a redirect. Please deliver the response using the HTTPS protocol. You can also use the 'localhost' origin instead. See https://www.w3.org/TR/powerful-features/#potentially-trustworthy-origin and https://html.spec.whatwg.org/#the-cross-origin-opener-policy-header.
|
||||||
|
game.js:2 DOM fully loaded and parsed
|
||||||
|
game.js:48 DOM elements initialized
|
||||||
|
game.js:71 Event listeners added
|
||||||
|
game.js:186 checkUserExists called with username: didi
|
||||||
|
game.js:203 User existence check response: {exists: false}
|
||||||
|
game.js:212 handleRegister called
|
||||||
|
game.js:225 Attempting to register user: didi
|
||||||
|
game.js:250 registerUser called with username: didi
|
||||||
|
game.js:273 Registration response data: {registered: true, token: '391a5261-4dac-4555-9c5f-7d1000557dc0'}
|
||||||
|
game.js:275 User registered successfully: {registered: true, token: '391a5261-4dac-4555-9c5f-7d1000557dc0'}
|
||||||
|
game.js:229 Token stored: 391a5261-4dac-4555-9c5f-7d1000557dc0
|
||||||
|
game.js:230 User registered successfully
|
||||||
|
game.js:964 Joining room: main_room with username: didi and token: 391a5261-4dac-4555-9c5f-7d1000557dc0
|
||||||
|
game.js:971 Joining new room: main_room
|
||||||
|
game.js:888 createRoomTab: main_room with username: didi and token: 391a5261-4dac-4555-9c5f-7d1000557dc0
|
||||||
|
game.js:898 Tab for room main_room already exists.
|
||||||
|
game.js:912 Showing tab for room: main_room
|
||||||
|
game.js:807 Initializing chat WebSocket...
|
||||||
|
game.js:808 Initializing chat WebSocket for room: main_room with username: didi
|
||||||
|
game.js:811 startChatWebSocket: main_room with username: didi and token: 391a5261-4dac-4555-9c5f-7d1000557dc0
|
||||||
|
game.js:875 WebSocket connection stored for room: main_room
|
||||||
|
game.js:919 switchRoom: main_room with username: didi and token: 391a5261-4dac-4555-9c5f-7d1000557dc0
|
||||||
|
game.js:925 Attempting to switch to room: main_room
|
||||||
|
game.js:931 Switching from room null to room main_room
|
||||||
|
game.js:816 Chat WebSocket connection established in room: main_room
|
||||||
|
game.js:825 Authentication message sent for room: main_room with username: didi
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'authenticated', username: 'didi'}
|
||||||
|
game.js:835 User authenticated successfully in room: main_room
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'chat_message', message: 'didi: a rejoint le chat main_room', room: 'main_room'}
|
||||||
|
game.js:846 Message displayed in chat log for room: main_room
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'chat_message', message: 'didi: kikou', room: 'main_room'}
|
||||||
|
game.js:846 Message displayed in chat log for room: main_room
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'chat_message', message: 'didi: /b', room: 'main_room'}
|
||||||
|
game.js:846 Message displayed in chat log for room: main_room
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'success', message: 'You have blocked dd'}
|
||||||
|
game.js:855 Unhandled message type: {type: 'success', message: 'You have blocked dd'}
|
||||||
|
chatSocket.onmessage @ game.js:855
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'chat_message', message: 'fifi: a rejoint le chat main_room', room: 'main_room'}
|
||||||
|
game.js:846 Message displayed in chat log for room: main_room
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'chat_message', message: 'fifi: hello', room: 'main_room'}
|
||||||
|
game.js:846 Message displayed in chat log for room: main_room
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'chat_message', message: 'didi: hello', room: 'main_room'}
|
||||||
|
game.js:846 Message displayed in chat log for room: main_room
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'chat_message', message: 'didi: tu veux jouer', room: 'main_room'}
|
||||||
|
game.js:846 Message displayed in chat log for room: main_room
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'chat_message', message: 'fifi: oui', room: 'main_room'}
|
||||||
|
game.js:846 Message displayed in chat log for room: main_room
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'error', message: 'Erreur interne du serveur'}
|
||||||
|
game.js:852 Error message received: Erreur interne du serveur
|
||||||
|
chatSocket.onmessage @ game.js:852
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'success', message: 'You have blocked fifi'}
|
||||||
|
game.js:855 Unhandled message type: {type: 'success', message: 'You have blocked fifi'}
|
||||||
|
chatSocket.onmessage @ game.js:855
|
||||||
|
game.js:831 Message received from server in room main_room: {type: 'chat_message', message: 'fifi: conard', room: 'main_room'}
|
||||||
|
game.js:846 Message displayed in chat log for room: main_room
|
||||||
72
logs/172.20.2.60-1726142931992.log
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
:8080/:1 The Cross-Origin-Opener-Policy header has been ignored, because the URL's origin was untrustworthy. It was defined either in the final response or a redirect. Please deliver the response using the HTTPS protocol. You can also use the 'localhost' origin instead. See https://www.w3.org/TR/powerful-features/#potentially-trustworthy-origin and https://html.spec.whatwg.org/#the-cross-origin-opener-policy-header.
|
||||||
|
game.js:2 DOM fully loaded and parsed
|
||||||
|
game.js:48 DOM elements initialized
|
||||||
|
game.js:71 Event listeners added
|
||||||
|
game.js:186 checkUserExists called with username: dudu
|
||||||
|
game.js:203 User existence check response: {exists: false}
|
||||||
|
game.js:212 handleRegister called
|
||||||
|
game.js:225 Attempting to register user: dudu
|
||||||
|
game.js:250 registerUser called with username: dudu
|
||||||
|
game.js:273 Registration response data: {registered: true, token: '5265ee4d-d0f3-4d7e-a465-e152d90f43f3'}
|
||||||
|
game.js:275 User registered successfully: {registered: true, token: '5265ee4d-d0f3-4d7e-a465-e152d90f43f3'}
|
||||||
|
game.js:229 Token stored: 5265ee4d-d0f3-4d7e-a465-e152d90f43f3
|
||||||
|
game.js:230 User registered successfully
|
||||||
|
game.js:973 Joining room: main_room with username: dudu and token: 5265ee4d-d0f3-4d7e-a465-e152d90f43f3
|
||||||
|
game.js:980 Joining new room: main_room
|
||||||
|
game.js:897 createRoomTab: main_room with username: dudu and token: 5265ee4d-d0f3-4d7e-a465-e152d90f43f3
|
||||||
|
game.js:907 Tab for room main_room already exists.
|
||||||
|
game.js:921 Showing tab for room: main_room
|
||||||
|
game.js:818 Initializing chat WebSocket...
|
||||||
|
game.js:819 Initializing chat WebSocket for room: main_room with username: dudu
|
||||||
|
game.js:822 startChatWebSocket: main_room with username: dudu and token: 5265ee4d-d0f3-4d7e-a465-e152d90f43f3
|
||||||
|
game.js:886 WebSocket connection stored for room: main_room
|
||||||
|
game.js:734 ChatInput initialized for room: main_room, username: dudu
|
||||||
|
game.js:928 switchRoom: main_room with username: dudu and token: 5265ee4d-d0f3-4d7e-a465-e152d90f43f3
|
||||||
|
game.js:934 Attempting to switch to room: main_room
|
||||||
|
game.js:940 Switching from room null to room main_room
|
||||||
|
game.js:827 Chat WebSocket connection established in room: main_room
|
||||||
|
game.js:836 Authentication message sent for room: main_room with username: dudu
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'authenticated', username: 'dudu'}
|
||||||
|
game.js:846 User authenticated successfully in room: main_room
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'dudu: a rejoint le chat main_room', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:749 Send button clicked, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: frfrfr
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'dudu: frfrfr', room: 'main_room'}message: "dudu: frfrfr"room: "main_room"type: "chat_message"[[Prototype]]: Object
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:749 Send button clicked, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: frfr
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'dudu: frfr', room: 'main_room'}message: "dudu: frfr"room: "main_room"type: "chat_message"[[Prototype]]: Object
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: /b
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'dudu: /b', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: /b b
|
||||||
|
game.js:761 Detected block command for user: b
|
||||||
|
game.js:784 Sending block command to WebSocket for user: b
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'success', message: 'You have blocked b'}
|
||||||
|
game.js:866 Unhandled message type: {type: 'success', message: 'You have blocked b'}
|
||||||
|
chatSocket.onmessage @ game.js:866
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: /i
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'dudu: /i', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: /i hhuhhihi hihi
|
||||||
|
game.js:765 Detected invite command for user: hhuhhihi hihi
|
||||||
|
game.js:794 Sending invite command to WebSocket for user: hhuhhihi hihi
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'error', message: 'Erreur interne du serveur'}message: "Erreur interne du serveur"type: "error"[[Prototype]]: Object
|
||||||
|
game.js:863 Error message received: Erreur interne du serveur
|
||||||
|
chatSocket.onmessage @ game.js:863
|
||||||
126
logs/172.20.2.60-1726144089884.log
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
:8080/:1 The Cross-Origin-Opener-Policy header has been ignored, because the URL's origin was untrustworthy. It was defined either in the final response or a redirect. Please deliver the response using the HTTPS protocol. You can also use the 'localhost' origin instead. See https://www.w3.org/TR/powerful-features/#potentially-trustworthy-origin and https://html.spec.whatwg.org/#the-cross-origin-opener-policy-header.
|
||||||
|
game.js:2 DOM fully loaded and parsed
|
||||||
|
game.js:48 DOM elements initialized
|
||||||
|
game.js:71 Event listeners added
|
||||||
|
game.js:186 checkUserExists called with username: rere
|
||||||
|
game.js:203 User existence check response: {exists: false}
|
||||||
|
game.js:212 handleRegister called
|
||||||
|
game.js:225 Attempting to register user: rere
|
||||||
|
game.js:250 registerUser called with username: rere
|
||||||
|
game.js:273 Registration response data: {registered: true, token: 'e07d4752-1960-43d2-a971-4cb24ae2486f'}
|
||||||
|
game.js:275 User registered successfully: {registered: true, token: 'e07d4752-1960-43d2-a971-4cb24ae2486f'}
|
||||||
|
game.js:229 Token stored: e07d4752-1960-43d2-a971-4cb24ae2486f
|
||||||
|
game.js:230 User registered successfully
|
||||||
|
game.js:978 Joining room: main_room with username: rere and token: e07d4752-1960-43d2-a971-4cb24ae2486f
|
||||||
|
game.js:985 Joining new room: main_room
|
||||||
|
game.js:902 createRoomTab: main_room with username: rere and token: e07d4752-1960-43d2-a971-4cb24ae2486f
|
||||||
|
game.js:912 Tab for room main_room already exists.
|
||||||
|
game.js:926 Showing tab for room: main_room
|
||||||
|
game.js:818 Initializing chat WebSocket...
|
||||||
|
game.js:819 Initializing chat WebSocket for room: main_room with username: rere
|
||||||
|
game.js:822 startChatWebSocket: main_room with username: rere and token: e07d4752-1960-43d2-a971-4cb24ae2486f
|
||||||
|
game.js:891 WebSocket connection stored for room: main_room
|
||||||
|
game.js:734 ChatInput initialized for room: main_room, username: rere
|
||||||
|
game.js:933 switchRoom: main_room with username: rere and token: e07d4752-1960-43d2-a971-4cb24ae2486f
|
||||||
|
game.js:939 Attempting to switch to room: main_room
|
||||||
|
game.js:945 Switching from room null to room main_room
|
||||||
|
game.js:827 Chat WebSocket connection established in room: main_room
|
||||||
|
game.js:836 Authentication message sent for room: main_room with username: rere
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'authenticated', username: 'rere'}
|
||||||
|
game.js:846 User authenticated successfully in room: main_room
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: a rejoint le chat main_room', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cdcdc
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: cdcdc', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cdcd
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: cdcd', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cdcdcdcd
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: cdcdcdcd', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cdcdcdc
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: cdcdcdc', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cdcdcd
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: cdcdcd', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: ccccc
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: ccccc', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cdcdcdcd
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: cdcdcdcd', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cdcdcdc
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: cdcdcdc', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cdcdcdc
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: cdcdcdc', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cdcdcdcdcd
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: cdcdcdcdcd', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cdcdcdc
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: cdcdcdc', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'aaaa: a rejoint le chat main_room', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'aaaa: cdcdcdcdc', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'aaaa: ccddcdcd', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cdcdcdc
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'chat_message', message: 'rere: cdcdcdc', room: 'main_room'}
|
||||||
|
game.js:857 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: /b aaaa
|
||||||
|
game.js:761 Detected block command for user: aaaa
|
||||||
|
game.js:784 Sending block command to WebSocket for user: aaaa
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'error', message: 'Target user aaaa not found in room'}
|
||||||
|
game.js:867 Error message received: Target user aaaa not found in room
|
||||||
|
chatSocket.onmessage @ game.js:867
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: /i aaaa
|
||||||
|
game.js:765 Detected invite command for user: aaaa
|
||||||
|
game.js:794 Sending invite command to WebSocket for user: aaaa
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:842 Message received from server in room main_room: {type: 'error', message: 'Erreur interne du serveur'}
|
||||||
|
game.js:867 Error message received: Erreur interne du serveur
|
||||||
|
chatSocket.onmessage @ game.js:867
|
||||||
78
logs/172.20.2.60-1726150242355.log
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
172.20.2.60/:1 The Cross-Origin-Opener-Policy header has been ignored, because the URL's origin was untrustworthy. It was defined either in the final response or a redirect. Please deliver the response using the HTTPS protocol. You can also use the 'localhost' origin instead. See https://www.w3.org/TR/powerful-features/#potentially-trustworthy-origin and https://html.spec.whatwg.org/#the-cross-origin-opener-policy-header.
|
||||||
|
game.js:2 DOM fully loaded and parsed
|
||||||
|
game.js:48 DOM elements initialized
|
||||||
|
game.js:71 Event listeners added
|
||||||
|
game.js:186 checkUserExists called with username: vivi
|
||||||
|
game.js:203 User existence check response: Object
|
||||||
|
game.js:212 handleRegister called
|
||||||
|
game.js:225 Attempting to register user: vivi
|
||||||
|
game.js:250 registerUser called with username: vivi
|
||||||
|
game.js:273 Registration response data: Object
|
||||||
|
game.js:275 User registered successfully: Object
|
||||||
|
game.js:229 Token stored: 66ce0c1a-dfbc-4f0f-9ec9-a4a9d4b990fe
|
||||||
|
game.js:230 User registered successfully
|
||||||
|
game.js:980 Joining room: main_room with username: vivi and token: 66ce0c1a-dfbc-4f0f-9ec9-a4a9d4b990fe
|
||||||
|
game.js:987 Joining new room: main_room
|
||||||
|
game.js:904 createRoomTab: main_room with username: vivi and token: 66ce0c1a-dfbc-4f0f-9ec9-a4a9d4b990fe
|
||||||
|
game.js:914 Tab for room main_room already exists.
|
||||||
|
game.js:928 Showing tab for room: main_room
|
||||||
|
game.js:820 Initializing chat WebSocket...
|
||||||
|
game.js:821 Initializing chat WebSocket for room: main_room with username: vivi
|
||||||
|
game.js:824 startChatWebSocket: main_room with username: vivi and token: 66ce0c1a-dfbc-4f0f-9ec9-a4a9d4b990fe
|
||||||
|
game.js:893 WebSocket connection stored for room: main_room
|
||||||
|
game.js:734 ChatInput initialized for room: main_room, username: vivi
|
||||||
|
game.js:935 switchRoom: main_room with username: vivi and token: 66ce0c1a-dfbc-4f0f-9ec9-a4a9d4b990fe
|
||||||
|
game.js:941 Attempting to switch to room: main_room
|
||||||
|
game.js:947 Switching from room null to room main_room
|
||||||
|
game.js:829 Chat WebSocket connection established in room: main_room
|
||||||
|
game.js:838 Authentication message sent for room: main_room with username: vivi
|
||||||
|
game.js:844 Message received from server in room main_room: Object
|
||||||
|
game.js:848 User authenticated successfully in room: main_room
|
||||||
|
game.js:844 Message received from server in room main_room: Object
|
||||||
|
game.js:859 Message displayed in chat log for room: main_room
|
||||||
|
game.js:749 Send button clicked, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cscscsc
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:844 Message received from server in room main_room: Object
|
||||||
|
game.js:859 Message displayed in chat log for room: main_room
|
||||||
|
game.js:749 Send button clicked, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: cscscs
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:844 Message received from server in room main_room: Object
|
||||||
|
game.js:859 Message displayed in chat log for room: main_room
|
||||||
|
game.js:844 Message received from server in room main_room: Object
|
||||||
|
game.js:859 Message displayed in chat log for room: main_room
|
||||||
|
game.js:844 Message received from server in room main_room: Object
|
||||||
|
game.js:859 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: /b sasa
|
||||||
|
game.js:761 Detected block command for user: sasa
|
||||||
|
game.js:784 Sending block command to WebSocket for user: sasa
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:844 Message received from server in room main_room: Object
|
||||||
|
game.js:869 Error message received: Target user sasa not found in room main_room
|
||||||
|
chatSocket.onmessage @ game.js:869
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: /isasa
|
||||||
|
game.js:768 Sending chat message to WebSocket...
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:844 Message received from server in room main_room: {type: 'chat_message', message: 'vivi: /isasa', room: 'main_room'}
|
||||||
|
game.js:859 Message displayed in chat log for room: main_room
|
||||||
|
game.js:742 Enter key pressed, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: /i sas
|
||||||
|
game.js:765 Detected invite command for user: sas
|
||||||
|
game.js:794 Sending invite command to WebSocket for user: sas
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:844 Message received from server in room main_room: {type: 'error', message: 'Target user sas not found in room main_room'}
|
||||||
|
game.js:869 Error message received: Target user sas not found in room main_room
|
||||||
|
chatSocket.onmessage @ game.js:869
|
||||||
|
game.js:749 Send button clicked, attempting to send message...
|
||||||
|
game.js:756 Attempting to send message: /i sasa
|
||||||
|
game.js:765 Detected invite command for user: sasa
|
||||||
|
game.js:794 Sending invite command to WebSocket for user: sasa
|
||||||
|
game.js:777 Message input cleared.
|
||||||
|
game.js:844 Message received from server in room main_room: {type: 'error', message: 'Target user sasa not found in room main_room'}
|
||||||
|
game.js:869 Error message received: Target user sasa not found in room main_room
|
||||||
|
chatSocket.onmessage @ game.js:869
|
||||||
41
logs/172.31.141.12-1726064615544.log
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
:8080/:1 The Cross-Origin-Opener-Policy header has been ignored, because the URL's origin was untrustworthy. It was defined either in the final response or a redirect. Please deliver the response using the HTTPS protocol. You can also use the 'localhost' origin instead. See https://www.w3.org/TR/powerful-features/#potentially-trustworthy-origin and https://html.spec.whatwg.org/#the-cross-origin-opener-policy-header.
|
||||||
|
game.js:2 DOM fully loaded and parsed
|
||||||
|
game.js:48 DOM elements initialized
|
||||||
|
game.js:71 Event listeners added
|
||||||
|
game.js:186 checkUserExists called with username: dede
|
||||||
|
game.js:203 User existence check response: {exists: false}
|
||||||
|
game.js:212 handleRegister called
|
||||||
|
game.js:225 Attempting to register user: dede
|
||||||
|
game.js:250 registerUser called with username: dede
|
||||||
|
game.js:273 Registration response data: {registered: true, token: 'c4ab5fd7-4b04-4353-8d4e-ae1afb2ba793'}
|
||||||
|
game.js:275 User registered successfully: {registered: true, token: 'c4ab5fd7-4b04-4353-8d4e-ae1afb2ba793'}
|
||||||
|
game.js:229 Token stored: c4ab5fd7-4b04-4353-8d4e-ae1afb2ba793
|
||||||
|
game.js:230 User registered successfully
|
||||||
|
game.js:922 Joining room: main_room with username: dede and token: c4ab5fd7-4b04-4353-8d4e-ae1afb2ba793
|
||||||
|
game.js:929 Joining new room: main_room
|
||||||
|
game.js:846 createRoomTab: main_room with username: dede and token: c4ab5fd7-4b04-4353-8d4e-ae1afb2ba793
|
||||||
|
game.js:856 Tab for room main_room already exists.
|
||||||
|
game.js:870 Showing tab for room: main_room
|
||||||
|
game.js:778 Initializing chat WebSocket...
|
||||||
|
game.js:779 Initializing chat WebSocket for room: main_room with username: dede
|
||||||
|
game.js:877 switchRoom: main_room with username: dede and token: c4ab5fd7-4b04-4353-8d4e-ae1afb2ba793
|
||||||
|
game.js:883 Attempting to switch to room: main_room
|
||||||
|
game.js:889 Switching from room null to room main_room
|
||||||
|
game.js:783 startChatWebSocket: main_room with username: dede and token: c4ab5fd7-4b04-4353-8d4e-ae1afb2ba793
|
||||||
|
game.js:785 Attempting to connect to WebSocket for room: main_room
|
||||||
|
game.js:835 WebSocket connection stored for room: main_room
|
||||||
|
game.js:784 WebSocket connection to 'ws://172.31.141.12:8080/ws/chat/main_room/' failed:
|
||||||
|
(anonymous) @ game.js:784
|
||||||
|
game.js:831 Chat WebSocket error in room main_room: Event {isTrusted: true, type: 'error', target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …}
|
||||||
|
chatSocket.onerror @ game.js:831
|
||||||
|
error
|
||||||
|
(anonymous) @ game.js:830
|
||||||
|
setTimeout
|
||||||
|
startChatWebSocket @ game.js:781
|
||||||
|
joinRoom @ game.js:932
|
||||||
|
handleRegister @ game.js:235
|
||||||
|
game.js:826 Chat WebSocket closed unexpectedly for room main_room
|
||||||
|
chatSocket.onclose @ game.js:826
|
||||||
|
game.js:754 WebSocket is already in CLOSING or CLOSED state.
|
||||||
|
sendMessage @ game.js:754
|
||||||
|
(anonymous) @ game.js:747
|
||||||
38
logs/172.31.141.12-1726065549172.log
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
:8080/:1 The Cross-Origin-Opener-Policy header has been ignored, because the URL's origin was untrustworthy. It was defined either in the final response or a redirect. Please deliver the response using the HTTPS protocol. You can also use the 'localhost' origin instead. See https://www.w3.org/TR/powerful-features/#potentially-trustworthy-origin and https://html.spec.whatwg.org/#the-cross-origin-opener-policy-header.
|
||||||
|
game.js:2 DOM fully loaded and parsed
|
||||||
|
game.js:48 DOM elements initialized
|
||||||
|
game.js:71 Event listeners added
|
||||||
|
game.js:186 checkUserExists called with username: ferdy
|
||||||
|
game.js:203 User existence check response: {exists: false}
|
||||||
|
game.js:212 handleRegister called
|
||||||
|
game.js:225 Attempting to register user: ferdy
|
||||||
|
game.js:250 registerUser called with username: ferdy
|
||||||
|
game.js:273 Registration response data: {registered: true, token: '4d383e70-92b8-4e04-8efb-d7bdfc0dcfac'}
|
||||||
|
game.js:275 User registered successfully: {registered: true, token: '4d383e70-92b8-4e04-8efb-d7bdfc0dcfac'}
|
||||||
|
game.js:229 Token stored: 4d383e70-92b8-4e04-8efb-d7bdfc0dcfac
|
||||||
|
game.js:230 User registered successfully
|
||||||
|
game.js:922 Joining room: main_room with username: ferdy and token: 4d383e70-92b8-4e04-8efb-d7bdfc0dcfac
|
||||||
|
game.js:929 Joining new room: main_room
|
||||||
|
game.js:846 createRoomTab: main_room with username: ferdy and token: 4d383e70-92b8-4e04-8efb-d7bdfc0dcfac
|
||||||
|
game.js:856 Tab for room main_room already exists.
|
||||||
|
game.js:870 Showing tab for room: main_room
|
||||||
|
game.js:778 Initializing chat WebSocket...
|
||||||
|
game.js:779 Initializing chat WebSocket for room: main_room with username: ferdy
|
||||||
|
game.js:877 switchRoom: main_room with username: ferdy and token: 4d383e70-92b8-4e04-8efb-d7bdfc0dcfac
|
||||||
|
game.js:883 Attempting to switch to room: main_room
|
||||||
|
game.js:889 Switching from room null to room main_room
|
||||||
|
game.js:783 startChatWebSocket: main_room with username: ferdy and token: 4d383e70-92b8-4e04-8efb-d7bdfc0dcfac
|
||||||
|
game.js:785 Attempting to connect to WebSocket for room: main_room
|
||||||
|
game.js:835 WebSocket connection stored for room: main_room
|
||||||
|
game.js:784 WebSocket connection to 'ws://172.31.141.12:8080/ws/chat/main_room/' failed:
|
||||||
|
(anonymous) @ game.js:784
|
||||||
|
game.js:831 Chat WebSocket error in room main_room: Event {isTrusted: true, type: 'error', target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …}isTrusted: truebubbles: falsecancelBubble: falsecancelable: falsecomposed: falsecurrentTarget: WebSocket {url: 'ws://172.31.141.12:8080/ws/chat/main_room/', readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …}defaultPrevented: falseeventPhase: 0returnValue: truesrcElement: WebSocket {url: 'ws://172.31.141.12:8080/ws/chat/main_room/', readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …}target: WebSocket {url: 'ws://172.31.141.12:8080/ws/chat/main_room/', readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …}timeStamp: 13273.79999999702type: "error"[[Prototype]]: Event
|
||||||
|
chatSocket.onerror @ game.js:831
|
||||||
|
error
|
||||||
|
(anonymous) @ game.js:830
|
||||||
|
setTimeout
|
||||||
|
startChatWebSocket @ game.js:781
|
||||||
|
joinRoom @ game.js:932
|
||||||
|
handleRegister @ game.js:235
|
||||||
|
game.js:826 Chat WebSocket closed unexpectedly for room main_room
|
||||||
|
chatSocket.onclose @ game.js:826
|
||||||
40
logs/172.31.141.12-1726069036744.log
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
:8080/:1 The Cross-Origin-Opener-Policy header has been ignored, because the URL's origin was untrustworthy. It was defined either in the final response or a redirect. Please deliver the response using the HTTPS protocol. You can also use the 'localhost' origin instead. See https://www.w3.org/TR/powerful-features/#potentially-trustworthy-origin and https://html.spec.whatwg.org/#the-cross-origin-opener-policy-header.
|
||||||
|
game.js:2 DOM fully loaded and parsed
|
||||||
|
game.js:48 DOM elements initialized
|
||||||
|
game.js:71 Event listeners added
|
||||||
|
game.js:186 checkUserExists called with username: gggg
|
||||||
|
game.js:203 User existence check response: {exists: false}
|
||||||
|
game.js:212 handleRegister called
|
||||||
|
game.js:225 Attempting to register user: gggg
|
||||||
|
game.js:250 registerUser called with username: gggg
|
||||||
|
game.js:273 Registration response data: {registered: true, token: 'a6010523-60c5-460b-ac49-39097e66a376'}
|
||||||
|
game.js:275 User registered successfully: {registered: true, token: 'a6010523-60c5-460b-ac49-39097e66a376'}
|
||||||
|
game.js:229 Token stored: a6010523-60c5-460b-ac49-39097e66a376
|
||||||
|
game.js:230 User registered successfully
|
||||||
|
game.js:926 Joining room: main_room with username: gggg and token: a6010523-60c5-460b-ac49-39097e66a376
|
||||||
|
game.js:933 Joining new room: main_room
|
||||||
|
game.js:850 createRoomTab: main_room with username: gggg and token: a6010523-60c5-460b-ac49-39097e66a376
|
||||||
|
game.js:860 Tab for room main_room already exists.
|
||||||
|
game.js:874 Showing tab for room: main_room
|
||||||
|
game.js:780 Initializing chat WebSocket...
|
||||||
|
game.js:781 Initializing chat WebSocket for room: main_room with username: gggg
|
||||||
|
game.js:881 switchRoom: main_room with username: gggg and token: a6010523-60c5-460b-ac49-39097e66a376
|
||||||
|
game.js:887 Attempting to switch to room: main_room
|
||||||
|
game.js:893 Switching from room null to room main_room
|
||||||
|
game.js:785 startChatWebSocket: main_room with username: gggg and token: a6010523-60c5-460b-ac49-39097e66a376
|
||||||
|
game.js:787 Attempting to connect to WebSocket for room: main_room
|
||||||
|
game.js:838 WebSocket connection stored for room: main_room
|
||||||
|
game.js:839 Authentication username for chat-input: gggg
|
||||||
|
game.js:790 Chat WebSocket connection established in room: main_room
|
||||||
|
game.js:798 Authentication message sent with username: gggg
|
||||||
|
game.js:799 Authentication message sent for room: main_room
|
||||||
|
game.js:804 Message received from server in room main_room: {type: 'chat_message', message: ': Anonyme Vous avez rejoint le chat main_room', room: 'main_room'}message: ": Anonyme Vous avez rejoint le chat main_room"room: "main_room"type: "chat_message"[[Prototype]]: Object
|
||||||
|
game.js:814 Message displayed in chat log for room: main_room
|
||||||
|
game.js:804 Message received from server in room main_room: {type: 'authenticated', username: 'gggg'}type: "authenticated"username: "gggg"[[Prototype]]: Object
|
||||||
|
game.js:806 User authenticated for chat successfully in room: main_room
|
||||||
|
game.js:754 Sending message from username: gggg
|
||||||
|
game.js:804 Message received from server in room main_room: {type: 'chat_message', message: 'gggg: hhfghfh', room: 'main_room'}
|
||||||
|
game.js:814 Message displayed in chat log for room: main_room
|
||||||
|
game.js:754 Sending message from username: gggg
|
||||||
|
game.js:804 Message received from server in room main_room: {type: 'chat_message', message: 'gggg: fhfhfh', room: 'main_room'}
|
||||||
|
game.js:814 Message displayed in chat log for room: main_room
|
||||||
9
logs/django_errors.log
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{"asctime": "2024-09-01 18:09:35,223", "levelname": "ERROR", "name": "django.request", "module": "log", "process": 25, "thread": 131470748288704, "message": "Internal Server Error: /register_user/", "taskName": null, "status_code": 500, "request": "<ASGIRequest: POST '/register_user/'>"}
|
||||||
|
{"asctime": "2024-09-01 18:19:53,264", "levelname": "ERROR", "name": "django.request", "module": "log", "process": 25, "thread": 131966181574336, "message": "Internal Server Error: /register_user/", "taskName": null, "status_code": 500, "request": "<ASGIRequest: POST '/register_user/'>"}
|
||||||
|
{"asctime": "2024-09-01 18:34:25,868", "levelname": "ERROR", "name": "django.request", "module": "log", "process": 25, "thread": 138740796229312, "message": "Internal Server Error: /register_user/", "taskName": null, "status_code": 500, "request": "<ASGIRequest: POST '/register_user/'>"}
|
||||||
|
{"asctime": "2024-09-01 18:35:04,063", "levelname": "ERROR", "name": "django.request", "module": "log", "process": 25, "thread": 138740796229312, "message": "Internal Server Error: /register_user/", "taskName": null, "status_code": 500, "request": "<ASGIRequest: POST '/register_user/'>"}
|
||||||
|
{"asctime": "2024-09-01 18:57:12,326", "levelname": "ERROR", "name": "django.request", "module": "log", "process": 25, "thread": 125916130838208, "message": "Internal Server Error: /register_user/", "taskName": null, "status_code": 500, "request": "<ASGIRequest: POST '/register_user/'>"}
|
||||||
|
{"asctime": "2024-09-01 19:05:27,423", "levelname": "ERROR", "name": "django.request", "module": "log", "process": 25, "thread": 132460855690944, "message": "Internal Server Error: /register_user/", "taskName": null, "status_code": 500, "request": "<ASGIRequest: POST '/register_user/'>"}
|
||||||
|
{"asctime": "2024-09-02 09:24:00,957", "levelname": "ERROR", "name": "django.request", "module": "log", "process": 25, "thread": 138073176278720, "message": "Internal Server Error: /register_user/", "taskName": null, "status_code": 500, "request": "<ASGIRequest: POST '/register_user/'>"}
|
||||||
|
{"asctime": "2024-09-02 09:31:57,272", "levelname": "ERROR", "name": "django.request", "module": "log", "process": 25, "thread": 129740826478272, "message": "Internal Server Error: /register_user/", "taskName": null, "status_code": 500, "request": "<ASGIRequest: POST '/register_user/'>"}
|
||||||
|
{"asctime": "2024-09-02 09:38:30,671", "levelname": "ERROR", "name": "django.request", "module": "log", "process": 25, "thread": 136981996635840, "message": "Internal Server Error: /register_user/", "taskName": null, "status_code": 500, "request": "<ASGIRequest: POST '/register_user/'>"}
|
||||||
10
makefile
@ -4,7 +4,7 @@ CONTAINER=$(c)
|
|||||||
|
|
||||||
up: down
|
up: down
|
||||||
$(COMPOSE) build
|
$(COMPOSE) build
|
||||||
$(COMPOSE) up -d $(CONTAINER) || true
|
$(COMPOSE) up $(CONTAINER) || true
|
||||||
|
|
||||||
build:
|
build:
|
||||||
$(COMPOSE) build $(CONTAINER)
|
$(COMPOSE) build $(CONTAINER)
|
||||||
@ -20,13 +20,8 @@ down:
|
|||||||
|
|
||||||
destroy:
|
destroy:
|
||||||
$(COMPOSE) down -v --rmi all
|
$(COMPOSE) down -v --rmi all
|
||||||
|
|
||||||
kill-pid:
|
|
||||||
sudo lsof -i :5432 | awk 'NR>1 {print $$2}' | xargs sudo kill -9 || true
|
sudo lsof -i :5432 | awk 'NR>1 {print $$2}' | xargs sudo kill -9 || true
|
||||||
sudo lsof -i :5601 | awk 'NR>1 {print $$2}' | xargs sudo kill -9 || true
|
sudo lsof -i :80 | awk 'NR>1 {print $$2}' | xargs sudo kill -9 || true
|
||||||
sudo lsof -i :9200 | awk 'NR>1 {print $$2}' | xargs sudo kill -9 || true
|
|
||||||
sudo lsof -i :8080 | awk 'NR>1 {print $$2}' | xargs sudo kill -9 || true
|
|
||||||
sudo lsof -i :5044 | awk 'NR>1 {print $$2}' | xargs sudo kill -9 || true
|
|
||||||
|
|
||||||
logs:
|
logs:
|
||||||
$(COMPOSE) logs -f $(CONTAINER)
|
$(COMPOSE) logs -f $(CONTAINER)
|
||||||
@ -52,4 +47,3 @@ help:
|
|||||||
@echo " make help # Show this help"
|
@echo " make help # Show this help"
|
||||||
|
|
||||||
.PHONY: up build start stop down destroy logs ps db-shell help
|
.PHONY: up build start stop down destroy logs ps db-shell help
|
||||||
|
|
||||||
|
|||||||
@ -11,8 +11,14 @@ https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import django
|
import django
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
logger.debug("Setting default DJANGO_SETTINGS_MODULE to 'pong.settings'")
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pong.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pong.settings')
|
||||||
|
|
||||||
|
logger.debug("Initializing Django setup")
|
||||||
django.setup()
|
django.setup()
|
||||||
|
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
@ -20,6 +26,7 @@ from channels.routing import ProtocolTypeRouter, URLRouter
|
|||||||
from channels.auth import AuthMiddlewareStack
|
from channels.auth import AuthMiddlewareStack
|
||||||
import pong.game.routing
|
import pong.game.routing
|
||||||
|
|
||||||
|
logger.debug("Configuring ProtocolTypeRouter")
|
||||||
application = ProtocolTypeRouter({
|
application = ProtocolTypeRouter({
|
||||||
"http": get_asgi_application(),
|
"http": get_asgi_application(),
|
||||||
"websocket": AuthMiddlewareStack(
|
"websocket": AuthMiddlewareStack(
|
||||||
@ -28,3 +35,5 @@ application = ProtocolTypeRouter({
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
logger.info("ASGI application configurée et prête à accepter les connexions")
|
||||||
|
|||||||
@ -1,106 +1,379 @@
|
|||||||
# /pong/game/consumers.py
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from channels.generic.websocket import AsyncWebsocketConsumer
|
from channels.generic.websocket import AsyncWebsocketConsumer
|
||||||
|
from asgiref.sync import sync_to_async
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from channels.db import database_sync_to_async
|
from channels.db import database_sync_to_async
|
||||||
from .matchmaking import match_maker
|
from .matchmaking import match_maker
|
||||||
from .tournament import tournament_match_maker
|
from .tournament import tournament_match_maker
|
||||||
import asyncio
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class GameConsumer(AsyncWebsocketConsumer):
|
class GameConsumer(AsyncWebsocketConsumer):
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
await self.accept()
|
try:
|
||||||
self.game = None
|
await self.accept()
|
||||||
print("User connected")
|
self.game = None
|
||||||
|
logger.info("User connected via WebSocket")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error during WebSocket connection: {str(e)}")
|
||||||
|
|
||||||
async def receive(self, text_data):
|
async def receive(self, text_data):
|
||||||
data = json.loads(text_data)
|
try:
|
||||||
if data['type'] == 'authenticate':
|
logger.debug(f"Received data: {text_data}")
|
||||||
await self.authenticate(data['token'])
|
data = json.loads(text_data)
|
||||||
elif data['type'] == 'authenticate2':
|
message_type = data.get('type')
|
||||||
await self.authenticate2(data['token_1'], data['token_2'])
|
|
||||||
elif data['type'] == 'authenticate3':
|
|
||||||
await self.authenticate3(data['token'])
|
|
||||||
elif data['type'] == 'key_press':
|
|
||||||
if self.game:
|
|
||||||
await self.game.handle_key_press(self, data['key'])
|
|
||||||
elif data['type'] == 'start_tournament':
|
|
||||||
print(f"Start TOURNAMENT received by {self.user}")
|
|
||||||
# Run the tournament in the background
|
|
||||||
asyncio.create_task(tournament_match_maker.start_tournament())
|
|
||||||
|
|
||||||
async def authenticate(self, token):
|
if message_type == 'authenticate':
|
||||||
user = await self.get_user_from_token(token)
|
await self.authenticate(data.get('token'))
|
||||||
if user:
|
elif message_type == 'authenticate2':
|
||||||
self.user = user
|
await self.authenticate2(data.get('token_1'), data.get('token_2'))
|
||||||
await self.send(text_data=json.dumps({'type': 'authenticated'}))
|
elif message_type == 'authenticate3':
|
||||||
print(f"User {self.user} authenticated")
|
await self.authenticate3(data.get('token'))
|
||||||
await self.join_waiting_room()
|
elif message_type == 'key_press':
|
||||||
else:
|
if self.game:
|
||||||
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Authentication failed'}))
|
await self.game.handle_key_press(self, data.get('key'))
|
||||||
print("Authentication failed")
|
else:
|
||||||
|
await match_maker.handle_key_press(self, data.get('key'))
|
||||||
|
else:
|
||||||
|
logger.warning(f"Received unknown message type: {message_type}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Unknown message type'}))
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
logger.error(f"JSON decode error: {str(e)} - Data received: {text_data}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Invalid JSON format'}))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error in WebSocket receive: {str(e)}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Internal server error'}))
|
||||||
|
|
||||||
@database_sync_to_async
|
async def authenticate(self, token):
|
||||||
def get_user_from_token(self, token):
|
if not token:
|
||||||
try:
|
logger.error("Token is None, authentication cannot proceed")
|
||||||
user = User.objects.filter(auth_token=token).first()
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Token is missing'}))
|
||||||
return user
|
return
|
||||||
except User.DoesNotExist:
|
try:
|
||||||
return None
|
user = await self.get_user_from_token(token)
|
||||||
|
if user:
|
||||||
|
self.user = user
|
||||||
|
await self.send(text_data=json.dumps({'type': 'authenticated'}))
|
||||||
|
logger.info(f"User {self.user} authenticated")
|
||||||
|
await self.join_waiting_room()
|
||||||
|
else:
|
||||||
|
logger.warning(f"Authentication failed for token: {token}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Authentication failed'}))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error during authentication: {str(e)}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Internal server error'}))
|
||||||
|
|
||||||
async def join_waiting_room(self):
|
async def authenticate2(self, token_1, token_2):
|
||||||
await self.send(text_data=json.dumps({'type': 'waiting_room'}))
|
try:
|
||||||
await match_maker.add_player(self)
|
user = await self.get_user_from_token(token_1)
|
||||||
|
if user:
|
||||||
|
self.user = user
|
||||||
|
await self.send(text_data=json.dumps({'type': 'authenticated'}))
|
||||||
|
logger.info(f"User {self.user} authenticated with token_1")
|
||||||
|
|
||||||
async def authenticate2(self, token, token2):
|
user2 = await self.get_user_from_token2(token_2)
|
||||||
user = await self.get_user_from_token(token)
|
if user2:
|
||||||
if user:
|
self.user2 = user2
|
||||||
self.user = user
|
await self.send(text_data=json.dumps({'type': 'authenticated'}))
|
||||||
await self.send(text_data=json.dumps({'type': 'authenticated'}))
|
logger.info(f"User {self.user2} authenticated with token_2")
|
||||||
print(f"User {self.user} authenticated")
|
await match_maker.create_game(self, None, True)
|
||||||
user2 = await self.get_user_from_token2(token2)
|
else:
|
||||||
if user2:
|
logger.warning(f"Authentication failed for token_2: {token_2}")
|
||||||
self.user2 = user2
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Authentication failed for user 2'}))
|
||||||
await self.send(text_data=json.dumps({'type': 'authenticated'}))
|
else:
|
||||||
print(f"User {self.user2} authenticated")
|
logger.warning(f"Authentication failed for token_1: {token_1}")
|
||||||
await match_maker.create_game(self, None, True)
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Authentication failed for user 1'}))
|
||||||
else:
|
except Exception as e:
|
||||||
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Authentication failed'}))
|
logger.error(f"Error during dual authentication: {str(e)}")
|
||||||
print("Authentication failed")
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Internal server error'}))
|
||||||
else:
|
|
||||||
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Authentication failed'}))
|
|
||||||
print("Authentication failed")
|
|
||||||
|
|
||||||
@database_sync_to_async
|
async def authenticate3(self, token):
|
||||||
def get_user_from_token2(self, token):
|
try:
|
||||||
try:
|
user = await self.get_user_from_token(token)
|
||||||
user2 = User.objects.filter(auth_token=token).first()
|
if user:
|
||||||
return user2
|
self.user = user
|
||||||
except User.DoesNotExist:
|
await self.send(text_data=json.dumps({'type': 'authenticated'}))
|
||||||
return None
|
logger.info(f"User {self.user} authenticated for tournament")
|
||||||
|
await self.join_tournament_waiting_room()
|
||||||
|
else:
|
||||||
|
logger.warning(f"Authentication failed for token: {token}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Authentication failed'}))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error during tournament authentication: {str(e)}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Internal server error'}))
|
||||||
|
|
||||||
async def authenticate3(self, token):
|
@database_sync_to_async
|
||||||
user = await self.get_user_from_token(token)
|
def get_user_from_token(self, token):
|
||||||
if user:
|
try:
|
||||||
self.user = user
|
user = User.objects.filter(auth_token=token).first()
|
||||||
await self.send(text_data=json.dumps({'type': 'authenticated'}))
|
logger.debug(f"User found: {user} for token: {token}")
|
||||||
print(f"User {self.user.username} authenticated for tournament")
|
return user
|
||||||
await self.join_tournament_waiting_room()
|
except User.DoesNotExist:
|
||||||
else:
|
logger.warning(f"User not found for token: {token}")
|
||||||
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Authentication failed'}))
|
return None
|
||||||
print("Tournament authentication failed")
|
|
||||||
|
|
||||||
async def join_tournament_waiting_room(self):
|
@database_sync_to_async
|
||||||
await tournament_match_maker.add_player(self)
|
def get_user_from_token2(self, token):
|
||||||
|
try:
|
||||||
|
user2 = User.objects.filter(auth_token=token).first()
|
||||||
|
logger.debug(f"User2 found: {user2} for token: {token}")
|
||||||
|
return user2
|
||||||
|
except User.DoesNotExist:
|
||||||
|
logger.warning(f"User not found for token_2: {token}")
|
||||||
|
return None
|
||||||
|
|
||||||
async def disconnect(self, close_code):
|
async def join_waiting_room(self):
|
||||||
if self.game:
|
logger.info("Joining waiting room")
|
||||||
await self.game.end_game(disconnected_player=self)
|
await self.send(text_data=json.dumps({'type': 'waiting_room'}))
|
||||||
await match_maker.remove_player(self)
|
await match_maker.add_player(self)
|
||||||
await tournament_match_maker.remove_player(self)
|
|
||||||
print(f"User {self.user.username if hasattr(self, 'user') else 'Unknown'} disconnected")
|
|
||||||
|
|
||||||
async def set_game(self, game):
|
async def join_tournament_waiting_room(self):
|
||||||
print(f"({self.user}) Game set to: {game}")
|
logger.info("Joining tournament waiting room")
|
||||||
self.game = game
|
await tournament_match_maker.add_player(self)
|
||||||
|
|
||||||
|
async def disconnect(self, close_code):
|
||||||
|
try:
|
||||||
|
if self.game:
|
||||||
|
await self.game.end_game(disconnected_player=self)
|
||||||
|
await match_maker.remove_player(self)
|
||||||
|
await tournament_match_maker.remove_player(self)
|
||||||
|
logger.info(f"User {self.user.username if hasattr(self, 'user') else 'Unknown'} disconnected")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error during WebSocket disconnection: {str(e)}")
|
||||||
|
|
||||||
|
async def set_game(self, game):
|
||||||
|
logger.info(f"Setting game: {game}")
|
||||||
|
self.game = game
|
||||||
|
###############################CHAT############################################
|
||||||
|
class ChatConsumer(AsyncWebsocketConsumer):
|
||||||
|
groups = {}
|
||||||
|
|
||||||
|
async def connect(self):
|
||||||
|
try:
|
||||||
|
# Récupérer le nom de la room
|
||||||
|
self.room_group_name = self.scope['url_route']['kwargs']['room_name']
|
||||||
|
|
||||||
|
# Accepter la connexion WebSocket
|
||||||
|
await self.accept()
|
||||||
|
|
||||||
|
logger.info(f"Connexion au WebSocket de chat dans la room {self.room_group_name}")
|
||||||
|
|
||||||
|
# Ajouter l'utilisateur au groupe en mémoire
|
||||||
|
if self.room_group_name not in self.groups:
|
||||||
|
self.groups[self.room_group_name] = []
|
||||||
|
self.groups[self.room_group_name].append(self.channel_name)
|
||||||
|
|
||||||
|
logger.info(f"User {self.channel_name} added to group {self.room_group_name}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Erreur lors de la connexion WebSocket: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
async def disconnect(self, close_code):
|
||||||
|
try:
|
||||||
|
# Retirer l'utilisateur du groupe en mémoire
|
||||||
|
if self.room_group_name in self.groups:
|
||||||
|
self.groups[self.room_group_name].remove(self.channel_name)
|
||||||
|
if not self.groups[self.room_group_name]:
|
||||||
|
del self.groups[self.room_group_name]
|
||||||
|
|
||||||
|
await self.send_group_message(
|
||||||
|
self.room_group_name,
|
||||||
|
{
|
||||||
|
'type': 'chat_message',
|
||||||
|
'message': f'{self.user.username if hasattr(self, "user") else "Unknown"} a quitté le chat',
|
||||||
|
'username': self.user.username if hasattr(self, "user") else "Unknown",
|
||||||
|
'room': self.room_group_name
|
||||||
|
}
|
||||||
|
)
|
||||||
|
logger.info(f"{self.user.username if hasattr(self, 'user') else 'Unknown'} déconnecté du WebSocket de chat dans la room {self.room_group_name}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Erreur lors de la déconnexion WebSocket du chat: {str(e)}")
|
||||||
|
|
||||||
|
async def receive(self, text_data):
|
||||||
|
try:
|
||||||
|
data = json.loads(text_data)
|
||||||
|
message_type = data.get('type')
|
||||||
|
username = data.get('username').strip().lower() # Normalisation du nom d'utilisateur
|
||||||
|
|
||||||
|
# Log pour vérifier que le username est bien reçu
|
||||||
|
logger.info(f"Message reçu avec username: {username}")
|
||||||
|
if not username:
|
||||||
|
logger.error(f"Username missing in message: {data}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Username is missing'}))
|
||||||
|
return
|
||||||
|
|
||||||
|
# Gestion des types de messages
|
||||||
|
if message_type == 'authenticate':
|
||||||
|
await self.authenticate(data.get('token'), username)
|
||||||
|
|
||||||
|
elif message_type == 'chat_message':
|
||||||
|
if 'message' not in data:
|
||||||
|
logger.error(f"Format de message incorrect : {data}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Format de message incorrect'}))
|
||||||
|
return
|
||||||
|
|
||||||
|
message = data['message']
|
||||||
|
|
||||||
|
# Envoyer le message à tous les autres utilisateurs de la room
|
||||||
|
await self.send_group_message(
|
||||||
|
self.room_group_name,
|
||||||
|
{
|
||||||
|
'type': 'chat_message',
|
||||||
|
'message': message,
|
||||||
|
'username': username,
|
||||||
|
'room': self.room_group_name
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Gestion de la commande /b pour bloquer un utilisateur
|
||||||
|
elif message_type == 'block_user':
|
||||||
|
target_user = data.get('target_user').strip().lower()
|
||||||
|
if target_user == username:
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'You cannot block yourself'}))
|
||||||
|
else:
|
||||||
|
await self.handle_block_user(data)
|
||||||
|
|
||||||
|
# Gestion de la commande /i pour inviter un utilisateur
|
||||||
|
elif message_type == 'invite_user':
|
||||||
|
target_user = data.get('target_user').strip().lower()
|
||||||
|
if target_user == username:
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'You cannot invite yourself'}))
|
||||||
|
else:
|
||||||
|
await self.handle_invite_user(data)
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.warning(f"Unhandled message type: {message_type}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Unhandled message type'}))
|
||||||
|
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
logger.error(f"Erreur de décodage JSON : {str(e)} - Données reçues : {text_data}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Format JSON invalide'}))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Erreur lors de la réception du message du chat: {str(e)}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Erreur interne du serveur'}))
|
||||||
|
|
||||||
|
async def handle_block_user(self, data):
|
||||||
|
username = data['username'].strip().lower() # Normalisation du nom d'utilisateur
|
||||||
|
target_user = data['target_user'].strip().lower()
|
||||||
|
|
||||||
|
# Utiliser self.room_group_name pour vérifier que l'utilisateur ciblé est bien dans la bonne room
|
||||||
|
if target_user not in self.groups.get(self.room_group_name, []):
|
||||||
|
logger.error(f"Target user {target_user} does not exist in room {self.room_group_name}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': f'Target user {target_user} not found in room {self.room_group_name}'}))
|
||||||
|
return
|
||||||
|
|
||||||
|
logger.info(f"Block request: {username} wants to block {target_user} in room {self.room_group_name}")
|
||||||
|
|
||||||
|
if target_user == username:
|
||||||
|
logger.warning(f"Block attempt failed: {username} tried to block themselves")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'You cannot block yourself'}))
|
||||||
|
else:
|
||||||
|
logger.info(f"{username} successfully blocked {target_user}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'success', 'message': f'You have blocked {target_user} in room {self.room_group_name}'}))
|
||||||
|
|
||||||
|
async def handle_invite_user(self, data):
|
||||||
|
username = data['username'].strip().lower()
|
||||||
|
target_user = data['target_user'].strip().lower()
|
||||||
|
|
||||||
|
# Utiliser self.room_group_name pour inviter l'utilisateur dans la room active
|
||||||
|
room = self.room_group_name
|
||||||
|
|
||||||
|
# Vérification que le joueur à inviter est dans la room
|
||||||
|
if target_user not in self.groups.get(room, []):
|
||||||
|
logger.error(f"Target user {target_user} does not exist in room {room}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': f'Target user {target_user} not found in room {room}'}))
|
||||||
|
return
|
||||||
|
|
||||||
|
logger.info(f"Invitation request: {username} wants to invite {target_user} to a quick match in room {room}")
|
||||||
|
|
||||||
|
if target_user == username:
|
||||||
|
logger.warning(f"Invite attempt failed: {username} tried to invite themselves")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'You cannot invite yourself'}))
|
||||||
|
else:
|
||||||
|
logger.info(f"{username} successfully sent an invitation to {target_user} in room {room}")
|
||||||
|
await self.send_group_message(room, {
|
||||||
|
'type': 'invite',
|
||||||
|
'message': f'{username} invited {target_user} to a quick match',
|
||||||
|
'username': username,
|
||||||
|
'target_user': target_user
|
||||||
|
})
|
||||||
|
await self.send(text_data=json.dumps({'type': 'success', 'message': f'Invitation sent to {target_user} in room {room}'}))
|
||||||
|
|
||||||
|
|
||||||
|
async def authenticate(self, token, username):
|
||||||
|
if not token:
|
||||||
|
logger.error("Token is None, authentication cannot proceed")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Token is missing'}))
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
user = await self.get_user_from_token(token)
|
||||||
|
if user:
|
||||||
|
self.user = user
|
||||||
|
logger.info(f"User {username} authenticated successfully with token: {token}")
|
||||||
|
|
||||||
|
# Envoyer un message d'authentification réussie au client
|
||||||
|
await self.send(text_data=json.dumps({'type': 'authenticated', 'username': username}))
|
||||||
|
|
||||||
|
# Envoyer le message de bienvenue après l'authentification réussie
|
||||||
|
await self.send_group_message(
|
||||||
|
self.room_group_name,
|
||||||
|
{
|
||||||
|
'username': username,
|
||||||
|
'room': self.room_group_name,
|
||||||
|
'type': 'chat_message',
|
||||||
|
'message': f' a rejoint le chat {self.room_group_name}',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
logger.warning(f"Authentication failed for token: {token}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Authentication failed'}))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error during authentication: {str(e)}")
|
||||||
|
await self.send(text_data=json.dumps({'type': 'error', 'message': 'Internal server error'}))
|
||||||
|
|
||||||
|
@sync_to_async
|
||||||
|
def get_user_from_token(self, token):
|
||||||
|
try:
|
||||||
|
user = User.objects.filter(auth_token=token).first()
|
||||||
|
logger.debug(f"User found: {user} for token: {token}")
|
||||||
|
return user
|
||||||
|
except User.DoesNotExist:
|
||||||
|
logger.warning(f"User not found for token: {token}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
async def send_group_message(self, group_name, message):
|
||||||
|
# Utilisation de self.room_group_name pour s'assurer que la bonne room est utilisée
|
||||||
|
group_name = self.room_group_name # Utilisation explicite de self.room_group_name
|
||||||
|
|
||||||
|
if group_name in self.groups:
|
||||||
|
logger.debug(f"Sending message to group {group_name}: {message}")
|
||||||
|
for channel_name in self.groups[group_name]:
|
||||||
|
try:
|
||||||
|
await self.channel_layer.send(channel_name, {
|
||||||
|
'type': 'chat_message',
|
||||||
|
'message': message['message'],
|
||||||
|
'username': message['username'],
|
||||||
|
'room': message['room']
|
||||||
|
})
|
||||||
|
logger.debug(f"Message sent to {channel_name} in room {message['room']}: {message}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to send message to {channel_name} in room {group_name}: {str(e)}")
|
||||||
|
else:
|
||||||
|
logger.error(f"Group {group_name} does not exist, unable to send message")
|
||||||
|
|
||||||
|
async def chat_message(self, event):
|
||||||
|
message = event['message']
|
||||||
|
username = event.get('username', 'Anonyme')
|
||||||
|
room = event.get('room', 'unknown')
|
||||||
|
|
||||||
|
# Log pour vérifier le username avant envoi
|
||||||
|
logger.info(f"Sending chat message from username: {username} in room: {room}")
|
||||||
|
|
||||||
|
# Envoyer le message au WebSocket
|
||||||
|
await self.send(text_data=json.dumps({
|
||||||
|
'type': 'chat_message',
|
||||||
|
'message': f'{username}: {message}',
|
||||||
|
'room': room
|
||||||
|
}))
|
||||||
|
|||||||
@ -4,14 +4,11 @@ import json
|
|||||||
import asyncio
|
import asyncio
|
||||||
import random
|
import random
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from .utils import handle_game_data, getlen
|
from .utils import handle_game_data
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
from .models import Tournoi
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
# Global variable to handle the using of the database
|
|
||||||
USING_DB = False
|
|
||||||
|
|
||||||
def __init__(self, game_id, player1, player2, localgame):
|
def __init__(self, game_id, player1, player2, localgame):
|
||||||
self.game_id = game_id
|
self.game_id = game_id
|
||||||
self.player1 = player1
|
self.player1 = player1
|
||||||
@ -31,10 +28,9 @@ class Game:
|
|||||||
'game_text': ''
|
'game_text': ''
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
# Set botgame to True if either player1 or player2 is None
|
self.botgame = player2 is None
|
||||||
self.botgame = player1 is None or player2 is None
|
|
||||||
self.game_state = {
|
self.game_state = {
|
||||||
'player1_name': player1.user.username if player1 else 'BOT',
|
'player1_name': player1.user.username,
|
||||||
'player2_name': player2.user.username if player2 else 'BOT',
|
'player2_name': player2.user.username if player2 else 'BOT',
|
||||||
'player1_position': 150,
|
'player1_position': 150,
|
||||||
'player2_position': 150,
|
'player2_position': 150,
|
||||||
@ -51,64 +47,57 @@ class Game:
|
|||||||
self.p2_mov = 0
|
self.p2_mov = 0
|
||||||
self.bt1 = 0
|
self.bt1 = 0
|
||||||
self.bt2 = 0
|
self.bt2 = 0
|
||||||
self.start_time = datetime.now()
|
self.start_time = None
|
||||||
self.future_ball_position = {'x': 390, 'y': 190}
|
|
||||||
|
|
||||||
async def start_game(self):
|
async def start_game(self):
|
||||||
print(f"- Game #{self.game_id} STARTED ({self.game_state['player1_name']} vs {self.game_state['player2_name']}) --- ({self})")
|
print(f"- Game #{self.game_id} STARTED")
|
||||||
self.game_loop_task = asyncio.create_task(self.game_loop())
|
self.game_loop_task = asyncio.create_task(self.game_loop())
|
||||||
|
self.start_time = datetime.now()
|
||||||
print(f" Begin MATCH at: {self.start_time}")
|
print(f" Begin MATCH at: {self.start_time}")
|
||||||
|
|
||||||
async def game_loop(self):
|
async def game_loop(self):
|
||||||
print(" In the game loop..")
|
print(" In the game loop..")
|
||||||
x = 59
|
x = 0
|
||||||
while not self.ended:
|
while not self.ended:
|
||||||
if self.botgame:
|
if self.botgame:
|
||||||
x += 1
|
x += 1
|
||||||
if x == 60:
|
if x == 60:
|
||||||
# Random BOT difficulty..
|
await self.update_bot_position()
|
||||||
steps = 60#random.randint(10, 60)
|
|
||||||
self.future_ball_position = await self.predict_ball_trajectory(steps)
|
|
||||||
x = 0
|
x = 0
|
||||||
if self.botgame:
|
|
||||||
await self.update_bot_position()
|
|
||||||
await self.handle_pad_movement()
|
await self.handle_pad_movement()
|
||||||
await self.update_game_state()
|
await self.update_game_state()
|
||||||
await self.send_game_state()
|
await self.send_game_state()
|
||||||
await asyncio.sleep(1/60) # Around 60 FPS
|
await asyncio.sleep(1/60) # Around 60 FPS
|
||||||
|
|
||||||
async def update_bot_position(self):
|
async def update_bot_position(self):
|
||||||
#future_ball_position = self.predict_ball_trajectory()
|
future_ball_position = self.predict_ball_trajectory()
|
||||||
target_y = self.future_ball_position['y']
|
|
||||||
|
target_y = future_ball_position['y']
|
||||||
player2_position = self.game_state['player2_position']
|
player2_position = self.game_state['player2_position']
|
||||||
|
|
||||||
# Adjusts bot position based on expected ball position
|
# Adjusts bot position based on expected ball position
|
||||||
if player2_position < target_y < player2_position + 80:
|
if player2_position < target_y < player2_position + 80:
|
||||||
pass #bot already placed
|
pass #bot already placed
|
||||||
elif player2_position < target_y:
|
elif player2_position < target_y:
|
||||||
self.p2_mov = 1
|
self.game_state['player2_position'] = min(player2_position + (50 * self.speed), 300)
|
||||||
#self.game_state['player2_position'] = min(player2_position + (50 * self.speed), 300)
|
|
||||||
elif player2_position + 80 > target_y:
|
elif player2_position + 80 > target_y:
|
||||||
self.p2_mov = -1
|
self.game_state['player2_position'] = max(player2_position - (50 * self.speed), 0)
|
||||||
#self.game_state['player2_position'] = max(player2_position - (50 * self.speed), 0)
|
|
||||||
|
def predict_ball_trajectory(self, steps=60):
|
||||||
|
|
||||||
async def predict_ball_trajectory(self, steps=60):
|
|
||||||
future_x = self.game_state['ball_position']['x']
|
future_x = self.game_state['ball_position']['x']
|
||||||
future_y = self.game_state['ball_position']['y']
|
future_y = self.game_state['ball_position']['y']
|
||||||
velocity_x = self.game_state['ball_velocity']['x']
|
velocity_x = self.game_state['ball_velocity']['x']
|
||||||
velocity_y = self.game_state['ball_velocity']['y']
|
velocity_y = self.game_state['ball_velocity']['y']
|
||||||
|
|
||||||
for _ in range(steps):
|
for _ in range(steps):
|
||||||
future_x += velocity_x
|
future_x += velocity_x
|
||||||
if future_x <= 10:
|
future_y += velocity_y
|
||||||
future_x = 10
|
|
||||||
velocity_x = -velocity_x
|
# Dealing with bounces off walls
|
||||||
elif future_x >= 790:
|
if future_y <= 0 or future_y >= 300:
|
||||||
future_x = 790
|
velocity_y = -velocity_y # Reverse the direction of vertical movement
|
||||||
else:
|
|
||||||
future_y += velocity_y
|
|
||||||
# Dealing with bounces off walls
|
|
||||||
if future_y <= 10 or future_y >= 390:
|
|
||||||
velocity_y = -velocity_y # Reverse the direction of vertical movement
|
|
||||||
return {'x': future_x, 'y': future_y}
|
return {'x': future_x, 'y': future_y}
|
||||||
|
|
||||||
async def update_game_state(self):
|
async def update_game_state(self):
|
||||||
@ -221,10 +210,10 @@ class Game:
|
|||||||
self.ended = True
|
self.ended = True
|
||||||
if self.game_loop_task:
|
if self.game_loop_task:
|
||||||
self.game_loop_task.cancel()
|
self.game_loop_task.cancel()
|
||||||
print(f"- Game #{self.game_id} ENDED --- ({self})")
|
print(f"- Game #{self.game_id} ENDED")
|
||||||
|
|
||||||
end_time = datetime.now()
|
end_time = datetime.now()
|
||||||
duration = (end_time - self.start_time).total_seconds() / 60
|
duration = (end_time - self.start_time).total_seconds() / 60
|
||||||
|
|
||||||
# Notify that one player left the game
|
# Notify that one player left the game
|
||||||
if disconnected_player:
|
if disconnected_player:
|
||||||
@ -246,17 +235,6 @@ class Game:
|
|||||||
if not self.botgame:
|
if not self.botgame:
|
||||||
if not self.localgame:
|
if not self.localgame:
|
||||||
await self.player2.send(end_message)
|
await self.player2.send(end_message)
|
||||||
while (Game.USING_DB):
|
await sync_to_async(handle_game_data)(self.game_state['player1_name'], self.game_state['player2_name'],
|
||||||
await asyncio.sleep(1)
|
|
||||||
Game.USING_DB = True
|
|
||||||
if hasattr(self, 'tournament'):
|
|
||||||
print(f"*** Game #{self.game_id} from tournament: {self.tournament.tournoi_reg.name} ENDED ***")
|
|
||||||
await sync_to_async(handle_game_data)(self.game_state['player1_name'], self.game_state['player2_name'],
|
|
||||||
self.game_state['player1_score'], self.game_state['player2_score'],
|
|
||||||
self.bt1, self.bt2, duration, True, self.tournament.tournoi_reg)
|
|
||||||
print(f"*** Game #{self.game_id} from tournament: {self.tournament.tournoi_reg.name} is REGISTERED ***")
|
|
||||||
else:
|
|
||||||
await sync_to_async(handle_game_data)(self.game_state['player1_name'], self.game_state['player2_name'],
|
|
||||||
self.game_state['player1_score'], self.game_state['player2_score'],
|
self.game_state['player1_score'], self.game_state['player2_score'],
|
||||||
self.bt1, self.bt2, duration, False, None)
|
self.bt1, self.bt2, duration, False, None)
|
||||||
Game.USING_DB = False
|
|
||||||
|
|||||||
@ -26,8 +26,7 @@ class MatchMaker:
|
|||||||
for game in self.active_games.values():
|
for game in self.active_games.values():
|
||||||
if player in [game.player1, game.player2]:
|
if player in [game.player1, game.player2]:
|
||||||
await game.end_game(disconnected_player=player)
|
await game.end_game(disconnected_player=player)
|
||||||
if game.game_id in self.active_games:
|
del self.active_games[game.game_id]
|
||||||
del self.active_games[game.game_id]
|
|
||||||
break
|
break
|
||||||
|
|
||||||
async def match_loop(self):
|
async def match_loop(self):
|
||||||
@ -103,5 +102,11 @@ class MatchMaker:
|
|||||||
'player2': 'BOT'
|
'player2': 'BOT'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
async def handle_key_press(self, player, key):
|
||||||
|
for game in self.active_games.values():
|
||||||
|
if player in [game.player1, game.player2]:
|
||||||
|
await game.handle_key_press(player, key)
|
||||||
|
break
|
||||||
|
|
||||||
# Instance of the class
|
# Instance of the class
|
||||||
match_maker = MatchMaker()
|
match_maker = MatchMaker()
|
||||||
|
|||||||
@ -1,19 +0,0 @@
|
|||||||
# Generated by Django 5.0.7 on 2024-07-31 16:04
|
|
||||||
|
|
||||||
import django.db.models.deletion
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('game', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='match',
|
|
||||||
name='winner',
|
|
||||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='won_matches', to='game.player'),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
# Generated by Django 5.1.1 on 2024-09-10 14:17
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('game', '0002_alter_match_winner'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='tournoi',
|
|
||||||
name='date',
|
|
||||||
field=models.DateField(auto_now_add=True),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@ -1,9 +1,13 @@
|
|||||||
# /pong/game/models.py
|
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# Ajout d'un champ auth_token à la classe User
|
||||||
User.add_to_class('auth_token', models.CharField(max_length=100, null=True, blank=True, unique=True))
|
User.add_to_class('auth_token', models.CharField(max_length=100, null=True, blank=True, unique=True))
|
||||||
|
logger.debug("Ajout du champ auth_token à la classe User")
|
||||||
|
|
||||||
class Player(models.Model):
|
class Player(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
@ -22,21 +26,31 @@ class Player(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
logger.info(f"Saving player: {self.name}")
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
logger.info(f"Player {self.name} saved successfully")
|
||||||
|
|
||||||
class Tournoi(models.Model):
|
class Tournoi(models.Model):
|
||||||
name = models.CharField(max_length=200)
|
name = models.CharField(max_length=200)
|
||||||
nbr_player = models.PositiveSmallIntegerField()
|
nbr_player = models.PositiveSmallIntegerField()
|
||||||
date = models.DateField(auto_now_add=True)
|
date = models.DateField()
|
||||||
winner = models.ForeignKey('Player', on_delete=models.SET_NULL, null=True)
|
winner = models.ForeignKey('Player', on_delete=models.SET_NULL, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
logger.info(f"Saving tournament: {self.name}")
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
logger.info(f"Tournament {self.name} saved successfully")
|
||||||
|
|
||||||
class Match(models.Model):
|
class Match(models.Model):
|
||||||
player1 = models.ForeignKey('Player', related_name='match_as_player1', on_delete=models.CASCADE)
|
player1 = models.ForeignKey('Player', related_name='match_as_player1', on_delete=models.CASCADE)
|
||||||
player2 = models.ForeignKey('Player', related_name='match_as_player2', on_delete=models.CASCADE)
|
player2 = models.ForeignKey('Player', related_name='match_as_player2', on_delete=models.CASCADE)
|
||||||
score_player1 = models.PositiveSmallIntegerField()
|
score_player1 = models.PositiveSmallIntegerField()
|
||||||
score_player2 = models.PositiveSmallIntegerField()
|
score_player2 = models.PositiveSmallIntegerField()
|
||||||
winner = models.ForeignKey('Player', related_name='won_matches',on_delete=models.CASCADE, null=True)
|
winner = models.ForeignKey('Player', related_name='won_matches', on_delete=models.CASCADE, null=True)
|
||||||
nbr_ball_touch_p1 = models.PositiveIntegerField()
|
nbr_ball_touch_p1 = models.PositiveIntegerField()
|
||||||
nbr_ball_touch_p2 = models.PositiveIntegerField()
|
nbr_ball_touch_p2 = models.PositiveIntegerField()
|
||||||
duration = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
|
duration = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
|
||||||
@ -45,6 +59,7 @@ class Match(models.Model):
|
|||||||
tournoi = models.ForeignKey('Tournoi', related_name='matches', on_delete=models.SET_NULL, null=True)
|
tournoi = models.ForeignKey('Tournoi', related_name='matches', on_delete=models.SET_NULL, null=True)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
logger.debug(f"Cleaning match: {self.player1.name} vs {self.player2.name}")
|
||||||
if self.score_player1 < 0 or self.score_player2 < 0:
|
if self.score_player1 < 0 or self.score_player2 < 0:
|
||||||
raise ValidationError('Les scores doivent être positifs.')
|
raise ValidationError('Les scores doivent être positifs.')
|
||||||
if self.score_player1 > self.score_player2 and self.winner != self.player1:
|
if self.score_player1 > self.score_player2 and self.winner != self.player1:
|
||||||
@ -54,8 +69,10 @@ class Match(models.Model):
|
|||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
logger.info(f"Saving match: {self.player1.name} vs {self.player2.name}")
|
||||||
self.clean()
|
self.clean()
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
logger.info(f"Match {self.player1.name} vs {self.player2.name} saved successfully")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.player1.name} vs {self.player2.name}"
|
return f"{self.player1.name} vs {self.player2.name}"
|
||||||
@ -1,8 +1,15 @@
|
|||||||
# /pong/game/routing.py
|
# /pong/game/routing.py
|
||||||
|
|
||||||
from django.urls import re_path
|
from django.urls import re_path
|
||||||
from . import consumers
|
from . import consumers
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
logger.debug("Configuring WebSocket routing patterns")
|
||||||
|
|
||||||
websocket_urlpatterns = [
|
websocket_urlpatterns = [
|
||||||
re_path(r'ws/game/$', consumers.GameConsumer.as_asgi()),
|
re_path(r'ws/game/$', consumers.GameConsumer.as_asgi(), name='game_ws'),
|
||||||
|
re_path(r'ws/chat/(?P<room_name>\w+)/$', consumers.ChatConsumer.as_asgi()),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
logger.info("WebSocket routing patterns configured successfully")
|
||||||
|
|||||||
@ -1,60 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Tournament Brackets</title>
|
|
||||||
<style>
|
|
||||||
.tournament-bracket {
|
|
||||||
display: flex;
|
|
||||||
padding: 20px;
|
|
||||||
font-family: Arial, sans-serif;
|
|
||||||
overflow-x: auto;
|
|
||||||
}
|
|
||||||
.round {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: space-around;
|
|
||||||
margin-right: 40px;
|
|
||||||
}
|
|
||||||
.match {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
.player {
|
|
||||||
width: 150px;
|
|
||||||
height: 30px;
|
|
||||||
line-height: 30px;
|
|
||||||
background-color: #000000;
|
|
||||||
border: 1px solid #ffffff;
|
|
||||||
margin: 2px 0;
|
|
||||||
padding: 0 10px;
|
|
||||||
white-space: nowrap;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
|
||||||
.player.winner {
|
|
||||||
background-color: #00ff3c;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="tournament-bracket">
|
|
||||||
{% for round in tournament_rounds %}
|
|
||||||
<div class="round">
|
|
||||||
{% for match in round %}
|
|
||||||
<div class="match">
|
|
||||||
<div class="player {% if match.winner == match.player1 %}winner{% endif %}">
|
|
||||||
{{ match.player1 }}
|
|
||||||
</div>
|
|
||||||
<div class="player {% if match.winner == match.player2 %}winner{% endif %}">
|
|
||||||
{{ match.player2|default:"BYE" }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@ -1,20 +1,10 @@
|
|||||||
<!-- pong/tournament_waiting_room.html -->
|
<!-- templates/tournament_waiting_room.html -->
|
||||||
<div class="tournament-waiting-room">
|
<div class="tournament-waiting-room">
|
||||||
<h2>Tournament Waiting Room</h2>
|
<h2>Tournament Waiting Room</h2>
|
||||||
|
<p>Players currently waiting: {{ players|length }}</p>
|
||||||
<p>Players currently waiting: {{ players_count }}</p>
|
|
||||||
<p>Minimum players needed to start: {{ min_players_to_start }}</p>
|
|
||||||
|
|
||||||
<h3>Players:</h3>
|
|
||||||
<ul>
|
<ul>
|
||||||
{% for player in players %}
|
{% for player in players %}
|
||||||
<li>{{ player }}</li>
|
<li>{{ player }}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{% if players_count >= min_players_to_start %}
|
|
||||||
<button id="start-tournament-btn">Start Tournament</button>
|
|
||||||
{% else %}
|
|
||||||
<p>Waiting for more players to join...</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
@ -1,224 +1,49 @@
|
|||||||
# /pong/game/tournament.py
|
# /pong/game/tournament.py
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import asyncio
|
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
import random
|
import logging
|
||||||
from .matchmaking import match_maker
|
|
||||||
from .game import Game
|
|
||||||
from .models import Tournoi
|
|
||||||
from .utils import create_tournament, update_tournament, getlen
|
|
||||||
from asgiref.sync import sync_to_async
|
|
||||||
|
|
||||||
TOURNAMENT_NAMES = [
|
logger = logging.getLogger(__name__)
|
||||||
"Champion's Clash", "Ultimate Showdown", "Battle Royale",
|
|
||||||
"Victory's Cup", "Legends Tournament", "Elite Series", "Clash of 42",
|
|
||||||
"Shibuya Incident", "Cunning Game", "Elite of the Stars", "Chaku's Disciples"
|
|
||||||
]
|
|
||||||
|
|
||||||
class TournamentMatch(Game):
|
|
||||||
def __init__(self, game_id, player1, player2, tournament):
|
|
||||||
# Initialize the parent Game class with the provided parameters
|
|
||||||
super().__init__(game_id, player1, player2, False)
|
|
||||||
# Store the current game instance in active games
|
|
||||||
match_maker.active_games[game_id] = self
|
|
||||||
# Store the tournament instance
|
|
||||||
self.tournament = tournament
|
|
||||||
|
|
||||||
async def end_game(self, disconnected_player=None):
|
|
||||||
# Call the parent class's end_game method
|
|
||||||
await super().end_game(disconnected_player)
|
|
||||||
# Handle the end of the match in the tournament context
|
|
||||||
await self.tournament.handle_match_end(self)
|
|
||||||
if self.game_id in match_maker.active_games:
|
|
||||||
del match_maker.active_games[self.game_id]
|
|
||||||
|
|
||||||
class TournamentMatchMaker:
|
class TournamentMatchMaker:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.waiting_players = []
|
self.waiting_players = []
|
||||||
self.matches = []
|
logger.debug("TournamentMatchMaker initialized with an empty waiting_players list")
|
||||||
self.rounds = []
|
|
||||||
self.current_round = 0
|
|
||||||
self.games = 0
|
|
||||||
self.tournament_state = "waiting" #Can be "waiting", "in_progress", or "ended"
|
|
||||||
self.name = random.choice(TOURNAMENT_NAMES)
|
|
||||||
self.final_name = ""
|
|
||||||
self.tournoi_reg = None
|
|
||||||
|
|
||||||
async def add_player(self, player):
|
async def add_player(self, player):
|
||||||
if self.tournament_state == "waiting" and player not in self.waiting_players:
|
if player not in self.waiting_players:
|
||||||
self.waiting_players.append(player)
|
self.waiting_players.append(player)
|
||||||
if player:
|
logger.info(f"User {player.user.username} added to the TOURNAMENT WAITING ROOM")
|
||||||
print(f"User {player.user.username} joins the TOURNAMENT WAITING ROOM")
|
|
||||||
else:
|
|
||||||
print("BOT joins the TOURNAMENT WAITING ROOM")
|
|
||||||
await self.update_waiting_room()
|
await self.update_waiting_room()
|
||||||
|
else:
|
||||||
async def update_waiting_room(self):
|
logger.warning(f"User {player.user.username} is already in the TOURNAMENT WAITING ROOM")
|
||||||
html = self.generate_waiting_room_html()
|
|
||||||
for player in self.waiting_players:
|
|
||||||
await self.send_to_player(player, {
|
|
||||||
'type': 'update_tournament_waiting_room',
|
|
||||||
'html': html
|
|
||||||
})
|
|
||||||
|
|
||||||
def generate_waiting_room_html(self):
|
|
||||||
context = {
|
|
||||||
'players': [player.user.username if player else 'BYE' for player in self.waiting_players],
|
|
||||||
'tournament_state': self.tournament_state,
|
|
||||||
'players_count': len(self.waiting_players),
|
|
||||||
'min_players_to_start': 3 # You can adjust this number as needed
|
|
||||||
}
|
|
||||||
return render_to_string('pong/tournament_waiting_room.html', context)
|
|
||||||
|
|
||||||
async def send_to_player(self, player, data):
|
|
||||||
if player:
|
|
||||||
await player.send(json.dumps(data))
|
|
||||||
|
|
||||||
async def remove_player(self, player):
|
async def remove_player(self, player):
|
||||||
if player in self.waiting_players:
|
if player in self.waiting_players:
|
||||||
self.waiting_players.remove(player)
|
self.waiting_players.remove(player)
|
||||||
|
logger.info(f"User {player.user.username} removed from the TOURNAMENT WAITING ROOM")
|
||||||
await self.update_waiting_room()
|
await self.update_waiting_room()
|
||||||
|
else:
|
||||||
|
logger.warning(f"Attempt to remove non-existent user {player.user.username} from the TOURNAMENT WAITING ROOM")
|
||||||
|
|
||||||
# Tournament start method
|
async def update_waiting_room(self):
|
||||||
async def start_tournament(self):
|
logger.debug("Updating TOURNAMENT WAITING ROOM")
|
||||||
if len(self.waiting_players) < 3:
|
html = self.generate_waiting_room_html()
|
||||||
return False
|
|
||||||
random.shuffle(self.waiting_players)
|
|
||||||
'''if (len(self.waiting_players) % 2) != 0:
|
|
||||||
print("Adding a BYE to the tournament..")
|
|
||||||
await self.add_player(None)'''
|
|
||||||
self.tournament_state = "in_progress"
|
|
||||||
self.current_round = 0
|
|
||||||
len_tournament = await sync_to_async(getlen)()
|
|
||||||
self.final_name = self.name + " #" + str(len_tournament + 1)
|
|
||||||
self.tournoi_reg = await sync_to_async(create_tournament)(self.final_name, len(self.waiting_players))
|
|
||||||
await self.advance_tournament()
|
|
||||||
return True
|
|
||||||
|
|
||||||
async def advance_tournament(self):
|
|
||||||
players = self.waiting_players
|
|
||||||
while len(players) > 1:
|
|
||||||
self.current_round += 1
|
|
||||||
print(f"Starting round {self.current_round} with {len(players)} players")
|
|
||||||
await self.create_matches(players)
|
|
||||||
await self.update_brackets()
|
|
||||||
await self.start_round_matches()
|
|
||||||
# Wait for all matches in the current round to finish
|
|
||||||
current_round_matches = self.rounds[-1]
|
|
||||||
while not all(match.ended for match in current_round_matches):
|
|
||||||
await asyncio.sleep(1) # Wait for 1 second before checking again
|
|
||||||
# Get winners for the next round
|
|
||||||
players = self.get_round_winners()
|
|
||||||
print(f"Round {self.current_round} finished. {len(players)} players advancing.")
|
|
||||||
# Tournament has ended
|
|
||||||
await self.update_brackets()
|
|
||||||
await self.end_tournament(players[0] if players else None)
|
|
||||||
|
|
||||||
async def create_matches(self, players):
|
|
||||||
matches = []
|
|
||||||
for i in range(0, len(players), 2):
|
|
||||||
self.games += 1
|
|
||||||
if i + 1 < len(players):
|
|
||||||
# Create a new instance of TournamentMatch for this round
|
|
||||||
match = TournamentMatch(self.games, players[i], players[i + 1], self)
|
|
||||||
matches.append(match)
|
|
||||||
else:
|
|
||||||
# Create a BYE match where the second player is None
|
|
||||||
match = TournamentMatch(self.games, players[i], None, self) # BYE match
|
|
||||||
matches.append(match)
|
|
||||||
|
|
||||||
# Assign the new match instance to the players
|
|
||||||
if players[i]:
|
|
||||||
await players[i].set_game(match)
|
|
||||||
if i + 1 < len(players):
|
|
||||||
if players[i + 1]:
|
|
||||||
await players[i + 1].set_game(match)
|
|
||||||
|
|
||||||
self.rounds.append(matches)
|
|
||||||
self.matches.extend(matches)
|
|
||||||
|
|
||||||
async def update_brackets(self):
|
|
||||||
html = self.generate_bracket_html()
|
|
||||||
for player in self.waiting_players:
|
for player in self.waiting_players:
|
||||||
await self.send_to_player(player, {
|
await player.send(json.dumps({
|
||||||
'type': 'update_brackets',
|
'type': 'update_waiting_room',
|
||||||
'html': html
|
'html': html
|
||||||
})
|
}))
|
||||||
|
logger.info("TOURNAMENT WAITING ROOM updated and sent to all players")
|
||||||
|
|
||||||
def generate_bracket_html(self):
|
def generate_waiting_room_html(self):
|
||||||
|
logger.debug("Generating TOURNAMENT WAITING ROOM HTML")
|
||||||
context = {
|
context = {
|
||||||
'tournament_rounds': self.get_tournament_data()
|
'players': [player.user.username for player in self.waiting_players]
|
||||||
}
|
}
|
||||||
return render_to_string('pong/tournament_brackets.html', context)
|
html = render_to_string('pong/tournament_waiting_room.html', context)
|
||||||
|
logger.info("TOURNAMENT WAITING ROOM HTML generated successfully")
|
||||||
def get_tournament_data(self):
|
return html
|
||||||
return [
|
|
||||||
[
|
|
||||||
{
|
|
||||||
'player1': match.player1.user.username if match.player1 else 'BYE',
|
|
||||||
'player2': match.player2.user.username if match.player2 else 'BYE',
|
|
||||||
'winner': match.game_state['player1_name'] if match.game_state['player1_score'] > match.game_state['player2_score'] else match.game_state['player2_name'] if match.ended else None,
|
|
||||||
'score1': match.game_state['player1_score'],
|
|
||||||
'score2': match.game_state['player2_score']
|
|
||||||
}
|
|
||||||
for match in round_matches
|
|
||||||
]
|
|
||||||
for round_matches in self.rounds
|
|
||||||
]
|
|
||||||
|
|
||||||
async def start_round_matches(self):
|
|
||||||
print(f"Starting TOURNAMENT round #{self.current_round}")
|
|
||||||
for match in self.rounds[-1]:
|
|
||||||
if match.player1 and match.player2:
|
|
||||||
await match_maker.notify_players(match.player1, match.player2, match.game_id, False)
|
|
||||||
asyncio.create_task(match.start_game())
|
|
||||||
elif match.player1:
|
|
||||||
# Handle BYE match
|
|
||||||
await match_maker.notify_players(match.player1, match.player2, match.game_id, False)
|
|
||||||
#asyncio.create_task(match.start_game())
|
|
||||||
match.game_state['player1_score'] = 3
|
|
||||||
match.game_state['player2_score'] = 0
|
|
||||||
await match.end_game()
|
|
||||||
await self.send_game_text(match.player1, "You lucky bastard! You got an auto-win!")
|
|
||||||
|
|
||||||
async def send_game_text(self, player, text):
|
|
||||||
message = json.dumps({
|
|
||||||
'type': 'game_text_update',
|
|
||||||
'game_text': text
|
|
||||||
})
|
|
||||||
await player.send(message)
|
|
||||||
|
|
||||||
def get_round_winners(self):
|
|
||||||
winners = []
|
|
||||||
for match in self.rounds[-1]:
|
|
||||||
if match.ended:
|
|
||||||
winner = match.player1 if match.game_state['player1_score'] > match.game_state['player2_score'] else match.player2
|
|
||||||
#if winner:
|
|
||||||
winners.append(winner)
|
|
||||||
return winners
|
|
||||||
|
|
||||||
async def end_tournament(self, winner):
|
|
||||||
self.tournament_state = "ended"
|
|
||||||
winner_username = winner.user.username if winner else "No winner"
|
|
||||||
print(f"The TOURNAMENT winner is {winner_username}")
|
|
||||||
for player in self.waiting_players:
|
|
||||||
await self.send_to_player(player, {
|
|
||||||
'type': 'tournament_end',
|
|
||||||
'winner': winner_username
|
|
||||||
})
|
|
||||||
|
|
||||||
await sync_to_async(update_tournament)(self.final_name, winner_username)
|
|
||||||
# Reset tournament state
|
|
||||||
self.waiting_players = []
|
|
||||||
self.matches = []
|
|
||||||
self.rounds = []
|
|
||||||
self.current_round = 0
|
|
||||||
self.games = 0
|
|
||||||
self.tournament_state = "waiting"
|
|
||||||
|
|
||||||
async def handle_match_end(self, match):
|
|
||||||
await self.update_brackets()
|
|
||||||
|
|
||||||
# Instance of the class
|
# Instance of the class
|
||||||
tournament_match_maker = TournamentMatchMaker()
|
tournament_match_maker = TournamentMatchMaker()
|
||||||
@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from . import views
|
from . import views
|
||||||
from rest_framework.routers import DefaultRouter
|
#from rest_framework.routers import DefaultRouter
|
||||||
from .views import match_list_json, player_list_json, tournoi_list_json
|
from .views import match_list_json, player_list_json, tournoi_list_json
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
path('check_user_exists/', views.check_user_exists, name='check_user_exists'),
|
path('check_user_exists/', views.check_user_exists, name='check_user_exists'),
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
from .models import Player, Tournoi, Match
|
from .models import Player, Tournoi, Match
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
@ -5,55 +6,62 @@ from django.db.models import Max, Sum, F
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from channels.db import database_sync_to_async
|
from channels.db import database_sync_to_async
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def handle_game_data(p1, p2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament):
|
def handle_game_data(p1, p2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament):
|
||||||
|
logger.info(f"Handling game data for players: {p1} vs {p2}")
|
||||||
try:
|
try:
|
||||||
player_1 = get_or_create_player(p1)
|
player_1 = get_or_create_player(p1)
|
||||||
player_2 = get_or_create_player(p2)
|
player_2 = get_or_create_player(p2)
|
||||||
|
logger.debug(f"Players created or retrieved: {player_1}, {player_2}")
|
||||||
|
|
||||||
print("CHAKU & THEOUCHE are the BEST")
|
|
||||||
create_match(player_1, player_2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament)
|
create_match(player_1, player_2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament)
|
||||||
print("and ADRIANO is the PEST")
|
logger.info("Match created successfully")
|
||||||
|
|
||||||
update_player_statistics(p1)
|
update_player_statistics(p1)
|
||||||
update_player_statistics(p2)
|
update_player_statistics(p2)
|
||||||
|
logger.info("Player statistics updated")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error in endfortheouche: {e}")
|
logger.error(f"Error in handle_game_data: {e}")
|
||||||
|
|
||||||
def get_player_by_name(name):
|
def get_player_by_name(name):
|
||||||
|
logger.debug(f"Checking if player exists with name: {name}")
|
||||||
exists = Player.objects.filter(name=name).exists()
|
exists = Player.objects.filter(name=name).exists()
|
||||||
|
logger.debug(f"Player exists: {exists}")
|
||||||
return exists
|
return exists
|
||||||
|
|
||||||
|
|
||||||
def get_player(name):
|
def get_player(name):
|
||||||
|
logger.debug(f"Retrieving player with name: {name}")
|
||||||
return Player.objects.get(name=name)
|
return Player.objects.get(name=name)
|
||||||
|
|
||||||
|
|
||||||
def get_or_create_player(name):
|
def get_or_create_player(name):
|
||||||
|
logger.info(f"Getting or creating player with name: {name}")
|
||||||
player_exists = get_player_by_name(name)
|
player_exists = get_player_by_name(name)
|
||||||
if not player_exists:
|
if not player_exists:
|
||||||
player = create_player(name)
|
player = create_player(name)
|
||||||
|
logger.info(f"Player created: {player}")
|
||||||
return player
|
return player
|
||||||
else:
|
else:
|
||||||
player = get_player(name)
|
player = get_player(name)
|
||||||
|
logger.info(f"Player retrieved: {player}")
|
||||||
return player
|
return player
|
||||||
|
|
||||||
|
|
||||||
def create_player(
|
def create_player(
|
||||||
name,
|
name,
|
||||||
total_match=0,
|
total_match=0,
|
||||||
total_win=0,
|
total_win=0,
|
||||||
p_win= None,
|
p_win=None,
|
||||||
m_score_match= None,
|
m_score_match=None,
|
||||||
m_score_adv_match= None,
|
m_score_adv_match=None,
|
||||||
best_score=0,
|
best_score=0,
|
||||||
m_nbr_ball_touch= None,
|
m_nbr_ball_touch=None,
|
||||||
total_duration= None,
|
total_duration=None,
|
||||||
m_duration= None,
|
m_duration=None,
|
||||||
num_participated_tournaments=0,
|
num_participated_tournaments=0,
|
||||||
num_won_tournaments=0
|
num_won_tournaments=0
|
||||||
):
|
):
|
||||||
|
logger.info(f"Creating player: {name}")
|
||||||
player = Player(
|
player = Player(
|
||||||
name=name,
|
name=name,
|
||||||
total_match=total_match,
|
total_match=total_match,
|
||||||
@ -69,14 +77,18 @@ def create_player(
|
|||||||
num_won_tournaments=num_won_tournaments
|
num_won_tournaments=num_won_tournaments
|
||||||
)
|
)
|
||||||
player.save()
|
player.save()
|
||||||
|
logger.info(f"Player {name} saved successfully")
|
||||||
return player
|
return player
|
||||||
|
|
||||||
def create_tournoi(name, nbr_player, date, winner):
|
def create_tournoi(name, nbr_player, date, winner):
|
||||||
|
logger.info(f"Creating tournament: {name}")
|
||||||
tournoi = Tournoi(name=name, nbr_player=nbr_player, date=date, winner=winner)
|
tournoi = Tournoi(name=name, nbr_player=nbr_player, date=date, winner=winner)
|
||||||
tournoi.save()
|
tournoi.save()
|
||||||
|
logger.info(f"Tournament {name} saved successfully")
|
||||||
return tournoi
|
return tournoi
|
||||||
|
|
||||||
def create_match(player1, player2, score_player1, score_player2, nbr_ball_touch_p1, nbr_ball_touch_p2, duration, is_tournoi, tournoi):
|
def create_match(player1, player2, score_player1, score_player2, nbr_ball_touch_p1, nbr_ball_touch_p2, duration, is_tournoi, tournoi):
|
||||||
|
logger.info(f"Creating match between {player1.name} and {player2.name}")
|
||||||
match = Match(
|
match = Match(
|
||||||
player1=player1,
|
player1=player1,
|
||||||
player2=player2,
|
player2=player2,
|
||||||
@ -97,9 +109,11 @@ def create_match(player1, player2, score_player1, score_player2, nbr_ball_touch_
|
|||||||
match.winner = None
|
match.winner = None
|
||||||
|
|
||||||
match.save()
|
match.save()
|
||||||
|
logger.info(f"Match saved successfully with winner: {match.winner.name if match.winner else 'None'}")
|
||||||
return match
|
return match
|
||||||
|
|
||||||
def update_player_statistics(player_name):
|
def update_player_statistics(player_name):
|
||||||
|
logger.info(f"Updating statistics for player: {player_name}")
|
||||||
player = get_object_or_404(Player, name=player_name)
|
player = get_object_or_404(Player, name=player_name)
|
||||||
|
|
||||||
matches_as_player1 = Match.objects.filter(player1=player)
|
matches_as_player1 = Match.objects.filter(player1=player)
|
||||||
@ -107,8 +121,8 @@ def update_player_statistics(player_name):
|
|||||||
|
|
||||||
total_match = matches_as_player1.count() + matches_as_player2.count()
|
total_match = matches_as_player1.count() + matches_as_player2.count()
|
||||||
|
|
||||||
# avoid dividing by 0
|
|
||||||
if total_match == 0:
|
if total_match == 0:
|
||||||
|
logger.warning(f"No matches found for player: {player_name}")
|
||||||
player.total_match = total_match
|
player.total_match = total_match
|
||||||
player.total_win = 0
|
player.total_win = 0
|
||||||
player.p_win = 0
|
player.p_win = 0
|
||||||
@ -121,6 +135,7 @@ def update_player_statistics(player_name):
|
|||||||
player.num_participated_tournaments = 0
|
player.num_participated_tournaments = 0
|
||||||
player.num_won_tournaments = 0
|
player.num_won_tournaments = 0
|
||||||
player.save()
|
player.save()
|
||||||
|
logger.info(f"Player statistics reset for {player_name}")
|
||||||
return
|
return
|
||||||
|
|
||||||
won_matches = Match.objects.filter(winner=player)
|
won_matches = Match.objects.filter(winner=player)
|
||||||
@ -169,30 +184,9 @@ def update_player_statistics(player_name):
|
|||||||
#player.num_won_tournaments = total_win_tourn
|
#player.num_won_tournaments = total_win_tourn
|
||||||
|
|
||||||
player.save()
|
player.save()
|
||||||
|
logger.info(f"Statistics updated for player: {player_name}")
|
||||||
|
|
||||||
def get_player_p_win(player_name):
|
def get_player_p_win(player_name):
|
||||||
|
logger.debug(f"Getting win percentage for player: {player_name}")
|
||||||
player = get_object_or_404(Player, name=player_name)
|
player = get_object_or_404(Player, name=player_name)
|
||||||
return player.p_win
|
return player.p_win
|
||||||
|
|
||||||
def create_tournament(name, nbr_player):
|
|
||||||
print("tournoi created!!!")
|
|
||||||
tournoi=Tournoi(name=name, nbr_player=nbr_player, winner=None)
|
|
||||||
tournoi.save()
|
|
||||||
print(f"tournoi name : {tournoi.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
|
||||||
return tournoi
|
|
||||||
|
|
||||||
def update_tournament(name_tournoi, winner_name):
|
|
||||||
tournoi = get_object_or_404(Tournoi, name=name_tournoi)
|
|
||||||
winner_p = get_object_or_404(Player, name=winner_name)
|
|
||||||
print(f"in update tourna - tournoi name : {tournoi.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
|
||||||
print(f"in update tourna - winner is : {winner_p.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
|
||||||
|
|
||||||
tournoi.winner = winner_p
|
|
||||||
print(f"in update tourna - TOURNOI winner is : {tournoi.winner.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
|
||||||
tournoi.save()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getlen():
|
|
||||||
return Tournoi.objects.count()
|
|
||||||
|
|||||||
@ -9,65 +9,111 @@ from django.contrib.auth.models import User
|
|||||||
from django.contrib.auth import authenticate
|
from django.contrib.auth import authenticate
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
from django.db import transaction, IntegrityError
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
|
logger.info("Accessing index view")
|
||||||
return render(request, 'index.html')
|
return render(request, 'index.html')
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def check_user_exists(request):
|
def check_user_exists(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
logger.info("POST request received for checking user existence")
|
||||||
data = json.loads(request.body)
|
data = json.loads(request.body)
|
||||||
username = data.get('username')
|
username = data.get('username')
|
||||||
if User.objects.filter(username=username).exists():
|
if User.objects.filter(username=username).exists():
|
||||||
|
logger.info(f"User {username} exists")
|
||||||
return JsonResponse({'exists': True})
|
return JsonResponse({'exists': True})
|
||||||
|
logger.info(f"User {username} does not exist")
|
||||||
return JsonResponse({'exists': False})
|
return JsonResponse({'exists': False})
|
||||||
|
logger.warning("Invalid request method for check_user_exists")
|
||||||
return JsonResponse({'error': 'Invalid request method'}, status=400)
|
return JsonResponse({'error': 'Invalid request method'}, status=400)
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def register_user(request):
|
def register_user(request):
|
||||||
if request.method == 'POST':
|
|
||||||
data = json.loads(request.body)
|
|
||||||
username = data.get('username')
|
|
||||||
password = data.get('password')
|
|
||||||
if not User.objects.filter(username=username).exists():
|
|
||||||
user = User.objects.create_user(username=username, password=password)
|
|
||||||
token = get_or_create_token(user)
|
|
||||||
return JsonResponse({'registered': True, 'token': token})
|
|
||||||
return JsonResponse({'registered': False, 'error': 'User already exists'})
|
|
||||||
return JsonResponse({'error': 'Invalid request method'}, status=400)
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
def authenticate_user(request):
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
try:
|
try:
|
||||||
|
logger.info("Received POST request for user registration")
|
||||||
data = json.loads(request.body)
|
data = json.loads(request.body)
|
||||||
username = data.get('username', '')
|
username = data.get('username')
|
||||||
password = data.get('password', '')
|
password = data.get('password')
|
||||||
user = authenticate(username=username, password=password)
|
|
||||||
if user is not None:
|
logger.info(f"Attempting to register user: {username}")
|
||||||
|
|
||||||
|
if not username or not password:
|
||||||
|
logger.warning("Username or password not provided")
|
||||||
|
return JsonResponse({'registered': False, 'error': 'Username and password are required'}, status=400)
|
||||||
|
|
||||||
|
with transaction.atomic():
|
||||||
|
user_exists = User.objects.select_for_update().filter(username=username).exists()
|
||||||
|
|
||||||
|
if user_exists:
|
||||||
|
logger.warning(f"User {username} already exists")
|
||||||
|
return JsonResponse({'registered': False, 'error': 'User already exists'}, status=409)
|
||||||
|
|
||||||
|
user = User.objects.create_user(username=username, password=password)
|
||||||
token = get_or_create_token(user)
|
token = get_or_create_token(user)
|
||||||
return JsonResponse({'authenticated': True, 'token': token, 'user_id': user.id})
|
logger.info(f"User {username} registered successfully")
|
||||||
else:
|
return JsonResponse({'registered': True, 'token': token})
|
||||||
return JsonResponse({'authenticated': False}, status=401)
|
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
logger.error(f"JSON decode error: {str(e)}")
|
||||||
|
return JsonResponse({'error': 'Invalid JSON data'}, status=400)
|
||||||
|
|
||||||
|
except IntegrityError:
|
||||||
|
logger.error(f"IntegrityError: User {username} already exists")
|
||||||
|
return JsonResponse({'registered': False, 'error': 'User already exists'}, status=409)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JsonResponse({'error': str(e)}, status=500)
|
logger.error(f"Error in register_user: {str(e)}")
|
||||||
else:
|
return JsonResponse({'error': f'Internal Server Error: {str(e)}'}, status=500)
|
||||||
return JsonResponse({'error': 'Method not allowed'}, status=405)
|
|
||||||
|
logger.warning("Invalid request method for register_user")
|
||||||
|
return JsonResponse({'error': 'Invalid request method'}, status=405)
|
||||||
|
|
||||||
def get_or_create_token(user):
|
def get_or_create_token(user):
|
||||||
|
logger.info(f"Generating or retrieving token for user: {user.username}")
|
||||||
if not user.auth_token:
|
if not user.auth_token:
|
||||||
while True:
|
while True:
|
||||||
token = str(uuid.uuid4())
|
token = str(uuid.uuid4())
|
||||||
if not User.objects.filter(auth_token=token).exists():
|
if not User.objects.filter(auth_token=token).exists():
|
||||||
user.auth_token = token
|
user.auth_token = token
|
||||||
user.save()
|
user.save()
|
||||||
|
logger.info(f"Token generated for user {user.username}: {token}")
|
||||||
break
|
break
|
||||||
return user.auth_token
|
return user.auth_token
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
def authenticate_user(request):
|
||||||
|
if request.method == 'POST':
|
||||||
|
try:
|
||||||
|
logger.info("Received POST request for user authentication")
|
||||||
|
data = json.loads(request.body)
|
||||||
|
username = data.get('username', '')
|
||||||
|
password = data.get('password', '')
|
||||||
|
user = authenticate(username=username, password=password)
|
||||||
|
if user is not None:
|
||||||
|
token = get_or_create_token(user)
|
||||||
|
logger.info(f"User {username} authenticated successfully")
|
||||||
|
return JsonResponse({'authenticated': True, 'token': token, 'user_id': user.id})
|
||||||
|
else:
|
||||||
|
logger.warning(f"Authentication failed for user {username}")
|
||||||
|
return JsonResponse({'authenticated': False}, status=401)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error in authenticate_user: {str(e)}")
|
||||||
|
return JsonResponse({'error': str(e)}, status=500)
|
||||||
|
else:
|
||||||
|
logger.warning("Invalid request method for authenticate_user")
|
||||||
|
return JsonResponse({'error': 'Method not allowed'}, status=405)
|
||||||
|
|
||||||
def match_list_json(request):
|
def match_list_json(request):
|
||||||
|
logger.info("Fetching match list")
|
||||||
matches = Match.objects.all()
|
matches = Match.objects.all()
|
||||||
data = {
|
data = {
|
||||||
'matches': list(matches.values(
|
'matches': list(matches.values(
|
||||||
@ -76,9 +122,11 @@ def match_list_json(request):
|
|||||||
'is_tournoi', 'tournoi__name'
|
'is_tournoi', 'tournoi__name'
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
logger.info(f"Match list fetched successfully: {len(data['matches'])} matches found")
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
def player_list_json(request):
|
def player_list_json(request):
|
||||||
|
logger.info("Fetching player list")
|
||||||
players = Player.objects.all()
|
players = Player.objects.all()
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
@ -89,25 +137,30 @@ def player_list_json(request):
|
|||||||
'num_participated_tournaments', 'num_won_tournaments'
|
'num_participated_tournaments', 'num_won_tournaments'
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
logger.info(f"Player list fetched successfully: {len(data['players'])} players found")
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
def get_tournoi_data(tournoi):
|
def tournoi_list_json(request):
|
||||||
return {
|
logger.info("Fetching tournoi list")
|
||||||
"id": tournoi.id,
|
tournois = Tournoi.objects.all()
|
||||||
"name": tournoi.name,
|
|
||||||
"nbr_player": tournoi.nbr_player,
|
data = {
|
||||||
"date": tournoi.date,
|
'tournois': list(tournois.values(
|
||||||
"winner": {
|
'id', 'name', 'nbr_player', 'date', 'winner'
|
||||||
"id": tournoi.winner.id,
|
))
|
||||||
"name": tournoi.winner.name
|
|
||||||
} if tournoi.winner else None
|
|
||||||
}
|
}
|
||||||
|
logger.info(f"Tournoi list fetched successfully: {len(data['tournois'])} tournois found")
|
||||||
|
return JsonResponse(data)
|
||||||
|
|
||||||
def tournoi_list_json(request):
|
def tournoi_list_json(request):
|
||||||
tournois = Tournoi.objects.select_related('winner').all() # Charge les données du gagnant
|
tournois = Tournoi.objects.all()
|
||||||
tournois_data = [get_tournoi_data(tournoi) for tournoi in tournois]
|
|
||||||
return JsonResponse({"tournois": tournois_data})
|
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'tournois': list(tournois.values(
|
||||||
|
'id', 'name', 'nbr_player', 'date', 'winner'
|
||||||
|
))
|
||||||
|
}
|
||||||
|
return JsonResponse(data)
|
||||||
|
|
||||||
from web3 import Web3
|
from web3 import Web3
|
||||||
|
|
||||||
@ -173,4 +226,3 @@ def write_data(request):
|
|||||||
# tx_receipt = web3.eth.wait_for_transaction_receipt(tx_hash)
|
# tx_receipt = web3.eth.wait_for_transaction_receipt(tx_hash)
|
||||||
# print("Transaction receipt:", tx_receipt)
|
# print("Transaction receipt:", tx_receipt)
|
||||||
print("-----------------------------")
|
print("-----------------------------")
|
||||||
|
|
||||||
|
|||||||
220
pong/settings.py
@ -29,43 +29,43 @@ ALLOWED_HOSTS = ['*']
|
|||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'channels',
|
'channels',
|
||||||
'pong.game',
|
'pong.game',
|
||||||
'rest_framework'
|
'rest_framework'
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'pong.urls'
|
ROOT_URLCONF = 'pong.urls'
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [os.path.join(BASE_DIR, 'pong', 'static')], # Ensure templates are found
|
'DIRS': [os.path.join(BASE_DIR, 'pong', 'static')], # Ensure templates are found
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
'django.template.context_processors.debug',
|
'django.template.context_processors.debug',
|
||||||
'django.template.context_processors.request',
|
'django.template.context_processors.request',
|
||||||
'django.contrib.auth.context_processors.auth',
|
'django.contrib.auth.context_processors.auth',
|
||||||
'django.contrib.messages.context_processors.messages',
|
'django.contrib.messages.context_processors.messages',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
ASGI_APPLICATION = 'pong.asgi.application'
|
ASGI_APPLICATION = 'pong.asgi.application'
|
||||||
@ -74,32 +74,32 @@ ASGI_APPLICATION = 'pong.asgi.application'
|
|||||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.postgresql',
|
'ENGINE': 'django.db.backends.postgresql',
|
||||||
'NAME': os.getenv('DB_NAME'),
|
'NAME': os.getenv('DB_NAME'),
|
||||||
'USER': os.getenv('DB_USER'),
|
'USER': os.getenv('DB_USER'),
|
||||||
'PASSWORD': os.getenv('DB_PASSWORD'),
|
'PASSWORD': os.getenv('DB_PASSWORD'),
|
||||||
'HOST': os.getenv('DB_HOST'),
|
'HOST': os.getenv('DB_HOST'),
|
||||||
'PORT': '5432',
|
'PORT': '5432',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
@ -115,10 +115,6 @@ USE_L10N = True
|
|||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
|
||||||
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'pong/static')]
|
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'pong/static')]
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||||
@ -130,43 +126,87 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|||||||
|
|
||||||
# Channels
|
# Channels
|
||||||
# Define the channel layers for WebSockets
|
# Define the channel layers for WebSockets
|
||||||
|
# Define the channel layers for WebSockets
|
||||||
CHANNEL_LAYERS = {
|
CHANNEL_LAYERS = {
|
||||||
'default': {
|
'default': {
|
||||||
'BACKEND': 'channels.layers.InMemoryChannelLayer',
|
'BACKEND': 'channels.layers.InMemoryChannelLayer',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
'''LOGGING = {
|
LOGGING = {
|
||||||
'version': 1, # The version of the logging configuration schema
|
'version': 1,
|
||||||
'disable_existing_loggers': False, # Allows existing loggers to keep logging
|
'disable_existing_loggers': False,
|
||||||
'formatters': { # Defines how log messages will be formatted
|
'formatters': {
|
||||||
'json': {
|
'json': {
|
||||||
'()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
|
'()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
|
||||||
# Formatter that outputs logs in JSON format, which is ideal for ingestion by Logstash.
|
'format': '%(asctime)s %(levelname)s %(name)s %(module)s %(process)d %(thread)d %(message)s',
|
||||||
},
|
},
|
||||||
'default': {
|
'default': {
|
||||||
'format': '[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s',
|
'format': '[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s',
|
||||||
# This is a basic text formatter with timestamp, log level, logger name, line number, and the actual message.
|
},
|
||||||
},
|
'verbose': {
|
||||||
},
|
'format': '[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s [%(process)d:%(thread)d]',
|
||||||
'handlers': { # Handlers determine where the log messages are sent
|
},
|
||||||
'file': {
|
'simple': {
|
||||||
'level': 'INFO', # Minimum log level to be handled (INFO and above)
|
'format': '%(levelname)s %(message)s',
|
||||||
'class': 'logging.FileHandler',
|
},
|
||||||
'filename': os.path.join(BASE_DIR, 'logs/django.log'), # The file where logs will be saved
|
},
|
||||||
'formatter': 'json', # Uses the JSON formatter defined above
|
'filters': {
|
||||||
},
|
'require_debug_true': {
|
||||||
'console': {
|
'()': 'django.utils.log.RequireDebugTrue',
|
||||||
'level': 'DEBUG', # Minimum log level to be handled (DEBUG and above)
|
},
|
||||||
'class': 'logging.StreamHandler',
|
'require_debug_false': {
|
||||||
'formatter': 'default', # Uses the default text formatter
|
'()': 'django.utils.log.RequireDebugFalse',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'loggers': { # Loggers are the actual log streams that get configured
|
'handlers': {
|
||||||
'django': { # The Django logger catches all messages sent by the Django framework
|
'file': {
|
||||||
'handlers': ['file', 'console'], # Sends logs to both the file and the console
|
'level': 'INFO',
|
||||||
'level': 'DEBUG', # Minimum log level to be logged
|
'class': 'logging.handlers.RotatingFileHandler',
|
||||||
'propagate': True, # If True, messages will be passed to the parent loggers as well
|
'filename': os.path.join(BASE_DIR, 'logs/django.log'),
|
||||||
},
|
'formatter': 'json',
|
||||||
},
|
'maxBytes': 1024 * 1024 * 5, # 5 MB
|
||||||
}'''
|
'backupCount': 5,
|
||||||
|
},
|
||||||
|
'error_file': {
|
||||||
|
'level': 'ERROR',
|
||||||
|
'class': 'logging.handlers.RotatingFileHandler',
|
||||||
|
'filename': os.path.join(BASE_DIR, 'logs/django_errors.log'),
|
||||||
|
'formatter': 'json',
|
||||||
|
'maxBytes': 1024 * 1024 * 5, # 5 MB
|
||||||
|
'backupCount': 5,
|
||||||
|
},
|
||||||
|
'console': {
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'class': 'logging.StreamHandler',
|
||||||
|
'formatter': 'verbose',
|
||||||
|
'filters': ['require_debug_true'],
|
||||||
|
},
|
||||||
|
'mail_admins': {
|
||||||
|
'level': 'ERROR',
|
||||||
|
'class': 'django.utils.log.AdminEmailHandler',
|
||||||
|
'filters': ['require_debug_false'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'loggers': {
|
||||||
|
'django': {
|
||||||
|
'handlers': ['file', 'console', 'mail_admins'],
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'propagate': True,
|
||||||
|
},
|
||||||
|
'django.request': {
|
||||||
|
'handlers': ['error_file', 'mail_admins'],
|
||||||
|
'level': 'ERROR',
|
||||||
|
'propagate': False,
|
||||||
|
},
|
||||||
|
'django.security': {
|
||||||
|
'handlers': ['error_file', 'mail_admins'],
|
||||||
|
'level': 'ERROR',
|
||||||
|
'propagate': False,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'root': {
|
||||||
|
'handlers': ['console', 'file'],
|
||||||
|
'level': 'INFO',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|||||||
@ -104,7 +104,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const matchListBody = document.querySelector('#match-list tbody');
|
const matchListBody = document.querySelector('#match-list tbody');
|
||||||
matchListBody.innerHTML = '';
|
matchListBody.innerHTML = '';
|
||||||
|
|
||||||
|
|
||||||
if (matches.length != 0) {
|
if (matches.length != 0) {
|
||||||
matches.forEach(match => {
|
matches.forEach(match => {
|
||||||
const row = document.createElement('tr');
|
const row = document.createElement('tr');
|
||||||
@ -125,7 +124,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
matchListBody.appendChild(row);
|
matchListBody.appendChild(row);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const row = document.createElement('tr');
|
|
||||||
row.innerHTML = `
|
row.innerHTML = `
|
||||||
<td colspan="12">No matches found.</td>
|
<td colspan="12">No matches found.</td>
|
||||||
`;
|
`;
|
||||||
@ -138,7 +136,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const playersListBody = document.querySelector('#player-list tbody');
|
const playersListBody = document.querySelector('#player-list tbody');
|
||||||
playersListBody.innerHTML = '';
|
playersListBody.innerHTML = '';
|
||||||
|
|
||||||
|
|
||||||
if (players.length != 0) {
|
if (players.length != 0) {
|
||||||
players.forEach(player => {
|
players.forEach(player => {
|
||||||
const row = document.createElement('tr');
|
const row = document.createElement('tr');
|
||||||
@ -160,9 +157,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
playersListBody.appendChild(row);
|
playersListBody.appendChild(row);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const row = document.createElement('tr');
|
|
||||||
row.innerHTML = `
|
row.innerHTML = `
|
||||||
<td colspan="12">No player found.</td>
|
<td colspan="12">No matches found.</td>
|
||||||
`
|
`
|
||||||
playersListBody.appendChild(row);
|
playersListBody.appendChild(row);
|
||||||
}
|
}
|
||||||
@ -175,22 +171,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
if (tournois.length != 0) {
|
if (tournois.length != 0) {
|
||||||
tournois.forEach(tournoi => {
|
tournois.forEach(tournoi => {
|
||||||
console.log('Winner:', tournoi.winner); //debug !!!!!!!!!!!!!!!!!
|
|
||||||
console.log('Winner:', tournoi.winner__name); //debug !!!!!!!!!!!!!!!!!
|
|
||||||
const row = document.createElement('tr');
|
const row = document.createElement('tr');
|
||||||
row.innerHTML = `
|
row.innerHTML = `
|
||||||
<td>${tournoi.id}</td>
|
<td>${tournoi.id}</td>
|
||||||
<td>${tournoi.name}</td>
|
<td>${tournoi.name}</td>
|
||||||
<td>${tournoi.nbr_player}</td>
|
<td>${tournoi.nbr_player}</td>
|
||||||
<td>${tournoi.date}</td>
|
<td>${tournoi.date}</td>
|
||||||
<td>${tournoi.winner ? tournoi.winner.name : 'No one yet ...'}</td>
|
<td>${tournoi.winner.name}</td>
|
||||||
`;
|
`;
|
||||||
tournoisListBody.appendChild(row);
|
tournoisListBody.appendChild(row);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const row = document.createElement('tr');
|
|
||||||
row.innerHTML = `
|
row.innerHTML = `
|
||||||
<td colspan="12">No tournoi found.</td>
|
<td colspan="12">No matches found.</td>
|
||||||
`
|
`
|
||||||
tournoisListBody.appendChild(row);
|
tournoisListBody.appendChild(row);
|
||||||
}
|
}
|
||||||
|
|||||||
0
pong/static/flags/de.svg
Executable file → Normal file
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
0
pong/static/flags/es.svg
Executable file → Normal file
|
Before Width: | Height: | Size: 415 KiB After Width: | Height: | Size: 415 KiB |
0
pong/static/flags/fr.svg
Executable file → Normal file
|
Before Width: | Height: | Size: 946 B After Width: | Height: | Size: 946 B |
0
pong/static/flags/it.svg
Executable file → Normal file
|
Before Width: | Height: | Size: 959 B After Width: | Height: | Size: 959 B |
0
pong/static/flags/us.svg
Executable file → Normal file
|
Before Width: | Height: | Size: 8.7 KiB After Width: | Height: | Size: 8.7 KiB |
1325
pong/static/game.js
@ -3,205 +3,279 @@
|
|||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Pong Game</title>
|
<title>Pong Game</title>
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'styles.css' %}?v=3">
|
<link rel="stylesheet" type="text/css" href="{% static 'styles.css' %}?v=3">
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
<img src="{% static 'logo-42-perpignan.png' %}" alt="Logo">
|
<img src="{% static 'logo-42-perpignan.png' %}" alt="Logo">
|
||||||
</div>
|
</div>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="language-switcher">
|
<div class="language-switcher">
|
||||||
<img id="lang-fr" src="{% static 'flags/fr.svg' %}" alt="Français">
|
<img id="lang-fr" src="{% static 'flags/fr.svg' %}" alt="Français">
|
||||||
<img id="lang-en" src="{% static 'flags/us.svg' %}" alt="English">
|
<img id="lang-en" src="{% static 'flags/us.svg' %}" alt="English">
|
||||||
<img id="lang-it" src="{% static 'flags/it.svg' %}" alt="Italiano">
|
<img id="lang-it" src="{% static 'flags/it.svg' %}" alt="Italiano">
|
||||||
<img id="lang-es" src="{% static 'flags/es.svg' %}" alt="Español">
|
<img id="lang-es" src="{% static 'flags/es.svg' %}" alt="Español">
|
||||||
<img id="lang-de" src="{% static 'flags/de.svg' %}" alt="Deutsch">
|
<img id="lang-de" src="{% static 'flags/de.svg' %}" alt="Deutsch">
|
||||||
</div>
|
</div>
|
||||||
<div class="background">
|
<div class="background">
|
||||||
<div class="stars" id="stars"></div>
|
<div class="stars" id="stars"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="pong-elements" style="display: flex;">
|
<div id="pong-elements" style="display: flex;">
|
||||||
<div class="paddle paddle-left"></div>
|
<div class="paddle paddle-left"></div>
|
||||||
<div class="paddle paddle-right"></div>
|
<div class="paddle paddle-right"></div>
|
||||||
<div class="ball_anim"></div>
|
<div class="ball_anim"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button id="settings-btn">⚙️ Réglages</button>
|
<button id="settings-btn">⚙️ Réglages</button>
|
||||||
<div id="settings-menu" style="display: none;">
|
<div id="settings-menu" style="display: none;">
|
||||||
<button id="close-settings">✖️</button>
|
<button id="close-settings">✖️</button>
|
||||||
<h2>Reglages</h2>
|
<h2>Reglages</h2>
|
||||||
<label for="color-picker">Couleur:</label>
|
<label for="color-picker">Couleur:</label>
|
||||||
<input type="color" id="color-picker">
|
<input type="color" id="color-picker">
|
||||||
<br>
|
<br>
|
||||||
<label for="font-selector">Police:</label>
|
<label for="font-selector">Police:</label>
|
||||||
<select id="font-selector">
|
<select id="font-selector">
|
||||||
<option value="Arial">Arial</option>
|
<option value="Arial">Arial</option>
|
||||||
<option value="Verdana">Verdana</option>
|
<option value="Verdana">Verdana</option>
|
||||||
<option value="Times New Roman">Times New Roman</option>
|
<option value="Times New Roman">Times New Roman</option>
|
||||||
<option value="Courier New">Courier New</option>
|
<option value="Courier New">Courier New</option>
|
||||||
</select>
|
</select>
|
||||||
<br>
|
<br>
|
||||||
<label for="font-size-slider">Taille:</label>
|
<label for="font-size-slider">Taille:</label>
|
||||||
<input type="range" id="font-size-slider" min="12" max="36" value="16">
|
<input type="range" id="font-size-slider" min="12" max="36" value="16">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="container" id="block-form">
|
<div class="container" id="block-form">
|
||||||
<h1 id="welcome">BIENVENUE DANS LE PONG 42</h1>
|
<h1 id="welcome">BIENVENUE DANS LE PONG 42</h1>
|
||||||
<div class="input-container">
|
<div class="input-container">
|
||||||
<div id="auth-form">
|
<div id="auth-form">
|
||||||
<label for="nickname" id="label-nickname">Enter your nickname:</label>
|
<label for="nickname" id="label-nickname">Enter your nickname:</label>
|
||||||
<input type="text" id="nickname" name="nickname">
|
<input type="text" id="nickname" name="nickname">
|
||||||
<button id="check-nickname">Check Nickname</button>
|
<button id="check-nickname">Check Nickname</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="register-form" style="display: none;">
|
<div id="register-form" style="display: none;">
|
||||||
<label for="password" id="label-password">Enter your password:</label>
|
<label for="password" id="label-password">Enter your password:</label>
|
||||||
<input type="password" id="password" name="password">
|
<input type="password" id="password" name="password">
|
||||||
<label for="confirm-password" id="label-confirm-password">Confirm your password:</label>
|
<label for="confirm-password" id="label-confirm-password">Confirm your password:</label>
|
||||||
<input type="password" id="confirm-password" name="confirm-password">
|
<input type="password" id="confirm-password" name="confirm-password">
|
||||||
<button id="register">Register</button>
|
<button id="register">Register</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="login-form" style="display: none;">
|
<div id="login-form" style="display: none;">
|
||||||
<label for="login-password" id="label-login-password">Enter your password:</label>
|
<label for="login-password" id="label-login-password">Enter your password:</label>
|
||||||
<input type="password" id="login-password" name="login-password">
|
<input type="password" id="login-password" name="login-password">
|
||||||
<button id="login">Login</button>
|
<button id="login">Login</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="post-form-buttons" style="display: none;">
|
<div id="post-form-buttons" style="display: none;">
|
||||||
<button id="local-game">Local Game</button>
|
<button id="local-game">Local Game</button>
|
||||||
<button id="quick-match">Quick Match</button>
|
<button id="quick-match">Quick Match</button>
|
||||||
<button id="tournament">Tournament</button>
|
<button id="tournament">Tournament</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="auth-form2" style="display: none;">
|
<div id="auth-form2" style="display: none;">
|
||||||
<label for="nickname" id="label-nickname2">Enter the second player's nickname:</label>
|
<label for="nickname" id="label-nickname2">Enter the second player's nickname:</label>
|
||||||
<input type="text" id="nickname2" name="nickname">
|
<input type="text" id="nickname2" name="nickname">
|
||||||
<button id="check-nickname2">Check Nickname</button>
|
<button id="check-nickname2">Check Nickname</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="register-form2" style="display: none;">
|
<div id="register-form2" style="display: none;">
|
||||||
<label for="password" id="label-password2">Enter the second player's password:</label>
|
<label for="password" id="label-password2">Enter the second player's password:</label>
|
||||||
<input type="password" id="password2" name="password">
|
<input type="password" id="password2" name="password">
|
||||||
<label for="confirm-password" id="label-confirm-password2">Confirm the second player's password:</label>
|
<label for="confirm-password" id="label-confirm-password2">Confirm the second player's password:</label>
|
||||||
<input type="password" id="confirm-password2" name="confirm-password">
|
<input type="password" id="confirm-password2" name="confirm-password">
|
||||||
<button id="register2">Register</button>
|
<button id="register2">Register</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="login-form2" style="display: none;">
|
<div id="login-form2" style="display: none;">
|
||||||
<label for="login-password" id="label-login-password2">Enter the second player's password:</label>
|
<label for="login-password" id="label-login-password2">Enter the second player's password:</label>
|
||||||
<input type="password" id="login-password2" name="login-password">
|
<input type="password" id="login-password2" name="login-password">
|
||||||
<button id="login2">Login</button>
|
<button id="login2">Login</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="navbar">
|
<div class="navbar">
|
||||||
<button class="burger-menu">☰</button>
|
<button class="burger-menu">☰</button>
|
||||||
<div id="dropdown-menu" class="dropdown-content">
|
<div id="dropdown-menu" class="dropdown-content">
|
||||||
<a href="#" data-table="player-list">Players</a>
|
<a href="#" data-table="player-list">Players</a>
|
||||||
<a href="#" data-table="match-list">Matches</a>
|
<a href="#" data-table="match-list">Matches</a>
|
||||||
<a href="#" data-table="tournoi-list">Tournois</a>
|
<a href="#" data-table="tournoi-list">Tournois</a>
|
||||||
<a href="#" data-table="blockchain-list">blockchain</a>
|
<a href="#" data-table="blockchain-list">blockchain</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="tournament-bracket" style="display: none;"></div>
|
<div id="tournament-bracket" style="display: none;"></div>
|
||||||
|
|
||||||
<div id="game-controls" style="display: none;">
|
<div id="game1" style="display: none;">
|
||||||
<button id="home">Home</button>
|
<div id="player1-name" class="name">Player 1</div>
|
||||||
<button id="retry">Rejouer</button>
|
<div id="player2-name" class="name">Player 2</div>
|
||||||
</div>
|
<div id="game2">
|
||||||
|
<div id="player1-score" class="score">0</div>
|
||||||
|
<div id="player2-score" class="score">0</div>
|
||||||
|
<div id="player1-pad" class="pad"></div>
|
||||||
|
<div id="player2-pad" class="pad"></div>
|
||||||
|
<div id="ball"></div>
|
||||||
|
<div id="game-text" class="gameText"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="game1" style="display: none;">
|
<div id="match-list" class="content-list" style="display: none;">
|
||||||
<div id="player1-name" class="name"></div>
|
<h1>Matches</h1>
|
||||||
<div id="player2-name" class="name"></div>
|
<input type="text" id="search-match-player" placeholder="Rechercher par nom de joueur">
|
||||||
<div id="game2">
|
<input type="date" id="search-match-date">
|
||||||
<div id="player1-score" class="score">0</div>
|
<table>
|
||||||
<div id="player2-score" class="score">0</div>
|
<thead>
|
||||||
<div id="player1-pad" class="pad"></div>
|
<tr>
|
||||||
<div id="player2-pad" class="pad"></div>
|
<th>ID</th>
|
||||||
<div id="ball"></div>
|
<th>Player 1</th>
|
||||||
<div id="game-text" class="gameText"></div>
|
<th>Player 2</th>
|
||||||
</div>
|
<th>Score Player 1</th>
|
||||||
</div>
|
<th>Score Player 2</th>
|
||||||
|
<th>Winner</th>
|
||||||
<div id="match-list" class="content-list" style="display: none;">
|
<th>Ball Touches Player 1</th>
|
||||||
<h1>Matches</h1>
|
<th>Ball Touches Player 2</th>
|
||||||
<input type="text" id="search-match-player" placeholder="Rechercher par nom de joueur">
|
<th>Duration</th>
|
||||||
<input type="date" id="search-match-date">
|
<th>Date</th>
|
||||||
<table>
|
<th>Is Tournament</th>
|
||||||
<thead>
|
<th>Tournament</th>
|
||||||
<tr>
|
</tr>
|
||||||
<th>ID</th>
|
</thead>
|
||||||
<th>Player 1</th>
|
|
||||||
<th>Player 2</th>
|
|
||||||
<th>Score Player 1</th>
|
|
||||||
<th>Score Player 2</th>
|
|
||||||
<th>Winner</th>
|
|
||||||
<th>Ball Touches Player 1</th>
|
|
||||||
<th>Ball Touches Player 2</th>
|
|
||||||
<th>Duration</th>
|
|
||||||
<th>Date</th>
|
|
||||||
<th>Is Tournament</th>
|
|
||||||
<th>Tournament</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<button id="generate-match-chart">Générer le graphique</button>
|
|
||||||
<canvas id="match-chart" style="display:none;"></canvas>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="player-list" class="content-list" style="display: none;">
|
|
||||||
<h1>Players</h1>
|
|
||||||
<input type="text" id="search-player" placeholder="Rechercher par nom">
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>ID</th>
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Total Matches</th>
|
|
||||||
<th>Total Wins</th>
|
|
||||||
<th>Win Percentage</th>
|
|
||||||
<th>Average Match Score</th>
|
|
||||||
<th>Average Opponent Score</th>
|
|
||||||
<th>Best Score</th>
|
|
||||||
<th>Average Ball Touches</th>
|
|
||||||
<th>Total Duration</th>
|
|
||||||
<th>Average Duration</th>
|
|
||||||
<th>Participated Tournaments</th>
|
|
||||||
<th>Won Tournaments</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<button id="generate-player-chart">Générer le graphique</button>
|
|
||||||
<canvas id="player-chart" style="display:none;"></canvas>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="tournoi-list" class="content-list" style="display: none;">
|
|
||||||
<h1>Tournois</h1>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>ID</th>
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Nbr_players</th>
|
|
||||||
<th>Date</th>
|
|
||||||
<th>Winner</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
<tbody>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
<button id="generate-match-chart">Générer le graphique</button>
|
||||||
|
<canvas id="match-chart" style="display:none;"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<div id="player-list" class="content-list" style="display: none;">
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
|
<h1>Players</h1>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@1.0.0/dist/chartjs-adapter-moment.min.js"></script>
|
<input type="text" id="search-player" placeholder="Rechercher par nom">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Total Matches</th>
|
||||||
|
<th>Total Wins</th>
|
||||||
|
<th>Win Percentage</th>
|
||||||
|
<th>Average Match Score</th>
|
||||||
|
<th>Average Opponent Score</th>
|
||||||
|
<th>Best Score</th>
|
||||||
|
<th>Average Ball Touches</th>
|
||||||
|
<th>Total Duration</th>
|
||||||
|
<th>Average Duration</th>
|
||||||
|
<th>Participated Tournaments</th>
|
||||||
|
<th>Won Tournaments</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<button id="generate-player-chart">Générer le graphique</button>
|
||||||
|
<canvas id="player-chart" style="display:none;"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="{% static 'game.js' %}"></script>
|
<div id="tournoi-list" class="content-list" style="display: none;">
|
||||||
<script src="{% static 'burger.js' %}"></script>
|
<h1>Tournois</h1>
|
||||||
<script src="{% static 'language.js' %}"></script>
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Nbr_players</th>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Winner</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@1.0.0/dist/chartjs-adapter-moment.min.js"></script>
|
||||||
|
|
||||||
|
<script src="{% static 'game.js' %}"></script>
|
||||||
|
<script src="{% static 'burger.js' %}"></script>
|
||||||
|
<script src="{% static 'language.js' %}"></script>
|
||||||
|
|
||||||
|
<div id="chat-container">
|
||||||
|
<!-- Conteneur des journaux de chat -->
|
||||||
|
<div id="chat-log-container">
|
||||||
|
<div id="chat-log-main_room" class="chat-log" style="display:block;"></div>
|
||||||
|
<div id="chat-log-tournament" class="chat-log" style="display:none;"></div>
|
||||||
|
<div id="chat-log-quick_match" class="chat-log" style="display:none;"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Entrées de texte et boutons d'envoi pour chaque room -->
|
||||||
|
<div id="chat-input-container">
|
||||||
|
<div id="chat-input-main_room" class="chat-input">
|
||||||
|
<input type="text" placeholder="Tapez votre message...">
|
||||||
|
<button id="chat-button-main_room" class="chat-button">➤</button>
|
||||||
|
</div>
|
||||||
|
<div id="chat-input-tournament" class="chat-input">
|
||||||
|
<input type="text" placeholder="Tapez votre message...">
|
||||||
|
<button id="chat-button-tournament" class="chat-button">➤</button>
|
||||||
|
</div>
|
||||||
|
<div id="chat-input-quick_match" class="chat-input">
|
||||||
|
<input type="text" placeholder="Tapez votre message...">
|
||||||
|
<button id="chat-button-quick_match" class="chat-button">➤</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Conteneur des onglets de room -->
|
||||||
|
<div id="room-tabs-container">
|
||||||
|
<div class="room-tab" data-room="main_room">Main Room</div>
|
||||||
|
<div class="room-tab" data-room="tournament">Tournament</div>
|
||||||
|
<div class="room-tab" data-room="quick_match">Quick Match</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Ajout du script JavaScript pour la gestion dynamique -->
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const tabs = document.querySelectorAll('.room-tab');
|
||||||
|
const chatLogs = document.querySelectorAll('.chat-log');
|
||||||
|
const chatInputs = document.querySelectorAll('.chat-input');
|
||||||
|
|
||||||
|
tabs.forEach(tab => {
|
||||||
|
tab.addEventListener('click', function() {
|
||||||
|
const roomId = this.dataset.room;
|
||||||
|
|
||||||
|
// Afficher le journal de chat correspondant
|
||||||
|
chatLogs.forEach(log => {
|
||||||
|
log.style.display = log.id === `chat-log-${roomId}` ? 'block' : 'none';
|
||||||
|
});
|
||||||
|
|
||||||
|
// Afficher l'entrée de texte correspondante
|
||||||
|
chatInputs.forEach(input => {
|
||||||
|
input.classList.remove('active');
|
||||||
|
if (input.id === `chat-input-${roomId}`) {
|
||||||
|
input.classList.add('active');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mettre à jour l'onglet actif
|
||||||
|
tabs.forEach(t => t.classList.remove('active'));
|
||||||
|
this.classList.add('active');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const starsContainer = document.getElementById('stars');
|
||||||
|
for (let i = 0; i < 500; i++) {
|
||||||
|
const star = document.createElement('div');
|
||||||
|
star.className = 'star';
|
||||||
|
star.style.width = `${Math.random() * 3}px`;
|
||||||
|
star.style.height = star.style.width;
|
||||||
|
star.style.left = `${Math.random() * 100}%`;
|
||||||
|
star.style.top = `${Math.random() * 100}%`;
|
||||||
|
star.style.animationDuration = `${Math.random() * 2 + 1}s`;
|
||||||
|
starsContainer.appendChild(star);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@ -1,472 +1,601 @@
|
|||||||
/* General styles */
|
/* General styles */
|
||||||
|
|
||||||
html {
|
html {
|
||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
color: #00ffff;
|
color: #00ffff;
|
||||||
background-color: #0a0a2a;
|
background-color: #0a0a2a;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
label {
|
label {
|
||||||
margin: 10px 0 5px;
|
margin: 10px 0 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
margin: 5px 0 20px;
|
margin: 5px 0 20px;
|
||||||
width: 200px;
|
width: 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
background-color: #00ffff;
|
background-color: #00ffff;
|
||||||
color: #000033;
|
color: #000033;
|
||||||
border: none;
|
border: none;
|
||||||
padding: 1rem 2rem;
|
padding: 1rem 2rem;
|
||||||
font-size: 1.5rem;
|
font-size: 1.5rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
letter-spacing: 2px;
|
letter-spacing: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
button:hover {
|
button:hover {
|
||||||
background-color: #000033;
|
background-color: #000033;
|
||||||
color: #00ffff;
|
color: #00ffff;
|
||||||
box-shadow: 0 0 20px #00ffff;
|
box-shadow: 0 0 20px #00ffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
#game1 {
|
#game1 {
|
||||||
width: 810px;
|
width: 810px;
|
||||||
height: 500px;
|
height: 500px;
|
||||||
position: relative;
|
position: relative;
|
||||||
background-color: #000;
|
background-color: #000;
|
||||||
border: 3px solid #00ffff;
|
border: 3px solid #00ffff;
|
||||||
box-shadow: 0 0 30px #00ffff, inset 0 0 20px #00ffff;
|
box-shadow: 0 0 30px #00ffff, inset 0 0 20px #00ffff;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.name {
|
.name {
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 20px;
|
top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#player1-name {
|
#player1-name {
|
||||||
left: 10px;
|
left: 10px;
|
||||||
/* Adjust player score position */
|
/* Adjust player score position */
|
||||||
}
|
}
|
||||||
|
|
||||||
#player2-name {
|
#player2-name {
|
||||||
right: 10px;
|
right: 10px;
|
||||||
/* Adjust bot score position */
|
/* Adjust bot score position */
|
||||||
}
|
}
|
||||||
|
|
||||||
#game2 {
|
#game2 {
|
||||||
top: 60px;
|
top: 60px;
|
||||||
width: 800px;
|
width: 800px;
|
||||||
height: 400px;
|
height: 400px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
background-color: #000;
|
background-color: #000;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
border: 2px solid white;
|
border: 2px solid white;
|
||||||
/* Add red border */
|
/* Add red border */
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.score {
|
.score {
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#player1-score {
|
#player1-score {
|
||||||
left: 50px;
|
left: 50px;
|
||||||
/* Adjust player score position */
|
/* Adjust player score position */
|
||||||
}
|
}
|
||||||
|
|
||||||
#player2-score {
|
#player2-score {
|
||||||
right: 50px;
|
right: 50px;
|
||||||
/* Adjust bot score position */
|
/* Adjust bot score position */
|
||||||
}
|
}
|
||||||
|
|
||||||
.pad {
|
.pad {
|
||||||
width: 10px;
|
width: 10px;
|
||||||
height: 100px;
|
height: 100px;
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
|
|
||||||
#player1-pad {
|
#player1-pad {
|
||||||
left: 10px;
|
left: 10px;
|
||||||
background-color: #00ffff;
|
background-color: #00ffff;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
box-shadow: 0 0 15px #00ffff;
|
box-shadow: 0 0 15px #00ffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
#player2-pad {
|
#player2-pad {
|
||||||
right: 10px;
|
right: 10px;
|
||||||
background-color: #00ffff;
|
background-color: #00ffff;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
box-shadow: 0 0 15px #00ffff;
|
box-shadow: 0 0 15px #00ffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ball {
|
#ball {
|
||||||
width: 20px;
|
width: 20px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
background-color: #00ffff;
|
background-color: #00ffff;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
|
|
||||||
#game-text {
|
#game-text {
|
||||||
font-size: 64px;
|
font-size: 64px;
|
||||||
color: #00ffff;
|
color: #00ffff;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 150px;
|
top: 150px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo {
|
.logo {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 20px;
|
top: 20px;
|
||||||
left: 20px;
|
left: 20px;
|
||||||
z-index: 20;
|
z-index: 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo img {
|
.logo img {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stars {
|
.stars {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.star {
|
.star {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
animation: twinkle 2s infinite alternate;
|
animation: twinkle 2s infinite alternate;
|
||||||
}
|
}
|
||||||
|
|
||||||
.background {
|
.background {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pong-elements {
|
.pong-elements {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
z-index: 5;
|
z-index: 5;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.paddle {
|
.paddle {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 20px;
|
width: 20px;
|
||||||
height: 100px;
|
height: 100px;
|
||||||
background-color: #00ffff;
|
background-color: #00ffff;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
box-shadow: 0 0 15px #00ffff;
|
box-shadow: 0 0 15px #00ffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.paddle-left {
|
.paddle-left {
|
||||||
left: 50px;
|
left: 50px;
|
||||||
animation: paddleMove 5s infinite alternate ease-in-out;
|
animation: paddleMove 5s infinite alternate ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.paddle-right {
|
.paddle-right {
|
||||||
right: 50px;
|
right: 50px;
|
||||||
animation: paddleMove 4s infinite alternate-reverse ease-in-out;
|
animation: paddleMove 4s infinite alternate-reverse ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ball_anim {
|
.ball_anim {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 30px;
|
width: 30px;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
background-color: #00ffff;
|
background-color: #00ffff;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
box-shadow: 0 0 20px #00ffff;
|
box-shadow: 0 0 20px #00ffff;
|
||||||
left: 80px;
|
left: 80px;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
transform-style: preserve-3d;
|
transform-style: preserve-3d;
|
||||||
animation: ballMove 3s linear infinite;
|
animation: ballMove 3s linear infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes paddleMove {
|
@keyframes paddleMove {
|
||||||
0% {
|
0% {
|
||||||
transform: translateY(10vh);
|
transform: translateY(10vh);
|
||||||
}
|
}
|
||||||
|
|
||||||
100% {
|
100% {
|
||||||
transform: translateY(70vh);
|
transform: translateY(70vh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes ballMove {
|
@keyframes ballMove {
|
||||||
0% {
|
0% {
|
||||||
transform: translateZ(0) scale(1);
|
transform: translateZ(0) scale(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
50% {
|
50% {
|
||||||
transform: translateZ(-500px) scale(0.5);
|
transform: translateZ(-500px) scale(0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
100% {
|
100% {
|
||||||
transform: translateZ(0) scale(1);
|
transform: translateZ(0) scale(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-container {
|
.input-container {
|
||||||
margin-bottom: 2rem;
|
margin-bottom: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
background-color: rgba(0, 0, 40, 0.8);
|
background-color: rgba(0, 0, 40, 0.8);
|
||||||
padding: 3rem;
|
padding: 3rem;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
border: 3px solid #00ffff;
|
border: 3px solid #00ffff;
|
||||||
box-shadow: 0 0 30px #00ffff, inset 0 0 20px #00ffff;
|
box-shadow: 0 0 30px #00ffff, inset 0 0 20px #00ffff;
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
max-width: 80%;
|
max-width: 80%;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.navbar {
|
.navbar {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 30px;
|
top: 30px;
|
||||||
right: 10px;
|
right: 10px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.burger-menu {
|
.burger-menu {
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
background: none;
|
background: none;
|
||||||
border: none;
|
border: none;
|
||||||
color: #00ffff;
|
color: #00ffff;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: color 0.3s ease;
|
transition: color 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.burger-menu:hover {
|
.burger-menu:hover {
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.dropdown-content {
|
.dropdown-content {
|
||||||
display: none;
|
display: none;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 100%;
|
top: 100%;
|
||||||
right: 0;
|
right: 0;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
background-color: #1a1a2e;
|
background-color: #1a1a2e;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.3);
|
box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.3);
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
width: max-content;
|
width: max-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dropdown-content.show {
|
.dropdown-content.show {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.dropdown-content a {
|
.dropdown-content a {
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
padding: 12px 16px;
|
padding: 12px 16px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
display: block;
|
display: block;
|
||||||
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
|
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
transition: background-color 0.3s ease;
|
transition: background-color 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.dropdown-content a:hover {
|
.dropdown-content a:hover {
|
||||||
background-color: #333;
|
background-color: #333;
|
||||||
color: #00ffff;
|
color: #00ffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.language-switcher {
|
.language-switcher {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
right: 10px;
|
right: 10px;
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.language-switcher img {
|
.language-switcher img {
|
||||||
width: 30px;
|
width: 30px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#settings-btn {
|
#settings-btn {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 10px;
|
bottom: 10px;
|
||||||
right: 10px;
|
right: 10px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#settings-menu {
|
#settings-menu {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 50px;
|
bottom: 50px;
|
||||||
right: 10px;
|
right: 10px;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
background-color: rgb(66, 63, 63);
|
background-color: rgb(66, 63, 63);
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||||
width: 250px;
|
width: 250px;
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
#close-settings {
|
#close-settings {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
right: 10px;
|
right: 10px;
|
||||||
background: none;
|
background: none;
|
||||||
border: none;
|
border: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal {
|
.modal {
|
||||||
display: none;
|
display: none;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
left: 0;
|
left: 0;
|
||||||
top: 0;
|
top: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
background-color: rgb(0, 0, 0);
|
background-color: rgb(0, 0, 0);
|
||||||
background-color: rgba(0, 0, 0, 0.4);
|
background-color: rgba(0, 0, 0, 0.4);
|
||||||
padding-top: 60px;
|
padding-top: 60px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-content {
|
.modal-content {
|
||||||
background-color: #fefefe;
|
background-color: #fefefe;
|
||||||
margin: 5% auto;
|
margin: 5% auto;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
border: 5px solid #888;
|
border: 5px solid #888;
|
||||||
width: 80%;
|
width: 80%;
|
||||||
max-height: 70vh;
|
max-height: 70vh;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.close {
|
.close {
|
||||||
color: #aaa;
|
color: #aaa;
|
||||||
float: right;
|
float: right;
|
||||||
font-size: 28px;
|
font-size: 28px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.close:hover,
|
.close:hover,
|
||||||
.close:focus {
|
.close:focus {
|
||||||
color: black;
|
color: black;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
.tournament-waiting-room {
|
.tournament-waiting-room {
|
||||||
background-color: rgba(0, 0, 0, 0.6);
|
background-color: rgba(0, 0, 0, 0.6);
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
color: #00ffff;
|
color: #00ffff;
|
||||||
width: 50%;
|
width: 50%;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
box-shadow: 0 0 30px #00ffff, inset 0 0 20px #00ffff;
|
box-shadow: 0 0 30px #00ffff, inset 0 0 20px #00ffff;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.tournament-waiting-room h2 {
|
.tournament-waiting-room h2 {
|
||||||
font-family: 'Arial', sans-serif;
|
font-family: 'Arial', sans-serif;
|
||||||
font-size: 2em;
|
font-size: 2em;
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
|
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
|
||||||
}
|
}
|
||||||
|
|
||||||
.tournament-waiting-room p {
|
.tournament-waiting-room p {
|
||||||
font-family: 'Verdana', sans-serif;
|
font-family: 'Verdana', sans-serif;
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
|
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
|
||||||
}
|
}
|
||||||
|
|
||||||
.tournament-waiting-room ul {
|
.tournament-waiting-room ul {
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
body {
|
body {
|
||||||
color: rgb(0, 255, 255); /* Valeur par défaut */
|
color: rgb(0, 255, 255); /* Valeur par défaut */
|
||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas {
|
canvas {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
height: auto;
|
height: auto;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#game-controls {
|
#game-controls {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 20px;
|
gap: 20px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#game-controls button {
|
#game-controls button {
|
||||||
background-color: #00ffff;
|
background-color: #00ffff;
|
||||||
color: #000033;
|
color: #000033;
|
||||||
border: none;
|
border: none;
|
||||||
padding: 1rem 2rem;
|
padding: 1rem 2rem;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
letter-spacing: 2px;
|
letter-spacing: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#game-controls button:hover {
|
#game-controls button:hover {
|
||||||
background-color: #000033;
|
background-color: #000033;
|
||||||
color: #00ffff;
|
color: #00ffff;
|
||||||
box-shadow: 0 0 20px #00ffff;
|
box-shadow: 0 0 20px #00ffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Styles pour le conteneur principal du chat */
|
||||||
|
#chat-container {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 10px;
|
||||||
|
left: 10px;
|
||||||
|
width: 300px;
|
||||||
|
background-color: rgba(0, 0, 0, 0.7);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 10px;
|
||||||
|
box-shadow: 0 0 30px #00ffff, inset 0 0 20px #00ffff;
|
||||||
|
z-index: 1000;
|
||||||
|
box-sizing: border-box; /* Ajouté */
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Styles pour le conteneur du chat log */
|
||||||
|
#chat-log-container {
|
||||||
|
width: 100%;
|
||||||
|
background-color: transparent; /* Fond transparent */
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 10px;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 14px;
|
||||||
|
max-height: 150px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
box-sizing: border-box; /* Ajouté */
|
||||||
|
flex: 1; /* Permet au conteneur de prendre tout l'espace disponible */
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-log {
|
||||||
|
max-height: 150px;
|
||||||
|
overflow-y: auto;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
box-sizing: border-box; /* Ajouté */
|
||||||
|
background-color: transparent; /* Fond transparent */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Styles pour l'entrée de texte du chat */
|
||||||
|
#chat-input-container {
|
||||||
|
width: 100%;
|
||||||
|
height: 25%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column; /* Aligner les chat-inputs verticalement */
|
||||||
|
background-color: transparent; /* Fond transparent */
|
||||||
|
padding: 5px;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-sizing: border-box; /* Ajouté */
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-input {
|
||||||
|
flex: 1;
|
||||||
|
padding: 5px;
|
||||||
|
font-size: 13px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
margin-right: 5px;
|
||||||
|
height: 28px;
|
||||||
|
box-sizing: border-box; /* Ajouté */
|
||||||
|
display: none; /* Masquer par défaut */
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-input.active {
|
||||||
|
display: flex; /* Afficher lorsque actif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-input input[type="text"] {
|
||||||
|
flex: 1; /* Permet à l'input de prendre tout l'espace disponible */
|
||||||
|
padding: 5px;
|
||||||
|
font-size: 13px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
box-sizing: border-box; /* Ajouté */
|
||||||
|
height: 28px; /* Augmenter la hauteur de l'input */
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-button {
|
||||||
|
height: 28px;
|
||||||
|
width: 150px; /* Réduire la largeur du bouton */
|
||||||
|
border: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
background-color: #00ffff;
|
||||||
|
color: #000033;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-left: 100px; /* Espace entre l'input et le bouton */
|
||||||
|
display: flex; /* Utiliser flexbox pour centrer le contenu */
|
||||||
|
align-items: center; /* Centrer verticalement */
|
||||||
|
justify-content: center; /* Centrer horizontalement */
|
||||||
|
text-align: center; /* Assurer que le texte est centré */
|
||||||
|
font-size: 13px; /* Ajuster la taille de la police */
|
||||||
|
padding: 0; /* Supprimer le padding interne */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Styles pour les onglets de room */
|
||||||
|
#room-tabs-container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Styles pour les onglets de room */
|
||||||
|
.room-tab {
|
||||||
|
font-size: 14px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
margin-right: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
border: 1px solid #00ffff;
|
||||||
|
background-color: #000033;
|
||||||
|
color: #00ffff;
|
||||||
|
border-radius: 5px;
|
||||||
|
box-sizing: border-box; /* Ajouté */
|
||||||
|
opacity: 0.1; /* Onglets inactifs grisés */
|
||||||
|
}
|
||||||
|
|
||||||
|
.room-tab:hover {
|
||||||
|
background-color: #00ffff;
|
||||||
|
color: #000033;
|
||||||
|
}
|
||||||
|
|
||||||
|
.room-tab.active {
|
||||||
|
background-color: #00ffff;
|
||||||
|
color: #000033;
|
||||||
|
opacity: 1; /* Onglets actifs non grisés */
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||