feat: add new game state 'disabled'
This commit is contained in:
parent
5550341359
commit
a2c95abde9
@ -4,11 +4,13 @@
|
|||||||
<Button class="game-controls__control game-controls__control__end" :border="false" :disabled="false" @click="backToPlay">{{ $t('back') }}</Button>
|
<Button class="game-controls__control game-controls__control__end" :border="false" :disabled="false" @click="backToPlay">{{ $t('back') }}</Button>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
|
<template v-if="game.state !== 'disabled'">
|
||||||
<Button class="game-controls__control" :border="!disabled.collect" :disabled="disabled.collect" @click="collect">{{ $t('collect-quotes') }}</Button>
|
<Button class="game-controls__control" :border="!disabled.collect" :disabled="disabled.collect" @click="collect">{{ $t('collect-quotes') }}</Button>
|
||||||
<Button class="game-controls__control" :border="!disabled.start" :disabled="disabled.start" @click="start">{{ $t('start') }}</Button>
|
<Button class="game-controls__control" :border="!disabled.start" :disabled="disabled.start" @click="start">{{ $t('start') }}</Button>
|
||||||
<Button class="game-controls__control" :border="!disabled.cont" :disabled="disabled.cont" @click="cont">{{ $t('continue') }}</Button>
|
<Button class="game-controls__control" :border="!disabled.cont" :disabled="disabled.cont" @click="cont">{{ $t('continue') }}</Button>
|
||||||
<Button class="game-controls__control" :border="!disabled.idle" :disabled="disabled.idle" @click="idle">{{ $t('idle') }}</Button>
|
<Button class="game-controls__control" :border="!disabled.idle" :disabled="disabled.idle" @click="idle">{{ $t('idle') }}</Button>
|
||||||
<Button class="game-controls__control" :border="!disabled.finish" :disabled="disabled.finish" @click="finish">{{ $t('finish') }}</Button>
|
<Button class="game-controls__control" :border="!disabled.finish" :disabled="disabled.finish" @click="finish">{{ $t('finish') }}</Button>
|
||||||
|
</template>
|
||||||
<Button class="game-controls__control game-controls__control__end" :border="false" :disabled="false" @click="goToAdmin">{{ $t('admin') }}</Button>
|
<Button class="game-controls__control game-controls__control__end" :border="false" :disabled="false" @click="goToAdmin">{{ $t('admin') }}</Button>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
@ -7,15 +7,18 @@
|
|||||||
<th class="gameinfos-tile__table-head">{{ $t('state')}}</th>
|
<th class="gameinfos-tile__table-head">{{ $t('state')}}</th>
|
||||||
<th class="gameinfos-tile__table-head">{{ $t('num-players')}}</th>
|
<th class="gameinfos-tile__table-head">{{ $t('num-players')}}</th>
|
||||||
<th class="gameinfos-tile__table-head">{{ $t('gamemasters')}}</th>
|
<th class="gameinfos-tile__table-head">{{ $t('gamemasters')}}</th>
|
||||||
<th class="gameinfos-tile__table-head"> </th>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="gameinfos-tile__row" v-for="game in games" :key="game.id" @click="selectGame(game)">
|
<tr
|
||||||
|
:class="{ 'gameinfos-tile__row': true, 'gameinfos-tile__row__disabled': game.state == 'disabled' }"
|
||||||
|
v-for="game in games"
|
||||||
|
:key="game.id"
|
||||||
|
@click="selectGame(game)"
|
||||||
|
>
|
||||||
<td class="gameinfos-tile__cell">{{ game.name }}</td>
|
<td class="gameinfos-tile__cell">{{ game.name }}</td>
|
||||||
<td class="gameinfos-tile__cell">{{ game.lang }}</td>
|
<td class="gameinfos-tile__cell">{{ game.lang }}</td>
|
||||||
<td class="gameinfos-tile__cell">{{ game.state }}</td>
|
<td class="gameinfos-tile__cell">{{ game.state }}</td>
|
||||||
<td class="gameinfos-tile__cell">{{ game.players.length }}</td>
|
<td class="gameinfos-tile__cell">{{ game.players.length }}</td>
|
||||||
<td class="gameinfos-tile__cell">{{ getGamemastersFromGame(game).join(', ') }}</td>
|
<td class="gameinfos-tile__cell">{{ getGamemastersFromGame(game).join(', ') }}</td>
|
||||||
<td class="gameinfos-tile__cell"><nuxt-icon name="toggle" /></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</AdminInfoTile>
|
</AdminInfoTile>
|
||||||
@ -71,6 +74,10 @@ const selectGame = async (game: GameInfo): Promise<void> => {
|
|||||||
&:hover {
|
&:hover {
|
||||||
background-color: #606060;
|
background-color: #606060;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__disabled {
|
||||||
|
color: #808080;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__cell {
|
&__cell {
|
||||||
|
36
server/src/application/disableGame.go
Normal file
36
server/src/application/disableGame.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package application
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"sirlab.de/go/knowyt/log"
|
||||||
|
"sirlab.de/go/knowyt/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (app *Application) DisableGame(usr *user.User, w http.ResponseWriter, r *http.Request) {
|
||||||
|
gameRef := r.URL.Query().Get("g")
|
||||||
|
gm, err := app.GetGameById(gameRef)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
fmt.Fprintf(w, "game not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if usr.GetGameId() != gameRef || !usr.IsAdminOrCameo() {
|
||||||
|
w.WriteHeader(http.StatusForbidden)
|
||||||
|
fmt.Fprintf(w, "forbidden")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
gm.DisableGame()
|
||||||
|
|
||||||
|
if err := app.saveGameState(gm); err != nil {
|
||||||
|
log.ErrorLog(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
fmt.Fprintf(w, "couldn't save game state")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(w, "ok")
|
||||||
|
}
|
@ -17,3 +17,13 @@ func (gm *Game) ResetGame() {
|
|||||||
|
|
||||||
gm.notifyClients()
|
gm.notifyClients()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gm *Game) DisableGame() {
|
||||||
|
err := gm.changeGameState(STATE_ANY, STATE_DISABLED, PHASE_NONE)
|
||||||
|
if err != nil {
|
||||||
|
log.ErrorLog(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
gm.notifyClients()
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@ const (
|
|||||||
STATE_READY_SET = "ready-set"
|
STATE_READY_SET = "ready-set"
|
||||||
STATE_PLAY = "play"
|
STATE_PLAY = "play"
|
||||||
STATE_FINAL = "final"
|
STATE_FINAL = "final"
|
||||||
|
STATE_DISABLED = "disabled"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -36,6 +36,7 @@ func main() {
|
|||||||
mux.PrivateHandleFunc("/api/resetGame", app.ResetGame)
|
mux.PrivateHandleFunc("/api/resetGame", app.ResetGame)
|
||||||
mux.PrivateHandleFunc("/api/continueGame", app.ContinueGame)
|
mux.PrivateHandleFunc("/api/continueGame", app.ContinueGame)
|
||||||
mux.PrivateHandleFunc("/api/finishGame", app.FinishGame)
|
mux.PrivateHandleFunc("/api/finishGame", app.FinishGame)
|
||||||
|
mux.PrivateHandleFunc("/api/disableGame", app.DisableGame)
|
||||||
mux.PrivateHandleFunc("/api/saveSelection", app.SaveSelection)
|
mux.PrivateHandleFunc("/api/saveSelection", app.SaveSelection)
|
||||||
mux.PrivateHandleFunc("/api/getQuotes", app.GetQuotes)
|
mux.PrivateHandleFunc("/api/getQuotes", app.GetQuotes)
|
||||||
mux.PrivateHandleFunc("/api/saveQuote", app.SaveQuote)
|
mux.PrivateHandleFunc("/api/saveQuote", app.SaveQuote)
|
||||||
|
@ -167,6 +167,23 @@ func (usr *User) IsAdmin() bool {
|
|||||||
return usr.role == ROLE_ADMIN
|
return usr.role == ROLE_ADMIN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (usr *User) IsAdminOrCameo() bool {
|
||||||
|
usr.mu.Lock()
|
||||||
|
defer usr.mu.Unlock()
|
||||||
|
|
||||||
|
if usr.role == ROLE_ADMIN {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if usr.cameo != nil {
|
||||||
|
if usr.cameo.role == ROLE_ADMIN {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (usr *User) SetCameo(usrCameo *User) {
|
func (usr *User) SetCameo(usrCameo *User) {
|
||||||
usr.mu.Lock()
|
usr.mu.Lock()
|
||||||
defer usr.mu.Unlock()
|
defer usr.mu.Unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user