Skip to content

Commit

Permalink
Merge pull request #118 from fleizean/mpa
Browse files Browse the repository at this point in the history
Mpa
  • Loading branch information
fleizean committed Feb 21, 2024
2 parents d7833d9 + 69a6b49 commit ff9ab5e
Show file tree
Hide file tree
Showing 17 changed files with 903 additions and 261 deletions.
5 changes: 4 additions & 1 deletion indianpong/indianpong/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,7 @@
EMAIL_HOST_PASSWORD = environ.get("EMAIL_HOST_PASSWORD", default="hxog cqpq jltp xjhi")
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False """
EMAIL_USE_SSL = False """

""" import certifi
environ['SSL_CERT_FILE'] = certifi.where() """
3 changes: 2 additions & 1 deletion indianpong/indianpong/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
from pong.views import aboutus, follow_unfollow, update_winner, inventory, store, activate_account, play_ai, pong_game_find, rps_game_find, auth_callback, chat, friends, match_history, password_change, password_reset, password_reset_done, rankings, dashboard, game, index, auth, chat_room, profile_view, search, set_password, signup, login_view, logout_view, profile_settings, setup_two_factor_auth, generate_jwt_token, create_tournament, create_tournament_match, start_chat, room
from pong.views import aboutus, follow_unfollow, local_game, update_winner, inventory, store, activate_account, play_ai, pong_game_find, rps_game_find, auth_callback, chat, friends, match_history, password_change, password_reset, password_reset_done, rankings, dashboard, game, index, auth, chat_room, profile_view, search, set_password, signup, login_view, logout_view, profile_settings, setup_two_factor_auth, generate_jwt_token, create_tournament, create_tournament_match, start_chat, room

urlpatterns = [
path('admin/', admin.site.urls),
Expand All @@ -32,6 +32,7 @@
path('rps-game-find', rps_game_find, name='rps_game_find'),
path('pong-game-find', pong_game_find, name='pong_game_find'),
path('play-ai', play_ai, name='play_ai'),
path('local-game', local_game, name='local_game'),
path('chat/', chat, name='chat'),
path("start_chat/<str:username>", start_chat, name="start_chat"),
path("chat/<str:room_name>/", room, name="room"),
Expand Down
4 changes: 2 additions & 2 deletions indianpong/pong/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class UserProfileForm(UserCreationForm):
email = forms.EmailField(label='Email', widget=forms.EmailInput(attrs={'class': 'input'}))
password1 = forms.CharField(label='Password', widget=forms.PasswordInput(attrs={'class': 'input'}))
password2 = forms.CharField(label='RePassword', widget=forms.PasswordInput(attrs={'class': 'input'}))
#avatar = forms.ImageField(required=False ,label='Avatar', widget=forms.FileInput(attrs={'class': 'input'}))
avatar = forms.ImageField(required=False ,label='Avatar', widget=forms.FileInput(attrs={'class': 'input'}))
class Meta:
model = UserProfile
fields = ['username', 'displayname', 'email', 'password1', 'password2']
fields = ['username', 'displayname', 'email', 'password1', 'password2', 'avatar']

""" def confirm_login_allowed(self, user):
if not user.is_verified:
Expand Down
23 changes: 10 additions & 13 deletions indianpong/pong/management/commands/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@
import string

class Command(BaseCommand):
help = 'Populates the database with 10 users'
usernames = [
"Indian1", "Indian2", "Indian3", "Indian4", "Indian5",
"Indian6", "Indian7", "Indian8", "Indian9", "Indian10"
]
displaynames = [
"Original Indian 1", "Original Indian 2", "Original Indian 3", "Original Indian 4", "Original Indian 5",
"Original Indian 6", "Original Indian 7", "Original Indian 8", "Original Indian 9", "Original Indian 10"
]
help = 'Populates the database with users'

def add_arguments(self, parser):
parser.add_argument('num_users', type=int, help='Number of users to create')

def handle(self, *args, **options):
for i in range(10):
username = self.usernames[i]
displayname = self.displaynames[i]
num_users = options['num_users']
for i in range(num_users):
username = "Indian" + str(i)
displayname = "Original Indian" + str(i)
email = username + '@indian.com'
password = '123456a.' # Replace with your desired password

UserProfile.objects.create_user(username=username, email=email, displayname=displayname, password=password)

self.stdout.write(self.style.SUCCESS('Successfully populated the database with 10 users.'))
self.stdout.write(self.style.SUCCESS(f'Successfully populated the database with {num_users} users.'))
237 changes: 111 additions & 126 deletions indianpong/pong/migrations/0001_initial.py

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions indianpong/pong/templates/local-game.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% extends "base.html" %}

{% load static %}

{% block title %}Play with AI{% endblock title %}

{% block app %}
{% include "_nav.html" %}

<div class="container-top" data-paddlecolor="{{paddlecolor}}" data-playgroundcolor="{{playgroundcolor}}">
<div class="ai-game">
<div id="gameStartInfos" class="game-start-info">
<h1 class="localGameText">1v1 Local Game</h1>
<div class="input-box">
<label class="localGamePlayerText" for="player1Name">Player1 Name</label>
<input class="input-style" type="text" id="player1Name">

<label class="localGamePlayerText" for="player1Name">Player2 Name</label>
<input class="input-style" type="text" id="player2Name">

<div class="selectorGame">
<label class="localGamePlayerText" for="maxScore">Max Score</label>
<select class="form-select" id="maxScore">
<option selected value="3">3</option>
<option value="5">5</option>
<option value="7">7</option>
<option value="10">10</option>
</select>
</div>

<div class="selectorGame">
<label class="localGamePlayerText" for="gameMode">Game Mode</label>
<select class="form-select" id="gameMode">
<option selected value="Vanilla">Vanilla</option>
<option value="Abilities">Abilities</option>
</select>
</div>
</div>


<button class="btn btn-outline-success" id="startButton">Start</button>
</div>
<canvas id="pongCanvas" width="800" height="600" style="display: none;"></canvas>
<div id="gameOverScreen" class="game-over">
<h1>Game Over</h1>
<p id="winnerText" class="winnerName"></p>
<button id="restartButton">Restart</button>
<button id="exitButton">Exit</button>
</div>
</div>
</div>
<script type=module src="{% static "js/local-game.js" %}"></script>
{% endblock %}
8 changes: 7 additions & 1 deletion indianpong/pong/templates/play-ai.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
<div class="ai-game">

<canvas id="pongCanvas" width="800" height="600"></canvas>
<div id="gameOverScreen" class="game-over">
<h1>Game Over</h1>
<p id="winnerText" class="winnerName"></p>
<button id="restartButton">Restart</button>
<button id="exitButton">Exit</button>
</div>
</div>
</div>
<script type=module src="{% static "js/socketless.js" %}"></script>
<script type=module src="{% static "js/play-ai.js" %}"></script>
{% csrf_token %}
{% endblock %}
5 changes: 4 additions & 1 deletion indianpong/pong/templates/pong-game-find.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ <h3 class="pong-game-text">Welcome to Tournament Pong Find</h3>
<div class="ai-btn">
<a href="/play-ai"><div class="ponggamebtn-ai">Play With AI <i class="bi bi-robot"></i></div></a>
</div>
<div class="opponent-btn">
<div class="ai-btn">
<a href="/local-game"><div class="ponggamebtn-local">Local Game <i class="bi bi-wifi-off"></i></div></a>
</div>
<div class="ai-btn">
<a href="/room-list"><div class="ponggamebtn">Search Opponent <i class="bi bi-person-arms-up"></i></div></a>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion indianpong/pong/templates/rps-game-find.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h3 class="pong-game-text">Welcome to Tournament RPS Find</h3>
<div class="ai-btn">
<div class="ponggamebtn-ai">Play With AI <i class="bi bi-robot"></i></div>
</div>
<div class="opponent-btn">
<div class="ai-btn">
<a href="/room-list"><div class="ponggamebtn">Search Opponent <i class="bi bi-person-arms-up"></i></div></a>
</div>
</div>
Expand Down
20 changes: 0 additions & 20 deletions indianpong/pong/templates/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,6 @@
</div>

<script>
document.addEventListener('DOMContentLoaded', function () {
// Toast'ı gösterme fonksiyonu
function showToastFailed(content) {
const liveToast = document.getElementById('liveToast');
var toastContent = document.querySelector('#liveToast .fw-semibold');
toastContent.textContent = content;
const toast = new bootstrap.Toast(liveToast);
toast.show();
setTimeout(function() {
toast.hide();
}, 3000);
}
const urlParams = new URLSearchParams(window.location.search);
const statusValue = urlParams.get('status');
if (statusValue === 'failed_42email') {
showToastFailed("You cannot register with email 42");
}

});


function showToast(content, status, iconClass) {
const liveToast = document.getElementById('liveToast');
Expand Down
8 changes: 8 additions & 0 deletions indianpong/pong/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def get_upload_to(instance, filename):
filename = "%s_%s.%s" % (instance.username, get_random_string(length=7), ext)
return filename

def get_equipped_item_value(user_items, item_name, default_item):
if (item_name == "My Playground" or item_name == "My Beautiful Paddle" or item_name == "My Beautiful AI"):
item = user_items.filter(item__name=item_name, is_equipped=True).first()
return item.whatis if item else default_item
else:
item = user_items.filter(item__name=item_name, is_equipped=True).first()
return "true" if item else "false"

def pass2fa(request, user_obj):
if user_obj.has_2fa:
hashed_secret = hashlib.sha512((user_obj.username + os.environ.get("OTP_SECRET")).encode("utf-8")).digest()
Expand Down
37 changes: 23 additions & 14 deletions indianpong/pong/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
Room,
Message,
)
from .utils import delete_from_media, pass2fa
from .utils import delete_from_media, get_equipped_item_value, pass2fa
from os import environ
from datetime import datetime, timedelta
from django.utils.http import urlsafe_base64_decode
Expand Down Expand Up @@ -99,7 +99,7 @@ def signup(request):
)
obj.send_verification_email(request, user)
messages.success(request, "Please check your email to verify your account.")
return HttpResponseRedirect("login?status=success")
return HttpResponseRedirect("login")
else:
form = UserProfileForm()
return render(request, "signup.html", {"form": form})
Expand Down Expand Up @@ -722,14 +722,23 @@ def play_ai(request):

return render(request, "play-ai.html", {"ainametag": ainametag, "paddlecolor": paddlecolor, "playgroundcolor": playgroundcolor, "giantman": giantman, "likeacheater": likeacheater, "fastandfurious": fastandfurious, "rageoffire": rageoffire, "frozenball": frozenball})


def get_equipped_item_value(user_items, item_name, default_item):
if (item_name == "My Playground" or item_name == "My Beautiful Paddle" or item_name == "My Beautiful AI"):
item = user_items.filter(item__name=item_name, is_equipped=True).first()
return item.whatis if item else default_item
else:
item = user_items.filter(item__name=item_name, is_equipped=True).first()
return "true" if item else "false"
@never_cache
@login_required()
def local_game(request):
user_items = UserItem.objects.filter(user=request.user)

# Just Customizations - PONG
player2name = "Player 2"
paddlecolor = get_equipped_item_value(user_items, "My Beautiful Paddle", "black")
playgroundcolor = get_equipped_item_value(user_items, "My Playground", "lightgrey")

# Just Abilities - PONG
giantman = get_equipped_item_value(user_items, "Giant-Man", "None")
likeacheater = get_equipped_item_value(user_items, "Like a Cheater", "None")
fastandfurious = get_equipped_item_value(user_items, "Fast and Furious", "None")
rageoffire = get_equipped_item_value(user_items, "Rage of Fire", "None")
frozenball = get_equipped_item_value(user_items, "Frozen Ball", "None")
return render(request, "local-game.html", {"player2name": player2name, "paddlecolor": paddlecolor, "playgroundcolor": playgroundcolor, "giantman": giantman, "likeacheater": likeacheater, "fastandfurious": fastandfurious, "rageoffire": rageoffire, "frozenball": frozenball})


@never_cache
Expand Down Expand Up @@ -960,12 +969,12 @@ def update_winner(request):
loser_profile = get_object_or_404(UserProfile, username=loser)

if winner:
winner_profile.indian_wallet += random.randint(200, 300)
winner_profile.elo_point += random.randint(1, 10)
winner_profile.indian_wallet += random.randint(35, 55)
winner_profile.elo_point += random.randint(20, 30)
winner_profile.save()
elif loser:
loser_profile.indian_wallet += random.randint(100, 200)
lose_elo -= random.randint(1, 6)
loser_profile.indian_wallet += random.randint(20, 30)
lose_elo -= random.randint(1, 10)
if lose_elo < loser_profile.elo_point:
loser_profile.elo_point -= lose_elo
loser_profile.save()
Expand Down
1 change: 1 addition & 0 deletions indianpong/renewdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +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
exec "$@"
62 changes: 52 additions & 10 deletions indianpong/static/css/game-find.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
text-decoration:none !important;
}

.opponent-btn {
margin-top: 1em;
margin-bottom: 0.5em;
}


.opponent-btn a {
text-decoration: none;
}

.pong-game-text {
text-align: center;
color: white;
Expand Down Expand Up @@ -130,4 +120,56 @@
.ponggamebtn-ai:hover:after {
left: 400px;
transition: .3s ease-in-out;
}



.ponggamebtn-local {
font-size: 36px;
font-family: 'Rajdhani', sans-serif;
text-align: center;
line-height: 85px;
color: #fff;
margin: 0 auto;
width: 350px;
height: 85px;
background: linear-gradient(#b2c114, #31380e);
border: 3px #b2c114 solid;
border-radius: 5px;
text-shadow: 0 0 20px rgba(255,255,255,0.3);
transition: .1s;
transform: scale(1);
cursor: pointer;
box-shadow: 0 0 50px rgba(0,117,9,0.5);
overflow: hidden;
}

.ponggamebtn-local:hover {
text-shadow: 0 0 20px rgba(255,255,255,0.5);
transform: scale(1.05);
}

.ponggamebtn-local:active {
background: linear-gradient(#1f8258, #114435);
text-shadow: 0 0 20px rgba(255,255,255,0.5);
transform: scale(1);
box-shadow: 0 0 75px rgba(43,137,68,0.5);
}

.ponggamebtn-local:after {
content: "";
position: relative;
top: -120px;
left: -90px;
display: block;
width: 35px;
height: 150px;
background: rgba(255, 255, 255, 0.5);
transform: rotate(35deg);
transition: none;
}

.ponggamebtn-local:hover:after {
left: 400px;
transition: .3s ease-in-out;
}
Loading

0 comments on commit ff9ab5e

Please sign in to comment.