33 lines
1002 B
Go
33 lines
1002 B
Go
package rpc
|
|
|
|
import (
|
|
"encoding/json"
|
|
"game/common/model/user"
|
|
"game/common/proto/pb"
|
|
"game/common/userBindService"
|
|
"github.com/fox/fox/ipb"
|
|
"github.com/fox/fox/log"
|
|
"github.com/fox/fox/service"
|
|
)
|
|
|
|
// 添加玩家资源,负数为减少
|
|
func RpcAddUserRes(bindService *userBindService.UserBindService, s service.IService, uid int64, addUserRes *user.AddUserRes) (map[string]int64, pb.ErrCode) {
|
|
node, err := bindService.HashServiceNode(pb.ServiceTypeId_STI_DB, uid)
|
|
if err != nil {
|
|
log.ErrorF("db service node error:%v", err)
|
|
return nil, pb.ErrCode_SystemErr
|
|
}
|
|
rpcMsg := ipb.MakeRpcMsg(AddUserResources, uid, addUserRes)
|
|
rspMsg, err := s.CallByTopic(service.RpcTopicEx(node.Name), 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 {
|
|
res := map[string]int64{}
|
|
_ = json.Unmarshal(rspMsg.Msg, &res)
|
|
return res, pb.ErrCode_OK
|
|
}
|
|
return nil, pb.ErrCode(rspMsg.RpcCode)
|
|
}
|