Update db-log-addOn.js

This commit is contained in:
Skillet 2023-03-04 10:02:59 -05:00 committed by GitHub
parent 18ddd401cb
commit 22631f081d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,24 +81,31 @@ export default class DBLogPlayerTime extends DBLog {
} }
async mount() { async mount() {
console.log('Mounting db-log');
await super.mount(); await super.mount();
console.log('finished mounting db-log');
this.server.on('PLAYER_CONNECTED', this.onPlayerConnected); this.server.on('PLAYER_CONNECTED', this.onPlayerConnected);
this.server.on('PLAYER_DISCONNECTED', this.onPlayerDisconnected); this.server.on('PLAYER_DISCONNECTED', this.onPlayerDisconnected);
console.log('finished mounting db-log-addOn');
} }
async repairDB() { async repairDB() {
console.log('starting DB repair');
await super.repairDB(); await super.repairDB();
let lastTickTime = this.models.TickRate.findOne( console.log('starting DB repair for addOn');
let lastTickTime = await this.models.TickRate.findOne(
{ where: { server: this.options.overrideServerID || this.server.id}, { where: { server: this.options.overrideServerID || this.server.id},
order: [['id', 'DESC']]} order: [['id', 'DESC']]}
); );
console.log('last tick found:', lastTickTime);
let lastServerTime = lastTickTime.time; let lastServerTime = lastTickTime.time;
let playerOnlineID = []; let playerOnlineID = [];
for (player of this.server.players){ for (player of this.server.players){
playerOnlineID.push(player.steamID); playerOnlineID.push(player.steamID);
} }
console.log('players online:', playerOnlineID);
const {not} = Sequelize.Op; const {not} = Sequelize.Op;
this.models.PlayerTime.update( let rowUpdate = await this.models.PlayerTime.update(
{ leaveTime: lastServerTime }, { leaveTime: lastServerTime },
{ where: { { where: {
leaveTime: null, leaveTime: null,
@ -106,6 +113,8 @@ export default class DBLogPlayerTime extends DBLog {
[not]: [{player: playerOnlineID}] [not]: [{player: playerOnlineID}]
} } } }
); );
console.log('updated playerTimes row count: %i', rowUpdate[0]);
console.log('finish DB repair');
} }
async unmount() { async unmount() {