This commit is contained in:
meixiongfeng 2022-06-28 15:26:28 +08:00
commit f2cf68f173
17 changed files with 61 additions and 56 deletions

View File

@ -38,7 +38,7 @@ type (
//消耗卡片
ChangeCard(uId string, heroCfgId int32, count int32) (code pb.ErrorCode)
//创建新英雄
CreatHero(uid string, heroCfgId ...int32) error
CreateHero(uid string, heroCfgId ...int32) error
// 获取英雄
// heroId 英雄ID

View File

@ -17,12 +17,12 @@ const (
Friend_SubType_Search = "search"
)
type ApiComp struct {
type apiComp struct {
modules.MComp_GateComp
module *Friend
}
func (this *ApiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options)
this.module = module.(*Friend)
return

View File

@ -6,7 +6,7 @@ import (
"go_dreamfactory/utils"
)
func (this *ApiComp) Addblack_Check(session comm.IUserSession, req *pb.Friend_BlackAdd_Req) (chk map[string]interface{}, code comm.ErrorCode) {
func (this *apiComp) Addblack_Check(session comm.IUserSession, req *pb.Friend_BlackAdd_Req) (chk map[string]interface{}, code comm.ErrorCode) {
chk = make(map[string]interface{})
var (
err error
@ -15,13 +15,13 @@ func (this *ApiComp) Addblack_Check(session comm.IUserSession, req *pb.Friend_Bl
self := &pb.DB_FriendData{UId: session.GetUserId()}
target := &pb.DB_FriendData{UId: req.FriendId}
err = this.module.model_friend.Get(session.GetUserId(), self)
err = this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
}
err = this.module.model_friend.Get(req.FriendId, target)
err = this.module.modelFriend.Get(req.FriendId, target)
if target == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetNoData}
return
@ -58,7 +58,7 @@ func (this *ApiComp) Addblack_Check(session comm.IUserSession, req *pb.Friend_Bl
}
//加入黑名单
func (this *ApiComp) Addblack(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_BlackAdd_Req) (code pb.ErrorCode) {
func (this *apiComp) Addblack(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_BlackAdd_Req) (code pb.ErrorCode) {
var (
self *pb.DB_FriendData
rsp *pb.Friend_BlackAdd_Rsp
@ -78,7 +78,7 @@ func (this *ApiComp) Addblack(session comm.IUserSession, chk map[string]interfac
self.BlackIds = append(self.BlackIds, req.FriendId)
//更新黑名单
err := this.module.model_friend.Change(self.UId, map[string]interface{}{
err := this.module.modelFriend.Change(self.UId, map[string]interface{}{
"blackIds": self.BlackIds,
})
if err != nil {

View File

@ -6,13 +6,13 @@ import (
"go_dreamfactory/utils"
)
func (this *ApiComp) Agree_Check(session comm.IUserSession, req *pb.Friend_Agree_Req) (chk map[string]interface{}, code comm.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{})
var err error
self := &pb.DB_FriendData{UId: session.GetUserId()}
//获取玩家自己好友数据
err = this.module.model_friend.Get(session.GetUserId(), self)
err = this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
@ -34,7 +34,7 @@ func (this *ApiComp) Agree_Check(session comm.IUserSession, req *pb.Friend_Agree
}
//单个/批量同意
func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Agree_Req) (code pb.ErrorCode) {
func (this *apiComp) Agree(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Agree_Req) (code pb.ErrorCode) {
var (
self *pb.DB_FriendData
rsp *pb.Friend_Agree_Rsp
@ -71,7 +71,7 @@ func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}
//双向添加:将自己加入到申请人的好友列表中
target := &pb.DB_FriendData{}
err := this.module.model_friend.Get(userId, target)
err := this.module.modelFriend.Get(userId, target)
if target == nil || err != nil {
code = pb.ErrorCode_FriendTargetNoData
@ -82,7 +82,7 @@ func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}
}
target.FriendIds = append(target.FriendIds, self.UId)
}
err = this.module.model_friend.Change(target.UId, map[string]interface{}{
err = this.module.modelFriend.Change(target.UId, map[string]interface{}{
"friendIds": target.FriendIds,
})
if err != nil {
@ -95,7 +95,7 @@ func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}
}
//更新
err := this.module.model_friend.Change(self.UId, map[string]interface{}{
err := this.module.modelFriend.Change(self.UId, map[string]interface{}{
"applyIds": self.ApplyIds,
"friendIds": self.FriendIds,
})

View File

@ -7,21 +7,21 @@ import (
"go_dreamfactory/utils"
)
func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.Friend_Apply_Req) (chk map[string]interface{}, code comm.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{})
var err error
self := &pb.DB_FriendData{UId: session.GetUserId()}
target := &pb.DB_FriendData{UId: req.FriendId}
//获取玩家自己好友数据
err = this.module.model_friend.Get(session.GetUserId(), self)
err = this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
}
//获取好友数据
err = this.module.model_friend.Get(req.FriendId, target)
err = this.module.modelFriend.Get(req.FriendId, target)
if target == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetNoData}
return
@ -79,7 +79,7 @@ func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.Friend_Apply
}
//好友申请
func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Apply_Req) (code pb.ErrorCode) {
func (this *apiComp) Apply(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Apply_Req) (code pb.ErrorCode) {
var (
target *pb.DB_FriendData
rsp *pb.Friend_Apply_Rsp
@ -116,7 +116,7 @@ func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{}
}
target.ApplyIds = append(target.ApplyIds, session.GetUserId())
err := this.module.model_friend.Change(req.FriendId, map[string]interface{}{
err := this.module.modelFriend.Change(req.FriendId, map[string]interface{}{
"applyIds": target.ApplyIds,
})
if err != nil {

View File

@ -5,10 +5,10 @@ import (
"go_dreamfactory/pb"
)
func (this *ApiComp) ApplyList_Check(session comm.IUserSession, req *pb.Friend_ApplyList_Req) (chk map[string]interface{}, code comm.ErrorCode) {
func (this *apiComp) ApplyList_Check(session comm.IUserSession, req *pb.Friend_ApplyList_Req) (chk map[string]interface{}, code comm.ErrorCode) {
chk = make(map[string]interface{})
self := &pb.DB_FriendData{UId: session.GetUserId()}
err := this.module.model_friend.Get(session.GetUserId(), self)
err := this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
@ -18,7 +18,7 @@ func (this *ApiComp) ApplyList_Check(session comm.IUserSession, req *pb.Friend_A
}
//申请列表
func (this *ApiComp) ApplyList(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_ApplyList_Req) (code pb.ErrorCode) {
func (this *apiComp) ApplyList(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_ApplyList_Req) (code pb.ErrorCode) {
var (
self *pb.DB_FriendData
rsp *pb.Friend_ApplyList_Rsp

View File

@ -5,10 +5,10 @@ import (
"go_dreamfactory/pb"
)
func (this *ApiComp) Blacklist_Check(session comm.IUserSession, req *pb.Friend_BlackList_Req) (chk map[string]interface{}, code comm.ErrorCode) {
func (this *apiComp) Blacklist_Check(session comm.IUserSession, req *pb.Friend_BlackList_Req) (chk map[string]interface{}, code comm.ErrorCode) {
chk = make(map[string]interface{})
self := &pb.DB_FriendData{UId: session.GetUserId()}
err := this.module.model_friend.Get(session.GetUserId(), self)
err := this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
@ -18,7 +18,7 @@ func (this *ApiComp) Blacklist_Check(session comm.IUserSession, req *pb.Friend_B
}
//黑名单
func (this *ApiComp) Blacklist(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_BlackList_Req) (code pb.ErrorCode) {
func (this *apiComp) Blacklist(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_BlackList_Req) (code pb.ErrorCode) {
var (
self *pb.DB_FriendData
rsp *pb.Friend_BlackList_Rsp

View File

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

View File

@ -6,10 +6,10 @@ import (
"go_dreamfactory/utils"
)
func (this *ApiComp) Delblack_Check(session comm.IUserSession, req *pb.Friend_DelBlack_Req) (chk map[string]interface{}, code comm.ErrorCode) {
func (this *apiComp) Delblack_Check(session comm.IUserSession, req *pb.Friend_DelBlack_Req) (chk map[string]interface{}, code comm.ErrorCode) {
chk = make(map[string]interface{})
self := &pb.DB_FriendData{UId: session.GetUserId()}
err := this.module.model_friend.Get(session.GetUserId(), self)
err := this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
@ -19,7 +19,7 @@ func (this *ApiComp) Delblack_Check(session comm.IUserSession, req *pb.Friend_De
}
//删除黑名单
func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_DelBlack_Req) (code pb.ErrorCode) {
func (this *apiComp) Delblack(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_DelBlack_Req) (code pb.ErrorCode) {
var (
self *pb.DB_FriendData
rsp *pb.Friend_DelBlack_Rsp
@ -43,7 +43,7 @@ func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interfac
//从黑名单列表中删除目标
self.BlackIds = utils.DeleteString(self.BlackIds, req.FriendId)
//更新黑名单
err := this.module.model_friend.Change(self.UId, map[string]interface{}{
err := this.module.modelFriend.Change(self.UId, map[string]interface{}{
"blackIds": self.BlackIds,
})
if err != nil {

View File

@ -5,10 +5,10 @@ import (
"go_dreamfactory/pb"
)
func (this *ApiComp) List_Check(session comm.IUserSession, req *pb.Friend_List_Req) (chk map[string]interface{}, code comm.ErrorCode) {
func (this *apiComp) List_Check(session comm.IUserSession, req *pb.Friend_List_Req) (chk map[string]interface{}, code comm.ErrorCode) {
chk = make(map[string]interface{})
self := &pb.DB_FriendData{UId: session.GetUserId()}
err := this.module.model_friend.Get(session.GetUserId(), self)
err := this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
@ -18,7 +18,7 @@ func (this *ApiComp) List_Check(session comm.IUserSession, req *pb.Friend_List_R
}
//好友列表
func (this *ApiComp) List(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_List_Req) (code pb.ErrorCode) {
func (this *apiComp) List(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_List_Req) (code pb.ErrorCode) {
var (
self *pb.DB_FriendData
rsp *pb.Friend_List_Rsp

View File

@ -6,13 +6,13 @@ import (
"go_dreamfactory/utils"
)
func (this *ApiComp) Refuse_Check(session comm.IUserSession, req *pb.Friend_Refuse_Req) (chk map[string]interface{}, code comm.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{})
var err error
self := &pb.DB_FriendData{UId: session.GetUserId()}
//获取玩家自己好友数据
err = this.module.model_friend.Get(session.GetUserId(), self)
err = this.module.modelFriend.Get(session.GetUserId(), self)
if self == nil || err != nil {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
return
@ -33,7 +33,7 @@ func (this *ApiComp) Refuse_Check(session comm.IUserSession, req *pb.Friend_Refu
}
//单个/批量拒绝
func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Refuse_Req) (code pb.ErrorCode) {
func (this *apiComp) Refuse(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Refuse_Req) (code pb.ErrorCode) {
//将申请人从申请列表中删除
var (
self *pb.DB_FriendData
@ -66,7 +66,7 @@ func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{
}
//更新
if optNum > 0 {
err := this.module.model_friend.Change(self.UId, map[string]interface{}{
err := this.module.modelFriend.Change(self.UId, map[string]interface{}{
"applyIds": self.ApplyIds,
})
if err != nil {

View File

@ -5,7 +5,7 @@ import (
"go_dreamfactory/pb"
)
func (this *ApiComp) Search_Check(session comm.IUserSession, req *pb.Friend_Search_Req) (chk map[string]interface{}, code comm.ErrorCode) {
func (this *apiComp) Search_Check(session comm.IUserSession, req *pb.Friend_Search_Req) (chk map[string]interface{}, code comm.ErrorCode) {
if req.NickName == "" {
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSearchNameEmpty}
return
@ -14,7 +14,7 @@ func (this *ApiComp) Search_Check(session comm.IUserSession, req *pb.Friend_Sear
}
//搜索
func (this *ApiComp) Search(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Search_Req) (code pb.ErrorCode) {
func (this *apiComp) Search(session comm.IUserSession, chk map[string]interface{}, req *pb.Friend_Search_Req) (code pb.ErrorCode) {
var (
rsp *pb.Friend_Search_Rsp
friend *pb.FriendBase
@ -28,7 +28,7 @@ func (this *ApiComp) Search(session comm.IUserSession, chk map[string]interface{
session.SendMsg(string(this.module.GetType()), Friend_SubType_Search, rsp)
}()
user := this.module.model_friend.Frined_FindCond(req.NickName)
user := this.module.modelFriend.Frined_FindCond(req.NickName)
if user != nil {
friend = &pb.FriendBase{
UserId: user.Uid,

View File

@ -10,8 +10,8 @@ import (
)
const (
DB_FriendTable core.SqlTable = "friend"
DB_UserTable core.SqlTable = "user" //用户表
TableFriend core.SqlTable = "friend"
TableUser core.SqlTable = "user" //用户表
)
type ModelFriend struct {
@ -20,13 +20,13 @@ type ModelFriend struct {
func (this *ModelFriend) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.Model_Comp.Init(service, module, comp, options)
this.TableName = "friend"
this.TableName = string(TableFriend)
return
}
func (this *ModelFriend) Frined_FindCond(nickName string) *pb.DB_UserData {
var user *pb.DB_UserData
err := this.DB.FindOne(DB_UserTable, bson.M{
err := this.DB.FindOne(TableUser, bson.M{
"name": nickName,
}).Decode(&user)
if err != nil {

View File

@ -14,8 +14,8 @@ func NewModule() core.IModule {
type Friend struct {
modules.ModuleBase
friend_comp *ApiComp
model_friend *ModelFriend
api *apiComp
modelFriend *ModelFriend
}
func (this *Friend) GetType() core.M_Modules {
@ -30,6 +30,6 @@ func (this *Friend) Init(service core.IService, module core.IModule, options cor
func (this *Friend) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.friend_comp = this.RegisterComp(new(ApiComp)).(*ApiComp)
this.model_friend = this.RegisterComp(new(ModelFriend)).(*ModelFriend)
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelFriend = this.RegisterComp(new(ModelFriend)).(*ModelFriend)
}

View File

@ -62,14 +62,19 @@ func (this *ModelHero) createOneHero(uid string, heroCfgId int32) error {
//创建多个指定的英雄 heroCfgIds可填入多个英雄ID
func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error {
data := make(map[string]interface{})
// data := make(map[string]interface{})
for _, v := range heroCfgIds {
hero := this.initHero(uid, v)
if hero != nil {
data[hero.Id] = hero
if err := this.createOneHero(uid, v); err != nil {
return err
}
// hero := this.initHero(uid, v)
// if hero != nil {
// data[hero.Id] = hero
// }
}
return this.moduleHero.modelHero.AddLists(uid, data)
return nil
// return this.moduleHero.model_hero.AddLists(uid, data)
}
//获取一个英雄

View File

@ -40,7 +40,7 @@ func (this *Hero) OnInstallComp() {
}
//创建新英雄
func (this *Hero) CreatHero(uid string, heroCfgId ...int32) error {
func (this *Hero) CreateHero(uid string, heroCfgId ...int32) error {
return this.modelHero.createMultiHero(uid, heroCfgId...)
}

View File

@ -41,7 +41,7 @@ func (this *apiComp) Create(session comm.IUserSession, result map[string]interfa
//初始化英雄卡
defaultHero := []int32{15001, 25001} //TODO 从配置中读取
err = this.hero.CreatHero(session.GetUserId(), defaultHero...)
err = this.hero.CreateHero(session.GetUserId(), defaultHero...)
if err != nil {
code = pb.ErrorCode_HeroInitCreat
return