You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.3 KiB
90 lines
2.3 KiB
const { genRandomString } = require('./common/randomString') |
|
const serverConfig = require('../config/serverConfig.js') |
|
const wrtColor = require('./common/wrtColor') |
|
const { state } = require('./objectDefinitions') |
|
|
|
let t = new Date() |
|
let m15 = t.setSeconds(t.getSeconds()-15) |
|
let p30 = t.setSeconds(t.getSeconds()+30) |
|
let p45 = t.setSeconds(t.getSeconds()+45) |
|
let p60 = t.setSeconds(t.getSeconds()+60) |
|
|
|
|
|
function addTestPlayers(players) { |
|
players.push({ |
|
id: genRandomString(serverConfig.playerIdLength), |
|
username: 'Charlie', |
|
gameid: 222, |
|
lastActivity: p30, |
|
connected: false |
|
}) |
|
players.push({ |
|
id: genRandomString(serverConfig.playerIdLength), |
|
username: 'Dee', |
|
gameid: 222, |
|
lastActivity: p45, |
|
connected: false |
|
}) |
|
players.push({ |
|
id: genRandomString(serverConfig.playerIdLength), |
|
username: 'Dennis', |
|
gameid: 222, |
|
lastActivity: p60, |
|
connected: false |
|
}) |
|
players.push({ |
|
id: genRandomString(serverConfig.playerIdLength), |
|
username: 'Frank', |
|
gameid: 222, |
|
lastActivity: m15, |
|
connected: true |
|
}) |
|
players.push({ |
|
id: genRandomString(serverConfig.playerIdLength), |
|
username: 'Mac', |
|
gameid: 222, |
|
lastActivity: p30, |
|
connected: true |
|
}) |
|
} |
|
|
|
function addFluxPlayers (state) { |
|
// Add and remove Pondy from players every 5 seconds |
|
setInterval(function () { |
|
// PONDY |
|
// console.log(players) |
|
let pondyFound = false |
|
for (let i = 0; i < state.players.length; i++) { |
|
if (state.players[i].username === 'Pondy') { |
|
pondyFound = true |
|
break |
|
} |
|
} |
|
if (pondyFound) { |
|
// wrtColor.yellow('Pondy Found, removing') |
|
let pondyFilteredPlayers = state.players.filter( function (player) { |
|
if (player.username !== 'Pondy') { |
|
return player |
|
} |
|
}) |
|
// console.log(pondyFilteredPlayers) |
|
state.players = pondyFilteredPlayers |
|
} else { |
|
// wrtColor.yellow('Pondy Not Found, adding') |
|
let t = new Date() |
|
let p30 = t.setSeconds(t.getSeconds()+30) |
|
state.players.push({ |
|
id: genRandomString(serverConfig.playerIdLength), |
|
username: 'Pondy', |
|
gameid: 222, |
|
lastActivity: p30, |
|
connected: true |
|
}) |
|
} |
|
}, 5000) |
|
} |
|
|
|
module.exports = { |
|
addTestPlayers: addTestPlayers, |
|
addFluxPlayers: addFluxPlayers |
|
} |