log.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. local skynet = require "skynet"
  2. require "skynet.manager"
  3. local cjson = require "cjson"
  4. local skynet_send = skynet.send
  5. local cjson_encode = cjson.encode
  6. cjson.encode_sparse_array(true, 1)
  7. local log = skynet.localname('.log')
  8. local function record(character, opcode, context)
  9. log = log or skynet.localname('.log')
  10. assert(character)
  11. assert(opcode)
  12. local bytes = cjson_encode({
  13. opcode=opcode,
  14. uid=character.uid,
  15. nickname=character.nickname,
  16. context=context,
  17. date=os.time()
  18. })
  19. skynet_send(log, "lua", "record", character.uid, bytes)
  20. end
  21. -- http传送的日志(内部开发日志记录)
  22. local function http_record(character, content)
  23. content.channel = character.channel
  24. skynet_send(log, "lua", "http_record", character.uid, content)
  25. end
  26. local MODULE = {}
  27. -- function MODULE.create(character, ipaddr,device) -- PK3-1366 数据统计
  28. -- local content = {
  29. -- id = character.uid,
  30. -- account = character.account,
  31. -- name = character.nickname,
  32. -- serverid = character.sid,
  33. -- platform = character.platform,
  34. -- country = "CN", -- 默认
  35. -- ip = ipaddr,
  36. -- device = device,
  37. -- create_time = os.date("%Y-%m-%d %H:%M:%S",character.createtime),
  38. -- opcode = "register",
  39. -- }
  40. -- http_record(character, content)
  41. -- end
  42. -- Reference: model.player
  43. -- function MODULE.login(character, ipaddr)
  44. -- assert(ipaddr)
  45. -- record(character, "login", {
  46. -- coins=character.coins,
  47. -- diamonds=character.diamonds,
  48. -- bind_diamonds=character.bind_diamonds,
  49. -- budo_point = character.budo_point,
  50. -- smeltpoint=character.smeltpoint,
  51. -- friendship=character.friendship,
  52. -- level=character.level,
  53. -- ipaddr=ipaddr,
  54. -- manual_exp = character.manual_exp, --PK3-1077
  55. -- })
  56. -- local content = { --PK3-1366 数据统计
  57. -- id = character.uid,
  58. -- login_level = character.level,
  59. -- login_ip = ipaddr,
  60. -- login_time = os.date("%Y-%m-%d %H:%M:%S"),
  61. -- opcode = "login",
  62. -- }
  63. -- http_record(character, content)
  64. -- end
  65. -- Reference: model.player
  66. -- function MODULE.logout(character)
  67. -- record(character, "logout", {
  68. -- coins=character.coins,
  69. -- diamonds=character.diamonds,
  70. -- bind_diamonds=character.bind_diamonds,
  71. -- budo_point = budo_point,
  72. -- smeltpoint=character.smeltpoint,
  73. -- friendship=character.friendship,
  74. -- level=character.level,
  75. -- })
  76. -- local content = { -- PK3-1366 数据统计
  77. -- id = character.uid,
  78. -- logout_level = character.level,
  79. -- logout_mark = "NULL-logout",
  80. -- logout_time = os.date("%Y-%m-%d %H:%M:%S"),
  81. -- online_time = os.time() - character.lastlogin,
  82. -- opcode = "logout",
  83. -- }
  84. -- http_record(character, content)
  85. -- end
  86. function MODULE.recharge(character, amount, info)
  87. assert(amount)
  88. record(character, "recharge", info)
  89. end
  90. -- Reference: model.reward
  91. function MODULE.reward(character, module, brief, specific, detail)
  92. assert(module)
  93. assert(brief)
  94. assert(detail)
  95. assert(type(module) == "string")
  96. assert(type(brief) == "string")
  97. record(character, "reward", {
  98. module=module,
  99. brief=brief,
  100. specific=specific,
  101. detail=detail
  102. })
  103. -- local content = {
  104. -- id = character.uid,
  105. -- output_time = os.date("%Y-%m-%d %H:%M:%S"),
  106. -- opcode = "output",
  107. -- output_type = 1,
  108. -- output_mark = module, -- 标识
  109. -- output_additional = cjson_encode(specific or {}), -- 额外参数
  110. -- output_item = cjson_encode(detail),
  111. -- }
  112. -- http_record(character, content)
  113. end
  114. -- Reference: model.payment
  115. function MODULE.receipt(character, module, brief, specific, receipt)
  116. assert(module)
  117. assert(brief)
  118. assert(receipt)
  119. assert(type(module) == "string")
  120. assert(type(brief) == "string")
  121. record(character, "receipt", {
  122. module=module,
  123. brief=brief,
  124. specific=specific,
  125. receipt=receipt
  126. })
  127. -- logger.trace(" #### receipt %s", stringify(receipt))
  128. -- local content = {
  129. -- id = character.uid,
  130. -- output_time = os.date("%Y-%m-%d %H:%M:%S"),
  131. -- opcode = "output",
  132. -- output_type = 2,
  133. -- output_mark = module, -- 标识
  134. -- output_additional = cjson_encode(specific or {}), -- 额外参数
  135. -- output_item = cjson_encode(replace_payment_arr(receipt)),
  136. -- }
  137. -- http_record(character, content)
  138. end
  139. -- DEMO:
  140. -- local module = "elf"
  141. -- local event = "release"
  142. -- local specific = {
  143. -- [127001]=2,
  144. -- [2222]=3
  145. -- }
  146. -- log.fire(character, module, event, specific)
  147. -- function MODULE.fire(character, module, event, specific)
  148. -- assert(module)
  149. -- assert(event)
  150. -- assert(type(module) == "string")
  151. -- assert(type(event) == "string")
  152. -- record(character, "event", {
  153. -- module=module,
  154. -- type=event,
  155. -- specific=specific
  156. -- })
  157. -- -- logger.trace(" #### module, event :%s, %s",module, event)
  158. -- local flag = nil
  159. -- local output_type = nil
  160. -- if specific.note then
  161. -- if specific.note == "elf_deduct" then -- 精灵扣除-来源 elf模块
  162. -- output_type = 2 -- 支出
  163. -- flag = {}
  164. -- for sid, num in pairs(specific.pokemon) do
  165. -- table.insert(flag, {TYPE_ELF, sid, num})
  166. -- end
  167. -- elseif specific.note == "equip_deduct" then -- 装备扣除-来源 bag背包模块
  168. -- output_type = 2 -- 支出
  169. -- flag = {}
  170. -- for _, sid in pairs(specific.equip) do
  171. -- table.insert(flag, {GOODS_EQUIP, sid, 1})
  172. -- end
  173. -- elseif module == "elf_rune" and event == "精灵放生销毁" then -- 精灵放生, 符文销毁 elf_rune
  174. -- if specific and specific.runelist and next(specific.runelist) then
  175. -- output_type = 2 -- 支出
  176. -- flag = {}
  177. -- for _, info in pairs(specific.runelist) do
  178. -- table.insert(flag, {TYPE_RUNE, info.sid, 1})
  179. -- end
  180. -- end
  181. -- elseif module == "elf" and specific.note == "elflv_upgrade" then -- elf: 精灵经验扣除
  182. -- output_type = 2 -- 支出
  183. -- flag = {}
  184. -- table.insert(flag, {GOODS_MONEY, MONEY_EXP1, specific.exp1 or 0})
  185. -- elseif specific.note == "shop_system_buy" then -- 商店
  186. -- output_type = 2 -- 支出
  187. -- flag = {}
  188. -- for sid, num in pairs(specific.equip) do
  189. -- table.insert(flag, {GOODS_EQUIP, sid, num})
  190. -- end
  191. -- elseif specific.note == "web_delitem" then -- 道具扣除接口
  192. -- output_type = 2 -- 支出
  193. -- flag = specific.other
  194. -- end
  195. -- end
  196. -- if flag then
  197. -- -- logger.trace(" ################## flag %s", stringify(flag))
  198. -- local content = {
  199. -- id = character.uid,
  200. -- output_time = os.date("%Y-%m-%d %H:%M:%S"),
  201. -- opcode = "output",
  202. -- output_type = output_type,
  203. -- output_mark = module, -- 标识
  204. -- output_additional = cjson_encode(specific or {}), -- 额外参数
  205. -- output_item = cjson_encode(flag),
  206. -- }
  207. -- http_record(character, content)
  208. -- end
  209. -- end
  210. return MODULE