From eb93beb54ac2346a6c54e6180c4000c542672451 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 19 Oct 2022 14:19:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=20=E7=A7=98=E5=A2=83?= =?UTF-8?q?=E4=B8=8E=E8=81=8A=E5=A4=A9=E7=B3=BB=E7=BB=9F=E8=B7=A8=E6=9C=8D?= =?UTF-8?q?=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_msgdistrib.json | 24 +++ comm/const.go | 2 + comm/usersession.go | 15 +- modules/chat/__api_getlist.go | 77 +++++++ modules/chat/__api_send.go | 116 ++++++++++ modules/chat/api_getcrosslist.go | 77 ------- modules/chat/api_getlist.go | 46 ++-- modules/chat/api_send.go | 61 +++--- modules/chat/api_sendcross.go | 117 ---------- modules/chat/core.go | 13 ++ modules/chat/modelChat.go | 5 +- modules/modulebase.go | 5 + modules/moonfantasy/modelDream.go | 37 ++-- modules/moonfantasy/module.go | 41 +++- modules/timer/chat.go | 2 +- pb/chat_db.pb.go | 34 +-- pb/comm.pb.go | 344 ++++++++++++++++++++++++++++-- sys/db/core.go | 6 + sys/db/db.go | 6 +- 19 files changed, 719 insertions(+), 309 deletions(-) create mode 100644 modules/chat/__api_getlist.go create mode 100644 modules/chat/__api_send.go delete mode 100644 modules/chat/api_getcrosslist.go delete mode 100644 modules/chat/api_sendcross.go create mode 100644 modules/chat/core.go diff --git a/bin/json/game_msgdistrib.json b/bin/json/game_msgdistrib.json index ca356330d..dcb13d304 100644 --- a/bin/json/game_msgdistrib.json +++ b/bin/json/game_msgdistrib.json @@ -11,6 +11,12 @@ "routrules": "~/worker", "describe": "论坛系统" }, + { + "msgid": "chat", + "open": true, + "routrules": "~/worker", + "describe": "聊天系统" + }, { "msgid": "chat.chanagechannel", "open": true, @@ -46,5 +52,23 @@ "open": true, "routrules": "~/worker", "describe": "查询英雄详细" + }, + { + "msgid": "friend.apply", + "open": true, + "routrules": "~/worker", + "describe": "好友申请" + }, + { + "msgid": "friend.agree", + "open": true, + "routrules": "~/worker", + "describe": "同意" + }, + { + "msgid": "friend.refuse", + "open": true, + "routrules": "~/worker", + "describe": "拒绝" } ] \ No newline at end of file diff --git a/comm/const.go b/comm/const.go index 177ec6bef..65a0d1144 100644 --- a/comm/const.go +++ b/comm/const.go @@ -161,6 +161,8 @@ const ( //Rpc Rpc_GatewayNoticeUserClose core.Rpc_Key = "Rpc_NoticeUserClose" //通知用户离线 //GM 后台消息 Rpc_GMReleaseChatSystemMessage core.Rpc_Key = "Rpc_GMChatReleaseSystemMessage" //发布聊天系统消息 + //Moonfantasy 月之秘境 + Rpc_ModuleMoonfantasyTrigger core.Rpc_Key = "Rpc_ModuleMoonfantasyTrigger" //月之秘境触发消息 ) //事件类型定义处 diff --git a/comm/usersession.go b/comm/usersession.go index 50bc7f631..bfda5793c 100644 --- a/comm/usersession.go +++ b/comm/usersession.go @@ -142,13 +142,16 @@ func (this *UserSession) Polls() []*pb.UserMessage { return msgs } +//推送消息到用户 func (this *UserSession) Push() (err error) { - reply := &pb.RPCMessageReply{} - if _, err = this.service.AcrossClusterRpcGo(context.Background(), this.ServiceTag, fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{ - UserSessionId: this.SessionId, - Reply: this.msgqueue, - }, reply); err != nil { - log.Errorf("SendMsgToUsers:%v err:%v", this, err) + // reply := &pb.RPCMessageReply{} + if len(this.msgqueue) > 0 { + if _, err = this.service.AcrossClusterRpcGo(context.Background(), this.ServiceTag, fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{ + UserSessionId: this.SessionId, + Reply: this.msgqueue, + }, nil); err != nil { + log.Errorf("SendMsgToUsers:%v err:%v", this, err) + } } return } diff --git a/modules/chat/__api_getlist.go b/modules/chat/__api_getlist.go new file mode 100644 index 000000000..1b1a3b482 --- /dev/null +++ b/modules/chat/__api_getlist.go @@ -0,0 +1,77 @@ +package chat + +// import ( +// "go_dreamfactory/comm" +// "go_dreamfactory/pb" + +// "google.golang.org/protobuf/proto" +// ) + +// //参数校验 +// func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.ChatGetListReq) (code pb.ErrorCode) { +// if req.Channel == pb.ChatChannel_World && req.ChannelId == 0 { +// code = pb.ErrorCode_ReqParameterError +// } +// return +// } + +// ///获取本服聊天消息记录 +// func (this *apiComp) GetList(session comm.IUserSession, req *pb.ChatGetListReq) (code pb.ErrorCode, data proto.Message) { +// var ( +// err error +// // result *pb.DBUserExpand +// list []*pb.DBChat +// ) + +// if code = this.GetListCheck(session, req); code != pb.ErrorCode_Success { +// return +// } + +// switch req.Channel { +// case pb.ChatChannel_World: +// if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", 0); err != nil { +// code = pb.ErrorCode_DBError +// return +// } +// break +// case pb.ChatChannel_Union: +// if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", 0); err != nil { +// code = pb.ErrorCode_DBError +// return +// } +// break +// case pb.ChatChannel_Private: +// if list, err = this.module.modelChat.QueryUserMsg(session.GetUserId()); err != nil { +// code = pb.ErrorCode_DBError +// return +// } +// break +// // case pb.ChatChannel_CrossServer: +// // if result, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { +// // this.module.Errorf("err:%v", err) +// // code = pb.ErrorCode_DBError +// // return +// // } +// // if req.ChannelId != result.Chatchannel { +// // code = pb.ErrorCode_ReqParameterError +// // return +// // } +// // if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", req.ChannelId); err != nil { +// // code = pb.ErrorCode_DBError +// // return +// // } +// // break +// case pb.ChatChannel_System: +// if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", 0); err != nil { +// code = pb.ErrorCode_DBError +// return +// } +// break +// default: +// code = pb.ErrorCode_ReqParameterError +// this.module.Errorf("getlist no support channel:%d ", req.Channel) +// return +// } +// session.SendMsg(string(this.module.GetType()), "getlist", &pb.ChatGetListResp{Chats: list}) +// return +// } diff --git a/modules/chat/__api_send.go b/modules/chat/__api_send.go new file mode 100644 index 000000000..bc7b5dde7 --- /dev/null +++ b/modules/chat/__api_send.go @@ -0,0 +1,116 @@ +package chat + +// import ( +// "fmt" +// "go_dreamfactory/comm" +// "go_dreamfactory/pb" +// "time" + +// "go.mongodb.org/mongo-driver/bson/primitive" +// "google.golang.org/protobuf/proto" +// ) + +// //参数校验 +// func (this *apiComp) SendCheck(session comm.IUserSession, req *pb.ChatSendReq) (code pb.ErrorCode) { +// if (req.Channel == pb.ChatChannel_Union && req.TargetId == "") || (req.Channel == pb.ChatChannel_Private && req.TargetId == "") { +// code = pb.ErrorCode_ReqParameterError +// } +// return +// } + +// ///消息发送请求 +// func (this *apiComp) Send(session comm.IUserSession, req *pb.ChatSendReq) (code pb.ErrorCode, data proto.Message) { +// var ( +// err error +// max int32 +// msg *pb.DBChat +// // userexpand *pb.DBUserExpand +// max_chat int32 +// ) +// if code = this.SendCheck(session, req); code != pb.ErrorCode_Success { +// return +// } + +// msg = &pb.DBChat{ +// Id: primitive.NewObjectID().Hex(), +// Channel: req.Channel, +// Suid: session.GetUserId(), +// Slv: req.Ulv, +// Uname: req.Uname, +// Avatar: req.Avatar, +// Stag: session.GetServiecTag(), +// Ctype: req.Ctype, +// Content: req.Content, +// Ctime: time.Now().Unix(), +// AppendInt: req.AppendInt, +// AppendStr: req.AppendStr, +// AppendBool: req.AppendBool, +// AppendBytes: req.AppendBytes, +// } +// if max, err = this.module.configure.GetChannelRecordMax(); err != nil { +// code = pb.ErrorCode_ConfigNoFound +// return +// } +// if max_chat, err = this.module.configure.GetChannelRecordMax(); err != nil { +// code = pb.ErrorCode_ConfigNoFound +// return +// } +// switch msg.Channel { +// case pb.ChatChannel_World: +// if this.module.options.GM { //判断gm命令 +// if code = this.module.gm.CreateCmd(session, req.Content); code == pb.ErrorCode_Success { +// session.SendMsg(string(this.module.GetType()), "send", &pb.ChatSendResp{Issucc: true}) +// return +// } +// code = pb.ErrorCode_Success +// } + +// if err = this.module.modelChat.addChatMsg(worldchatkey, int64(max), msg); err != nil { +// code = pb.ErrorCode_DBError +// return +// } +// if err = this.module.PushWorld(msg); err != nil { +// code = pb.ErrorCode_DBError +// return +// } +// //随机任务 +// this.module.ModuleRtask.SendToRtask(session, comm.Rtype62, 1) +// break +// case pb.ChatChannel_Union: +// msg.UnionId = req.TargetId +// if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s:%s", unionchatkey, req.TargetId), int64(max_chat), msg); err != nil { +// code = pb.ErrorCode_DBError +// return +// } +// if err = this.module.PushUnion(req.TargetId, msg); err != nil { +// code = pb.ErrorCode_DBError +// return +// } +// break +// case pb.ChatChannel_Private: +// msg.Ruid = req.TargetId +// if err = this.module.PushUser(msg); err != nil { +// code = pb.ErrorCode_DBError +// return +// } +// session.SendMsg(string(this.module.GetType()), "message", &pb.ChatMessagePush{Chat: msg}) +// break +// // case pb.ChatChannel_CrossServer: +// // if userexpand, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { +// // code = pb.ErrorCode_DBError +// // return +// // } +// // msg.ChannelId = userexpand.Chatchannel //指定频道 +// // if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%d", crosschatkey, userexpand.Chatchannel), int64(max_chat), msg); err != nil { +// // code = pb.ErrorCode_DBError +// // return +// // } +// // this.module.PushToUsers(userexpand.Chatchannel, msg) +// default: +// code = pb.ErrorCode_ReqParameterError +// this.module.Errorf("getlist no support channel:%d ", req.Channel) +// return +// } +// session.SendMsg(string(this.module.GetType()), "send", &pb.ChatSendResp{Issucc: true}) +// return +// } diff --git a/modules/chat/api_getcrosslist.go b/modules/chat/api_getcrosslist.go deleted file mode 100644 index f24839fbd..000000000 --- a/modules/chat/api_getcrosslist.go +++ /dev/null @@ -1,77 +0,0 @@ -package chat - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" - - "google.golang.org/protobuf/proto" -) - -//参数校验 -func (this *apiComp) GetCrossListCheck(session comm.IUserSession, req *pb.ChatGetCrossListReq) (code pb.ErrorCode) { - if req.Channel == pb.ChatChannel_World && req.ChannelId == 0 { - code = pb.ErrorCode_ReqParameterError - } - return -} - -///获取本服聊天消息记录 -func (this *apiComp) GetCrossList(session comm.IUserSession, req *pb.ChatGetCrossListReq) (code pb.ErrorCode, data proto.Message) { - var ( - err error - result *pb.DBUserExpand - list []*pb.DBChat - ) - - if code = this.GetCrossListCheck(session, req); code != pb.ErrorCode_Success { - return - } - - switch req.Channel { - // case pb.ChatChannel_World: - // if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", 0); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // break - // case pb.ChatChannel_Union: - // if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", 0); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // break - // case pb.ChatChannel_Private: - // if list, err = this.module.modelChat.QueryUserMsg(session.GetUserId()); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // break - case pb.ChatChannel_CrossServer: - if result, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { - this.module.Errorf("err:%v", err) - code = pb.ErrorCode_DBError - return - } - if req.ChannelId != result.Chatchannel { - code = pb.ErrorCode_ReqParameterError - return - } - if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", req.ChannelId); err != nil { - code = pb.ErrorCode_DBError - return - } - break - // case pb.ChatChannel_System: - // if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", 0); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // break - default: - code = pb.ErrorCode_ReqParameterError - this.module.Errorf("getlist no support channel:%d ", req.Channel) - return - } - session.SendMsg(string(this.module.GetType()), "getcrosslist", &pb.ChatGetCrossListResp{Chats: list}) - return -} diff --git a/modules/chat/api_getlist.go b/modules/chat/api_getlist.go index 9c037b5ab..e6c383392 100644 --- a/modules/chat/api_getlist.go +++ b/modules/chat/api_getlist.go @@ -8,7 +8,7 @@ import ( ) //参数校验 -func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.ChatGetListReq) (code pb.ErrorCode) { +func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.ChatGetCrossListReq) (code pb.ErrorCode) { if req.Channel == pb.ChatChannel_World && req.ChannelId == 0 { code = pb.ErrorCode_ReqParameterError } @@ -16,11 +16,11 @@ func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.ChatGetList } ///获取本服聊天消息记录 -func (this *apiComp) GetList(session comm.IUserSession, req *pb.ChatGetListReq) (code pb.ErrorCode, data proto.Message) { +func (this *apiComp) GetList(session comm.IUserSession, req *pb.ChatGetCrossListReq) (code pb.ErrorCode, data proto.Message) { var ( - err error - // result *pb.DBUserExpand - list []*pb.DBChat + err error + result *pb.DBUserExpand + list []*pb.DBChat ) if code = this.GetListCheck(session, req); code != pb.ErrorCode_Success { @@ -46,32 +46,32 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.ChatGetListReq) return } break - // case pb.ChatChannel_CrossServer: - // if result, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { - // this.module.Errorf("err:%v", err) - // code = pb.ErrorCode_DBError - // return - // } - // if req.ChannelId != result.Chatchannel { - // code = pb.ErrorCode_ReqParameterError - // return - // } - // if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", req.ChannelId); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // break - case pb.ChatChannel_System: - if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", 0); err != nil { + case pb.ChatChannel_CrossServer: + if result, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { + this.module.Errorf("err:%v", err) + code = pb.ErrorCode_DBError + return + } + if req.ChannelId != result.Chatchannel { + code = pb.ErrorCode_ReqParameterError + return + } + if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", req.ChannelId); err != nil { code = pb.ErrorCode_DBError return } break + // case pb.ChatChannel_System: + // if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", 0); err != nil { + // code = pb.ErrorCode_DBError + // return + // } + // break default: code = pb.ErrorCode_ReqParameterError this.module.Errorf("getlist no support channel:%d ", req.Channel) return } - session.SendMsg(string(this.module.GetType()), "getlist", &pb.ChatGetListResp{Chats: list}) + session.SendMsg(string(this.module.GetType()), "getcrosslist", &pb.ChatGetCrossListResp{Chats: list}) return } diff --git a/modules/chat/api_send.go b/modules/chat/api_send.go index e9e1e1815..a9eb1ae05 100644 --- a/modules/chat/api_send.go +++ b/modules/chat/api_send.go @@ -11,7 +11,7 @@ import ( ) //参数校验 -func (this *apiComp) SendCheck(session comm.IUserSession, req *pb.ChatSendReq) (code pb.ErrorCode) { +func (this *apiComp) SendCheck(session comm.IUserSession, req *pb.ChatSendCrossReq) (code pb.ErrorCode) { if (req.Channel == pb.ChatChannel_Union && req.TargetId == "") || (req.Channel == pb.ChatChannel_Private && req.TargetId == "") { code = pb.ErrorCode_ReqParameterError } @@ -19,13 +19,13 @@ func (this *apiComp) SendCheck(session comm.IUserSession, req *pb.ChatSendReq) ( } ///消息发送请求 -func (this *apiComp) Send(session comm.IUserSession, req *pb.ChatSendReq) (code pb.ErrorCode, data proto.Message) { +func (this *apiComp) Send(session comm.IUserSession, req *pb.ChatSendCrossReq) (code pb.ErrorCode, data proto.Message) { var ( - err error - max int32 - msg *pb.DBChat - // userexpand *pb.DBUserExpand - max_chat int32 + err error + max int32 + msg *pb.DBChat + userexpand *pb.DBUserExpand + max_chat int32 ) if code = this.SendCheck(session, req); code != pb.ErrorCode_Success { return @@ -58,14 +58,14 @@ func (this *apiComp) Send(session comm.IUserSession, req *pb.ChatSendReq) (code switch msg.Channel { case pb.ChatChannel_World: if this.module.options.GM { //判断gm命令 - if code = this.module.gm.CreateCmd(session, req.Content); code == pb.ErrorCode_Success { + if IsCmd(req.Content) { //是否是GM命令 session.SendMsg(string(this.module.GetType()), "send", &pb.ChatSendResp{Issucc: true}) return } code = pb.ErrorCode_Success } - if err = this.module.modelChat.addChatMsg(worldchatkey, int64(max), msg); err != nil { + if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%s", worldchatkey, session.GetServiecTag()), int64(max), msg); err != nil { code = pb.ErrorCode_DBError return } @@ -74,7 +74,7 @@ func (this *apiComp) Send(session comm.IUserSession, req *pb.ChatSendReq) (code return } //随机任务 - this.module.ModuleRtask.SendToRtask(session, comm.Rtype62, 1) + // this.module.ModuleRtask.SendToRtask(session, comm.Rtype62, 1) break case pb.ChatChannel_Union: msg.UnionId = req.TargetId @@ -87,30 +87,31 @@ func (this *apiComp) Send(session comm.IUserSession, req *pb.ChatSendReq) (code return } break - // case pb.ChatChannel_Private: - // msg.Ruid = req.TargetId - // if err = this.module.PushUser(msg); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // session.SendMsg(string(this.module.GetType()), "message", &pb.ChatMessagePush{Chat: msg}) - // break - // case pb.ChatChannel_CrossServer: - // if userexpand, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // msg.ChannelId = userexpand.Chatchannel //指定频道 - // if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%d", crosschatkey, userexpand.Chatchannel), int64(max_chat), msg); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // this.module.PushToUsers(userexpand.Chatchannel, msg) + case pb.ChatChannel_Private: + msg.Ruid = req.TargetId + if err = this.module.PushUser(msg); err != nil { + code = pb.ErrorCode_DBError + return + } + session.SendMsg(string(this.module.GetType()), "message", &pb.ChatMessagePush{Chat: msg}) + break + case pb.ChatChannel_CrossServer: + if userexpand, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { + code = pb.ErrorCode_DBError + return + } + msg.ChannelId = userexpand.Chatchannel //指定频道 + if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%d", crosschatkey, userexpand.Chatchannel), int64(max_chat), msg); err != nil { + code = pb.ErrorCode_DBError + return + } + this.module.PushToUsers(userexpand.Chatchannel, msg) + break default: code = pb.ErrorCode_ReqParameterError this.module.Errorf("getlist no support channel:%d ", req.Channel) return } - session.SendMsg(string(this.module.GetType()), "send", &pb.ChatSendResp{Issucc: true}) + session.SendMsg(string(this.module.GetType()), "sendcross", &pb.ChatSendCrossResp{Issucc: true}) return } diff --git a/modules/chat/api_sendcross.go b/modules/chat/api_sendcross.go deleted file mode 100644 index 82cc955ce..000000000 --- a/modules/chat/api_sendcross.go +++ /dev/null @@ -1,117 +0,0 @@ -package chat - -import ( - "fmt" - "go_dreamfactory/comm" - "go_dreamfactory/pb" - "time" - - "go.mongodb.org/mongo-driver/bson/primitive" - "google.golang.org/protobuf/proto" -) - -//参数校验 -func (this *apiComp) SendCrossCheck(session comm.IUserSession, req *pb.ChatSendCrossReq) (code pb.ErrorCode) { - if (req.Channel == pb.ChatChannel_Union && req.TargetId == "") || (req.Channel == pb.ChatChannel_Private && req.TargetId == "") { - code = pb.ErrorCode_ReqParameterError - } - return -} - -///消息发送请求 -func (this *apiComp) SendCross(session comm.IUserSession, req *pb.ChatSendCrossReq) (code pb.ErrorCode, data proto.Message) { - var ( - err error - // max int32 - msg *pb.DBChat - userexpand *pb.DBUserExpand - max_chat int32 - ) - if code = this.SendCrossCheck(session, req); code != pb.ErrorCode_Success { - return - } - - msg = &pb.DBChat{ - Id: primitive.NewObjectID().Hex(), - Channel: req.Channel, - Suid: session.GetUserId(), - Slv: req.Ulv, - Uname: req.Uname, - Avatar: req.Avatar, - Stag: session.GetServiecTag(), - Ctype: req.Ctype, - Content: req.Content, - Ctime: time.Now().Unix(), - AppendInt: req.AppendInt, - AppendStr: req.AppendStr, - AppendBool: req.AppendBool, - AppendBytes: req.AppendBytes, - } - // if max, err = this.module.configure.GetChannelRecordMax(); err != nil { - // code = pb.ErrorCode_ConfigNoFound - // return - // } - if max_chat, err = this.module.configure.GetChannelRecordMax(); err != nil { - code = pb.ErrorCode_ConfigNoFound - return - } - switch msg.Channel { - // case pb.ChatChannel_World: - // if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%s", worldchatkey, session.GetServiecTag()), int64(max), msg); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // if err = this.module.PushWorld(msg); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // //随机任务 - // this.module.ModuleRtask.SendToRtask(session, comm.Rtype62, 1) - // break - // case pb.ChatChannel_Union: - // msg.UnionId = req.TargetId - // if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s:%s", unionchatkey, req.TargetId), int64(max_chat), msg); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // if err = this.module.PushUnion(req.TargetId, msg); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // break - // case pb.ChatChannel_Private: - // msg.Ruid = req.TargetId - // if err = this.module.PushUser(msg); err != nil { - // code = pb.ErrorCode_DBError - // return - // } - // session.SendMsg(string(this.module.GetType()), "message", &pb.ChatMessagePush{Chat: msg}) - // break - case pb.ChatChannel_Private: - msg.Ruid = req.TargetId - if err = this.module.PushUser(msg); err != nil { - code = pb.ErrorCode_DBError - return - } - session.SendMsg(string(this.module.GetType()), "message", &pb.ChatMessagePush{Chat: msg}) - break - case pb.ChatChannel_CrossServer: - if userexpand, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { - code = pb.ErrorCode_DBError - return - } - msg.ChannelId = userexpand.Chatchannel //指定频道 - if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%d", crosschatkey, userexpand.Chatchannel), int64(max_chat), msg); err != nil { - code = pb.ErrorCode_DBError - return - } - this.module.PushToUsers(userexpand.Chatchannel, msg) - break - default: - code = pb.ErrorCode_ReqParameterError - this.module.Errorf("getlist no support channel:%d ", req.Channel) - return - } - session.SendMsg(string(this.module.GetType()), "sendcross", &pb.ChatSendCrossResp{Issucc: true}) - return -} diff --git a/modules/chat/core.go b/modules/chat/core.go new file mode 100644 index 000000000..090800d42 --- /dev/null +++ b/modules/chat/core.go @@ -0,0 +1,13 @@ +package chat + +import "strings" + +func IsCmd(cmd string) bool { + keys := strings.Split(cmd, ":") + if len(keys) == 2 { + if keys[0] == "bingo" { + return true + } + } + return false +} diff --git a/modules/chat/modelChat.go b/modules/chat/modelChat.go index 7eb7f36e9..2a87cedd5 100644 --- a/modules/chat/modelChat.go +++ b/modules/chat/modelChat.go @@ -75,7 +75,8 @@ func (this *modelChatComp) getChatQueue(channel pb.ChatChannel, stag, union stri ) switch channel { case pb.ChatChannel_World: - key = worldchatkey + // key = worldchatkey + key = fmt.Sprintf("%s-%s", worldchatkey, stag) find = bson.M{"channel": channel} break case pb.ChatChannel_Union: @@ -240,7 +241,7 @@ func (this *modelChatComp) sendWorldChat(msg *pb.DBChat) (code pb.ErrorCode) { code = pb.ErrorCode_ConfigNoFound return } - if err = this.module.modelChat.addChatMsg(worldchatkey, int64(max), msg); err != nil { + if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%s", worldchatkey, msg.Stag), int64(max), msg); err != nil { code = pb.ErrorCode_DBError return } diff --git a/modules/modulebase.go b/modules/modulebase.go index 79b3c865a..26de96db9 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -104,6 +104,11 @@ func (this *ModuleBase) Start() (err error) { return } +//判断当前环境是本服还还是跨服 +func (this *ModuleBase) IsCross() bool { + return db.IsCross() +} + //获取跨服标签 func (this *ModuleBase) GetCrossTag() string { return db.CrossTag() diff --git a/modules/moonfantasy/modelDream.go b/modules/moonfantasy/modelDream.go index cf8027851..77e5fc45c 100644 --- a/modules/moonfantasy/modelDream.go +++ b/modules/moonfantasy/modelDream.go @@ -4,13 +4,11 @@ import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" - "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/lego/sys/redis" "go_dreamfactory/lego/sys/timewheel" "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" - "go_dreamfactory/sys/db" "time" "go.mongodb.org/mongo-driver/bson/primitive" @@ -86,7 +84,7 @@ func (this *modelDreamComp) addDreamData(user *pb.UserInfo, boss *cfg.GameDreaml } //触发月之秘境 -func (this *modelDreamComp) trigger(session comm.IUserSession, source *pb.BattleReport) { +func (this *modelDreamComp) trigger(session comm.IUserSession) { var ( user *pb.DBUser umfantasy *pb.DBUserMFantasy @@ -153,20 +151,22 @@ func (this *modelDreamComp) trigger(session comm.IUserSession, source *pb.Battle ///查询好友数据 func (this *modelDreamComp) noticeuserfriend(session comm.IUserSession, mid string, chat *pb.DBChat) (code pb.ErrorCode) { var ( - model *db.DBModel - err error + // model *db.DBModel + // err error + friend []string ) - if model, err = this.module.GetDBNodule(session, comm.TableFriend, 0); err != nil { - code = pb.ErrorCode_DBError - this.module.Errorf("session:%v err:%v", session, err) - return - } - friend := &pb.DBFriend{Uid: session.GetUserId(), FriendIds: make([]string, 0)} - if err = model.Get(session.GetUserId(), friend); err != nil && err != mgo.MongodbNil { - this.module.Errorln(err) - return - } - for _, v := range friend.FriendIds { + // if model, err = this.module.GetDBNodule(session, comm.TableFriend, 0); err != nil { + // code = pb.ErrorCode_DBError + // this.module.Errorf("session:%v err:%v", session, err) + // return + // } + // friend := &pb.DBFriend{Uid: session.GetUserId(), FriendIds: make([]string, 0)} + // if err = model.Get(session.GetUserId(), friend); err != nil && err != mgo.MongodbNil { + // this.module.Errorln(err) + // return + // } + friend = this.module.friend.GetFriendList(session.GetUserId()) + for _, v := range friend { temp := *chat temp.Id = primitive.NewObjectID().Hex() temp.Channel = pb.ChatChannel_Private @@ -175,13 +175,14 @@ func (this *modelDreamComp) noticeuserfriend(session comm.IUserSession, mid stri } chat.Id = primitive.NewObjectID().Hex() chat.Channel = pb.ChatChannel_World + chat.Stag = session.GetServiecTag() // code = this.module.chat.SendWorldChat(stag, chat) - this.delaynoticeWorld(session.GetServiecTag(), mid, chat) + this.delaynoticeWorld(mid, chat) return } //延迟推送到 世界聊天频道 -func (this *modelDreamComp) delaynoticeWorld(stag, mid string, chat *pb.DBChat) { +func (this *modelDreamComp) delaynoticeWorld(mid string, chat *pb.DBChat) { timewheel.Add(time.Minute*15, func(t *timewheel.Task, i ...interface{}) { _mid := i[0].(string) _chat := i[1].(*pb.DBChat) diff --git a/modules/moonfantasy/module.go b/modules/moonfantasy/module.go index 6beafa64a..8b32a5f9a 100644 --- a/modules/moonfantasy/module.go +++ b/modules/moonfantasy/module.go @@ -1,10 +1,14 @@ package moonfantasy import ( + "context" "crypto/rand" + "errors" + "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" @@ -25,6 +29,7 @@ type Moonfantasy struct { modules.ModuleBase service base.IRPCXService chat comm.IChat + friend comm.IFriend battle comm.IBattle api_comp *apiComp configure *configureComp @@ -51,10 +56,15 @@ func (this *Moonfantasy) Start() (err error) { return } this.chat = module.(comm.IChat) + if module, err = this.service.GetModule(comm.ModuleFriend); err != nil { + return + } + this.friend = module.(comm.IFriend) if module, err = this.service.GetModule(comm.ModuleBattle); err != nil { return } this.battle = module.(comm.IBattle) + this.service.RegisterFunctionName(string(comm.Rpc_ModuleMoonfantasyTrigger), this.Rpc_ModuleMoonfantasyTrigger) return } @@ -76,7 +86,36 @@ func (this *Moonfantasy) Trigger(session comm.IUserSession, source *pb.BattleRep if triggerData, err = this.configure.GettriggerData(int32(source.Info.Ptype)); err == nil && triggerData.Open { n, _ := rand.Int(rand.Reader, big.NewInt(1000)) if int32(n.Int64()) < triggerData.DreamlandPro { - this.modelDream.trigger(session, source) + if this.IsCross() { + this.modelDream.trigger(session) + } else { + if _, err = this.service.AcrossClusterRpcGo(context.Background(), + this.GetCrossTag(), + comm.Service_Worker, + string(comm.Rpc_ModuleMoonfantasyTrigger), + pb.RPCGeneralReqA1{Param1: session.GetUserId()}, + nil, + ); err != nil { + this.Errorln(err) + } + } } } } + +//接收区服worker发起的秘境事件 +func (this *Moonfantasy) Rpc_ModuleMoonfantasyTrigger(ctx context.Context, args *pb.RPCGeneralReqA1, reply *pb.EmptyResp) (err error) { + this.Debug("Rpc_ModuleMoonfantasyTrigger", log.Field{Key: "args", Value: args.String()}) + if args.Param1 == "" { + err = errors.New("参数异常!") + return + } + if session, ok := this.GetUserSession(args.Param1); !ok { + err = fmt.Errorf("未查询到用户:%s在线信息!", args.Param1) + return + } else { + this.modelDream.trigger(session) + session.Push() + } + return +} diff --git a/modules/timer/chat.go b/modules/timer/chat.go index 37a7cfae4..fcdcde899 100644 --- a/modules/timer/chat.go +++ b/modules/timer/chat.go @@ -90,7 +90,7 @@ func (this *ChatComp) chatNoticen(content string) func() { } data, _ := anypb.New(&pb.ChatMessagePush{Chat: msg}) this.module.Debug("广播公告消息", log.Field{Key: "chat", Value: content}) - if err := this.module.service.AcrossClusterBroadcast(context.Background(), msg.Stag, comm.Service_Gateway, string(comm.Rpc_GatewaySendRadioMsg), pb.UserMessage{ + if err := this.module.service.RpcBroadcast(context.Background(), comm.Service_Gateway, string(comm.Rpc_GatewaySendRadioMsg), pb.UserMessage{ MainType: string(comm.ModuleChat), SubType: "message", Data: data, diff --git a/pb/chat_db.pb.go b/pb/chat_db.pb.go index 91241c9c6..b32e55308 100644 --- a/pb/chat_db.pb.go +++ b/pb/chat_db.pb.go @@ -139,23 +139,23 @@ type DBChat struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID - Channel ChatChannel `protobuf:"varint,2,opt,name=channel,proto3,enum=ChatChannel" json:"channel"` //频道 - Ctype ChatType `protobuf:"varint,3,opt,name=ctype,proto3,enum=ChatType" json:"ctype"` //消息类型 - Suid string `protobuf:"bytes,4,opt,name=suid,proto3" json:"suid"` //发送用户id - Slv int32 `protobuf:"varint,5,opt,name=slv,proto3" json:"slv"` //发送者等级 - Ruid string `protobuf:"bytes,6,opt,name=ruid,proto3" json:"ruid"` //接收用户id channel == Private 有效 - ChannelId int32 `protobuf:"varint,7,opt,name=channelId,proto3" json:"channelId"` //跨服频道 频道Id - UnionId string `protobuf:"bytes,8,opt,name=unionId,proto3" json:"unionId"` //工会id - Stag string `protobuf:"bytes,9,opt,name=stag,proto3" json:"stag"` //区服id - Avatar string `protobuf:"bytes,10,opt,name=avatar,proto3" json:"avatar"` //用户头像 - Uname string `protobuf:"bytes,11,opt,name=uname,proto3" json:"uname"` //用户名 - Content string `protobuf:"bytes,12,opt,name=content,proto3" json:"content"` //内容 - Ctime int64 `protobuf:"varint,13,opt,name=ctime,proto3" json:"ctime"` //创建时间 - AppendInt int64 `protobuf:"varint,14,opt,name=appendInt,proto3" json:"appendInt" bson:"appendInt"` //聊天附加数据 - AppendStr string `protobuf:"bytes,15,opt,name=appendStr,proto3" json:"appendStr" bson:"appendStr"` //聊天附加数据 - AppendBool string `protobuf:"bytes,16,opt,name=appendBool,proto3" json:"appendBool" bson:"appendBool"` //聊天附加数据 - AppendBytes []byte `protobuf:"bytes,17,opt,name=appendBytes,proto3" json:"appendBytes" bson:"appendInt"` //聊天附加数据 + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID + Channel ChatChannel `protobuf:"varint,2,opt,name=channel,proto3,enum=ChatChannel" json:"channel"` //频道 + Ctype ChatType `protobuf:"varint,3,opt,name=ctype,proto3,enum=ChatType" json:"ctype"` //消息类型 + Suid string `protobuf:"bytes,4,opt,name=suid,proto3" json:"suid"` //发送用户id + Slv int32 `protobuf:"varint,5,opt,name=slv,proto3" json:"slv"` //发送者等级 + Ruid string `protobuf:"bytes,6,opt,name=ruid,proto3" json:"ruid"` //接收用户id channel == Private 有效 + ChannelId int32 `protobuf:"varint,7,opt,name=channelId,proto3" json:"channelId" bson:"channelId"` //ID跨服频道 频道Id + UnionId string `protobuf:"bytes,8,opt,name=unionId,proto3" json:"unionId"` //@go_tags(`bson:"unionId"`)工会id + Stag string `protobuf:"bytes,9,opt,name=stag,proto3" json:"stag"` //区服id + Avatar string `protobuf:"bytes,10,opt,name=avatar,proto3" json:"avatar"` //用户头像 + Uname string `protobuf:"bytes,11,opt,name=uname,proto3" json:"uname"` //用户名 + Content string `protobuf:"bytes,12,opt,name=content,proto3" json:"content"` //内容 + Ctime int64 `protobuf:"varint,13,opt,name=ctime,proto3" json:"ctime"` //创建时间 + AppendInt int64 `protobuf:"varint,14,opt,name=appendInt,proto3" json:"appendInt" bson:"appendInt"` //聊天附加数据 + AppendStr string `protobuf:"bytes,15,opt,name=appendStr,proto3" json:"appendStr" bson:"appendStr"` //聊天附加数据 + AppendBool string `protobuf:"bytes,16,opt,name=appendBool,proto3" json:"appendBool" bson:"appendBool"` //聊天附加数据 + AppendBytes []byte `protobuf:"bytes,17,opt,name=appendBytes,proto3" json:"appendBytes" bson:"appendBytes"` //聊天附加数据 } func (x *DBChat) Reset() { diff --git a/pb/comm.pb.go b/pb/comm.pb.go index dee2168be..b8be12389 100644 --- a/pb/comm.pb.go +++ b/pb/comm.pb.go @@ -1190,6 +1190,246 @@ func (*EmptyResp) Descriptor() ([]byte, []int) { return file_comm_proto_rawDescGZIP(), []int{17} } +// rpc 通用请求消息 1 +type RPCGeneralReqA1 struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Param1 string `protobuf:"bytes,1,opt,name=param1,proto3" json:"param1"` +} + +func (x *RPCGeneralReqA1) Reset() { + *x = RPCGeneralReqA1{} + if protoimpl.UnsafeEnabled { + mi := &file_comm_proto_msgTypes[18] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RPCGeneralReqA1) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RPCGeneralReqA1) ProtoMessage() {} + +func (x *RPCGeneralReqA1) ProtoReflect() protoreflect.Message { + mi := &file_comm_proto_msgTypes[18] + 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 RPCGeneralReqA1.ProtoReflect.Descriptor instead. +func (*RPCGeneralReqA1) Descriptor() ([]byte, []int) { + return file_comm_proto_rawDescGZIP(), []int{18} +} + +func (x *RPCGeneralReqA1) GetParam1() string { + if x != nil { + return x.Param1 + } + return "" +} + +// rpc 通用请求消息 1 +type RPCGeneralReqA2 struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Param1 string `protobuf:"bytes,1,opt,name=param1,proto3" json:"param1"` + Param2 string `protobuf:"bytes,2,opt,name=param2,proto3" json:"param2"` +} + +func (x *RPCGeneralReqA2) Reset() { + *x = RPCGeneralReqA2{} + if protoimpl.UnsafeEnabled { + mi := &file_comm_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RPCGeneralReqA2) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RPCGeneralReqA2) ProtoMessage() {} + +func (x *RPCGeneralReqA2) ProtoReflect() protoreflect.Message { + mi := &file_comm_proto_msgTypes[19] + 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 RPCGeneralReqA2.ProtoReflect.Descriptor instead. +func (*RPCGeneralReqA2) Descriptor() ([]byte, []int) { + return file_comm_proto_rawDescGZIP(), []int{19} +} + +func (x *RPCGeneralReqA2) GetParam1() string { + if x != nil { + return x.Param1 + } + return "" +} + +func (x *RPCGeneralReqA2) GetParam2() string { + if x != nil { + return x.Param2 + } + return "" +} + +// rpc 通用请求消息 1 +type RPCGeneralReqA3 struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Param1 string `protobuf:"bytes,1,opt,name=param1,proto3" json:"param1"` + Param2 string `protobuf:"bytes,2,opt,name=param2,proto3" json:"param2"` + Param3 string `protobuf:"bytes,3,opt,name=param3,proto3" json:"param3"` +} + +func (x *RPCGeneralReqA3) Reset() { + *x = RPCGeneralReqA3{} + if protoimpl.UnsafeEnabled { + mi := &file_comm_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RPCGeneralReqA3) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RPCGeneralReqA3) ProtoMessage() {} + +func (x *RPCGeneralReqA3) ProtoReflect() protoreflect.Message { + mi := &file_comm_proto_msgTypes[20] + 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 RPCGeneralReqA3.ProtoReflect.Descriptor instead. +func (*RPCGeneralReqA3) Descriptor() ([]byte, []int) { + return file_comm_proto_rawDescGZIP(), []int{20} +} + +func (x *RPCGeneralReqA3) GetParam1() string { + if x != nil { + return x.Param1 + } + return "" +} + +func (x *RPCGeneralReqA3) GetParam2() string { + if x != nil { + return x.Param2 + } + return "" +} + +func (x *RPCGeneralReqA3) GetParam3() string { + if x != nil { + return x.Param3 + } + return "" +} + +// rpc 通用请求消息 1 +type RPCGeneralReqA4 struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Param1 string `protobuf:"bytes,1,opt,name=param1,proto3" json:"param1"` + Param2 string `protobuf:"bytes,2,opt,name=param2,proto3" json:"param2"` + Param3 string `protobuf:"bytes,3,opt,name=param3,proto3" json:"param3"` + Param4 string `protobuf:"bytes,4,opt,name=param4,proto3" json:"param4"` +} + +func (x *RPCGeneralReqA4) Reset() { + *x = RPCGeneralReqA4{} + if protoimpl.UnsafeEnabled { + mi := &file_comm_proto_msgTypes[21] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RPCGeneralReqA4) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RPCGeneralReqA4) ProtoMessage() {} + +func (x *RPCGeneralReqA4) ProtoReflect() protoreflect.Message { + mi := &file_comm_proto_msgTypes[21] + 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 RPCGeneralReqA4.ProtoReflect.Descriptor instead. +func (*RPCGeneralReqA4) Descriptor() ([]byte, []int) { + return file_comm_proto_rawDescGZIP(), []int{21} +} + +func (x *RPCGeneralReqA4) GetParam1() string { + if x != nil { + return x.Param1 + } + return "" +} + +func (x *RPCGeneralReqA4) GetParam2() string { + if x != nil { + return x.Param2 + } + return "" +} + +func (x *RPCGeneralReqA4) GetParam3() string { + if x != nil { + return x.Param3 + } + return "" +} + +func (x *RPCGeneralReqA4) GetParam4() string { + if x != nil { + return x.Param4 + } + return "" +} + var File_comm_proto protoreflect.FileDescriptor var file_comm_proto_rawDesc = []byte{ @@ -1309,12 +1549,32 @@ var file_comm_proto_rawDesc = []byte{ 0x64, 0x22, 0x1d, 0x0a, 0x07, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x0a, 0x0a, 0x08, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x22, 0x0b, 0x0a, 0x09, - 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x73, 0x70, 0x2a, 0x43, 0x0a, 0x12, 0x48, 0x65, 0x72, - 0x6f, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, - 0x06, 0x0a, 0x02, 0x48, 0x70, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x74, 0x6b, 0x10, 0x01, - 0x12, 0x07, 0x0a, 0x03, 0x44, 0x65, 0x66, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x70, 0x65, - 0x65, 0x64, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x43, 0x72, 0x69, 0x74, 0x10, 0x04, 0x42, 0x06, - 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x73, 0x70, 0x22, 0x29, 0x0a, 0x0f, 0x52, 0x50, 0x43, + 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x52, 0x65, 0x71, 0x41, 0x31, 0x12, 0x16, 0x0a, 0x06, + 0x70, 0x61, 0x72, 0x61, 0x6d, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x31, 0x22, 0x41, 0x0a, 0x0f, 0x52, 0x50, 0x43, 0x47, 0x65, 0x6e, 0x65, 0x72, + 0x61, 0x6c, 0x52, 0x65, 0x71, 0x41, 0x32, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, + 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x31, 0x12, + 0x16, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x32, 0x22, 0x59, 0x0a, 0x0f, 0x52, 0x50, 0x43, 0x47, 0x65, + 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x52, 0x65, 0x71, 0x41, 0x33, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, + 0x6d, 0x31, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x32, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x32, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x33, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, + 0x6d, 0x33, 0x22, 0x71, 0x0a, 0x0f, 0x52, 0x50, 0x43, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, + 0x52, 0x65, 0x71, 0x41, 0x34, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x31, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x31, 0x12, 0x16, 0x0a, + 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, + 0x61, 0x72, 0x61, 0x6d, 0x32, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x33, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x33, 0x12, 0x16, 0x0a, + 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x34, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, + 0x61, 0x72, 0x61, 0x6d, 0x34, 0x2a, 0x43, 0x0a, 0x12, 0x48, 0x65, 0x72, 0x6f, 0x41, 0x74, 0x74, + 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x06, 0x0a, 0x02, 0x48, + 0x70, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x74, 0x6b, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, + 0x44, 0x65, 0x66, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x70, 0x65, 0x65, 0x64, 0x10, 0x03, + 0x12, 0x08, 0x0a, 0x04, 0x43, 0x72, 0x69, 0x74, 0x10, 0x04, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, + 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1330,7 +1590,7 @@ func file_comm_proto_rawDescGZIP() []byte { } var file_comm_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_comm_proto_msgTypes = make([]protoimpl.MessageInfo, 18) +var file_comm_proto_msgTypes = make([]protoimpl.MessageInfo, 22) var file_comm_proto_goTypes = []interface{}{ (HeroAttributesType)(0), // 0: HeroAttributesType (*UserMessage)(nil), // 1: UserMessage @@ -1351,18 +1611,22 @@ var file_comm_proto_goTypes = []interface{}{ (*NameReq)(nil), // 16: NameReq (*EmptyReq)(nil), // 17: EmptyReq (*EmptyResp)(nil), // 18: EmptyResp - (*anypb.Any)(nil), // 19: google.protobuf.Any - (ErrorCode)(0), // 20: ErrorCode + (*RPCGeneralReqA1)(nil), // 19: RPCGeneralReqA1 + (*RPCGeneralReqA2)(nil), // 20: RPCGeneralReqA2 + (*RPCGeneralReqA3)(nil), // 21: RPCGeneralReqA3 + (*RPCGeneralReqA4)(nil), // 22: RPCGeneralReqA4 + (*anypb.Any)(nil), // 23: google.protobuf.Any + (ErrorCode)(0), // 24: ErrorCode } var file_comm_proto_depIdxs = []int32{ - 19, // 0: UserMessage.data:type_name -> google.protobuf.Any - 19, // 1: AgentMessage.Message:type_name -> google.protobuf.Any - 20, // 2: RPCMessageReply.Code:type_name -> ErrorCode - 19, // 3: RPCMessageReply.ErrorData:type_name -> google.protobuf.Any + 23, // 0: UserMessage.data:type_name -> google.protobuf.Any + 23, // 1: AgentMessage.Message:type_name -> google.protobuf.Any + 24, // 2: RPCMessageReply.Code:type_name -> ErrorCode + 23, // 3: RPCMessageReply.ErrorData:type_name -> google.protobuf.Any 1, // 4: RPCMessageReply.Reply:type_name -> UserMessage 1, // 5: AgentSendMessageReq.Reply:type_name -> UserMessage - 19, // 6: BatchMessageReq.Data:type_name -> google.protobuf.Any - 19, // 7: BroadCastMessageReq.Data:type_name -> google.protobuf.Any + 23, // 6: BatchMessageReq.Data:type_name -> google.protobuf.Any + 23, // 7: BroadCastMessageReq.Data:type_name -> google.protobuf.Any 8, // [8:8] is the sub-list for method output_type 8, // [8:8] is the sub-list for method input_type 8, // [8:8] is the sub-list for extension type_name @@ -1593,6 +1857,54 @@ func file_comm_proto_init() { return nil } } + file_comm_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RPCGeneralReqA1); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comm_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RPCGeneralReqA2); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comm_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RPCGeneralReqA3); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comm_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RPCGeneralReqA4); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1600,7 +1912,7 @@ func file_comm_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_comm_proto_rawDesc, NumEnums: 1, - NumMessages: 18, + NumMessages: 22, NumExtensions: 0, NumServices: 0, }, diff --git a/sys/db/core.go b/sys/db/core.go index eaa05e377..c43460afd 100644 --- a/sys/db/core.go +++ b/sys/db/core.go @@ -8,6 +8,8 @@ type ( ISys interface { //本服数据连接 Local() (conn *DBConn, err error) + //当前是否是跨服 + IsCross() bool //跨服区服id CrossTag() string //本服数据连接 @@ -53,6 +55,10 @@ func Local() (conn *DBConn, err error) { return defsys.Local() } +func IsCross() bool { + return defsys.IsCross() +} + func CrossTag() string { return defsys.CrossTag() } diff --git a/sys/db/db.go b/sys/db/db.go index 6946aedaa..77acdddcc 100644 --- a/sys/db/db.go +++ b/sys/db/db.go @@ -106,7 +106,9 @@ func (this *DB) Local() (conn *DBConn, err error) { } return } - +func (this *DB) IsCross() bool { + return this.options.IsCross +} func (this *DB) CrossTag() string { return this.options.CrossTag } @@ -119,6 +121,7 @@ func (this *DB) Cross() (conn *DBConn, err error) { return } + func (this *DB) ServerDBConn(stage string) (conn *DBConn, err error) { ok := false conn, ok = this.servers[stage] @@ -127,6 +130,7 @@ func (this *DB) ServerDBConn(stage string) (conn *DBConn, err error) { } return } + func (this *DB) GetServerTags() []string { keys := make([]string, 0) for k, _ := range this.servers {