mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Refactor of commands
This commit is contained in:
37
old/modules/ExpGamingPlayer/afkKick/control.lua
Normal file
37
old/modules/ExpGamingPlayer/afkKick/control.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
--- A full ranking system for factorio.
|
||||
-- @module ExpGamingPlayer.afkKick@4.0.0
|
||||
-- @author Cooldude2606
|
||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||
|
||||
local Game = require('FactorioStdLib.Game')
|
||||
local Role -- ExpGamingCore.Role@^4.0.0
|
||||
local Sync -- ExpGamingCore.Sync@^4.0.0
|
||||
|
||||
local function get_allowed_afk_time(player)
|
||||
player = Game.get_player(player)
|
||||
local role = Role and Role.get_highest(player) or {index=1,allow_afk_kick=not player.admin}
|
||||
local player_count = #game.connected_players
|
||||
local role_count = Role and Role.meta.count or 1
|
||||
local role_index = role.allow_afk_kick and role.index or false
|
||||
if not role_index then return false end
|
||||
return (role_count/role_index)*player_count
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_tick,function(event)
|
||||
if (game.tick%3600) ~= 0 then return end
|
||||
for _,player in pairs(game.connected_players) do
|
||||
local afk = #game.connected_players < 3 and 10 or get_allowed_afk_time(player)
|
||||
if afk then
|
||||
if player.afk_time > afk*3600 then game.kick_player(player,'AFK For Too Long ('..math.floor(afk)..' Minutes)') end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
return setmetatable({
|
||||
get_allowed_afk_time=get_allowed_afk_time,
|
||||
on_init=function(self)
|
||||
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
|
||||
if loaded_modules['ExpGamingCore.Sync'] then Sync = require('ExpGamingCore.Sync') end
|
||||
if loaded_modules['ExpGamingCore.Server'] then require(module_path..'/src/server',{Sync=Sync,self=self}) end
|
||||
end
|
||||
},{__call=function(self,...) return self.get_allowed_afk_time(...) end})
|
||||
22
old/modules/ExpGamingPlayer/afkKick/softmod.json
Normal file
22
old/modules/ExpGamingPlayer/afkKick/softmod.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "ExpGamingPlayer.afkKick",
|
||||
"version": "4.0.0",
|
||||
"description": "Adds a varible amount of time before a user is kicked based on the current player count.",
|
||||
"location": "FSM_ARCHIVE",
|
||||
"keywords": [
|
||||
"Kick",
|
||||
"AFK",
|
||||
"Players",
|
||||
"Smart",
|
||||
"Varible"
|
||||
],
|
||||
"dependencies": {
|
||||
"FactorioStdLib.Game": "^0.8.0",
|
||||
"ExpGamingCore.Gui": "^4.0.0",
|
||||
"ExpGamingCore.Role": "?^4.0.0",
|
||||
"ExpGamingCore.Sync": "?^4.0.0",
|
||||
"ExpGamingCore.Server": "?^4.0.0"
|
||||
},
|
||||
"collection": "ExpGamingPlayer@4.0.0",
|
||||
"submodules": {}
|
||||
}
|
||||
29
old/modules/ExpGamingPlayer/afkKick/src/server.lua
Normal file
29
old/modules/ExpGamingPlayer/afkKick/src/server.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
local Sync = Sync
|
||||
local get_allowed_afk_time = self
|
||||
local Server = require('ExpGamingCore.Server')
|
||||
local Color = require('FactorioStdLib.Color')
|
||||
Event[defines.events.on_tick] = nil
|
||||
|
||||
script.on_init(function(event)
|
||||
Server.new_thread{
|
||||
name='afk-kick',
|
||||
}:on_event('tick',function(self)
|
||||
if (game.tick%3600) ~= 0 then return end
|
||||
for _,player in pairs(game.connected_players) do
|
||||
local afk = #game.connected_players < 3 and 10 or get_allowed_afk_time(player)
|
||||
if afk then
|
||||
if player.afk_time > afk*3600 then game.kick_player(player,'AFK For Too Long ('..math.floor(afk)..' Minutes)') end
|
||||
end
|
||||
end
|
||||
end):on_event('error',function(self,err)
|
||||
if Sync then
|
||||
Sync.emit_embedded{
|
||||
title='Auto Kick Error',
|
||||
color=Color.to_hex(defines.textcolor.bg),
|
||||
description='Auto Kick Error - Closed Thread',
|
||||
Error=err
|
||||
}
|
||||
end
|
||||
self:close()
|
||||
end):open()
|
||||
end)
|
||||
Reference in New Issue
Block a user