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() {
await this.$engine.start()
},
async beforeDestroy() {
await this.$engine.stop()
},
computed: {
userJson() {
return JSON.stringify(this.$store.state.engine.user, null, 2)

View File

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

View File

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