diff --git a/skynet b/skynet index dce5314..7d39312 160000 --- a/skynet +++ b/skynet @@ -1 +1 @@ -Subproject commit dce531485f84bb7a555e9bb35b22c58fb469192c +Subproject commit 7d39312ae9d50054c4b8dbb675da8024ccb5a834 diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index 89e0917..0ad8a68 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -16,7 +16,7 @@ function _M.clientRequest(agent, data) end function _M.testhotfix(role, pms) - return csvdb["itemCsv"][1]["name"] .. " -=- " .. csvdb["itemCsv"][2]["name"] .. " -=- " .. role:getItemCount(123) .. " -=- " .. table.pack(next(role.heros))[2]:getBattleValue() + return csvdb["itemCsv"][1]["name"] .. " -=- " .. globalCsv["codeVersion"] .. " -=- " .. role:getItemCount(123) .. " -=- " .. table.pack(next(role.heros))[2]:getBattleValue() end function _M.ignoreout(role, pms) diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index 947790a..6eac4c5 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -233,7 +233,7 @@ function _M.commentHeroRpc(agent, data) result.status = 1 else local commentKey = getCommentKey(heroType) - local SERV = string.format(".NAMED%d", math.random(1, 5)) + local SERV = string.format(".chatd%d", math.random(1, 5)) local legal, mod = skynet.call(SERV, "lua", "check", content) if not legal then content = mod or "" diff --git a/src/actions/HttpAction.lua b/src/actions/HttpAction.lua index 5bb9bcf..6e3984a 100644 --- a/src/actions/HttpAction.lua +++ b/src/actions/HttpAction.lua @@ -1,5 +1,3 @@ -local codecache = require "skynet.codecache" -- 清空缓存用 - local _M = {} @@ -19,45 +17,12 @@ local _M = {} ]=] --- 清空缓存 -function _M.clearcache(query, body) - skynet.error(string.format("clearcache time: %s", skynet.timex())) - codecache.clear() - return 'success' -end - ---重新加载 需要修改的csvdb -- 单字段修改 优先使用hotfix_csvdata ---[=[ eg: - body = """ - csvdb["itemCsv"][1]["name"] = "测试一下" - """ -]=] - -function _M.reload_csvdata(query, body) - if not body or body == "" then - return 'no body' - end - - local ok = pcall(load, body) - if not ok then - return "code error" - end - - local ok, status = pcall(skynet.call, '.CSVDATA', "lua", "reload", body) - if status == "ok" then - skynet.error(string.format("reload_csvdata time: %s, code: %s", skynet.timex(), body)) - return 'success' - else - return 'error update' - end -end - ---指定更新某个字段值 --[=[ 解码后 body = { - {"itemCsv", 1, "name", "测试一下"}, - {"itemCsv", 2, "name", "测试一下"} + "src/csvdata/init.lua", + "unitCsv", + "story_cgCsv", } ]=] function _M.hotfix_csvdata(query, body) @@ -69,14 +34,10 @@ function _M.hotfix_csvdata(query, body) if not ok or type(result) ~= 'table' then return "decode error" end - local ok, status = pcall(skynet.call, '.CSVDATA', "lua", "hotfix", result) - if status == "ok" then - skynet.error(string.format("hotfix_csvdata time: %s, code: %s", skynet.timex(), body)) - return 'success' - else - return 'error update' - end + csvdb.hotfix(table.unpack(result)) + + return 'success' end -- 热更新代码 -- 针对 agent 执行发送过来的代码 -- 代码要规范~ @@ -150,7 +111,7 @@ function _M.hotfix_code(query, body) skynet.error(string.format("hotfix_code time: %s, code: %s", skynet.timex(), body)) - pcall(skynet.call, '.WATCHDOG', "lua", "hotfix", body) + pcall(skynet.call, '.watchdog', "lua", "hotfix", body) return 'success' end diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 6cbb779..5e3abce 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -22,7 +22,7 @@ local function validName(name) local exist = redisproxy:exists(string_format("user:%s", name)) if exist then return "existed" end - local SERV = string_format(".NAMED%d", math.random(1, 5)) + local SERV = string_format(".named%d", math.random(1, 5)) local legal = skynet.call(SERV, "lua", "check", name) return legal and "ok" or "illegal" end @@ -217,7 +217,7 @@ function _M.loginRpc( agent, data ) -- 发下缓存的世界消息 local worldChatResponse = {worldChats = {}} - local ok, msgs = pcall(skynet.call, '.GLOBALD', "lua", "getWorldMsg", role._channelIdx) + local ok, msgs = pcall(skynet.call, '.globald', "lua", "getWorldMsg", role._channelIdx) if not ok then msgs = {} end @@ -365,7 +365,7 @@ function _M.changeIntroRpc(agent, data) local content = msg.content if not content or type(content) ~= "string" then return end - local SERV = string_format(".CHATED%d", math.random(1, 5)) + local SERV = string_format(".chated%d", math.random(1, 5)) local legal, mod = skynet.call(SERV, "lua", "check", content) if not legal then content = mod or "" @@ -750,7 +750,7 @@ function _M.chatRpc(agent, data) -- 判断禁言 local result = nil - local SERV = string_format(".CHATED%d", math.random(1, 5)) + local SERV = string_format(".chated%d", math.random(1, 5)) local legal, mod = skynet.call(SERV, "lua", "check", content) if not legal then content = mod or "" @@ -805,7 +805,7 @@ function _M.chatRpc(agent, data) end end mcast_util.pub_world(actionCodes.Role_chat, MsgPack.pack(response)) - pcall(skynet.send, '.GLOBALD', "lua", "sendWorldMsg", role._channelIdx, response) + pcall(skynet.send, '.globald', "lua", "sendWorldMsg", role._channelIdx, response) end, -- 私聊 [2] = function () diff --git a/src/agent.lua b/src/agent.lua index 40aed0c..2395744 100644 --- a/src/agent.lua +++ b/src/agent.lua @@ -8,14 +8,13 @@ require "skynet.manager" local queue = require "skynet.queue" local netpack = require "skynet.netpack" local socket = require "skynet.socket" -local sharedata = require "skynet.sharedata" local xxtea = require "xxtea" skynet = require "skynet" redisproxy = require "shared.redisproxy" datacenter = require "skynet.datacenter" mcast_util = require "services/mcast_util" -globalCsv = require "csvdata/GlobalDefine" +csvdb = require "shared.csvdata" local CMD = {} local agentInfo = {} -- { client_fd, role, gate_serv, open_timer} @@ -217,7 +216,7 @@ skynet.register_protocol { skynet.register_protocol { name = "role", - id = 13, + id = 101, pack = skynet.pack, unpack = skynet.unpack, dispatch = function(session, address, submethod, ...) @@ -326,20 +325,19 @@ skynet.start(function() end end) - redisd = skynet.localname(".REDIS") + redisd = skynet.localname(".redis") if tonumber(skynet.getenv "logd") == 1 then - logd = skynet.localname(".LOGD") + logd = skynet.localname(".log") end cs = queue() - csvdb = sharedata.query("csvdata") - pvpd = skynet.localname(".PVPCROSS") + pvpd = skynet.localname(".pvpcross") -- 错误码特殊处理 -- todo -- for key, value in pairs(csvdb["sys_codesCsv"]) do -- _G[string.upper(value.varname)] = key -- end - + globalCsv = csvdb["GlobalDefineCsv"] agent_util = require "services/agent_util" end) diff --git a/src/services/chated.lua b/src/services/chated.lua index 6db517f..38bef4e 100644 --- a/src/services/chated.lua +++ b/src/services/chated.lua @@ -35,12 +35,13 @@ if mode == "sub" then skynet.ret(skynet.pack(f(...))) end) - skynet.register(string.format(".CHATED%d", id)) + skynet.register(string.format(".chated%d", id)) end) else skynet.start(function() - local ok, forbidNames = pcall(require, "csvdata.forbid_chat") - if not ok then forbidNames = {} end + local csvdb = require "shared.csvdata" + local forbidNames = csvdb["forbid_chatCsv"] + if not forbidNames then forbidNames = {} end local words = {} for _, data in ipairs(forbidNames) do diff --git a/src/services/csvdatad.lua b/src/services/csvdatad.lua deleted file mode 100644 index d740367..0000000 --- a/src/services/csvdatad.lua +++ /dev/null @@ -1,115 +0,0 @@ -local sharedata = require "skynet.sharedata" -local skynet = require "skynet" -local lfs = require "lfs" -local redisproxy = require "shared.redisproxy" -require "shared.init" -require "utils.init" -require "csvdata.init" -require "skynet.manager" -require "RedisKeys" - --- local csvdb = {} - -local function formatFileName(filename) - filename = string.trim(filename) - local basename = filename:match("([^/]+)%.lua$") - if not basename then return end - local loadname = filename:match("^src/([^.]+)%.lua$") - loadname = loadname:gsub('/', '.') - return basename, loadname -end - -local function travCsv(rootPath, pathes) - pathes = pathes or {} - local modified = false - local ok, files, iter = pcall(lfs.dir, rootPath) - if not ok then return modified end - for entry in files, iter do - -- 过滤 . 开始的字符串包括 . .. .git .开头的文件名 - if string.byte(entry, 1) ~= 46 then - local pathfile = rootPath .. '/' .. entry - local attrs = lfs.attributes(pathfile) - if attrs.mode == 'directory' then - modified = travCsv(pathfile, pathes) or modified - else - local basename, loadname = formatFileName(pathfile) - if basename then - if tonum(pathes[loadname]) < attrs.modification then - modified = true - pathes[loadname] = attrs.modification - end - if basename == "init" or basename == "init_adv" then - require(loadname) - end - end - end - end - end - return modified -end - --- 每分钟检查是否有更改 -local file2timeMap = {} -local function handle_timeout() - if travCsv("src/csvdata", file2timeMap) then - sharedata.update("csvdata", csvdb) - end - skynet.timeout(100*5, handle_timeout) -end - --- 重新加载csvdb - - -local CMD = {} - -function CMD.reload(code) - csvdb = csvdb or {} - - local ok, func = pcall(load, code) - if ok then - ok = pcall(func) - end - if not ok then - skynet.error("reload_csvdata error by code " .. code) - return 'error' - end - - sharedata.update("csvdata", csvdb) - return 'ok' -end - ---更新已经存在的 -function CMD.hotfix(fieldss) - csvdb = csvdb or {} - for _, fields in ipairs(fieldss) do - if #fields >= 3 and (type(fields[#fields]) == 'number' or type(fields[#fields]) == 'string') then - local temp = csvdb - local ok = false - for i = 1, #fields - 1 do - if type(temp) ~= 'table' then break end - if type(fields[i]) ~= 'number' and type(fields[i]) ~= 'string' then break end - if i == #fields - 1 then - if type(temp[fields[i]]) ~= 'number' and type(temp[fields[i]]) ~= 'string' then break end - temp[fields[i]] = fields[#fields] - else - temp = temp[fields[i]] - end - end - end - end - sharedata.update("csvdata", csvdb) - return 'ok' -end - -skynet.start(function () - travCsv("src/csvdata", file2timeMap) - sharedata.new("csvdata", csvdb) - -- handle_timeout() - - skynet.dispatch("lua", function(_, _, command, ...) - local f = CMD[command] - skynet.ret(skynet.pack(f(...))) - end) - - skynet.register(".CSVDATA") -end) diff --git a/src/services/dbseed.lua b/src/services/dbseed.lua index 92df467..a0ab92d 100644 --- a/src/services/dbseed.lua +++ b/src/services/dbseed.lua @@ -1,4 +1,3 @@ -require "csvdata.init" require "shared.init" require "utils.init" require "GlobalVar" @@ -9,7 +8,6 @@ require "skynet.manager" skynet = require "skynet" redisproxy = require("shared.redisproxy") -globalCsv = require "csvdata/GlobalDefine" SendPacket = function ( ... ) end @@ -36,7 +34,7 @@ local steps = { } skynet.start(function () - redisd = skynet.localname(".REDIS") + redisd = skynet.localname(".redis") redisproxy = require("shared.redisproxy") @@ -46,6 +44,8 @@ skynet.start(function () skynet.exit() return end + csvdb = require "shared.csvdata" + globalCsv = csvdb["GlobalDefineCsv"] for _, action in ipairs(steps) do print(action.desc .. "start ...") diff --git a/src/services/globald.lua b/src/services/globald.lua index 04ad135..e0e9ff9 100644 --- a/src/services/globald.lua +++ b/src/services/globald.lua @@ -129,8 +129,8 @@ local function __init__() end end end) - redisd = skynet.localname(".REDIS") - skynet.register(".GLOBALD") + redisd = skynet.localname(".redis") + skynet.register(".globald") end diff --git a/src/services/httpweb.lua b/src/services/httpweb.lua index 2243dce..901d576 100644 --- a/src/services/httpweb.lua +++ b/src/services/httpweb.lua @@ -8,9 +8,8 @@ skynet = require "skynet" redisproxy = require "shared.redisproxy" netpack = require "skynet.netpack" datacenter = require "skynet.datacenter" -sharedata = require "skynet.sharedata" mcast_util = require "services/mcast_util" -globalCsv = require "csvdata/GlobalDefine" +csvdb = require "shared.csvdata" local socket = require "skynet.socket" @@ -33,7 +32,7 @@ local string = string skynet.register_protocol { name = "role", - id = 13, + id = 101, pack = skynet.pack, unpack = skynet.unpack, } @@ -54,8 +53,8 @@ end local CMD = require "actions.HttpAction" local function start() - redisd = skynet.localname(".REDIS") - csvdb = sharedata.query("csvdata") + redisd = skynet.localname(".redis") + globalCsv = csvdb["GlobalDefineCsv"] local listen_socket = socket.listen("0.0.0.0", port) print("Listen web port " .. port) diff --git a/src/services/logd.lua b/src/services/logd.lua index 682cdfa..672f64d 100644 --- a/src/services/logd.lua +++ b/src/services/logd.lua @@ -108,7 +108,7 @@ local function __init__() end) cs = queue() - skynet.register(".LOGD") + skynet.register(".log") end skynet.start(__init__) diff --git a/src/services/named.lua b/src/services/named.lua index e821de7..9fb1591 100644 --- a/src/services/named.lua +++ b/src/services/named.lua @@ -35,12 +35,13 @@ if mode == "sub" then skynet.ret(skynet.pack(f(...))) end) - skynet.register(string.format(".NAMED%d", id)) + skynet.register(string.format(".named%d", id)) end) else skynet.start(function() - local ok, forbidNames = pcall(require, "csvdata.forbid_name") - if not ok then forbidNames = {} end + local csvdb = require "shared.csvdata" + local forbidNames = csvdb["forbid_nameCsv"] + if not forbidNames then forbidNames = {} end local words = {} for _, data in ipairs(forbidNames) do diff --git a/src/services/pvpd.lua b/src/services/pvpd.lua index 4f8f423..fe822da 100644 --- a/src/services/pvpd.lua +++ b/src/services/pvpd.lua @@ -3,13 +3,12 @@ local json = require("shared.json") redisproxy = require("shared.redisproxy") local cluster = require "skynet.cluster" local serverId = tonumber(skynet.getenv("servId")) -local sharedata = require "skynet.sharedata" datacenter = require "skynet.datacenter" +csvdb = require "shared.csvdata" require "shared.init" require "utils.init" require "RedisKeys" require "skynet.manager" -globalCsv = require "csvdata/GlobalDefine" require "GlobalVar" @@ -30,7 +29,7 @@ end skynet.register_protocol { name = "role", - id = 13, + id = 101, pack = skynet.pack, unpack = skynet.unpack, dispatch = function(session, address, submethod, ...) @@ -294,7 +293,9 @@ end ------------------------------------------------------ function CMD.start() - redisd = skynet.localname(".REDIS") + redisd = skynet.localname(".redis") + globalCsv = csvdb["GlobalDefineCsv"] + pvpInfo = require("models.Pvpd").new({key = "cross:pvpInfo"}) pvpInfo:load() end @@ -308,9 +309,8 @@ local function __init__() skynet.ret(skynet.pack(f(...))) end end) - csvdb = sharedata.query("csvdata") - skynet.register(".PVPCROSS") + skynet.register(".pvpcross") end skynet.start(__init__) diff --git a/src/services/redisd.lua b/src/services/redisd.lua index 47fa12f..f7838fc 100644 --- a/src/services/redisd.lua +++ b/src/services/redisd.lua @@ -24,5 +24,5 @@ skynet.start(function() skynet.ret(skynet.pack(db[string.lower(cmd)](db, ...))) end end) - skynet.register ".REDIS" + skynet.register ".redis" end) \ No newline at end of file diff --git a/src/services/uniond.lua b/src/services/uniond.lua deleted file mode 100644 index e5c6ff0..0000000 --- a/src/services/uniond.lua +++ /dev/null @@ -1,143 +0,0 @@ -require "shared.init" -require "utils.init" -require "ProtocolCode" -require "GlobalVar" -require "RedisKeys" -require "skynet.manager" - -local sharedata = require "sharedata" -local redisproxy = require "shared.redisproxy" -local datacenter = require "datacenter" -local queue = require "skynet.queue" - -skynet = require "skynet" -globalCsv = require "csvdata.GlobalDefine" - -local table_pack = table.pack -local table_unpack = table.unpack -local string_format = string.format -local pairs = pairs -local ipairs = ipairs -local tonumber = tonumber - --- 维护在线状态 - -local unionInfo, CMD, cs = {}, {} - -skynet.register_protocol { - name = "role", - id = 13, - pack = skynet.pack, - unpack = skynet.unpack, -} - -local function handle_timeout() - local now = skynet.timex() - unionInfo:onTimer(now) - skynet.timeout(100, handle_timeout) -end - ---[[ -getProperties({"field1", "field2", ...}) -return: {field1 = value1, field2 = value2, ...} -------- -setProperties({field1 = value1, field2 = value2, ...}) -]] -function rpcRole(roleId, funcName, ...) - if not unionInfo.members[roleId] then return end - local serv = unionInfo.members[roleId].serv - if serv then - if funcName == "getProperties" then - return skynet.call(serv, "role", funcName, table_unpack(...)) - else - return skynet.call(serv, "role", funcName, ...) - end - else - local rediskey = string_format("role:%d", roleId) - if funcName == "getProperty" then - return redisproxy:hget(rediskey, ...) - elseif funcName == "setProperty" then - return redisproxy:hset(rediskey, ...) - elseif funcName == "getProperties" then - local sRole = require "models.Role" - local fields = table_pack(...) - local rets = redisproxy:hmget(rediskey, table_unpack(fields, 1, fields.n)) - local result = {} - for i=1, fields.n do - local typ = sRole.schema[fields[i]][1] - local def = sRole.schema[fields[i]][2] - if typ == "number" then - result[fields[i]] = tonumber(rets[i] or def) - else - result[fields[i]] = rets[i] - end - end - return result - elseif funcName == "setProperties" then - local fields = ... - local params = {} - for field, value in pairs(fields) do - params[#params+1] = field - params[#params+1] = value - end - return redisproxy:hmset(rediskey, table_unpack(params)) - end - end -end - --- 加载联盟数据 -function CMD.load(unionId) - unionInfo = require("models.Union").new({key = UNION_KEY:format(unionId)}) - unionInfo:load() - unionInfo:loadMembers() -end - --- 创建一个联盟 -function CMD.new(roleId) - local unionId = redisproxy:hincrby("autoincrement_set", "union", 1) - unionInfo = require("models.Union").new({ - key = UNION_KEY:format(unionId), - master = roleId - }) - unionInfo:create() - unionInfo:addMember(roleId, true) - redisproxy:sadd(UNION_SET, unionId) - return unionId -end - --- 登录/登出 需要向联盟服务报备 -function CMD.sign(cmd, roleId, serv) - if not unionInfo.members[roleId] then return end - if cmd == "login" then - unionInfo.members[roleId].serv = serv - elseif cmd == "logout" then - unionInfo.members[roleId].serv = nil - end -end - -local function __init__() - skynet.dispatch("lua", function(_, _, command, ...) - cs(function (...) - if CMD[command] then - skynet.ret(skynet.pack(CMD[command](...))) - return - else - if unionInfo and unionInfo[submethod] then - if command == 'dismiss' then - unionInfo:dismiss(...) - return - end - local result = unionInfo[submethod](unionInfo, ...) - skynet.ret(skynet.pack(result)) - return - end - end - skynet.error("uniond commond error cmd=", command) - end) - end) - skynet.register("UNIOND") - csvdb = sharedata.query("csvdata") - cs = queue() -end - -skynet.start(__init__) \ No newline at end of file diff --git a/src/services/watchdog.lua b/src/services/watchdog.lua index 4ffae30..6a0a83e 100644 --- a/src/services/watchdog.lua +++ b/src/services/watchdog.lua @@ -9,6 +9,7 @@ local agent_ctrl = require "services.agent_ctrl" local xxtea = require "xxtea" local mc = require "skynet.multicast" local cluster = require "skynet.cluster" +local csvdata = require "shared.csvdata" require "ProtocolCode" require "GlobalVar" @@ -107,12 +108,12 @@ skynet.start(function() skynet.ret(skynet.pack(f(subcmd, ...))) end end) - skynet.register ".WATCHDOG" + skynet.register ".watchdog" -- 数据库服务 redisd = skynet.newservice("services/redisd") - -- load all csv data - skynet.newservice("services/csvdatad") + -- 提前加载好 + csvdata.init() print("launch csvdatad ...") -- 日志服务 diff --git a/src/shared/csvdata.lua b/src/shared/csvdata.lua new file mode 100644 index 0000000..7c05700 --- /dev/null +++ b/src/shared/csvdata.lua @@ -0,0 +1,183 @@ +-- 对sharetable 的一层封装 实现热更新 + +local skynet = require "skynet" +local service = require "skynet.service" +local sharetable = require "skynet.sharetable" + +local function sharetable_service() + local skynet = require "skynet" + local sharetable = require "skynet.sharetable" + + local files = {} -- filename + local csvdata = {} + + local initfile = { + ["src/csvdata/init.lua"] = {}, + ["src/csvdata/init_adv.lua"] = {}, + } + + function csvdata.query(source, filename) + files[filename] = files[filename] or {} + files[filename][source] = 1 + end + + function csvdata.close(source) + for filename, info in pairs(files) do + info[source] = nil + end + end + + function csvdata.realName(file) + if string.match(file, "Csv$") then + if initfile["src/csvdata/init.lua"] and initfile["src/csvdata/init.lua"][file] then + file = initfile["src/csvdata/init.lua"][file] + elseif initfile["src/csvdata/init_adv.lua"] and initfile["src/csvdata/init_adv.lua"][file] then + file = initfile["src/csvdata/init_adv.lua"][file] + end + file = "src/" .. file .. ".lua" + end + return file + end + + function csvdata.hotfix(_, ...) + local now = skynet.timex() + + local filenames = {...} + + local needHotfix = {} + for _, filename in ipairs(filenames) do + -- 更新下 + skynet.error(string.format("hotfix_csvdata time: %s, file: %s", now, filename)) + + if initfile[filename] then + sharetable.loadfile(filename) + sharetable.update(filename) + else + sharetable.loadfile(csvdata.realName(filename)) + end + + if files[filename] then + for source, _ in pairs(files[filename]) do + needHotfix[source] = needHotfix[source] or {} + table.insert(needHotfix[source], filename) + end + end + end + + for source, files in pairs(needHotfix) do + skynet.send(source, "csvdata", "hotfix", table.unpack(files)) + end + end + + skynet.dispatch("lua", function(_,source,cmd,...) + skynet.ignoreret() + csvdata[cmd](source,...) + end) + + skynet.register_protocol { + name = "csvdata", + id = 102, + pack = skynet.pack, + unpack = skynet.unpack, + } + + -- 初始化csvdata + skynet.start(function() + for file, _ in pairs(initfile) do + sharetable.loadfile(file) + local init = sharetable.query(file) + if not init then + error("csvdata load init file error " .. file) + return + end + initfile[file] = init + for _, one in pairs(init) do + sharetable.loadfile("src/" .. one .. ".lua") + end + end + end) +end + + +local cache = {} +local csvdata + +local function load_csvdata(t, key) + if key == "address" then + t.address = service.new("csvdata", sharetable_service) + return t.address + else + if cache[key] then return cache[key] end + + local realName = csvdata.realName(key) + + local tab = sharetable.query(realName) + if not tab then + error("dont have csvdata : " .. realName) + return + end + cache[key] = tab + -- 增加引用 + skynet.send(csvdata.address, "lua", "query", key) + return tab + end +end + +local function close_hotfix(t) + local addr = rawget(t, "address") + if addr then + skynet.send(addr, "lua", "close") + end +end + +csvdata = setmetatable ( {} , { + __index = load_csvdata, + __gc = close_hotfix, +}) + +function csvdata.init() + return csvdata.address +end + +function csvdata.hotfix(...) + skynet.send(csvdata.address, "lua", "hotfix", ...) +end + +function csvdata.realName(file) + if string.match(file, "Csv$") then + if csvdata["src/csvdata/init.lua"] and csvdata["src/csvdata/init.lua"][file] then + file = csvdata["src/csvdata/init.lua"][file] + elseif csvdata["src/csvdata/init_adv.lua"] and csvdata["src/csvdata/init_adv.lua"][file] then + file = csvdata["src/csvdata/init_adv.lua"][file] + end + file = "src/" .. file .. ".lua" + end + return file +end + +local function update(file) + -- 更新一下 + if cache[file] then + sharetable.update(csvdata.realName(file)) + end +end + +skynet.register_protocol { + name = "csvdata", + id = 102, + pack = skynet.pack, + unpack = skynet.unpack, + dispatch = function(_, _, cmd, ...) + skynet.ignoreret() + if cmd == "hotfix" then + -- skynet.error("csvdara hotfix update", ...) + local files = {...} + for _, file in ipairs(files) do + update(file) + end + return + end + end, +} + +return csvdata -- libgit2 0.21.2