rename the project
This commit is contained in:
0
transcendence/__init__.py
Normal file
0
transcendence/__init__.py
Normal file
53
transcendence/abstract/AbstractRoom.py
Normal file
53
transcendence/abstract/AbstractRoom.py
Normal file
@ -0,0 +1,53 @@
|
||||
from .AbstractRoomMember import AbstractRoomMember
|
||||
|
||||
class AbstractRoom:
|
||||
|
||||
def __init__(self, room_manager):
|
||||
self._member_list: [AbstractRoomMember] = []
|
||||
self.room_manager = room_manager
|
||||
|
||||
def broadcast(self, detail: str, data: dict = {}):
|
||||
for member in self._member_list:
|
||||
member: AbstractRoomMember
|
||||
member.send(detail, data)
|
||||
|
||||
def clear(self):
|
||||
self._member_list.clear()
|
||||
|
||||
def get_member_by_socket(self, socket: WebsocketConsumer):
|
||||
for member in self._member_list:
|
||||
member: AbstractRoomMember
|
||||
if (member.socket is socket):
|
||||
return member
|
||||
return None
|
||||
|
||||
def get_member_by_user_id(self, user_id: int):
|
||||
for member in self._member_list:
|
||||
member: AbstractRoomMember
|
||||
if (member.user_id == user_id):
|
||||
return member
|
||||
return None
|
||||
|
||||
|
||||
def append(self, member: AbstractRoomMember):
|
||||
tmp: AbstractRoomMember = self.get_member_by_user_id(member.user_id)
|
||||
if (tmp is not None):
|
||||
tmp.send("Connection close: Another connection open with the same user id.")
|
||||
self.remove(tmp)
|
||||
member.accept()
|
||||
self._member_list.append(waiter)
|
||||
|
||||
def remove(self, member: AbstractRoomMember):
|
||||
self._member_list.remove(member)
|
||||
waiter.disconnect()
|
||||
|
||||
def empty(self):
|
||||
for _ in self._waiter_list:
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_users_id(self):
|
||||
return [waiter.user_id for waiter in self._waiter_list]
|
||||
|
||||
def __len__(self):
|
||||
return len(self._waiter_list)
|
18
transcendence/abstract/AbstractRoomManager.py
Normal file
18
transcendence/abstract/AbstractRoomManager.py
Normal file
@ -0,0 +1,18 @@
|
||||
from .AbstractRoom import AbstractRoom
|
||||
|
||||
class AbstractRoomManager:
|
||||
|
||||
def __init__(self):
|
||||
self._room_list: [AbstractRoom] = []
|
||||
|
||||
def get(self, mode: int):
|
||||
for room in self._room_list:
|
||||
room: A
|
||||
if (waiting_room._mode == mode):
|
||||
return waiting_room
|
||||
tmp: WaitingRoom = WaitingRoom(self, mode)
|
||||
self._waiting_rooms.append(tmp)
|
||||
return tmp
|
||||
|
||||
def remove(self, waiting_room: WaitingRoom):
|
||||
self._waiting_rooms.remove(waiting_room)
|
16
transcendence/abstract/AbstractRoomMember.py
Normal file
16
transcendence/abstract/AbstractRoomMember.py
Normal file
@ -0,0 +1,16 @@
|
||||
class AbstractRoomMember:
|
||||
|
||||
def __init__(self, user_id: int, socket: WebsocketConsumer):
|
||||
self.user_id: int = user_id
|
||||
self.socket: WebsocketConsumer = socket
|
||||
|
||||
def send(self, detail: str, data: dict = {}):
|
||||
raw_data: dict = {"detail": detail}
|
||||
raw_data.update(data)
|
||||
self.socket.send(text_data=json.dumps(raw_data))
|
||||
|
||||
def accept(self):
|
||||
self.socket.accept()
|
||||
|
||||
def disconnect(self):
|
||||
self.socket.disconnect(200)
|
30
transcendence/asgi.py
Normal file
30
transcendence/asgi.py
Normal file
@ -0,0 +1,30 @@
|
||||
"""
|
||||
ASGI config for trancendence project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
from channels.routing import ProtocolTypeRouter, URLRouter
|
||||
from channels.auth import AuthMiddlewareStack
|
||||
|
||||
import chat.routing
|
||||
import matchmaking.routing
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'trancendence.settings')
|
||||
|
||||
application = ProtocolTypeRouter({
|
||||
'http':get_asgi_application(),
|
||||
'websocket':AuthMiddlewareStack(
|
||||
URLRouter(
|
||||
chat.routing.websocket_urlpatterns +
|
||||
matchmaking.routing.websocket_urlpatterns
|
||||
)
|
||||
)
|
||||
})
|
||||
|
155
transcendence/settings.py
Normal file
155
transcendence/settings.py
Normal file
@ -0,0 +1,155 @@
|
||||
"""
|
||||
Django settings for transcendence project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.2.6.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.2/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-18!@88-wm-!skec9^n-85n(f$my^#mh3!#@f=_e@=*arh_yyjj'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
CORS_ORIGIN_ALLOW_ALL = False
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = ["https://django.chauvet.pro"]
|
||||
|
||||
CORS_ORIGIN_WHITELIST = (
|
||||
'http://localhost:8000',
|
||||
)
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'channels',
|
||||
'daphne',
|
||||
|
||||
'tournament.apps.TournamentConfig',
|
||||
'matchmaking.apps.MatchmakingConfig',
|
||||
'games.apps.GamesConfig',
|
||||
'accounts.apps.AccountsConfig',
|
||||
'profiles.apps.ProfilesConfig',
|
||||
'frontend.apps.FrontendConfig',
|
||||
'chat.apps.ChatConfig',
|
||||
|
||||
'corsheaders',
|
||||
'rest_framework',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
]
|
||||
|
||||
ASGI_APPLICATION = 'transcendence.asgi.application'
|
||||
|
||||
CHANNEL_LAYERS = {
|
||||
'default' :{
|
||||
'BACKEND':'channels.layers.InMemoryChannelLayer'
|
||||
}
|
||||
}
|
||||
|
||||
MIDDLEWARE = [
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'transcendence.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'transcendence.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
27
transcendence/urls.py
Normal file
27
transcendence/urls.py
Normal file
@ -0,0 +1,27 @@
|
||||
"""
|
||||
URL configuration for trancendence project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('api/profiles/', include('profiles.urls')),
|
||||
path('api/accounts/', include('accounts.urls')),
|
||||
path('api/chat/', include('chat.urls')),
|
||||
path('api/tournaments/', include('tournament.urls')),
|
||||
path('', include('frontend.urls')),
|
||||
]
|
16
transcendence/wsgi.py
Normal file
16
transcendence/wsgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for trancendence project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'trancendence.settings')
|
||||
|
||||
application = get_wsgi_application()
|
Reference in New Issue
Block a user