From ab5416a54739e5783063fdf9d7e1817c821eead3 Mon Sep 17 00:00:00 2001 From: Settel Date: Thu, 12 Aug 2021 23:08:17 +0200 Subject: [PATCH] stop engine when leaving /play --- client/src/pages/play.vue | 3 +++ client/src/plugins/engine.js | 8 ++++---- server/src/application/expireInactivePlayers.go | 2 -- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/client/src/pages/play.vue b/client/src/pages/play.vue index 18b1d72..a30f2e6 100644 --- a/client/src/pages/play.vue +++ b/client/src/pages/play.vue @@ -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) diff --git a/client/src/plugins/engine.js b/client/src/plugins/engine.js index bdb6743..f0091a6 100644 --- a/client/src/plugins/engine.js +++ b/client/src/plugins/engine.js @@ -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 diff --git a/server/src/application/expireInactivePlayers.go b/server/src/application/expireInactivePlayers.go index a92fee9..875db48 100644 --- a/server/src/application/expireInactivePlayers.go +++ b/server/src/application/expireInactivePlayers.go @@ -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) } } }