From c4890b796b9fd6d5f8653899b62b703f62b031c3 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 31 Aug 2022 19:45:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=9C=88=E5=AD=90=E7=A7=98?= =?UTF-8?q?=E5=A2=83=20=E5=AF=B9=E6=8E=A5=E8=81=8A=E5=A4=A9=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=8E=A8=E9=80=81=E5=A5=BD=E5=8F=8B=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 6 ++++++ modules/moonfantasy/api_trigger.go | 11 ++++++++++ modules/moonfantasy/modelDream.go | 19 +++++++++++++++++ modules/moonfantasy/module.go | 14 +++++++++++++ pb/moonfantasy_msg.pb.go | 33 ++++++++++++++++++++++++++++-- 5 files changed, 81 insertions(+), 2 deletions(-) diff --git a/comm/imodule.go b/comm/imodule.go index 94e53d145..2619ebaba 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -121,4 +121,10 @@ type ( // 重置点赞列表和每日友情点 ResetFriend(uid string) } + + //聊天系统 + IChat interface { + //推送消息到用户 + PushUser(msg *pb.DBChat) (err error) + } ) diff --git a/modules/moonfantasy/api_trigger.go b/modules/moonfantasy/api_trigger.go index 178a845cb..ac85a4313 100644 --- a/modules/moonfantasy/api_trigger.go +++ b/modules/moonfantasy/api_trigger.go @@ -23,6 +23,7 @@ func (this *apiComp) Trigger(session comm.IUserSession, req *pb.MoonfantasyTrigg uexpand *pb.DBUserExpand boss *cfg.GameDreamlandBoosData mdata *pb.DBMoonfantasy + chat *pb.DBChat issucc bool err error ) @@ -64,6 +65,16 @@ func (this *apiComp) Trigger(session comm.IUserSession, req *pb.MoonfantasyTrigg "moonfantasyTriggerNum": uexpand.MoonfantasyTriggerNum + 1, "moonfantasyLastTrigger": time.Now().Unix(), }) + chat = &pb.DBChat{ + Ctype: pb.ChatType_Moonfantasy, + Suid: session.GetUserId(), + Avatar: req.Avatar, + Uname: req.Uname, + Slv: req.Ulv, + AppendInt: int64(mdata.Monster), + AppendStr: mdata.Id, + } + this.module.modelDream.noticeuserfriend(session.GetServiecTag(), session.GetUserId(), chat) session.SendMsg(string(this.module.GetType()), "trigger", &pb.MoonfantasyTriggerResp{Issucc: true, Mid: mdata.Id, Monster: mdata.Monster}) } else { session.SendMsg(string(this.module.GetType()), "trigger", &pb.MoonfantasyTriggerResp{Issucc: false}) diff --git a/modules/moonfantasy/modelDream.go b/modules/moonfantasy/modelDream.go index f89a843bd..da78c14af 100644 --- a/modules/moonfantasy/modelDream.go +++ b/modules/moonfantasy/modelDream.go @@ -6,6 +6,7 @@ import ( "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" + "go_dreamfactory/sys/db" "time" "go.mongodb.org/mongo-driver/bson/primitive" @@ -57,3 +58,21 @@ func (this *modelDreamComp) addDreamData(uid string, boss *cfg.GameDreamlandBoos } return } + +///查询好友数据 +func (this *modelDreamComp) noticeuserfriend(stag, uid string, chat *pb.DBChat) (err error) { + model := db.NewDBModel(comm.TableFriend, 0, db.ServerDBConn(stag)) + friend := &pb.DBFriend{Uid: uid} + if err = model.Get(uid, friend); err != nil { + this.module.Errorln(err) + return + } + for _, v := range friend.FriendIds { + temp := *chat + temp.Id = primitive.NewObjectID().Hex() + temp.Channel = pb.ChatChannel_Private + temp.Ruid = v + this.module.chat.PushUser(&temp) + } + return +} diff --git a/modules/moonfantasy/module.go b/modules/moonfantasy/module.go index 8f5fb8a6e..2877d3520 100644 --- a/modules/moonfantasy/module.go +++ b/modules/moonfantasy/module.go @@ -2,6 +2,7 @@ package moonfantasy import ( "go_dreamfactory/comm" + "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/modules" ) @@ -18,6 +19,8 @@ func NewModule() core.IModule { type Moonfantasy struct { modules.ModuleBase + service base.IRPCXService + chat comm.IChat api_comp *apiComp configure *configureComp modelDream *modelDreamComp @@ -31,6 +34,17 @@ func (this *Moonfantasy) GetType() core.M_Modules { //模块初始化接口 注册用户创建角色事件 func (this *Moonfantasy) 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 +} + +func (this *Moonfantasy) Start() (err error) { + err = this.ModuleBase.Start() + var module core.IModule + if module, err = this.service.GetModule(comm.ModuleChat); err != nil { + return + } + this.chat = module.(comm.IChat) return } diff --git a/pb/moonfantasy_msg.pb.go b/pb/moonfantasy_msg.pb.go index 9f9c795aa..db85829fd 100644 --- a/pb/moonfantasy_msg.pb.go +++ b/pb/moonfantasy_msg.pb.go @@ -25,6 +25,10 @@ type MoonfantasyTriggerReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + Avatar string `protobuf:"bytes,1,opt,name=avatar,proto3" json:"avatar"` //用户头像 + Uname string `protobuf:"bytes,2,opt,name=uname,proto3" json:"uname"` //用户名 + Ulv int32 `protobuf:"varint,3,opt,name=ulv,proto3" json:"ulv"` //用户等级 } func (x *MoonfantasyTriggerReq) Reset() { @@ -59,6 +63,27 @@ func (*MoonfantasyTriggerReq) Descriptor() ([]byte, []int) { return file_moonfantasy_moonfantasy_msg_proto_rawDescGZIP(), []int{0} } +func (x *MoonfantasyTriggerReq) GetAvatar() string { + if x != nil { + return x.Avatar + } + return "" +} + +func (x *MoonfantasyTriggerReq) GetUname() string { + if x != nil { + return x.Uname + } + return "" +} + +func (x *MoonfantasyTriggerReq) GetUlv() int32 { + if x != nil { + return x.Ulv + } + return 0 +} + ///触发秘境 type MoonfantasyTriggerResp struct { state protoimpl.MessageState @@ -231,8 +256,12 @@ var File_moonfantasy_moonfantasy_msg_proto protoreflect.FileDescriptor var file_moonfantasy_moonfantasy_msg_proto_rawDesc = []byte{ 0x0a, 0x21, 0x6d, 0x6f, 0x6f, 0x6e, 0x66, 0x61, 0x6e, 0x74, 0x61, 0x73, 0x79, 0x2f, 0x6d, 0x6f, 0x6f, 0x6e, 0x66, 0x61, 0x6e, 0x74, 0x61, 0x73, 0x79, 0x5f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x22, 0x17, 0x0a, 0x15, 0x4d, 0x6f, 0x6f, 0x6e, 0x66, 0x61, 0x6e, 0x74, 0x61, - 0x73, 0x79, 0x54, 0x72, 0x69, 0x67, 0x67, 0x65, 0x72, 0x52, 0x65, 0x71, 0x22, 0x5c, 0x0a, 0x16, + 0x6f, 0x74, 0x6f, 0x22, 0x57, 0x0a, 0x15, 0x4d, 0x6f, 0x6f, 0x6e, 0x66, 0x61, 0x6e, 0x74, 0x61, + 0x73, 0x79, 0x54, 0x72, 0x69, 0x67, 0x67, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, + 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x76, + 0x61, 0x74, 0x61, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x75, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x05, 0x75, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x6c, + 0x76, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x75, 0x6c, 0x76, 0x22, 0x5c, 0x0a, 0x16, 0x4d, 0x6f, 0x6f, 0x6e, 0x66, 0x61, 0x6e, 0x74, 0x61, 0x73, 0x79, 0x54, 0x72, 0x69, 0x67, 0x67, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x73, 0x73, 0x75, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x73, 0x73, 0x75, 0x63, 0x63, 0x12, 0x10,