stop engine when leaving /play

This commit is contained in:
Settel 2021-08-12 23:08:17 +02:00
parent 0014a81ce3
commit ab5416a547
3 changed files with 7 additions and 6 deletions

View File

@ -10,6 +10,9 @@ export default {
async mounted() { async mounted() {
await this.$engine.start() await this.$engine.start()
}, },
async beforeDestroy() {
await this.$engine.stop()
},
computed: { computed: {
userJson() { userJson() {
return JSON.stringify(this.$store.state.engine.user, null, 2) return JSON.stringify(this.$store.state.engine.user, null, 2)

View File

@ -1,7 +1,7 @@
import buildUrl from 'build-url' import buildUrl from 'build-url'
export default (context, inject) => { export default (context, inject) => {
const { store, $axios, $config } = context const { store, $axios, $config, redirect } = context
const engine = { const engine = {
lastFetched: [0, 0, 0, 0, 0], lastFetched: [0, 0, 0, 0, 0],
@ -11,7 +11,7 @@ export default (context, inject) => {
async start() { async start() {
if (!store.state.engine.user) { if (!store.state.engine.user) {
if (!await this.fetchUserInfo()) { if (!await this.fetchUserInfo()) {
window.location.href = "/" redirect('/')
} }
} }
if (this.isActive) { if (this.isActive) {
@ -70,8 +70,8 @@ export default (context, inject) => {
async fetchUserInfo() { async fetchUserInfo() {
try { try {
const user = await $axios.$get('/api/userinfo') const response = await $axios.get('/api/userinfo')
store.commit('engine/setUser', user) store.commit('engine/setUser', response.data)
} catch(e) { } catch(e) {
store.commit('engine/setUser', undefined) store.commit('engine/setUser', undefined)
return false return false

View File

@ -1,7 +1,6 @@
package application package application
import ( import (
"fmt"
"time" "time"
) )
@ -22,7 +21,6 @@ func (app *Application) expireInactivePlayersThread() {
} }
gm.EventPlayerLeaves(usr) gm.EventPlayerLeaves(usr)
fmt.Printf("expired %s\n", usrId)
} }
} }
} }