mirror of
https://github.com/AsgardEternal/SquadJSDocker.git
synced 2025-01-02 12:09:20 -06:00
add database repair for playertimes table
This commit is contained in:
parent
1e7a41a950
commit
4f0612fab7
@ -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 },
|
||||
|
Loading…
Reference in New Issue
Block a user