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

LambdaMUD--Anthony Greb #131

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

agreb17
Copy link

@agreb17 agreb17 commented Dec 10, 2018

Adventure Project Week

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.

Using API requests, clients are able to create, read, update and delete
data on remote servers but what if the server needs to initiate a
request to the client? Say, to alert them that another player has
entered their room or that they have received a chat message. This is
where WebSockets come in.

WebSocket is a computer communications protocol, providing full-duplex
communication channels over a single TCP connection. You will be using
the Pusher service to handle the WebSocket connections for your project.
You can read more about them here.

You are to treat this week as if you are working at a company and the
instructor is your client. The project managers will be your main
support throughout the week.

The main objective of this week is to develop the MVP feature set listed
below using any other technologies you have learned here at Lambda
School. There are design files in this repository you should use as a
creative guide.

Git Commits

  • You are required to showcase progress with at least 1 commit a day.
    This will let your project manager know where you are and if you need
    help. This also allows the client to get progress reports from the
    company in a real world setting.

Trello Set Up:

  • Create a Trello account if you don't have one already
  • Create a new board called "LambdaMUD - {Your Name}"
  • Create lists titled backlog,To Do, In Progress, and Done
  • Fill in the To Do list with the MVP features listed below
  • Fill in the backlog list with all the extra features listed below
  • Share your board with the project manager that has been assigned to you. If you have not been assigned yet, reach out to your lead PM for guidance
  • Add your Trello URL to your project's README.md file. Commit the change, push it to your repository & submit a pull request

https://trello.com/b/62H8aKgt/lambdamud-anthony-greb

MVP Features:

Client

  • Create a standalone frontend app that communicates with the server via API calls
  • Be able to create a new account on the server (implemented on server)
  • Be able to log in to the server (implemented on server)
  • Create an interface that displays the current room name, its description and the other players in the room
  • Be able to move between rooms and update the display accordingly (implemented on server)
  • Be able to use a say command to say things that other people in the room will see (server implementation incomplete)
  • Upon login, subscribe to a Pusher channel based on the player's universally unique id: p-channel-<uuid>
  • Bind the player channel to broadcast events and display the messages to the player
  • Alert the player when someone enters and leaves the current room (implemented on server)
  • Alert the player when someone in the current room says something (server implementation incomplete)

Server

  • Create a new API endpoint for say which broadcasts a message to other players in the current room
  • Deploy to Heroku

General

  • Header comments in all source files that describe overall what the file does
  • Header comments on all functions that describe what the function does, function arguments, and return values

Upon your first commit, please submit a Pull Request and add both the
Trello Set Up and MVP Features Task lists to your first Pull
Request comment:

## Trello Set Up:

- [ ] Create a Trello account if you don't have one already
- [ ] Create a new board called "LambdaMUD - {Your Name}"
- [ ] Create lists titled `backlog`,`To Do`, `In Progress`, and `Done`
- [ ] Fill in the `To Do` list with the MVP features listed below
- [ ] Fill in the `backlog` list with all the extra features listed below
- [ ] Share your board with the project manager that has been assigned to you. If you have not been assigned yet, reach out to your lead PM for guidance
- [ ] Add your Trello URL to your project's README.md file. Commit the change, push it to your repository & submit a pull request

## MVP Features:

#### Client
- [ ] Create a standalone frontend app that communicates with the server via API calls
- [ ] Be able to create a new account on the server (implemented on server)
- [ ] Be able to log in to the server (implemented on server)
- [ ] Create an interface that displays the current room name, its description and the other players in the room
- [ ] Be able to move between rooms and update the display accordingly (implemented on server)
- [ ] Be able to use a `say` command to say things that other people in the room will see (server implementation incomplete)
- [ ] Upon login, subscribe to a Pusher channel based on the player's universally unique id: `p-channel-<uuid>`
- [ ] Bind the player channel to `broadcast` events and display the messages to the player
- [ ] Alert the player when someone enters and leaves the current room (implemented on server)
- [ ] Alert the player when someone in the current room says something (server implementation incomplete)

#### Server
- [ ] Create a new API endpoint for `say` which broadcasts a message to other players in the current room
- [ ] Deploy to Heroku

#### General
- [ ] Header comments in all source files that describe overall what the file does
- [ ] Header comments on all functions that describe what the function does, function arguments, and return values

Once you have completed the Minimum Viable Product requirements,
direct message your project manager for approval. If approved, you may
continue working on the Extra Features.

Once your MVP has been approved, you have been given a feature list that
the client would love to have completed. Your goal would be to finish
MVP as soon as you can and get working the list of features.

Extra Features:

  • Add a shout command that broadcasts a message to every player
  • Add a whisper command that sends a private message to a single player
  • Disconnect inactive players
  • Replace text-based movement with graphical navigation
  • Expand the world map
  • Add a search function to find the shortest path to another player (hint: BFS)
  • Generate and display a map of the world
  • Add the ability to pick up and drop objects
  • Add NPCs that wander around the world (hint: look into Celery)
  • Add weapons
  • Add combat with NPCs
  • Add PvP combat

Directions

Set up a Pusher account

  • Sign up for a free account on pusher.com
  • Create a new app
  • Take note of your credentials
    • app_id, key, secret, cluster
  • Look through the provided sample code and documentation

Set up your local server

  • Set up your virtual environment

    • pipenv --three
    • pipenv install
    • pipenv shell
  • Add your secret credentials

    • Create .env in the root directory of your project
    • Add your pusher credentials and secret key
      SECRET_KEY='<your_secret_key>'
      DEBUG=True
      PUSHER_APP_ID=<your_app_id>
      PUSHER_KEY=<your_pusher_key>
      PUSHER_SECRET=<your_pusher_secret>
      PUSHER_CLUSTER=<your_pusher_cluster>
      
  • Run database migrations

    • ./manage.py makemigrations
    • ./manage.py migrate
  • Add rooms to your database

    • ./manage.py shell
    • Copy/paste the contents of util/create_world.py into the Python interpreter
    • Exit the interpreter
  • Run the server

    • ./manage.py runserver

Test API commands

  • Windows users might want to use Postman to test API commands

Registration

  • curl -X POST -H "Content-Type: application/json" -d '{"username":"testuser", "password1":"testpassword", "password2":"testpassword"}' localhost:8000/api/registration/
  • Response:
    • {"key":"6b7b9d0f33bd76e75b0a52433f268d3037e42e66"}

Login

  • Request:
    • curl -X POST -H "Content-Type: application/json" -d '{"username":"testuser", "password":"testpassword"}' localhost:8000/api/login/
  • Response:
    • {"key":"6b7b9d0f33bd76e75b0a52433f268d3037e42e66"}

Initialize

  • Request: (Replace token string with logged in user's auth token)
    • curl -X GET -H 'Authorization: Token 6b7b9d0f33bd76e75b0a52433f268d3037e42e66' localhost:8000/api/adv/init/
  • Response:
    • {"uuid": "c3ee7f04-5137-427e-8591-7fcf0557dd7b", "name": "testuser", "title": "Outside Cave Entrance", "description": "North of you, the cave mount beckons", "players": []}

Move

  • Request: (Replace token string with logged in user's auth token)
    • curl -X POST -H 'Authorization: Token 6b7b9d0f33bd76e75b0a52433f268d3037e42e66' -H "Content-Type: application/json" -d '{"direction":"n"}' localhost:8000/api/adv/move/
  • Response:
    • {"name": "testuser", "title": "Foyer", "description": "Dim light filters in from the south. Dusty\npassages run north and east.", "players": [], "error_msg": ""}
  • Pusher broadcast:
    • Players in previous room receive a message: <name> has walked north.
    • Players in next room receive a message: <name> has entered from the south.

Say (NOT YET IMPLEMENTED)

  • Request: (Replace token string with logged in user's auth token)
    • curl -X POST -H 'Authorization: Token 6b7b9d0f33bd76e75b0a52433f268d3037e42e66' -H "Content-Type: application/json" -d '{"message":"Hello, world!"}' localhost:8000/api/adv/say/
  • Pusher broadcast:
    • Players in current room receive a message: <name> says "Hello, world!"

Deploy server to Heroku

Client Frontend

  • Fork the LambdaMUD-Client repo and put your front-end code there. Back-end code goes in this repo.
  • Implement user registration and login via calls to the server API
    • Store the response token for subsequent API requests
  • Create a game view for a logged in user
    • Make an init request upon loading game view to receive the player's starting location and unique id
    • Subscribe to the pusher channel named p-channel-<uuid> and bind to broadcast events
      • Handle incoming broadcast messages by displaying them to the player
    • Parse user commands, then make API calls based on valid inputs
      • Handle valid API responses and update the display accordingly
        @Dilstom

Copy link

@TheDeterminator TheDeterminator left a comment

Choose a reason for hiding this comment

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

Anthony, you have a very solid project here. Only things I might highlight are you should be careful about putting your secret key in committed code and you should commit your code more frequently and with more detail. Currently you have only three commits in your commit history but you want to add one every time you add a new feature (e.g. a new method, structure, file or creation of a group of variables). All the same, this looks great, good work here!

player_id = player.id
player_uuid = player.uuid
data = json.loads(request.body)
message = data['message']

Choose a reason for hiding this comment

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

It's small thing, but have you thought about how you'd handle the case in which the user sends a blank message, or a message with malicious code?

@@ -45,3 +45,5 @@
p.currentRoom=r_outside.id
p.save()

cfe1913928b90b3516e9981d7f3cd76524ecc870

Choose a reason for hiding this comment

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

This is your secret key? Why the choice to store it here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants