diff --git a/comm/const.go b/comm/const.go index f1240d41a..c03a585a5 100644 --- a/comm/const.go +++ b/comm/const.go @@ -29,7 +29,7 @@ const ( //模块名定义处 const ( ModuleGate core.M_Modules = "gateway" //gate模块 网关服务模块 - ModuleWeb core.M_Modules = "web" //gm模块 + ModuleWeb core.M_Modules = "web" //后台模块 ModuleUser core.M_Modules = "user" //用户模块 ModulePack core.M_Modules = "pack" //背包模块 ModuleMail core.M_Modules = "mail" //邮件模块 @@ -44,6 +44,7 @@ const ( ModuleMainline core.M_Modules = "mainline" //主线模块 ModuleNotify core.M_Modules = "notify" //公告模块 ModuleChat core.M_Modules = "chat" //装备模块 + ModuleGM core.M_Modules = "gm" //gm模块 ) //RPC服务接口定义处 diff --git a/modules/gm/api.go b/modules/gm/api.go new file mode 100644 index 000000000..45c6f1a3d --- /dev/null +++ b/modules/gm/api.go @@ -0,0 +1,29 @@ +package gm + +import ( + "go_dreamfactory/modules" + + "go_dreamfactory/lego/core" +) + +/* +装备模块 API +*/ +type apiComp struct { + modules.MCompGate + service core.IService + module *GM +} + +//组件初始化接口 +func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.MCompGate.Init(service, module, comp, options) + this.module = module.(*GM) + this.service = service + return +} + +func (this *apiComp) Start() (err error) { + err = this.MCompGate.Start() + return +} diff --git a/modules/gm/module.go b/modules/gm/module.go new file mode 100644 index 000000000..fd6b30130 --- /dev/null +++ b/modules/gm/module.go @@ -0,0 +1,39 @@ +package gm + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" +) + +/* +模块名:GM工具模块 +描述:处理客户端发过来的gm命令 +开发:李伟 +*/ +func NewModule() core.IModule { + m := new(GM) + return m +} + +type GM struct { + modules.ModuleBase + api_comp *apiComp +} + +//模块名 +func (this *GM) GetType() core.M_Modules { + return comm.ModuleGM +} + +//模块初始化接口 注册用户创建角色事件 +func (this *GM) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { + err = this.ModuleBase.Init(service, module, options) + return +} + +//装备组件 +func (this *GM) OnInstallComp() { + this.ModuleBase.OnInstallComp() + this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp) +} diff --git a/modules/gm/module_test.go b/modules/gm/module_test.go new file mode 100644 index 000000000..b88548d2d --- /dev/null +++ b/modules/gm/module_test.go @@ -0,0 +1,83 @@ +package gm_test + +import ( + "fmt" + "go_dreamfactory/comm" + "go_dreamfactory/lego" + "go_dreamfactory/lego/base/rpcx" + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/modules/equipment" + "go_dreamfactory/modules/gm" + "go_dreamfactory/modules/hero" + "go_dreamfactory/modules/items" + "go_dreamfactory/modules/user" + "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(gm.GM) + +//测试环境下初始化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, + hero.NewModule(), + user.NewModule(), + items.NewModule(), + equipment.NewModule(), + ) + }() + time.Sleep(time.Second * 3) + defer os.Exit(m.Run()) +} + +func Test_Module(t *testing.T) { + +}