game/common/rpc/rpcGameUser.go

59 lines
1.4 KiB
Go
Raw Normal View History

2025-06-07 23:22:09 +08:00
package rpc
import (
"encoding/json"
"game/common/model/user"
"game/common/proto/pb"
"github.com/fox/fox/ipb"
"github.com/fox/fox/log"
"github.com/fox/fox/service"
"time"
)
const (
timeout = time.Second * 30
)
// 获取玩家数据
2025-06-17 00:00:19 +08:00
func RpcGetGameUser(s service.IService, uid int64) (*user.GameUser, pb.ErrCode) {
2025-06-07 23:22:09 +08:00
us := &user.GameUser{
User: user.User{
ID: uid,
},
UserResources: user.UserResources{
UID: uid,
},
}
2025-06-15 11:25:51 +08:00
rpcMsg := ipb.MakeRpcMsg(GetGameUser, uid, us)
2025-06-17 18:22:26 +08:00
log.DebugF("%v call rpc:%v", s.Name(), GetGameUser)
2025-06-17 00:00:19 +08:00
rspMsg, err := s.CallByServiceId(int(pb.ServiceTypeId_STI_DB), timeout, rpcMsg)
2025-06-07 23:22:09 +08:00
if err != nil {
log.ErrorF("call rpc:%v err:%s ", rpcMsg.RpcMsgId, err.Error())
return nil, pb.ErrCode_SystemErr
}
2025-06-14 16:40:15 +08:00
if rspMsg.RpcCode == 0 {
_ = json.Unmarshal(rspMsg.Msg, us)
return us, pb.ErrCode_OK
}
2025-06-16 00:50:42 +08:00
return nil, pb.ErrCode(rspMsg.RpcCode)
2025-06-07 23:22:09 +08:00
}
// 获取玩家数据
func RpcGetAccountByUid(s service.IService, uid int64) (*user.UserAccount, pb.ErrCode) {
us := &user.UserAccount{
ID: uid,
}
rpcMsg := ipb.MakeRpcMsg(GetUserAccountById, uid, us)
log.DebugF("%v call rpc:%v", s.Name(), GetUserAccountById)
rspMsg, err := s.CallByServiceId(int(pb.ServiceTypeId_STI_DB), timeout, rpcMsg)
if err != nil {
log.ErrorF("call rpc:%v err:%s ", rpcMsg.RpcMsgId, err.Error())
return nil, pb.ErrCode_SystemErr
}
if rspMsg.RpcCode == 0 {
_ = json.Unmarshal(rspMsg.Msg, us)
return us, pb.ErrCode_OK
}
return nil, pb.ErrCode(rspMsg.RpcCode)
}