mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 04:51:40 +09:00
Minor bug fixes
This commit is contained in:
16
config/expcore-commands/auth_admin.lua
Normal file
16
config/expcore-commands/auth_admin.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
--- This is a very simple config file which adds a admin only auth function
|
||||
-- not much to change here its more so it can be enabled and disabled from ./config/file_loader.lua
|
||||
-- either way you can change the requirements to be "admin" if you wanted to
|
||||
local Commands = require 'expcore.commands'
|
||||
|
||||
Commands.add_authenticator(function(player,command,tags,reject)
|
||||
if tags.admin_only then
|
||||
if player.admin then
|
||||
return true
|
||||
else
|
||||
return reject{'command-auth.admin-only'}
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
end)
|
||||
11
config/expcore-commands/auth_roles.lua
Normal file
11
config/expcore-commands/auth_roles.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
--- This will make commands only work if the role has been allowed it in the role config
|
||||
local Commands = require 'expcore.commands'
|
||||
local Roles = require 'expcore.roles'
|
||||
|
||||
Commands.add_authenticator(function(player,command,tags,reject)
|
||||
if Roles.player_allowed(player,'command/'..command) then
|
||||
return true
|
||||
else
|
||||
return reject()
|
||||
end
|
||||
end)
|
||||
25
config/expcore-commands/auth_runtime_disable.lua
Normal file
25
config/expcore-commands/auth_runtime_disable.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
--- This config for command auth allows commands to be globally enabled and disabled during runtime
|
||||
-- this config adds Commands.disable and Commands.enable to enable and disable commands for all users
|
||||
local Commands = require 'expcore.commands'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local disabled_commands = {}
|
||||
Global.register(disabled_commands,function(tbl)
|
||||
disabled_commands = tbl
|
||||
end)
|
||||
|
||||
function Commands.disable(command_name)
|
||||
disabled_commands[command_name] = true
|
||||
end
|
||||
|
||||
function Commands.enable(command_name)
|
||||
disabled_commands[command_name] = nil
|
||||
end
|
||||
|
||||
Commands.add_authenticator(function(player,command,tags,reject)
|
||||
if disabled_commands[command] then
|
||||
return reject{'command-auth.command-disabled'}
|
||||
else
|
||||
return true
|
||||
end
|
||||
end)
|
||||
147
config/expcore-commands/parse_general.lua
Normal file
147
config/expcore-commands/parse_general.lua
Normal file
@@ -0,0 +1,147 @@
|
||||
--- This file contains some common command param parse functions
|
||||
-- this file is less of a config and more of a requirement but you may wish to change how some behave
|
||||
-- as such you need to be confident with lua but you edit this config file
|
||||
-- use Commands.add_parse('name',function(input,player,reject) end) to add a parse
|
||||
-- see ./expcore/commands.lua for more details
|
||||
local Commands = require 'expcore.commands'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
--[[
|
||||
>>>>Adds Parses:
|
||||
boolean
|
||||
string-options - options: array
|
||||
string-max-length - max_length: number
|
||||
number
|
||||
integer
|
||||
number-range - range_min: number, range_max: number
|
||||
integer-range - range_min: number, range_max: number
|
||||
player
|
||||
player-online
|
||||
player-alive
|
||||
force
|
||||
surface
|
||||
]]
|
||||
|
||||
Commands.add_parse('boolean',function(input,player,reject)
|
||||
if not input then return end -- nil check
|
||||
input = input:lower()
|
||||
if input == 'yes'
|
||||
or input == 'y'
|
||||
or input == 'true'
|
||||
or input == '1' then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('string-options',function(input,player,reject,options)
|
||||
if not input then return end -- nil check
|
||||
input = input:lower()
|
||||
for option in options do
|
||||
if input == option:lower() then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return reject{'reject-string-options',options:concat(', ')}
|
||||
end)
|
||||
|
||||
Commands.add_parse('string-max-length',function(input,player,reject,max_length)
|
||||
if not input then return end -- nil check
|
||||
local length = input:len()
|
||||
if length > max_length then
|
||||
return reject{'expcore-commands.reject-string-max-length',max_length}
|
||||
else
|
||||
return input
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('number',function(input,player,reject)
|
||||
if not input then return end -- nil check
|
||||
local number = tonumber(input)
|
||||
if not number then
|
||||
return reject{'expcore-commands.reject-number'}
|
||||
else
|
||||
return number
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('integer',function(input,player,reject)
|
||||
if not input then return end -- nil check
|
||||
local number = tonumber(input)
|
||||
if not number then
|
||||
return reject{'expcore-commands.reject-number'}
|
||||
else
|
||||
return math.floor(number)
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('number-range',function(input,player,reject,range_min,range_max)
|
||||
local number = Commands.parse('number',input,player,reject)
|
||||
if not number then return end -- nil check
|
||||
if number < range_min or number > range_max then
|
||||
return reject{'expcore-commands.reject-number-range',range_min,range_max}
|
||||
else
|
||||
return number
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('integer-range',function(input,player,reject,range_min,range_max)
|
||||
local number = Commands.parse('integer',input,player,reject)
|
||||
if not number then return end -- nil check
|
||||
if number < range_min or number > range_max then
|
||||
return reject{'expcore-commands.reject-number-range',range_min,range_max}
|
||||
else
|
||||
return number
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('player',function(input,player,reject)
|
||||
if not input then return end -- nil check
|
||||
local input_player = Game.get_player_from_any(input)
|
||||
if not input_player then
|
||||
return reject{'expcore-commands.reject-player',input}
|
||||
else
|
||||
return input_player
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('player-online',function(input,player,reject)
|
||||
local input_player = Commands.parse('player',input,player,reject)
|
||||
if not input_player then return end -- nil check
|
||||
if not input_player.connected then
|
||||
return reject{'expcore-commands.reject-player-online'}
|
||||
else
|
||||
return input_player
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('player-alive',function(input,player,reject)
|
||||
local input_player = Commands.parse('player-online',input,player,reject)
|
||||
if not input_player then return end -- nil check
|
||||
if not input_player.character or not input_player.character.health or input_player.character.health <= 0 then
|
||||
return reject{'expcore-commands.reject-player-alive'}
|
||||
else
|
||||
return input_player
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('force',function(input,player,reject)
|
||||
if not input then return end -- nil check
|
||||
local force = game.forces[input]
|
||||
if not force then
|
||||
return reject{'expcore-commands.reject-force'}
|
||||
else
|
||||
return force
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('surface',function(input,player,reject)
|
||||
if not input then return end
|
||||
local surface = game.surfaces[input]
|
||||
if not surface then
|
||||
return reject{'expcore-commands.reject-surface'}
|
||||
else
|
||||
return surface
|
||||
end
|
||||
end)
|
||||
45
config/expcore-commands/parse_roles.lua
Normal file
45
config/expcore-commands/parse_roles.lua
Normal file
@@ -0,0 +1,45 @@
|
||||
--- Adds some parse functions that can be used with the role system
|
||||
local Commands = require 'expcore.commands'
|
||||
local Roles = require 'expcore.roles'
|
||||
local auto_complete = ext_require('expcore.common','auto_complete')
|
||||
require 'config.expcore-commands.parse_general'
|
||||
|
||||
Commands.add_parse('role',function(input,player,reject)
|
||||
if not input then return end
|
||||
local roles = Roles.config.order
|
||||
local rev_roles = {}
|
||||
for i=#roles,1,-1 do
|
||||
table.insert(rev_roles,roles[i])
|
||||
end
|
||||
local role = auto_complete(rev_roles,input)
|
||||
role = Roles.get_role_by_name(role)
|
||||
if not role then
|
||||
return reject{'expcore-role.reject-role'}
|
||||
else
|
||||
return role
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('player-role',function(input,player,reject)
|
||||
local input_player = Commands.parse('player',input,player,reject)
|
||||
if not input_player then return end -- nil check
|
||||
local player_highest = Roles.get_player_highest_role(player)
|
||||
local input_player_highest = Roles.get_player_highest_role(input_player)
|
||||
if player_highest.index < input_player_highest.index then
|
||||
return input_player
|
||||
else
|
||||
return reject{'expcore-roles.reject-player-role'}
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('player-role-online',function(input,player,reject)
|
||||
local input_player = Commands.parse('player-role',input,player,reject)
|
||||
if not input_player then return end -- nil check
|
||||
return Commands.parse('player-online',input_player,player,reject)
|
||||
end)
|
||||
|
||||
Commands.add_parse('player-role-alive',function(input,player,reject)
|
||||
local input_player = Commands.parse('player-role',input,player,reject)
|
||||
if not input_player then return end -- nil check
|
||||
return Commands.parse('player-alive',input_player,player,reject)
|
||||
end)
|
||||
Reference in New Issue
Block a user