Skip to content

Commit

Permalink
bugfix: use botId and replayId from event replay file
Browse files Browse the repository at this point in the history
- also added more logging and debugging
  • Loading branch information
aadityabhatia committed Jul 27, 2023
1 parent 44e224a commit 12c9ef9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@corsaircoalition/replay-ranger",
"version": "2.0.1",
"version": "2.1.0",
"description": "record and replay generals.io game updates to Redis",
"main": "out/index.js",
"type": "module",
Expand Down
17 changes: 14 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export default class App {
public static sendEventsToRedis = async (replayFile: string, sendGameState: boolean, numEventsToSend: number, numEventsToSkip: number, delay: number) => {

const dataStore = JSON.parse(await fs.readFile(replayFile, 'utf8'))
App.botId = dataStore.botId
App.replayId = dataStore.replayId

// Send messages to Redis with a delay
const totalEvents = dataStore[RedisData.CHANNEL.TURN].length
Expand All @@ -107,14 +109,23 @@ export default class App {
}

for (let i = numEventsToSkip; i < numEventsToSkip + numEventsToSend; i++) {
Redis.publisher.publish(`${App.botId}-${RedisData.CHANNEL.TURN}`, dataStore[RedisData.CHANNEL.TURN][i])
Redis.publisher.publish(`${App.botId}-${RedisData.CHANNEL.GAME_UPDATE}`, dataStore[RedisData.CHANNEL.GAME_UPDATE][i])
const pubTurn = Redis.publisher.publish(`${App.botId}-${RedisData.CHANNEL.TURN}`, dataStore[RedisData.CHANNEL.TURN][i])
const pubUpdate = Redis.publisher.publish(`${App.botId}-${RedisData.CHANNEL.GAME_UPDATE}`, dataStore[RedisData.CHANNEL.GAME_UPDATE][i])

Redis.setKeys(`${App.botId}-${App.replayId}`, dataStore.KEYS[i]).catch((error) => {
Log.stdout(`Setting keys for event ${i+1} of ${totalEvents} to ${App.botId}`)
Redis.setKeys(`${App.botId}-${App.replayId}`, dataStore.KEYS[i]).then(()=> {
Log.stdout(`Set keys for event ${i+1} of ${totalEvents} to ${App.botId}`)
}).catch((error) => {
Log.stderr('Error setting keys: ', error)
})

Log.stdout(`Sent event ${i+1} of ${totalEvents} to ${App.botId}`)
Promise.all([pubTurn, pubUpdate]).then(() => {
Log.stdout(`Published event ${i+1} of ${totalEvents} to ${App.botId}`)
Log.debugObject('Turn', dataStore[RedisData.CHANNEL.TURN][i])
Log.debugObject('Game update', dataStore[RedisData.CHANNEL.GAME_UPDATE][i])
})

await later(delay)
}

Expand Down

0 comments on commit 12c9ef9

Please sign in to comment.