上传用户离线以及论坛模块
This commit is contained in:
parent
1f3106ce77
commit
f589bf55cc
@ -38,6 +38,7 @@ const (
|
||||
SM_FriendModule core.M_Modules = "friend" //好友模块
|
||||
SM_LogModelModule core.M_Modules = "model" //日志模块
|
||||
SM_EquipmentModule core.M_Modules = "equipment" //装备模块
|
||||
SM_ForumModule core.M_Modules = "forum" //论坛模块
|
||||
)
|
||||
|
||||
//RPC服务接口定义处
|
||||
@ -49,6 +50,7 @@ const ( //Rpc
|
||||
Rpc_GatewaySendBatchMsg core.Rpc_Key = "Rpc_GatewaySendBatchMsg" //向多个用户发送消息
|
||||
Rpc_GatewaySendRadioMsg core.Rpc_Key = "Rpc_GatewaySendRadioMsg" //广播消息
|
||||
Rpc_GatewayAgentClose core.Rpc_Key = "Rpc_GatewayAgentClose" //代理关闭 关闭用户连接
|
||||
Rpc_NoticeUserClose core.Rpc_Key = "Rpc_NoticeUserClose" //通知用户离线
|
||||
)
|
||||
|
||||
//事件类型定义处
|
||||
|
29
modules/forum/api.go
Normal file
29
modules/forum/api.go
Normal file
@ -0,0 +1,29 @@
|
||||
package forum
|
||||
|
||||
import (
|
||||
"go_dreamfactory/modules"
|
||||
|
||||
"go_dreamfactory/lego/core"
|
||||
)
|
||||
|
||||
/*
|
||||
装备模块 API
|
||||
*/
|
||||
type Api_Comp struct {
|
||||
modules.MComp_GateComp
|
||||
service core.IService
|
||||
module *Forum
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.MComp_GateComp.Init(service, module, comp, options)
|
||||
this.module = module.(*Forum)
|
||||
this.service = service
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Api_Comp) Start() (err error) {
|
||||
err = this.MComp_GateComp.Start()
|
||||
return
|
||||
}
|
27
modules/forum/model_forum_comp.go
Normal file
27
modules/forum/model_forum_comp.go
Normal file
@ -0,0 +1,27 @@
|
||||
package forum
|
||||
|
||||
import (
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/modules"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||
)
|
||||
|
||||
///论坛 数据组件
|
||||
type Model_Forum_Comp struct {
|
||||
modules.Model_Comp
|
||||
module *Forum
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
func (this *Model_Forum_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
||||
this.Model_Comp.Init(service, module, comp, opt)
|
||||
this.module = module.(*Forum)
|
||||
this.TableName = "forum"
|
||||
//创建uid索引
|
||||
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
||||
})
|
||||
return
|
||||
}
|
43
modules/forum/module.go
Normal file
43
modules/forum/module.go
Normal file
@ -0,0 +1,43 @@
|
||||
package forum
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/modules"
|
||||
)
|
||||
|
||||
/*
|
||||
模块名:论坛
|
||||
描述:处理跨服社交论坛相关业务
|
||||
开发:李伟
|
||||
*/
|
||||
func NewModule() core.IModule {
|
||||
m := new(Forum)
|
||||
return m
|
||||
}
|
||||
|
||||
type Forum struct {
|
||||
modules.ModuleBase
|
||||
api_comp *Api_Comp
|
||||
configure_comp *Configure_Comp
|
||||
model_forum_comp *Model_Forum_Comp
|
||||
}
|
||||
|
||||
//模块名
|
||||
func (this *Forum) GetType() core.M_Modules {
|
||||
return comm.SM_EquipmentModule
|
||||
}
|
||||
|
||||
//模块初始化接口 注册用户创建角色事件
|
||||
func (this *Forum) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
||||
err = this.ModuleBase.Init(service, module, options)
|
||||
return
|
||||
}
|
||||
|
||||
//装备组件
|
||||
func (this *Forum) OnInstallComp() {
|
||||
this.ModuleBase.OnInstallComp()
|
||||
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
||||
this.model_forum_comp = this.RegisterComp(new(Model_Forum_Comp)).(*Model_Forum_Comp)
|
||||
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
|
||||
}
|
74
modules/forum/module_test.go
Normal file
74
modules/forum/module_test.go
Normal file
@ -0,0 +1,74 @@
|
||||
package forum
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego"
|
||||
"go_dreamfactory/lego/base/rpcx"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/services"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/sys/configure"
|
||||
"go_dreamfactory/sys/db"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func newService(ops ...rpcx.Option) core.IService {
|
||||
s := new(TestService)
|
||||
s.Configure(ops...)
|
||||
return s
|
||||
}
|
||||
|
||||
//梦工厂基础服务对象
|
||||
type TestService struct {
|
||||
rpcx.RPCXService
|
||||
}
|
||||
|
||||
//初始化相关系统
|
||||
func (this *TestService) InitSys() {
|
||||
this.RPCXService.InitSys()
|
||||
if err := cache.OnInit(this.GetSettings().Sys["cache"]); err != nil {
|
||||
panic(fmt.Sprintf("init sys.cache err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.cache success!")
|
||||
}
|
||||
if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil {
|
||||
panic(fmt.Sprintf("init sys.db err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.db success!")
|
||||
}
|
||||
if err := configure.OnInit(this.GetSettings().Sys["configure"]); err != nil {
|
||||
panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.configure success!")
|
||||
}
|
||||
}
|
||||
|
||||
var service core.IService
|
||||
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
|
||||
var module = new(Forum)
|
||||
|
||||
//测试环境下初始化db和cache 系统
|
||||
func TestMain(m *testing.M) {
|
||||
service = newService(
|
||||
rpcx.SetConfPath("../../bin/conf/worker_1.yaml"),
|
||||
rpcx.SetVersion("1.0.0.0"),
|
||||
)
|
||||
service.OnInstallComp( //装备组件
|
||||
s_gateComp, //此服务需要接受用户的消息 需要装备网关组件
|
||||
)
|
||||
go func() {
|
||||
lego.Run(service, //运行模块
|
||||
module,
|
||||
)
|
||||
}()
|
||||
time.Sleep(time.Second * 3)
|
||||
defer os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func Test_Module(t *testing.T) {
|
||||
|
||||
}
|
@ -174,6 +174,10 @@ func (this *Agent) UserId() string {
|
||||
return this.uId
|
||||
}
|
||||
|
||||
func (this *Agent) WorkerId() string {
|
||||
return this.wId
|
||||
}
|
||||
|
||||
func (this *Agent) Bind(uId string, wId string) {
|
||||
this.uId = uId
|
||||
this.wId = wId
|
||||
|
@ -2,11 +2,15 @@ package gateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"sync"
|
||||
|
||||
"go_dreamfactory/lego/base"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/core/cbase"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -14,11 +18,13 @@ import (
|
||||
*/
|
||||
type AgentMgr_Comp struct {
|
||||
cbase.ModuleCompBase
|
||||
agents *sync.Map
|
||||
service base.IRPCXService
|
||||
agents *sync.Map
|
||||
}
|
||||
|
||||
func (this *AgentMgr_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
err = this.ModuleCompBase.Init(service, module, comp, options)
|
||||
this.service = service.(base.IRPCXService)
|
||||
this.agents = new(sync.Map)
|
||||
return
|
||||
}
|
||||
@ -31,6 +37,14 @@ func (this *AgentMgr_Comp) Connect(a IAgent) {
|
||||
//移除断开的用户
|
||||
func (this *AgentMgr_Comp) DisConnect(a IAgent) {
|
||||
this.agents.Delete(a.SessionId())
|
||||
if a.UserId() != "" { //登录用户 通知业务服务处理玩家离线相关
|
||||
reply := &pb.RPCMessageReply{}
|
||||
if _, err := this.service.RpcGo(context.Background(), fmt.Sprintf("%s/%s", comm.Service_Worker, a.WorkerId()), string(comm.Rpc_NoticeUserClose), &pb.NoticeUserCloseReq{
|
||||
UserId: a.UserId(),
|
||||
}, reply); err != nil {
|
||||
log.Errorf(" uId:%s Rpc_NoticeUserClose err:%v", a.UserId(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//用户登录绑定Id
|
||||
|
@ -13,6 +13,7 @@ type (
|
||||
SessionId() string
|
||||
IP() string
|
||||
UserId() string
|
||||
WorkerId() string
|
||||
Bind(uId string, wId string)
|
||||
UnBind()
|
||||
WriteMsg(msg *pb.UserMessage) (err error)
|
||||
|
@ -614,6 +614,54 @@ func (x *AgentCloseeReq) GetUserSessionId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
//通知用户离线
|
||||
type NoticeUserCloseReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserId string `protobuf:"bytes,1,opt,name=UserId,proto3" json:"UserId"`
|
||||
}
|
||||
|
||||
func (x *NoticeUserCloseReq) Reset() {
|
||||
*x = NoticeUserCloseReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_comm_proto_msgTypes[9]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *NoticeUserCloseReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*NoticeUserCloseReq) ProtoMessage() {}
|
||||
|
||||
func (x *NoticeUserCloseReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_comm_proto_msgTypes[9]
|
||||
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 NoticeUserCloseReq.ProtoReflect.Descriptor instead.
|
||||
func (*NoticeUserCloseReq) Descriptor() ([]byte, []int) {
|
||||
return file_comm_proto_rawDescGZIP(), []int{9}
|
||||
}
|
||||
|
||||
func (x *NoticeUserCloseReq) GetUserId() string {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_comm_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_comm_proto_rawDesc = []byte{
|
||||
@ -688,8 +736,11 @@ var file_comm_proto_rawDesc = []byte{
|
||||
0x74, 0x61, 0x22, 0x36, 0x0a, 0x0e, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x43, 0x6c, 0x6f, 0x73, 0x65,
|
||||
0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73,
|
||||
0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65,
|
||||
0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b,
|
||||
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x2c, 0x0a, 0x12, 0x4e, 0x6f,
|
||||
0x74, 0x69, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x71,
|
||||
0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@ -704,7 +755,7 @@ func file_comm_proto_rawDescGZIP() []byte {
|
||||
return file_comm_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_comm_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
|
||||
var file_comm_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
|
||||
var file_comm_proto_goTypes = []interface{}{
|
||||
(*UserMessage)(nil), // 0: UserMessage
|
||||
(*AgentMessage)(nil), // 1: AgentMessage
|
||||
@ -715,16 +766,17 @@ var file_comm_proto_goTypes = []interface{}{
|
||||
(*BatchMessageReq)(nil), // 6: BatchMessageReq
|
||||
(*BroadCastMessageReq)(nil), // 7: BroadCastMessageReq
|
||||
(*AgentCloseeReq)(nil), // 8: AgentCloseeReq
|
||||
(*anypb.Any)(nil), // 9: google.protobuf.Any
|
||||
(ErrorCode)(0), // 10: ErrorCode
|
||||
(*NoticeUserCloseReq)(nil), // 9: NoticeUserCloseReq
|
||||
(*anypb.Any)(nil), // 10: google.protobuf.Any
|
||||
(ErrorCode)(0), // 11: ErrorCode
|
||||
}
|
||||
var file_comm_proto_depIdxs = []int32{
|
||||
9, // 0: UserMessage.data:type_name -> google.protobuf.Any
|
||||
9, // 1: AgentMessage.Message:type_name -> google.protobuf.Any
|
||||
10, // 2: RPCMessageReply.Code:type_name -> ErrorCode
|
||||
9, // 3: AgentSendMessageReq.Data:type_name -> google.protobuf.Any
|
||||
9, // 4: BatchMessageReq.Data:type_name -> google.protobuf.Any
|
||||
9, // 5: BroadCastMessageReq.Data:type_name -> google.protobuf.Any
|
||||
10, // 0: UserMessage.data:type_name -> google.protobuf.Any
|
||||
10, // 1: AgentMessage.Message:type_name -> google.protobuf.Any
|
||||
11, // 2: RPCMessageReply.Code:type_name -> ErrorCode
|
||||
10, // 3: AgentSendMessageReq.Data:type_name -> google.protobuf.Any
|
||||
10, // 4: BatchMessageReq.Data:type_name -> google.protobuf.Any
|
||||
10, // 5: BroadCastMessageReq.Data:type_name -> google.protobuf.Any
|
||||
6, // [6:6] is the sub-list for method output_type
|
||||
6, // [6:6] is the sub-list for method input_type
|
||||
6, // [6:6] is the sub-list for extension type_name
|
||||
@ -847,6 +899,18 @@ func file_comm_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_comm_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*NoticeUserCloseReq); 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{
|
||||
@ -854,7 +918,7 @@ func file_comm_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_comm_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 9,
|
||||
NumMessages: 10,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
|
@ -62,4 +62,7 @@ message BroadCastMessageReq {
|
||||
}
|
||||
|
||||
//关闭用户代理
|
||||
message AgentCloseeReq { string UserSessionId = 1; }
|
||||
message AgentCloseeReq { string UserSessionId = 1; }
|
||||
|
||||
//通知用户离线
|
||||
message NoticeUserCloseReq { string UserId = 1; }
|
@ -1,15 +0,0 @@
|
||||
syntax = "proto3";
|
||||
option go_package = ".;pb";
|
||||
|
||||
message DB_EquipData {
|
||||
string id = 1; //@go_tags(`bson:"_id"`) ID
|
||||
string uid = 2;
|
||||
int32 equipID = 3; // 装备的配置表ID
|
||||
int32 star = 4; // 装备星级
|
||||
int32 quality = 5; // 装备品质
|
||||
int32 lv = 6; // 装备等级
|
||||
map<int32, int32> addProperty = 7; // 装备附加属性
|
||||
int32 baodi = 8; // 保底次数
|
||||
int32 advance = 9; // 强化次数
|
||||
int32 failCount = 10; // 连续强化失败次数
|
||||
}
|
@ -63,7 +63,8 @@ func (this *SComp_GateRouteComp) Init(service core.IService, comp core.IServiceC
|
||||
|
||||
//组件启动时注册rpc服务监听
|
||||
func (this *SComp_GateRouteComp) Start() (err error) {
|
||||
this.service.RegisterFunctionName(string(comm.Rpc_GatewayRoute), this.ReceiveMsg) //注册网关路由接收接口
|
||||
this.service.RegisterFunctionName(string(comm.Rpc_GatewayRoute), this.ReceiveMsg) //注册网关路由接收接口
|
||||
this.service.RegisterFunctionName(string(comm.Rpc_NoticeUserClose), this.NoticeUserClose) //注册用户离线通知
|
||||
err = this.ServiceCompBase.Start()
|
||||
event.RegisterGO(core.Event_ServiceStartEnd, func() {
|
||||
for k, v := range this.msghandles {
|
||||
@ -181,3 +182,9 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//RPC_NoticeUserClose 接收用户离线通知
|
||||
func (this *SComp_GateRouteComp) NoticeUserClose(ctx context.Context, args *pb.NoticeUserCloseReq, reply *pb.RPCMessageReply) error {
|
||||
event.TriggerEvent(comm.Event_UserOffline, args.UserId)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user