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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3"
}
4 changes: 4 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ django-cors-headers = "*"
gunicorn = "*"
django-heroku = "*"
django-rest-api = "*"
"psycopg2-binary" = "*"
dj-database-url = "*"
whitenoise = "*"

[dev-packages]
pylint = "*"

[requires]
python_version = "3.7"
296 changes: 203 additions & 93 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Cameron's Trello Board URL: https://trello.com/b/cjRCp0Co/lambdamud

Choose a reason for hiding this comment

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

Good that you added a link to your URL here. It's a small thing but many students forget/ignore that instruction.


# Adventure Project Week

This week you'll be implementing a frontend interface for a multi-user
Expand Down
8 changes: 6 additions & 2 deletions adv_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""

import os
from decouple import config
from decouple import config, Csv

# 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 +26,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', cast=bool)

ALLOWED_HOSTS = []
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())


# Application definition
Expand Down Expand Up @@ -55,6 +55,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 @@ -148,6 +149,9 @@
# 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())

del DATABASES['default']['OPTIONS']['sslmode'] # <-- Add this line
3 changes: 2 additions & 1 deletion adv_project/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib import admin
from django.urls import path, include
from django.urls import path, re_path, include
from django.conf.urls import include
from rest_framework.authtoken import views

urlpatterns = [
path('admin/', admin.site.urls),
Expand Down
13 changes: 11 additions & 2 deletions adventure/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,18 @@ def move(request):
players = room.playerNames(player_id)
return JsonResponse({'name':player.user.username, 'title':room.title, 'description':room.description, 'players':players, 'error_msg':"You cannot move that way."}, safe=True)


@csrf_exempt
@api_view(["POST"])
def say(request):
# IMPLEMENT
return JsonResponse({'error':"Not yet implemented"}, safe=True, status=500)
player = request.user.player
player_id = player.id
player_uuid = player.uuid
data = json.loads(request.body)
message = data['message']
room = player.room()
currentPlayerUUIDs = room.playerUUIDs(player_id)
for p_uuid in currentPlayerUUIDs:

Choose a reason for hiding this comment

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

This say command looks great! It might be nice to have a few more comments. Also have you thought about how you might handle the case where a user tries to send an empty message?

pusher.trigger(f'p-channel-{p_uuid}', u'broadcast', {'message':f'{player.user.username} says {message}.'})
return JsonResponse({'username':player.user.username, 'message': message}, safe=True, status=200)

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.1 on 2018-12-10 23:32

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)),
],
),
]
1 change: 1 addition & 0 deletions adventure/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Room(models.Model):
s_to = models.IntegerField(default=0)
e_to = models.IntegerField(default=0)
w_to = models.IntegerField(default=0)
# going to try implementing xy coords
def connectRooms(self, destinationRoom, direction):
destinationRoomID = destinationRoom.id
try:
Expand Down
3 changes: 3 additions & 0 deletions key_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import random
key = ''.join([random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])

Choose a reason for hiding this comment

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

This is cool, I like how you set a file to do this secret key generation. It's good reusability and accessibility.

print(key)