mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Added Admin Only Auth
This commit is contained in:
@@ -15,7 +15,6 @@ Debug = require 'utils.debug'
|
||||
require 'resources.version'
|
||||
|
||||
local files = {
|
||||
'modules.test',
|
||||
'modules.commands.me',
|
||||
'modules.commands.kill',
|
||||
'modules.commands.admin-chat',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local Commands = require 'expcore.commands'
|
||||
require 'expcore.common_parse'
|
||||
require 'modules.commands.admin-only-auth'
|
||||
|
||||
Commands.new_command('admin-chat','Sends a message in chat that only admins can see.')
|
||||
:add_param('message',false) -- the message to send in the admin chat
|
||||
|
||||
13
modules/commands/admin-only-auth.lua
Normal file
13
modules/commands/admin-only-auth.lua
Normal file
@@ -0,0 +1,13 @@
|
||||
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('This command is for admins only!')
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
end)
|
||||
@@ -1,5 +1,6 @@
|
||||
local Commands = require 'expcore.commands'
|
||||
require 'expcore.common_parse'
|
||||
require 'modules.commands.admin-only-auth'
|
||||
|
||||
Commands.new_command('toggle-cheat-mode','Toggles cheat mode for your player, or another player.')
|
||||
:add_param('player',true,'player') -- player to toggle chest mode of, can be nil for self
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local Commands = require 'expcore.commands'
|
||||
local Global = require 'utils.global'
|
||||
local Common = require 'expcore.common'
|
||||
require 'modules.commands.admin-only-auth'
|
||||
|
||||
-- modules that are loaded into the interface env to be accessed
|
||||
local interface_modules = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local Commands = require 'expcore.commands'
|
||||
require 'expcore.common_parse'
|
||||
require 'modules.commands.admin-only-auth'
|
||||
|
||||
Commands.new_command('kill','Kills yourself or another player.')
|
||||
:add_param('player',true,'player-alive') -- the player to kill, must be alive to be valid
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local Commands = require 'expcore.commands'
|
||||
require 'expcore.common_parse'
|
||||
require 'modules.commands.admin-only-auth'
|
||||
|
||||
local function teleport(from_player,to_player)
|
||||
local surface = to_player.surface
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
local Event = require 'utils.event'
|
||||
|
||||
function thisIsATestFunction(...)
|
||||
game.print(serpent.line({...}))
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_console_chat,function(event)
|
||||
if event.player_index then game.print('Message: '..event.message) end
|
||||
end)
|
||||
|
||||
local Commands = require 'expcore.commands' -- require the Commands module
|
||||
|
||||
Commands.add_authenticator(function(player,command,tags,reject)
|
||||
if tags.admin_only then
|
||||
if player.admin then
|
||||
return true
|
||||
else
|
||||
return reject('This command is for admins only!')
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse('number_range_int',function(input,player,reject,range_min,range_max)
|
||||
local rtn = tonumber(input) and math.floor(tonumber(input)) or nil
|
||||
if not rtn or rtn < range_min or rtn > range_max then
|
||||
return reject('Number entered is not in range: '..range_min..', '..range_max)
|
||||
else
|
||||
return rtn
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.new_command('repeat-name','Will repeat you name a number of times in chat.')
|
||||
:add_param('repeat-count',false,'number_range_int',1,5)
|
||||
:add_param('smiley',true,function(input,player,reject)
|
||||
if not input then return end
|
||||
if input:lower() == 'true' or input:lower() == 'yes' then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end)
|
||||
:add_defaults{smiley=false}
|
||||
:add_tag('admin_only',true)
|
||||
:add_alias('name','rname')
|
||||
:register(function(player,repeat_count,smiley,raw)
|
||||
game.print(player.name..' used a command with input: '..raw)
|
||||
local msg = ') '..player.name
|
||||
if smiley then
|
||||
msg = ':'..msg
|
||||
end
|
||||
for i = 1,repeat_count do
|
||||
Commands.print(i..msg)
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user