mirror of
https://github.com/evgen-app/chess_rpg_backend.git
synced 2024-11-22 09:37:05 +03:00
commit
5ce7e0edb1
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,6 +1,6 @@
|
|||
.idea
|
||||
static/
|
||||
media/
|
||||
media/uploads/
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
|
12
README.md
12
README.md
|
@ -1,15 +1,23 @@
|
|||
# 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
|
||||
```shell
|
||||
$ 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
|
||||
```
|
||||
|
||||
### run
|
||||
```shell
|
||||
$ python3 manage.py runserver 0.0.0.0:8000
|
||||
$ daphne -b 0.0.0.0 -p 8000 chess_backend.asgi:application
|
||||
```
|
||||
|
||||
### Описание команд сокетов
|
||||
|
|
|
@ -11,10 +11,14 @@ DEBUG = True
|
|||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
if DEBUG:
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.staticfiles",
|
||||
"django.contrib.messages",
|
||||
# Packages
|
||||
"rest_framework",
|
||||
|
@ -25,10 +29,26 @@ INSTALLED_APPS = [
|
|||
]
|
||||
|
||||
if DEBUG:
|
||||
INSTALLED_APPS.append("django.contrib.staticfiles")
|
||||
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 = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
|
|
|
@ -22,8 +22,10 @@ schema_view = get_schema_view(
|
|||
permission_classes=(permissions.AllowAny,),
|
||||
)
|
||||
|
||||
urlpatterns = [path("api/", include("game.urls"))] + static(
|
||||
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT
|
||||
urlpatterns = (
|
||||
[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:
|
||||
|
@ -43,4 +45,4 @@ if settings.DEBUG:
|
|||
schema_view.with_ui("redoc", cache_timeout=0),
|
||||
name="schema-redoc",
|
||||
),
|
||||
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
]
|
||||
|
|
31
docker-compose.yaml
Normal file
31
docker-compose.yaml
Normal 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
|
|
@ -97,7 +97,7 @@ class Hero(models.Model):
|
|||
added = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
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(
|
||||
validators=[MinValueValidator(1), MaxValueValidator(10)], blank=False
|
||||
)
|
||||
|
@ -108,14 +108,8 @@ class Hero(models.Model):
|
|||
validators=[MinValueValidator(1), MaxValueValidator(10)], blank=False
|
||||
)
|
||||
|
||||
def idle_img(self):
|
||||
return self.idle_img_f.image.url
|
||||
|
||||
def attack_img(self):
|
||||
return self.attack_img_f.image.url
|
||||
|
||||
def die_img(self):
|
||||
return self.die_img_f.image.url
|
||||
def model(self):
|
||||
return self.model_f.model.url
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.type} {self.player.name}"
|
||||
|
@ -145,7 +139,7 @@ class Hero(models.Model):
|
|||
|
||||
class HeroModelSet(models.Model):
|
||||
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):
|
||||
return f"{self.hero_type} model file"
|
||||
|
|
BIN
media/dump_data/dump.jpg
Normal file
BIN
media/dump_data/dump.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 145 KiB |
BIN
media/dump_data/dump_1P13Svy.jpg
Normal file
BIN
media/dump_data/dump_1P13Svy.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 145 KiB |
BIN
media/dump_data/dump_d6lH7IJ.jpg
Normal file
BIN
media/dump_data/dump_d6lH7IJ.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 145 KiB |
BIN
media/dump_data/dump_mx4zxHq.jpg
Normal file
BIN
media/dump_data/dump_mx4zxHq.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 145 KiB |
34
media/dump_data/hero_model_fixture.json
Normal file
34
media/dump_data/hero_model_fixture.json
Normal 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
44
nginx.conf
Normal 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;
|
||||
}
|
|
@ -1,9 +1,14 @@
|
|||
import json
|
||||
import os
|
||||
import django
|
||||
|
||||
from asgiref.sync import sync_to_async
|
||||
from channels.generic.websocket import AsyncWebsocketConsumer
|
||||
from channels.layers import get_channel_layer
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "chess_backend.settings")
|
||||
django.setup()
|
||||
|
||||
from game.models import Deck
|
||||
from room.models import PlayerInQueue, Room, PlayerInRoom, GameState
|
||||
from room.services.room_create import create_room
|
||||
|
|
Loading…
Reference in New Issue
Block a user