diff --git a/lualib/skynet-fly/sharedata.lua b/lualib/skynet-fly/sharedata.lua index bb14a1ce..8d13091e 100644 --- a/lualib/skynet-fly/sharedata.lua +++ b/lualib/skynet-fly/sharedata.lua @@ -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 @@ -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, @@ -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] diff --git a/service/sharedata_service.lua b/service/sharedata_service.lua index fc32b915..c03f6d52 100644 --- a/service/sharedata_service.lua +++ b/service/sharedata_service.lua @@ -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 = {} @@ -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() @@ -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() @@ -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()