gift.lua 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. local skynet = require "skynet"
  2. require "skynet.manager"
  3. local logger = require "logger"
  4. local asset = require "model.asset"
  5. local stringify = require "stringify"
  6. local skynet_retpack = skynet.retpack
  7. local list = {
  8. --[[
  9. [shop_type] =
  10. {
  11. {
  12. id = id
  13. num = num
  14. }
  15. }
  16. ]]
  17. }
  18. local CMD = {}
  19. local function optimize()
  20. local temp = {}
  21. for _, conf in pairs(asset.GiftConfig_proto) do
  22. temp[conf.type] = temp[conf.type] or {}
  23. table.insert(temp[conf.type], conf)
  24. end
  25. list = temp
  26. -- logger.trace("gift:"..stringify(list))
  27. end
  28. function CMD.start()
  29. logger.info("start")
  30. optimize()
  31. end
  32. function CMD.get_all_gift(model_id)
  33. return list[model_id] or {}
  34. end
  35. skynet.init(function()
  36. skynet.register(".gift")
  37. end)
  38. skynet.start(function()
  39. logger.label("<Gift>,")
  40. skynet.dispatch("lua", function(session,_, cmd, ...)
  41. local f = assert(CMD[cmd])
  42. if session == 0 then
  43. f(...)
  44. else
  45. skynet_retpack(f(...))
  46. end
  47. end)
  48. end)