crude games list
This commit is contained in:
parent
b56aedbca6
commit
e963576e46
7 changed files with 141 additions and 22 deletions
26
backend/routes/games/list.coffee
Normal file
26
backend/routes/games/list.coffee
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
logger = (require 'logging').default '/games/list'
|
||||||
|
|
||||||
|
# session storage (volatile data)
|
||||||
|
session = (require '../../session')
|
||||||
|
|
||||||
|
module.exports =
|
||||||
|
url: '/games/list'
|
||||||
|
method: 'POST'
|
||||||
|
# schema: (require './info.schema')
|
||||||
|
|
||||||
|
handler: (request, reply) ->
|
||||||
|
session.check request.body.session ? ""
|
||||||
|
.then (userid) ->
|
||||||
|
# active session found, get associated user
|
||||||
|
session.getGames()
|
||||||
|
.then (games) ->
|
||||||
|
logger.debug "OK '#{userid}' got games"
|
||||||
|
reply.send
|
||||||
|
success: true
|
||||||
|
games: games
|
||||||
|
|
||||||
|
.catch ->
|
||||||
|
# no session found
|
||||||
|
logger.info "FAIL '#{request.body.session}' session not found"
|
||||||
|
reply.send
|
||||||
|
success: false
|
|
@ -28,6 +28,8 @@ fastify.route (require "./routes/#{route}") for route in [
|
||||||
'decks/modify'
|
'decks/modify'
|
||||||
# delete deck
|
# delete deck
|
||||||
'decks/delete'
|
'decks/delete'
|
||||||
|
# list games
|
||||||
|
'games/list'
|
||||||
]
|
]
|
||||||
|
|
||||||
# request logging
|
# request logging
|
||||||
|
|
|
@ -88,32 +88,50 @@ class FFTCGSESSION
|
||||||
resolve digest
|
resolve digest
|
||||||
|
|
||||||
getGames: ->
|
getGames: ->
|
||||||
# function to return all active gameKeys
|
new Promise (resolve) =>
|
||||||
activeGameKeys = (set, cursor) =>
|
# function to return all active gameKeys
|
||||||
# start iteration
|
activeGameKeys = (set, cursor) =>
|
||||||
set ?= new Set()
|
# start iteration
|
||||||
cursor ?= '0'
|
set ?= new Set()
|
||||||
|
cursor ?= '0'
|
||||||
|
|
||||||
return new Promise (resolve, reject) =>
|
return new Promise (resolve, reject) =>
|
||||||
# scan "active" gameKey
|
# scan "active" gameKey
|
||||||
@db.sscan (@gameKey 'active'), cursor, 'COUNT', '100', (err, res) ->
|
@db.sscan (@gameKey 'active'), cursor, 'COUNT', '100', (err, res) ->
|
||||||
|
if err
|
||||||
|
reject null
|
||||||
|
|
||||||
# add to results set
|
# add to results set
|
||||||
cursor = res[0]
|
cursor = res[0]
|
||||||
for key in res[1]
|
for key in res[1]
|
||||||
set.add key
|
set.add key
|
||||||
|
|
||||||
if cursor == '0'
|
if cursor == '0'
|
||||||
# done on cursor = 0
|
# done on cursor = 0
|
||||||
resolve set
|
|
||||||
else
|
|
||||||
# recursive call (resolve one step deeper)
|
|
||||||
allGames set, cursor
|
|
||||||
.then (set) ->
|
|
||||||
resolve set
|
resolve set
|
||||||
|
else
|
||||||
|
# recursive call (resolve one step deeper)
|
||||||
|
allGames set, cursor
|
||||||
|
.then (set) ->
|
||||||
|
resolve set
|
||||||
|
|
||||||
|
activeGameKeys()
|
||||||
|
.then (set) =>
|
||||||
|
activeGames = []
|
||||||
|
|
||||||
|
for key in Array.from set
|
||||||
|
activeGames.push new Promise (resolve) =>
|
||||||
|
@db.hget key, 'owner', (err, res) ->
|
||||||
|
if(err)
|
||||||
|
resolve null
|
||||||
|
|
||||||
|
resolve res
|
||||||
|
|
||||||
|
Promise.all activeGames
|
||||||
|
.then (activeGames) ->
|
||||||
|
console.log activeGames
|
||||||
|
resolve activeGames
|
||||||
|
|
||||||
activeGameKeys().then (set) ->
|
|
||||||
logger.info "game count: #{Array.from(set).length}"
|
|
||||||
|
|
||||||
joinGame: (digest, userid) ->
|
joinGame: (digest, userid) ->
|
||||||
new Promise (resolve, reject) =>
|
new Promise (resolve, reject) =>
|
||||||
|
|
36
frontend/src/components/GamesList.vue
Normal file
36
frontend/src/components/GamesList.vue
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div v-for="game in games" :key="game">
|
||||||
|
{{ game }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import axios from '@/plugins/axios'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'GamesList',
|
||||||
|
|
||||||
|
props: {
|
||||||
|
session: String
|
||||||
|
},
|
||||||
|
|
||||||
|
asyncComputed: {
|
||||||
|
games: {
|
||||||
|
get() {
|
||||||
|
return axios
|
||||||
|
.post('/games/list', {
|
||||||
|
session: this.session
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.data.success) {
|
||||||
|
return response.data.games
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
default: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -4,7 +4,9 @@
|
||||||
<v-icon>view_carousel</v-icon> Decks
|
<v-icon>view_carousel</v-icon> Decks
|
||||||
</v-btn>
|
</v-btn>
|
||||||
|
|
||||||
<v-btn flat> <v-icon>play_arrow</v-icon> Play </v-btn>
|
<v-btn flat :to="{ name: 'games' }">
|
||||||
|
<v-icon>play_arrow</v-icon> Play
|
||||||
|
</v-btn>
|
||||||
|
|
||||||
<v-btn flat :to="{ name: 'usercp' }">
|
<v-btn flat :to="{ name: 'usercp' }">
|
||||||
<v-icon>person</v-icon> {{ user.login }}
|
<v-icon>person</v-icon> {{ user.login }}
|
||||||
|
|
|
@ -28,6 +28,12 @@ export default new Router({
|
||||||
component: () =>
|
component: () =>
|
||||||
import(/* webpackChunkName: "deckcp" */ './views/DeckCP.vue')
|
import(/* webpackChunkName: "deckcp" */ './views/DeckCP.vue')
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/games',
|
||||||
|
name: 'games',
|
||||||
|
component: () =>
|
||||||
|
import(/* webpackChunkName: "games" */ './views/Games.vue')
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/game',
|
path: '/game',
|
||||||
name: 'game',
|
name: 'game',
|
||||||
|
|
29
frontend/src/views/Games.vue
Normal file
29
frontend/src/views/Games.vue
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<template>
|
||||||
|
<v-content>
|
||||||
|
<HeaderIntern v-model="session" @user="user = $event" />
|
||||||
|
|
||||||
|
<v-container v-if="user">
|
||||||
|
<h2 class="headline">Open Tables</h2>
|
||||||
|
<GamesList :session="session" />
|
||||||
|
</v-container>
|
||||||
|
</v-content>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import HeaderIntern from '@/components/HeaderIntern.vue'
|
||||||
|
import GamesList from '@/components/GamesList.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'Games',
|
||||||
|
|
||||||
|
components: {
|
||||||
|
HeaderIntern,
|
||||||
|
GamesList
|
||||||
|
},
|
||||||
|
|
||||||
|
data: () => ({
|
||||||
|
session: null,
|
||||||
|
user: null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
Reference in a new issue