mirror of
https://github.com/AudebertAdrien/ft_transcendence.git
synced 2026-02-04 11:40:25 +01:00
endfortheouche doesnt work yet
This commit is contained in:
parent
ca3d36dd59
commit
6ac9629f6a
@ -58,61 +58,6 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 120
|
retries: 120
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
backend:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
image: backend
|
|
||||||
container_name: backend
|
|
||||||
restart: always
|
|
||||||
command: /bin/sh -c "sleep 5 &&
|
|
||||||
venv/bin/python manage.py makemigrations --noinput &&
|
|
||||||
venv/bin/python manage.py migrate --noinput &&
|
|
||||||
venv/bin/python manage.py collectstatic --noinput &&
|
|
||||||
venv/bin/daphne -b 0.0.0.0 -p 8080 pong.asgi:application"
|
|
||||||
volumes:
|
|
||||||
- pong:/transcendence/pong
|
|
||||||
ports:
|
|
||||||
- 8080:8080
|
|
||||||
networks:
|
|
||||||
- app-network
|
|
||||||
environment:
|
|
||||||
DB_HOST: db
|
|
||||||
DB_PORT: 5432
|
|
||||||
DB_NAME: ${POSTGRES_DB}
|
|
||||||
DB_USER: ${POSTGRES_USER}
|
|
||||||
DB_PASSWORD: ${POSTGRES_PASSWORD}
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD-SHELL", "curl", "http://localhost:8080"]
|
|
||||||
interval: 30s
|
|
||||||
timeout: 10s
|
|
||||||
retries: 3
|
|
||||||
start_period: 10s
|
|
||||||
|
|
||||||
db:
|
|
||||||
image: postgres:latest
|
|
||||||
container_name: postgres
|
|
||||||
restart: always
|
|
||||||
volumes:
|
|
||||||
- pong_pg_data:/var/lib/postgresql/data
|
|
||||||
ports:
|
|
||||||
- "5432:5432"
|
|
||||||
networks:
|
|
||||||
- app-network
|
|
||||||
environment:
|
|
||||||
POSTGRES_DB: ${POSTGRES_DB}
|
|
||||||
POSTGRES_USER: ${POSTGRES_USER}
|
|
||||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
|
|
||||||
es01:
|
es01:
|
||||||
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
|
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
|
||||||
container_name: es01
|
container_name: es01
|
||||||
@ -209,6 +154,59 @@ services:
|
|||||||
- ELASTIC_USER=${ELASTIC_USERNAME}
|
- ELASTIC_USER=${ELASTIC_USERNAME}
|
||||||
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
|
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
|
||||||
- xpack.monitoring.enabled=false
|
- xpack.monitoring.enabled=false
|
||||||
|
|
||||||
|
backend:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
image: backend
|
||||||
|
container_name: backend
|
||||||
|
restart: always
|
||||||
|
command: /bin/sh -c "sleep 5 &&
|
||||||
|
venv/bin/python manage.py makemigrations --noinput &&
|
||||||
|
venv/bin/python manage.py migrate --noinput &&
|
||||||
|
venv/bin/python manage.py collectstatic --noinput &&
|
||||||
|
venv/bin/daphne -b 0.0.0.0 -p 8080 pong.asgi:application"
|
||||||
|
volumes:
|
||||||
|
- pong:/transcendence/pong
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
|
networks:
|
||||||
|
- app-network
|
||||||
|
environment:
|
||||||
|
DB_HOST: db
|
||||||
|
DB_PORT: 5432
|
||||||
|
DB_NAME: ${POSTGRES_DB}
|
||||||
|
DB_USER: ${POSTGRES_USER}
|
||||||
|
DB_PASSWORD: ${POSTGRES_PASSWORD}
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "curl", "http://localhost:8080"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 10s
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:latest
|
||||||
|
container_name: postgres
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- pong_pg_data:/var/lib/postgresql/data
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
networks:
|
||||||
|
- app-network
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB}
|
||||||
|
POSTGRES_USER: ${POSTGRES_USER}
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
pong:
|
pong:
|
||||||
|
|||||||
@ -100,12 +100,14 @@ class Game:
|
|||||||
self.game_state['player2_score'] += 1
|
self.game_state['player2_score'] += 1
|
||||||
if self.game_state['player2_score'] > 2:
|
if self.game_state['player2_score'] > 2:
|
||||||
print("Here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
print("Here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||||
|
await self.send_game_state()
|
||||||
await self.end_game()
|
await self.end_game()
|
||||||
self.reset_ball()
|
self.reset_ball()
|
||||||
elif self.game_state['ball_position']['x'] >= 790:
|
elif self.game_state['ball_position']['x'] >= 790:
|
||||||
self.game_state['player1_score'] += 1
|
self.game_state['player1_score'] += 1
|
||||||
if self.game_state['player1_score'] > 2:
|
if self.game_state['player1_score'] > 2:
|
||||||
print("Here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
print("Here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||||
|
await self.send_game_state()
|
||||||
await self.end_game()
|
await self.end_game()
|
||||||
self.reset_ball()
|
self.reset_ball()
|
||||||
|
|
||||||
@ -197,7 +199,8 @@ class Game:
|
|||||||
'player': disconnected_name
|
'player': disconnected_name
|
||||||
})
|
})
|
||||||
if not self.botgame:
|
if not self.botgame:
|
||||||
await remaining_player.send(message)
|
if not self.localgame:
|
||||||
|
await remaining_player.send(message)
|
||||||
# Notify both players that the game has ended
|
# Notify both players that the game has ended
|
||||||
end_message = json.dumps({
|
end_message = json.dumps({
|
||||||
'type': 'game_ended',
|
'type': 'game_ended',
|
||||||
|
|||||||
@ -4,25 +4,34 @@ from django.shortcuts import get_object_or_404
|
|||||||
from django.db.models import Max, Sum, F
|
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
|
||||||
#from asgiref.sync import database_sync_to_async
|
|
||||||
|
|
||||||
|
|
||||||
async def endfortheouche(p1, p2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament):
|
async def endfortheouche(p1, p2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament):
|
||||||
try:
|
try:
|
||||||
print("here endfortheouche §!!!")
|
print("here endfortheouche §!!!")
|
||||||
if not await database_sync_to_async(Player.objects.filter(name=p1).exists)():
|
|
||||||
|
# Handle Player 1
|
||||||
|
exists = await database_sync_to_async(Player.objects.filter(name=p1).exists)()
|
||||||
|
if exists:
|
||||||
|
print(f"Player {p1} exists.")
|
||||||
|
else:
|
||||||
|
print(f"Player {p1} does not exist.")
|
||||||
|
|
||||||
|
player_1 = await get_name(p1)
|
||||||
|
print(f"Player 1 retrieval result: {player_1}")
|
||||||
|
if player_1 is None:
|
||||||
|
print("############# CREATING PLAYER")
|
||||||
player_1 = await create_player(p1)
|
player_1 = await create_player(p1)
|
||||||
print("############# PLAYER DONE")
|
|
||||||
else:
|
else:
|
||||||
player_1 = await database_sync_to_async(Player.objects.get)(name=p1)
|
print("############# PLAYER FOUND")
|
||||||
|
|
||||||
print("ok")
|
# Handle Player 2
|
||||||
|
player_2 = await get_name(p2)
|
||||||
if not await database_sync_to_async(Player.objects.filter(name=p2).exists)():
|
print(f"Player 2 retrieval result: {player_2}")
|
||||||
|
if player_2 is None:
|
||||||
|
print("############# CREATING PLAYER")
|
||||||
player_2 = await create_player(p2)
|
player_2 = await create_player(p2)
|
||||||
print("############# PLAYER DONE")
|
|
||||||
else:
|
else:
|
||||||
player_2 = await database_sync_to_async(Player.objects.get)(name=p2)
|
print("############# PLAYER FOUND")
|
||||||
|
|
||||||
print("############# BEFORE MATCH")
|
print("############# BEFORE MATCH")
|
||||||
await create_match(player_1, player_2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament)
|
await create_match(player_1, player_2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament)
|
||||||
@ -31,9 +40,19 @@ async def endfortheouche(p1, p2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_
|
|||||||
await update_player_statistics(p1)
|
await update_player_statistics(p1)
|
||||||
print("############# END STAT P1")
|
print("############# END STAT P1")
|
||||||
await update_player_statistics(p2)
|
await update_player_statistics(p2)
|
||||||
|
print("############# END STAT P2")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error in endfortheouche: {e}")
|
print(f"Error in endfortheouche: {e}")
|
||||||
|
|
||||||
|
@database_sync_to_async
|
||||||
|
def get_name(p):
|
||||||
|
print(f"in get_name({p})..")
|
||||||
|
try:
|
||||||
|
return Player.objects.get(name=p)
|
||||||
|
except Player.DoesNotExist:
|
||||||
|
print("get_name() exception")
|
||||||
|
return None
|
||||||
|
|
||||||
@database_sync_to_async
|
@database_sync_to_async
|
||||||
def create_player(
|
def create_player(
|
||||||
name,
|
name,
|
||||||
|
|||||||
@ -5,3 +5,4 @@ channels
|
|||||||
daphne
|
daphne
|
||||||
djangorestframework
|
djangorestframework
|
||||||
web3
|
web3
|
||||||
|
asyncpg
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user