mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:22:26 +08:00
完善文档
This commit is contained in:
@@ -34,11 +34,22 @@ func Run(ctx context.Context, configFile string) error {
|
||||
IpAddr: config.CONF.Hk4e.KcpAddr,
|
||||
Port: uint32(config.CONF.Hk4e.KcpPort),
|
||||
},
|
||||
Version: config.CONF.Hk4e.Version,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
APPID = rsp.GetAppId()
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Second * 15)
|
||||
for {
|
||||
<-ticker.C
|
||||
_, _ = client.Discovery.KeepaliveServer(context.TODO(), &api.KeepaliveServerReq{
|
||||
ServerType: api.GATE,
|
||||
AppId: APPID,
|
||||
})
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
_, _ = client.Discovery.CancelServer(context.TODO(), &api.CancelServerReq{
|
||||
ServerType: api.GATE,
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
## 功能介绍
|
||||
|
||||
### 开启本功能后,网关服务器以及游戏服务器等其他服务器,将预先对客户端上行和服务器下行的协议数据做前置转换,采用任意版本的协议文件(必要字段名必须与现有的协议保持一致)均可,避免了因协议序号混淆等频繁变动,而造成游戏服务器代码不必要的频繁改动
|
||||
#### 开启本功能后,网关服务器以及游戏服务器等其他服务器,将预先对客户端上行和服务器下行的协议数据做前置转换,采用任意版本的协议文件(必要字段名必须与现有的协议保持一致)均可,避免了因协议序号混淆等频繁变动,而造成游戏服务器代码不必要的频繁改动
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 在此目录下建立bin目录和proto目录
|
||||
2. 将client_cmd.csv文件放到bin目录下
|
||||
3. 将对应版本的proto协议文件复制到proto目录下并编译成pb.go
|
||||
4. 将client_proto_gen_test.go的TestClientProtoGen方法添加运行配置
|
||||
5. 将运行配置输出目录和工作目录都设置为bin目录
|
||||
6. 运行并生成client_proto_gen.go
|
||||
7. 将client_cmd.csv放入gate和gs和fight服务器的运行目录下
|
||||
8. 将gate和gs和fight服务器的配置文件中开启client_proto_proxy_enable客户端协议代理功能
|
||||
> 1. 在此目录下建立bin目录和proto目录
|
||||
> 2. 将对应版本的proto协议文件复制到proto目录下并编译成pb.go
|
||||
> 3. 将client_proto_gen_test.go的TestClientProtoGen方法添加运行配置
|
||||
> 4. 将运行配置输出目录和工作目录都设置为bin目录
|
||||
> 5. 运行并生成client_proto_gen.go
|
||||
> 6. 将client_cmd.csv放入gate和gs和fight服务器的运行目录下
|
||||
> 7. 将gate和gs和fight服务器的配置文件中开启client_proto_proxy_enable客户端协议代理功能
|
||||
|
||||
@@ -14,9 +14,8 @@ func TestClientProtoGen(t *testing.T) {
|
||||
nameList := make([]string, 0)
|
||||
for _, entry := range dir {
|
||||
split := strings.Split(entry.Name(), ".")
|
||||
if len(split) != 2 {
|
||||
if len(split) != 2 || split[1] != "proto" {
|
||||
continue
|
||||
//panic("file name error")
|
||||
}
|
||||
nameList = append(nameList, split[0])
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ func (k *KcpConnectManager) getPlayerToken(req *proto.GetPlayerTokenReq, session
|
||||
}
|
||||
oldSession := k.GetSessionByUserId(tokenVerifyRsp.PlayerID)
|
||||
if oldSession != nil {
|
||||
// 顶号
|
||||
// 本地顶号
|
||||
kickFinishNotifyChan := make(chan bool)
|
||||
k.kcpEventInput <- &KcpEvent{
|
||||
ConvId: oldSession.conn.GetConv(),
|
||||
@@ -303,6 +303,18 @@ func (k *KcpConnectManager) getPlayerToken(req *proto.GetPlayerTokenReq, session
|
||||
EventMessage: kickFinishNotifyChan,
|
||||
}
|
||||
<-kickFinishNotifyChan
|
||||
} else {
|
||||
// 远程全局顶号
|
||||
connCtrlMsg := new(mq.ConnCtrlMsg)
|
||||
connCtrlMsg.KickUserId = tokenVerifyRsp.PlayerID
|
||||
connCtrlMsg.KickReason = kcp.EnetServerRelogin
|
||||
k.messageQueue.SendToAll(&mq.NetMsg{
|
||||
MsgType: mq.MsgTypeConnCtrl,
|
||||
EventId: mq.KickPlayerNotify,
|
||||
ConnCtrlMsg: connCtrlMsg,
|
||||
})
|
||||
// TODO 确保旧连接已下线 已通知GS已保存好数据
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
// 关联玩家uid和连接信息
|
||||
session.userId = tokenVerifyRsp.PlayerID
|
||||
|
||||
@@ -83,7 +83,7 @@ func (k *KcpConnectManager) Start() {
|
||||
k.dispatchKey = regionEc2b.XorKey()
|
||||
// kcp
|
||||
port := strconv.Itoa(int(config.CONF.Hk4e.KcpPort))
|
||||
listener, err := kcp.ListenWithOptions(config.CONF.Hk4e.KcpAddr+":"+port, nil, 0, 0)
|
||||
listener, err := kcp.ListenWithOptions("0.0.0.0:"+port, nil, 0, 0)
|
||||
if err != nil {
|
||||
logger.Error("listen kcp err: %v", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user