上传月之秘境代码
This commit is contained in:
parent
30a1a48af8
commit
ce838025f3
@ -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": "月之秘境参战接口"
|
||||
}
|
||||
]
|
@ -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)
|
||||
}
|
||||
)
|
||||
|
@ -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))
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()))
|
||||
|
Loading…
Reference in New Issue
Block a user