mirror of
https://github.com/AsgardEternal/SquadJSDocker.git
synced 2025-01-02 13:19:20 -06:00
commit
4c7eba4d82
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@ -3,7 +3,7 @@ name: Docker Image CI
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '30 17 * * *'
|
- cron: '45 18 * * *'
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- Development
|
- Development
|
||||||
@ -33,6 +33,4 @@ jobs:
|
|||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
push: true
|
push: true
|
||||||
cache-from: type=registry,ref=${{ vars.DOCKER_REGISTRY_URL }}/squadjs:latest
|
|
||||||
cache-to: type=inline
|
|
||||||
tags: "${{ vars.DOCKER_REGISTRY_URL }}/squadjs:latest"
|
tags: "${{ vars.DOCKER_REGISTRY_URL }}/squadjs:latest"
|
||||||
|
@ -30,6 +30,8 @@ export default class DBLogPlayerTime extends DBLog {
|
|||||||
super(server, options, connectors);
|
super(server, options, connectors);
|
||||||
|
|
||||||
this.seeding = false;
|
this.seeding = false;
|
||||||
|
this.repairSessions = true;
|
||||||
|
this.lastTickTime = null;
|
||||||
|
|
||||||
this.createModel(
|
this.createModel(
|
||||||
'PlayerTime',
|
'PlayerTime',
|
||||||
@ -39,9 +41,6 @@ export default class DBLogPlayerTime extends DBLog {
|
|||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
autoIncrement: true
|
autoIncrement: true
|
||||||
},
|
},
|
||||||
playerName: {
|
|
||||||
type: DataTypes.STRING
|
|
||||||
},
|
|
||||||
joinTime: {
|
joinTime: {
|
||||||
type: DataTypes.DATE
|
type: DataTypes.DATE
|
||||||
},
|
},
|
||||||
@ -77,59 +76,117 @@ export default class DBLogPlayerTime extends DBLog {
|
|||||||
|
|
||||||
async prepareToMount() {
|
async prepareToMount() {
|
||||||
await super.prepareToMount();
|
await super.prepareToMount();
|
||||||
await this.models.PlayerTime.sync();
|
await this.models.PlayerTime.sync();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async mount() {
|
async mount() {
|
||||||
|
console.log('Mounting db-log');
|
||||||
await super.mount();
|
await super.mount();
|
||||||
this.server.on('PLAYER_CONNECTED', this.onPlayerConnected);
|
console.log('finished mounting db-log');
|
||||||
this.server.on('PLAYER_DISCONNECTED', this.onPlayerDisconnected);
|
this.server.on('PLAYER_CONNECTED', this.onPlayerConnected);
|
||||||
|
this.server.on('PLAYER_DISCONNECTED', this.onPlayerDisconnected);
|
||||||
|
console.log('finished mounting db-log-addOn');
|
||||||
|
}
|
||||||
|
|
||||||
|
async repairDB() {
|
||||||
|
console.log('starting DB repair');
|
||||||
|
await super.repairDB();
|
||||||
|
console.log('starting DB repair for addOn');
|
||||||
|
let lastTickTime = await this.models.TickRate.findOne({
|
||||||
|
where: { server: this.options.overrideServerID || this.server.id},
|
||||||
|
order: [['id', 'DESC']],
|
||||||
|
logging: console.log
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.log('last tick found:', lastTickTime);
|
||||||
|
let lastServerDate = lastTickTime.time;
|
||||||
|
let lastServerTime = lastServerDate.getFullYear() + '-' + (lastServerDate.getMonth() + 1) + '-' + lastServerDate.getDate()+' '+lastServerDate.getHours()+':'+lastServerDate.getMinutes()+':'+lastServerDate.getSeconds();
|
||||||
|
console.log('last time found:', lastServerTime);
|
||||||
|
let playerOnlineID = [];
|
||||||
|
playerOnlineID.push(0);
|
||||||
|
for (const player of this.server.players){
|
||||||
|
playerOnlineID.push(player.steamID);
|
||||||
|
}
|
||||||
|
console.log('players online:', playerOnlineID);
|
||||||
|
const {ne, not, notIn, is} = Sequelize.Op;
|
||||||
|
let updateVals = { leaveTime: lastServerTime };
|
||||||
|
let whereStuff = {
|
||||||
|
leaveTime: {[is]: null},
|
||||||
|
server: this.options.overrideServerID || this.server.id,
|
||||||
|
player: {[notIn]: playerOnlineID}
|
||||||
|
};
|
||||||
|
console.log(updateVals);
|
||||||
|
console.log(whereStuff);
|
||||||
|
let rowUpdate = await this.models.PlayerTime.update(
|
||||||
|
updateVals, {
|
||||||
|
where: whereStuff,
|
||||||
|
logging: console.log
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.log('updated playerTimes row count: %i', rowUpdate[0]);
|
||||||
|
console.log('finish DB repair');
|
||||||
}
|
}
|
||||||
|
|
||||||
async unmount() {
|
async unmount() {
|
||||||
this.models.PlayerTime.update(
|
this.models.PlayerTime.update(
|
||||||
{ leaveTime: 0 },
|
{ leaveTime: 0 },
|
||||||
{ where: { leaveTime: null , server: this.options.overrideServerID || this.server.id } }
|
{ where: { leaveTime: null , server: this.options.overrideServerID || this.server.id } }
|
||||||
);
|
);
|
||||||
await super.unmount();
|
await super.unmount();
|
||||||
this.server.removeEventListener('PLAYER_CONNECTED', this.onPlayerConnected);
|
this.server.removeEventListener('PLAYER_CONNECTED', this.onPlayerConnected);
|
||||||
this.server.removeEventListener('PLAYER_DISCONNECTED', this.onPlayerDisconnected);
|
this.server.removeEventListener('PLAYER_DISCONNECTED', this.onPlayerDisconnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
async onUpdatedA2SInformation(info) {
|
async onUpdatedA2SInformation(info) {
|
||||||
await super.onUpdatedA2SInformation(info);
|
await super.onUpdatedA2SInformation(info);
|
||||||
|
|
||||||
if(info.a2sPlayerCount >= this.options.seedingThreshold && this.seeding === true) {
|
|
||||||
await this.models.PlayerTime.update(
|
|
||||||
{ seedTime: info.time },
|
|
||||||
{ where: { seedTime: null, joinedSeeding: 1, leaveTime: null, server: this.options.overrideServerID || this.server.id } }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.seeding === true && info.a2sPlayerCount >= this.options.seedingThreshold) this.seeding = false;
|
if((this.seeding == true) && (info.a2sPlayerCount >= this.options.seedingThreshold)){
|
||||||
else if(this.seeding === false && (info.a2sPlayerCount-20) < this.options.seedingThreshold) this.seeding = true;
|
console.log('switching to Live');
|
||||||
|
this.seeding = false;
|
||||||
|
let curDateTime = new Date();
|
||||||
|
let timeNow = curDateTime.getFullYear() + '-' + (curDateTime.getMonth() + 1) + '-' + curDateTime.getDate()+' '+curDateTime.getHours()+':'+curDateTime.getMinutes()+':'+curDateTime.getSeconds();
|
||||||
|
console.log(timeNow);
|
||||||
|
await this.models.PlayerTime.update(
|
||||||
|
{ seedTime: timeNow },
|
||||||
|
{ where: { seedTime: null, joinedSeeding: 1, leaveTime: null, server: this.options.overrideServerID || this.server.id } }
|
||||||
|
);
|
||||||
|
}else if(this.seeding == false && (info.a2sPlayerCount-20) < this.options.seedingThreshold){
|
||||||
|
console.log('switching to seeding');
|
||||||
|
this.seeding = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onPlayerConnected(info) {
|
async onPlayerConnected(info) {
|
||||||
console.log(info);
|
console.log(info);
|
||||||
if(info.player){
|
if(info.player){
|
||||||
await this.models.PlayerTime.create({
|
await this.models.SteamUser.upsert({
|
||||||
server: this.options.overrideServerID || this.server.id,
|
steamID: info.player.steamID,
|
||||||
player: info.player.steamID,
|
lastName: info.player.name
|
||||||
playerName: info.player.name,
|
});
|
||||||
joinTime: info.time,
|
await this.models.PlayerTime.create({
|
||||||
joinedSeeding: this.seeding
|
server: this.options.overrideServerID || this.server.id,
|
||||||
});
|
player: info.steamID,
|
||||||
}
|
joinTime: info.time,
|
||||||
|
joinedSeeding: this.seeding
|
||||||
|
});
|
||||||
|
console.log('player connect complete');
|
||||||
|
} else console.log('player is null');
|
||||||
}
|
}
|
||||||
|
|
||||||
async onPlayerDisconnected(info) {
|
async onPlayerDisconnected(info) {
|
||||||
|
await sleep (500);
|
||||||
console.log(info);
|
console.log(info);
|
||||||
if(info.player){
|
if(info.player){
|
||||||
await this.models.PlayerTime.update(
|
await this.models.SteamUser.upsert({
|
||||||
{ leaveTime: info.time },
|
steamID: info.player.steamID,
|
||||||
{ where: { player: info.player.steamID, leaveTime: null, server: this.options.overrideServerID || this.server.id } }
|
lastName: info.player.name
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
let rowAffect = await this.models.PlayerTime.update(
|
||||||
|
{ leaveTime: info.time },
|
||||||
|
{ where: { player: info.steamID, leaveTime: null, server: this.options.overrideServerID || this.server.id } }
|
||||||
|
);
|
||||||
|
console.log('player disconnect rows update: %i', rowAffect[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user