diff --git a/config/permission_groups.lua b/config/permission_groups.lua index d171bdcc..29b9ff5f 100644 --- a/config/permission_groups.lua +++ b/config/permission_groups.lua @@ -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') diff --git a/expcore/commands.lua b/expcore/commands.lua index 432e2680..dbfc9b06 100644 --- a/expcore/commands.lua +++ b/expcore/commands.lua @@ -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 '' 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, @@ -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) diff --git a/modules/commands/admin-chat.lua b/modules/commands/admin-chat.lua index 00ae2d5d..6df5a58b 100644 --- a/modules/commands/admin-chat.lua +++ b/modules/commands/admin-chat.lua @@ -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 '' 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 diff --git a/modules/commands/help.lua b/modules/commands/help.lua index 07e1c572..9d8a2183 100644 --- a/modules/commands/help.lua +++ b/modules/commands/help.lua @@ -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)) @@ -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 @@ -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 diff --git a/modules/commands/interface.lua b/modules/commands/interface.lua index d4354721..a2eff255 100644 --- a/modules/commands/interface.lua +++ b/modules/commands/interface.lua @@ -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 diff --git a/modules/commands/me.lua b/modules/commands/me.lua index 47c1285a..87b3d5c8 100644 --- a/modules/commands/me.lua +++ b/modules/commands/me.lua @@ -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 '' + game.print(string.format('* %s %s *',player_name,action),player.chat_color) end) \ No newline at end of file