--[[ Descripttion: version: Author: Neo,Huang Date: 2022-07-28 09:16:34 LastEditors: Neo,Huang LastEditTime: 2022-07-28 09:19:49 --]] local skynet = require "skynet" local protobufUtil = require "utils.protobufUtil" local protobuf = require "protobuf" local proto_type = ... -- 注册协议文件 local function register_protos() local pb_path, protos_tbl if proto_type == "game_proto" then pb_path, protos_tbl = protobufUtil.get_game_protos() else pb_path, protos_tbl = protobufUtil.get_http_protos() end for _, file in ipairs(protos_tbl) do protobuf.register_file(pb_path .. file) end end local CMD = {} -- 编码协议 function CMD.encode(name, msg) if not name or not msg then return end return protobuf.encode(name, msg) end -- 解码协议 function CMD.decode(name, msg) if not name or not msg then return end return protobuf.decode(name, msg) end -- 更新协议(注:只能热更协议增加字段或新增协议,其他均会异常!!!!!!!) function CMD.update_proto() protobuf.clear_register_file() register_protos() end -- 服务退出 function CMD.exit() skynet.retpack(nil) skynet.exit() end skynet.dispatch( "lua", function(session, _, cmd, ...) local func = assert(CMD[cmd], cmd .. " not found") local ret = func(...) if session > 0 and cmd ~= "exit" then skynet.retpack(ret) end end ) skynet.start( function() register_protos() end )