合并杂项功能服务器节点到multi服务器节点

This commit is contained in:
flswld committed 2023-10-22 19:46:08 +08:00
1 parent 64699c23d7
commit 6cca998915
42 files changed
+344 -647

No files matched your search

+48 -59
View File
@@ -51,17 +51,16 @@ type KcpEvent struct {
}
type KcpConnManager struct {
kcpListener *kcp.Listener
db *dao.Dao
discoveryClient *rpc.DiscoveryClient // 节点服务器rpc客户端
messageQueue *mq.MessageQueue // 消息队列
globalGsOnlineMap map[uint32]string // 全服玩家在线表
globalGsOnlineMapLock sync.RWMutex
minLoadGsServerAppId string
minLoadAnticheatServerAppId string
minLoadPathfindingServerAppId string
stopServerInfo *api.StopServerInfo
whiteList *api.GetWhiteListRsp
kcpListener *kcp.Listener
db *dao.Dao
discoveryClient *rpc.DiscoveryClient // 节点服务器rpc客户端
messageQueue *mq.MessageQueue // 消息队列
globalGsOnlineMap map[uint32]string // 全服玩家在线表
globalGsOnlineMapLock sync.RWMutex
minLoadGsServerAppId string
minLoadMultiServerAppId string
stopServerInfo *api.StopServerInfo
whiteList *api.GetWhiteListRsp
// 会话
sessionIdCounter uint32
sessionMap map[uint32]*Session
@@ -89,8 +88,7 @@ func NewKcpConnManager(db *dao.Dao, messageQueue *mq.MessageQueue, discovery *rp
r.messageQueue = messageQueue
r.globalGsOnlineMap = make(map[uint32]string)
r.minLoadGsServerAppId = ""
r.minLoadAnticheatServerAppId = ""
r.minLoadPathfindingServerAppId = ""
r.minLoadMultiServerAppId = ""
r.stopServerInfo = nil
r.whiteList = nil
r.sessionIdCounter = 0
@@ -260,23 +258,22 @@ func (k *KcpConnManager) acceptHandle(tcpMode bool, kcpListener *kcp.Listener, t
logger.Info("[ACCEPT] client connect, tcpMode: %v, sessionId: %v, conv: %v, addr: %v",
tcpMode, sessionId, conn.GetConv(), conn.RemoteAddr())
session := &Session{
sessionId: sessionId,
conn: conn,
connState: ConnEst,
userId: 0,
sendChan: make(chan *ProtoMsg, SessionSendChanLen),
seed: 0,
xorKey: k.dispatchKey,
changeXorKeyFin: false,
gsServerAppId: "",
anticheatServerAppId: "",
pathfindingServerAppId: "",
robotServerAppId: "",
useMagicSeed: false,
keyId: 0,
clientRandKey: "",
tcpRtt: 0,
tcpRttLastSendTime: 0,
sessionId: sessionId,
conn: conn,
connState: ConnEst,
userId: 0,
sendChan: make(chan *ProtoMsg, SessionSendChanLen),
seed: 0,
xorKey: k.dispatchKey,
changeXorKeyFin: false,
gsServerAppId: "",
multiServerAppId: "",
robotServerAppId: "",
useMagicSeed: false,
keyId: 0,
clientRandKey: "",
tcpRtt: 0,
tcpRttLastSendTime: 0,
}
if config.GetConfig().Hk4e.ForwardModeEnable {
robotServerAppId, err := k.discoveryClient.GetServerAppId(context.TODO(), &api.GetServerAppIdReq{
@@ -353,23 +350,22 @@ func (k *KcpConnManager) kcpEnetHandle(listener *kcp.Listener) {
// Session 连接会话结构 只允许定义并发安全或者简单的基础数据结构
type Session struct {
sessionId uint32
conn *Conn
connState uint8
userId uint32
sendChan chan *ProtoMsg
seed uint64
xorKey []byte
changeXorKeyFin bool
gsServerAppId string
anticheatServerAppId string
pathfindingServerAppId string
robotServerAppId string
useMagicSeed bool
keyId uint32
clientRandKey string
tcpRtt uint32
tcpRttLastSendTime int64
sessionId uint32
conn *Conn
connState uint8
userId uint32
sendChan chan *ProtoMsg
seed uint64
xorKey []byte
changeXorKeyFin bool
gsServerAppId string
multiServerAppId string
robotServerAppId string
useMagicSeed bool
keyId uint32
clientRandKey string
tcpRtt uint32
tcpRttLastSendTime int64
}
// 接收协程
@@ -706,21 +702,14 @@ func (k *KcpConnManager) syncMinLoadServerAppid() {
} else {
k.minLoadGsServerAppId = gsServerAppId.AppId
}
anticheatServerAppId, err := k.discoveryClient.GetServerAppId(context.TODO(), &api.GetServerAppIdReq{
ServerType: api.ANTICHEAT,
multiServerAppId, err := k.discoveryClient.GetServerAppId(context.TODO(), &api.GetServerAppIdReq{
ServerType: api.MULTI,
})
if err != nil {
k.minLoadAnticheatServerAppId = ""
k.minLoadMultiServerAppId = ""
} else {
k.minLoadAnticheatServerAppId = anticheatServerAppId.AppId
}
pathfindingServerAppId, err := k.discoveryClient.GetServerAppId(context.TODO(), &api.GetServerAppIdReq{
ServerType: api.PATHFINDING,
})
if err != nil {
k.minLoadPathfindingServerAppId = ""
} else {
k.minLoadPathfindingServerAppId = pathfindingServerAppId.AppId
k.minLoadMultiServerAppId = multiServerAppId.AppId
}
}
+8 -22
View File
@@ -121,23 +121,11 @@ func (k *KcpConnManager) forwardClientMsgToServerHandle(protoMsg *ProtoMsg, sess
}
k.serverCmdProtoMap.PutProtoObjCache(protoMsg.CmdId, protoMsg.PayloadMessage)
gameMsg.PayloadMessageData = payloadMessageData
// 转发到寻路服务器
if session.pathfindingServerAppId != "" {
// 转发到寻路服务
if session.multiServerAppId != "" {
if protoMsg.CmdId == cmd.QueryPathReq ||
protoMsg.CmdId == cmd.ObstacleModifyNotify {
k.messageQueue.SendToPathfinding(session.pathfindingServerAppId, &mq.NetMsg{
MsgType: mq.MsgTypeGame,
EventId: mq.NormalMsg,
GameMsg: gameMsg,
})
return
}
}
// 转发到反作弊服务器
if session.anticheatServerAppId != "" {
if protoMsg.CmdId == cmd.CombatInvocationsNotify ||
protoMsg.CmdId == cmd.ToTheMoonEnterSceneReq {
k.messageQueue.SendToAnticheat(session.anticheatServerAppId, &mq.NetMsg{
k.messageQueue.SendToMulti(session.multiServerAppId, &mq.NetMsg{
MsgType: mq.MsgTypeGame,
EventId: mq.NormalMsg,
GameMsg: gameMsg,
@@ -244,8 +232,8 @@ func (k *KcpConnManager) gameMsgHandle(
session.connState = ConnActive
// 通知GS玩家各个服务器的appid
serverMsg := &mq.ServerMsg{
UserId: session.userId,
AnticheatServerAppId: session.anticheatServerAppId,
UserId: session.userId,
MultiServerAppId: session.multiServerAppId,
}
k.messageQueue.SendToGs(session.gsServerAppId, &mq.NetMsg{
MsgType: mq.MsgTypeServer,
@@ -293,7 +281,7 @@ func (k *KcpConnManager) serverMsgHandle(
return
}
session.gsServerAppId = serverMsg.GameServerAppId
session.anticheatServerAppId = ""
session.multiServerAppId = ""
// 网关代发登录请求到新的GS
gameMsg := &mq.GameMsg{
UserId: serverMsg.UserId,
@@ -603,11 +591,9 @@ func (k *KcpConnManager) doGateLogin(req *proto.GetPlayerTokenReq, session *Sess
return k.loginFailRsp(0, proto.Retcode_RET_SVR_ERROR, false, 0)
}
session.gsServerAppId = k.minLoadGsServerAppId
session.anticheatServerAppId = k.minLoadAnticheatServerAppId
session.pathfindingServerAppId = k.minLoadPathfindingServerAppId
session.multiServerAppId = k.minLoadMultiServerAppId
logger.Debug("session gs appid: %v, uid: %v", session.gsServerAppId, uid)
logger.Debug("session anticheat appid: %v, uid: %v", session.anticheatServerAppId, uid)
logger.Debug("session pathfinding appid: %v, uid: %v", session.pathfindingServerAppId, uid)
logger.Debug("session multi appid: %v, uid: %v", session.multiServerAppId, uid)
// 构造响应
rsp := k.buildGateLoginRsp(uid, req.AccountUid, req.AccountToken, clientIp)
// 密钥交换