Skip to content

Commit

Permalink
Merge branch 'release/5.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Cooldude2606 committed Mar 16, 2019
2 parents c735dd8 + 89b9d8e commit 47a6a3f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
5 changes: 3 additions & 2 deletions config/permission_groups.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ Permission_Groups.new_group('Restricted')
local trusted_time = 60*60*60*10 -- 10 hour
local standard_time = 60*60*60*3 -- 3 hour
local function assign_group(player)
local current_group_name = player.permission_group and player.permission_group.name or 'None'
if player.admin then
Permission_Groups.set_player_group(player,'Admin')
elseif player.online_time > trusted_time then
elseif player.online_time > trusted_time and current_group_name == 'Trusted' then
Permission_Groups.set_player_group(player,'Trusted')
elseif player.online_time > standard_time then
elseif player.online_time > standard_time and current_group_name == 'Guest' then
Permission_Groups.set_player_group(player,'Standard')
else
Permission_Groups.set_player_group(player,'Guest')
Expand Down
9 changes: 7 additions & 2 deletions expcore/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,9 @@ end

-- logs command usage to file
local function command_log(player,command,comment,params,raw,details)
local player_name = player and player.name or '<Server>'
game.write_file('log/commands.log',game.table_to_json{
player_name=player.name,
player_name=player_name,
command_name=command.name,
comment=comment,
details=details,
Expand All @@ -537,7 +538,11 @@ end
-- @tparam command_event table passed directly from command event from the add_command function
function Commands.run_command(command_event)
local command_data = Commands.commands[command_event.name]
local player = Game.get_player_by_index(command_event.player_index)
-- player can be nil when it is the server
local player
if command_event.player_index and command_event.player_index > 0 then
player = Game.get_player_by_index(command_event.player_index)
end

-- checks if player is allowed to use the command
local authorized, auth_fail = Commands.authorize(player,command_data.name)
Expand Down
5 changes: 3 additions & 2 deletions modules/commands/admin-chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ Commands.new_command('admin-chat','Sends a message in chat that only admins can
:add_tag('admin_only',true)
:add_alias('ac')
:register(function(player,message,raw)
local pcc = player.chat_color
local pcc = player and player.chat_color or {r=255,g=255,b=255}
local player_name = player and player.name or '<Server>'
local colour = string.format('%s,%s,%s',pcc.r,pcc.g,pcc.b)
for _,return_player in pairs(game.connected_players) do
if return_player.admin then
return_player.print{'exp-commands.admin-chat-format',player.name,message,colour}
return_player.print{'exp-commands.admin-chat-format',player_name,message,colour}
end
end
return Commands.success -- prevents command complete message from showing
Expand Down
9 changes: 5 additions & 4 deletions modules/commands/help.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Commands.new_command('chelp','Searches for a keyword in all commands you are all
:add_param('page',true,'integer') -- the keyword that will be looked for
:add_defaults{keyword='',page=1}
:register(function(player,keyword,page,raw)
local player_index = player and player.index or 0
-- if keyword is a number then treat it as page number
if tonumber(keyword) then
page = math.floor(tonumber(keyword))
Expand All @@ -22,9 +23,9 @@ Commands.new_command('chelp','Searches for a keyword in all commands you are all
-- gets a value for pages, might have result in cache
local pages
local found = 0
if search_cache[player.index] and search_cache[player.index].keyword == keyword:lower() then
pages = search_cache[player.index].pages
found = search_cache[player.index].found
if search_cache[player_index] and search_cache[player_index].keyword == keyword:lower() then
pages = search_cache[player_index].pages
found = search_cache[player_index].found
else
pages = {{}}
local current_page = 1
Expand All @@ -51,7 +52,7 @@ Commands.new_command('chelp','Searches for a keyword in all commands you are all
})
end
-- adds the result to the cache
search_cache[player.index] = {
search_cache[player_index] = {
keyword=keyword:lower(),
pages=pages,
found=found
Expand Down
10 changes: 6 additions & 4 deletions modules/commands/interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ Commands.new_command('interface','Sends an innovation to be ran and returns the
end
-- temp_env will index to interface_env and interface_modules if value not found
local temp_env = setmetatable({},{__index=get_index})
for name,callback in pairs(interface_callbacks) do
-- loops over callbacks and loads the values returned
local success, rtn = pcall(callback,player)
temp_env[name]=rtn
if player then -- player can be nil when it is the server
for name,callback in pairs(interface_callbacks) do
-- loops over callbacks and loads the values returned
local success, rtn = pcall(callback,player)
temp_env[name]=rtn
end
end
-- sets the global metatable to prevent new values being made
-- global will index to temp_env and new indexs saved to interface_sandbox
Expand Down
3 changes: 2 additions & 1 deletion modules/commands/me.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Commands.new_command('me','Sends an action message in the chat')
:add_param('action',false) -- action that is done by the player, just text its meaningless
:enable_auto_concat()
:register(function(player,action,raw)
game.print(string.format('* %s %s *',player.name,action),player.chat_color)
local player_name = player and player.name or '<Server>'
game.print(string.format('* %s %s *',player_name,action),player.chat_color)
end)

0 comments on commit 47a6a3f

Please sign in to comment.