Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alexis-Reyes MUD #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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 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
204 changes: 118 additions & 86 deletions Pipfile.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Trello.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TRELLO LINK:
https://trello.com/b/AWtjYmt7/lambda-mud

PULL REQUEST LINK:
https://github.com/CSPT1-TEAMS/LambdaMUD-Project/pull/3
10 changes: 9 additions & 1 deletion adv_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import os
from decouple import config
import dj_database_url
from whitenoise import WhiteNoise

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

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ["0.0.0.0", "127.0.0.1", ".herokuapp.com"]


# Application definition
Expand Down Expand Up @@ -54,7 +56,9 @@
SITE_ID = 1

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 @@ -143,11 +147,15 @@

USE_TZ = True

DATABASES = {}

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

# Static files (CSS, JavaScript, Images)
# 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())
30 changes: 28 additions & 2 deletions adventure/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
# instantiate pusher
pusher = Pusher(app_id=config('PUSHER_APP_ID'), key=config('PUSHER_KEY'), secret=config('PUSHER_SECRET'), cluster=config('PUSHER_CLUSTER'))


# if it finds and puts the uuid in a json, that means this finds the token and returns that user data
# gets additional information [player current room]
# the uuid for use in pusher?

@csrf_exempt
@api_view(["GET"])
def initialize(request):
Expand All @@ -22,6 +27,10 @@ def initialize(request):
players = room.playerNames(player_id)
return JsonResponse({'uuid': uuid, 'name':player.user.username, 'title':room.title, 'description':room.description, 'players':players}, safe=True)

# Finds the direction/ room the player goes to
# If initialized in a room, returns current room/ otherwise returns the next room the user entered
# uses uuid for pusher to update pusher that user entered another room


# @csrf_exempt
@api_view(["POST"])
Expand Down Expand Up @@ -59,9 +68,26 @@ def move(request):
players = room.playerNames(player_uuid)
return JsonResponse({'name':player.user.username, 'title':room.title, 'description':room.description, 'players':players, 'error_msg':"You cannot move that way."}, safe=True)

# gives a json obj (response) that contains a message given by the user
# must tell pusher that a user sent a message


@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
room = player.room()

# jsonobj is inside of our req.body

data = json.loads(request.body)
message = data['message']
players = room.playerNames(player_id)
currentPlayerUUIDs = room.playerUUIDs(player_id)
for p_uuid in currentPlayerUUIDs:
pusher.trigger(f'p-channel-{p_uuid}', u'broadcast', {'message':f'{player.user.username} says {message}'})

return JsonResponse({'name':player.user.username, 'title':room.title, 'description':room.description, 'players':players, 'error_msg':""}, 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.3 on 2018-11-29 03:07

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)),
],
),
]
23 changes: 12 additions & 11 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.10.15
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.3
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
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.20.1
requests-oauthlib==1.0.0
six==1.11.0
urllib3==1.23
whitenoise==4.1
urllib3==1.24.1
whitenoise==4.1.2