check修改

This commit is contained in:
zhaocy 2022-07-01 14:48:45 +08:00
parent 93b6ad9e89
commit b08afb9bbd
15 changed files with 359 additions and 372 deletions

View File

@ -15,7 +15,7 @@ var (
subType: friend.FriendSubTypeList, subType: friend.FriendSubTypeList,
req: &pb.FriendListReq{}, req: &pb.FriendListReq{},
rsp: &pb.FriendListRsp{}, rsp: &pb.FriendListRsp{},
enabled: true, // enabled: true,
}, { }, {
//blacklist //blacklist
mainType: string(comm.ModuleFriend), mainType: string(comm.ModuleFriend),
@ -60,9 +60,10 @@ var (
mainType: string(comm.ModuleFriend), mainType: string(comm.ModuleFriend),
subType: friend.FriendSubTypeAddBlack, subType: friend.FriendSubTypeAddBlack,
req: &pb.FriendBlackAddReq{ req: &pb.FriendBlackAddReq{
FriendId: "", FriendId: "0_62bd1c804cf36044f36bff33",
}, },
rsp: &pb.FriendBlackAddRsp{}, rsp: &pb.FriendBlackAddRsp{},
enabled: true,
}, { }, {
//delblack //delblack
mainType: string(comm.ModuleFriend), mainType: string(comm.ModuleFriend),

View File

@ -4,62 +4,23 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"github.com/spf13/cast"
"google.golang.org/protobuf/proto"
) )
func (this *apiComp) AddblackCheck(session comm.IUserSession, req *pb.FriendBlackAddReq) (chk map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) AddblackCheck(session comm.IUserSession, req *pb.FriendBlackAddReq) (code pb.ErrorCode) {
chk = make(map[string]interface{}) if req.FriendId == "" {
var ( code = pb.ErrorCode_ReqParameterError
err error
blackNumMax = 50 //TODO 从配置中读取
)
self := &pb.DBFriend{UId: session.GetUserId()}
target := &pb.DBFriend{UId: req.FriendId}
err = this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
} }
err = this.module.modelFriend.Get(req.FriendId, target)
if target == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetNoData}
return
}
//判断目标是否在好友列表里面
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendYet}
return
}
//判断目标是否已经在黑名单中
if _, ok := utils.Find(self.BlackIds, req.FriendId); ok {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfBlackYet}
return
}
// 判断自己是否在对方的黑名单中
if _, ok := utils.Find(target.BlackIds, self.UId); ok {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetBlackYet}
return
}
// 判断是否黑名单人数已满
if len(self.BlackIds) >= blackNumMax {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendBlackMax}
return
}
chk["self"] = self
chk["target"] = target
return return
} }
//加入黑名单 //加入黑名单
func (this *apiComp) Addblack(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendBlackAddReq) (code pb.ErrorCode) { func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendBlackAddReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
err error
self *pb.DBFriend self *pb.DBFriend
rsp *pb.FriendBlackAddRsp rsp *pb.FriendBlackAddRsp
) )
@ -69,22 +30,64 @@ func (this *apiComp) Addblack(session comm.IUserSession, chk map[string]interfac
FriendId: req.FriendId, FriendId: req.FriendId,
UserId: session.GetUserId(), UserId: session.GetUserId(),
} }
session.SendMsg(string(this.module.GetType()), FriendSubTypeAddBlack, rsp) if err := session.SendMsg(string(this.module.GetType()), FriendSubTypeAddBlack, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
}() }()
if v, ok := chk["self"]; ok { self = &pb.DBFriend{UId: session.GetUserId()}
self = v.(*pb.DBFriend) target := &pb.DBFriend{UId: req.FriendId}
//将目标加入黑名单
self.BlackIds = append(self.BlackIds, req.FriendId)
//更新黑名单 err = this.module.modelFriend.Get(session.GetUserId(), self)
err := this.module.modelFriend.Change(self.UId, map[string]interface{}{ if self == nil || err != nil {
"blackIds": self.BlackIds, code = pb.ErrorCode_FriendSelfNoData
}) return
if err != nil { }
code = pb.ErrorCode_DBError
return err = this.module.modelFriend.Get(req.FriendId, target)
} if target == nil || err != nil {
code = pb.ErrorCode_FriendTargetNoData
return
}
//判断目标是否在好友列表里面
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
code = pb.ErrorCode_FriendYet
return
}
//判断目标是否已经在黑名单中
if _, ok := utils.Find(self.BlackIds, req.FriendId); ok {
code = pb.ErrorCode_FriendSelfBlackYet
return
}
// 判断自己是否在对方的黑名单中
if _, ok := utils.Find(target.BlackIds, self.UId); ok {
code = pb.ErrorCode_FriendTargetBlackYet
return
}
blackNumMax := 0
if maxhy := this.module.configure.GetGlobalConf("max_hy"); maxhy != "" {
blackNumMax = cast.ToInt(maxhy)
}
// 判断是否黑名单人数已满
if len(self.BlackIds) >= blackNumMax {
code = pb.ErrorCode_FriendBlackMax
return
}
//将目标加入黑名单
self.BlackIds = append(self.BlackIds, req.FriendId)
//更新黑名单
err = this.module.modelFriend.Change(self.UId, map[string]interface{}{
"blackIds": self.BlackIds,
})
if err != nil {
code = pb.ErrorCode_DBError
return
} }
return return

View File

@ -4,38 +4,22 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
) )
func (this *apiComp) AgreeCheck(session comm.IUserSession, req *pb.FriendAgreeReq) (chk map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) AgreeCheck(session comm.IUserSession, req *pb.FriendAgreeReq) (code pb.ErrorCode) {
chk = make(map[string]interface{}) if len(req.FriendIds) == 0 {
var err error code = pb.ErrorCode_ReqParameterError
self := &pb.DBFriend{UId: session.GetUserId()}
//获取玩家自己好友数据
err = this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
} }
//同意的好友
agreeIds := []string{}
for _, friendId := range req.FriendIds {
if _, ok := utils.Find(self.FriendIds, friendId); !ok {
//不在好友列表中就加入
agreeIds = append(agreeIds, friendId)
}
}
chk["agreeIds"] = agreeIds
chk["self"] = self
return return
} }
//单个/批量同意 //单个/批量同意
func (this *apiComp) Agree(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendAgreeReq) (code pb.ErrorCode) { func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
err error
self *pb.DBFriend self *pb.DBFriend
rsp *pb.FriendAgreeRsp rsp *pb.FriendAgreeRsp
optNum int32 optNum int32
@ -52,57 +36,66 @@ func (this *apiComp) Agree(session comm.IUserSession, chk map[string]interface{}
} }
}() }()
if v, ok := chk["self"]; !ok { self = &pb.DBFriend{UId: session.GetUserId()}
code = pb.ErrorCode_FriendTargetNoData
//获取玩家自己好友数据
err = this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = pb.ErrorCode_FriendSelfNoData
return return
} else {
self = v.(*pb.DBFriend)
} }
if agreeIds, ok := chk["agreeIds"]; ok { //同意的好友
//将目标加入到自己的好友列表中 agreeIds := []string{}
for _, userId := range agreeIds.([]string) { for _, friendId := range req.FriendIds {
if _, ok := utils.Find(self.FriendIds, userId); !ok { if _, ok := utils.Find(self.FriendIds, friendId); !ok {
if self.FriendIds == nil { //不在好友列表中就加入
self.FriendIds = []string{} agreeIds = append(agreeIds, friendId)
} }
self.FriendIds = append(self.FriendIds, userId) }
}
//双向添加:将自己加入到申请人的好友列表中
target := &pb.DBFriend{}
err := this.module.modelFriend.Get(userId, target)
if target == nil || err != nil {
code = pb.ErrorCode_FriendTargetNoData
//将目标加入到自己的好友列表中
for _, userId := range agreeIds {
if _, ok := utils.Find(self.FriendIds, userId); !ok {
if self.FriendIds == nil {
self.FriendIds = []string{}
} }
if _, ok := utils.Find(target.FriendIds, self.UId); !ok { self.FriendIds = append(self.FriendIds, userId)
if target.FriendIds == nil {
target.FriendIds = []string{}
}
target.FriendIds = append(target.FriendIds, self.UId)
}
err = this.module.modelFriend.Change(target.UId, map[string]interface{}{
"friendIds": target.FriendIds,
})
if err != nil {
code = pb.ErrorCode_DBError
}
//将目标从申请列表中删除
self.ApplyIds = utils.DeleteString(self.ApplyIds, userId)
optNum++
} }
//更新 //双向添加:将自己加入到申请人的好友列表中
err := this.module.modelFriend.Change(self.UId, map[string]interface{}{ target := &pb.DBFriend{}
"applyIds": self.ApplyIds, err := this.module.modelFriend.Get(userId, target)
"friendIds": self.FriendIds, if target == nil || err != nil {
code = pb.ErrorCode_FriendTargetNoData
}
if _, ok := utils.Find(target.FriendIds, self.UId); !ok {
if target.FriendIds == nil {
target.FriendIds = []string{}
}
target.FriendIds = append(target.FriendIds, self.UId)
}
err = this.module.modelFriend.Change(target.UId, map[string]interface{}{
"friendIds": target.FriendIds,
}) })
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return
} }
//将目标从申请列表中删除
self.ApplyIds = utils.DeleteString(self.ApplyIds, userId)
optNum++
}
//更新
err = this.module.modelFriend.Change(self.UId, map[string]interface{}{
"applyIds": self.ApplyIds,
"friendIds": self.FriendIds,
})
if err != nil {
code = pb.ErrorCode_DBError
return
} }
return return

View File

@ -5,82 +5,22 @@ import (
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
) )
func (this *apiComp) ApplyCheck(session comm.IUserSession, req *pb.FriendApplyReq) (chk map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) ApplyCheck(session comm.IUserSession, req *pb.FriendApplyReq) (code pb.ErrorCode) {
chk = make(map[string]interface{}) if req.FriendId == "" {
var err error code = pb.ErrorCode_ReqParameterError
self := &pb.DBFriend{UId: session.GetUserId()}
target := &pb.DBFriend{UId: req.FriendId}
//获取玩家自己好友数据
err = this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
} }
//获取好友数据
err = this.module.modelFriend.Get(req.FriendId, target)
if target == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetNoData}
return
}
//判断是否是自己
if req.FriendId == session.GetUserId() {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendNotSelf}
return
}
//判断是否超过最大好友数量
//TODO 最大数从全局配置中获取
var max int = 50
total := len(self.FriendIds)
if total >= max {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfMax}
return
}
//判断对方是否也超过最大好友数量
ttotal := len(target.FriendIds)
if ttotal >= max {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetMax}
return
}
//判断是否是好友
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendYet}
return
}
//判断自己是否在目标用户的申请列表中
if _, ok := utils.Find(target.ApplyIds, self.UId); ok {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendApplyYet}
return
}
//判断目标用户是否在黑名单中
if _, ok := utils.Find(self.BlackIds, req.FriendId); ok {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfBlackYet}
return
}
//判断是否在对方的黑名单中
if _, ok := utils.Find(target.BlackIds, self.UId); ok {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetBlackYet}
return
}
chk["self"] = self
chk["target"] = target
return return
} }
//好友申请 //好友申请
func (this *apiComp) Apply(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendApplyReq) (code pb.ErrorCode) { func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
err error
self *pb.DBFriend
target *pb.DBFriend target *pb.DBFriend
rsp *pb.FriendApplyRsp rsp *pb.FriendApplyRsp
) )
@ -103,11 +43,67 @@ func (this *apiComp) Apply(session comm.IUserSession, chk map[string]interface{}
} }
}() }()
if v, ok := chk["target"]; !ok { self = &pb.DBFriend{UId: session.GetUserId()}
target = &pb.DBFriend{UId: req.FriendId}
//获取玩家自己好友数据
err = this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = pb.ErrorCode_FriendSelfNoData
return
}
//获取好友数据
err = this.module.modelFriend.Get(req.FriendId, target)
if target == nil || err != nil {
code = pb.ErrorCode_FriendTargetNoData code = pb.ErrorCode_FriendTargetNoData
return return
} else { }
target = v.(*pb.DBFriend)
//判断是否是自己
if req.FriendId == session.GetUserId() {
code = pb.ErrorCode_FriendNotSelf
return
}
//判断是否超过最大好友数量
//TODO 最大数从全局配置中获取
var max int = 50
total := len(self.FriendIds)
if total >= max {
code = pb.ErrorCode_FriendSelfMax
return
}
//判断对方是否也超过最大好友数量
ttotal := len(target.FriendIds)
if ttotal >= max {
code = pb.ErrorCode_FriendTargetMax
return
}
//判断是否是好友
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
code = pb.ErrorCode_FriendYet
return
}
//判断自己是否在目标用户的申请列表中
if _, ok := utils.Find(target.ApplyIds, self.UId); ok {
code = pb.ErrorCode_FriendApplyYet
return
}
//判断目标用户是否在黑名单中
if _, ok := utils.Find(self.BlackIds, req.FriendId); ok {
code = pb.ErrorCode_FriendSelfBlackYet
return
}
//判断是否在对方的黑名单中
if _, ok := utils.Find(target.BlackIds, self.UId); ok {
code = pb.ErrorCode_FriendTargetBlackYet
return
} }
//将自己加入到目标用户的申请列表中 //将自己加入到目标用户的申请列表中
@ -116,7 +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.modelFriend.Change(req.FriendId, map[string]interface{}{ err = this.module.modelFriend.Change(req.FriendId, map[string]interface{}{
"applyIds": target.ApplyIds, "applyIds": target.ApplyIds,
}) })
if err != nil { if err != nil {

View File

@ -5,20 +5,13 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
func (this *apiComp) ApplyListCheck(session comm.IUserSession, req *pb.FriendApplyListReq) (chk map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) ApplyListCheck(session comm.IUserSession, req *pb.FriendApplyListReq) (code pb.ErrorCode) {
chk = make(map[string]interface{})
self := &pb.DBFriend{UId: session.GetUserId()}
err := this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
}
chk["self"] = self
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, req *pb.FriendApplyListReq) (code pb.ErrorCode) {
var ( var (
self *pb.DBFriend self *pb.DBFriend
rsp *pb.FriendApplyListRsp rsp *pb.FriendApplyListRsp
@ -31,17 +24,23 @@ func (this *apiComp) ApplyList(session comm.IUserSession, chk map[string]interfa
List: list, List: list,
} }
} }
session.SendMsg(string(this.module.GetType()), FriendSubTypeApplyList, rsp) if err := session.SendMsg(string(this.module.GetType()), FriendSubTypeApplyList, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
}() }()
if v, ok := chk["self"]; ok { self = &pb.DBFriend{UId: session.GetUserId()}
self = v.(*pb.DBFriend) err := this.module.modelFriend.Get(session.GetUserId(), self)
for _, userId := range self.ApplyIds { if self == nil || err != nil {
//TODO 组装FriendBase明细数据 code = pb.ErrorCode_FriendSelfNoData
list = append(list, &pb.FriendBase{ return
UserId: userId, }
})
} for _, userId := range self.ApplyIds {
//TODO 组装FriendBase明细数据
list = append(list, &pb.FriendBase{
UserId: userId,
})
} }
return return

View File

@ -3,22 +3,17 @@ package friend
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
) )
func (this *apiComp) BlacklistCheck(session comm.IUserSession, req *pb.FriendBlackListReq) (chk map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) BlacklistCheck(session comm.IUserSession, req *pb.FriendBlackListReq) (code pb.ErrorCode) {
chk = make(map[string]interface{})
self := &pb.DBFriend{UId: session.GetUserId()}
err := this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
}
chk["self"] = self
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, req *pb.FriendBlackListReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
self *pb.DBFriend self *pb.DBFriend
rsp *pb.FriendBlackListRsp rsp *pb.FriendBlackListRsp
@ -37,14 +32,18 @@ func (this *apiComp) Blacklist(session comm.IUserSession, chk map[string]interfa
} }
}() }()
if v, ok := chk["self"]; ok { self = &pb.DBFriend{UId: session.GetUserId()}
self = v.(*pb.DBFriend) err := this.module.modelFriend.Get(session.GetUserId(), self)
for _, userId := range self.BlackIds { if self == nil || err != nil {
//TODO 完善FriendBase信息 code = pb.ErrorCode_FriendSelfNoData
list = append(list, &pb.FriendBase{ return
UserId: userId, }
})
} for _, userId := range self.BlackIds {
//TODO 完善FriendBase信息
list = append(list, &pb.FriendBase{
UserId: userId,
})
} }
return return

View File

@ -4,22 +4,19 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
) )
func (this *apiComp) DelblackCheck(session comm.IUserSession, req *pb.FriendDelBlackReq) (chk map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) DelblackCheck(session comm.IUserSession, req *pb.FriendDelBlackReq) (code pb.ErrorCode) {
chk = make(map[string]interface{}) if req.FriendId == "" {
self := &pb.DBFriend{UId: session.GetUserId()} code = pb.ErrorCode_ReqParameterError
err := this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
} }
chk["self"] = self
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, req *pb.FriendDelBlackReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
self *pb.DBFriend self *pb.DBFriend
rsp *pb.FriendDelBlackRsp rsp *pb.FriendDelBlackRsp
@ -38,18 +35,22 @@ func (this *apiComp) Delblack(session comm.IUserSession, chk map[string]interfac
} }
}() }()
if v, ok := chk["self"]; ok { self = &pb.DBFriend{UId: session.GetUserId()}
self = v.(*pb.DBFriend) err := this.module.modelFriend.Get(session.GetUserId(), self)
//从黑名单列表中删除目标 if self == nil || err != nil {
self.BlackIds = utils.DeleteString(self.BlackIds, req.FriendId) code = pb.ErrorCode_FriendSelfNoData
//更新黑名单 return
err := this.module.modelFriend.Change(self.UId, map[string]interface{}{ }
"blackIds": self.BlackIds,
}) //从黑名单列表中删除目标
if err != nil { self.BlackIds = utils.DeleteString(self.BlackIds, req.FriendId)
code = pb.ErrorCode_DBError //更新黑名单
return err = this.module.modelFriend.Change(self.UId, map[string]interface{}{
} "blackIds": self.BlackIds,
})
if err != nil {
code = pb.ErrorCode_DBError
return
} }
return return

View File

@ -3,22 +3,17 @@ package friend
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
) )
func (this *apiComp) ListCheck(session comm.IUserSession, req *pb.FriendListReq) (chk map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) ListCheck(session comm.IUserSession, req *pb.FriendListReq) (code pb.ErrorCode) {
chk = make(map[string]interface{})
self := &pb.DBFriend{UId: session.GetUserId()}
err := this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
}
chk["self"] = self
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.FriendListReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
self *pb.DBFriend self *pb.DBFriend
rsp *pb.FriendListRsp rsp *pb.FriendListRsp
@ -36,13 +31,17 @@ func (this *apiComp) List(session comm.IUserSession, chk map[string]interface{},
} }
}() }()
if v, ok := chk["self"]; ok { self = &pb.DBFriend{UId: session.GetUserId()}
self = v.(*pb.DBFriend) err := this.module.modelFriend.Get(session.GetUserId(), self)
for _, userId := range self.FriendIds { if self == nil || err != nil {
list = append(list, &pb.FriendBase{ code = pb.ErrorCode_FriendSelfNoData
UserId: userId, return
}) }
}
for _, userId := range self.FriendIds {
list = append(list, &pb.FriendBase{
UserId: userId,
})
} }
return return

View File

@ -4,38 +4,23 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
) )
func (this *apiComp) RefuseCheck(session comm.IUserSession, req *pb.FriendRefuseReq) (chk map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) RefuseCheck(session comm.IUserSession, req *pb.FriendRefuseReq) (code pb.ErrorCode) {
chk = make(map[string]interface{}) if len(req.FriendIds) == 0 {
var err error code = pb.ErrorCode_ReqParameterError
self := &pb.DBFriend{UId: session.GetUserId()}
//获取玩家自己好友数据
err = this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
} }
//拒绝的Ids
refuseIds := []string{}
for _, friendId := range req.FriendIds {
if _, ok := utils.Find(self.ApplyIds, friendId); ok {
refuseIds = append(refuseIds, friendId)
}
}
chk["self"] = self
chk["refuseIds"] = refuseIds
return return
} }
//单个/批量拒绝 //单个/批量拒绝
func (this *apiComp) Refuse(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendRefuseReq) (code pb.ErrorCode) { func (this *apiComp) Refuse(session comm.IUserSession, req *pb.FriendRefuseReq) (code pb.ErrorCode, data proto.Message) {
//将申请人从申请列表中删除 //将申请人从申请列表中删除
var ( var (
err error
self *pb.DBFriend self *pb.DBFriend
rsp *pb.FriendRefuseRsp rsp *pb.FriendRefuseRsp
optNum int32 optNum int32
@ -52,30 +37,38 @@ func (this *apiComp) Refuse(session comm.IUserSession, chk map[string]interface{
} }
}() }()
if v, ok := chk["self"]; !ok { self = &pb.DBFriend{UId: session.GetUserId()}
code = pb.ErrorCode_FriendTargetNoData
//获取玩家自己好友数据
err = this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = pb.ErrorCode_FriendSelfNoData
return return
} else { }
self = v.(*pb.DBFriend)
if v, ok := chk["refuseIds"]; ok {
//将申请人从申请列表中删除
for _, userId := range v.([]string) {
self.ApplyIds = utils.DeleteString(self.ApplyIds, userId)
optNum++
}
//更新
if optNum > 0 {
err := this.module.modelFriend.Change(self.UId, map[string]interface{}{
"applyIds": self.ApplyIds,
})
if err != nil {
code = pb.ErrorCode_DBError
return
}
}
//拒绝的Ids
refuseIds := []string{}
for _, friendId := range req.FriendIds {
if _, ok := utils.Find(self.ApplyIds, friendId); ok {
refuseIds = append(refuseIds, friendId)
} }
} }
//将申请人从申请列表中删除
for _, userId := range refuseIds {
self.ApplyIds = utils.DeleteString(self.ApplyIds, userId)
optNum++
}
//更新
if optNum > 0 {
err := this.module.modelFriend.Change(self.UId, map[string]interface{}{
"applyIds": self.ApplyIds,
})
if err != nil {
code = pb.ErrorCode_DBError
return
}
}
return return
} }

View File

@ -16,6 +16,7 @@ type Friend struct {
modules.ModuleBase modules.ModuleBase
api *apiComp api *apiComp
modelFriend *ModelFriend modelFriend *ModelFriend
configure *modules.MCompConfigure
} }
func (this *Friend) GetType() core.M_Modules { func (this *Friend) GetType() core.M_Modules {

View File

@ -4,20 +4,16 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
) )
//参数校验 //参数校验
func (this *apiComp) InfoCheck(session comm.IUserSession, req *pb.HeroInfoReq) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) InfoCheck(session comm.IUserSession, req *pb.HeroInfoReq) (code pb.ErrorCode) {
result = map[string]interface{}{}
hero := this.moduleHero.hero.getOneHero(session.GetUserId(), req.HeroId)
if hero == nil {
code = comm.ErrorCode{Code: pb.ErrorCode_HeroNoExist}
}
result["hero"] = hero
return return
} }
func (this *apiComp) Info(session comm.IUserSession, result map[string]interface{}, req *pb.HeroInfoReq) (code pb.ErrorCode) { func (this *apiComp) Info(session comm.IUserSession, req *pb.HeroInfoReq) (code pb.ErrorCode, data proto.Message) {
rsp := &pb.HeroInfoRsp{} rsp := &pb.HeroInfoRsp{}
defer func() { defer func() {
err := session.SendMsg(string(this.moduleHero.GetType()), HeroSubTypeInfo, rsp) err := session.SendMsg(string(this.moduleHero.GetType()), HeroSubTypeInfo, rsp)
@ -28,8 +24,12 @@ func (this *apiComp) Info(session comm.IUserSession, result map[string]interface
utils.TraceFunc(session.GetUserId(), string(this.moduleHero.GetType()), HeroSubTypeList, req, rsp) utils.TraceFunc(session.GetUserId(), string(this.moduleHero.GetType()), HeroSubTypeList, req, rsp)
}() }()
if v, ok := result["hero"]; ok { hero := this.moduleHero.hero.getOneHero(session.GetUserId(), req.HeroId)
rsp.Base = v.(*pb.DBHero) if hero == nil {
code = pb.ErrorCode_HeroNoExist
} }
rsp.Base = hero
return return
} }

View File

@ -4,14 +4,16 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
) )
//参数校验 //参数校验
func (this *apiComp) ListCheck(session comm.IUserSession, req *pb.HeroListReq) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) ListCheck(session comm.IUserSession, req *pb.HeroListReq) (code pb.ErrorCode) {
return return
} }
func (this *apiComp) List(session comm.IUserSession, result map[string]interface{}, req *pb.HeroListReq) (code pb.ErrorCode) { func (this *apiComp) List(session comm.IUserSession, req *pb.HeroListReq) (code pb.ErrorCode, data proto.Message) {
rsp := &pb.HeroListRsp{} rsp := &pb.HeroListRsp{}
defer func() { defer func() {

View File

@ -4,22 +4,21 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
) )
func (this *apiComp) CreateCheck(session comm.IUserSession, req *pb.UserCreateReq) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) CreateCheck(session comm.IUserSession, req *pb.UserCreateReq) (code pb.ErrorCode) {
result = make(map[string]interface{}) if req.NickName == "" {
self := &pb.DBUser{} code = pb.ErrorCode_ReqParameterError
err := this.module.modelUser.Get(session.GetUserId(), self)
if err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_DBError}
return
} }
result["self"] = self
return return
} }
//创角 //创角
func (this *apiComp) Create(session comm.IUserSession, result map[string]interface{}, req *pb.UserCreateReq) (code pb.ErrorCode) { func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (code pb.ErrorCode, data proto.Message) {
var err error
defer utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), UserSubTypeCreate, req, nil) defer utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), UserSubTypeCreate, req, nil)
defer func() { defer func() {
@ -29,12 +28,11 @@ func (this *apiComp) Create(session comm.IUserSession, result map[string]interfa
} }
}() }()
if self, ok := result["self"]; ok { self := &pb.DBUser{}
v := self.(*pb.DBUser) err = this.module.modelUser.Get(session.GetUserId(), self)
if v.Created { if err != nil {
code = pb.ErrorCode_RoleCreated code = pb.ErrorCode_DBError
return return
}
} }
update := map[string]interface{}{ update := map[string]interface{}{
@ -47,7 +45,7 @@ func (this *apiComp) Create(session comm.IUserSession, result map[string]interfa
update["gold"] = val update["gold"] = val
} }
err := this.module.modelUser.Change(session.GetUserId(), update) err = this.module.modelUser.Change(session.GetUserId(), update)
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return

View File

@ -9,16 +9,17 @@ import (
"time" "time"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"google.golang.org/protobuf/proto"
) )
//参数校验 //参数校验
func (this *apiComp) LoginCheck(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) LoginCheck(session comm.IUserSession, req *pb.UserLoginReq) (code pb.ErrorCode) {
result = map[string]interface{}{}
return return
} }
//登录 //登录
func (this *apiComp) Login(session comm.IUserSession, result map[string]interface{}, req *pb.UserLoginReq) (code pb.ErrorCode) { func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
err error err error
user *pb.DBUser user *pb.DBUser

View File

@ -3,20 +3,18 @@ package user
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
) )
func (this *apiComp) AddResCheck(session comm.IUserSession, req *pb.UserAddResReq) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) AddResCheck(session comm.IUserSession, req *pb.UserAddResReq) (code pb.ErrorCode) {
result = make(map[string]interface{}) if req.ResType == "" || req.Count <= 0 {
user := this.module.modelUser.getUser(session.GetUserId()) code = pb.ErrorCode_ReqParameterError
if user == nil {
code = comm.ErrorCode{Code: pb.ErrorCode_UserSessionNobeing}
return
} }
result["user"] = user
return return
} }
func (this *apiComp) AddRes(session comm.IUserSession, result map[string]interface{}, req *pb.UserAddResReq) (code pb.ErrorCode) { func (this *apiComp) AddRes(session comm.IUserSession, req *pb.UserAddResReq) (code pb.ErrorCode, data proto.Message) {
rsp := &pb.UserAddResResp{} rsp := &pb.UserAddResResp{}
defer func() { defer func() {
@ -26,24 +24,27 @@ func (this *apiComp) AddRes(session comm.IUserSession, result map[string]interfa
} }
}() }()
if u, ok := result["user"]; ok { user := this.module.modelUser.getUser(session.GetUserId())
user := u.(*pb.DBUser) if user == nil {
count := req.Count code = pb.ErrorCode_UserSessionNobeing
return
switch req.ResType {
case comm.ResGold:
count += user.Gold
case comm.ResExp:
count += user.Exp
}
code = this.module.AddAttributeValue(session.GetUserId(), req.ResType, count)
if code != pb.ErrorCode_Success {
return
}
rsp.ResType = req.ResType
rsp.Count = count
} }
count := req.Count
switch req.ResType {
case comm.ResGold:
count += user.Gold
case comm.ResExp:
count += user.Exp
}
code = this.module.AddAttributeValue(session.GetUserId(), req.ResType, count)
if code != pb.ErrorCode_Success {
return
}
rsp.ResType = req.ResType
rsp.Count = count
return return
} }