add replay functionality
This commit is contained in:
parent
4158aa0854
commit
083fc0463c
13 changed files with 452 additions and 125 deletions
25
server/GameLog.js
Normal file
25
server/GameLog.js
Normal 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,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue