Skip to content

Commit

Permalink
Merge pull request #27 from mc-putchar/dev
Browse files Browse the repository at this point in the history
The end of dev
  • Loading branch information
CarloCattano authored Oct 1, 2024
2 parents baf11cf + efa8e4f commit dcc3d1f
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 148 deletions.
4 changes: 2 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ POSTGRES_PASSWORD= # Set password for Postgres database user
# Django
DJANGO_SECRET_KEY= # Django secret key
DJANGO_ALLOWED_HOSTS=localhost # Django allowed hosts: comma separated, no []
DJANGO_TRUSTED_ORIGINS=https://localhost # Django trusted origins: no trailing /
DJANGO_TRUSTED_ORIGINS=https://0.0.0.0 # Django trusted origins: no trailing /
# OAuth
CLIENT_ID= # OAuth client ID
CLIENT_SECRET= # OAuth client secret
REDIRECT_URI=https://localhost/redirect # same as registered OAuth redirect URI
REDIRECT_URI=https://localhost:4243/redirect # same as registered OAuth redirect URI
# Blockchain
HARDHAT_PRIVATE_KEY=
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ COLOUR_MAGB := \033[1;35m
COLOUR_CYN := \033[36m
COLOUR_CYNB := \033[1;36m

.PHONY: help up down start stop re logs logs-django ps db-shell migrate debug clean shred collect schema newkey swapmode maintenance clitest testlogin tests
.PHONY: help up down start stop re logs logs-django ps db-shell migrate debug clean shred collect schema newkey swapmode maintenance cli CLI testlogin tests

help: # Display this helpful message
@awk 'BEGIN { \
Expand Down Expand Up @@ -117,8 +117,14 @@ debug: # DEBUG MODE
@echo -e 'using $(DC) and $(SRC)'
$(DC) -f $(SRC) --profile debug up --build

clitest: # CLI test
cd transcendCLI && source .venv/bin/activate && python $(CLI)
cli CLI: # run CLI
@if [[ ! -d transcendCLI/.venv ]]; then \
{ echo -e "$(COLOUR_CYNB)Setting up virtual environment...$(COLOUR_END)"; \
python3 -m venv transcendCLI/.venv && \
pip install -r transcendCLI/requirements.txt && \
exit 0; } \
fi
cd transcendCLI && source .venv/bin/activate && python $(CLI) --url=$(DOMAIN)

testlogin: # Selenium tests
# docker exec ft_transcendence-django-1 python test_selenium.py
Expand Down
1 change: 1 addition & 0 deletions pong/ONLINE_GAME.md → ONLINE_GAME.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

## Server side
TOP SECRET
:detective:

# Game websocket listener

Expand Down
53 changes: 34 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# _ft_transcendence_

[![Uptime Robot status](https://img.shields.io/uptimerobot/status/m797505515-6190c28211f4dbd75e68ae49?up_message=ONLINE&up_color=green&down_message=DOWN&down_color=red&style=plastic&link=https%3A%2F%2Fstats.uptimerobot.com%2FiK804X9tfp)](https://stats.uptimerobot.com/iK804X9tfp)
![Cloudflare](https://img.shields.io/badge/Cloudflare-F38020?style=plastic&logo=Cloudflare&logoColor=white)
![Etherium](https://img.shields.io/badge/Ethereum-3C3C3D?logo=ethereum&logoColor=fff&style=plastic)
![GitHub top language](https://img.shields.io/github/languages/top/mc-putchar/ft_transcendence?style=plastic&logo=javascript)
![42 Berlin](https://img.shields.io/badge/Made_for-42Berlin-black?style=plastic)

> This project is about doing something you’ve never done before.
> Remind yourself the beginning of your journey in computer science.
Expand All @@ -10,13 +14,15 @@
![IMAGE_PLACEHOLDER](pong/static/img/jinja-dashboard.png)

# _Description_:

Free open-source web platform, mainly for playing Pong games and tournaments.
Inspired by the classic Pong game of the 70s, infused with modern features and technologies.

# _Setup_:

- Everything is launched with a single command line to run
```bash
$ make
make up
```
- Follow the Setup Wizard to configure the project for your instance.
Required information:
Expand Down Expand Up @@ -44,23 +50,46 @@ Inspired by the classic Pong game of the 70s, infused with modern features and t
- Make mentions with `@<username>` (only works if at the beginning of a message)
- Use commands with `/<command> <args>`
- Command `/duel <username>` to challenge another online user to a Pong duel
- Command `/duel4P <username1> <username2> <username3>` to challenge 3 other online users to a 4 Player Pong match

## _Pong Game_

> 🏓
![Pong3D](pong/static/img/pong3d.gif)

### Local
- Play Pong on a local computer against another player or AI opponent
- Different variants of Pong available:
- 2D Pong
- 3D Pong
- 4 Player Pong


### Online
- Play Pong online against other users

## _Tournaments_
### Tournaments
- Join or create tournaments to compete against other players
- Setup and play local tournaments on the same computer

## **CLI**

Showing off the beauty of terminals (are sexy), `transcendCLI` makes it possible to login, interact with the live chat and play online games with other players, all without leaving the comfortable blink of the tty cursor.

For a stunning terminal client, use ft_ascii pong cli, included as submodule:

```bash
git submodule update --init
make -C ft_ascii
make cli
```

Once authenticated, check more options typing `/help`

## _Music:_
[![pixabay](https://img.shields.io/badge/pixabay-green?style=plastic)](https://pixabay.com/de/music/search/arcade/)

## _Blockchain_
- Use blockchain to store tournament results (Opt-in feature)

# _Points:_

Expand All @@ -74,28 +103,14 @@ Inspired by the classic Pong game of the 70s, infused with modern features and t
0.5 - Additional browser support
0.5 - Support of all devices 1
1 - Standard User managment 1
1 - Blockchain 1
1 - Remote Players 1
1 - Live Chat 1
0.5 - Server-Side Rendering
0.5 - GDPR compliance 1
1 - Server-Side Pong Game with API 1
1 - AI Opponent 1
```
1 - CLI Pong 1
required 7 , current total = 13

potential extras:

```
1 - Additional Game 1
1 - CLI Pong 1
1 - JWT and 2FA 1
```

for ft_ascii pong cli:
```git submodule update --init```


### Music:
[pixabay](https://pixabay.com/de/music/search/arcade/)
12 changes: 5 additions & 7 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Documentation:
- [x] README.md
- [ ] LICENSE
- [X] LICENSE
- [x] API schema
- [ ] Dependencies and their justifications
- [ ] ? code documentation
Expand Down Expand Up @@ -45,9 +45,9 @@
- [ ] validate user email
- [ ] password recovery
- [ ] ? easy 2FA on top
- [ ] change password
- [x] change password
- [x] anonymize account (ensure no personal data is stored)
- [ ] delete account (adjust cascading in db on delete)
- [x] delete account (adjust cascading in db on delete)
- [x] resolve 42 acount username conflict
- [ ] connect 42 account (after conventional registration)
- [x] ? display blockchain user address? status? (after optin)
Expand All @@ -73,7 +73,7 @@
- [x] server side game logic
- [x] 2D client option
- [x] 3D client option
- [ ] mobile controls
- [x] mobile controls (2D client only)
- [ ] improve predictive client
- [ ] global matchmaking
- [ ] spectating mode
Expand All @@ -97,9 +97,7 @@

- [ ] swag:
- [x] notifications
- [ ] modals:
- [ ] need better controls over them (closing, dissmissing, persisting)
- [ ] improve look
- [x] modals
- [x] sound controls
- [ ] ensure device support

Expand Down
24 changes: 24 additions & 0 deletions UNLICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>
10 changes: 0 additions & 10 deletions pong/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,6 @@ class Meta:
def __str__(self):
return f"{self.player} in {self.match} scored {self.score} and {'won' if self.winner else 'lost'} "

# def get_opponent(self):
# """Returns the opponent of the player in the match."""
# try:
# opponent = self.match.players.exclude(player=self.player).first()
# except PlayerMatch.DoesNotExist:
# return None
# if opponent:
# return opponent.player
# return None

def get_opponent(self):
"""Returns the PlayerMatch instance of the opponent in the match."""
try:
Expand Down
9 changes: 3 additions & 6 deletions pong/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@

DEBUG = env.bool('DEBUG', default=False)

ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=[
'localhost', '127.0.0.1', 'pong42.ktano-studio.com'])
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['localhost', '127.0.0.1'])

CSRF_TRUSTED_ORIGINS = env.list('DJANGO_TRUSTED_ORIGINS', default=['https://localhost:4243', 'https://127.0.0.1:4243',
'https://pong42.ktano-studio.com'])
CSRF_TRUSTED_ORIGINS = env.list('DJANGO_TRUSTED_ORIGINS', default=['https://localhost:4243', 'https://127.0.0.1:4243'])

CORS_ALLOWED_ORIGINS = env.list('DJANGO_TRUSTED_ORIGINS', default=['https://localhost:4243', 'https://127.0.0.1:4243',
'https://pong42.ktano-studio.com'])
CORS_ALLOWED_ORIGINS = env.list('DJANGO_TRUSTED_ORIGINS', default=['https://localhost:4243', 'https://127.0.0.1:4243'])
CORS_ALLOW_METHODS = ['GET', 'POST']
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_HEADERS = [
Expand Down
3 changes: 0 additions & 3 deletions pong/game/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ def get_match(match_id):
@database_sync_to_async
def update_player_match(match, player, score, win=False):
PlayerMatch.objects.filter(match=match, player=player).update(score=score,winner=win)
logger.debug(f"Player {type(player)} {player.username} updated with score {score}")
logger.debug(f"Match {type(match)} {match.id} updated with score {score}")
logger.debug(f"Score {type(score)}")

class PongGameConsumer(AsyncWebsocketConsumer):

Expand Down
45 changes: 36 additions & 9 deletions pong/pong/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import requests

from django.conf import settings
from django.contrib import messages
from django.contrib.auth import update_session_auth_hash
from django.contrib.auth.models import User
from django.contrib.auth.forms import PasswordChangeForm
from django.core.files.images import ImageFile
from django.http import HttpResponse, JsonResponse
from django.shortcuts import redirect, render
Expand Down Expand Up @@ -138,29 +141,53 @@ def get_user_info(request, username):
'match_history': played,
'tournament_history': TournamentPlayer.objects.filter(player=profile, tournament__status='closed')
}
# logger.info(context)
return context

def update_profile(request, user):
if request.method == 'POST':
u_form = UserUpdateForm(request.POST, instance=user)
p_form = ProfileUpdateForm(
request.POST, request.FILES, instance=user.profile)
cp_form = ChangePasswordForm(request.POST)
if u_form.is_valid() and p_form.is_valid():
u_form.save()
p_form.save()
if cp_form.is_valid():
user.set_password(cp_form.cleaned_data['password'])
user.save()
cp_form = PasswordChangeForm(user, request.POST)
try:
if u_form.is_valid() and p_form.is_valid():
u_form.save()
p_form.save()
if cp_form.is_valid():
cp_form.save()
update_session_auth_hash(request, user)
refresh = RefreshToken.for_user(user)
access_token = str(refresh.access_token)
refresh_token = str(refresh)
messages.success(request, 'Password updated successfully')
context = {
'u_form': u_form,
'p_form': p_form,
'cp_form': cp_form,
'username': user.username,
'profilepic': user.profile.image.url,
'access_token': access_token,
'refresh_token': refresh_token,
'user': get_user_from_validated_token(access_token),
}
except Exception as e:
messages.error(request, 'An error occurred')
context = {
'u_form': u_form,
'p_form': p_form,
'cp_form': cp_form,
'username': user.username,
'profilepic': user.profile.image.url
}
else:
u_form = UserUpdateForm(instance=user)
p_form = ProfileUpdateForm(instance=user.profile)
cp_form = ChangePasswordForm()
cp_form = PasswordChangeForm(user)

context = {
'u_form': u_form,
'p_form': p_form,
'cp_form': cp_form,
'username': user.username,
'profilepic': user.profile.image.url
}
Expand Down
Binary file added pong/static/img/pong3d.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dcc3d1f

Please sign in to comment.