add database repair for playertimes table

This commit is contained in:
Skillet 2023-03-01 13:32:18 -05:00 committed by GitHub
parent 1e7a41a950
commit 4f0612fab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,6 +75,7 @@ export default class DBLogPlayerTime extends DBLog {
async prepareToMount() {
await super.prepareToMount();
await this.models.PlayerTime.sync();
}
async mount() {
@ -83,6 +84,28 @@ export default class DBLogPlayerTime extends DBLog {
this.server.on('PLAYER_DISCONNECTED', this.onPlayerDisconnected);
}
async repairDB() {
await super.repairDB();
let lastTickTime = this.models.TickRate.findOne(
{ where: { server: this.options.overrideServerID || this.server.id},
order: [['id', 'DESC']]}
);
let lastServerTime = lastTickTime.time;
let playerOnlineID = [];
for (player of this.players){
playerOnlineID.push(player.steamID);
}
const {not} = Sequelize.Op;
this.models.PlayerTime.update(
{ leaveTime: lastServerTime },
{ where: {
leaveTime: null,
server: this.options.overrideServerID || this.server.id,
[not]: [{player: playerOnlineID}]
} }
);
}
async unmount() {
this.models.PlayerTime.update(
{ leaveTime: 0 },