diff --git a/docker-compose.yml b/docker-compose.yml index 6576208c..a93691f7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,23 +9,22 @@ services: restart: always ports: - 8000:8000 -# depends_on: -# - db -# env_file: -# - .env -# networks: -# - indianpongnet - -# db: -# container_name: db -# image: db -# build: -# context: ./ -# dockerfile: docker.dockerfile -# restart: always -# networks: -# - indianpongnet -# -#networks: -# indianpongnet: -# driver: bridge + depends_on: + - db + env_file: + - .env + networks: + - indianpongnet + db: + container_name: db + image: db + build: + context: ./ + dockerfile: docker.dockerfile + restart: always + networks: + - indianpongnet + +networks: + indianpongnet: + driver: bridge diff --git a/indianpong/indianpong/settings.py b/indianpong/indianpong/settings.py index 53402b74..b25aa7c4 100644 --- a/indianpong/indianpong/settings.py +++ b/indianpong/indianpong/settings.py @@ -101,16 +101,16 @@ # Database # https://docs.djangoproject.com/en/5.0/ref/settings/#databases - +""" DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } -} +} """ -""" DATABASES = { +DATABASES = { 'default': { 'ENGINE': os.getenv('DB_ENGINE', default='django.db.backends.postgresql'), 'NAME': os.getenv('DB_NAME', default='pong'), @@ -119,7 +119,7 @@ 'HOST': 'db', # Değişiklik burada 'PORT': os.getenv('DB_PORT', default='5432'), } -} """ +} # For production, you should use a more robust caching backend like Memcached or Redis. CACHES = { diff --git a/indianpong/pong/langs.py b/indianpong/pong/langs.py index adadd4b0..a00bc411 100644 --- a/indianpong/pong/langs.py +++ b/indianpong/pong/langs.py @@ -86,6 +86,12 @@ def get_lang_en(): "setPasswordInputConfirmPasswordText": "Confirm New Password", "setPasswordButtonText": "Set ✓", + #ActivationFailed + "activationFailedPageTittle": "Activation Failed", + "activationFailedHeaderText": "Activation Failed", + "activationFailedSubHeaderText": "Your activation is failed!", + "activationFailedButtonText": "GO HOME", + #Dashboard "dashboardPageTittle": "Dashboard", "dashboardText1": "Welcome, ", @@ -449,6 +455,12 @@ def get_lang_tr(): "setPasswordInputConfirmPasswordText": "Yeni Şifreyi Onayla", "setPasswordButtonText": "Belirle ✓", + #ActivationFailed + "activationFailedPageTittle": "Aktivasyon Başarısız", + "activationFailedHeaderText": "Aktivasyon Basarisiz", + "activationFailedSubHeaderText": "Aktivasyonunuz başarısız oldu!", + "activationFailedButtonText": "ANA SAYFA'YA DÖN", + #Dashboard "dashboardPageTittle": "Ana Sayfa", "dashboardText1": "HOŞ GELDİNİZ, ", @@ -816,6 +828,12 @@ def get_lang_pt(): "setPasswordInputConfirmPasswordText": "Confirme a Nova Senha", "setPasswordButtonText": "Definir ✓", + #ActivationFailed + "activationFailedPageTittle": "Ativação Falhou", + "activationFailedHeaderText": "Ativacao Falhou", + "activationFailedSubHeaderText": "Sua ativação falhou!", + "activationFailedButtonText": "VOLTAR AO LOGIN", + #Dashboard "dashboardPageTittle": "Painel", "dashboardText1": "Bem-vindo, ", @@ -1177,6 +1195,12 @@ def get_lang_hi(): "setPasswordInputConfirmPasswordText": "नया पासवर्ड की पुष्टि करें", "setPasswordButtonText": "सेट करें ✓", + #ActivationFailed + "activationFailedPageTittle": "सक्रियण विफल", + "activationFailedHeaderText": "सक्रियण विफल", + "activationFailedSubHeaderText": "आपका सक्रियण विफल हुआ!", + "activationFailedButtonText": "वापस लॉगिन", + #Dashboard "dashboardPageTittle": "डैशबोर्ड", "dashboardText1": "स्वागत, ", diff --git a/indianpong/pong/models.py b/indianpong/pong/models.py index 59d39f62..7cc107ea 100644 --- a/indianpong/pong/models.py +++ b/indianpong/pong/models.py @@ -111,8 +111,7 @@ def get_rank_name(self): if rank_range[0] <= self.elo_point <= rank_range[1]: return rank_name return "Reinald" - - + class UserItem(models.Model): user = models.ForeignKey(UserProfile, on_delete=models.CASCADE) item = models.ForeignKey(StoreItem, on_delete=models.CASCADE) diff --git a/indianpong/pong/templates/aboutus.html b/indianpong/pong/templates/aboutus.html index 697e5ab2..b3deb9af 100644 --- a/indianpong/pong/templates/aboutus.html +++ b/indianpong/pong/templates/aboutus.html @@ -16,7 +16,7 @@
- Avatar + Avatar

Samet Çiftçi

@@ -32,7 +32,7 @@
- Avatar + Avatar

Furkan Yurtseven

@@ -47,7 +47,7 @@
- Avatar + Avatar

Yunus Emre Aktaş

@@ -62,7 +62,7 @@
- Avatar + Avatar

Enes Yağız

@@ -78,7 +78,7 @@
- Avatar + Avatar

A. Can Taşkın

diff --git a/indianpong/pong/templates/activate_account_email.html b/indianpong/pong/templates/activate_account_email.html index a6012d3a..d7d91564 100644 --- a/indianpong/pong/templates/activate_account_email.html +++ b/indianpong/pong/templates/activate_account_email.html @@ -249,6 +249,15 @@ style="display: block; height: auto; border: 0;" title="yaktas" width="32" /> + + cantaskin +
diff --git a/indianpong/pong/templates/activation_fail.html b/indianpong/pong/templates/activation_fail.html index 0f1b0487..fec7ff8e 100644 --- a/indianpong/pong/templates/activation_fail.html +++ b/indianpong/pong/templates/activation_fail.html @@ -1,10 +1,23 @@ {% extends "base.html" %} -{% block title %}Activation Failed{% endblock %} +{% block title %}{{context.activationFailedPageTittle}}{% endblock %} {% block app %}
-
Activation Failed
-
Your activation is failed!
+
{{context.activationFailedHeaderText}}
+
{{context.activationFailedSubHeaderText}}
+
{% endblock app %} \ No newline at end of file diff --git a/indianpong/pong/templates/password_reset_email.html b/indianpong/pong/templates/password_reset_email.html index c4352bed..04caac7e 100644 --- a/indianpong/pong/templates/password_reset_email.html +++ b/indianpong/pong/templates/password_reset_email.html @@ -254,6 +254,14 @@ style="display: block; height: auto; border: 0;" title="yaktas" width="32" /> + cantaskin +
diff --git a/indianpong/pong/views.py b/indianpong/pong/views.py index 4c91f85b..9ee4062f 100644 --- a/indianpong/pong/views.py +++ b/indianpong/pong/views.py @@ -105,10 +105,12 @@ def signup(request): @never_cache def activate_account(request, token): + lang = request.COOKIES.get('selectedLanguage', 'en') + context = langs.get_langs(lang) try: token = VerifyToken.objects.get(token=token) except VerifyToken.DoesNotExist: - return render(request, "activation_fail.html") + return render(request, "activation_fail.html", {"context": context}) token.user.is_verified = True token.user.save() token.delete() diff --git a/indianpong/renewdb.sh b/indianpong/renewdb.sh index 61f7e1f1..4e453092 100644 --- a/indianpong/renewdb.sh +++ b/indianpong/renewdb.sh @@ -16,6 +16,6 @@ rm -rf media/* python3 manage.py makemigrations python3 manage.py migrate python3 manage.py initdata -#python3 manage.py populate 10 +python3 manage.py populate 10 #python3 manage.py populate exec "$@" diff --git a/indianpong/static/assets/profile/ataskin.jpeg b/indianpong/static/assets/profile/ataskin.jpeg new file mode 100644 index 00000000..e4de670f Binary files /dev/null and b/indianpong/static/assets/profile/ataskin.jpeg differ diff --git a/indianpong/static/assets/profile/eyagiz.jpeg b/indianpong/static/assets/profile/eyagiz.jpeg new file mode 100644 index 00000000..37914bd0 Binary files /dev/null and b/indianpong/static/assets/profile/eyagiz.jpeg differ diff --git a/indianpong/static/assets/profile/fyurtsev.jpeg b/indianpong/static/assets/profile/fyurtsev.jpeg new file mode 100644 index 00000000..134f7578 Binary files /dev/null and b/indianpong/static/assets/profile/fyurtsev.jpeg differ diff --git a/indianpong/static/assets/profile/sciftci.jpeg b/indianpong/static/assets/profile/sciftci.jpeg new file mode 100644 index 00000000..d17f713f Binary files /dev/null and b/indianpong/static/assets/profile/sciftci.jpeg differ diff --git a/indianpong/static/assets/profile/yeaktas.jpeg b/indianpong/static/assets/profile/yeaktas.jpeg new file mode 100644 index 00000000..f85e0438 Binary files /dev/null and b/indianpong/static/assets/profile/yeaktas.jpeg differ diff --git a/indianpong/static/css/style.css b/indianpong/static/css/style.css index 53656681..689dd7fe 100644 --- a/indianpong/static/css/style.css +++ b/indianpong/static/css/style.css @@ -111,6 +111,15 @@ body { margin-bottom: 5px; } + +.big-text-activation { + animation: backInDown 1s ease; + font-size: 6em; + color: aliceblue; + font-family: "VT323", monospace; + margin-bottom: 5px; +} + .big-text-email { animation: backInDown 1s ease; font-size: 6em; diff --git a/indianpong/static/js/game/sockPong.js b/indianpong/static/js/game/sockPong.js index 6cabb109..7ca98000 100644 --- a/indianpong/static/js/game/sockPong.js +++ b/indianpong/static/js/game/sockPong.js @@ -233,350 +233,352 @@ matchsocket.onerror = function (e) { matchsocket.onmessage = function (e) { const data = JSON.parse(e.data); //console.log(data); - switch (data.type) { - case 'inlobby': - // Self send message - console.log('In lobby', data.user); - if (my.username === '') { - my.username = data.user; - } - // Take online users usernames and display them - addUsersToTable(data.users); - console.log('Online users', data.users); - break; - - case 'user.inlobby': - // Send others i joined the lobby - console.log('User in lobby', data.user); - // Add user to online users list - if (data.user !== my.username) { - addUsersToTable([data.user]); - } - if (lang === 'tr') - showToast(data.user + ' katıldı!', 'text-bg-success', 'bi bi-check-circle-fill') - else if (lang === 'hi') - showToast(data.user + ' शामिल हो गया!', 'text-bg-success', 'bi bi-check-circle-fill') - else if (lang === 'pt') - showToast(data.user + ' entrou!', 'text-bg-success', 'bi bi-check-circle-fill') - else - showToast(data.user + ' joined!', 'text-bg-success', 'bi bi-check-circle-fill') - break; - - case 'user.outlobby': - // Send others user left the lobby - console.log('User out lobby', data.user); - // Remove user from online users list - removeUserFromTable(data.user); - if (lang === 'tr') - showToast(data.user + ' ayrıldı!', 'text-bg-danger', 'bi bi-check-circle-fill') - else if (lang === 'hi') - showToast(data.user + ' चला गया!', 'text-bg-danger', 'bi bi-check-circle-fill') - else if (lang === 'pt') - showToast(data.user + ' saiu!', 'text-bg-danger', 'bi bi-check-circle-fill') - else - showToast(data.user + ' left!', 'text-bg-danger', 'bi bi-check-circle-fill') - break; - - case 'game.disconnected': - //clearInterval(BallRequest); - stopGame(); - gameOverScreen.style.display = 'block'; - showToast(`${data.disconnected} disconnected You are automatically winner`, 'text-bg-danger', 'bi bi-check-circle-fill') - console.log('Player disconnected', data.disconnected); - - case 'game.invite': - // Tell user that he/she is invited to a game - console.log('Game invite', data.inviter); - console.log('data: ', data.invitee + " " + my.username) - // Display the modal for accepting or declining the invitation - - hideInviteButtons(data.inviter, data.invitee); - - const acceptButton = document.getElementById(`acceptButton${data.inviter}`); - const declineButton = document.getElementById(`declineButton${data.inviter}`); - if (data.invitee === my.username) { + if (window.location.pathname.includes('/remote-game')) { + switch (data.type) { + case 'inlobby': + // Self send message + console.log('In lobby', data.user); + if (my.username === '') { + my.username = data.user; + } + // Take online users usernames and display them + addUsersToTable(data.users); + console.log('Online users', data.users); + break; + + case 'user.inlobby': + // Send others i joined the lobby + console.log('User in lobby', data.user); + // Add user to online users list + if (data.user !== my.username) { + addUsersToTable([data.user]); + } if (lang === 'tr') - showToast(`${data.inviter} tarafından bir oyun daveti aldınız`, 'text-bg-success', 'bi bi-check-circle-fill'); - else if (lang === 'hi') - showToast(`${data.inviter} द्वारा आपको एक खेल आमंत्रण मिला है`, 'text-bg-success', 'bi bi-check-circle-fill'); - else if (lang === 'pt') - showToast(`Você recebeu um convite de jogo de ${data.inviter}`, 'text-bg-success', 'bi bi-check-circle-fill'); + showToast(data.user + ' katıldı!', 'text-bg-success', 'bi bi-check-circle-fill') + else if (lang === 'hi') + showToast(data.user + ' शामिल हो गया!', 'text-bg-success', 'bi bi-check-circle-fill') + else if (lang === 'pt') + showToast(data.user + ' entrou!', 'text-bg-success', 'bi bi-check-circle-fill') else - showToast(`You received a game invitation from ${data.inviter}`, 'text-bg-success', 'bi bi-check-circle-fill') - acceptButton.style.display = 'flex'; - declineButton.style.display = 'flex'; - } - - acceptButton.onclick = function () { - accept(data.inviter); - acceptButton.style.display = 'none'; - declineButton.style.display = 'none'; - }; - - declineButton.onclick = function () { - decline(data.inviter); - acceptButton.style.display = 'none'; - declineButton.style.display = 'none'; - }; - - console.log(`Invited Group: ${data.inviter} vs ${data.invitee}`); - break; - - case 'tournament.match': - checkbox.disabled = true; - leftArea.style.display = 'none'; - player1.username = data.player1; - player2.username = data.player2; - my.game_id = data.game_id; - my.tournament_id = data.tournament_id; - leftArea.style.display = 'none'; - if (lang === 'tr') - showToast(`Turnuva maçı başladı! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); - else if (lang === 'hi') - showToast(`टूर्नामेंट मैच शुरू हो गया! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); - else if (lang === 'pt') - showToast(`Jogo de torneio começou! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); - else - showToast(`Tournament match started! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); - - render(); - showToast('Press Space to start the game', 'text-bg-primary', 'bi bi-exclamation-triangle-fill') - - document.addEventListener("keydown", SpaceKeyDown); - - console.log(`Tournament Id: ${data.tournament_id}, Match Id: ${data.game_id} => ${data.player1} vs ${data.player2}`); + showToast(data.user + ' joined!', 'text-bg-success', 'bi bi-check-circle-fill') break; - - case 'chat.game': - checkbox.disabled = true; - leftArea.style.display = 'none'; - player1.username = data.player1; - player2.username = data.player2; - my.game_id = data.game_id; - my.opponent_username = data.player1 === my.username ? data.player2 : data.player1; - if (lang === 'tr') - showToast(`Chat maçı başladı! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); - else if (lang === 'hi') - showToast(`टूर्नामेंट मैच शुरू हो गया! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); - else if (lang === 'pt') - showToast(`Jogo de torneio começou! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); - else - showToast(`Chat match started! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); - - render(); - showToast('Press Space to start the game', 'text-bg-primary', 'bi bi-exclamation-triangle-fill') - - document.addEventListener("keydown", SpaceKeyDown); - - console.log(`Match Id: ${data.game_id} => ${data.player1} vs ${data.player2}`); - break; - - case 'game.accept': - player1.username = data.accepted; - player2.username = data.accepter; - my.game_id = data.game_id; - if (data.accepter === my.username) { + + case 'user.outlobby': + // Send others user left the lobby + console.log('User out lobby', data.user); + // Remove user from online users list + removeUserFromTable(data.user); if (lang === 'tr') - showToast(`Davetiniz ${data.accepted} tarafından kabul edildi`, 'text-bg-success', 'bi bi-check-circle-fill'); + showToast(data.user + ' ayrıldı!', 'text-bg-danger', 'bi bi-check-circle-fill') else if (lang === 'hi') - showToast(`आपका निमंत्रण ${data.accepted} द्वारा स्वीकृत किया गया`, 'text-bg-success', 'bi bi-check-circle-fill'); + showToast(data.user + ' चला गया!', 'text-bg-danger', 'bi bi-check-circle-fill') else if (lang === 'pt') - showToast(`Seu convite foi aceito por ${data.accepted}`, 'text-bg-success', 'bi bi-check-circle-fill'); + showToast(data.user + ' saiu!', 'text-bg-danger', 'bi bi-check-circle-fill') else - showToast(`You accepted the game invitation from ${data.accepted}`, 'text-bg-success', 'bi bi-check-circle-fill'); - my.opponent_username = data.accepted; // if gerekir mi? - } - else if (data.accepted === my.username) { + showToast(data.user + ' left!', 'text-bg-danger', 'bi bi-check-circle-fill') + break; + + case 'game.disconnected': + //clearInterval(BallRequest); + stopGame(); + gameOverScreen.style.display = 'block'; + showToast(`${data.disconnected} disconnected You are automatically winner`, 'text-bg-danger', 'bi bi-check-circle-fill') + console.log('Player disconnected', data.disconnected); + + case 'game.invite': + // Tell user that he/she is invited to a game + console.log('Game invite', data.inviter); + console.log('data: ', data.invitee + " " + my.username) + // Display the modal for accepting or declining the invitation + + hideInviteButtons(data.inviter, data.invitee); + + const acceptButton = document.getElementById(`acceptButton${data.inviter}`); + const declineButton = document.getElementById(`declineButton${data.inviter}`); + if (data.invitee === my.username) { + if (lang === 'tr') + showToast(`${data.inviter} tarafından bir oyun daveti aldınız`, 'text-bg-success', 'bi bi-check-circle-fill'); + else if (lang === 'hi') + showToast(`${data.inviter} द्वारा आपको एक खेल आमंत्रण मिला है`, 'text-bg-success', 'bi bi-check-circle-fill'); + else if (lang === 'pt') + showToast(`Você recebeu um convite de jogo de ${data.inviter}`, 'text-bg-success', 'bi bi-check-circle-fill'); + else + showToast(`You received a game invitation from ${data.inviter}`, 'text-bg-success', 'bi bi-check-circle-fill') + acceptButton.style.display = 'flex'; + declineButton.style.display = 'flex'; + } + + acceptButton.onclick = function () { + accept(data.inviter); + acceptButton.style.display = 'none'; + declineButton.style.display = 'none'; + }; + + declineButton.onclick = function () { + decline(data.inviter); + acceptButton.style.display = 'none'; + declineButton.style.display = 'none'; + }; + + console.log(`Invited Group: ${data.inviter} vs ${data.invitee}`); + break; + + case 'tournament.match': + checkbox.disabled = true; + leftArea.style.display = 'none'; + player1.username = data.player1; + player2.username = data.player2; + my.game_id = data.game_id; + my.tournament_id = data.tournament_id; + leftArea.style.display = 'none'; if (lang === 'tr') - showToast(`Davetiniz ${data.accepter} tarafından kabul edildi`, 'text-bg-success', 'bi bi-check-circle-fill'); + showToast(`Turnuva maçı başladı! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); else if (lang === 'hi') - showToast(`आपका निमंत्रण ${data.accepter} द्वारा स्वीकृत किया गया`, 'text-bg-success', 'bi bi-check-circle-fill'); + showToast(`टूर्नामेंट मैच शुरू हो गया! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); else if (lang === 'pt') - showToast(`Seu convite foi aceito por ${data.accepter}`, 'text-bg-success', 'bi bi-check-circle-fill'); + showToast(`Jogo de torneio começou! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); else - showToast(`Your invitation is accepted by ${data.accepter}`, 'text-bg-success', 'bi bi-check-circle-fill'); - my.opponent_username = data.accepter; // if gerekir mi? - } - render(); - showToast('Press Space to start the game', 'text-bg-primary', 'bi bi-exclamation-triangle-fill'); + showToast(`Tournament match started! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); - - document.addEventListener("keydown", SpaceKeyDown); - - console.log(`Accepted Game Id: ${data.game_id} => ${data.accepted} vs ${data.accepter}`); - break; - - case 'game.decline': - if (data.declined === my.username) { - if (lang === 'tr') - showToast(`Davetiniz ${data.decliner} tarafından reddedildi`, 'text-bg-danger', 'bi bi-check-circle-fill'); - else if (lang === 'hi') - showToast(`आपका निमंत्रण ${data.decliner} द्वारा अस्वीकार किया गया`, 'text-bg-danger', 'bi bi-check-circle-fill'); - else if (lang === 'pt') - showToast(`Seu convite foi recusado por ${data.decliner}`, 'text-bg-danger', 'bi bi-check-circle-fill'); - else - showToast(`Your invitation is declined by ${data.decliner}`, 'text-bg-danger', 'bi bi-check-circle-fill'); - } - console.log(`Declined Game => ${data.declined} vs ${data.decliner}`); - break; - - case 'game.start': - // if they vote for Start, start the game otherwise update votes - // Start the game - checkbox.disabled = true; - leftArea.style.display = 'none'; - if (data.vote == 2) { + render(); + showToast('Press Space to start the game', 'text-bg-primary', 'bi bi-exclamation-triangle-fill') + + document.addEventListener("keydown", SpaceKeyDown); + + console.log(`Tournament Id: ${data.tournament_id}, Match Id: ${data.game_id} => ${data.player1} vs ${data.player2}`); + break; + + case 'chat.game': + checkbox.disabled = true; + leftArea.style.display = 'none'; + player1.username = data.player1; + player2.username = data.player2; + my.game_id = data.game_id; + my.opponent_username = data.player1 === my.username ? data.player2 : data.player1; if (lang === 'tr') - showToast(`3 saniye içinde ${player1.username} ve ${player2.username} arasında oyun başlıyor`, 'text-bg-success', 'bi bi-check-circle-fill'); + showToast(`Chat maçı başladı! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); else if (lang === 'hi') - showToast(`3 सेकंड में ${player1.username} और ${player2.username} के बीच खेल शुरू हो रहा है`, 'text-bg-success', 'bi bi-check-circle-fill'); + showToast(`टूर्नामेंट मैच शुरू हो गया! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); else if (lang === 'pt') - showToast(`Jogo começando em 3 segundos entre ${player1.username} e ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); + showToast(`Jogo de torneio começou! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); else - showToast(`Game starting in 3 sec between ${player1.username} and ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); + showToast(`Chat match started! ${player1.username} vs ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); + + render(); + showToast('Press Space to start the game', 'text-bg-primary', 'bi bi-exclamation-triangle-fill') + + document.addEventListener("keydown", SpaceKeyDown); + + console.log(`Match Id: ${data.game_id} => ${data.player1} vs ${data.player2}`); + break; + + case 'game.accept': + player1.username = data.accepted; + player2.username = data.accepter; + my.game_id = data.game_id; + if (data.accepter === my.username) { + if (lang === 'tr') + showToast(`Davetiniz ${data.accepted} tarafından kabul edildi`, 'text-bg-success', 'bi bi-check-circle-fill'); + else if (lang === 'hi') + showToast(`आपका निमंत्रण ${data.accepted} द्वारा स्वीकृत किया गया`, 'text-bg-success', 'bi bi-check-circle-fill'); + else if (lang === 'pt') + showToast(`Seu convite foi aceito por ${data.accepted}`, 'text-bg-success', 'bi bi-check-circle-fill'); + else + showToast(`You accepted the game invitation from ${data.accepted}`, 'text-bg-success', 'bi bi-check-circle-fill'); + my.opponent_username = data.accepted; // if gerekir mi? + } + else if (data.accepted === my.username) { + if (lang === 'tr') + showToast(`Davetiniz ${data.accepter} tarafından kabul edildi`, 'text-bg-success', 'bi bi-check-circle-fill'); + else if (lang === 'hi') + showToast(`आपका निमंत्रण ${data.accepter} द्वारा स्वीकृत किया गया`, 'text-bg-success', 'bi bi-check-circle-fill'); + else if (lang === 'pt') + showToast(`Seu convite foi aceito por ${data.accepter}`, 'text-bg-success', 'bi bi-check-circle-fill'); + else + showToast(`Your invitation is accepted by ${data.accepter}`, 'text-bg-success', 'bi bi-check-circle-fill'); + my.opponent_username = data.accepter; // if gerekir mi? + } + render(); + showToast('Press Space to start the game', 'text-bg-primary', 'bi bi-exclamation-triangle-fill'); - leaveButton.style.display = 'block'; - gameUtilsReset(); + + document.addEventListener("keydown", SpaceKeyDown); + + console.log(`Accepted Game Id: ${data.game_id} => ${data.accepted} vs ${data.accepter}`); + break; + + case 'game.decline': + if (data.declined === my.username) { + if (lang === 'tr') + showToast(`Davetiniz ${data.decliner} tarafından reddedildi`, 'text-bg-danger', 'bi bi-check-circle-fill'); + else if (lang === 'hi') + showToast(`आपका निमंत्रण ${data.decliner} द्वारा अस्वीकार किया गया`, 'text-bg-danger', 'bi bi-check-circle-fill'); + else if (lang === 'pt') + showToast(`Seu convite foi recusado por ${data.decliner}`, 'text-bg-danger', 'bi bi-check-circle-fill'); + else + showToast(`Your invitation is declined by ${data.decliner}`, 'text-bg-danger', 'bi bi-check-circle-fill'); + } + console.log(`Declined Game => ${data.declined} vs ${data.decliner}`); + break; + + case 'game.start': + // if they vote for Start, start the game otherwise update votes + // Start the game + checkbox.disabled = true; + leftArea.style.display = 'none'; + if (data.vote == 2) { + if (lang === 'tr') + showToast(`3 saniye içinde ${player1.username} ve ${player2.username} arasında oyun başlıyor`, 'text-bg-success', 'bi bi-check-circle-fill'); + else if (lang === 'hi') + showToast(`3 सेकंड में ${player1.username} और ${player2.username} के बीच खेल शुरू हो रहा है`, 'text-bg-success', 'bi bi-check-circle-fill'); + else if (lang === 'pt') + showToast(`Jogo começando em 3 segundos entre ${player1.username} e ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); + else + showToast(`Game starting in 3 sec between ${player1.username} and ${player2.username}`, 'text-bg-success', 'bi bi-check-circle-fill'); + + leaveButton.style.display = 'block'; + gameUtilsReset(); + + // make invitationMessage disappear after 3 seconds + + leaveButton.onclick = function () { + leaveGame(); + leaveButton.style.display = 'none'; + } + + // Control paddle1 with w, s keys + document.addEventListener("keydown", function(event) { + if (event.key === "w" || event.key === "W" || event.key === "ArrowUp") { + upPressed = true; + } else if (event.key === "s" || event.key === "S"|| event.key === "ArrowDown") { + downPressed = true; + } + if (event.key === '1' && likeaCheaterCount < 1 && likeaCheater == "true" && (gameMode === "Abilities" || tournament === "abilities")) { + sendAbility("likeaCheater"); + showToast('You used like a cheater!', 'text-bg-primary', 'bi bi-exclamation-triangle-fill'); + likeaCheaterCount += 1; + } + else if (event.key === '2' && fastandFuriousCount < 1 && fastandFurious == "true" && isFrozenBallActive == false && (gameMode === "Abilities" || tournament === "abilities")) { + sendAbility("fastandFurious"); + showToast('You used fast and furious!', 'text-bg-primary', 'bi bi-exclamation-triangle-fill'); + fastandFuriousCount += 1; + } + else if (event.key === '3' && frozenBallCount < 1 && frozenBall == "true" && (gameMode === "Abilities" || tournament === "abilities")) { + sendAbility("frozenBall"); + showToast('You used frozen ball!', 'text-bg-primary', 'bi bi-exclamation-triangle-fill'); + isFrozenBallActive = true; + setTimeout(function () { + isFrozenBallActive = false; + }, 3000); + frozenBallCount += 1; + } + }); + + document.addEventListener("keyup", function(event) { + if (event.key === "w" || event.key === "W" || event.key === "ArrowUp") { + upPressed = false; + } else if (event.key === "s" || event.key === "S"|| event.key === "ArrowDown") { + downPressed = false; + } + }); - // make invitationMessage disappear after 3 seconds + setTimeout(function () { + startGame(); + }, 3000); + // Ask ball coordinates every 16 milliseconds + //setInterval(BallRequest, 16); - leaveButton.onclick = function () { - leaveGame(); - leaveButton.style.display = 'none'; + console.log(`Started Game Id: ${data.game_id} => ${data.player1} vs ${data.player2}`); + } + else if (data.vote == 1) { + console.log(`Waiting for Game Id: ${data.game_id} => ${data.player1} vs ${data.player2}`); + } + else if (data.vote == 0) { + console.log(`None of the players hit space Game Id: ${data.game_id} => ${data.player1} vs ${data.player2}`); } + break; + + case 'game.leave': + //clearInterval(BallRequest); + leftArea.style.display = 'block'; + stopGame(); + var left_score = data.left_score; + var opponent_score = data.opponent_score; + var winner = data.winner; + var loser = data.loser; + document.getElementById('winnerText').innerText = winner; + document.getElementById('loserText').innerText = loser; + gameOverScreen.style.display = 'block'; + // Show some left game message with scores etc. + //showToast(`${data.left} left the game. Winner is ${winner}`, 'text-bg-success', 'bi bi-check-circle-fill'); + // maybe put restart + leaveButton.style.display = 'none'; + console.log(`Left Game Id: ${data.game_id}`); + break; + + case 'game.end': + //clearInterval(BallRequest); + leftArea.style.display = 'block'; + stopGame(); + checkbox.disabled = false; + player1.score = data.player1_score; + player2.score = data.player2_score; + + var winner = data.winner; + var loser = data.loser; + console.log('Winner: ' + winner + ' Loser: ' + loser + ' Player1 score: ' + player1.score + ' Player2 score: ' + player2.score); + document.getElementById('winnerText').innerText = winner; + document.getElementById('loserText').innerText = loser; + gameOverScreen.style.display = 'block'; + // Show some game ended message with scores etc + if (lang === 'tr') + showToast(`Oyun bitti. Kazanan ${data.winner}`, 'text-bg-success', 'bi bi-check-circle-fill'); + else if (lang === 'hi') + showToast(`खेल समाप्त हो गया। विजेता ${data.winner}`, 'text-bg-success', 'bi bi-check-circle-fill'); + else if (lang === 'pt') + showToast(`O jogo acabou. Vencedor é ${data.winner}`, 'text-bg-success', 'bi bi-check-circle-fill'); + else + showToast(`Game is ended. Winner is ${data.winner}`, 'text-bg-success', 'bi bi-check-circle-fill'); + // maybe put restart + + console.log(`Ended Game Id: ${data.game_id} => ${data.winner} won`); + break; + + case 'game.pause': + // Pause the game + console.log('Game id: ' + data.game_id + ' paused'); + break; + + case 'game.resume': + // Resume the game + console.log('Game id: ' + data.game_id + ' resumed'); + break; + + case 'game.ball': + //get ball position and update it + ballMove(data.x, data.y) + scoreUpdate(data.player1_score, data.player2_score) + //console.log(`Moving Ball Id: ${data.game_id} for ball: ${data.x} ${data.y}`); + break; + + case 'game.paddle': + //get paddle position and update it + paddleMove(data.player, data.y) + //console.log(`Moving Paddle Id: ${data.game_id} for ${data.player}: ${data.y}`); + break; + + case 'game.ability': + console.log(data.ability + ' is used!') + if (data.ability == 'giantMan' && (gameMode === "Abilities" || tournament === "abilities")) { + if (data.player == player1.username) + paddle1.height = 115 + else if (data.player == player2.username) + paddle2.height = 115 - // Control paddle1 with w, s keys - document.addEventListener("keydown", function(event) { - if (event.key === "w" || event.key === "W" || event.key === "ArrowUp") { - upPressed = true; - } else if (event.key === "s" || event.key === "S"|| event.key === "ArrowDown") { - downPressed = true; - } - if (event.key === '1' && likeaCheaterCount < 1 && likeaCheater == "true" && (gameMode === "Abilities" || tournament === "abilities")) { - sendAbility("likeaCheater"); - showToast('You used like a cheater!', 'text-bg-primary', 'bi bi-exclamation-triangle-fill'); - likeaCheaterCount += 1; - } - else if (event.key === '2' && fastandFuriousCount < 1 && fastandFurious == "true" && isFrozenBallActive == false && (gameMode === "Abilities" || tournament === "abilities")) { - sendAbility("fastandFurious"); - showToast('You used fast and furious!', 'text-bg-primary', 'bi bi-exclamation-triangle-fill'); - fastandFuriousCount += 1; - } - else if (event.key === '3' && frozenBallCount < 1 && frozenBall == "true" && (gameMode === "Abilities" || tournament === "abilities")) { - sendAbility("frozenBall"); - showToast('You used frozen ball!', 'text-bg-primary', 'bi bi-exclamation-triangle-fill'); - isFrozenBallActive = true; - setTimeout(function () { - isFrozenBallActive = false; - }, 3000); - frozenBallCount += 1; - } - }); + break; - document.addEventListener("keyup", function(event) { - if (event.key === "w" || event.key === "W" || event.key === "ArrowUp") { - upPressed = false; - } else if (event.key === "s" || event.key === "S"|| event.key === "ArrowDown") { - downPressed = false; - } - }); - - setTimeout(function () { - startGame(); - }, 3000); - // Ask ball coordinates every 16 milliseconds - //setInterval(BallRequest, 16); - - console.log(`Started Game Id: ${data.game_id} => ${data.player1} vs ${data.player2}`); - } - else if (data.vote == 1) { - console.log(`Waiting for Game Id: ${data.game_id} => ${data.player1} vs ${data.player2}`); - } - else if (data.vote == 0) { - console.log(`None of the players hit space Game Id: ${data.game_id} => ${data.player1} vs ${data.player2}`); - } - break; - - case 'game.leave': - //clearInterval(BallRequest); - leftArea.style.display = 'block'; - stopGame(); - var left_score = data.left_score; - var opponent_score = data.opponent_score; - var winner = data.winner; - var loser = data.loser; - document.getElementById('winnerText').innerText = winner; - document.getElementById('loserText').innerText = loser; - gameOverScreen.style.display = 'block'; - // Show some left game message with scores etc. - //showToast(`${data.left} left the game. Winner is ${winner}`, 'text-bg-success', 'bi bi-check-circle-fill'); - // maybe put restart - leaveButton.style.display = 'none'; - console.log(`Left Game Id: ${data.game_id}`); - break; - - case 'game.end': - //clearInterval(BallRequest); - leftArea.style.display = 'block'; - stopGame(); - checkbox.disabled = false; - player1.score = data.player1_score; - player2.score = data.player2_score; - - var winner = data.winner; - var loser = data.loser; - console.log('Winner: ' + winner + ' Loser: ' + loser + ' Player1 score: ' + player1.score + ' Player2 score: ' + player2.score); - document.getElementById('winnerText').innerText = winner; - document.getElementById('loserText').innerText = loser; - gameOverScreen.style.display = 'block'; - // Show some game ended message with scores etc - if (lang === 'tr') - showToast(`Oyun bitti. Kazanan ${data.winner}`, 'text-bg-success', 'bi bi-check-circle-fill'); - else if (lang === 'hi') - showToast(`खेल समाप्त हो गया। विजेता ${data.winner}`, 'text-bg-success', 'bi bi-check-circle-fill'); - else if (lang === 'pt') - showToast(`O jogo acabou. Vencedor é ${data.winner}`, 'text-bg-success', 'bi bi-check-circle-fill'); - else - showToast(`Game is ended. Winner is ${data.winner}`, 'text-bg-success', 'bi bi-check-circle-fill'); - // maybe put restart - - console.log(`Ended Game Id: ${data.game_id} => ${data.winner} won`); - break; - - case 'game.pause': - // Pause the game - console.log('Game id: ' + data.game_id + ' paused'); - break; - - case 'game.resume': - // Resume the game - console.log('Game id: ' + data.game_id + ' resumed'); - break; - - case 'game.ball': - //get ball position and update it - ballMove(data.x, data.y) - scoreUpdate(data.player1_score, data.player2_score) - //console.log(`Moving Ball Id: ${data.game_id} for ball: ${data.x} ${data.y}`); - break; - - case 'game.paddle': - //get paddle position and update it - paddleMove(data.player, data.y) - //console.log(`Moving Paddle Id: ${data.game_id} for ${data.player}: ${data.y}`); - break; - - case 'game.ability': - console.log(data.ability + ' is used!') - if (data.ability == 'giantMan' && (gameMode === "Abilities" || tournament === "abilities")) { - if (data.player == player1.username) - paddle1.height = 115 - else if (data.player == player2.username) - paddle2.height = 115 - - break; - - }}; + }}; + } } matchsocket.sendJSON = function (data) { diff --git a/indianpong/static/js/sockRps.js b/indianpong/static/js/sockRps.js index 1b0c43b9..c7fc40c6 100644 --- a/indianpong/static/js/sockRps.js +++ b/indianpong/static/js/sockRps.js @@ -94,124 +94,126 @@ websocket.onerror = function (e) { websocket.onmessage = function (e) { const data = JSON.parse(e.data); - switch (data.type) { - case 'insearch': - // Self send message - console.log('In search', data.user); - if (my.username === '') { - my.username = data.user; - } - // Take online users usernames and display them - addUserCount(data.user_count); - console.log('Online users', data.user_count); - break; - - case 'user.insearch': - // Send others i joined the lobby - console.log('User in search', data.user); - // Add user to online users list - if (data.user !== my.username) { - addUserCount(1); - } - - if (selectedLanguage === 'tr') - showToast(data.user + ' katıldı!', 'text-bg-success', 'bi bi-check-circle-fill') - else if (selectedLanguage === 'hi') - showToast(data.user + ' शामिल हो गया!', 'text-bg-success', 'bi bi-check-circle-fill') - else if (selectedLanguage === 'pt') - showToast(data.user + ' entrou!', 'text-bg-success', 'bi bi-check-circle-fill') - else - showToast(data.user + ' joined!', 'text-bg-success', 'bi bi-check-circle-fill') - break; - case 'user.outsearch': - // Send others user left the lobby - console.log('User out search', data.user); - // Remove user from online users list - addUserCount(-1); - if (selectedLanguage === 'tr') - showToast(data.user + ' ayrıldı!', 'text-bg-danger', 'bi bi-check-circle-fill') - else if (selectedLanguage === 'hi') - showToast(data.user + ' चला गया!', 'text-bg-danger', 'bi bi-check-circle-fill') - else if (selectedLanguage === 'pt') - showToast(data.user + ' saiu!', 'text-bg-danger', 'bi bi-check-circle-fill') - else - showToast(data.user + ' left!', 'text-bg-danger', 'bi bi-check-circle-fill') - break; - case 'game.disconnected': - // stop the game - gameOverScreen.style.display = 'block'; //? check - if (selectedLanguage === 'tr') - showToast(`${data.disconnected} bağlantısı kesildi. Otomatik olarak kazanan sizsiniz`, 'text-bg-danger', 'bi bi-check-circle-fill') - else if (selectedLanguage === 'hi') - showToast(`${data.disconnected} डिस्कनेक्ट हो गया आप ऑटोमेटिक विनर हैं`, 'text-bg-danger', 'bi bi-check-circle-fill') - else if (selectedLanguage === 'pt') - showToast(`${data.disconnected} desconectado Você é o vencedor automaticamente`, 'text-bg-danger', 'bi bi-check-circle-fill') - else - showToast(`${data.disconnected} disconnected You are automatically winner`, 'text-bg-danger', 'bi bi-check-circle-fill') - break; - case 'start': - // Start the game - my.game_id = data.game_id; - player1.username = data.player1; - player2.username = data.player2; - - - gameArea.style.visibility = "visible"; - matchmakingButton.style.display = "none"; - if (abilityStatus) { - cheaterButton.style.display = 'block'; - godthingsButton.style.display = 'block'; - } - - document.getElementById("player1Name").innerText = player1.username; - document.getElementById("player2Name").innerText = player2.username; + if (window.location.pathname.includes('/play-rps')) { + switch (data.type) { + case 'insearch': + // Self send message + console.log('In search', data.user); + if (my.username === '') { + my.username = data.user; + } + // Take online users usernames and display them + addUserCount(data.user_count); + console.log('Online users', data.user_count); + break; - if (selectedLanguage === 'tr') - showToast('Oyun başladı', 'text-bg-success', 'bi bi-check-circle-fill') - else if (selectedLanguage === 'hi') - showToast('खेल शुरू हुआ', 'text-bg-success', 'bi bi-check-circle-fill') - else if (selectedLanguage === 'pt') - showToast('Jogo começou', 'text-bg-success', 'bi bi-check-circle-fill') - else - showToast('Game started', 'text-bg-success', 'bi bi-check-circle-fill') - break; - - case 'matchmaking.notfound': - // Matchmaking found - if (selectedLanguage === 'tr') - showToast('Rakip bulunamadı', 'text-bg-danger', 'bi bi-check-circle-fill') - else if (selectedLanguage === 'hi') - showToast('विरोधी नहीं मिला', 'text-bg-danger', 'bi bi-check-circle-fill') - else if (selectedLanguage === 'pt') - showToast('Oponente não encontrado', 'text-bg-danger', 'bi bi-check-circle-fill') - else - showToast('No opponent found', 'text-bg-danger', 'bi bi-check-circle-fill') - break; - - case 'result': - // Game result - var result = data.result; - var game_id = data.game_id; - var player1_choice = data.player1_choice; - var player2_choice = data.player2_choice; - var player1_score = data.player1_score; - var player2_score = data.player2_score; + case 'user.insearch': + // Send others i joined the lobby + console.log('User in search', data.user); + // Add user to online users list + if (data.user !== my.username) { + addUserCount(1); + } + + if (selectedLanguage === 'tr') + showToast(data.user + ' katıldı!', 'text-bg-success', 'bi bi-check-circle-fill') + else if (selectedLanguage === 'hi') + showToast(data.user + ' शामिल हो गया!', 'text-bg-success', 'bi bi-check-circle-fill') + else if (selectedLanguage === 'pt') + showToast(data.user + ' entrou!', 'text-bg-success', 'bi bi-check-circle-fill') + else + showToast(data.user + ' joined!', 'text-bg-success', 'bi bi-check-circle-fill') + break; + case 'user.outsearch': + // Send others user left the lobby + console.log('User out search', data.user); + // Remove user from online users list + addUserCount(-1); + if (selectedLanguage === 'tr') + showToast(data.user + ' ayrıldı!', 'text-bg-danger', 'bi bi-check-circle-fill') + else if (selectedLanguage === 'hi') + showToast(data.user + ' चला गया!', 'text-bg-danger', 'bi bi-check-circle-fill') + else if (selectedLanguage === 'pt') + showToast(data.user + ' saiu!', 'text-bg-danger', 'bi bi-check-circle-fill') + else + showToast(data.user + ' left!', 'text-bg-danger', 'bi bi-check-circle-fill') + break; + case 'game.disconnected': + // stop the game + gameOverScreen.style.display = 'block'; //? check + if (selectedLanguage === 'tr') + showToast(`${data.disconnected} bağlantısı kesildi. Otomatik olarak kazanan sizsiniz`, 'text-bg-danger', 'bi bi-check-circle-fill') + else if (selectedLanguage === 'hi') + showToast(`${data.disconnected} डिस्कनेक्ट हो गया आप ऑटोमेटिक विनर हैं`, 'text-bg-danger', 'bi bi-check-circle-fill') + else if (selectedLanguage === 'pt') + showToast(`${data.disconnected} desconectado Você é o vencedor automaticamente`, 'text-bg-danger', 'bi bi-check-circle-fill') + else + showToast(`${data.disconnected} disconnected You are automatically winner`, 'text-bg-danger', 'bi bi-check-circle-fill') + break; + case 'start': + // Start the game + my.game_id = data.game_id; + player1.username = data.player1; + player2.username = data.player2; + + + gameArea.style.visibility = "visible"; + matchmakingButton.style.display = "none"; + if (abilityStatus) { + cheaterButton.style.display = 'block'; + godthingsButton.style.display = 'block'; + } + + document.getElementById("player1Name").innerText = player1.username; + document.getElementById("player2Name").innerText = player2.username; + + if (selectedLanguage === 'tr') + showToast('Oyun başladı', 'text-bg-success', 'bi bi-check-circle-fill') + else if (selectedLanguage === 'hi') + showToast('खेल शुरू हुआ', 'text-bg-success', 'bi bi-check-circle-fill') + else if (selectedLanguage === 'pt') + showToast('Jogo começou', 'text-bg-success', 'bi bi-check-circle-fill') + else + showToast('Game started', 'text-bg-success', 'bi bi-check-circle-fill') + break; - if (my.username === player1.username && player1_choice === "LIKEACHEATER") - cheaterAbilities = true; - else if (my.username === player2.username && player2_choice === "LIKEACHEATER") - cheaterAbilities = true; - if (my.username === player1.username && player1_choice === "GODOFTHINGS") - godthingsAbilities = true; - else if (my.username === player2.username && player2_choice === "GODOFTHINGS") - godthingsAbilities = true; + case 'matchmaking.notfound': + // Matchmaking found + if (selectedLanguage === 'tr') + showToast('Rakip bulunamadı', 'text-bg-danger', 'bi bi-check-circle-fill') + else if (selectedLanguage === 'hi') + showToast('विरोधी नहीं मिला', 'text-bg-danger', 'bi bi-check-circle-fill') + else if (selectedLanguage === 'pt') + showToast('Oponente não encontrado', 'text-bg-danger', 'bi bi-check-circle-fill') + else + showToast('No opponent found', 'text-bg-danger', 'bi bi-check-circle-fill') + break; - scoreUpdate(player1_score, player2_score); - - displayResults([player1_choice, player2_choice]); - displayWinner(result); - break; + case 'result': + // Game result + var result = data.result; + var game_id = data.game_id; + var player1_choice = data.player1_choice; + var player2_choice = data.player2_choice; + var player1_score = data.player1_score; + var player2_score = data.player2_score; + + if (my.username === player1.username && player1_choice === "LIKEACHEATER") + cheaterAbilities = true; + else if (my.username === player2.username && player2_choice === "LIKEACHEATER") + cheaterAbilities = true; + if (my.username === player1.username && player1_choice === "GODOFTHINGS") + godthingsAbilities = true; + else if (my.username === player2.username && player2_choice === "GODOFTHINGS") + godthingsAbilities = true; + + scoreUpdate(player1_score, player2_score); + + displayResults([player1_choice, player2_choice]); + displayWinner(result); + break; + } } }