mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:22:26 +08:00
添加了节点服务器,各个服务器之间支持多对多
This commit is contained in:
@@ -10,17 +10,36 @@ import (
|
||||
|
||||
"hk4e/common/config"
|
||||
"hk4e/common/mq"
|
||||
"hk4e/common/rpc"
|
||||
"hk4e/node/api"
|
||||
"hk4e/pathfinding/handle"
|
||||
"hk4e/pkg/logger"
|
||||
)
|
||||
|
||||
var APPID string
|
||||
|
||||
func Run(ctx context.Context, configFile string) error {
|
||||
config.InitConfig(configFile)
|
||||
|
||||
logger.InitLogger("pathfinding")
|
||||
logger.Warn("pathfinding start")
|
||||
// natsrpc client
|
||||
client, err := rpc.NewClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
messageQueue := mq.NewMessageQueue(mq.PATHFINDING, "1")
|
||||
// 注册到节点服务器
|
||||
rsp, err := client.Discovery.RegisterServer(context.TODO(), &api.RegisterServerReq{
|
||||
ServerType: api.PATHFINDING,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
APPID = rsp.GetAppId()
|
||||
|
||||
logger.InitLogger("pathfinding_" + APPID)
|
||||
logger.Warn("pathfinding start, appid: %v", APPID)
|
||||
|
||||
messageQueue := mq.NewMessageQueue(api.PATHFINDING, APPID)
|
||||
defer messageQueue.Close()
|
||||
|
||||
_ = handle.NewHandle(messageQueue)
|
||||
@@ -35,7 +54,7 @@ func Run(ctx context.Context, configFile string) error {
|
||||
logger.Warn("get a signal %s", s.String())
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
logger.Warn("pathfinding exit")
|
||||
logger.Warn("pathfinding exit, appid: %v", APPID)
|
||||
time.Sleep(time.Second)
|
||||
return nil
|
||||
case syscall.SIGHUP:
|
||||
|
||||
@@ -2,6 +2,7 @@ package handle
|
||||
|
||||
import (
|
||||
"hk4e/common/mq"
|
||||
"hk4e/node/api"
|
||||
"hk4e/pathfinding/world"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/protocol/cmd"
|
||||
@@ -34,12 +35,15 @@ func (h *Handle) run() {
|
||||
if netMsg.EventId != mq.NormalMsg {
|
||||
continue
|
||||
}
|
||||
if netMsg.OriginServerType != api.GATE {
|
||||
continue
|
||||
}
|
||||
gameMsg := netMsg.GameMsg
|
||||
switch gameMsg.CmdId {
|
||||
case cmd.QueryPathReq:
|
||||
h.QueryPath(gameMsg.UserId, gameMsg.PayloadMessage)
|
||||
h.QueryPath(gameMsg.UserId, netMsg.OriginServerAppId, gameMsg.PayloadMessage)
|
||||
case cmd.ObstacleModifyNotify:
|
||||
h.ObstacleModifyNotify(gameMsg.UserId, gameMsg.PayloadMessage)
|
||||
h.ObstacleModifyNotify(gameMsg.UserId, netMsg.OriginServerAppId, gameMsg.PayloadMessage)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -47,7 +51,7 @@ func (h *Handle) run() {
|
||||
}
|
||||
|
||||
// SendMsg 发送消息给客户端
|
||||
func (h *Handle) SendMsg(cmdId uint16, userId uint32, payloadMsg pb.Message) {
|
||||
func (h *Handle) SendMsg(cmdId uint16, userId uint32, gateAppId string, payloadMsg pb.Message) {
|
||||
if userId < 100000000 || payloadMsg == nil {
|
||||
return
|
||||
}
|
||||
@@ -62,7 +66,7 @@ func (h *Handle) SendMsg(cmdId uint16, userId uint32, payloadMsg pb.Message) {
|
||||
return
|
||||
}
|
||||
gameMsg.PayloadMessageData = payloadMessageData
|
||||
h.messageQueue.SendToGate("1", &mq.NetMsg{
|
||||
h.messageQueue.SendToGate(gateAppId, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeGame,
|
||||
EventId: mq.NormalMsg,
|
||||
GameMsg: gameMsg,
|
||||
|
||||
@@ -41,9 +41,9 @@ func (h *Handle) ConvMeshVecListToPbVecList(meshVecList []pfalg.MeshVector) []*p
|
||||
return ret
|
||||
}
|
||||
|
||||
func (h *Handle) QueryPath(userId uint32, payloadMsg pb.Message) {
|
||||
func (h *Handle) QueryPath(userId uint32, gateAppId string, payloadMsg pb.Message) {
|
||||
req := payloadMsg.(*proto.QueryPathReq)
|
||||
logger.Debug("query path req: %v, uid: %v", req, userId)
|
||||
logger.Debug("query path req: %v, uid: %v, gateAppId: %v", req, userId, gateAppId)
|
||||
var ok = false
|
||||
var path []pfalg.MeshVector = nil
|
||||
for _, destinationPos := range req.DestinationPos {
|
||||
@@ -57,7 +57,7 @@ func (h *Handle) QueryPath(userId uint32, payloadMsg pb.Message) {
|
||||
QueryId: req.QueryId,
|
||||
QueryStatus: proto.QueryPathRsp_PATH_STATUS_TYPE_FAIL,
|
||||
}
|
||||
h.SendMsg(cmd.QueryPathRsp, userId, queryPathRsp)
|
||||
h.SendMsg(cmd.QueryPathRsp, userId, gateAppId, queryPathRsp)
|
||||
return
|
||||
}
|
||||
queryPathRsp := &proto.QueryPathRsp{
|
||||
@@ -65,10 +65,10 @@ func (h *Handle) QueryPath(userId uint32, payloadMsg pb.Message) {
|
||||
QueryStatus: proto.QueryPathRsp_PATH_STATUS_TYPE_SUCC,
|
||||
Corners: h.ConvMeshVecListToPbVecList(path),
|
||||
}
|
||||
h.SendMsg(cmd.QueryPathRsp, userId, queryPathRsp)
|
||||
h.SendMsg(cmd.QueryPathRsp, userId, gateAppId, queryPathRsp)
|
||||
}
|
||||
|
||||
func (h *Handle) ObstacleModifyNotify(userId uint32, payloadMsg pb.Message) {
|
||||
func (h *Handle) ObstacleModifyNotify(userId uint32, gateAppId string, payloadMsg pb.Message) {
|
||||
req := payloadMsg.(*proto.ObstacleModifyNotify)
|
||||
logger.Debug("obstacle modify req: %v, uid: %v", req, userId)
|
||||
logger.Debug("obstacle modify req: %v, uid: %v, gateAppId: %v", req, userId, gateAppId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user