From 6fdc60642e0add3375eb348df66c3148fe4f17a0 Mon Sep 17 00:00:00 2001 From: omer Date: Sun, 12 May 2024 16:25:36 +0300 Subject: [PATCH] =?UTF-8?q?Turnuva=20sadece=20bi=20kere=20ba=C5=9Flat?= =?UTF-8?q?=C4=B1labilir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/ft-transcendence.iml | 18 ++++++++++++++++++ .idea/inspectionProfiles/Project_Default.xml | 8 ++++++++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 7 +++++++ .idea/vcs.xml | 6 ++++++ API/API/settings.py | 2 +- API/Apps/Tournament/Serializers.py | 2 +- API/Apps/Tournament/consumers.py | 14 ++++++++++---- API/Apps/Tournament/templates/w.html | 2 +- 9 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 .idea/ft-transcendence.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/ft-transcendence.iml b/.idea/ft-transcendence.iml new file mode 100644 index 00000000..1edba38c --- /dev/null +++ b/.idea/ft-transcendence.iml @@ -0,0 +1,18 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..92db1df4 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..105ce2da --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..86abaf79 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/API/API/settings.py b/API/API/settings.py index fb868317..dd9c1887 100644 --- a/API/API/settings.py +++ b/API/API/settings.py @@ -102,7 +102,7 @@ "default": { "BACKEND": "channels_redis.core.RedisChannelLayer", "CONFIG": { - "hosts": [("127.0.0.1", 6379)], + "hosts": [("192.168.228.2", 6379)], }, }, } diff --git a/API/Apps/Tournament/Serializers.py b/API/Apps/Tournament/Serializers.py index ed08c6a2..d86b6967 100644 --- a/API/Apps/Tournament/Serializers.py +++ b/API/Apps/Tournament/Serializers.py @@ -38,7 +38,7 @@ class Meta: class TournamentPostSerializer(serializers.ModelSerializer): class Meta: model = Tournament - fields = ['id', 'name', 'max_participants', 'created_by', 'current_participants'] + fields = ['id', 'name', 'max_participants', 'created_by'] def validate(self, val): if val['max_participants'] <= 2: diff --git a/API/Apps/Tournament/consumers.py b/API/Apps/Tournament/consumers.py index 7e0b68a9..682a4964 100644 --- a/API/Apps/Tournament/consumers.py +++ b/API/Apps/Tournament/consumers.py @@ -79,11 +79,11 @@ def connect(self): def receive(self, text_data): data = json.loads(text_data) print("data",data) - if data['send_type'] == 'checkMatch': + if data['request_type'] == 'checkMatch': self.checkMatch(self.nickname, self.tournament_id) - elif data['send_type'] == 'start': - self.check_start_conditions() - self.StartTournament(data) + elif data['request_type'] == 'StartTournament': + self.check_start_conditions() + self.StartTournament(data) def check_start_conditions(self): player = get_player_from_cache(f"user_{self.tournament_id}", self.nickname) @@ -130,10 +130,16 @@ def disconnect(self, close_code): def StartTournament(self, data): print(get_players_from_cache(f"user_{self.tournament_id}")) tournament = Tournament.objects.get(id=self.tournament_id) + print("turrrrrr",tournament.is_started) + if tournament.is_started == True: + print("31313131313") + return participants = tournament.current_participants.all() if tournament.current_participants.count() > 2: round_number = 1 round_obj = Round.objects.create(round_number=round_number) + tournament.is_started = True + tournament.save() round_obj.participants.set(participants) tournament.rounds.add(round_obj) try: diff --git a/API/Apps/Tournament/templates/w.html b/API/Apps/Tournament/templates/w.html index 06b2d3b1..f3dbbe1a 100644 --- a/API/Apps/Tournament/templates/w.html +++ b/API/Apps/Tournament/templates/w.html @@ -16,7 +16,7 @@ const url = window.location.pathname; const param = url.split("/"); const nickname = param[param.length - 2]; - const tournament_id = "eba06344-e081-4e52-852f-38bbff0fdbd6"; + const tournament_id = "a8671b64-478e-4483-b693-d44b22b0ea17"; const socket = new WebSocket('ws://localhost:8000/ws/tournament/?nickname=' + nickname + '&tournament_id=' + tournament_id);