Skip to content

Commit

Permalink
优化sharedata使用错误时,输出更友好的错误提示
Browse files Browse the repository at this point in the history
  • Loading branch information
huahua132 committed Jan 11, 2025
1 parent 528b091 commit 5ff4d7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lualib/skynet-fly/sharedata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ end})

--加载指定路径列表下配置, mode = sharedata or sharetable
function M.load(dir_list, mode)
assert(mode == M.enum.sharedata or mode == M.enum.sharetable)
assert(mode == M.enum.sharedata or mode == M.enum.sharetable, "not exists mode = " .. mode)
local sd = skynet.uniqueservice("sharedata_service")
skynet.call(sd, 'lua', 'load', dir_list, mode)
end
Expand All @@ -189,7 +189,9 @@ end

--访问代理
function M:new(file_path, mode)
assert(mode == M.enum.sharedata or mode == M.enum.sharetable)
assert(mode == M.enum.sharedata or mode == M.enum.sharetable, "not exists mode = " .. mode)
local sd = skynet.uniqueservice("sharedata_service")
assert(skynet.call(sd, 'lua', 'is_vaild_file_path', file_path, mode))
local t = {
mode = mode,
file_path = file_path,
Expand All @@ -203,6 +205,7 @@ function M:new(file_path, mode)
map_map = {}, --map映射表
map_map_fields = {}, --map映射表key字段列表
}

g_mode_map[file_path] = mode
t.data_table = g_data_map[file_path]
t.version = g_version_map[file_path]
Expand Down
21 changes: 21 additions & 0 deletions service/sharedata_service.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ local ENUM = {
sharetable = 2,
}

local MODE_NAME = {
[1] = "sharedata",
[2] = "sharetable",
}

local g_watch_server = nil
local g_file_changetime_map = {}
local g_load_dir_map = {}
Expand Down Expand Up @@ -58,6 +63,7 @@ local function load_new_file(file_path, file_info, cur_time, mode)
log.info("sharedata load loadfile:", file_path)
end

--加载目录下的配置
function CMD.load(dir_list, mode)
assert(g_modes[mode], "not exists mode:" .. tostring(mode))
local cur_time = time_util.time()
Expand All @@ -73,6 +79,7 @@ function CMD.load(dir_list, mode)
end
end

--检查热更目录下的配置
function CMD.check_reload()
local reload_list = {}
local cur_time = time_util.time()
Expand Down Expand Up @@ -108,6 +115,20 @@ function CMD.check_reload()
return json.encode(reload_list)
end

--检查路径是否有效
function CMD.is_vaild_file_path(file_path, mode)
if not g_file_changetime_map[file_path] then
return false, string.format("not exists file_path[%s]", file_path)
end

local info = g_file_changetime_map[file_path]
if info.mode ~= mode then
return false, string.format("mode not match load mode[%s] use mode[%s]", MODE_NAME[info.mode], MODE_NAME[mode])
end

return true
end

g_watch_server = watch_syn.new_server(CMD)

skynet.start(function()
Expand Down

0 comments on commit 5ff4d7b

Please sign in to comment.