From 56b809406ca369ca4d8b356822b606cbb71b4d37 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Thu, 20 Oct 2022 18:01:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8A=A9=E6=88=98=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 2 + modules/friend/api.go | 1 - modules/friend/api_croos_assistherolist.go | 34 ------- modules/friend/api_cross_assisthero.go | 13 +++ modules/friend/module.go | 9 ++ pb/friend_msg.pb.go | 103 +++++---------------- 6 files changed, 49 insertions(+), 113 deletions(-) delete mode 100644 modules/friend/api_croos_assistherolist.go diff --git a/comm/const.go b/comm/const.go index a9d0ece60..380a28d0c 100644 --- a/comm/const.go +++ b/comm/const.go @@ -171,6 +171,8 @@ const ( //Rpc Rpc_ModuleMoonfantasyTrigger core.Rpc_Key = "Rpc_ModuleMoonfantasyTrigger" //月之秘境触发消息 //rtask 上传随机任务代码 Rpc_ModuleRtaskSendTask core.Rpc_Key = "Rpc_ModuleRtaskSendTask" //随机任务触发 + // friend + Rpc_ModuleFriendUseAssitHero core.Rpc_Key = "Rpc_ModuleFriendUseAssitHero" //使用助战英雄 ) //事件类型定义处 diff --git a/modules/friend/api.go b/modules/friend/api.go index 44b648231..88a6e6f04 100644 --- a/modules/friend/api.go +++ b/modules/friend/api.go @@ -24,7 +24,6 @@ const ( FriendSubTypeDel = "del" FriendSubTypeAssistlist = "assistlist" FriendSubTypeGetreward = "getreward" - FriendSubTypeAssistHeroList = "assistherolist" ) type apiComp struct { diff --git a/modules/friend/api_croos_assistherolist.go b/modules/friend/api_croos_assistherolist.go deleted file mode 100644 index 81779992f..000000000 --- a/modules/friend/api_croos_assistherolist.go +++ /dev/null @@ -1,34 +0,0 @@ -package friend - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" - - "google.golang.org/protobuf/proto" -) - -// 助战英雄列表 - -func (this *apiComp) AssistherolistCheck(session comm.IUserSession, req *pb.FriendAssistHeroListReq) (code pb.ErrorCode) { - return -} - -func (this *apiComp) Assistherolist(session comm.IUserSession, req *pb.FriendAssistHeroListReq) (code pb.ErrorCode, data proto.Message) { - - resp := &pb.FriendAssistHeroListResp{} - self := this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) - - for _, fId := range self.FriendIds { - d := this.moduleFriend.modelFriend.GetFriend(fId) - resp.Friends = append(resp.Friends, &pb.FriendBase{ - HeroObjId: d.AssistHeroId, - }) - } - - err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeAssistHeroList, resp) - if err != nil { - code = pb.ErrorCode_SystemError - } - - return -} diff --git a/modules/friend/api_cross_assisthero.go b/modules/friend/api_cross_assisthero.go index 0b34ad760..06c1bef78 100644 --- a/modules/friend/api_cross_assisthero.go +++ b/modules/friend/api_cross_assisthero.go @@ -65,6 +65,19 @@ func (this *apiComp) Assisthero(session comm.IUserSession, req *pb.FriendAssisth return } + //推送 + push := &pb.FriendAssistHeroListPush{} + for _, fId := range self.FriendIds { + d := this.moduleFriend.modelFriend.GetFriend(fId) + push.Friends = append(push.Friends, &pb.FriendBase{ + HeroObjId: d.AssistHeroId, + }) + } + if err := this.moduleFriend.SendMsgToUsers(string(this.moduleFriend.GetType()), "AssistHeroList", + &pb.FriendAssistHeroListPush{}, self.FriendIds...); err != nil { + this.moduleFriend.Errorf("push AssistHeroList err:", err) + } + // 随机任务Rtype13 this.moduleFriend.ModuleRtask.SendToRtask(session, comm.Rtype13, 1) diff --git a/modules/friend/module.go b/modules/friend/module.go index 0d1f468fe..33df6d14c 100644 --- a/modules/friend/module.go +++ b/modules/friend/module.go @@ -6,6 +6,7 @@ import ( "go_dreamfactory/pb" "time" + "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" @@ -24,6 +25,7 @@ type Friend struct { api *apiComp modelFriend *ModelFriend configure *modules.MCompConfigure + service base.IRPCXService } func (this *Friend) GetType() core.M_Modules { @@ -32,6 +34,7 @@ func (this *Friend) GetType() core.M_Modules { func (this *Friend) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) + this.service = service.(base.IRPCXService) return } @@ -41,6 +44,12 @@ func (this *Friend) OnInstallComp() { this.modelFriend = this.RegisterComp(new(ModelFriend)).(*ModelFriend) } +func (this *Friend) Start() (err error) { + err = this.ModuleBase.Start() + this.service.RegisterFunctionName(string(comm.Rpc_ModuleFriendUseAssitHero), this.UseAssistHero) + return +} + func (this *Friend) ResetFriend(uid string) { // 重置点赞列表 zanUpdate := map[string]interface{}{ diff --git a/pb/friend_msg.pb.go b/pb/friend_msg.pb.go index 9883908e6..51bd3a031 100644 --- a/pb/friend_msg.pb.go +++ b/pb/friend_msg.pb.go @@ -1866,15 +1866,17 @@ func (x *FriendGetrewardResp) GetReceived() int32 { return 0 } -// 助战英雄列表 -type FriendAssistHeroListReq struct { +// 助战英雄列表推送 +type FriendAssistHeroListPush struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + Friends []*FriendBase `protobuf:"bytes,1,rep,name=friends,proto3" json:"friends"` //好友列表 } -func (x *FriendAssistHeroListReq) Reset() { - *x = FriendAssistHeroListReq{} +func (x *FriendAssistHeroListPush) Reset() { + *x = FriendAssistHeroListPush{} if protoimpl.UnsafeEnabled { mi := &file_friend_friend_msg_proto_msgTypes[37] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -1882,13 +1884,13 @@ func (x *FriendAssistHeroListReq) Reset() { } } -func (x *FriendAssistHeroListReq) String() string { +func (x *FriendAssistHeroListPush) String() string { return protoimpl.X.MessageStringOf(x) } -func (*FriendAssistHeroListReq) ProtoMessage() {} +func (*FriendAssistHeroListPush) ProtoMessage() {} -func (x *FriendAssistHeroListReq) ProtoReflect() protoreflect.Message { +func (x *FriendAssistHeroListPush) ProtoReflect() protoreflect.Message { mi := &file_friend_friend_msg_proto_msgTypes[37] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -1900,52 +1902,12 @@ func (x *FriendAssistHeroListReq) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use FriendAssistHeroListReq.ProtoReflect.Descriptor instead. -func (*FriendAssistHeroListReq) Descriptor() ([]byte, []int) { +// Deprecated: Use FriendAssistHeroListPush.ProtoReflect.Descriptor instead. +func (*FriendAssistHeroListPush) Descriptor() ([]byte, []int) { return file_friend_friend_msg_proto_rawDescGZIP(), []int{37} } -type FriendAssistHeroListResp struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Friends []*FriendBase `protobuf:"bytes,1,rep,name=friends,proto3" json:"friends"` //好友 -} - -func (x *FriendAssistHeroListResp) Reset() { - *x = FriendAssistHeroListResp{} - if protoimpl.UnsafeEnabled { - mi := &file_friend_friend_msg_proto_msgTypes[38] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *FriendAssistHeroListResp) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*FriendAssistHeroListResp) ProtoMessage() {} - -func (x *FriendAssistHeroListResp) ProtoReflect() protoreflect.Message { - mi := &file_friend_friend_msg_proto_msgTypes[38] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use FriendAssistHeroListResp.ProtoReflect.Descriptor instead. -func (*FriendAssistHeroListResp) Descriptor() ([]byte, []int) { - return file_friend_friend_msg_proto_rawDescGZIP(), []int{38} -} - -func (x *FriendAssistHeroListResp) GetFriends() []*FriendBase { +func (x *FriendAssistHeroListPush) GetFriends() []*FriendBase { if x != nil { return x.Friends } @@ -2091,14 +2053,12 @@ var file_friend_friend_msg_proto_rawDesc = []byte{ 0x22, 0x31, 0x0a, 0x13, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x47, 0x65, 0x74, 0x72, 0x65, 0x77, 0x61, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69, - 0x76, 0x65, 0x64, 0x22, 0x19, 0x0a, 0x17, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x73, 0x73, - 0x69, 0x73, 0x74, 0x48, 0x65, 0x72, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x22, 0x41, - 0x0a, 0x18, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x73, 0x73, 0x69, 0x73, 0x74, 0x48, 0x65, - 0x72, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x25, 0x0a, 0x07, 0x66, 0x72, - 0x69, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x46, 0x72, - 0x69, 0x65, 0x6e, 0x64, 0x42, 0x61, 0x73, 0x65, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, - 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x76, 0x65, 0x64, 0x22, 0x41, 0x0a, 0x18, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x73, 0x73, + 0x69, 0x73, 0x74, 0x48, 0x65, 0x72, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x75, 0x73, 0x68, 0x12, + 0x25, 0x0a, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x0b, 0x2e, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x61, 0x73, 0x65, 0x52, 0x07, 0x66, + 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -2113,7 +2073,7 @@ func file_friend_friend_msg_proto_rawDescGZIP() []byte { return file_friend_friend_msg_proto_rawDescData } -var file_friend_friend_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 39) +var file_friend_friend_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 38) var file_friend_friend_msg_proto_goTypes = []interface{}{ (*FriendBase)(nil), // 0: FriendBase (*FriendListReq)(nil), // 1: FriendListReq @@ -2152,9 +2112,8 @@ var file_friend_friend_msg_proto_goTypes = []interface{}{ (*FriendAssistlistResp)(nil), // 34: FriendAssistlistResp (*FriendGetrewardReq)(nil), // 35: FriendGetrewardReq (*FriendGetrewardResp)(nil), // 36: FriendGetrewardResp - (*FriendAssistHeroListReq)(nil), // 37: FriendAssistHeroListReq - (*FriendAssistHeroListResp)(nil), // 38: FriendAssistHeroListResp - (*ZhuZhanRecord)(nil), // 39: ZhuZhanRecord + (*FriendAssistHeroListPush)(nil), // 37: FriendAssistHeroListPush + (*ZhuZhanRecord)(nil), // 38: ZhuZhanRecord } var file_friend_friend_msg_proto_depIdxs = []int32{ 0, // 0: FriendListResp.list:type_name -> FriendBase @@ -2164,8 +2123,8 @@ var file_friend_friend_msg_proto_depIdxs = []int32{ 0, // 4: FriendBlackListResp.friends:type_name -> FriendBase 0, // 5: FriendZanlistResp.list:type_name -> FriendBase 0, // 6: FriendAssistlistResp.list:type_name -> FriendBase - 39, // 7: FriendAssistlistResp.record:type_name -> ZhuZhanRecord - 0, // 8: FriendAssistHeroListResp.friends:type_name -> FriendBase + 38, // 7: FriendAssistlistResp.record:type_name -> ZhuZhanRecord + 0, // 8: FriendAssistHeroListPush.friends:type_name -> FriendBase 9, // [9:9] is the sub-list for method output_type 9, // [9:9] is the sub-list for method input_type 9, // [9:9] is the sub-list for extension type_name @@ -2625,19 +2584,7 @@ func file_friend_friend_msg_proto_init() { } } file_friend_friend_msg_proto_msgTypes[37].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*FriendAssistHeroListReq); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_friend_friend_msg_proto_msgTypes[38].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*FriendAssistHeroListResp); i { + switch v := v.(*FriendAssistHeroListPush); i { case 0: return &v.state case 1: @@ -2655,7 +2602,7 @@ func file_friend_friend_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_friend_friend_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 39, + NumMessages: 38, NumExtensions: 0, NumServices: 0, }, From 02f8b18c1b6df6fee8742d798e0140700fbec69d Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 20 Oct 2022 18:03:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 1 + modules/gourmet/api_getlist.go | 4 --- modules/hero/hero_test.go | 1 + modules/smithy/api_getlist.go | 1 + modules/smithy/api_getranduser.go | 44 +++++++++++++++++++++++-------- modules/timer/chat.go | 2 -- modules/timer/season.go | 7 +++-- 7 files changed, 39 insertions(+), 21 deletions(-) diff --git a/comm/const.go b/comm/const.go index a9d0ece60..becdc135a 100644 --- a/comm/const.go +++ b/comm/const.go @@ -339,6 +339,7 @@ const ( const ( PagodaType = 101 // 普通塔 + SeasonType = 2 // 赛季塔类型 ) const ( diff --git a/modules/gourmet/api_getlist.go b/modules/gourmet/api_getlist.go index 951c48651..239deb20d 100644 --- a/modules/gourmet/api_getlist.go +++ b/modules/gourmet/api_getlist.go @@ -32,9 +32,5 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.GourmetGetListRe // 计算订单信息 this.module.modelGourmet.CalculationGourmet(session.GetUserId(), _gourmet) session.SendMsg(string(this.module.GetType()), GourmetGetListResp, &pb.GourmetGetListResp{Data: _gourmet}) - - // this.GetRandUser(session, &pb.GourmetGetRandUserReq{ - // People: 10, - // }) return } diff --git a/modules/hero/hero_test.go b/modules/hero/hero_test.go index 663fbb5aa..3bd0fc7b4 100644 --- a/modules/hero/hero_test.go +++ b/modules/hero/hero_test.go @@ -60,6 +60,7 @@ func (this *TestService) InitSys() { } func Test_Main(t *testing.T) { + ids := utils.Numbers(0, 10, 5) for _, v := range ids { fmt.Printf("%d", v) diff --git a/modules/smithy/api_getlist.go b/modules/smithy/api_getlist.go index 6050fa1ff..c1f4e6a91 100644 --- a/modules/smithy/api_getlist.go +++ b/modules/smithy/api_getlist.go @@ -28,5 +28,6 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.SmithyGetListReq // 计算订单信息 this.module.modelSmithy.CalculationSmithy(session.GetUserId(), _gourmet) session.SendMsg(string(this.module.GetType()), SmithyGetListResp, &pb.SmithyGetListResp{Data: _gourmet}) + return } diff --git a/modules/smithy/api_getranduser.go b/modules/smithy/api_getranduser.go index 3f2ddb9f7..ed6b75b3d 100644 --- a/modules/smithy/api_getranduser.go +++ b/modules/smithy/api_getranduser.go @@ -1,10 +1,14 @@ package smithy import ( + "context" "go_dreamfactory/comm" + "go_dreamfactory/lego/core" "go_dreamfactory/pb" "go_dreamfactory/utils" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo/options" "google.golang.org/protobuf/proto" ) @@ -20,15 +24,16 @@ func (this *apiComp) GetRandUserCheck(session comm.IUserSession, req *pb.SmithyG /// 获取一些玩家数据 func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.SmithyGetRandUserReq) (code pb.ErrorCode, data proto.Message) { var ( - szDbUser []*pb.DBUser - randOnlineUsers []string + szDbUser []*pb.DBUser + mapUser map[string]struct{} ) + mapUser = make(map[string]struct{}, req.People) code = this.GetRandUserCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } // 获取在线玩家信息 - onlineList, err := this.module.ModuleUser.UserOnlineList() + onlineList, err := this.module.ModuleUser.CrossUserOnlineList() if err != nil { code = pb.ErrorCode_DBError return @@ -36,27 +41,44 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.SmithyGetRan var szUid []string for _, v := range onlineList { - if v.Uid == session.GetUserId() { // 过滤自己信息 + if v.Uid == session.GetUserId() || v.Uid == "" { // 过滤自己信息 continue } - + mapUser[v.Uid] = struct{}{} szUid = append(szUid, v.Uid) } // 随机在线玩家信息 - if len(onlineList) > int(req.People) { - randArr := utils.Numbers(0, len(onlineList), int(req.People)) + if len(szUid) > int(req.People) { + randArr := utils.Numbers(0, len(szUid), int(req.People)) for _, v := range randArr { if szUid[v] != "" { - randOnlineUsers = append(randOnlineUsers, szUid[v]) + mapUser[szUid[v]] = struct{}{} } } } else { // 数量不足 则有多少给多少 for _, v := range szUid { - randOnlineUsers = append(randOnlineUsers, v) + mapUser[v] = struct{}{} + } + left := int(req.People) - len(mapUser) + if left > 0 { // 一个人也没有 那就从db 中随机取 + if _data, err1 := this.module.modelSmithy.DB.Find(core.SqlTable(comm.TableUser), bson.M{}, options.Find().SetSort(bson.M{"lv": -1}).SetLimit(int64(req.People))); err1 == nil { + for _data.Next(context.TODO()) { + temp := &pb.DBUser{} + if err = _data.Decode(temp); err == nil { + if len(mapUser) >= int(req.People) { + break + } + if _, ok := mapUser[temp.Uid]; !ok { + mapUser[temp.Uid] = struct{}{} + } + } + } + } } } - for _, v := range randOnlineUsers { - szDbUser = append(szDbUser, this.module.ModuleUser.GetUser(v)) // 转成user对象 + for k := range mapUser { + user, _ := this.module.ModuleUser.GetCrossUser(k) + szDbUser = append(szDbUser, user) // 转成user对象 } session.SendMsg(string(this.module.GetType()), SmithyGetRandUserResp, &pb.SmithyGetRandUserResp{User: szDbUser}) return diff --git a/modules/timer/chat.go b/modules/timer/chat.go index a4753f69a..fcdcde899 100644 --- a/modules/timer/chat.go +++ b/modules/timer/chat.go @@ -14,7 +14,6 @@ import ( "go_dreamfactory/lego/sys/cron" "go_dreamfactory/lego/sys/log" - "go.mongodb.org/mongo-driver/bson" "google.golang.org/protobuf/types/known/anypb" ) @@ -78,7 +77,6 @@ func (this *ChatComp) Start() (err error) { } } }) - this.module.chat.module.rank.DB.Find("heor", bson.M{}) return } diff --git a/modules/timer/season.go b/modules/timer/season.go index 5d2703aa5..782e6951a 100644 --- a/modules/timer/season.go +++ b/modules/timer/season.go @@ -50,7 +50,7 @@ func (this *SeasonPagoda) Start() (err error) { // _data := this.GetSeasonLoop(2) // this.module.Debugf("%v", _data) - // this.TimerSeasonOver() + this.TimerSeasonOver() return } func (this *SeasonPagoda) GetSeasonLoop(id int32) *cfg.GameSeasonLoopData { @@ -70,9 +70,8 @@ func (this *SeasonPagoda) GetSeasonLoop(id int32) *cfg.GameSeasonLoopData { // // 赛季塔结束 func (this *SeasonPagoda) TimerSeasonOver() { this.module.Debugf("TimerSeasonOver:%d", time.Now().Unix()) - // 修改 - conf := this.GetSeasonLoop(2) - rest, err := this.DB.Find(comm.TableServerData, bson.M{}) + conf := this.GetSeasonLoop(comm.SeasonType) // 获取赛季塔重置配置 + rest, err := this.DB.Find(comm.TableServerData, bson.M{}) // 查询服务器记录的赛季塔信息 if err != nil { serverData := &pb.DBServerData{} for rest.Next(context.TODO()) {