优化服务器之间的底层连接方式

This commit is contained in:
flswld
2023-01-08 22:11:14 +08:00
parent 99408a745f
commit 6779ed8f20
21 changed files with 742 additions and 216 deletions

View File

@@ -47,10 +47,13 @@ func Run(ctx context.Context, configFile string) error {
ticker := time.NewTicker(time.Second * 15)
for {
<-ticker.C
_, _ = client.Discovery.KeepaliveServer(context.TODO(), &api.KeepaliveServerReq{
_, err := client.Discovery.KeepaliveServer(context.TODO(), &api.KeepaliveServerReq{
ServerType: api.GS,
AppId: APPID,
})
if err != nil {
logger.Error("keepalive error: %v", err)
}
}
}()
GSID = rsp.GetGsId()
@@ -75,7 +78,7 @@ func Run(ctx context.Context, configFile string) error {
}
defer db.CloseDao()
messageQueue := mq.NewMessageQueue(api.GS, APPID)
messageQueue := mq.NewMessageQueue(api.GS, APPID, client)
defer messageQueue.Close()
gameManager := game.NewGameManager(db, messageQueue, GSID)

View File

@@ -54,6 +54,7 @@ func (r *RouteManager) doRoute(cmdId uint16, userId uint32, clientSeq uint32, pa
}
func (r *RouteManager) initRoute() {
r.registerRouter(cmd.QueryPathReq, GAME_MANAGER.QueryPathReq)
r.registerRouter(cmd.UnionCmdNotify, GAME_MANAGER.UnionCmdNotify)
r.registerRouter(cmd.MassiveEntityElementOpBatchNotify, GAME_MANAGER.MassiveEntityElementOpBatchNotify)
r.registerRouter(cmd.ToTheMoonEnterSceneReq, GAME_MANAGER.ToTheMoonEnterSceneReq)

View File

@@ -40,6 +40,18 @@ func (g *GameManager) TowerAllDataReq(player *model.Player, payloadMsg pb.Messag
g.SendMsg(cmd.TowerAllDataRsp, player.PlayerID, player.ClientSeq, towerAllDataRsp)
}
func (g *GameManager) QueryPathReq(player *model.Player, payloadMsg pb.Message) {
// logger.Debug("user query path, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.QueryPathReq)
queryPathRsp := &proto.QueryPathRsp{
QueryId: req.QueryId,
QueryStatus: proto.QueryPathRsp_PATH_STATUS_TYPE_SUCC,
Corners: []*proto.Vector{req.DestinationPos[0]},
}
g.SendMsg(cmd.QueryPathRsp, player.PlayerID, player.ClientSeq, queryPathRsp)
}
func (g *GameManager) EntityAiSyncNotify(player *model.Player, payloadMsg pb.Message) {
logger.Debug("user entity ai sync, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.EntityAiSyncNotify)

View File

@@ -1,6 +1,7 @@
package game
import (
"hk4e/common/constant"
"hk4e/common/utils"
"hk4e/gs/model"
"hk4e/pkg/logger"
@@ -101,7 +102,51 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
for _, entry := range req.InvokeList {
switch entry.ArgumentType {
case proto.CombatTypeArgument_COMBAT_TYPE_ARGUMENT_EVT_BEING_HIT:
continue
hitInfo := new(proto.EvtBeingHitInfo)
clientProtoObj := g.GetClientProtoObjByName("EvtBeingHitInfo")
if clientProtoObj == nil {
logger.Error("get client proto obj is nil")
return
}
ok := utils.UnmarshalProtoObj(hitInfo, clientProtoObj, entry.CombatData)
if !ok {
continue
}
attackResult := hitInfo.AttackResult
if attackResult == nil {
logger.Error("attackResult is nil")
continue
}
logger.Debug("run attack handler, attackResult: %v", attackResult)
target := scene.GetEntity(attackResult.DefenseId)
if target == nil {
logger.Error("could not found target, defense id: %v", attackResult.DefenseId)
continue
}
attackResult.Damage *= 100
damage := attackResult.Damage
attackerId := attackResult.AttackerId
_ = attackerId
currHp := float32(0)
if target.fightProp != nil {
currHp = target.fightProp[uint32(constant.FightPropertyConst.FIGHT_PROP_CUR_HP)]
currHp -= damage
if currHp < 0 {
currHp = 0
}
target.fightProp[uint32(constant.FightPropertyConst.FIGHT_PROP_CUR_HP)] = currHp
}
entityFightPropUpdateNotify := &proto.EntityFightPropUpdateNotify{
FightPropMap: target.fightProp,
EntityId: target.id,
}
g.SendToWorldA(world, cmd.EntityFightPropUpdateNotify, player.ClientSeq, entityFightPropUpdateNotify)
combatData, err := pb.Marshal(hitInfo)
if err != nil {
logger.Error("create combat invocations entity hit info error: %v", err)
}
entry.CombatData = combatData
player.CombatInvokeHandler.AddEntry(entry.ForwardType, entry)
case proto.CombatTypeArgument_COMBAT_TYPE_ARGUMENT_ENTITY_MOVE:
entityMoveInfo := new(proto.EntityMoveInfo)
clientProtoObj := g.GetClientProtoObjByName("EntityMoveInfo")