Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ __pycache__/
*.py[cod]
*$py.class


# Django stuff:
*.log
local_settings.py
Expand Down
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ django-cors-headers = "*"
gunicorn = "*"
django-heroku = "*"
django-rest-api = "*"
"psycopg2-binary" = "*"
dj-database-url = "*"
whitenoise = "*"

[dev-packages]

Expand Down
216 changes: 124 additions & 92 deletions Pipfile.lock

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion adv_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import os
from decouple import config
import dj_database_url

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand All @@ -26,7 +27,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', cast=bool)

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['.herokuapp.com']


# Application definition
Expand Down Expand Up @@ -55,6 +56,7 @@

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down Expand Up @@ -96,6 +98,8 @@
}
}

DATABASES['default'] = dj_database_url.config(default = config('DATABASE_URL'), conn_max_age=600)


# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
Expand Down Expand Up @@ -148,6 +152,7 @@
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

import django_heroku
django_heroku.settings(locals())
11 changes: 10 additions & 1 deletion adventure/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,13 @@ def move(request):
@api_view(["POST"])
def say(request):
# IMPLEMENT
return JsonResponse({'error':"Not yet implemented"}, safe=True, status=500)
player = request.user.player # --> Grab player

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good comment here, would be nice to have a few more throughout your code.

data = json.loads(request.body)
player_id = player.id
response = data['message']
room = player.room() # --> Grab room
currentPlayerUUIDs = room.playerUUIDs(player_id)
for uuid in currentPlayerUUIDs:
pusher.trigger(f'p-channel-{uuid}', u'broadcast', {'say': f'{player.user.username} says {response}'})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this broadcasts an alert to the player who said the message too, but ideally you would want to exclude the player who performed say from the list of who receives the alert. This differentiates "say" from "shout"


return JsonResponse({'say': f'{player.user.username} says {response}'}, safe=True)
39 changes: 39 additions & 0 deletions adventure/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 2.1.4 on 2018-12-10 17:41

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Player',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('currentRoom', models.IntegerField(default=0)),
('uuid', models.UUIDField(default=uuid.uuid4, unique=True)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Room',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(default='DEFAULT TITLE', max_length=50)),
('description', models.CharField(default='DEFAULT DESCRIPTION', max_length=500)),
('n_to', models.IntegerField(default=0)),
('s_to', models.IntegerField(default=0)),
('e_to', models.IntegerField(default=0)),
('w_to', models.IntegerField(default=0)),
],
),
]
27 changes: 14 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
asn1crypto==0.24.0
certifi==2018.8.24
certifi==2018.11.29
cffi==1.11.5
chardet==3.0.4
cryptography==2.3.1
cryptography==2.4.2
defusedxml==0.5.0
dj-database-url==0.5.0
Django==2.1.1
django-allauth==0.37.1
Django==2.1.4
django-allauth==0.38.0
django-cors-headers==2.4.0
django-heroku==0.3.1
django-rest-api==0.1.5
django-rest-auth==0.9.3
djangorestframework==3.8.2
djangorestframework==3.9.0
gunicorn==19.9.0
idna==2.7
idna==2.8
ndg-httpsclient==0.5.1
oauthlib==2.1.0
psycopg2==2.7.5
pusher==2.0.1
psycopg2==2.7.6.1
psycopg2-binary==2.7.6.1
pusher==2.0.2
pyasn1==0.4.4
pycparser==2.19
pyOpenSSL==18.0.0
python-decouple==3.1
python3-openid==3.1.0
pytz==2018.5
requests==2.19.1
pytz==2018.7
requests==2.21.0
requests-oauthlib==1.0.0
six==1.11.0
urllib3==1.23
whitenoise==4.1
six==1.12.0
urllib3==1.24.1
whitenoise==4.1.2