diff --git a/modules/chat/api_send.go b/modules/chat/api_send.go index 69ddfbd82..0b84cbd10 100644 --- a/modules/chat/api_send.go +++ b/modules/chat/api_send.go @@ -52,6 +52,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 { + 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 diff --git a/modules/chat/module.go b/modules/chat/module.go index cdd3478b2..f74070a8b 100644 --- a/modules/chat/module.go +++ b/modules/chat/module.go @@ -28,11 +28,18 @@ func NewModule() core.IModule { type Chat struct { modules.ModuleBase service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口 + options *Options + gm comm.IGm api_comp *apiComp configure *configureComp modelChat *modelChatComp } +//重构模块配置对象 +func (this *Chat) NewOptions() (options core.IModuleOptions) { + return new(Options) +} + //模块名 func (this *Chat) GetType() core.M_Modules { return comm.ModuleChat @@ -42,11 +49,17 @@ func (this *Chat) GetType() core.M_Modules { func (this *Chat) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service.(base.IRPCXService) + this.options = options.(*Options) return } func (this *Chat) Start() (err error) { err = this.ModuleBase.Start() + var module core.IModule + if module, err = this.service.GetModule(comm.ModuleGM); err != nil { + return + } + this.gm = module.(comm.IGm) event.RegisterGO(comm.EventUserOffline, this.EventUserOffline) return } diff --git a/modules/chat/options.go b/modules/chat/options.go new file mode 100644 index 000000000..a25c94c81 --- /dev/null +++ b/modules/chat/options.go @@ -0,0 +1,42 @@ +package chat + +import ( + "errors" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/lego/utils/mapstructure" + "go_dreamfactory/modules" +) + +type ( + IOptions interface { + modules.IOptions + } + Options struct { + modules.Options + GM bool //是否开启gm工具 + } +) + +func (this *Options) GetDebug() bool { + return this.Debug +} + +func (this *Options) GetLog() log.ILogger { + return this.Log +} + +func (this *Options) LoadConfig(settings map[string]interface{}) (err error) { + if settings != nil { + if err = mapstructure.Decode(settings, &this.Options); err != nil { + return + } + if err = mapstructure.Decode(settings, this); err != nil { + return + } + } + + if this.Log = log.NewTurnlog(this.Debug, log.Clone("", 4)); this.Log == nil { + err = errors.New("log is nil") + } + return +}