修改bug
This commit is contained in:
parent
1fdbe979ab
commit
b596e502ee
@ -18,7 +18,7 @@ func RpcAddUserRes(bindService *userBindService.UserBindService, s service.IServ
|
|||||||
return nil, pb.ErrCode_SystemErr
|
return nil, pb.ErrCode_SystemErr
|
||||||
}
|
}
|
||||||
rpcMsg := ipb.MakeRpcMsg(AddUserResources, uid, addUserRes)
|
rpcMsg := ipb.MakeRpcMsg(AddUserResources, uid, addUserRes)
|
||||||
rspMsg, err := s.Call(service.RpcTopicEx(node.Name), timeout, rpcMsg)
|
rspMsg, err := s.CallByTopic(service.RpcTopicEx(node.Name), timeout, rpcMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF("call rpc:%v err:%s ", rpcMsg.RpcMsgId, err.Error())
|
log.ErrorF("call rpc:%v err:%s ", rpcMsg.RpcMsgId, err.Error())
|
||||||
return nil, pb.ErrCode_SystemErr
|
return nil, pb.ErrCode_SystemErr
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
如果需要gate处理后,继续将消息转发给玩家,则最后需要调用SendClientData
|
如果需要gate处理后,继续将消息转发给玩家,则最后需要调用SendClientData
|
||||||
*/
|
*/
|
||||||
func (s *GateService) initProcessor() {
|
func (s *GateService) initProcessor() {
|
||||||
s.processor.RegisterMessages(processor.RegisterMetas{
|
s.Processor().RegisterMessages(processor.RegisterMetas{
|
||||||
pb.MsgId_RspUserLoginId: {pb.RspUserLogin{}, s.onUserLogin},
|
pb.MsgId_RspUserLoginId: {pb.RspUserLogin{}, s.onUserLogin},
|
||||||
pb.MsgId_RspUserLogoutId: {pb.RspUserLogout{}, s.onUserLogout},
|
pb.MsgId_RspUserLogoutId: {pb.RspUserLogout{}, s.onUserLogout},
|
||||||
})
|
})
|
||||||
@ -31,7 +31,7 @@ func (s *GateService) onUserLogin(iMsg *ipb.InternalMsg, conn ws.IConn, msg *pb.
|
|||||||
}
|
}
|
||||||
s.SendClientMsg(conn, iMsg.ServiceName, int32(pb.MsgId_RspUserLoginId), msg)
|
s.SendClientMsg(conn, iMsg.ServiceName, int32(pb.MsgId_RspUserLoginId), msg)
|
||||||
s.wss.SetUserId(conn.Id(), msg.UserId)
|
s.wss.SetUserId(conn.Id(), msg.UserId)
|
||||||
sName := s.bindService.LoadFromRedis(conn.UserId(), pb.ServiceTypeId_STI_Gate)
|
sName := s.BindService().LoadFromRedis(conn.UserId(), pb.ServiceTypeId_STI_Gate)
|
||||||
// 网关不同,说明玩家在其它网关上登陆,
|
// 网关不同,说明玩家在其它网关上登陆,
|
||||||
if sName != "" && sName != s.Name() {
|
if sName != "" && sName != s.Name() {
|
||||||
s.SendServiceMsg(service.TopicEx(sName), conn, int32(pb.MsgId_RspUserLogoutId), &pb.RspUserLogout{Code: pb.ErrCode_LoginDiffLoc})
|
s.SendServiceMsg(service.TopicEx(sName), conn, int32(pb.MsgId_RspUserLogoutId), &pb.RspUserLogout{Code: pb.ErrCode_LoginDiffLoc})
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/fox/fox/processor"
|
"github.com/fox/fox/processor"
|
||||||
"github.com/fox/fox/service"
|
"github.com/fox/fox/service"
|
||||||
"github.com/fox/fox/xrand"
|
"github.com/fox/fox/xrand"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,14 +22,14 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (s *LoginService) initProcessor() {
|
func (s *LoginService) initProcessor() {
|
||||||
s.processor.RegisterMessages(processor.RegisterMetas{
|
s.Processor().RegisterMessages(processor.RegisterMetas{
|
||||||
pb.MsgId_ReqUserLoginId: {pb.ReqUserLogin{}, s.onLoginOrRegister},
|
pb.MsgId_ReqUserLoginId: {pb.ReqUserLogin{}, s.onLoginOrRegister},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *LoginService) checkLoginOrRegister(req *pb.ReqUserLogin) (us *user.UserAccount, code pb.ErrCode, node *etcd.ServiceNode) {
|
func (s *LoginService) checkLoginOrRegister(req *pb.ReqUserLogin) (us *user.UserAccount, code pb.ErrCode, node *etcd.ServiceNode) {
|
||||||
var err error
|
var err error
|
||||||
node, err = s.bindService.HashServiceNode(pb.ServiceTypeId_STI_DB, xrand.RandN[int64](100))
|
node, err = s.BindService().HashServiceNode(pb.ServiceTypeId_STI_DB, xrand.RandN[int64](100))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF(s.Log("not find db service.err:%s ", err.Error()))
|
log.ErrorF(s.Log("not find db service.err:%s ", err.Error()))
|
||||||
return nil, pb.ErrCode_SystemErr, node
|
return nil, pb.ErrCode_SystemErr, node
|
||||||
@ -43,7 +44,7 @@ func (s *LoginService) checkLoginOrRegister(req *pb.ReqUserLogin) (us *user.User
|
|||||||
LastLoginIP: req.Ip,
|
LastLoginIP: req.Ip,
|
||||||
}
|
}
|
||||||
rpcMsg := ipb.MakeRpcMsg(rpc.GetUserAccount, 0, us)
|
rpcMsg := ipb.MakeRpcMsg(rpc.GetUserAccount, 0, us)
|
||||||
rspMsg, err := s.Call(service.RpcTopicEx(node.Name), timeout, rpcMsg)
|
rspMsg, err := s.CallByServiceId(int(pb.ServiceTypeId_STI_DB), timeout, rpcMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF(s.Log("call rpc:%v err:%s ", rpcMsg.RpcMsgId, err.Error()))
|
log.ErrorF(s.Log("call rpc:%v err:%s ", rpcMsg.RpcMsgId, err.Error()))
|
||||||
return nil, pb.ErrCode_SystemErr, node
|
return nil, pb.ErrCode_SystemErr, node
|
||||||
@ -66,7 +67,7 @@ func (s *LoginService) checkLoginOrRegister(req *pb.ReqUserLogin) (us *user.User
|
|||||||
RegisterTime: time.Now(),
|
RegisterTime: time.Now(),
|
||||||
}
|
}
|
||||||
rpcMsg = ipb.MakeRpcMsg(rpc.CreateUserAccount, 0, us)
|
rpcMsg = ipb.MakeRpcMsg(rpc.CreateUserAccount, 0, us)
|
||||||
rspMsg, err = s.Call(service.RpcTopicEx(node.Name), timeout, rpcMsg)
|
rspMsg, err = s.CallByTopic(service.RpcTopicEx(node.Name), timeout, rpcMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF(s.Log("call rpc:%v err:%s ", rpcMsg.RpcMsgId, err.Error()))
|
log.ErrorF(s.Log("call rpc:%v err:%s ", rpcMsg.RpcMsgId, err.Error()))
|
||||||
return nil, pb.ErrCode_SystemErr, node
|
return nil, pb.ErrCode_SystemErr, node
|
||||||
@ -107,7 +108,7 @@ func generateToken(userID int64, username string) (string, error) {
|
|||||||
|
|
||||||
// 获取用户数据,如果没有则创建
|
// 获取用户数据,如果没有则创建
|
||||||
func (s *LoginService) getUser(accountId int64) (*user.User, pb.ErrCode) {
|
func (s *LoginService) getUser(accountId int64) (*user.User, pb.ErrCode) {
|
||||||
node, err := s.bindService.HashServiceNode(pb.ServiceTypeId_STI_DB, xrand.RandN[int64](100))
|
node, err := s.BindService().HashServiceNode(pb.ServiceTypeId_STI_DB, xrand.RandN[int64](100))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF(s.Log("not find db service.err:%s ", err.Error()))
|
log.ErrorF(s.Log("not find db service.err:%s ", err.Error()))
|
||||||
return nil, pb.ErrCode_SystemErr
|
return nil, pb.ErrCode_SystemErr
|
||||||
@ -116,7 +117,7 @@ func (s *LoginService) getUser(accountId int64) (*user.User, pb.ErrCode) {
|
|||||||
AccountId: accountId,
|
AccountId: accountId,
|
||||||
}
|
}
|
||||||
rpcMsg := ipb.MakeRpcMsg(rpc.GetUserByAccountId, 0, us)
|
rpcMsg := ipb.MakeRpcMsg(rpc.GetUserByAccountId, 0, us)
|
||||||
rsp, err := s.Call(service.RpcTopicEx(node.Name), timeout, rpcMsg)
|
rsp, err := s.CallByServiceId(int(pb.ServiceTypeId_STI_DB), timeout, rpcMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF(s.Log("call src:%v rpc:%v err:%s", node.Name, rpcMsg.RpcMsgId, err.Error()))
|
log.ErrorF(s.Log("call src:%v rpc:%v err:%s", node.Name, rpcMsg.RpcMsgId, err.Error()))
|
||||||
return nil, pb.ErrCode_SystemErr
|
return nil, pb.ErrCode_SystemErr
|
||||||
@ -151,7 +152,10 @@ func (s *LoginService) onLoginOrRegister(iMsg *ipb.InternalMsg, req *pb.ReqUserL
|
|||||||
rsp.Code = code
|
rsp.Code = code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, userId, int32(pb.MsgId_RspUserLoginId), rsp)
|
topic := service.TopicEx(iMsg.ServiceName)
|
||||||
|
log.DebugF("send to:%v msg id:%v, msg:%v", topic, pb.MsgId_RspUserLoginId, rsp.String())
|
||||||
|
data, _ := proto.Marshal(rsp)
|
||||||
|
s.SendServiceData(topic, iMsg.ConnId, userId, int32(pb.MsgId_RspUserLoginId), data)
|
||||||
|
|
||||||
if account != nil && account.ID > 0 {
|
if account != nil && account.ID > 0 {
|
||||||
loginLog := &user.UserLoginLog{
|
loginLog := &user.UserLoginLog{
|
||||||
@ -166,7 +170,7 @@ func (s *LoginService) onLoginOrRegister(iMsg *ipb.InternalMsg, req *pb.ReqUserL
|
|||||||
case pb.ErrCode_LoginUserOrPwdErr, pb.ErrCode_OK:
|
case pb.ErrCode_LoginUserOrPwdErr, pb.ErrCode_OK:
|
||||||
rpcMsg := ipb.MakeRpcMsg(rpc.LogUserAccountLogin, 0, loginLog)
|
rpcMsg := ipb.MakeRpcMsg(rpc.LogUserAccountLogin, 0, loginLog)
|
||||||
ksync.GoSafe(func() {
|
ksync.GoSafe(func() {
|
||||||
_, _ = s.Call(service.RpcTopicEx(node.Name), timeout, rpcMsg)
|
_, _ = s.CallByTopic(service.RpcTopicEx(node.Name), timeout, rpcMsg)
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user