Fix issues with util and commands

- Use rawget when testing for locale strings
- Use player index 0 for errors in rcon commands
This commit is contained in:
Cooldude2606
2025-01-11 00:38:24 +00:00
parent 6b0949047e
commit 3e6ec6a867
2 changed files with 3 additions and 3 deletions

View File

@@ -565,7 +565,7 @@ function Commands._prototype:register(callback)
local success, traceback = xpcall(Commands._event_handler, debug.traceback, event)
--- @cast traceback string
if not success and not traceback:find("Command does not support rcon usage") then
local key = "<" .. table.concat({ event.name, event.player_index, event.tick }, ":") .. ">"
local key = "<" .. table.concat({ event.name, event.player_index or 0, event.tick }, ":") .. ">"
local _, msg = Commands.status.internal_error(key)
Commands.error(msg)
log("Internal Command Error " .. key .. "\n" .. traceback)

View File

@@ -145,7 +145,7 @@ end
--- @param level number? The level of the stack to get the module of, a value of 1 is the caller of this function
--- @return string # The name of the module at the given stack frame
function ExpUtil.get_module_name(level)
local file_within_module = getinfo((level or 1) + 1, "S").short_src:sub(18, -5)
local file_within_module = getinfo((level or 1) + 1, "S").short_src:sub(19, -5)
local next_slash = file_within_module:find("/")
if next_slash then
return file_within_module:sub(1, next_slash - 1)
@@ -197,7 +197,7 @@ end
function ExpUtil.safe_value(value)
local _type = type(value)
if _type == "table" then
local v1 = value[1]
local v1 = rawget(value, 1)
local str = tostring(value)
if type(v1) == "string" and not v1:find("%s")
and (v1 == "" or v1 == "?" or v1:find(".+[.].+"))