Git Product home page Git Product logo

17f-webadventure-backend's Introduction

WebAdventure Backend

This is the repository for the backend of the WebAdventure Project. For more information see the repo: https://github.com/dartmouth-cs98/17f-webadventure

Setup

The backend is automatically build via heroku and uses socket.io to deploy websockets.

The server points to https://webadventure-api.herokuapp.com/. There are two servers types of connections to the backend server: Lobby Server and Game Server.

To run the backend locally first make sure you have MongoDB installed and start a local MongoDB server:

mongod

Then npm install and npm start the repo. The backend server should now be running on localhost:9090

Models:

The backend stores 3 models using Mongoose with MongoDB:

  • Game : represents a game
{
  startPage(String): the starting URL in the game,
  goalPage(String): the goal/ending URL in the game,
  host(String): username of the user hosting the game. If the game is public game, "public" is the host,
  isPrivate(Boolean): boolean that indicates whether or not the game is private,
  players: array of players in the game. Max of 5 players.
  [{
    finishTime(Number): the number of seconds it takes for the user to reach the goalPage. If the user has not reached the goalPage, default value is -1,
    numClicks(Number): the number of clicks (links the user goes through) in the game,
    username(String): username of the player,
    curUrl(String): current URL the player is on,
  }],
  active(Boolean): boolean that indicates if the game has been started; default value is false,
}
  • User: represents a user
{
  username(String): unique string that identifies a user,
  active(Boolean): boolean that identifies whether the player is currently playing a game,
  avatar([String]): an array/pair of urls to the avatar gifs of the player. The element avatar[0] = left-facing and avatar[1] = right-facing,
}
  • GamePath: represents the path a user takes in a particular game
{
  game (Game): stores the ObjectId of the Game object connected to this game path,
  player (User): stores the ObjectId of the User object connected to this game path,
  path([String]): an array of urls as strings in the order the user takes to get to the goalPage,
}

Socket Servers

Lobby Server

The player connects to the lobby server before playing the game. The lobby contains information about what public games are available and handles players joining or creating games.

The events the server emits are:

  • 'games', (games) => {}: pushes the public games available for the user to join
  • 'users', (users) => {}: pushes the players currently live, but not playing a games

The events the server responds to are:

  • 'getOrCreateUser', (username), (user) => {}: gets or creates a user with the given username
  • 'updateUser', (username, fields), (user) => {}: update the username
  • 'createGame', (username, endpoints, isPrivate), (game) => {}: creates a new game
  • 'joinNewGame', (gameId, username), (game) => {}: user with the provided username is added to the list of players in the games
  • 'leaveNewGame', (gameId, username), (game) => {}: user with provided username removed from the list of players in the games
  • 'startGame', (gameId), (game) => {}: starts a game by setting the game to active, logging out all the players in the game and emitting a start game event

Game Server

When the game begins the player connects to the game server.

The events the server emits are:

  • 'game', (game) => {}: pushes the current games

The events the server responds to are:

  • 'updatePlayer', (gameId, username, playerInfo): updates the player's numClicks, curUrl and finishTime

API endpoints

  • /api/endpoints POST - expected query object
{
  startPage: 'URL',
  goalPage:'URL'
  path: 'string delimited by commas'
}

17f-webadventure-backend's People

Contributors

byang18 avatar almawang avatar sxguo avatar

Watchers

James Cloos avatar Imanol Avendaño avatar  avatar  avatar  avatar

17f-webadventure-backend's Issues

Add in catch errors

Right now, there is no catching errors in the backend -- thinking about using the then? and then console.log error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.