This commit is contained in:
liwei 2022-10-19 14:27:14 +08:00
commit a01af8da67
41 changed files with 885 additions and 360 deletions

View File

@ -11,6 +11,12 @@
"routrules": "~/worker",
"describe": "论坛系统"
},
{
"msgid": "chat",
"open": true,
"routrules": "~/worker",
"describe": "聊天系统"
},
{
"msgid": "chat.chanagechannel",
"open": true,
@ -46,5 +52,107 @@
"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": "拒绝"
},
{
"msgid": "friend.list",
"open": true,
"routrules": "~/worker",
"describe": "好友列表"
},
{
"msgid": "friend.applylist",
"open": true,
"routrules": "~/worker",
"describe": "好友申请列表"
},
{
"msgid": "friend.addblack",
"open": true,
"routrules": "~/worker",
"describe": "加黑名单"
},
{
"msgid": "friend.delblack",
"open": true,
"routrules": "~/worker",
"describe": "删除黑名单"
},
{
"msgid": "friend.blacklist",
"open": true,
"routrules": "~/worker",
"describe": "黑名单列表"
},
{
"msgid": "friend.zan",
"open": true,
"routrules": "~/worker",
"describe": "好友点赞"
},
{
"msgid": "friend.zanreceive",
"open": true,
"routrules": "~/worker",
"describe": "接收点赞"
},
{
"msgid": "friend.zanlist",
"open": true,
"routrules": "~/worker",
"describe": "点赞列表"
},
{
"msgid": "friend.assisthero",
"open": true,
"routrules": "~/worker",
"describe": "英雄助战"
},
{
"msgid": "friend.assistlist",
"open": true,
"routrules": "~/worker",
"describe": "助战列表"
},
{
"msgid": "friend.getreward",
"open": true,
"routrules": "~/worker",
"describe": "获取奖励"
},
{
"msgid": "friend.del",
"open": true,
"routrules": "~/worker",
"describe": "删除好友"
},
{
"msgid": "friend.search",
"open": true,
"routrules": "~/worker",
"describe": "搜索好友"
},
{
"msgid": "friend.randlist",
"open": true,
"routrules": "~/worker",
"describe": "好友推荐"
}
]

View File

@ -163,6 +163,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" //月之秘境触发消息
)
//事件类型定义处

View File

@ -93,6 +93,10 @@ type (
CrossUserSession(uid string) *pb.CacheUser
// 跨服搜索玩家
CrossSearchUser(nickname string) ([]*pb.DBUser, error)
// 获取远程用户
GetRmoteUser(uid string) (*pb.DBUser, error)
// 搜索远程用户
SearchRmoteUser(nickname string) ([]*pb.DBUser, error)
}
//武器模块
IEquipment interface {

View File

@ -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
}

View File

@ -38,6 +38,7 @@ type RPCX struct {
func (this *RPCX) Start() (err error) {
this.service.Start()
this.client.Start()
return
}

View File

@ -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
// }

116
modules/chat/__api_send.go Normal file
View File

@ -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
// }

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

13
modules/chat/core.go Normal file
View File

@ -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
}

View File

@ -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
}

View File

@ -38,7 +38,7 @@ func (this *apiComp) Init(service core.IService, module core.IModule, comp core.
}
func (this *apiComp) setDefaultFriendUserBaseInfo(userId string) *pb.FriendBase {
if user, err := this.moduleFriend.ModuleUser.GetCrossUser(userId); err != nil {
if user, err := this.moduleFriend.ModuleUser.GetRmoteUser(userId); err != nil {
return nil
} else {
if user != nil {

View File

@ -22,12 +22,13 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistR
}
//在线玩家列表
cuList, err := this.moduleFriend.ModuleUser.CrossUserOnlineList()
cuList, err := this.moduleFriend.ModuleUser.UserOnlineList()
if err != nil {
code = pb.ErrorCode_DBError
return
}
recommend := 5 //推荐数量
//过滤
var newList []*pb.CacheUser
for _, v := range cuList {
@ -47,10 +48,9 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistR
newList = append(newList, v)
}
// 只随机选择5个在线玩家
var randOnlineUsers []string
if len(newList) > 5 {
randArr := utils.Numbers(0, len(newList), 5)
if len(newList) > recommend {
randArr := utils.Numbers(0, len(newList), recommend)
for _, v := range randArr {
if newList[v] != nil {
randOnlineUsers = append(randOnlineUsers, newList[v].Uid)

View File

@ -23,7 +23,7 @@ func (this *apiComp) Search(session comm.IUserSession, req *pb.FriendSearchReq)
resp := &pb.FriendSearchResp{}
users, err := this.moduleFriend.ModuleUser.CrossSearchUser(req.NickName)
users, err := this.moduleFriend.ModuleUser.SearchRmoteUser(req.NickName)
if err != nil {
code = pb.ErrorCode_DBError
return

View File

@ -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()

View File

@ -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)

View File

@ -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
}

View File

@ -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,

View File

@ -97,11 +97,11 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod
//不是新账号
if !isNewUser {
lastLoginTime := user.Logintime
update := map[string]interface{}{
"logintime": time.Now().Unix(),
"lastloginip": session.GetIP(),
}
err = this.module.modelUser.ChangeList(user.Uid, user.Id, update)
user.Logintime = time.Now().Unix()
user.Lastloginip = session.GetIP()
user.Offlinetime = 0
update := utils.StructToMap(user)
err = this.module.modelUser.Change(user.Uid, update)
if err != nil {
code = pb.ErrorCode_DBError
return

View File

@ -95,6 +95,15 @@ func (this *User) GetCrossUser(uid string) (*pb.DBUser, error) {
return reply, err
}
// 获取远程用户数据sss
func (this *User) GetRmoteUser(uid string) (*pb.DBUser, error) {
reply := &pb.DBUser{}
if err := this.getUserFromRemoteDb(uid, reply); err != nil {
return nil, err
}
return reply, nil
}
//获取用户会话
func (this *User) GetUserSession(uid string) *pb.CacheUser {
return this.modelSession.getUserSession(uid)
@ -161,6 +170,15 @@ func (this *User) CrossSearchUser(nickName string) ([]*pb.DBUser, error) {
return reply.Users, nil
}
// 远程搜索用户
func (this *User) SearchRmoteUser(nickname string) ([]*pb.DBUser, error) {
reply := &pb.UserDataListResp{}
if err := this.queryUserFromRemoteDb(nickname, reply); err != nil {
return nil, err
}
return reply.Users, nil
}
//查询用户属性值 例如 金币 经验
func (this *User) QueryAttributeValue(uid string, attr string) (value int64) {
user := this.modelUser.GetUser(uid)
@ -330,10 +348,54 @@ func (this *User) ChangeUserExpand(uid string, value map[string]interface{}) err
return this.modelExpand.ChangeUserExpand(uid, value)
}
// 从远程库查询用户
func (this *User) getUserFromRemoteDb(uid string, rsp *pb.DBUser) error {
sid, _, ok := utils.UIdSplit(uid)
if !ok {
return errors.New("sid split error")
}
conn, err := db.ServerDBConn(sid)
if err != nil {
log.Errorf("cross db err: %v", err)
return err
}
model := db.NewDBModel(comm.TableUser, 0, conn)
if err := model.Get(uid, rsp); err != nil {
return err
}
return nil
}
func (this *User) queryUserFromRemoteDb(name string, reply *pb.UserDataListResp) error {
// 区服列表
for _, tag := range db.GetServerTags() {
conn, err := db.ServerDBConn(tag)
if err != nil {
return err
}
//查询用户
filter := bson.M{
"name": name,
}
sr := conn.Mgo.FindOne(comm.TableUser, filter)
user := &pb.DBUser{}
if err = sr.Decode(user); err != nil {
if err != mongo.ErrNoDocuments {
return err
}
}
if user.Uid != "" {
reply.Users = append(reply.Users, user)
}
}
return nil
}
func (this *User) RpcGetAllOnlineUser(ctx context.Context, args *pb.EmptyReq, reply *pb.UserOnlineResp) error {
conn, err := db.Local()
if err != nil {
log.Errorf("cross db err: %v", err)
return err
}
model := db.NewDBModel(comm.TableSession, 0, conn)
@ -346,60 +408,24 @@ func (this *User) RpcGetAllOnlineUser(ctx context.Context, args *pb.EmptyReq, re
}
func (this *User) RpcGetCrossUser(ctx context.Context, req *pb.UIdReq, reply *pb.DBUser) error {
sid, _, ok := utils.UIdSplit(req.Uid)
if !ok {
return errors.New("sid split error")
}
conn, err := db.ServerDBConn(sid)
if err != nil {
log.Errorf("cross db err: %v", err)
return err
}
model := db.NewDBModel(comm.TableUser, 0, conn)
if err := model.Get(req.Uid, reply); err != nil {
return err
}
return nil
return this.getUserFromRemoteDb(req.Uid, reply)
}
func (this *User) RpcGetCrossUserSession(ctx context.Context, req *pb.UIdReq, reply *pb.CacheUser) error {
conn, err := db.Local()
if err != nil {
log.Errorf("cross db err: %v", err)
return err
}
model := db.NewDBModel(comm.TableSession, 0, conn)
if err := model.GetListObj(comm.RDS_SESSION, req.Uid, reply); err != nil {
if err != mongo.ErrNoDocuments {
log.Errorf("%v", err)
return err
}
return nil
}
return nil
}
func (this *User) RpcQueryUser(ctx context.Context, req *pb.NameReq, reply *pb.UserDataListResp) error {
// 区服列表
for _, tag := range db.GetServerTags() {
conn, err := db.ServerDBConn(tag)
if err != nil {
log.Errorf("cross db err: %v", err)
return err
}
//查询用户
filter := bson.M{
"name": req.Name,
}
sr := conn.Mgo.FindOne(comm.TableUser, filter)
user := &pb.DBUser{}
if err = sr.Decode(user); err != nil {
return err
}
reply.Users = append(reply.Users, user)
}
return nil
return this.queryUserFromRemoteDb(req.Name, reply)
}

View File

@ -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() {

View File

@ -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,
},

View File

@ -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()
}

View File

@ -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 {