package chat import ( "go_dreamfactory/comm" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" "go_dreamfactory/lego/core" ) const ( game_chatchannel = "game_chatchannel.json" game_chatsystem = "game_chatsystem.json" game_chatservergroup = "game_chatservergroup.json" game_chatchannelcom = "game_chatchannelcom.json" ) ///背包配置管理组件 type configureComp struct { modules.MCompConfigure module *Chat lock sync.RWMutex chatsystem map[int32][]*cfg.GameChatSystemData } //组件初始化接口 func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.MCompConfigure.Init(service, module, comp, options) this.module = module.(*Chat) this.LoadConfigure(game_chatchannel, cfg.NewGameChatChannel) configure.RegisterConfigure(game_chatsystem, cfg.NewGameChatSystem, func() { this.lock.Lock() if v, err := this.GetConfigure(game_chatsystem); err != nil { this.module.Errorf("err:%v", err) return } else { this.chatsystem = make(map[int32][]*cfg.GameChatSystemData) for _, v := range v.(*cfg.GameChatSystem).GetDataList() { if this.chatsystem[v.Type] == nil { this.chatsystem[v.Type] = make([]*cfg.GameChatSystemData, 0) } this.chatsystem[v.Type] = append(this.chatsystem[v.Type], v) } } this.lock.Unlock() }) this.LoadConfigure(game_chatchannelcom, cfg.NewGameChatChannelCom) return } //获取自动加入频道 任务限制 func (this *configureComp) GetAutoIntoChannelMax() (max int32, err error) { var ( v interface{} configure *cfg.GameChatChannelComData ok bool ) if v, err = this.GetConfigure(game_chatchannelcom); err != nil { this.module.Errorf("err:%v", err) return } else { if configure, ok = v.(*cfg.GameChatChannelCom).GetDataMap()["channel_allocation_max"]; !ok { err = comm.NewNotFoundConfErr(moduleName, game_chatchannelcom, "channel_allocation_max") // err = fmt.Errorf("cfg.Game_chatServerGroupData on found channel_allocation_max") this.module.Errorf("err:%v", err) return } max = configure.Value if max <= 0 { err = comm.NewNotFoundConfErr(moduleName, game_chatchannelcom, "channel_allocation_max:0") // err = fmt.Errorf("cfg.GamechatChannelComData channel_allocation_max:%v", v) } } return } //获取手动加入频道 任务限制 func (this *configureComp) GetChanageChannelMax() (max int32, err error) { var ( v interface{} configure *cfg.GameChatChannelComData ok bool ) if v, err = this.GetConfigure(game_chatchannelcom); err != nil { this.module.Errorf("err:%v", err) return } else { if configure, ok = v.(*cfg.GameChatChannelCom).GetDataMap()["channel_switching_max"]; !ok { err = comm.NewNotFoundConfErr(moduleName, game_chatchannelcom, "channel_switching_max") // err = fmt.Errorf("cfg.Game_chatServerGroupData on found channel_switching_max") this.module.Errorf("err:%v", err) return } max = configure.Value if max <= 0 { err = comm.NewNotFoundConfErr(moduleName, game_chatchannelcom, "channel_switching_max:0") // err = fmt.Errorf("cfg.GamechatChannelComData channel_switching_max:%v", v) } } return } //获取手动加入频道 任务限制 func (this *configureComp) GetChannelRecordMax() (max int32, err error) { var ( v interface{} configure *cfg.GameChatChannelComData ok bool ) if v, err = this.GetConfigure(game_chatchannelcom); err != nil { this.module.Errorf("err:%v", err) return } else { if configure, ok = v.(*cfg.GameChatChannelCom).GetDataMap()["max_chat"]; !ok { // err = fmt.Errorf("cfg.Game_chatServerGroupData on found max_chat") err = comm.NewNotFoundConfErr(moduleName, game_chatchannelcom, "max_chat") this.module.Errorln(err) return } max = configure.Value if max <= 0 { err = comm.NewNotFoundConfErr(moduleName, game_chatchannelcom, "max_chat:0") // err = fmt.Errorf("cfg.GamechatChannelComData max_chat:%v", v) } } return } //获取手动加入频道 任务限制 func (this *configureComp) GetChannelReadRecordNum() (max int32, err error) { var ( v interface{} configure *cfg.GameChatChannelComData ok bool ) if v, err = this.GetConfigure(game_chatchannelcom); err != nil { this.module.Errorf("err:%v", err) return } else { if configure, ok = v.(*cfg.GameChatChannelCom).GetDataMap()["load_chat"]; !ok { // err = fmt.Errorf("cfg.Game_chatServerGroupData on found max_chat") err = comm.NewNotFoundConfErr(moduleName, game_chatchannelcom, "load_chat") this.module.Errorf("err:%v", err) return } max = configure.Value if max <= 0 { // err = fmt.Errorf("cfg.GamechatChannelComData max_chat:%v", v) err = comm.NewNotFoundConfErr(moduleName, game_chatchannelcom, "load_chat:0") } } return } ///获取校验聊天系统推送 func (this *configureComp) GetCheckChatSystem(ctype int32, value0 int32, value1 int32) (sitem *cfg.GameChatSystemData, ok bool) { this.lock.RLock() vs, ok := this.chatsystem[ctype] this.lock.RUnlock() if ok { for _, v := range vs { if v.Data == value0 && v.Data2 == value1 { return v, true } } } return nil, false }