Giter VIP home page Giter VIP logo

huahua132 / skynet_fly Goto Github PK

View Code? Open in Web Editor NEW
399.0 31.0 64.0 3.64 MB

基于云风的skynet,搭建开箱即用的微服务框架,提供优雅的服务热更新

Home Page: https://huahua132.github.io/2023/02/25/skynet_fly_word/word_1/A_home/

License: MIT License

Makefile 0.79% C 47.86% HTML 0.94% Lua 48.60% CSS 0.13% Shell 0.15% Perl 0.03% CMake 1.51%
httpserver microservice rpc-framework gameservers gameservices hot-reload skynet orm-skynet

skynet_fly's Introduction

skynet_fly(1)


致力于服务端对skynet的最佳实践 使用文档

觉得不错,不妨点个**星星**吧!你的星星是作者持续创作维护的最大动力!

技术交流群

QQ群号:102993581

skynet_fly简介

skynet_fly是基于skynet扩展的可以快速开发web,游戏,和需要rpc调用的框架。
使用skynet_fly的好处:
* 支持不停服更新。
* 一键生成skynet的配置文件和skynet_fly的配置文件以及配套shell脚本。
* 对匹配房间类游戏做了gate,ws_gate的基础设施封装以及pb,json协议的支持,开发游戏只需要实现相关业务逻辑。
* 对redis,mysql,timer,log 使用封装。
* 基于skynet cluster封装出简单易用的远程rpc调用。
* 支持服务发现。
* 支持http服务长连接。
* 支持http服务路由,中间件模式。
* 支持jwt鉴权。
* 内置日志分割。
* 支持快进时间。
* 支持orm(数据关系映射)目前适配了(mysql,mongo),数据库可无缝切换。

第三方依赖来源

快速开始 http服务 (运行examples/webapp)

  1. 编译skynet 参考了涵曦的 skynet_demo
    • git clone https://github.com/huahua132/skynet_fly
    • 安装MakeRequests.sh中依赖的库。
    • 根据系统手动安装。
    • make linux
  2. 构建skynet_config, webapp运维脚本
    • cd examples/webapp/
    • sh ../../binshell/make_server.sh ../../
    • 如果一些顺利的话将会生成script文件夹,文件夹下有:
      • run.sh 运行并配置日志分割
      • stop.sh 停止
      • restart.sh 重启
      • reload.sh 热更某个可热更模块。
      • kill_mod.sh 干掉某个可热更模块(不是强行kill,是通知服务可以退出了)
      • check_reload.sh 检查可热更模块是否有文件或者配置修改,有就更新。
      • fasttime.sh 快进时间。 sh script/fasttime.sh load_mods.lua "2023:11:19 11:10:59" 1
      • try_again_reload.sh 当热更失败,可以解决相关错误之后进行重试热更。
    • 还会生成webapp_config.lua,也就是skynet启动用的配置文件。
  3. 运行
    • sh script/run.sh load_mods.lua 0
  4. 访问
    • 浏览器打开 x.x.x.x:80
    • 如果一切顺利的话,网页将会显示内容。
  5. 热更
    • 修改 webapp/lualib/webapp_dispatch.lua 中的任意代码。
    • 之后执行 sh script/check_reload.sh load_mods.lua
    • 再次访问网站就更新了。
    • 也可以观察webapp/logs/server.log

http服务已经接入了涵曦的wlua,扩展了路由和中间件模式,完整示例请看运行examples/webapp 源码。 默认webapp运行的是webapp_dispatch.lua,想要切换其他示例,只需要更改load_mods.lua中的dispatch即可。

return {
	web_agent_m = {
		launch_seq = 1,
		launch_num = 6,
		default_arg = {
			protocol = 'http',
			dispatch = 'apps.webapp_dispatch',
		}
	},

	web_master_m = {
		launch_seq = 2,
		launch_num = 1,
		default_arg = {
			protocol = 'http',
			port = 80,
		}
	}
}
  • 处理没有命中路由
--初始化一个纯净版
local app = engine_web:new()
--请求处理
M.dispatch = engine_web.dispatch(app)

--初始化
function M.init()
	--注册全局中间件
	app:use(logger_mid())

	--注册没有找到的路径处理函数
	app:set_no_route(function(c)
		local method = c.req.method
		log.error("no route handle begin 1:",method)

		c:next()
	
		log.error("not route handle end 1:",c.res.status,c.res.resp_header,c.res.body)
	end,
	function(c)
		local method = c.req.method
		log.error("no route handle begin 2:",method)

		c:next()
	
		log.error("not route handle end 2:",c.res.status,c.res.resp_header,c.res.body)
	end)
	
	app:run()
end

--服务退出
function M.exit()

end
  • params路径方式
--初始化一个纯净版
local app = engine_web:new()
--请求处理
M.dispatch = engine_web.dispatch(app)

--初始化
function M.init()
	--注册全局中间件
	app:use(logger_mid())
	
	--/login 路径不会命中
	--/login/123 会命中
	app:get("/login/:player_id/*",function(c)
		local params = c.params
		local player_id = params.player_id

		log.error("params:",params)
		log.error("path:",c.req.path)
		log.error("body:",c.req.body,c.req.body_raw)

		c.res:set_rsp("hello " .. player_id,HTTP_STATUS.OK)
	end)

	app:run()
end

--服务退出
function M.exit()

end
  • query 和 post from
--初始化一个纯净版
local app = engine_web:new()
--请求处理
M.dispatch = engine_web.dispatch(app)

--初始化
function M.init()
	--注册全局中间件
	app:use(logger_mid())

	app:post("/login",function(c)
		local player_id = c.req.query.player_id
		assert(player_id)

		log.error("query:",c.req.query)
		log.error("post from:",c.req.body)

		c.res:set_rsp("hello " .. player_id,HTTP_STATUS.OK)
	end)

	app:run()
end

--服务退出
function M.exit()

end
  • json请求
--初始化一个纯净版
local app = engine_web:new()
--请求处理
M.dispatch = engine_web.dispatch(app)

--初始化
function M.init()
	--注册全局中间件
	app:use(logger_mid())

	app:post("/login",function(c)
		local player_id = c.req.query.player_id
		assert(player_id)

		log.error("query:",c.req.query)
		log.error("json body:",c.req.body)

		local rsp = {
			msg = "hello " .. player_id
		}
		c.res:set_json_rsp(rsp)
	end)

	app:run()
end

--服务退出
function M.exit()

end
  • 自定义中间件
--初始化一个纯净版
local app = engine_web:new()
--请求处理
M.dispatch = engine_web.dispatch(app)

--初始化
function M.init()
	--注册全局中间件
	app:use(logger_mid())

	--自定义中间件
	app:use(function(c)
		log.info("process begin :",c.req.path,c.req.method)

		--执行下一个中间件
		c:next()

		log.info("process end :",c.req.path,c.req.method)
	end)

	app:get("/",function(c)
		log.info("end point process ",c.req.path,c.req.method)
		c.res:set_rsp("hello skynet_fly",HTTP_STATUS.OK)
	end)

	app:run()
end

--服务退出
function M.exit()

end
  • 多路由组
--初始化一个纯净版
local app = engine_web:new()
--请求处理
M.dispatch = engine_web.dispatch(app)

--初始化
function M.init()
	--注册全局中间件
	app:use(logger_mid())
	do
		local v1 = app:group("v1")
		v1:get('/login',function(c)
			log.info("v1 login ")
		end)

		v1:get('/logout',function(c)
			log.info("v1 logout ")
		end)
	end

	do
		local v2 = app:group("v2")
		v2:get('/login',function(c)
			log.info("v2 login ")
		end)

		v2:get('/logout',function(c)
			log.info("v2 logout ")
		end)
	end

	app:run()
end

--服务退出
function M.exit()

end
  • 多路由组中间件
--初始化一个纯净版
local app = engine_web:new()
--请求处理
M.dispatch = engine_web.dispatch(app)

--初始化
function M.init()
	--注册全局中间件
	app:use(logger_mid())
	do
		local v1 = app:group("v1")
		--注册v1路由组的中间件
		v1:use(function(c)
			log.info("process begin v1 mid ",c.req.path,c.req.method)
			c:next()
			log.info("process end v1 mid ",c.req.path,c.req.method)
		end)
		v1:get('/login',function(c)
			log.info("v1 login ")
		end)

		v1:get('/logout',function(c)
			log.info("v1 logout ")
		end)
	end

	do
		local v2 = app:group("v2")
		--注册v2路由组的中间件
		v2:use(function(c)
			log.info("process begin v2 mid ",c.req.path,c.req.method)
			c:next()
			log.info("process end v2 mid ",c.req.path,c.req.method)
		end)
		v2:get('/login',function(c)
			log.info("v2 login ")
		end)

		v2:get('/logout',function(c)
			log.info("v2 logout ")
		end)
	end

	app:run()
end

--服务退出
function M.exit()

end
  • 单文件
--初始化一个纯净版
local app = engine_web:new()
--请求处理
M.dispatch = engine_web.dispatch(app)

--初始化
function M.init()
	--注册全局中间件
	app:use(logger_mid())

	app:static_file('/login/test.webp','./static/test.webp')

	app:run()
end

--服务退出
function M.exit()

end
  • 资源文件夹
--初始化一个纯净版
local app = engine_web:new()
--请求处理
M.dispatch = engine_web.dispatch(app)

--初始化
function M.init()
	--注册全局中间件
	app:use(logger_mid())

	app:static_dir("/login","./static/imgs")

	app:run()
end

--服务退出
function M.exit()

end
  • Benchmark

skynet_fly

30 threads and 1000 connections
Thread Stats   Avg      Stdev     Max   +/- Stdev
Latency    43.07ms    5.32ms 423.34ms   95.72%
Req/Sec   761.97     93.59     1.00k    82.94%
680746 requests in 30.10s, 52.60MB read
Requests/sec:  22619.75
Transfer/sec:      1.75MB

gin

30 threads and 1000 connections
Thread Stats   Avg      Stdev     Max   +/- Stdev
Latency    10.91ms   10.15ms 421.71ms   82.49%
Req/Sec     3.43k     1.09k   30.39k    77.92%
3051430 requests in 30.11s, 325.93MB read
Requests/sec: 101354.20
Transfer/sec:     10.83MB

gin还是快啊

快速开始 游戏服务 (运行examples/digitalbomb)

  • 构建服务

    • cd examples/digitalbomb/
    • sh ../../binshell/make_server.sh ../../
  • 运行服务 sh script/run.sh

基于tcp长连接实现不停服更新 digitalbomb 数字炸弹游戏。 除了登录 login 服不能热更。 hall 大厅服。 alloc 分配服。 table 桌子服都是可行的。 内置了客户端,可以直接看到效果。

  • 业务解耦登录大厅匹配游戏,还有协议都完成了解耦,开发新游戏只需要实现对应的插件接口即可。

  • 切换示例 把digitalbomb游戏由pb协议转换到跑json协议。

    修改配置文件 load_mods.lua

client_m 配置的 net_util由pbnet_util 改为 jsonet_util

room_game_hall_m 配置的 net_util由pbnet_util 改为 jsonet_util

room_game_alloc_m 配置的 net_util由pbnet_util 改为 jsonet_util

room_game_table_m 配置的 net_util由pbnet_util 改为 jsonet_util

执行 sh script/restart.sh

  • 热更新 client_m 表写了测试用例,可以用来验证热更新。 也可以通过script/check_reload.sh的方式,不过你先修改好文件,然后开始执行。

  • 游戏热更新原理 新服替换旧服务的方案。 旧连接跟旧服务通信。 新连接跟新服务通信。 适合用于玩一把游戏就退出的微服务架构。

如何远程rpc调用

具体使用例子可以参照examples/cluster_client examples/cluster_server

完整项目示例

skynet_fly's People

Contributors

bluesky0521 avatar huahua132 avatar sssfldddsa avatar vm-001 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

skynet_fly's Issues

在游戏中使用redisf会报错

在table_plug.lua中写入:
local redisf = require "redisf"
执行到skynet_fly_demo\skynet_fly\lualib\write_mod_required.lua这里会报错,无法生成module_info\room_game_table_m.required:

[:00000012][20231121 17:59:51 58]lua call [d to :12 : 11 msgsz = 72] error : ^[[31m../../skynet_fly/skynet/lualib/skynet.lua:966: ../../skynet_fly/skynet/lualib/skynet.lua:434: ../../skynet_fly/skynet/lualib/skynet/require.lua:96: ../../skynet_fly/skynet/lualib/skynet/require.lua:96: ../../skynet_fly/skynet/lualib/skynet/require.lua:36: module 'sha2' not found:
no field package.preload['sha2']
no file './sha2.lua'
no file './/logs/sha2.lua'
no file './/lualib/sha2.lua'
no file './/lualib/alloc/sha2.lua'
no file './/lualib/enum/sha2.lua'
no file './/lualib/hall/sha2.lua'
no file './/lualib/login/sha2.lua'
no file './/lualib/module/sha2.lua'
no file './/lualib/table/sha2.lua'
no file './/module_info/sha2.lua'
no file './/proto/sha2.lua'
no file './/script/sha2.lua'
no file '../../common/sha2.lua'
no file '../../common//enum/sha2.lua'
no file '../../common//msg/sha2.lua'
no file '../../common//proto/sha2.lua'
no file '../../skynet_fly/lualib/sha2.lua'
no file '../../skynet_fly/lualib/cache/sha2.lua'
no file '../../skynet_fly/lualib/check/sha2.lua'
no file '../../skynet_fly/lualib/client/sha2.lua'

make build fail due to luaclib/lfs.so

Cannot build on both Intel and Apple CPU on MacOSX

make build
cc -g -O0 -Wall -Iskynet/3rd/lua -I3rd/lua-openssl-0.8.5-0/deps/auxiliar/ -I3rd/lua-openssl-0.8.5-0/deps/lua-compat/ -I3rd/lua-openssl-0.8.5-0/deps/lua-compat/c-api/ -I3rd/lua-openssl-0.8.5-0/src/   -fPIC --shared -I3rd/luafilesystem-1_8_0/src 3rd/luafilesystem-1_8_0/src/lfs.c -o luaclib/lfs.so
ld: Undefined symbols:
  _luaL_argerror, referenced from:
      _dir_iter in lfs-c038af.o
  _luaL_checklstring, referenced from:
      _change_dir in lfs-c038af.o
      _dir_iter_factory in lfs-c038af.o
      _make_link in lfs-c038af.o
      _make_link in lfs-c038af.o
      _file_lock in lfs-c038af.o
      _make_dir in lfs-c038af.o
      _remove_dir in lfs-c038af.o
      ...
  _luaL_checkoption, referenced from:
      _lfs_g_setmode in lfs-c038af.o
  _luaL_checkudata, referenced from:
      _dir_iter in lfs-c038af.o
      _lfs_unlock_dir in lfs-c038af.o
      _check_file in lfs-c038af.o
  _luaL_checkversion_, referenced from:
      _luaopen_lfs in lfs-c038af.o
  _luaL_error, referenced from:
      _dir_iter_factory in lfs-c038af.o
      __file_info_ in lfs-c038af.o
      _check_file in lfs-c038af.o
      __file_lock in lfs-c038af.o
  _luaL_newmetatable, referenced from:
      _dir_create_meta in lfs-c038af.o
      _lock_create_meta in lfs-c038af.o
  _luaL_optinteger, referenced from:
      _file_lock in lfs-c038af.o
      _file_lock in lfs-c038af.o
      _file_utime in lfs-c038af.o
      _file_unlock in lfs-c038af.o
      _file_unlock in lfs-c038af.o
  _luaL_optnumber, referenced from:
      _file_utime in lfs-c038af.o
  _luaL_setfuncs, referenced from:
      _luaopen_lfs in lfs-c038af.o
  _lua_createtable, referenced from:
      _luaopen_lfs in lfs-c038af.o
      _dir_create_meta in lfs-c038af.o
      _lock_create_meta in lfs-c038af.o
      __file_info_ in lfs-c038af.o
  _lua_getfield, referenced from:
      _dir_iter_factory in lfs-c038af.o
      _lfs_lock_dir in lfs-c038af.o
  _lua_gettop, referenced from:
      _file_utime in lfs-c038af.o
  _lua_isstring, referenced from:
      _link_info in lfs-c038af.o
      __file_info_ in lfs-c038af.o
  _lua_newuserdatauv, referenced from:
      _dir_iter_factory in lfs-c038af.o
      _lfs_lock_dir in lfs-c038af.o
  _lua_pushboolean, referenced from:
      _change_dir in lfs-c038af.o
      _file_lock in lfs-c038af.o
      _file_unlock in lfs-c038af.o
      _pushresult in lfs-c038af.o
      _lfs_g_setmode in lfs-c038af.o
  _lua_pushcclosure, referenced from:
      _dir_create_meta in lfs-c038af.o
      _dir_create_meta in lfs-c038af.o
      _dir_create_meta in lfs-c038af.o
      _dir_create_meta in lfs-c038af.o
      _lock_create_meta in lfs-c038af.o
      _lock_create_meta in lfs-c038af.o
      _dir_iter_factory in lfs-c038af.o
      ...
  _lua_pushfstring, referenced from:
      _change_dir in lfs-c038af.o
      _file_lock in lfs-c038af.o
      _file_unlock in lfs-c038af.o
      __file_info_ in lfs-c038af.o
      _pusherror in lfs-c038af.o
  _lua_pushinteger, referenced from:
      _push_st_dev in lfs-c038af.o
      _push_st_ino in lfs-c038af.o
      _push_st_nlink in lfs-c038af.o
      _push_st_uid in lfs-c038af.o
      _push_st_gid in lfs-c038af.o
      _push_st_rdev in lfs-c038af.o
      _push_st_atime in lfs-c038af.o
      ...
  _lua_pushlstring, referenced from:
      _push_link_target in lfs-c038af.o
  _lua_pushnil, referenced from:
      _change_dir in lfs-c038af.o
      _dir_iter_factory in lfs-c038af.o
      _file_lock in lfs-c038af.o
      _file_unlock in lfs-c038af.o
      _lfs_lock_dir in lfs-c038af.o
      _lfs_lock_dir in lfs-c038af.o
      __file_info_ in lfs-c038af.o
      ...
  _lua_pushstring, referenced from:
      _push_st_mode in lfs-c038af.o
      _push_st_perm in lfs-c038af.o
      _set_info in lfs-c038af.o
      _set_info in lfs-c038af.o
      _set_info in lfs-c038af.o
      _dir_iter in lfs-c038af.o
      _get_dir in lfs-c038af.o
      ...
  _lua_pushvalue, referenced from:
      _luaopen_lfs in lfs-c038af.o
      _dir_iter_factory in lfs-c038af.o
  _lua_rawset, referenced from:
      __file_info_ in lfs-c038af.o
  _lua_setfield, referenced from:
      _dir_create_meta in lfs-c038af.o
      _dir_create_meta in lfs-c038af.o
      _dir_create_meta in lfs-c038af.o
      _dir_create_meta in lfs-c038af.o
      _dir_create_meta in lfs-c038af.o
      _lock_create_meta in lfs-c038af.o
      _lock_create_meta in lfs-c038af.o
      _lock_create_meta in lfs-c038af.o
      ...
  _lua_setglobal, referenced from:
      _luaopen_lfs in lfs-c038af.o
  _lua_setmetatable, referenced from:
      _dir_iter_factory in lfs-c038af.o
      _lfs_lock_dir in lfs-c038af.o
  _lua_settop, referenced from:
      __file_info_ in lfs-c038af.o
  _lua_toboolean, referenced from:
      _make_link in lfs-c038af.o
  _lua_tolstring, referenced from:
      _link_info in lfs-c038af.o
      __file_info_ in lfs-c038af.o
  _lua_touserdata, referenced from:
      _dir_close in lfs-c038af.o
  _lua_type, referenced from:
      _link_info in lfs-c038af.o
      __file_info_ in lfs-c038af.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [luaclib/lfs.so] Error 1

如何解析业务层json数据包的内容

这里我使用的是json封包解包
skynet_fly_demo\skynet_fly\lualib\utils\net\util_net_base.lua:

                        local msg, err = pack(name, tab)
			if not msg then
				log.error("pb_netpack.pack err ", name, tab, err)
				return
			end

			--大端2字节表示包长度
			local send_buffer = string.pack(">I2", msg:len()) .. msg

			log.info("send name:", name)
			log.info("send msg:", tostring(msg))

那我对应的测试客户端可以直接用json.unpack解出来吗
还是必须要按这个pack的逆向过程处理一遍

在阿里云机器上启动报错了

之前在腾讯云上传启动没问题,今天换了一台阿里云的机器就报这样的错误了,环境搭建都是一样的步骤,这是为啥啊

[:0000000d][20231128 13:26:21 23][fatal][contriner_mgr][../../skynet_fly/service/contriner_mgr.lua:81]launch_new_module err room_game_hall_m {
net_util = ws_pbnet_util,
hall_plug = hall_plug,
}

[:00000011][20231128 13:26:21 23]LAUNCH snlua hot_container room_game_alloc_m 1 2023-11-28[13:26:21] 1701149181 1
[:00000010][20231128 13:26:21 23]lua call [d to :10 : 6 msgsz = 51] error : ^[[31m../../skynet_fly/skynet/lualib/skynet.lua:966: ../../skynet_fly/skynet/lualib/skynet.lua:434: ../../skynet_fly/skynet/lualib/skynet/require.lua:96: ../../skynet_fly/skynet/lualib/skynet/require.lua:96: ../../skynet_fly/skynet/lualib/skynet/require.lua:96: ../../skynet_fly/skynet/lualib/skynet/require.lua:96: ../../skynet_fly/skynet/lualib/skynet.lua:53: assertion failed!
stack traceback:
[C]: in function 'assert'
../../skynet_fly/skynet/lualib/skynet.lua:53: in function 'skynet.register_protocol'
../../skynet_fly/skynet/lualib/skynet/socket.lua:201: in upvalue 'modfunc'
../../skynet_fly/skynet/lualib/skynet/require.lua:67: in function <../../skynet_fly/skynet/lualib/skynet/require.lua:66>
[C]: in function 'xpcall'
../../skynet_fly/skynet/lualib/skynet/require.lua:80: in function 'skynet.require.require'
(...tail calls...)
../../skynet_fly/lualib/utils/net/util_net_base.lua:2: in upvalue 'modfunc'
../../skynet_fly/skynet/lualib/skynet/require.lua:67: in function <../../skynet_fly/skynet/lualib/skynet/require.lua:66>
[C]: in function 'xpcall'
../../skynet_fly/skynet/lualib/skynet/require.lua:80: in function 'skynet.require.require'
(...tail calls...)
../../skynet_fly/lualib/utils/net/ws_pbnet_util.lua:3: in upvalue 'modfunc'
../../skynet_fly/skynet/lualib/skynet/require.lua:67: in function <../../skynet_fly/s

json插件如何正确使用

function M.create_pack(encode)
	return function(name,tab)
		assert(name)
		assert(tab)
	
		local ok,str = encode(name,tab)
		if not ok then
			return nil,str
		end
	
		local pbmsgbuff = spack(">I2",name:len()) .. name .. str
		return pbmsgbuff
	end
end

打包json消息的时候也要传入packname吗?

常驻的table如何热更

我想在第一个玩家进入后只创建一个桌子,之后所有玩家都进去这个桌子,于是我这么写

enter = function(player_id)
			if not m_player_list[player_id] then
				log.info("进入房间成功 ", player_id)
				m_player_list[player_id] = player:new()
				m_player_list[player_id]:init(player_id)
				if m_finish_init ~= true then
					m_finish_init = true
					timer:new(timer.second * 3, 1, function()
						skynet.fork(game_start)
					end)
				end
			else
				log.info("断线重连 ", player_id)
			end

			return 0
		end,

但是热更失效了,代码和配置都无法热更新。我这种写法有问题吗?

如何调整util_net_base.lua

比如客户端的通用的protobuffer格式如下:

message RequestMessage{
  int32 cmdCode = 1;
  int32 cmdMerge = 2;
  sint32 status = 3; //固定0
  bytes data = 4;
}

具体某个业务协议如下:

message playgameReq{
  int32 playerid = 1;
  int32 type=2;
}

客户端首先将业务协议用protoc打包成data,放入到通用格式的最后一个字段。然后再对通用格式又一次进行protoc打包,最后发送。

那底层这边的pb_netpack.lua是否要这么改:

function M.encode(name, cmdCode, cmdMerge, status, tab)
	assert(name)
	assert(tab)

	if not g_loaded[name] then
		return nil, "encode not exists " .. name
	end

       local ok, str = x_pcall(pb.encode,name, tab)

       pack_msg={
             cmdCode=1000,
            cmdmerge = 0,
            data = str,
       }
	return x_pcall(pb.encode,"RequestMessage", msg)
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.