local skynet = require "skynet" require "skynet.manager" local cjson = require "cjson" local skynet_send = skynet.send local cjson_encode = cjson.encode cjson.encode_sparse_array(true, 1) local log = skynet.localname('.log') local function record(character, opcode, context) log = log or skynet.localname('.log') assert(character) assert(opcode) local bytes = cjson_encode({ opcode=opcode, uid=character.uid, nickname=character.nickname, context=context, date=os.time() }) skynet_send(log, "lua", "record", character.uid, bytes) end -- http传送的日志(内部开发日志记录) local function http_record(character, content) content.channel = character.channel skynet_send(log, "lua", "http_record", character.uid, content) end local MODULE = {} -- function MODULE.create(character, ipaddr,device) -- PK3-1366 数据统计 -- local content = { -- id = character.uid, -- account = character.account, -- name = character.nickname, -- serverid = character.sid, -- platform = character.platform, -- country = "CN", -- 默认 -- ip = ipaddr, -- device = device, -- create_time = os.date("%Y-%m-%d %H:%M:%S",character.createtime), -- opcode = "register", -- } -- http_record(character, content) -- end -- Reference: model.player -- function MODULE.login(character, ipaddr) -- assert(ipaddr) -- record(character, "login", { -- coins=character.coins, -- diamonds=character.diamonds, -- bind_diamonds=character.bind_diamonds, -- budo_point = character.budo_point, -- smeltpoint=character.smeltpoint, -- friendship=character.friendship, -- level=character.level, -- ipaddr=ipaddr, -- manual_exp = character.manual_exp, --PK3-1077 -- }) -- local content = { --PK3-1366 数据统计 -- id = character.uid, -- login_level = character.level, -- login_ip = ipaddr, -- login_time = os.date("%Y-%m-%d %H:%M:%S"), -- opcode = "login", -- } -- http_record(character, content) -- end -- Reference: model.player -- function MODULE.logout(character) -- record(character, "logout", { -- coins=character.coins, -- diamonds=character.diamonds, -- bind_diamonds=character.bind_diamonds, -- budo_point = budo_point, -- smeltpoint=character.smeltpoint, -- friendship=character.friendship, -- level=character.level, -- }) -- local content = { -- PK3-1366 数据统计 -- id = character.uid, -- logout_level = character.level, -- logout_mark = "NULL-logout", -- logout_time = os.date("%Y-%m-%d %H:%M:%S"), -- online_time = os.time() - character.lastlogin, -- opcode = "logout", -- } -- http_record(character, content) -- end function MODULE.recharge(character, amount, info) assert(amount) record(character, "recharge", info) end -- Reference: model.reward function MODULE.reward(character, module, brief, specific, detail) assert(module) assert(brief) assert(detail) assert(type(module) == "string") assert(type(brief) == "string") record(character, "reward", { module=module, brief=brief, specific=specific, detail=detail }) -- local content = { -- id = character.uid, -- output_time = os.date("%Y-%m-%d %H:%M:%S"), -- opcode = "output", -- output_type = 1, -- output_mark = module, -- 标识 -- output_additional = cjson_encode(specific or {}), -- 额外参数 -- output_item = cjson_encode(detail), -- } -- http_record(character, content) end -- Reference: model.payment function MODULE.receipt(character, module, brief, specific, receipt) assert(module) assert(brief) assert(receipt) assert(type(module) == "string") assert(type(brief) == "string") record(character, "receipt", { module=module, brief=brief, specific=specific, receipt=receipt }) -- logger.trace(" #### receipt %s", stringify(receipt)) -- local content = { -- id = character.uid, -- output_time = os.date("%Y-%m-%d %H:%M:%S"), -- opcode = "output", -- output_type = 2, -- output_mark = module, -- 标识 -- output_additional = cjson_encode(specific or {}), -- 额外参数 -- output_item = cjson_encode(replace_payment_arr(receipt)), -- } -- http_record(character, content) end -- DEMO: -- local module = "elf" -- local event = "release" -- local specific = { -- [127001]=2, -- [2222]=3 -- } -- log.fire(character, module, event, specific) -- function MODULE.fire(character, module, event, specific) -- assert(module) -- assert(event) -- assert(type(module) == "string") -- assert(type(event) == "string") -- record(character, "event", { -- module=module, -- type=event, -- specific=specific -- }) -- -- logger.trace(" #### module, event :%s, %s",module, event) -- local flag = nil -- local output_type = nil -- if specific.note then -- if specific.note == "elf_deduct" then -- 精灵扣除-来源 elf模块 -- output_type = 2 -- 支出 -- flag = {} -- for sid, num in pairs(specific.pokemon) do -- table.insert(flag, {TYPE_ELF, sid, num}) -- end -- elseif specific.note == "equip_deduct" then -- 装备扣除-来源 bag背包模块 -- output_type = 2 -- 支出 -- flag = {} -- for _, sid in pairs(specific.equip) do -- table.insert(flag, {GOODS_EQUIP, sid, 1}) -- end -- elseif module == "elf_rune" and event == "精灵放生销毁" then -- 精灵放生, 符文销毁 elf_rune -- if specific and specific.runelist and next(specific.runelist) then -- output_type = 2 -- 支出 -- flag = {} -- for _, info in pairs(specific.runelist) do -- table.insert(flag, {TYPE_RUNE, info.sid, 1}) -- end -- end -- elseif module == "elf" and specific.note == "elflv_upgrade" then -- elf: 精灵经验扣除 -- output_type = 2 -- 支出 -- flag = {} -- table.insert(flag, {GOODS_MONEY, MONEY_EXP1, specific.exp1 or 0}) -- elseif specific.note == "shop_system_buy" then -- 商店 -- output_type = 2 -- 支出 -- flag = {} -- for sid, num in pairs(specific.equip) do -- table.insert(flag, {GOODS_EQUIP, sid, num}) -- end -- elseif specific.note == "web_delitem" then -- 道具扣除接口 -- output_type = 2 -- 支出 -- flag = specific.other -- end -- end -- if flag then -- -- logger.trace(" ################## flag %s", stringify(flag)) -- local content = { -- id = character.uid, -- output_time = os.date("%Y-%m-%d %H:%M:%S"), -- opcode = "output", -- output_type = output_type, -- output_mark = module, -- 标识 -- output_additional = cjson_encode(specific or {}), -- 额外参数 -- output_item = cjson_encode(flag), -- } -- http_record(character, content) -- end -- end return MODULE