From 1f3106ce77aeb8dba5e42e69925afca7d4e7a233 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 23 Jun 2022 15:03:25 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=BA=E5=9D=9B?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E4=BB=A5=E5=8F=8A=E7=94=A8=E6=88=B7=E7=A6=BB?= =?UTF-8?q?=E7=BA=BF=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/forum/configure_comp.go | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 modules/forum/configure_comp.go diff --git a/modules/forum/configure_comp.go b/modules/forum/configure_comp.go new file mode 100644 index 000000000..811381c69 --- /dev/null +++ b/modules/forum/configure_comp.go @@ -0,0 +1,42 @@ +package forum + +import ( + "fmt" + "go_dreamfactory/modules" + cfg "go_dreamfactory/sys/configure/structs" + + "go_dreamfactory/lego/core" +) + +const ( + game_equipment = "game_equipment.json" +) + +///背包配置管理组件 +type Configure_Comp struct { + modules.MComp_Configure +} + +//组件初始化接口 +func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.ModuleCompBase.Init(service, module, comp, options) + this.LoadConfigure(game_equipment, cfg.NewGame_equipment) + return +} + +//获取装备配置数据 +func (this *Configure_Comp) GetEquipmentConfigure() (configure *cfg.Game_equipment, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(game_equipment); err != nil { + return + } else { + if configure, ok = v.(*cfg.Game_equipment); !ok { + err = fmt.Errorf("%T no is *cfg.Game_equipment", v) + return + } + } + return +} From f589bf55ccc3e87151ddbcb4ea5f9da27df28e3c Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 23 Jun 2022 15:03:47 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=A6=BB=E7=BA=BF=E4=BB=A5=E5=8F=8A=E8=AE=BA=E5=9D=9B=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/core.go | 2 + modules/forum/api.go | 29 ++++++++++ modules/forum/model_forum_comp.go | 27 ++++++++++ modules/forum/module.go | 43 +++++++++++++++ modules/forum/module_test.go | 74 ++++++++++++++++++++++++++ modules/gateway/agent.go | 4 ++ modules/gateway/agentmgr_comp.go | 16 +++++- modules/gateway/core.go | 1 + pb/comm.pb.go | 88 ++++++++++++++++++++++++++----- pb/proto/comm.proto | 5 +- pb/proto/equip_db.proto | 15 ------ services/comp_gateroute.go | 9 +++- 12 files changed, 283 insertions(+), 30 deletions(-) create mode 100644 modules/forum/api.go create mode 100644 modules/forum/model_forum_comp.go create mode 100644 modules/forum/module.go create mode 100644 modules/forum/module_test.go delete mode 100644 pb/proto/equip_db.proto diff --git a/comm/core.go b/comm/core.go index f807a3db6..c543467f5 100644 --- a/comm/core.go +++ b/comm/core.go @@ -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" //通知用户离线 ) //事件类型定义处 diff --git a/modules/forum/api.go b/modules/forum/api.go new file mode 100644 index 000000000..dd3dd45c5 --- /dev/null +++ b/modules/forum/api.go @@ -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 +} diff --git a/modules/forum/model_forum_comp.go b/modules/forum/model_forum_comp.go new file mode 100644 index 000000000..a54914256 --- /dev/null +++ b/modules/forum/model_forum_comp.go @@ -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 +} diff --git a/modules/forum/module.go b/modules/forum/module.go new file mode 100644 index 000000000..63c03bb8d --- /dev/null +++ b/modules/forum/module.go @@ -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) +} diff --git a/modules/forum/module_test.go b/modules/forum/module_test.go new file mode 100644 index 000000000..4efc0bd88 --- /dev/null +++ b/modules/forum/module_test.go @@ -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) { + +} diff --git a/modules/gateway/agent.go b/modules/gateway/agent.go index 8ed506fe5..0ba488c6b 100644 --- a/modules/gateway/agent.go +++ b/modules/gateway/agent.go @@ -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 diff --git a/modules/gateway/agentmgr_comp.go b/modules/gateway/agentmgr_comp.go index e69b3f7b1..56c73e7b0 100644 --- a/modules/gateway/agentmgr_comp.go +++ b/modules/gateway/agentmgr_comp.go @@ -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 diff --git a/modules/gateway/core.go b/modules/gateway/core.go index 44fc74aae..217c8a797 100644 --- a/modules/gateway/core.go +++ b/modules/gateway/core.go @@ -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) diff --git a/pb/comm.pb.go b/pb/comm.pb.go index c17fe2adf..0ebb8a470 100644 --- a/pb/comm.pb.go +++ b/pb/comm.pb.go @@ -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, }, diff --git a/pb/proto/comm.proto b/pb/proto/comm.proto index 4674ef021..001e9129c 100644 --- a/pb/proto/comm.proto +++ b/pb/proto/comm.proto @@ -62,4 +62,7 @@ message BroadCastMessageReq { } //关闭用户代理 -message AgentCloseeReq { string UserSessionId = 1; } \ No newline at end of file +message AgentCloseeReq { string UserSessionId = 1; } + +//通知用户离线 +message NoticeUserCloseReq { string UserId = 1; } \ No newline at end of file diff --git a/pb/proto/equip_db.proto b/pb/proto/equip_db.proto deleted file mode 100644 index 3d353db44..000000000 --- a/pb/proto/equip_db.proto +++ /dev/null @@ -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 addProperty = 7; // 装备附加属性 - int32 baodi = 8; // 保底次数 - int32 advance = 9; // 强化次数 - int32 failCount = 10; // 连续强化失败次数 -} \ No newline at end of file diff --git a/services/comp_gateroute.go b/services/comp_gateroute.go index 43b4ffe1e..8d3a0f969 100644 --- a/services/comp_gateroute.go +++ b/services/comp_gateroute.go @@ -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 +} From e8a503c99b2a7601ec73b300ea2d5748010310aa Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 23 Jun 2022 15:09:03 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/core.go | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/modules/core.go b/modules/core.go index 8123a7a6c..0e3ef535a 100644 --- a/modules/core.go +++ b/modules/core.go @@ -5,34 +5,15 @@ import ( "go_dreamfactory/pb" "github.com/golang/protobuf/proto" - "go.mongodb.org/mongo-driver/bson" ) type ( //业务模块基类接口 定义所有业务模块都可以使用的接口 IModule interface { core.IModule - API() IAPI_Comp - Cache() ICache_Comp - DB() IDB_Comp - Configure() IConfigure_Comp // ///向指定用户发送消息 SendMsgToUser(mainType, subType string, msg proto.Message, user *pb.Cache_UserData) (err error) // ///向多个用户发送消息 SendMsgToUsers(mainType, subType string, msg proto.Message, user ...*pb.Cache_UserData) (err error) } - IAPI_Comp interface { - } - ICache_Comp interface { - // 向db 写日志信息 - InsertModelLogs(table string, uID string, target interface{}) (err error) - DeleteModelLogs(table string, uID string, where interface{}) (err error) - UpdateModelLogs(table string, uID string, where bson.M, target interface{}) (err error) - } - IDB_Comp interface { - } - IConfigure_Comp interface { - LoadConfigure(name string, fn interface{}) (err error) - GetConfigure(name string) (v interface{}, err error) - } ) From d1831001768b0fc94168187b4f0b65c900f66a16 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 23 Jun 2022 18:03:19 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=83=8C=E5=8C=85?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go_dreamfactory.rar | Bin 10925 -> 0 bytes modules/game/api.go | 29 +++++++++++++ modules/game/configure_comp.go | 42 +++++++++++++++++++ modules/game/module.go | 41 ++++++++++++++++++ modules/game/module_test.go | 74 +++++++++++++++++++++++++++++++++ modules/pack/module.go | 10 ++++- pb/proto/forum/forum_db.proto | 3 ++ pb/proto/forum/forum_msg.proto | 2 + 8 files changed, 200 insertions(+), 1 deletion(-) delete mode 100644 go_dreamfactory.rar create mode 100644 modules/game/api.go create mode 100644 modules/game/configure_comp.go create mode 100644 modules/game/module.go create mode 100644 modules/game/module_test.go create mode 100644 pb/proto/forum/forum_db.proto create mode 100644 pb/proto/forum/forum_msg.proto diff --git a/go_dreamfactory.rar b/go_dreamfactory.rar deleted file mode 100644 index 7b1212ae4d955bcc4024b934cb5a81ebb32d49e3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10925 zcmZvibyOVNvhb0C!QI_LaMuKvV8Ma~2r|In3^usCgy0e+AwX~o?hxFaU^t%MqMqK>a>~{D}x0~jmyVe`P0*zHeWWSH(hUA?ud@3ElGN| z#;(|$_={bQ&XjED1DECX_F0q+HwH6S z#7@;dZ~nRxC?<^2e@jMPTsJ9p!J-+5}k*a~**Z|ccqWL#OTM){& zDecc*-&{gI>4J?GDAp}!-PL@s_7DFRj z($;?X#~-b;!N0|gVvkaLLQ|p0%WJmpx?6%`gQGr$Im&g#McuJ1Xuve)tk0n*)1Q}= zI?6PVLb~?8WJhx2@x&s{I!<=!6FU)i$_HPEW71_>u8&}_v!k}4g>3L#jC5DGHb|k; za|dPCR)4b7&iDnfReN5jep)GXTtFW!erpzt;mAXuOAjF4Nz^xH6Go#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Wt?q zQNDot?s`Gx)%Uh_yCw$s=SM(6z(aul;0+wKKe6`D=oK7YZ%be+e?}(;-u<-uzr_B8 z54hMr@gkuvV;0^S{GZx@f3*E=J@p@?Q5T`}h=`mjRsUP+UvqG9UAlg=CZ*2vh#AIc dU#b6F7cyKITw;+v!}^aEQhVrXBBKBh{vRvlYPtXb diff --git a/modules/game/api.go b/modules/game/api.go new file mode 100644 index 000000000..a929fda55 --- /dev/null +++ b/modules/game/api.go @@ -0,0 +1,29 @@ +package game + +import ( + "go_dreamfactory/modules" + + "go_dreamfactory/lego/core" +) + +/* +API +*/ +type Api_Comp struct { + modules.MComp_GateComp + service core.IService + module *Game +} + +//组件初始化接口 +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.(*Game) + this.service = service + return +} + +func (this *Api_Comp) Start() (err error) { + err = this.MComp_GateComp.Start() + return +} diff --git a/modules/game/configure_comp.go b/modules/game/configure_comp.go new file mode 100644 index 000000000..ef8da7ee6 --- /dev/null +++ b/modules/game/configure_comp.go @@ -0,0 +1,42 @@ +package game + +import ( + "fmt" + "go_dreamfactory/modules" + cfg "go_dreamfactory/sys/configure/structs" + + "go_dreamfactory/lego/core" +) + +const ( + game_equipment = "game_equipment.json" +) + +///配置管理组件 +type Configure_Comp struct { + modules.MComp_Configure +} + +//组件初始化接口 +func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.ModuleCompBase.Init(service, module, comp, options) + this.LoadConfigure(game_equipment, cfg.NewGame_equipment) + return +} + +//获取装备配置数据 +func (this *Configure_Comp) GetEquipmentConfigure() (configure *cfg.Game_equipment, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(game_equipment); err != nil { + return + } else { + if configure, ok = v.(*cfg.Game_equipment); !ok { + err = fmt.Errorf("%T no is *cfg.Game_equipment", v) + return + } + } + return +} diff --git a/modules/game/module.go b/modules/game/module.go new file mode 100644 index 000000000..0d62a9443 --- /dev/null +++ b/modules/game/module.go @@ -0,0 +1,41 @@ +package game + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" +) + +/* +模块名:游戏模块 +描述:游戏战斗逻辑模块 +开发:李伟 +*/ +func NewModule() core.IModule { + m := new(Game) + return m +} + +type Game struct { + modules.ModuleBase + api_comp *Api_Comp + configure_comp *Configure_Comp +} + +//模块名 +func (this *Game) GetType() core.M_Modules { + return comm.SM_EquipmentModule +} + +//模块初始化接口 注册用户创建角色事件 +func (this *Game) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { + err = this.ModuleBase.Init(service, module, options) + return +} + +//装备组件 +func (this *Game) OnInstallComp() { + this.ModuleBase.OnInstallComp() + this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) + this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) +} diff --git a/modules/game/module_test.go b/modules/game/module_test.go new file mode 100644 index 000000000..87d42fdf1 --- /dev/null +++ b/modules/game/module_test.go @@ -0,0 +1,74 @@ +package game + +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(Game) + +//测试环境下初始化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) { + +} diff --git a/modules/pack/module.go b/modules/pack/module.go index 22b2bce0e..c9b8165ed 100644 --- a/modules/pack/module.go +++ b/modules/pack/module.go @@ -64,10 +64,18 @@ func (this *Pack) QueryUserPackItemsAmount(uId string, itemid ...int32) (result } ///添加单个物品到背包 (可以加物品和减物品) -func (this *Pack) AddItemToUserPack(uId string, itemid, addnum int32) (err error) { +func (this *Pack) AddItemToUserPack(uId string, itemid, addnum int32) (code pb.ErrorCode) { + var err error defer log.Debugf("给用户添加物品 uId:%s itemid:%d addnum:%d issucc:%v", uId, itemid, addnum, err == nil) if err = this.model_pack_comp.Pack_AddItemToUserPack(uId, itemid, addnum); err != nil { log.Errorf("给用户添加物品 uId:%s itemid:%d addnum:%d err:%v", uId, itemid, addnum, err) + if err == ItemNotEnoughError { + code = pb.ErrorCode_PackNoEnough + } else if err == PackGridNumUpper { + code = pb.ErrorCode_PackGridNumUpper + } else { + code = pb.ErrorCode_Unknown + } } return } diff --git a/pb/proto/forum/forum_db.proto b/pb/proto/forum/forum_db.proto new file mode 100644 index 000000000..f3d2253e6 --- /dev/null +++ b/pb/proto/forum/forum_db.proto @@ -0,0 +1,3 @@ +syntax = "proto3"; +option go_package = ".;pb"; + diff --git a/pb/proto/forum/forum_msg.proto b/pb/proto/forum/forum_msg.proto new file mode 100644 index 000000000..fbeb20245 --- /dev/null +++ b/pb/proto/forum/forum_msg.proto @@ -0,0 +1,2 @@ +syntax = "proto3"; +option go_package = ".;pb"; \ No newline at end of file