assetcenter.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. local skynet = require "skynet"
  2. require "skynet.manager"
  3. local sharedata = require "skynet.sharedata"
  4. local logger = require "logger"
  5. local cache = require "skynet.codecache"
  6. cache.mode "OFF" -- turn off codecache, because CMD.new may load data file
  7. local index = ...
  8. local SET_FILES
  9. local path = skynet.getenv "asset"
  10. local skynet_retpack = skynet.retpack
  11. local FILES = {
  12. -- TODO: 在下面定义需要引入的配置文件
  13. DataConfig_proto = "DataConfig_proto", -- 离散表
  14. GoodsConfig_proto = "GoodsConfig_proto", -- 货币表
  15. StageConfig_proto = "StageConfig_proto", -- 关卡表
  16. StageInfoConfig_proto = "StageInfoConfig_proto", -- 关卡信息表
  17. RoleConfig_proto = "RoleConfig_proto", -- 角色表
  18. RoleLevelConfig_proto = "RoleLevelConfig_proto", -- 角色升级表
  19. RanksLevelConfig_proto = "RanksLevelConfig_proto", -- 队伍升级表
  20. ArmorConfig_proto = "ArmorConfig_proto", -- 装备表
  21. EquipmentQualityConfig_proto = "EquipmentQualityConfig_proto", -- 装备升阶表
  22. EquipmentLevelConfig_proto = "EquipmentLevelConfig_proto", -- 装备升级表
  23. AwardConfig_proto = "AwardConfig_proto", -- 奖励库id
  24. TalentConfig_proto = "TalentConfig_proto", -- 天赋配置表
  25. SigninConfig_proto = "SigninConfig_proto", -- 签到配置
  26. GiftConfig_proto = "GiftConfig_proto", -- 计费点礼包配置
  27. RechargeConfig_proto = "RechargeConfig_proto", -- 充值计费点
  28. MonsterConfig_proto = "MonsterConfig_proto", -- 怪物表
  29. NewawardConfig_proto = "NewawardConfig_proto", -- 奖励库活动
  30. EntryConfig_proto = "EntryConfig_proto", -- 词条表
  31. BoxConfig_proto = "BoxConfig_proto", -- 宝箱配置
  32. }
  33. -- TODO: 集群使用的配置表
  34. local SPAN_FILES = {
  35. }
  36. local function encode(filename)
  37. return string.format("@%s%s.lua", path, filename)
  38. end
  39. local function reload(k, filename)
  40. local ok = pcall(sharedata.update, k, encode(filename))
  41. if ok then
  42. logger.warn("hotfix: '%s.lua'", k)
  43. else
  44. return filename
  45. end
  46. end
  47. local function hotfix(...)
  48. local args = { ... }
  49. if #args == 0 then
  50. for k, v in pairs(SET_FILES) do
  51. local error = reload(k, v)
  52. if error then
  53. return error
  54. end
  55. end
  56. else
  57. for _, k in ipairs(args) do
  58. local v = SET_FILES[k]
  59. if v then
  60. local error = reload(k, v)
  61. if error then
  62. return error
  63. end
  64. end
  65. end
  66. end
  67. end
  68. local CMD = {}
  69. function CMD.start()
  70. logger.info("start")
  71. if index == "master" then
  72. SET_FILES = SPAN_FILES
  73. else
  74. SET_FILES = FILES
  75. end
  76. for k, filename in pairs(SET_FILES) do
  77. sharedata.new(k, encode(filename))
  78. end
  79. end
  80. function CMD.hotfix(...)
  81. local error = hotfix(...)
  82. collectgarbage "collect"
  83. return error
  84. end
  85. skynet.memlimit(128 * 1024 * 1024)
  86. skynet.init(function() skynet.register(".assetcenter") end)
  87. skynet.start(function()
  88. logger.label("<Assetcenter>")
  89. skynet.dispatch("lua", function(session, _, cmd, ...)
  90. local f = assert(CMD[cmd])
  91. if session == 0 then
  92. f(...)
  93. else
  94. skynet_retpack(f(...))
  95. end
  96. end)
  97. end)