add replay functionality

This commit is contained in:
Zutatensuppe 2020-12-22 22:35:09 +01:00
parent 4158aa0854
commit 083fc0463c
13 changed files with 452 additions and 125 deletions

25
server/GameLog.js Normal file
View file

@ -0,0 +1,25 @@
import fs from 'fs'
const DATA_DIR = './../data'
const log = (gameId, ...args) => {
const str = JSON.stringify(args)
fs.appendFileSync(`${DATA_DIR}/log_${gameId}.log`, str + "\n")
}
const get = (gameId) => {
const all = fs.readFileSync(`${DATA_DIR}/log_${gameId}.log`, 'utf-8')
return all.split("\n").filter(line => !!line).map((line) => {
try {
return JSON.parse(line)
} catch (e) {
console.log(line)
console.log(e)
}
})
}
export default {
log,
get,
}