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

Huthman King: LambdaMUD #124

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
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": "/Users/Huff/.local/share/virtualenvs/Intro-Django-N-_rix2Y/bin/python"
}
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.

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Adventure Project Week

deployed on netlify (frontend): https://adventureatlambda.netlify.com/
deployed on heroku (backend): https://mudlambdahuthman.herokuapp.com/admin

https://trello.com/b/XzgFsOz8/lambdamud

This week you'll be implementing a frontend interface for a multi-user
dungeon (MUD) game called _LambdaMUD_. The backend is partially written
but needs to be completed.
Expand Down Expand Up @@ -368,3 +373,7 @@ django_heroku.settings(locals())

del DATABASES['default']['OPTIONS']['sslmode'] # <-- Add this line
```


b8fb9e5ef75a088c9d9ba5135f0ddaff65c7293c

19 changes: 17 additions & 2 deletions 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


# 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 @@ -23,11 +25,12 @@
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY')



# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', cast=bool)

ALLOWED_HOSTS = []

ALLOWED_HOSTS = config('ALLOWED_HOSTS').split(',')

# Application definition

Expand Down Expand Up @@ -55,6 +58,7 @@

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand All @@ -64,6 +68,7 @@
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
]
#CORS_ORIGIN_ALLOW_ALL = True

ROOT_URLCONF = 'adv_project.urls'

Expand All @@ -89,12 +94,17 @@
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

#DATABASES = {}
#DATABASES['default'] = dj_database_url.config(default=os.getenv('DATABASE_URL'))


DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
DATABASES['default'] = dj_database_url.config(conn_max_age=600)


# Password validation
Expand Down Expand Up @@ -148,6 +158,11 @@
# 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']

15 changes: 13 additions & 2 deletions adventure/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,16 @@ def move(request):
@csrf_exempt
@api_view(["POST"])
def say(request):
# IMPLEMENT
return JsonResponse({'error':"Not yet implemented"}, safe=True, status=500)
player = request.user.player
p_uuid = player.uuid
data = json.loads(request.body)
msg = data['message']
room = player.room()
player_id = player.id
currentPlayerUUIDs = room.playerUUIDs(player_id)
if len(currentPlayerUUIDs) != 0:
for p_uuid in currentPlayerUUIDs:
pusher.trigger(f'p-channel-{p_uuid}', u'broadcast', {'message':f'{player.user.username}: {msg}'})
return JsonResponse({'msg': "success!"}, safe=True, status=200)
else:
return JsonResponse({'msg': "no one is around to message"}, safe=True, status=500)
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 18:43

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)),
],
),
]
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ requests-oauthlib==1.0.0
six==1.11.0
urllib3==1.23
whitenoise==4.1

pip freeze > requirements.txt
15 changes: 15 additions & 0 deletions util/create_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,18 @@
p.currentRoom=r_outside.id
p.save()




'''curl -X GET -H 'Authorization: Token 735bd88c3e1f931b3b4396667eba7f09e0dbb1c7'

curl -X POST -H 'Authorization: Token 735bd88c3e1f931b3b4396667eba7f09e0dbb1c7' -H "Content-Type: application/json" -d '{"direction":"n"}' https://mudlambdahuthman.herokuapp.com/api/adv/move/

b8fb9e5ef75a088c9d9ba5135f0ddaff65c7293c
curl -X GET -H 'Authorization: Token 735bd88c3e1f931b3b4396667eba7f09e0dbb1c7' https://mudlambdahuthman.herokuapp.com/api/adv/init/

curl -X POST -H "Content-Type: application/json" -d '{"username":"mudadmin", "password":"123admin"}' https://mudlambdahuthman.herokuapp.com/api/login/

735bd88c3e1f931b3b4396667eba7f09e0dbb1c7

curl -X POST -H 'Authorization: Token 735bd88c3e1f931b3b4396667eba7f09e0dbb1c7' -H "Content-Type: application/json" -d '{"direction":"n"}' https://mudlambdahuthman.herokuapp.com/api/login/'''