Embezzle/index.js

109 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-02-15 23:22:09 +00:00
const lobby = require("./lobby.js")
const game = require("./game.js")
2020-02-15 10:01:01 +00:00
const express = require('express')
2020-02-15 14:59:27 +00:00
const bodyParser = require('body-parser');
2020-02-15 10:01:01 +00:00
const app = express()
2020-02-15 23:22:09 +00:00
app.use(bodyParser.json(),function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE')
res.setHeader('Access-Control-Allow-Headers', 'Content-Type')
res.setHeader('Access-Control-Allow-Credentials', true)
next()
})
2020-02-15 10:01:01 +00:00
//top level
//get game list
2020-02-15 23:22:09 +00:00
app.get('/lobby/list' , async function (req, res) {
lobby.list().then(r => {
2020-02-16 08:53:52 +00:00
res.send(JSON.stringify({gamesArr: r }))
2020-02-15 23:22:09 +00:00
})
2020-02-15 14:59:27 +00:00
})
2020-02-15 23:22:09 +00:00
2020-02-15 10:01:01 +00:00
//get game details
2020-02-16 08:53:52 +00:00
app.get('/lobby/details/:gameID', function (req, res) {
lobby.details(req.params.gameID).then(r => {
res.send(JSON.stringify(r[0]))
2020-02-16 08:53:52 +00:00
})
2020-02-15 14:59:27 +00:00
})
2020-02-15 23:22:09 +00:00
2020-02-15 10:01:01 +00:00
//post register player
2020-02-15 23:22:09 +00:00
app.post('/lobby/register', function (req, res) {
2020-02-15 14:59:27 +00:00
let obj=req.body
2020-02-15 23:22:09 +00:00
response=JSON.stringify(lobby.register(obj.name))
res.send(response)
2020-02-15 14:59:27 +00:00
})
2020-02-15 23:22:09 +00:00
//post join an existing game
app.post('/lobby/join', function (req, res) {
let obj=req.body
response=JSON.stringify(lobby.join(obj.ownerID,obj.gameID))
res.send(response)
})
2020-02-15 10:01:01 +00:00
//get an empty game made
2020-02-15 23:22:09 +00:00
app.post('/lobby/make', function (req, res) {
let obj=req.body
lobby.make(obj.ownerID,obj.seats).then(result => {
res.send(JSON.stringify(result))
})
2020-02-15 14:59:27 +00:00
})
2020-02-15 10:01:01 +00:00
2020-02-15 23:22:09 +00:00
//start a game
app.post('/lobby/start', function (req, res) {
let obj=req.body
response=JSON.stringify(lobby.start(obj.ownerID, obj.gameID))
res.send(response)
})
//myCharity
app.post('/game/:gameID/charity', function (req, res) {
game.myCharity(req.params.gameID, req.body.ownerID).then(r => {
res.send(JSON.stringify(r))
})
})
// charityList
app.get('/game/:gameID/charityList', function (req, res) {
game.charityList(req.params.gameID).then(r => {
res.send(JSON.stringify(r))
})
})
//playerList
app.get('/game/:gameID/playerList', function (req, res) {
game.playerList(req.params.gameID).then(r => {
res.send(JSON.stringify(r))
})
})
// boardFunding
app.get('/game/:gameID/boardFunding', function (req, res) {
game.boardFunding(req.params.gameID).then(r => {
res.send(JSON.stringify(r))
})
})
// distribution
app.post('/game/:gameID/distribution', function (req, res) {
game.distribution(req.params.gameID, req.body.ownerID, req.body.charityID, req.body.amount).then(r => {
res.send(JSON.stringify(r))
})
})
// accuse
app.post('/game/:gameID/accuse', function (req, res) {
game.accuse(req.params.gameID, req.body.ownerID, req.body.player).then(r => {
res.send(JSON.stringify(r))
})
})
// roundStatus -- this should not be public wtf?
// app.get('/game/:gameID/roundStatus', function (req, res) {
// game.roundStatus(req.params.gameID).then(r => {
// res.send(JSON.stringify(r))
// })
// })
2020-02-15 10:01:01 +00:00
2020-02-15 14:59:27 +00:00
console.log("Up")
2020-02-15 10:01:01 +00:00
app.listen(3000)