mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 16:24:25 -05:00
add more options
This commit is contained in:
parent
de49addc95
commit
b784a9f4c9
@ -288,4 +288,7 @@ export default class Rcon extends EventEmiiter {
|
|||||||
async warn(steamID, message) {
|
async warn(steamID, message) {
|
||||||
await this.execute(`AdminWarn "${steamID}" ${message}`);
|
await this.execute(`AdminWarn "${steamID}" ${message}`);
|
||||||
}
|
}
|
||||||
|
async kick(steamID, reason) {
|
||||||
|
await this.execute(`AdminKick "${steamID}" ${reason}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,29 @@ export default class AutoKickAFK extends BasePlugin {
|
|||||||
warning: {
|
warning: {
|
||||||
required: false,
|
required: false,
|
||||||
description:
|
description:
|
||||||
'If enabled SquadJS will warn a player once before kicking them. To disable remove the message `""`',
|
'If enabled SquadJS will warn a player once before kicking them. To disable remove the message (`""`)',
|
||||||
default: 'Players not in a squad are unassigned and will be kicked in 3 minutes'
|
default: 'Players not in a squad are unassigned and will be kicked in 3 minutes'
|
||||||
},
|
},
|
||||||
updateInterval: {
|
updateInterval: {
|
||||||
required: true,
|
required: false,
|
||||||
description: 'How frequently to check if players are AFK in minutes.',
|
description: 'How frequently to check if players are AFK in minutes. If the warning is enabled a player will be kicked after 2x this value otherwise they will be kicked immediately.',
|
||||||
default: 3
|
default: 3
|
||||||
}
|
},
|
||||||
|
playerThreshold:{
|
||||||
|
required: false,
|
||||||
|
description: 'Player count required for Auto Kick to start kicking players to disable set to above max player count',
|
||||||
|
default: 93
|
||||||
|
},
|
||||||
|
queueThreshold:{
|
||||||
|
required: false,
|
||||||
|
description: 'The number of players in the queue before Auto Kick starts kicking players set to -1 to disable',
|
||||||
|
default: -1
|
||||||
|
}/*,
|
||||||
|
ignoreAdmins:{
|
||||||
|
required: false,
|
||||||
|
description: 'Whether or not admins will be auto kicked for being unassigned',
|
||||||
|
default: false
|
||||||
|
}*/
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,41 +44,65 @@ export default class AutoKickAFK extends BasePlugin {
|
|||||||
super();
|
super();
|
||||||
|
|
||||||
this.playerDict = {};
|
this.playerDict = {};
|
||||||
|
//for initial testing
|
||||||
|
this.auditMode = true;
|
||||||
|
|
||||||
const intervalMS = options.updateInterval * 60 * 1000;
|
const intervalMS = options.updateInterval * 60 * 1000;
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval( async ()=>{
|
||||||
console.log(server.players);
|
if(server.players.count <= options.playerCountThreshold || ( server.publicQueue > options.queueThreshold > 0) ){
|
||||||
const lookup = {};
|
// clear tracking vlaues so if the player count indreases/decreases past any threshold stale players arent counted again if they happen to be unassigned
|
||||||
for (const player of server.players) {
|
this.playerDict = {};
|
||||||
lookup[player.steamID] = player;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const player of server.players) {
|
||||||
// marks player if not in a Squad
|
// marks player if not in a Squad
|
||||||
if (player.squadID === null) {
|
if(player.squadID === null){
|
||||||
if (player.steamID in this.playerDict) {
|
if(player.steamID in this.playerDict){
|
||||||
|
// player in dict was already warned mark for kick
|
||||||
this.playerDict[player.steamID] += 1;
|
this.playerDict[player.steamID] += 1;
|
||||||
} else {
|
}else{
|
||||||
|
// player not in dict is added for warning
|
||||||
this.playerDict[player.steamID] = 0;
|
this.playerDict[player.steamID] = 0;
|
||||||
}
|
}
|
||||||
} else if (player.steamID in this.playerDict) {
|
}else if(player.steamID in this.playerDict){
|
||||||
// remove player from list if they joined a squad
|
// remove player from list if they joined a squad
|
||||||
delete this.playerDict[player.steamID];
|
delete this.playerDict[player.steamID];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(this.playerDict);
|
||||||
|
|
||||||
const copy = Object.assign({}, this.playerDict);
|
const copy = Object.assign({}, this.playerDict);
|
||||||
for (const [steamID, count] of Object.entries(copy)) {
|
for(const [steamID, warnings] of Object.entries(copy)){
|
||||||
if (count >= 1) {
|
if(warnings >= 1 || options.warning === ''){
|
||||||
await server.rcon.kick(steamID);
|
if(this.auditMode){
|
||||||
delete this.playerDict[steamID];
|
console.log(`[AUTO AFK] kick ${steamID} for AFK`)
|
||||||
}
|
}else{
|
||||||
if (count === 0 && options.warning !== '') {
|
// kick player that has been warned
|
||||||
await server.rcon.warn(steamID, options.warning);
|
await server.rcon.kick(steamID, 'UNASSIGNED - automatically removed');
|
||||||
} else {
|
delete this.playerDict[steamID];
|
||||||
await server.rcon.kick(steamID);
|
}
|
||||||
delete this.playerDict[steamID];
|
}else{
|
||||||
|
if(this.auditMode){
|
||||||
|
console.log(`[AUTO AFK] warn player ${steamID} for AFK`);
|
||||||
|
}else{
|
||||||
|
server.rcon.warn(steamID, options.warning);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, intervalMS);
|
} , intervalMS );
|
||||||
|
|
||||||
|
|
||||||
|
//clean up every 20 minutes, removes players no longer on the server that may be stuck in the tracking dict
|
||||||
|
const cleanupMS = 20*60*1000;
|
||||||
|
setInterval( ()=> {
|
||||||
|
for(steamID of Object.keys(this.playerDict))
|
||||||
|
if(!steamID in server.players.map(p => p.steamID))
|
||||||
|
delete this.playerDict[steamID];
|
||||||
|
}, cleanupMS);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user