Skip to content

Commit aef8d4e

Browse files
tec272Pacalypse-
authored andcommitted
Send the game results to the server on game end. (ShieldBattery#539)
This sets things up so we can make this request from the Rust code, as the game finishes. We make 3 attempts, if all 3 fail, the expectation is that the app will retry at some point in the future (but this is NOT implemented yet as of this PR). The app can know to do this by the fact that the game exits without calling /game/resultSent (and my plan is to always submit some sort of results if that occurs, to try to give us fewer result timeouts in the case of weird issues). APM calculation is also not included in this PR, for now everybody is registered as having 0 APM. Note that there's a number of random Rust reformatting changes in here, as VSCode really wanted to do them. I adjusted our .editorconfig to preserve most of the existing formatting.
1 parent ce36ce0 commit aef8d4e

File tree

16 files changed

+836
-73
lines changed

16 files changed

+836
-73
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ trim_trailing_whitespace = true
1010

1111
[*.bat]
1212
end_of_line = crlf
13+
14+
[*.rs]
15+
indent_size = 4

client/active-game/active-game-manager.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
GAME_STATUS_FINISHED,
1414
GAME_STATUS_ERROR,
1515
statusToString,
16+
GAME_STATUS_HAS_RESULT,
17+
GAME_STATUS_RESULT_SENT,
1618
} from '../../common/game-status'
1719
import { SCR_SETTINGS_OVERWRITE } from '../../common/ipc-constants'
1820

@@ -182,14 +184,30 @@ export default class ActiveGameManager extends EventEmitter {
182184
this._setStatus(GAME_STATUS_PLAYING)
183185
}
184186

185-
handleGameEnd(gameId, results, time) {
187+
handleGameResult(gameId, results, time) {
186188
if (!this.activeGame || this.activeGame.id !== gameId) {
187189
return
188190
}
189-
// TODO(tec27): this needs to be handled differently (game should really be reporting these
190-
// directly to the server)
191-
log.verbose(`Game finished: ${JSON.stringify({ results, time })}`)
191+
192+
// TODO(tec27): Store these results and attempt to send them ourselves if the game fails to
193+
log.verbose(`Game results: ${JSON.stringify({ results, time })}`)
194+
this._setStatus(GAME_STATUS_HAS_RESULT)
192195
this.emit('gameResults', { results, time })
196+
}
197+
198+
handleGameResultSent(gameId) {
199+
if (!this.activeGame || this.activeGame.id !== gameId) {
200+
return
201+
}
202+
203+
this._setStatus(GAME_STATUS_RESULT_SENT)
204+
}
205+
206+
handleGameFinished(gameId) {
207+
if (!this.activeGame || this.activeGame.id !== gameId) {
208+
return
209+
}
210+
193211
this._setStatus(GAME_STATUS_FINISHED)
194212
this.emit('gameCommand', gameId, 'cleanup_and_quit')
195213
}

client/active-game/game-server.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,14 @@ class GameServer {
8080
case '/game/start':
8181
activeGameManager.handleGameStart(gameId)
8282
break
83-
case '/game/end':
84-
activeGameManager.handleGameEnd(gameId, payload.results, payload.time)
83+
case '/game/result':
84+
activeGameManager.handleGameResult(gameId, payload.results, payload.time)
85+
break
86+
case '/game/resultSent':
87+
activeGameManager.handleGameResultSent(gameId)
88+
break
89+
case '/game/finished':
90+
activeGameManager.handleGameFinished(gameId)
8591
break
8692
case '/game/replaySave':
8793
activeGameManager.handleReplaySave(gameId, payload.path)

client/lobbies/socket-handlers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import activeGameManager from '../active-game/active-game-manager-instance'
3333
import audioManager, { SOUNDS } from '../audio/audio-manager-instance'
3434
import { getIngameLobbySlotsWithIndexes } from '../../common/lobbies'
3535
import { openSnackbar } from '../snackbars/action-creators'
36+
import { makeServerUrl } from '../network/server-url'
3637

3738
const ipcRenderer = IS_ELECTRON ? require('electron').ipcRenderer : null
3839

@@ -242,6 +243,7 @@ const eventToAction = {
242243
host,
243244
seed: event.setup.seed,
244245
resultCode: event.resultCode,
246+
serverUrl: makeServerUrl(''),
245247
},
246248
}
247249

client/matchmaking/socket-handlers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { openDialog, closeDialog } from '../dialogs/action-creators'
2323
import { openSnackbar } from '../snackbars/action-creators'
2424
import { MATCHMAKING_ACCEPT_MATCH_TIME } from '../../common/constants'
2525
import { USER_ATTENTION_REQUIRED } from '../../common/ipc-constants'
26+
import { makeServerUrl } from '../network/server-url'
2627

2728
const ipcRenderer = IS_ELECTRON ? require('electron').ipcRenderer : null
2829

@@ -177,6 +178,7 @@ const eventToAction = {
177178
host: event.slots[0], // Arbitrarily set first player as host
178179
seed: event.setup.seed,
179180
resultCode: event.resultCode,
181+
serverUrl: makeServerUrl(''),
180182
},
181183
}
182184

common/game-status.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ export const GAME_STATUS_CONFIGURING = 2
99
export const GAME_STATUS_AWAITING_PLAYERS = 3
1010
export const GAME_STATUS_STARTING = 4
1111
export const GAME_STATUS_PLAYING = 5
12-
export const GAME_STATUS_FINISHED = 6
13-
export const GAME_STATUS_ERROR = 7
12+
export const GAME_STATUS_HAS_RESULT = 6
13+
export const GAME_STATUS_RESULT_SENT = 7
14+
export const GAME_STATUS_FINISHED = 8
15+
export const GAME_STATUS_ERROR = 666
1416

1517
export function statusToString(status) {
1618
switch (status) {
@@ -26,6 +28,10 @@ export function statusToString(status) {
2628
return 'starting'
2729
case GAME_STATUS_PLAYING:
2830
return 'playing'
31+
case GAME_STATUS_HAS_RESULT:
32+
return 'hasResult'
33+
case GAME_STATUS_RESULT_SENT:
34+
return 'resultSent'
2935
case GAME_STATUS_FINISHED:
3036
return 'finished'
3137
case GAME_STATUS_ERROR:
@@ -49,6 +55,10 @@ export function stringToStatus(string) {
4955
return GAME_STATUS_STARTING
5056
case 'playing':
5157
return GAME_STATUS_PLAYING
58+
case 'hasResults':
59+
return GAME_STATUS_HAS_RESULT
60+
case 'resultSent':
61+
return GAME_STATUS_RESULT_SENT
5262
case 'finished':
5363
return GAME_STATUS_FINISHED
5464
case 'error':

0 commit comments

Comments
 (0)