nats-server.exe),其他操作系统需自行搭建nats serverrobot_client 为go实现的游戏压测客户端,使用tcp/protobuf协议nodes/web/view/ 为h5实现的游戏客户端,使用websocket/protobuf协议examples/config/profile-gc.jsonexamples/config/data/git clone https://github.com/mhaya.gitcode按钮Download zip下载源码包打开项目源码,找到
examples/demo_game_cluster目录
nats为高性能的分布式消息中间件,详情可通过
https://github.com/nats-io/nats-server进行了解
本框架中所有节点都基于nats进行消息通信
单机版nats执行程序在examples/3rd/nats-server目录中
正式环境请使用集群nats-streaming-server进行部署https://github.com/nats-io/nats-streaming-server
examples/3rd/nats-server/run_nats.bat单机版Listening for client connections on 0.0.0.0:4222 代表nats启动成功,nats默认监听4222端口找到
exmaples/demo_game_cluster/nodes/main.go,所有节点都从main.go启动
启动参数请参考launch.json文件
master节点主要用于实现最基础的发现服务,基于nats构建
正式环境也可配置为etcd方式提供发现服务
相关的代码在examples/demo_game_cluster/master/目录
master --path=./examples/config/profile-gc.json --node=gc-mastercenter节点目前主要用于处理帐号相关的业务或全局唯一的业务
center --path=./examples/config/profile-gc.json --node=gc-centerweb节点主要对外提供一些http的接口,可横向扩展,多节点部署
目前用于开发者帐号注册、区服列表、sdk登陆/支付回调、验证token生成等业务
web --path=./examples/config/profile-gc.json --node=gc-web-1gate节点为游戏对外网关,可横向扩展,多节点部署
主要用于管理客户端的连接、消息路由与转发
gate --path=./examples/config/profile-gc.json --node=gc-gate-1game节点为具体的游戏逻辑业务,根据业务需求可多节点部署
在分服的游戏中可提供游戏内的各种逻辑实现
game --path=./examples/config/profile-gc.json --node=10001examples/demo_game_cluster/robot_client/main.go 文件,并执行注册帐号,登陆获取token、连接网关、用户登录游戏服、查看角色、创建角色、进入角色maxRobotNum参数进行测试Console可以查看到onlineCount = 10000字样,表示1万帐号已经进入游戏http://127.0.0.1,按照界面步骤提示操作internal 内部业务逻辑
code 定义一些业务的状态码component 组件目录,
check_center组件, 用于在启动前节点先检查center节点是否已启动constant 一些常用定义data 策划配表包装的struct,用于读取../../config/data目录的策划配表event 游戏事件guid 生成全局idpb protobuf生成的协议结构protocol protobuf结构定义目录rpc 跨节点rpc函数封装session_key 一些session相关的常量定义token 登录token逻辑,包含生成token、验证tokentypes 各种自定义类型封装,方便struct从配置文件、数据库读取数据时进行序列化、反序列化nodes 分布式节点目录
center节点game 节点gate 节点master 节点web 节点(为了演示方便,包含了h5客户端)robot_client 压测机器人(tcp/protobuf协议)
build_protocol.bat 生成protobuf结构代码到internal/pb/目录