Skip to content

Commit c577ab3

Browse files
committed
Support new game topic formats
1 parent 601ea1b commit c577ab3

File tree

5 files changed

+53
-18
lines changed

5 files changed

+53
-18
lines changed

app/Jobs/GetPlayerCounts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function handle()
4141
$response = GameBridge::server($server)
4242
->force(true)
4343
->priority('high')
44-
->players();
44+
->ping();
4545
$playerCount = $response->failed() ? null : $response->asNumber();
4646
$playersOnline = new PlayersOnline;
4747
$playersOnline->timestamps = false;

app/Services/GameBridge/Server.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ public function priority(string $priority): self
7474
return $this;
7575
}
7676

77+
/**
78+
* Ping the server, returns player count
79+
*/
80+
public function ping(): GameBridgeResponse
81+
{
82+
if (! $this->priority) {
83+
$this->priority = 'low';
84+
}
85+
86+
return $this->send('ping');
87+
}
88+
7789
/**
7890
* Get server status
7991
*/
@@ -87,15 +99,15 @@ public function status(): GameBridgeResponse
8799
}
88100

89101
/**
90-
* Get player count
102+
* Get player list
91103
*/
92-
public function players(): GameBridgeResponse
104+
public function who(): GameBridgeResponse
93105
{
94106
if (! $this->priority) {
95107
$this->priority = 'low';
96108
}
97109

98-
return $this->send('players');
110+
return $this->send('who');
99111
}
100112

101113
/**

app/Services/GameBridge/ServerCollection.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ public function priority(string $priority): self
7777
return $this;
7878
}
7979

80+
/**
81+
* Ping all servers, returns player count
82+
*/
83+
public function ping(): Collection
84+
{
85+
if (! $this->priority) {
86+
$this->priority = 'low';
87+
}
88+
89+
return $this->send('ping');
90+
}
91+
8092
/**
8193
* Get status from all servers
8294
*/
@@ -90,15 +102,15 @@ public function status(): Collection
90102
}
91103

92104
/**
93-
* Get player count from all servers
105+
* Get player list from all servers
94106
*/
95-
public function players(): Collection
107+
public function who(): Collection
96108
{
97109
if (! $this->priority) {
98110
$this->priority = 'low';
99111
}
100112

101-
return $this->send('players');
113+
return $this->send('who');
102114
}
103115

104116
/**

resources/js/Pages/Home/Partials/ServerStatus.vue

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<div v-if="error">&nbsp;</div>
2424
<q-skeleton type="text" v-else-if="loading" width="100%" />
2525
<template v-else>
26-
<span>{{ $formats.capitalize(status.mode) }} Mode</span>
26+
<span>{{ $formats.capitalize(status.mode || 'Secret') }} Mode</span>
2727
<q-separator vertical color="grey" class="q-mx-sm q-my-xs" />
2828
<span>{{ status.players }} players</span>
2929
<q-separator vertical color="grey" class="q-mx-sm q-my-xs" />
@@ -167,16 +167,18 @@ export default {
167167
168168
computed: {
169169
isPreRound() {
170-
return this.status?.elapsed === 'pre'
170+
// GAME_STATE_PREGAME = 5
171+
return parseInt(this.status.gamestate) <= 5
171172
},
172173
173174
isPostRound() {
174-
return this.status?.elapsed === 'post'
175+
// GAME_STATE_FINISHED = 8
176+
return parseInt(this.status.gamestate) === 8
175177
},
176178
177179
roundTime() {
178-
if (!this.status.elapsed || this.isPreRound) return 0
179-
return dayjs.duration(parseInt(this.status.elapsed), 'seconds').format('H[h] m[m]')
180+
if (!this.status.round_duration || this.isPreRound) return 0
181+
return dayjs.duration(parseInt(this.status.round_duration), 'seconds').format('H[h] m[m]')
180182
},
181183
182184
mapId() {
@@ -214,6 +216,11 @@ export default {
214216
preserveState: false,
215217
onCancelToken: (cancelToken) => (this.cancelToken = cancelToken),
216218
onSuccess: (page) => {
219+
if (page.props.status.error) {
220+
this.error = true
221+
this.status = {}
222+
return
223+
}
217224
this.status = page.props.status
218225
},
219226
onError: () => {
@@ -240,8 +247,8 @@ export default {
240247
cleanup() {
241248
if (this.cleaned) return
242249
this.cleaned = true
243-
this.cancelToken && this.cancelToken.cancel()
244-
this.refreshTimer && clearTimeout(this.refreshTimer)
250+
if (this.cancelToken) this.cancelToken.cancel()
251+
if (this.refreshTimer) clearTimeout(this.refreshTimer)
245252
},
246253
},
247254
}

resources/views/open-graph/home.blade.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,22 @@
7777
</div>
7878
@else
7979
<div class="status__details">
80-
<span>{{ Str::ucfirst($server['status']['mode']) }}</span>
80+
<span>
81+
{{ Str::ucfirst(isset($server['status']['mode']) ? $server['status']['mode'] : 'Secret') }}
82+
</span>
8183
<span class="text-primary">
8284
{{ $server['status']['players'] }}
8385
player{{ (int) $server['status']['players'] === 1 ? '' : 's' }}
8486
</span>
8587
<span>
86-
@if ($server['status']['elapsed'] === 'pre')
88+
{{-- GAME_STATE_PREGAME = 5 --}}
89+
@if ((int) $server['status']['gamestate'] <= 5)
8790
Lobby
88-
@elseif ($server['status']['elapsed'] === 'post')
91+
{{-- GAME_STATE_FINISHED = 8 --}}
92+
@elseif ((int) $server['status']['gamestate'] === 8)
8993
Ended
9094
@else
91-
{{ date("G\h i\m", (int) $server['status']['elapsed']) }}
95+
{{ date("G\h i\m", (int) $server['status']['round_duration']) }}
9296
@endif
9397
</span>
9498
@isset ($server['status']['map_name'])

0 commit comments

Comments
 (0)