数据层接口修改

This commit is contained in:
zhaocy 2022-06-16 18:27:19 +08:00
parent 6149c29e86
commit 67190818ae
24 changed files with 652 additions and 572 deletions

View File

@ -30,7 +30,7 @@ func (r *Robot) handleFriendMsg(msg *pb.UserMessage) {
//好友列表 //好友列表
func (r *Robot) FriendList() { func (r *Robot) FriendList() {
req := &pb.FriendListReq{} req := &pb.Friend_List_Req{}
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_List} head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_List}
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req) defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
err := r.SendToClient(head, req) err := r.SendToClient(head, req)
@ -40,7 +40,7 @@ func (r *Robot) FriendList() {
} }
func (r *Robot) handleFriendList(msg *pb.UserMessage) { func (r *Robot) handleFriendList(msg *pb.UserMessage) {
rsp := &pb.FriendListRsp{} rsp := &pb.Friend_List_Rsp{}
if !comm.ProtoDecode(msg, rsp) { if !comm.ProtoDecode(msg, rsp) {
return return
} }
@ -49,7 +49,7 @@ func (r *Robot) handleFriendList(msg *pb.UserMessage) {
//好友搜索 //好友搜索
func (r *Robot) FriendSearch(nickName string) { func (r *Robot) FriendSearch(nickName string) {
req := &pb.FriendSearchReq{ req := &pb.Friend_Search_Req{
NickName: nickName, NickName: nickName,
} }
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Search} head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Search}
@ -61,7 +61,7 @@ func (r *Robot) FriendSearch(nickName string) {
} }
func (r *Robot) handleFriendSearch(msg *pb.UserMessage) { func (r *Robot) handleFriendSearch(msg *pb.UserMessage) {
rsp := &pb.FriendSearchRsp{} rsp := &pb.Friend_Search_Rsp{}
if !comm.ProtoDecode(msg, rsp) { if !comm.ProtoDecode(msg, rsp) {
return return
} }
@ -70,7 +70,7 @@ func (r *Robot) handleFriendSearch(msg *pb.UserMessage) {
//好友申请 //好友申请
func (r *Robot) FriendApply(friendId string) { func (r *Robot) FriendApply(friendId string) {
req := &pb.FriendApplyReq{ req := &pb.Friend_Apply_Req{
FriendId: friendId, FriendId: friendId,
} }
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Apply} head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Apply}
@ -82,7 +82,7 @@ func (r *Robot) FriendApply(friendId string) {
} }
func (r *Robot) handleFriendApply(msg *pb.UserMessage) { func (r *Robot) handleFriendApply(msg *pb.UserMessage) {
rsp := &pb.FriendApplyRsp{} rsp := &pb.Friend_Apply_Rsp{}
if !comm.ProtoDecode(msg, rsp) { if !comm.ProtoDecode(msg, rsp) {
return return
} }
@ -91,7 +91,7 @@ func (r *Robot) handleFriendApply(msg *pb.UserMessage) {
//申请列表 //申请列表
func (r *Robot) FriendApplyList() { func (r *Robot) FriendApplyList() {
req := &pb.FriendApplyListReq{} req := &pb.Friend_ApplyList_Req{}
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_ApplyList} head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_ApplyList}
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req) defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
err := r.SendToClient(head, req) err := r.SendToClient(head, req)
@ -101,7 +101,7 @@ func (r *Robot) FriendApplyList() {
} }
func (r *Robot) handleFriendApplyList(msg *pb.UserMessage) { func (r *Robot) handleFriendApplyList(msg *pb.UserMessage) {
rsp := &pb.FriendApplyListRsp{} rsp := &pb.Friend_ApplyList_Rsp{}
if !comm.ProtoDecode(msg, rsp) { if !comm.ProtoDecode(msg, rsp) {
return return
} }
@ -110,7 +110,7 @@ func (r *Robot) handleFriendApplyList(msg *pb.UserMessage) {
//同意 //同意
func (r *Robot) FriendAgree(friendIds []string) { func (r *Robot) FriendAgree(friendIds []string) {
req := &pb.FriendAgreeReq{ req := &pb.Friend_Agree_Req{
FriendIds: friendIds, FriendIds: friendIds,
} }
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Agree} head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Agree}
@ -122,7 +122,7 @@ func (r *Robot) FriendAgree(friendIds []string) {
} }
func (r *Robot) handleFriendAgree(msg *pb.UserMessage) { func (r *Robot) handleFriendAgree(msg *pb.UserMessage) {
rsp := &pb.FriendAgreeRsp{} rsp := &pb.Friend_Agree_Rsp{}
if !comm.ProtoDecode(msg, rsp) { if !comm.ProtoDecode(msg, rsp) {
return return
} }
@ -131,7 +131,7 @@ func (r *Robot) handleFriendAgree(msg *pb.UserMessage) {
//拒绝 //拒绝
func (r *Robot) FriendRefuse(friendIds []string) { func (r *Robot) FriendRefuse(friendIds []string) {
req := &pb.FriendRefuseReq{ req := &pb.Friend_Refuse_Req{
FriendIds: friendIds, FriendIds: friendIds,
} }
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Refuse} head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Refuse}
@ -143,7 +143,7 @@ func (r *Robot) FriendRefuse(friendIds []string) {
} }
func (r *Robot) handleFriendRefuse(msg *pb.UserMessage) { func (r *Robot) handleFriendRefuse(msg *pb.UserMessage) {
rsp := &pb.FriendRefuseRsp{} rsp := &pb.Friend_Refuse_Rsp{}
if !comm.ProtoDecode(msg, rsp) { if !comm.ProtoDecode(msg, rsp) {
return return
} }
@ -152,7 +152,7 @@ func (r *Robot) handleFriendRefuse(msg *pb.UserMessage) {
//黑名单列表 //黑名单列表
func (r *Robot) FriendBlacklist() { func (r *Robot) FriendBlacklist() {
req := &pb.FriendBlackListReq{} req := &pb.Friend_BlackList_Req{}
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Blacklist} head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Blacklist}
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req) defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
err := r.SendToClient(head, req) err := r.SendToClient(head, req)
@ -162,7 +162,7 @@ func (r *Robot) FriendBlacklist() {
} }
func (r *Robot) handleFriendBlacklist(msg *pb.UserMessage) { func (r *Robot) handleFriendBlacklist(msg *pb.UserMessage) {
rsp := &pb.FriendBlackListRsp{} rsp := &pb.Friend_BlackList_Rsp{}
if !comm.ProtoDecode(msg, rsp) { if !comm.ProtoDecode(msg, rsp) {
return return
} }
@ -171,7 +171,7 @@ func (r *Robot) handleFriendBlacklist(msg *pb.UserMessage) {
//添加黑名单 //添加黑名单
func (r *Robot) FriendAddBlack() { func (r *Robot) FriendAddBlack() {
req := &pb.FriendBlackAddReq{} req := &pb.Friend_BlackAdd_Req{}
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_AddBlack} head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_AddBlack}
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req) defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
err := r.SendToClient(head, req) err := r.SendToClient(head, req)
@ -181,7 +181,7 @@ func (r *Robot) FriendAddBlack() {
} }
func (r *Robot) handleFriendAddBlack(msg *pb.UserMessage) { func (r *Robot) handleFriendAddBlack(msg *pb.UserMessage) {
rsp := &pb.FriendBlackAddRsp{} rsp := &pb.Friend_BlackAdd_Rsp{}
if !comm.ProtoDecode(msg, rsp) { if !comm.ProtoDecode(msg, rsp) {
return return
} }
@ -190,7 +190,7 @@ func (r *Robot) handleFriendAddBlack(msg *pb.UserMessage) {
//删除黑名单 //删除黑名单
func (r *Robot) FriendDelBlack(friendId string) { func (r *Robot) FriendDelBlack(friendId string) {
req := &pb.FriendDelBlackReq{ req := &pb.Friend_DelBlack_Req{
FriendId: friendId, FriendId: friendId,
} }
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_DelBlack} head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_DelBlack}
@ -202,7 +202,7 @@ func (r *Robot) FriendDelBlack(friendId string) {
} }
func (r *Robot) handleFriendDelBlack(msg *pb.UserMessage) { func (r *Robot) handleFriendDelBlack(msg *pb.UserMessage) {
rsp := &pb.FriendDelBlackRsp{} rsp := &pb.Friend_DelBlack_Rsp{}
if !comm.ProtoDecode(msg, rsp) { if !comm.ProtoDecode(msg, rsp) {
return return
} }

View File

@ -49,5 +49,5 @@ func (r *Robot) AccountLogin() {
log.Fatalf("send err:%v", err) log.Fatalf("send err:%v", err)
} }
log.Printf("account:[%s] login...", r.opts.Account) log.Printf("区服:[%d] 账号:[%s] login...", r.opts.ServerId, r.opts.Account)
} }

View File

@ -41,6 +41,9 @@ func (r *Robot) Run() {
if r.opts.Create { //创建新用户 if r.opts.Create { //创建新用户
r.AccountRegister(r.opts.Account, int32(r.opts.ServerId)) r.AccountRegister(r.opts.Account, int32(r.opts.ServerId))
} else { } else {
if r.opts.Account == "" {
log.Fatal("WARNNING: account is required !!!")
}
r.AccountLogin() r.AccountLogin()
} }

View File

@ -159,9 +159,14 @@ func Test_Redis_Type(t *testing.T) {
} }
} }
type TestAny struct {
SubName string `json:"subname"`
Age int32 `json:"age"`
}
type TestData struct { type TestData struct {
Name string `json:"name"` Name string `json:"name"`
Agr int `json:"agr"` Agr int `json:"agr"`
Sub *TestAny `json:"sub"`
} }
func Test_Redis_Encoder_Struct(t *testing.T) { func Test_Redis_Encoder_Struct(t *testing.T) {
@ -177,15 +182,20 @@ func Test_Redis_Encoder_int(t *testing.T) {
} }
func Test_Redis_Encoder_Hash(t *testing.T) { func Test_Redis_Encoder_Hash(t *testing.T) {
// err := redis.HMSet("test:1003", &TestData{Name: "liwei1dao", Agr: 12}) // err := redis.HMSet("test:1005", &TestData{Name: "liwei1dao", Agr: 12, Sub: &TestAny{SubName: "test", Age: 20}})
// fmt.Printf("err:%v\n", err) // fmt.Printf("err:%v\n", err)
data := &TestData{}
err := redis.HGetAll("test:1003", data)
fmt.Printf("data:%v err:%v\n", data, err)
// name := "" // data := &TestData{}
// err := redis.HGet("test:1003", "Name", &name) // err = redis.HGetAll("test:1005", data)
// fmt.Printf("name:%v err:%v", name, err) // fmt.Printf("data:%v err:%v\n", data, err)
// redis.HSet("test:1003", "Name", "eeee")
name := ""
err := redis.HGet("test:1003", "Name", &name)
if err != nil {
fmt.Println(err)
}
fmt.Println(name)
// data1 := map[string]*TestData{"li_1": {Name: "liwei2dao", Agr: 56}, "li_2": {Name: "liwei3dao", Agr: 78}} // data1 := map[string]*TestData{"li_1": {Name: "liwei2dao", Agr: 56}, "li_2": {Name: "liwei3dao", Agr: 78}}
// err := redis.HMSet("test:1004", data1) // err := redis.HMSet("test:1004", data1)

View File

@ -6,23 +6,23 @@ import (
"go_dreamfactory/utils" "go_dreamfactory/utils"
) )
func (this *ApiComp) Addblack_Check(session comm.IUserSession, req *pb.FriendBlackAddReq) (result map[string]interface{}, code pb.ErrorCode) { func (this *ApiComp) Addblack_Check(session comm.IUserSession, req *pb.Friend_BlackAdd_Req) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }
//加入黑名单 //加入黑名单
func (this *ApiComp) Addblack(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendBlackAddReq) (err error) { func (this *ApiComp) Addblack(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_BlackAdd_Req) (err error) {
var ( var (
code pb.ErrorCode code pb.ErrorCode
self *pb.DB_FriendData self *pb.DB_FriendData
target *pb.DB_FriendData target *pb.DB_FriendData
rsp *pb.FriendBlackAddRsp rsp *pb.Friend_BlackAdd_Rsp
blackNumMax = 50 //TODO 从配置中读取 blackNumMax = 50 //TODO 从配置中读取
) )
defer func() { defer func() {
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
rsp = &pb.FriendBlackAddRsp{ rsp = &pb.Friend_BlackAdd_Rsp{
FriendId: req.FriendId, FriendId: req.FriendId,
UserId: session.GetUserId(), UserId: session.GetUserId(),
} }
@ -64,6 +64,10 @@ func (this *ApiComp) Addblack(session comm.IUserSession, chk map[string]interfac
self.BlackIds = append(self.BlackIds, req.FriendId) self.BlackIds = append(self.BlackIds, req.FriendId)
//更新黑名单 //更新黑名单
this.module.model_friend.SetObj(self.UserId, self, false, true) err = this.module.model_friend.SetObj(self.UserId, self)
if err != nil {
code = pb.ErrorCode_DBError
return
}
return return
} }

View File

@ -6,7 +6,7 @@ import (
"go_dreamfactory/utils" "go_dreamfactory/utils"
) )
func (this *ApiComp) Agree_Check(session comm.IUserSession, req *pb.FriendAgreeReq) (chk map[string]interface{}, code pb.ErrorCode) { func (this *ApiComp) Agree_Check(session comm.IUserSession, req *pb.Friend_Agree_Req) (chk map[string]interface{}, code comm.ErrorCode) {
chk = make(map[string]interface{}) chk = make(map[string]interface{})
var err error var err error
self := &pb.DB_FriendData{UserId: session.GetUserId()} self := &pb.DB_FriendData{UserId: session.GetUserId()}
@ -14,7 +14,7 @@ func (this *ApiComp) Agree_Check(session comm.IUserSession, req *pb.FriendAgreeR
//获取玩家自己好友数据 //获取玩家自己好友数据
err = this.module.model_friend.GetObj(session.GetUserId(), self) err = this.module.model_friend.GetObj(session.GetUserId(), self)
if self == nil || err != nil { if self == nil || err != nil {
code = pb.ErrorCode_FriendSelfNoData code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return return
} }
@ -34,16 +34,16 @@ func (this *ApiComp) Agree_Check(session comm.IUserSession, req *pb.FriendAgreeR
} }
//单个/批量同意 //单个/批量同意
func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendAgreeReq) (code pb.ErrorCode) { func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Agree_Req) (code pb.ErrorCode) {
var ( var (
self *pb.DB_FriendData self *pb.DB_FriendData
rsp *pb.FriendAgreeRsp rsp *pb.Friend_Agree_Rsp
optNum int32 optNum int32
) )
defer func() { defer func() {
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
rsp = &pb.FriendAgreeRsp{ rsp = &pb.Friend_Agree_Rsp{
Num: optNum, Num: optNum,
} }
} }
@ -80,7 +80,7 @@ func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}
} }
target.FriendIds = append(target.FriendIds, self.UserId) target.FriendIds = append(target.FriendIds, self.UserId)
} }
err = this.module.model_friend.SetObj(target.UserId, target, false, true) err = this.module.model_friend.SetObj(target.UserId, target)
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
} }
@ -91,7 +91,7 @@ func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}
} }
//更新 //更新
err := this.module.model_friend.SetObj(self.UserId, self, false, true) err := this.module.model_friend.SetObj(self.UserId, self)
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return

View File

@ -7,7 +7,7 @@ import (
"go_dreamfactory/utils" "go_dreamfactory/utils"
) )
func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.FriendApplyReq) (chk map[string]interface{}, code pb.ErrorCode) { func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.Friend_Apply_Req) (chk map[string]interface{}, code comm.ErrorCode) {
chk = make(map[string]interface{}) chk = make(map[string]interface{})
var err error var err error
self := &pb.DB_FriendData{UserId: session.GetUserId()} self := &pb.DB_FriendData{UserId: session.GetUserId()}
@ -16,20 +16,20 @@ func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.FriendApplyR
//获取玩家自己好友数据 //获取玩家自己好友数据
err = this.module.model_friend.GetObj(session.GetUserId(), self) err = this.module.model_friend.GetObj(session.GetUserId(), self)
if self == nil || err != nil { if self == nil || err != nil {
code = pb.ErrorCode_FriendSelfNoData code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return return
} }
//获取好友数据 //获取好友数据
err = this.module.model_friend.GetObj(req.FriendId, target) err = this.module.model_friend.GetObj(req.FriendId, target)
if target == nil || err != nil { if target == nil || err != nil {
code = pb.ErrorCode_FriendTargetNoData code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetNoData}
return return
} }
//判断是否是自己 //判断是否是自己
if req.FriendId == session.GetUserId() { if req.FriendId == session.GetUserId() {
code = pb.ErrorCode_FriendNotSelf code = comm.ErrorCode{Code: pb.ErrorCode_FriendNotSelf}
return return
} }
@ -38,38 +38,38 @@ func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.FriendApplyR
var max int = 50 var max int = 50
total := len(self.FriendIds) total := len(self.FriendIds)
if total >= max { if total >= max {
code = pb.ErrorCode_FriendSelfMax code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfMax}
return return
} }
//判断对方是否也超过最大好友数量 //判断对方是否也超过最大好友数量
ttotal := len(target.FriendIds) ttotal := len(target.FriendIds)
if ttotal >= max { if ttotal >= max {
code = pb.ErrorCode_FriendTargetMax code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetMax}
return return
} }
//判断是否是好友 //判断是否是好友
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok { if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
code = pb.ErrorCode_FriendYet code = comm.ErrorCode{Code: pb.ErrorCode_FriendYet}
return return
} }
//判断自己是否在目标用户的申请列表中 //判断自己是否在目标用户的申请列表中
if _, ok := utils.Find(target.ApplyIds, self.UserId); ok { if _, ok := utils.Find(target.ApplyIds, self.UserId); ok {
code = pb.ErrorCode_FriendApplyYet code = comm.ErrorCode{Code: pb.ErrorCode_FriendApplyYet}
return return
} }
//判断目标用户是否在黑名单中 //判断目标用户是否在黑名单中
if _, ok := utils.Find(self.BlackIds, req.FriendId); ok { if _, ok := utils.Find(self.BlackIds, req.FriendId); ok {
code = pb.ErrorCode_FriendSelfBlackYet code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfBlackYet}
return return
} }
//判断是否在对方的黑名单中 //判断是否在对方的黑名单中
if _, ok := utils.Find(target.BlackIds, self.UserId); ok { if _, ok := utils.Find(target.BlackIds, self.UserId); ok {
code = pb.ErrorCode_FriendTargetBlackYet code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetBlackYet}
return return
} }
@ -79,10 +79,10 @@ func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.FriendApplyR
} }
//好友申请 //好友申请
func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendApplyReq) (code pb.ErrorCode) { func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Apply_Req) (code pb.ErrorCode) {
var ( var (
target *pb.DB_FriendData target *pb.DB_FriendData
rsp *pb.FriendApplyRsp rsp *pb.Friend_Apply_Rsp
) )
defer func() { defer func() {
@ -91,7 +91,7 @@ func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{}
defer func() { defer func() {
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
rsp = &pb.FriendApplyRsp{ rsp = &pb.Friend_Apply_Rsp{
UserId: session.GetUserId(), UserId: session.GetUserId(),
FriendId: req.FriendId, FriendId: req.FriendId,
} }
@ -112,8 +112,7 @@ func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{}
} }
target.ApplyIds = append(target.ApplyIds, session.GetUserId()) target.ApplyIds = append(target.ApplyIds, session.GetUserId())
err := this.module.model_friend.SetObj(req.FriendId, target, false, true) err := this.module.model_friend.SetObj(req.FriendId, target)
if err != nil { if err != nil {
log.Errorf("firend Apply err:%v", err) log.Errorf("firend Apply err:%v", err)
code = pb.ErrorCode_FriendApplyError code = pb.ErrorCode_FriendApplyError

View File

@ -5,21 +5,21 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
func (this *ApiComp) ApplyList_Check(session comm.IUserSession, req *pb.FriendApplyListReq) (chk map[string]interface{}, code pb.ErrorCode) { func (this *ApiComp) ApplyList_Check(session comm.IUserSession, req *pb.Friend_ApplyList_Req) (chk map[string]interface{}, code comm.ErrorCode) {
return return
} }
//申请列表 //申请列表
func (this *ApiComp) ApplyList(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendApplyListReq) (code pb.ErrorCode) { func (this *ApiComp) ApplyList(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_ApplyList_Req) (code pb.ErrorCode) {
var ( var (
self *pb.DB_FriendData self *pb.DB_FriendData
rsp *pb.FriendApplyListRsp rsp *pb.Friend_ApplyList_Rsp
list []*pb.FriendBase list []*pb.FriendBase
) )
defer func() { defer func() {
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
rsp = &pb.FriendApplyListRsp{ rsp = &pb.Friend_ApplyList_Rsp{
List: list, List: list,
} }
} }

View File

@ -5,21 +5,21 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
func (this *ApiComp) Blacklist_Check(session comm.IUserSession, req *pb.FriendBlackListReq) (chk map[string]interface{}, code pb.ErrorCode) { func (this *ApiComp) Blacklist_Check(session comm.IUserSession, req *pb.Friend_BlackList_Req) (chk map[string]interface{}, code comm.ErrorCode) {
return return
} }
//黑名单 //黑名单
func (this *ApiComp) Blacklist(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendBlackListReq) (code pb.ErrorCode) { func (this *ApiComp) Blacklist(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_BlackList_Req) (code pb.ErrorCode) {
var ( var (
self *pb.DB_FriendData self *pb.DB_FriendData
rsp *pb.FriendBlackListRsp rsp *pb.Friend_BlackList_Rsp
list []*pb.FriendBase list []*pb.FriendBase
) )
defer func() { defer func() {
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
rsp = &pb.FriendBlackListRsp{ rsp = &pb.Friend_BlackList_Rsp{
Friends: list, Friends: list,
} }
} }

View File

@ -5,11 +5,11 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
func (this *ApiComp) Del_Check(session comm.IUserSession, req *pb.FriendDelReq) (chk map[string]interface{}, code pb.ErrorCode) { func (this *ApiComp) Del_Check(session comm.IUserSession, req *pb.Friend_Del_Req) (chk map[string]interface{}, code comm.ErrorCode) {
return return
} }
//删除好友 //删除好友
func (this *ApiComp) Del(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendDelReq) error { func (this *ApiComp) Del(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Del_Req) error {
return nil return nil
} }

View File

@ -6,19 +6,19 @@ import (
"go_dreamfactory/utils" "go_dreamfactory/utils"
) )
func (this *ApiComp) Delblack_Check(session comm.IUserSession, req *pb.FriendDelBlackReq) (chk map[string]interface{}, code pb.ErrorCode) { func (this *ApiComp) Delblack_Check(session comm.IUserSession, req *pb.Friend_DelBlack_Req) (chk map[string]interface{}, code comm.ErrorCode) {
return return
} }
//删除黑名单 //删除黑名单
func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendDelBlackReq) (code pb.ErrorCode) { func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_DelBlack_Req) (code pb.ErrorCode) {
var ( var (
self *pb.DB_FriendData self *pb.DB_FriendData
rsp *pb.FriendDelBlackRsp rsp *pb.Friend_DelBlack_Rsp
) )
defer func() { defer func() {
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
rsp = &pb.FriendDelBlackRsp{ rsp = &pb.Friend_DelBlack_Rsp{
FriendId: req.FriendId, FriendId: req.FriendId,
UserId: session.GetUserId(), UserId: session.GetUserId(),
} }
@ -34,7 +34,7 @@ func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interfac
//从黑名单列表中删除目标 //从黑名单列表中删除目标
self.BlackIds = utils.DeleteString(self.BlackIds, req.FriendId) self.BlackIds = utils.DeleteString(self.BlackIds, req.FriendId)
//更新黑名单 //更新黑名单
err = this.module.model_friend.SetObj(self.UserId, self, false, true) err = this.module.model_friend.SetObj(self.UserId, self)
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return

View File

@ -5,21 +5,21 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
func (this *ApiComp) List_Check(session comm.IUserSession, req *pb.FriendListReq) (chk map[string]interface{}, code pb.ErrorCode) { func (this *ApiComp) List_Check(session comm.IUserSession, req *pb.Friend_List_Req) (chk map[string]interface{}, code comm.ErrorCode) {
return return
} }
//好友列表 //好友列表
func (this *ApiComp) List(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendListReq) (code pb.ErrorCode) { func (this *ApiComp) List(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_List_Req) (code pb.ErrorCode) {
var ( var (
self *pb.DB_FriendData self *pb.DB_FriendData
rsp *pb.FriendListRsp rsp *pb.Friend_List_Rsp
list []*pb.FriendBase list []*pb.FriendBase
) )
defer func() { defer func() {
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
rsp = &pb.FriendListRsp{ rsp = &pb.Friend_List_Rsp{
List: list, List: list,
} }
} }

View File

@ -6,7 +6,7 @@ import (
"go_dreamfactory/utils" "go_dreamfactory/utils"
) )
func (this *ApiComp) Refuse_Check(session comm.IUserSession, req *pb.FriendRefuseReq) (chk map[string]interface{}, code pb.ErrorCode) { func (this *ApiComp) Refuse_Check(session comm.IUserSession, req *pb.Friend_Refuse_Req) (chk map[string]interface{}, code comm.ErrorCode) {
chk = make(map[string]interface{}) chk = make(map[string]interface{})
var err error var err error
self := &pb.DB_FriendData{UserId: session.GetUserId()} self := &pb.DB_FriendData{UserId: session.GetUserId()}
@ -14,7 +14,7 @@ func (this *ApiComp) Refuse_Check(session comm.IUserSession, req *pb.FriendRefus
//获取玩家自己好友数据 //获取玩家自己好友数据
err = this.module.model_friend.GetObj(session.GetUserId(), self) err = this.module.model_friend.GetObj(session.GetUserId(), self)
if self == nil || err != nil { if self == nil || err != nil {
code = pb.ErrorCode_FriendSelfNoData code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return return
} }
@ -33,19 +33,18 @@ func (this *ApiComp) Refuse_Check(session comm.IUserSession, req *pb.FriendRefus
} }
//单个/批量拒绝 //单个/批量拒绝
func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendRefuseReq) (code pb.ErrorCode) { func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Refuse_Req) (code pb.ErrorCode) {
//将申请人从申请列表中删除 //将申请人从申请列表中删除
var ( var (
self *pb.DB_FriendData self *pb.DB_FriendData
rsp *pb.FriendAgreeRsp rsp *pb.Friend_Refuse_Rsp
optNum int32 optNum int32
) )
defer func() { defer func() {
if code == pb.ErrorCode_Success { rsp = &pb.Friend_Refuse_Rsp{
rsp = &pb.FriendAgreeRsp{ Num: optNum,
Num: optNum,
}
} }
session.SendMsg(string(this.module.GetType()), Friend_SubType_Refuse, rsp) session.SendMsg(string(this.module.GetType()), Friend_SubType_Refuse, rsp)
}() }()
@ -63,7 +62,7 @@ func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{
} }
//更新 //更新
if optNum > 0 { if optNum > 0 {
err := this.module.model_friend.SetObj(self.UserId, self, false, true) err := this.module.model_friend.SetObj(self.UserId, self)
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return

View File

@ -5,23 +5,23 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
func (this *ApiComp) Search_Check(session comm.IUserSession, req *pb.FriendSearchReq) (chk map[string]interface{}, code pb.ErrorCode) { func (this *ApiComp) Search_Check(session comm.IUserSession, req *pb.Friend_Search_Req) (chk map[string]interface{}, code comm.ErrorCode) {
return return
} }
//搜索 //搜索
func (this *ApiComp) Search(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendSearchReq) (code pb.ErrorCode) { func (this *ApiComp) Search(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Search_Req) (code pb.ErrorCode) {
var ( var (
rsp *pb.FriendSearchRsp rsp *pb.Friend_Search_Rsp
friend *pb.FriendBase friend *pb.FriendBase
) )
defer func() { defer func() {
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
rsp = &pb.FriendSearchRsp{ rsp = &pb.Friend_Search_Rsp{
Friend: friend, Friend: friend,
} }
} }
session.SendMsg(string(this.module.GetType()), Friend_SubType_Search, rsp) session.SendMsg(string(this.module.GetType()), Friend_SubType_Search, rsp)
}() }()
user := this.module.model_friend.Frined_FindCond(req.NickName) user := this.module.model_friend.Frined_FindCond(req.NickName)

View File

@ -7,7 +7,7 @@ import (
) )
//参数校验 //参数校验
func (this *Api_Comp) DelUserMailReq_Check(session comm.IUserSession, req *pb.Mail_DelMail_Req) (result map[string]interface{}, code pb.ErrorCode) { func (this *Api_Comp) DelUserMailReq_Check(session comm.IUserSession, req *pb.Mail_DelMail_Req) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }

View File

@ -10,7 +10,6 @@ import (
"go_dreamfactory/lego/sys/redis" "go_dreamfactory/lego/sys/redis"
"go_dreamfactory/sys/cache" "go_dreamfactory/sys/cache"
"go_dreamfactory/sys/db" "go_dreamfactory/sys/db"
"reflect"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
@ -100,21 +99,30 @@ func (this *Model_Comp) UpdateModelLogs(table string, uID string, where bson.M,
} }
//设置缓存JSON格式数据 //设置缓存JSON格式数据
func (this *Model_Comp) SetObj(uid string, data proto.Message, isnew, islog bool) error { //data 值允许protobuf格式的对象
// attrs 操作可选项目 eg.传入WithDisabledMgoLog() 表示关闭日志,否则开启;WithND() 传入表示插入操作不传表示更新前提不能传入传入WithDisabledMgoLog()
func (this *Model_Comp) SetObj(uid string, data proto.Message, attrs ...*cache.OperationAttr) error {
err := this.Redis.Set(fmt.Sprintf("%s:%s", this.TableName, uid), data, 0) err := this.Redis.Set(fmt.Sprintf("%s:%s", this.TableName, uid), data, 0)
if err != nil { if err != nil {
log.Errorf("set err:%v", err) log.Errorf("set err:%v", err)
return err return err
} }
if islog { return this.logOpt(uid, data, attrs...)
if isnew { }
return this.InsertModelLogs(this.TableName, uid, data)
} else { //cache hashmap data参数 允许map或protobuf
return this.UpdateModelLogs(this.TableName, uid, bson.M{"uid": uid}, data) //eg.map[string]*TestData{"li_1": {Name: "liwei2dao", Agr: 56}, "li_2": {Name: "liwei3dao", Agr: 78}}
} //or &TestData{Name: "liwei1dao", Agr: 12, Sub: &TestAny{SubName: "test", Age: 20}}
// attrs 操作可选项目 eg.传入WithDisabledMgoLog() 表示关闭日志,否则开启;WithND() 传入表示插入操作不传表示更新前提不能传入传入WithDisabledMgoLog()
func (this *Model_Comp) SetHM(uid string, data interface{}, attrs ...*cache.OperationAttr) error {
err := this.Redis.HMSet(fmt.Sprintf("%s:%s", this.TableName, uid), data)
if err != nil {
log.Errorf("HMSet err: %v", err)
return err
} }
return nil
return this.logOpt(uid, data, attrs...)
} }
//更新缓存字段 //更新缓存字段
@ -152,7 +160,7 @@ func (this *Model_Comp) GetObj(uid string, v proto.Message) error {
return err return err
} }
//set cache //set cache
return this.SetObj(uid, v, true, false) return this.SetObj(uid, v, cache.WithND())
} }
} }
} else { } else {
@ -163,11 +171,12 @@ func (this *Model_Comp) GetObj(uid string, v proto.Message) error {
} }
//获取对象数据 //获取对象数据
func (this *Model_Comp) Get(uid string, v reflect.Type, fields ...string) ([]interface{}, error) { //data
return this.Redis.HMGet(fmt.Sprintf("%s:%s", this.TableName, uid), v, fields...) func (this *Model_Comp) GetAll(uid string, data interface{}) error {
return this.Redis.HGetAll(fmt.Sprintf("%s:%s", this.TableName, uid), data)
} }
//获取字段数据 //获取字段数据 缓存存储的数据为hashmap时
func (this *Model_Comp) GetField(uid string, field string, v interface{}) error { func (this *Model_Comp) GetField(uid string, field string, v interface{}) error {
return this.Redis.HGet(fmt.Sprintf("%s:%s", this.TableName, uid), field, v) return this.Redis.HGet(fmt.Sprintf("%s:%s", this.TableName, uid), field, v)
} }
@ -182,3 +191,17 @@ func (this *Model_Comp) Del(uid string) error {
return this.DeleteModelLogs(this.TableName, uid, bson.M{"_id": uid}) return this.DeleteModelLogs(this.TableName, uid, bson.M{"_id": uid})
} }
//日志操作可选项
func (this *Model_Comp) logOpt(uid string, data interface{}, attrs ...*cache.OperationAttr) error {
ret := cache.OperationAttrs(attrs).Find(cache.ATTR_MGOLOG).Unwrap_Or(nil)
if ret == nil {
ir := cache.OperationAttrs(attrs).Find(cache.ATTR_INSERT).Unwrap_Or(nil)
if ir != nil && ir.(bool) {
return this.UpdateModelLogs(this.TableName, uid, bson.M{"uid": uid}, data)
} else {
return this.InsertModelLogs(this.TableName, uid, data)
}
}
return nil
}

View File

@ -4,10 +4,11 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/event" "go_dreamfactory/lego/sys/event"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/cache"
"go_dreamfactory/utils" "go_dreamfactory/utils"
) )
func (this *Api_Comp) Create_Check(session comm.IUserSession, req *pb.UserCreateReq) (result map[string]interface{}, code pb.ErrorCode) { func (this *Api_Comp) Create_Check(session comm.IUserSession, req *pb.UserCreateReq) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }
@ -16,9 +17,9 @@ func (this *Api_Comp) Create(session comm.IUserSession, result map[string]interf
defer utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), User_SubType_Create, req, nil) defer utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), User_SubType_Create, req, nil)
self := &pb.DB_UserData{} self := &pb.DB_UserData{}
defer func() { defer func() {
session.SendMsg(string(this.module.GetType()), User_SubType_Create, &pb.UserCreateRsp{}) session.SendMsg(string(this.module.GetType()), User_SubType_Create, &pb.UserCreateRsp{})
}() }()
//更新昵称 //更新昵称
@ -31,7 +32,7 @@ func (this *Api_Comp) Create(session comm.IUserSession, result map[string]interf
return return
} }
self.Name = req.NickName self.Name = req.NickName
err = this.module.modelUser.SetObj(session.GetUserId(), self, false, true) err = this.module.modelUser.SetObj(session.GetUserId(), self, cache.WithND())
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return

View File

@ -6,6 +6,7 @@ import (
"go_dreamfactory/lego/sys/event" "go_dreamfactory/lego/sys/event"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/cache"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"time" "time"
@ -35,7 +36,7 @@ func decodeUserData(base64Str string) *pb.DB_UserData {
} }
//参数校验 //参数校验
func (this *Api_Comp) Login_Check(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code pb.ErrorCode) { func (this *Api_Comp) Login_Check(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code comm.ErrorCode) {
result = map[string]interface{}{} result = map[string]interface{}{}
return return
} }
@ -93,12 +94,12 @@ func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interfa
SessionId: cache_user.SessionId, SessionId: cache_user.SessionId,
GatewayServiceId: cache_user.GatewayServiceId, GatewayServiceId: cache_user.GatewayServiceId,
} }
err = this.module.modelSession.SetObj(cache_user.Uid, data, true, true) err = this.module.modelSession.SetObj(cache_user.Uid, data)
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }
err = this.module.modelUser.SetObj(cache_user.Uid, user, true, true) err = this.module.modelUser.SetObj(cache_user.Uid, user, cache.WithND())
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
@ -114,13 +115,13 @@ func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interfa
// "sessionId": cache_user.SessionId, // "sessionId": cache_user.SessionId,
// "gatewayServiceId": cache_user.GatewayServiceId, // "gatewayServiceId": cache_user.GatewayServiceId,
// } // }
err = this.module.modelSession.SetObj(db_user.Uid, data, false, false) err = this.module.modelSession.SetObj(db_user.Uid, data)
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }
err = this.module.modelUser.SetObj(db_user.Uid, db_user, false, true) err = this.module.modelUser.SetObj(db_user.Uid, db_user)
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return

View File

@ -6,13 +6,13 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
func (this *Api_Comp) Logout_Check(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code pb.ErrorCode) { func (this *Api_Comp) Logout_Check(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }
//注销 //注销
func (this *Api_Comp) Logout(session comm.IUserSession, result map[string]interface{}, rsp *pb.UserLoginReq) error { func (this *Api_Comp) Logout(session comm.IUserSession, result map[string]interface{}, rsp *pb.UserLoginReq) (code pb.ErrorCode) {
log.Debugf("User - Logout: session:%v rsp:%v", session.ToString(), rsp) log.Debugf("User - Logout: session:%v rsp:%v", session.ToString(), rsp)
return nil return
} }

File diff suppressed because it is too large Load Diff

View File

@ -2,134 +2,107 @@ syntax = "proto3";
option go_package = ".;pb"; option go_package = ".;pb";
message FriendBase { message FriendBase {
string userId = 1; //ID string userId = 1; // ID
string NickName = 2; // string NickName = 2; //
int32 level = 3; // int32 level = 3; //
int32 avatar = 4; // int32 avatar = 4; //
int64 strength = 5; // int64 strength = 5; //
int32 serverId = 6;// int32 serverId = 6; //
int64 offlineTime =7;//线 0线 int64 offlineTime = 7; //线 0线
} }
// //
message FriendListReq{ message Friend_List_Req {}
} message Friend_List_Rsp { repeated FriendBase list = 1; }
message FriendListRsp{
repeated FriendBase list = 1;
}
// //
message FriendApplyReq{ message Friend_Apply_Req {
string friendId = 1; //ID string friendId = 1; //ID
} }
message FriendApplyRsp{ message Friend_Apply_Rsp {
string userId = 1; //ID string userId = 1; //ID
string friendId =2;//ID string friendId = 2; //ID
} }
// //
message FriendDelReq{ message Friend_Del_Req {
string friendId = 1;//ID string friendId = 1; //ID
} }
message FriendDelRsp{ message Friend_Del_Rsp {
string friendId = 1;//ID string friendId = 1; //ID
string userId = 2; //ID string userId = 2; //ID
} }
// //
message FriendAgreeReq{ message Friend_Agree_Req {
repeated string friendIds = 1; // repeated string friendIds = 1; //
} }
message FriendAgreeRsp{ message Friend_Agree_Rsp {
int32 Num = 1;// int32 Num = 1; //
} }
// //
message FriendRefuseReq{ message Friend_Refuse_Req {
repeated string friendIds = 1; // repeated string friendIds = 1; //
} }
message FriendRefuseRsp{ message Friend_Refuse_Rsp {
int32 Num = 1;// int32 Num = 1; //
} }
// //
message FriendApplyListReq{ message Friend_ApplyList_Req {}
message Friend_ApplyList_Rsp { repeated FriendBase list = 1; }
}
message FriendApplyListRsp{
repeated FriendBase list = 1;
}
// //
message FriendSearchReq{ message Friend_Search_Req {
string nickName = 1; // string nickName = 1; //
} }
message FriendSearchRsp{ message Friend_Search_Rsp { FriendBase friend = 1; }
FriendBase friend = 1;
}
// //
message FriendBlackListReq{ message Friend_BlackList_Req {}
} message Friend_BlackList_Rsp { repeated FriendBase friends = 1; }
message FriendBlackListRsp{
repeated FriendBase friends = 1;
}
// //
message FriendBlackAddReq{ message Friend_BlackAdd_Req { string friendId = 1; }
string friendId = 1;
}
message FriendBlackAddRsp{ message Friend_BlackAdd_Rsp {
string friendId = 1; string friendId = 1;
string userId = 2; string userId = 2;
} }
// //
message FriendDelBlackReq{ message Friend_DelBlack_Req { string friendId = 1; }
string friendId = 1;
}
message FriendDelBlackRsp{ message Friend_DelBlack_Rsp {
string friendId = 1; string friendId = 1;
string userId = 2; string userId = 2;
} }
// //
message FriendReceiveReq{ message Friend_Receive_Req { string friendId = 1; }
string friendId = 1;
}
message FriendReceiveRsp{ message Friend_Receive_Rsp {
string friendId = 1; string friendId = 1;
string userId = 2; string userId = 2;
} }
// //
message FriendGiveReq{ message Friend_Give_Req { string friendId = 1; }
string friendId = 1;
}
message FriendGiveRsp{ message Friend_Give_Rsp {
string friendId = 1; string friendId = 1;
string userId = 2; string userId = 2;
} }
// //
message FriendTotalReq{ message Friend_Total_Req { string friendId = 1; }
string friendId = 1;
}
message FriendTotalRsp{ message Friend_Total_Rsp {
string friendId = 1; string friendId = 1;
int32 total = 2; // int32 total = 2; //
} }

View File

@ -159,7 +159,7 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM
} }
result := returnValues[0].Interface().(map[string]interface{}) result := returnValues[0].Interface().(map[string]interface{})
returnValues = msghandle.fn.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(result), reflect.ValueOf(msg)}) returnValues = msghandle.fn.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(result), reflect.ValueOf(msg)})
errcode := pb.ErrorCode(returnValues[1].Int()) errcode := pb.ErrorCode(returnValues[0].Int())
if errcode != pb.ErrorCode_Success { if errcode != pb.ErrorCode_Success {
log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code) log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code)
reply.Code = errcode reply.Code = errcode

17
sys/cache/interfaceResult.go vendored Normal file
View File

@ -0,0 +1,17 @@
package cache
type InterfaceResult struct {
Result interface{}
Err error
}
func NewInterfaceResult(result interface{}, err error) *InterfaceResult {
return &InterfaceResult{Result: result, Err: err}
}
func (ths *InterfaceResult) Unwrap_Or(v interface{}) interface{} {
if ths.Err != nil {
return v
}
return ths.Result
}

47
sys/cache/optionAttr.go vendored Normal file
View File

@ -0,0 +1,47 @@
package cache
import "fmt"
const (
ATTR_MGOLOG = "mgolog"
ATTR_INSERT = "insert"
OpenMgoLog = false //true表示不禁用Mgolog即不传入WithDisabledMgoLog()时也表示禁用
)
type empty struct {
}
type OperationAttr struct {
Name string
Value interface{}
}
type OperationAttrs []*OperationAttr
func (this OperationAttrs) Find(name string) *InterfaceResult {
for _, v := range this {
if v.Name == name {
return NewInterfaceResult(v.Value, nil)
}
}
if OpenMgoLog {
return NewInterfaceResult(ATTR_MGOLOG, nil)
}
return NewInterfaceResult(nil, fmt.Errorf("Operationattrs not found err: %v", name))
}
func WithDisabledMgoLog() *OperationAttr {
return &OperationAttr{
Name: ATTR_MGOLOG,
Value: empty{},
}
}
func WithND() *OperationAttr {
return &OperationAttr{
Name: ATTR_INSERT,
Value: true,
}
}