mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 16:02:26 +08:00
优化代码
This commit is contained in:
@@ -70,6 +70,9 @@ func Run(ctx context.Context, configFile string) error {
|
||||
|
||||
logger.InitLogger("gs_" + APPID)
|
||||
logger.Warn("gs start, appid: %v, gsid: %v", APPID, GSID)
|
||||
defer func() {
|
||||
logger.CloseLogger()
|
||||
}()
|
||||
|
||||
gdconf.InitGameDataConfig()
|
||||
|
||||
@@ -86,7 +89,7 @@ func Run(ctx context.Context, configFile string) error {
|
||||
defer gameManager.Close()
|
||||
|
||||
// natsrpc server
|
||||
conn, err := nats.Connect(config.CONF.MQ.NatsUrl)
|
||||
conn, err := nats.Connect(config.GetConfig().MQ.NatsUrl)
|
||||
if err != nil {
|
||||
logger.Error("connect nats error: %v", err)
|
||||
return err
|
||||
@@ -109,7 +112,6 @@ func Run(ctx context.Context, configFile string) error {
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
logger.Warn("gs exit, appid: %v", APPID)
|
||||
time.Sleep(time.Second)
|
||||
return nil
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
|
||||
@@ -20,7 +20,7 @@ type Dao struct {
|
||||
|
||||
func NewDao() (r *Dao, err error) {
|
||||
r = new(Dao)
|
||||
clientOptions := options.Client().ApplyURI(config.CONF.Database.Url).SetMinPoolSize(1).SetMaxPoolSize(10)
|
||||
clientOptions := options.Client().ApplyURI(config.GetConfig().Database.Url).SetMinPoolSize(1).SetMaxPoolSize(10)
|
||||
client, err := mongo.Connect(context.TODO(), clientOptions)
|
||||
if err != nil {
|
||||
logger.Error("mongo connect error: %v", err)
|
||||
@@ -34,8 +34,8 @@ func NewDao() (r *Dao, err error) {
|
||||
r.mongo = client
|
||||
r.db = client.Database("gs_hk4e")
|
||||
r.redis = redis.NewClient(&redis.Options{
|
||||
Addr: config.CONF.Redis.Addr,
|
||||
Password: config.CONF.Redis.Password,
|
||||
Addr: config.GetConfig().Redis.Addr,
|
||||
Password: config.GetConfig().Redis.Password,
|
||||
DB: 0,
|
||||
PoolSize: 10,
|
||||
MinIdleConns: 1,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"hk4e/gdconf"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"hk4e/gdconf"
|
||||
|
||||
"hk4e/gs/model"
|
||||
)
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ type CommandMessage struct {
|
||||
Text string // 命令原始文本
|
||||
Name string // 命令前缀
|
||||
Args map[string]string // 命令参数
|
||||
FuncName string // 函数名
|
||||
Param []string // 函数参数列表
|
||||
}
|
||||
|
||||
// CommandManager 命令管理器
|
||||
@@ -129,6 +131,12 @@ func (c *CommandManager) InputCommand(executor any, text string) {
|
||||
// HandleCommand 处理命令
|
||||
// 主协程接收到命令消息后执行
|
||||
func (c *CommandManager) HandleCommand(cmd *CommandMessage) {
|
||||
if cmd.FuncName != "" {
|
||||
logger.Info("run gm cmd, FuncName: %v, Param: %v", cmd.FuncName, cmd.Param)
|
||||
// TODO 反射调用command_gm.go中的函数并反射解析传入参数类型
|
||||
return
|
||||
}
|
||||
|
||||
executor := cmd.Executor
|
||||
|
||||
// 分割出命令的每个参数
|
||||
|
||||
@@ -63,7 +63,7 @@ func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gs
|
||||
r.dao = dao
|
||||
MESSAGE_QUEUE = messageQueue
|
||||
r.snowflake = alg.NewSnowflakeWorker(int64(gsId))
|
||||
if config.CONF.Hk4e.ClientProtoProxyEnable {
|
||||
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
|
||||
r.clientCmdProtoMap = client_proto.NewClientCmdProtoMap()
|
||||
// 反射调用的方法在启动时测试是否正常防止中途panic
|
||||
r.GetClientProtoObjByName("PingReq")
|
||||
@@ -276,7 +276,6 @@ func (g *GameManager) Close() {
|
||||
},
|
||||
})
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
// SendMsgToGate 发送消息给客户端 指定网关
|
||||
|
||||
@@ -112,7 +112,7 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
|
||||
switch entry.ArgumentType {
|
||||
case proto.CombatTypeArgument_COMBAT_EVT_BEING_HIT:
|
||||
hitInfo := new(proto.EvtBeingHitInfo)
|
||||
if config.CONF.Hk4e.ClientProtoProxyEnable {
|
||||
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
|
||||
clientProtoObj := g.GetClientProtoObjByName("EvtBeingHitInfo")
|
||||
if clientProtoObj == nil {
|
||||
logger.Error("get client proto obj is nil")
|
||||
@@ -170,7 +170,7 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
|
||||
player.CombatInvokeHandler.AddEntry(entry.ForwardType, entry)
|
||||
case proto.CombatTypeArgument_ENTITY_MOVE:
|
||||
entityMoveInfo := new(proto.EntityMoveInfo)
|
||||
if config.CONF.Hk4e.ClientProtoProxyEnable {
|
||||
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
|
||||
clientProtoObj := g.GetClientProtoObjByName("EntityMoveInfo")
|
||||
if clientProtoObj == nil {
|
||||
logger.Error("get client proto obj is nil")
|
||||
@@ -239,7 +239,7 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
|
||||
player.CombatInvokeHandler.AddEntry(entry.ForwardType, entry)
|
||||
case proto.CombatTypeArgument_COMBAT_ANIMATOR_STATE_CHANGED:
|
||||
evtAnimatorStateChangedInfo := new(proto.EvtAnimatorStateChangedInfo)
|
||||
if config.CONF.Hk4e.ClientProtoProxyEnable {
|
||||
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
|
||||
clientProtoObj := g.GetClientProtoObjByName("EvtAnimatorStateChangedInfo")
|
||||
if clientProtoObj == nil {
|
||||
logger.Error("get client proto obj is nil")
|
||||
@@ -403,7 +403,7 @@ func (g *GameManager) ClientAbilityChangeNotify(player *model.Player, payloadMsg
|
||||
switch abilityInvokeEntry.ArgumentType {
|
||||
case proto.AbilityInvokeArgument_ABILITY_META_ADD_NEW_ABILITY:
|
||||
abilityMetaAddAbility := new(proto.AbilityMetaAddAbility)
|
||||
if config.CONF.Hk4e.ClientProtoProxyEnable {
|
||||
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
|
||||
clientProtoObj := g.GetClientProtoObjByName("AbilityMetaAddAbility")
|
||||
if clientProtoObj == nil {
|
||||
logger.Error("get client proto obj is nil")
|
||||
@@ -433,7 +433,7 @@ func (g *GameManager) ClientAbilityChangeNotify(player *model.Player, payloadMsg
|
||||
worldAvatar.SetAbilityList(abilityList)
|
||||
case proto.AbilityInvokeArgument_ABILITY_META_MODIFIER_CHANGE:
|
||||
abilityMetaModifierChange := new(proto.AbilityMetaModifierChange)
|
||||
if config.CONF.Hk4e.ClientProtoProxyEnable {
|
||||
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
|
||||
clientProtoObj := g.GetClientProtoObjByName("AbilityMetaModifierChange")
|
||||
if clientProtoObj == nil {
|
||||
logger.Error("get client proto obj is nil")
|
||||
|
||||
@@ -23,7 +23,7 @@ type UserInfo struct {
|
||||
// 获取卡池信息
|
||||
func (g *GameManager) GetGachaInfoReq(player *model.Player, payloadMsg pb.Message) {
|
||||
logger.Debug("user get gacha info, uid: %v", player.PlayerID)
|
||||
serverAddr := config.CONF.Hk4e.GachaHistoryServer
|
||||
serverAddr := config.GetConfig().Hk4e.GachaHistoryServer
|
||||
userInfo := &UserInfo{
|
||||
UserId: player.PlayerID,
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
|
||||
@@ -23,7 +23,7 @@ func (g *GameManager) HandleAbilityStamina(player *model.Player, entry *proto.Ab
|
||||
case proto.AbilityInvokeArgument_ABILITY_MIXIN_COST_STAMINA:
|
||||
// 大剑重击 或 持续技能 耐力消耗
|
||||
costStamina := new(proto.AbilityMixinCostStamina)
|
||||
if config.CONF.Hk4e.ClientProtoProxyEnable {
|
||||
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
|
||||
clientProtoObj := g.GetClientProtoObjByName("AbilityMixinCostStamina")
|
||||
if clientProtoObj == nil {
|
||||
logger.Error("get client proto obj is nil")
|
||||
|
||||
@@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"hk4e/gs/api"
|
||||
"hk4e/gs/game"
|
||||
@@ -15,9 +14,12 @@ type GMService struct {
|
||||
}
|
||||
|
||||
func (s *GMService) Cmd(ctx context.Context, req *api.CmdRequest) (*api.CmdReply, error) {
|
||||
// TODO implement me
|
||||
fmt.Println("Cmd", req.FuncName, req.Param)
|
||||
commandTextInput := game.COMMAND_MANAGER.GetCommandTextInput()
|
||||
commandTextInput <- &game.CommandMessage{
|
||||
FuncName: req.FuncName,
|
||||
Param: req.Param,
|
||||
}
|
||||
return &api.CmdReply{
|
||||
Message: "TODO",
|
||||
Message: "OK",
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user