check修改
This commit is contained in:
parent
93b6ad9e89
commit
b08afb9bbd
@ -15,7 +15,7 @@ var (
|
||||
subType: friend.FriendSubTypeList,
|
||||
req: &pb.FriendListReq{},
|
||||
rsp: &pb.FriendListRsp{},
|
||||
enabled: true,
|
||||
// enabled: true,
|
||||
}, {
|
||||
//blacklist
|
||||
mainType: string(comm.ModuleFriend),
|
||||
@ -60,9 +60,10 @@ var (
|
||||
mainType: string(comm.ModuleFriend),
|
||||
subType: friend.FriendSubTypeAddBlack,
|
||||
req: &pb.FriendBlackAddReq{
|
||||
FriendId: "",
|
||||
FriendId: "0_62bd1c804cf36044f36bff33",
|
||||
},
|
||||
rsp: &pb.FriendBlackAddRsp{},
|
||||
rsp: &pb.FriendBlackAddRsp{},
|
||||
enabled: true,
|
||||
}, {
|
||||
//delblack
|
||||
mainType: string(comm.ModuleFriend),
|
||||
|
@ -4,62 +4,23 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"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) {
|
||||
chk = make(map[string]interface{})
|
||||
var (
|
||||
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
|
||||
func (this *apiComp) AddblackCheck(session comm.IUserSession, req *pb.FriendBlackAddReq) (code pb.ErrorCode) {
|
||||
if req.FriendId == "" {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
//加入黑名单
|
||||
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 (
|
||||
err error
|
||||
self *pb.DBFriend
|
||||
rsp *pb.FriendBlackAddRsp
|
||||
)
|
||||
@ -69,22 +30,64 @@ func (this *apiComp) Addblack(session comm.IUserSession, chk map[string]interfac
|
||||
FriendId: req.FriendId,
|
||||
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 = v.(*pb.DBFriend)
|
||||
//将目标加入黑名单
|
||||
self.BlackIds = append(self.BlackIds, req.FriendId)
|
||||
self = &pb.DBFriend{UId: session.GetUserId()}
|
||||
target := &pb.DBFriend{UId: req.FriendId}
|
||||
|
||||
//更新黑名单
|
||||
err := this.module.modelFriend.Change(self.UId, map[string]interface{}{
|
||||
"blackIds": self.BlackIds,
|
||||
})
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
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
|
||||
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
|
||||
|
@ -4,38 +4,22 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"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) {
|
||||
chk = make(map[string]interface{})
|
||||
var err error
|
||||
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
|
||||
func (this *apiComp) AgreeCheck(session comm.IUserSession, req *pb.FriendAgreeReq) (code pb.ErrorCode) {
|
||||
if len(req.FriendIds) == 0 {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
|
||||
//同意的好友
|
||||
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
|
||||
}
|
||||
|
||||
//单个/批量同意
|
||||
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 (
|
||||
err error
|
||||
self *pb.DBFriend
|
||||
rsp *pb.FriendAgreeRsp
|
||||
optNum int32
|
||||
@ -52,57 +36,66 @@ func (this *apiComp) Agree(session comm.IUserSession, chk map[string]interface{}
|
||||
}
|
||||
}()
|
||||
|
||||
if v, ok := chk["self"]; !ok {
|
||||
code = pb.ErrorCode_FriendTargetNoData
|
||||
self = &pb.DBFriend{UId: session.GetUserId()}
|
||||
|
||||
//获取玩家自己好友数据
|
||||
err = this.module.modelFriend.Get(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
} else {
|
||||
self = v.(*pb.DBFriend)
|
||||
}
|
||||
|
||||
if agreeIds, ok := chk["agreeIds"]; ok {
|
||||
//将目标加入到自己的好友列表中
|
||||
for _, userId := range agreeIds.([]string) {
|
||||
if _, ok := utils.Find(self.FriendIds, userId); !ok {
|
||||
if self.FriendIds == nil {
|
||||
self.FriendIds = []string{}
|
||||
}
|
||||
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
|
||||
//同意的好友
|
||||
agreeIds := []string{}
|
||||
for _, friendId := range req.FriendIds {
|
||||
if _, ok := utils.Find(self.FriendIds, friendId); !ok {
|
||||
//不在好友列表中就加入
|
||||
agreeIds = append(agreeIds, friendId)
|
||||
}
|
||||
}
|
||||
|
||||
//将目标加入到自己的好友列表中
|
||||
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 {
|
||||
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++
|
||||
self.FriendIds = append(self.FriendIds, userId)
|
||||
}
|
||||
|
||||
//更新
|
||||
err := this.module.modelFriend.Change(self.UId, map[string]interface{}{
|
||||
"applyIds": self.ApplyIds,
|
||||
"friendIds": self.FriendIds,
|
||||
//双向添加:将自己加入到申请人的好友列表中
|
||||
target := &pb.DBFriend{}
|
||||
err := this.module.modelFriend.Get(userId, target)
|
||||
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 {
|
||||
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
|
||||
|
@ -5,82 +5,22 @@ import (
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"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) {
|
||||
chk = make(map[string]interface{})
|
||||
var err error
|
||||
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
|
||||
func (this *apiComp) ApplyCheck(session comm.IUserSession, req *pb.FriendApplyReq) (code pb.ErrorCode) {
|
||||
if req.FriendId == "" {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
|
||||
//获取好友数据
|
||||
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
|
||||
}
|
||||
|
||||
//好友申请
|
||||
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 (
|
||||
err error
|
||||
self *pb.DBFriend
|
||||
target *pb.DBFriend
|
||||
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
|
||||
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())
|
||||
|
||||
err := this.module.modelFriend.Change(req.FriendId, map[string]interface{}{
|
||||
err = this.module.modelFriend.Change(req.FriendId, map[string]interface{}{
|
||||
"applyIds": target.ApplyIds,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -5,20 +5,13 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
func (this *apiComp) ApplyListCheck(session comm.IUserSession, req *pb.FriendApplyListReq) (chk map[string]interface{}, code comm.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
|
||||
func (this *apiComp) ApplyListCheck(session comm.IUserSession, req *pb.FriendApplyListReq) (code pb.ErrorCode) {
|
||||
|
||||
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 (
|
||||
self *pb.DBFriend
|
||||
rsp *pb.FriendApplyListRsp
|
||||
@ -31,17 +24,23 @@ func (this *apiComp) ApplyList(session comm.IUserSession, chk map[string]interfa
|
||||
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 = v.(*pb.DBFriend)
|
||||
for _, userId := range self.ApplyIds {
|
||||
//TODO 组装FriendBase明细数据
|
||||
list = append(list, &pb.FriendBase{
|
||||
UserId: userId,
|
||||
})
|
||||
}
|
||||
self = &pb.DBFriend{UId: session.GetUserId()}
|
||||
err := this.module.modelFriend.Get(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
}
|
||||
|
||||
for _, userId := range self.ApplyIds {
|
||||
//TODO 组装FriendBase明细数据
|
||||
list = append(list, &pb.FriendBase{
|
||||
UserId: userId,
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -3,22 +3,17 @@ package friend
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"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) {
|
||||
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
|
||||
func (this *apiComp) BlacklistCheck(session comm.IUserSession, req *pb.FriendBlackListReq) (code pb.ErrorCode) {
|
||||
|
||||
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 (
|
||||
self *pb.DBFriend
|
||||
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 = v.(*pb.DBFriend)
|
||||
for _, userId := range self.BlackIds {
|
||||
//TODO 完善FriendBase信息
|
||||
list = append(list, &pb.FriendBase{
|
||||
UserId: userId,
|
||||
})
|
||||
}
|
||||
self = &pb.DBFriend{UId: session.GetUserId()}
|
||||
err := this.module.modelFriend.Get(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
}
|
||||
|
||||
for _, userId := range self.BlackIds {
|
||||
//TODO 完善FriendBase信息
|
||||
list = append(list, &pb.FriendBase{
|
||||
UserId: userId,
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -4,22 +4,19 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"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) {
|
||||
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
|
||||
func (this *apiComp) DelblackCheck(session comm.IUserSession, req *pb.FriendDelBlackReq) (code pb.ErrorCode) {
|
||||
if req.FriendId == "" {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
chk["self"] = self
|
||||
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 (
|
||||
self *pb.DBFriend
|
||||
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 = v.(*pb.DBFriend)
|
||||
//从黑名单列表中删除目标
|
||||
self.BlackIds = utils.DeleteString(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
|
||||
}
|
||||
self = &pb.DBFriend{UId: session.GetUserId()}
|
||||
err := this.module.modelFriend.Get(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
}
|
||||
|
||||
//从黑名单列表中删除目标
|
||||
self.BlackIds = utils.DeleteString(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
|
||||
|
@ -3,22 +3,17 @@ package friend
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"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) {
|
||||
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
|
||||
func (this *apiComp) ListCheck(session comm.IUserSession, req *pb.FriendListReq) (code pb.ErrorCode) {
|
||||
|
||||
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 (
|
||||
self *pb.DBFriend
|
||||
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 = v.(*pb.DBFriend)
|
||||
for _, userId := range self.FriendIds {
|
||||
list = append(list, &pb.FriendBase{
|
||||
UserId: userId,
|
||||
})
|
||||
}
|
||||
self = &pb.DBFriend{UId: session.GetUserId()}
|
||||
err := this.module.modelFriend.Get(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
}
|
||||
|
||||
for _, userId := range self.FriendIds {
|
||||
list = append(list, &pb.FriendBase{
|
||||
UserId: userId,
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -4,38 +4,23 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"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) {
|
||||
chk = make(map[string]interface{})
|
||||
var err error
|
||||
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
|
||||
func (this *apiComp) RefuseCheck(session comm.IUserSession, req *pb.FriendRefuseReq) (code pb.ErrorCode) {
|
||||
if len(req.FriendIds) == 0 {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
|
||||
//拒绝的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
|
||||
}
|
||||
|
||||
//单个/批量拒绝
|
||||
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 (
|
||||
err error
|
||||
self *pb.DBFriend
|
||||
rsp *pb.FriendRefuseRsp
|
||||
optNum int32
|
||||
@ -52,30 +37,38 @@ func (this *apiComp) Refuse(session comm.IUserSession, chk map[string]interface{
|
||||
}
|
||||
}()
|
||||
|
||||
if v, ok := chk["self"]; !ok {
|
||||
code = pb.ErrorCode_FriendTargetNoData
|
||||
self = &pb.DBFriend{UId: session.GetUserId()}
|
||||
|
||||
//获取玩家自己好友数据
|
||||
err = this.module.modelFriend.Get(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
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
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ type Friend struct {
|
||||
modules.ModuleBase
|
||||
api *apiComp
|
||||
modelFriend *ModelFriend
|
||||
configure *modules.MCompConfigure
|
||||
}
|
||||
|
||||
func (this *Friend) GetType() core.M_Modules {
|
||||
|
@ -4,20 +4,16 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"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) {
|
||||
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
|
||||
func (this *apiComp) InfoCheck(session comm.IUserSession, req *pb.HeroInfoReq) (code pb.ErrorCode) {
|
||||
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{}
|
||||
defer func() {
|
||||
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)
|
||||
}()
|
||||
|
||||
if v, ok := result["hero"]; ok {
|
||||
rsp.Base = v.(*pb.DBHero)
|
||||
hero := this.moduleHero.hero.getOneHero(session.GetUserId(), req.HeroId)
|
||||
if hero == nil {
|
||||
code = pb.ErrorCode_HeroNoExist
|
||||
}
|
||||
|
||||
rsp.Base = hero
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -4,14 +4,16 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"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
|
||||
}
|
||||
|
||||
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{}
|
||||
|
||||
defer func() {
|
||||
|
@ -4,22 +4,21 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"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) {
|
||||
result = make(map[string]interface{})
|
||||
self := &pb.DBUser{}
|
||||
err := this.module.modelUser.Get(session.GetUserId(), self)
|
||||
if err != nil {
|
||||
code = comm.ErrorCode{Code: pb.ErrorCode_DBError}
|
||||
return
|
||||
func (this *apiComp) CreateCheck(session comm.IUserSession, req *pb.UserCreateReq) (code pb.ErrorCode) {
|
||||
if req.NickName == "" {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
result["self"] = self
|
||||
|
||||
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 func() {
|
||||
@ -29,12 +28,11 @@ func (this *apiComp) Create(session comm.IUserSession, result map[string]interfa
|
||||
}
|
||||
}()
|
||||
|
||||
if self, ok := result["self"]; ok {
|
||||
v := self.(*pb.DBUser)
|
||||
if v.Created {
|
||||
code = pb.ErrorCode_RoleCreated
|
||||
return
|
||||
}
|
||||
self := &pb.DBUser{}
|
||||
err = this.module.modelUser.Get(session.GetUserId(), self)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
|
||||
update := map[string]interface{}{
|
||||
@ -47,7 +45,7 @@ func (this *apiComp) Create(session comm.IUserSession, result map[string]interfa
|
||||
update["gold"] = val
|
||||
}
|
||||
|
||||
err := this.module.modelUser.Change(session.GetUserId(), update)
|
||||
err = this.module.modelUser.Change(session.GetUserId(), update)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
|
@ -9,16 +9,17 @@ import (
|
||||
"time"
|
||||
|
||||
"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) {
|
||||
result = map[string]interface{}{}
|
||||
func (this *apiComp) LoginCheck(session comm.IUserSession, req *pb.UserLoginReq) (code pb.ErrorCode) {
|
||||
|
||||
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 (
|
||||
err error
|
||||
user *pb.DBUser
|
||||
|
@ -3,20 +3,18 @@ package user
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"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) {
|
||||
result = make(map[string]interface{})
|
||||
user := this.module.modelUser.getUser(session.GetUserId())
|
||||
if user == nil {
|
||||
code = comm.ErrorCode{Code: pb.ErrorCode_UserSessionNobeing}
|
||||
return
|
||||
func (this *apiComp) AddResCheck(session comm.IUserSession, req *pb.UserAddResReq) (code pb.ErrorCode) {
|
||||
if req.ResType == "" || req.Count <= 0 {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
result["user"] = user
|
||||
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{}
|
||||
|
||||
defer func() {
|
||||
@ -26,24 +24,27 @@ func (this *apiComp) AddRes(session comm.IUserSession, result map[string]interfa
|
||||
}
|
||||
}()
|
||||
|
||||
if u, ok := result["user"]; ok {
|
||||
user := u.(*pb.DBUser)
|
||||
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
|
||||
user := this.module.modelUser.getUser(session.GetUserId())
|
||||
if user == nil {
|
||||
code = pb.ErrorCode_UserSessionNobeing
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user