上传聊天gm命令

This commit is contained in:
liwei1dao 2022-09-19 11:02:28 +08:00
parent 70935119a4
commit 16862ec78a
3 changed files with 63 additions and 0 deletions

View File

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

View File

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

42
modules/chat/options.go Normal file
View File

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