From ce838025f3b05e010d99956fb275b65e21e1c5e8 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 1 Sep 2022 14:41:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=9C=88=E4=B9=8B=E7=A7=98?= =?UTF-8?q?=E5=A2=83=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_msgdistrib.json | 15 +++++++++++++++ comm/imodule.go | 4 +++- modules/chat/modelChat.go | 27 +++++++++++++++++++++++++++ modules/chat/module.go | 28 ++++++++++++++++++++++++++++ modules/moonfantasy/api_trigger.go | 3 ++- modules/moonfantasy/modelDream.go | 10 ++++++++-- services/worker/main.go | 7 +++++++ 7 files changed, 90 insertions(+), 4 deletions(-) diff --git a/bin/json/game_msgdistrib.json b/bin/json/game_msgdistrib.json index b8f2453ec..d6aeafb4c 100644 --- a/bin/json/game_msgdistrib.json +++ b/bin/json/game_msgdistrib.json @@ -38,5 +38,20 @@ "msgid": "chat.send", "routrules": "~/worker", "describe": "聊天消息发送" + }, + { + "msgid": "forum.like", + "routrules": "~/worker", + "describe": "论坛点赞入口" + }, + { + "msgid": "moonfantasy.trigger", + "routrules": "~/worker", + "describe": "月之秘境触发接口" + }, + { + "msgid": "moonfantasy.dare", + "routrules": "~/worker", + "describe": "月之秘境参战接口" } ] \ No newline at end of file diff --git a/comm/imodule.go b/comm/imodule.go index 2619ebaba..fd19972d2 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -124,7 +124,9 @@ type ( //聊天系统 IChat interface { + //推送消息到世界频道 + SendWorldChat(stag string, msg *pb.DBChat) (code pb.ErrorCode) //推送消息到用户 - PushUser(msg *pb.DBChat) (err error) + SendUserChat(msg *pb.DBChat) (code pb.ErrorCode) } ) diff --git a/modules/chat/modelChat.go b/modules/chat/modelChat.go index 87faa28d1..9145c43b0 100644 --- a/modules/chat/modelChat.go +++ b/modules/chat/modelChat.go @@ -13,6 +13,7 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" + "google.golang.org/protobuf/types/known/anypb" ) var worldchatkey = "chat:world" @@ -229,6 +230,32 @@ func (this *modelChatComp) SaveUserMsg(msg *pb.DBChat) (err error) { return } +//发送世界频道聊天 +func (this *modelChatComp) sendWorldChat(stag string, msg *pb.DBChat) (code pb.ErrorCode) { + var ( + err error + max int32 + ) + if max, err = this.module.configure.GetChannelRecordMax(); err != nil { + code = pb.ErrorCode_ConfigNoFound + return + } + if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%s", worldchatkey, stag), int64(max), msg); err != nil { + code = pb.ErrorCode_DBError + return + } + data, _ := anypb.New(&pb.ChatMessagePush{Chat: msg}) + if err = this.module.service.AcrossClusterBroadcast(context.Background(), msg.Stag, comm.Service_Gateway, string(comm.Rpc_GatewaySendRadioMsg), pb.UserMessage{ + MainType: string(this.module.GetType()), + SubType: "message", + Data: data, + }, nil); err != nil { + this.module.Errorf("err:%v", err) + code = pb.ErrorCode_SystemError + } + return +} + func (this *modelChatComp) addChatMsg(key string, count int64, msgs ...*pb.DBChat) (err error) { var ( data map[string]*pb.DBChat = make(map[string]*pb.DBChat, len(msgs)) diff --git a/modules/chat/module.go b/modules/chat/module.go index 5effcbf8b..5cbc9746d 100644 --- a/modules/chat/module.go +++ b/modules/chat/module.go @@ -62,6 +62,34 @@ func (this *Chat) EventUserOffline(session comm.IUserSession) { this.Debugf("EventUserOffline:%s err:%v", session, err) } +//对外接口---------------------------------------------------------------------------------------------------------- +//向世界频道发送聊天消息 +func (this *Chat) SendWorldChat(stag string, msg *pb.DBChat) (code pb.ErrorCode) { + code = this.modelChat.sendWorldChat(stag, msg) + return +} + +//向个人发送聊天消息 +func (this *Chat) SendUserChat(msg *pb.DBChat) (code pb.ErrorCode) { + var ( + err error + ) + if session, ok := this.GetUserSession(msg.Ruid); ok { + session.SendMsg(string(this.GetType()), "message", &pb.ChatMessagePush{Chat: msg}) + if err = session.Push(); err != nil { + this.Errorf("err:%v", err) + code = pb.ErrorCode_SystemError + } + return + } else { + if err = this.modelChat.SaveUserMsg(msg); err != nil { + code = pb.ErrorCode_DBError + return + } + } + return +} + //Push-------------------------------------------------------------------------------------------------------------- //推送消息到世界 func (this *Chat) PushWorld(msg *pb.DBChat) (err error) { diff --git a/modules/moonfantasy/api_trigger.go b/modules/moonfantasy/api_trigger.go index ac85a4313..9b3574bdc 100644 --- a/modules/moonfantasy/api_trigger.go +++ b/modules/moonfantasy/api_trigger.go @@ -8,6 +8,7 @@ import ( "math/big" "time" + "go.mongodb.org/mongo-driver/mongo" "google.golang.org/protobuf/proto" ) @@ -38,7 +39,7 @@ func (this *apiComp) Trigger(session comm.IUserSession, req *pb.MoonfantasyTrigg issucc = false } if issucc { - if uexpand, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { + if uexpand, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil && err != mongo.ErrNoDocuments { code = pb.ErrorCode_DBError this.module.Errorln(err) return diff --git a/modules/moonfantasy/modelDream.go b/modules/moonfantasy/modelDream.go index da78c14af..eb70cc4be 100644 --- a/modules/moonfantasy/modelDream.go +++ b/modules/moonfantasy/modelDream.go @@ -60,7 +60,10 @@ func (this *modelDreamComp) addDreamData(uid string, boss *cfg.GameDreamlandBoos } ///查询好友数据 -func (this *modelDreamComp) noticeuserfriend(stag, uid string, chat *pb.DBChat) (err error) { +func (this *modelDreamComp) noticeuserfriend(stag, uid string, chat *pb.DBChat) (code pb.ErrorCode) { + var ( + err error + ) model := db.NewDBModel(comm.TableFriend, 0, db.ServerDBConn(stag)) friend := &pb.DBFriend{Uid: uid} if err = model.Get(uid, friend); err != nil { @@ -72,7 +75,10 @@ func (this *modelDreamComp) noticeuserfriend(stag, uid string, chat *pb.DBChat) temp.Id = primitive.NewObjectID().Hex() temp.Channel = pb.ChatChannel_Private temp.Ruid = v - this.module.chat.PushUser(&temp) + this.module.chat.SendUserChat(&temp) } + chat.Id = primitive.NewObjectID().Hex() + chat.Channel = pb.ChatChannel_World + code = this.module.chat.SendWorldChat(stag, chat) return } diff --git a/services/worker/main.go b/services/worker/main.go index 82636eca0..dacfd15fd 100644 --- a/services/worker/main.go +++ b/services/worker/main.go @@ -29,6 +29,7 @@ import ( "go_dreamfactory/lego" "go_dreamfactory/lego/base/rpcx" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/cron" "go_dreamfactory/lego/sys/log" ) @@ -88,6 +89,12 @@ type Service struct { //初始化worker需要的一些系统工具 func (this *Service) InitSys() { this.ServiceBase.InitSys() + //定时系统 + if err := cron.OnInit(nil); err != nil { + panic(fmt.Sprintf("init sys.cron err: %s", err.Error())) + } else { + log.Infof("init sys.cron success!") + } //存储系统 if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil { panic(fmt.Sprintf("init sys.db err: %s", err.Error()))