Merge pull request #1 from evgen-app/dev

merging dev into stable
This commit is contained in:
Alexandr Karpov 2022-07-02 17:05:44 +03:00 committed by GitHub
commit 5ce7e0edb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 155 additions and 17 deletions

2
.gitignore vendored
View File

@ -1,6 +1,6 @@
.idea .idea
static/ static/
media/ media/uploads/
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/

View File

@ -1,15 +1,23 @@
# chess_rpg_backend # chess_rpg_backend
Backend for chess rpg game DEV branch for backend for chess rpg game
<hr>
##### dev server for up to date endpoints(web socket not provided)
- https://dev.akarpov.ru
<hr>
### installation ### installation
```shell ```shell
$ python3 manage.py makemigrations & python3 manage.py migrate $ python3 manage.py makemigrations & python3 manage.py migrate
$ python3 manage.py loaddata media/dump_data/hero_model_fixture.json
$ docker run -p 6379:6379 -d redis:5 $ docker run -p 6379:6379 -d redis:5
``` ```
### run ### run
```shell ```shell
$ python3 manage.py runserver 0.0.0.0:8000 $ daphne -b 0.0.0.0 -p 8000 chess_backend.asgi:application
``` ```
### Описание команд сокетов ### Описание команд сокетов

View File

@ -11,10 +11,14 @@ DEBUG = True
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
if DEBUG:
ALLOWED_HOSTS = ["*"]
INSTALLED_APPS = [ INSTALLED_APPS = [
"django.contrib.sessions", "django.contrib.sessions",
"django.contrib.auth", "django.contrib.auth",
"django.contrib.contenttypes", "django.contrib.contenttypes",
"django.contrib.staticfiles",
"django.contrib.messages", "django.contrib.messages",
# Packages # Packages
"rest_framework", "rest_framework",
@ -25,10 +29,26 @@ INSTALLED_APPS = [
] ]
if DEBUG: if DEBUG:
INSTALLED_APPS.append("django.contrib.staticfiles")
INSTALLED_APPS.append("drf_yasg") INSTALLED_APPS.append("drf_yasg")
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',
],
},
},
]
MIDDLEWARE = [ MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware", "django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware", "django.contrib.sessions.middleware.SessionMiddleware",

View File

@ -22,8 +22,10 @@ schema_view = get_schema_view(
permission_classes=(permissions.AllowAny,), permission_classes=(permissions.AllowAny,),
) )
urlpatterns = [path("api/", include("game.urls"))] + static( urlpatterns = (
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT [path("api/", include("game.urls"))]
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
) )
if settings.DEBUG: if settings.DEBUG:
@ -43,4 +45,4 @@ if settings.DEBUG:
schema_view.with_ui("redoc", cache_timeout=0), schema_view.with_ui("redoc", cache_timeout=0),
name="schema-redoc", name="schema-redoc",
), ),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) ]

31
docker-compose.yaml Normal file
View File

@ -0,0 +1,31 @@
services:
daphne:
build:
dockerfile: ./build/Dockerfile
context: .
image: daphne
volumes:
- type: bind
source: ${ROOT_DIR}/logs
target: /app/logs
ports:
- "8080:8080"
- "8000:8000"
depends_on:
- postgres
tty: true
container_name: daphne_server
postgres:
image: postgres:latest
ports:
- "5432:5432"
environment:
- POSTGRES_USER=daphne
- POSTGRES_PASSWORD=daphne
- POSTGRES_DB=daphne
container_name: daphne_database
redis:
image: redis:latest
ports:
- "6379:6379"
container_name: daphne_redis

View File

@ -97,7 +97,7 @@ class Hero(models.Model):
added = models.DateTimeField(auto_now_add=True) added = models.DateTimeField(auto_now_add=True)
type = models.CharField(blank=False, choices=HeroTypes.choices, max_length=7) type = models.CharField(blank=False, choices=HeroTypes.choices, max_length=7)
model = models.ForeignKey("HeroModelSet", on_delete=models.CASCADE) model_f = models.ForeignKey("HeroModelSet", on_delete=models.CASCADE)
health = models.IntegerField( health = models.IntegerField(
validators=[MinValueValidator(1), MaxValueValidator(10)], blank=False validators=[MinValueValidator(1), MaxValueValidator(10)], blank=False
) )
@ -108,14 +108,8 @@ class Hero(models.Model):
validators=[MinValueValidator(1), MaxValueValidator(10)], blank=False validators=[MinValueValidator(1), MaxValueValidator(10)], blank=False
) )
def idle_img(self): def model(self):
return self.idle_img_f.image.url return self.model_f.model.url
def attack_img(self):
return self.attack_img_f.image.url
def die_img(self):
return self.die_img_f.image.url
def __str__(self): def __str__(self):
return f"{self.type} {self.player.name}" return f"{self.type} {self.player.name}"
@ -145,7 +139,7 @@ class Hero(models.Model):
class HeroModelSet(models.Model): class HeroModelSet(models.Model):
hero_type = models.CharField(blank=False, choices=HeroTypes.choices, max_length=7) hero_type = models.CharField(blank=False, choices=HeroTypes.choices, max_length=7)
model = models.ImageField(upload_to="uploads/") model = models.FileField(upload_to="uploads/")
def __str__(self): def __str__(self):
return f"{self.hero_type} model file" return f"{self.hero_type} model file"

BIN
media/dump_data/dump.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

View File

@ -0,0 +1,34 @@
[
{
"model": "game.heromodelset",
"pk": 1,
"fields": {
"hero_type": "KING",
"model": "dump_data/dump.jpg"
}
},
{
"model": "game.heromodelset",
"pk": 2,
"fields": {
"hero_type": "WARRIOR",
"model": "dump_data/dump_mx4zxHq.jpg"
}
},
{
"model": "game.heromodelset",
"pk": 3,
"fields": {
"hero_type": "ARCHER",
"model": "dump_data/dump_d6lH7IJ.jpg"
}
},
{
"model": "game.heromodelset",
"pk": 4,
"fields": {
"hero_type": "WIZARD",
"model": "dump_data/dump_1P13Svy.jpg"
}
}
]

44
nginx.conf Normal file
View File

@ -0,0 +1,44 @@
server {
# Base settings for client body size
client_max_body_size 64M;
client_body_timeout 10;
send_timeout 10;
keepalive_timeout 10;
client_header_timeout 10;
client_body_buffer_size 64M;
client_header_buffer_size 64M;
client_max_header_size 64M;
location /static {
allow all;
autoindex off;
root /var/www;
}
location /media {
allow all;
autoindex off;
root /var/www;
}
location / {
allow all;
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
listen 443 ssl;
# ssl settings
# ssl_certificate /etc/nginx/ssl/nginx.crt;
# ssl_certificate_key /etc/nginx/ssl/nginx.key;
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
}

View File

@ -1,9 +1,14 @@
import json import json
import os
import django
from asgiref.sync import sync_to_async from asgiref.sync import sync_to_async
from channels.generic.websocket import AsyncWebsocketConsumer from channels.generic.websocket import AsyncWebsocketConsumer
from channels.layers import get_channel_layer from channels.layers import get_channel_layer
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "chess_backend.settings")
django.setup()
from game.models import Deck from game.models import Deck
from room.models import PlayerInQueue, Room, PlayerInRoom, GameState from room.models import PlayerInQueue, Room, PlayerInRoom, GameState
from room.services.room_create import create_room from room.services.room_create import create_room