1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| local log = require "skynet-fly.log" local ws_pbnet_util = require "skynet-fly.utils.net.ws_pbnet_util" local pb_netpack = require "skynet-fly.netpack.pb_netpack" local timer = require "skynet-fly.timer" local errors_msg = require "gamecommon.msg.errors_msg" local skynet = require "skynet" local g_modules_list = require "hall.hall"
local assert = assert local ipairs = ipairs local pairs = pairs
local g_interface_mgr = nil
local M = {}
M.unpack = ws_pbnet_util.unpack M.send = ws_pbnet_util.send M.broadcast = ws_pbnet_util.broadcast M.disconn_time_out = timer.minute
function M.init(interface_mgr) pb_netpack.load('../../commonlualib/gamecommon/proto') pb_netpack.load('./proto') g_interface_mgr = interface_mgr errors_msg = errors_msg:new(interface_mgr)
for _, m in ipairs(g_modules_list) do local handle = m.handle for packname,func in pairs(handle) do g_interface_mgr:handle(packname, func) end end
for _, m in ipairs(g_modules_list) do m.init(interface_mgr) end end
local function on_login(player_id) for _, m in ipairs(g_modules_list) do if m.on_login then m.on_login(player_id) end end end
function M.connect(player_id) skynet.fork(on_login, player_id) return { isreconnect = 0, } end
function M.disconnect(player_id) for _, m in ipairs(g_modules_list) do if m.on_disconnect then m.on_disconnect(player_id) end end end
local function on_reconnect(player_id) for _, m in ipairs(g_modules_list) do if m.on_reconnect then m.on_reconnect(player_id) end end end
function M.reconnect(player_id) skynet.fork(on_reconnect, player_id) return { isreconnect = 1, } end
function M.goout(player_id) for _, m in ipairs(g_modules_list) do if m.on_loginout then m.on_loginout(player_id) end end end
M.register_cmd = {}
for _, m in ipairs(g_modules_list) do local register_cmd = m.register_cmd for cmdname,func in pairs(register_cmd) do assert(not M.register_cmd[cmdname], "exists cmdname: " .. cmdname) M.register_cmd[cmdname] = func end end
function M.handle_end(player_id, packname, pack_body, ret, errcode, errmsg) if not ret then log.info("handle_end err >>> ", packname, ret, errcode, errmsg) errors_msg:errors(player_id, errcode, errmsg, packname) end end
function M.leave_table(player_id, table_name, table_id) skynet.fork(g_interface_mgr.goout, g_interface_mgr, player_id) end
return M
|