From 6feadbfeefd6f78166eb19c41987cd42b4c3abbe Mon Sep 17 00:00:00 2001 From: liuxiaobo <1224730913@qq.com> Date: Sun, 15 Jun 2025 20:22:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gate/config/config.go | 6 +++--- server/gate/server/service.go | 10 +++++++--- server/login/config/config.go | 4 ++-- server/login/server/processor.go | 8 ++++---- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/server/gate/config/config.go b/server/gate/config/config.go index d659b83..3527c12 100644 --- a/server/gate/config/config.go +++ b/server/gate/config/config.go @@ -17,7 +17,7 @@ const ( var Command *config.Command var Cfg *config.Common -var GateCfg *GateConfig +var GateCfg = &GateConfig{} type GateConfig struct { Address []string `json:"address"` // 网关地址 @@ -39,12 +39,12 @@ func LoadConfig(GitCommit, GitBranch, BuildDate string) { return } defer func() { _ = rdb.Close() }() - Cfg, err = config.LoadCommonConfig[GateConfig](rdb, GitCommit, GitBranch, BuildDate) + Cfg, err = config.LoadCommonConfig(rdb, GitCommit, GitBranch, BuildDate) if err != nil { log.Error(err.Error()) return } - if err = config.LoadGameConfig[GateConfig](rdb, gateKey, Cfg); err != nil { + if err = config.LoadGameConfig(rdb, gateKey, Cfg); err != nil { log.DebugF("load config:empty etcd key") GateCfg = &GateConfig{ Address: []string{gateAddress1, gateAddress2}, diff --git a/server/gate/server/service.go b/server/gate/server/service.go index 4db685c..0513e74 100644 --- a/server/gate/server/service.go +++ b/server/gate/server/service.go @@ -65,11 +65,11 @@ func newGateService(serviceId int) *GateService { } addressPos := serviceId - config.Command.ServiceId - if len(config.Cfg.Special.Address) <= addressPos { + if len(config.GateCfg.Address) <= addressPos { log.FatalF("Special address number must be greater than %d", addressPos) return nil } - wsAddress := config.Cfg.Special.Address[addressPos] + wsAddress := config.GateCfg.Address[addressPos] s.wss = ws.NewWsServer(wsAddress, s.WsOnMessage, s.WsOnDisconnect) s.bindService = userBindService.NewUserBindService(model.UserBindServiceRedis, s.ServiceEtcd()) @@ -166,7 +166,11 @@ func (s *GateService) WsOnMessage(conn ws.IConn, data []byte) { if msg.ServiceName != "" { topic = service.TopicEx(msg.ServiceName) } else { - topic, msg.ServiceName = s.bindService.FindTopic(conn.UserId(), msg.ServiceTid) + if node, err := s.bindService.FindServiceNode(msg.ServiceTid, conn.UserId()); err == nil { + topic, msg.ServiceName = service.TopicEx(node.Name), node.Name + } else { + log.ErrorF("uid:%v 查找节点:%v 失败:%v", conn.UserId(), msg.ServiceTid, err.Error()) + } } if topic != "" { if msg.MsgId == int32(pb.MsgId_ReqUserLoginId) { diff --git a/server/login/config/config.go b/server/login/config/config.go index d0837dd..39d7369 100644 --- a/server/login/config/config.go +++ b/server/login/config/config.go @@ -8,7 +8,7 @@ import ( ) var Command *config.Command -var Cfg *config.Common[LoginConfig] +var Cfg *config.Common type LoginConfig struct { } @@ -29,7 +29,7 @@ func LoadConfig(GitCommit, GitBranch, BuildDate string) { return } defer func() { _ = rdb.Close() }() - Cfg, err = config.LoadCommonConfig[LoginConfig](rdb, GitCommit, GitBranch, BuildDate) + Cfg, err = config.LoadCommonConfig(rdb, GitCommit, GitBranch, BuildDate) if err != nil { log.Error(err.Error()) return diff --git a/server/login/server/processor.go b/server/login/server/processor.go index 661bfc7..643b7b8 100644 --- a/server/login/server/processor.go +++ b/server/login/server/processor.go @@ -42,7 +42,7 @@ func (s *LoginService) checkLoginOrRegister(req *pb.ReqUserLogin) (us *user.User DeviceID: req.DeviceId, LastLoginIP: req.Ip, } - rpcMsg := ipb.MakeRpcMsg[user.UserAccount](rpc.GetUserAccount, 0, us) + rpcMsg := ipb.MakeRpcMsg(rpc.GetUserAccount, 0, us) rspMsg, err := s.Call(service.RpcTopicEx(node.Name), timeout, rpcMsg) if err != nil { log.ErrorF(s.Log("call rpc:%v err:%s ", rpcMsg.RpcMsgId, err.Error())) @@ -65,7 +65,7 @@ func (s *LoginService) checkLoginOrRegister(req *pb.ReqUserLogin) (us *user.User RegisterIP: req.Ip, RegisterTime: time.Now(), } - rpcMsg = ipb.MakeRpcMsg[user.UserAccount](rpc.CreateUserAccount, 0, us) + rpcMsg = ipb.MakeRpcMsg(rpc.CreateUserAccount, 0, us) rspMsg, err = s.Call(service.RpcTopicEx(node.Name), timeout, rpcMsg) if err != nil { log.ErrorF(s.Log("call rpc:%v err:%s ", rpcMsg.RpcMsgId, err.Error())) @@ -110,7 +110,7 @@ func (s *LoginService) getUser(accountId int64, tName string) (*user.User, pb.Er us := &user.User{ AccountId: accountId, } - rpcMsg := ipb.MakeRpcMsg[user.User](rpc.GetUserByAccountId, 0, us) + rpcMsg := ipb.MakeRpcMsg(rpc.GetUserByAccountId, 0, us) rsp, err := s.Call(service.RpcTopicEx(tName), timeout, rpcMsg) if err != nil { log.ErrorF(s.Log("call rpc:%v err:%s", rpcMsg.RpcMsgId, err.Error())) @@ -157,7 +157,7 @@ func (s *LoginService) onLoginOrRegister(iMsg *ipb.InternalMsg, req *pb.ReqUserL } switch code { case pb.ErrCode_LoginUserOrPwdErr, pb.ErrCode_OK: - rpcMsg := ipb.MakeRpcMsg[user.UserLoginLog](rpc.LogUserAccountLogin, 0, loginLog) + rpcMsg := ipb.MakeRpcMsg(rpc.LogUserAccountLogin, 0, loginLog) ksync.GoSafe(func() { _, _ = s.Call(service.RpcTopicEx(node.Name), timeout, rpcMsg) }, nil)