diff --git a/modules/configure_comp.go b/modules/comp_configure.go similarity index 62% rename from modules/configure_comp.go rename to modules/comp_configure.go index 6986c981f..2a45b932e 100644 --- a/modules/configure_comp.go +++ b/modules/comp_configure.go @@ -8,14 +8,14 @@ import ( ) ///配置管理基础组件 -type MComp_Configure struct { +type MCompConfigure struct { cbase.ModuleCompBase S base.IRPCXService //rpc服务对象 M IModule //当前业务模块 } //组件初始化接口 -func (this *MComp_Configure) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { +func (this *MCompConfigure) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.ModuleCompBase.Init(service, module, comp, options) this.S = service.(base.IRPCXService) this.M = module.(IModule) @@ -23,12 +23,12 @@ func (this *MComp_Configure) Init(service core.IService, module core.IModule, co } //加载一个配置文件 -func (this *MComp_Configure) LoadConfigure(name string, fn interface{}) (err error) { +func (this *MCompConfigure) LoadConfigure(name string, fn interface{}) (err error) { return configure.RegisterConfigure(name, fn) } //加载多个配置文件 -func (this *MComp_Configure) LoadMultiConfigure(confs map[string]interface{}) (err error) { +func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (err error) { for k, v := range confs { err = configure.RegisterConfigure(k, v) if err != nil { @@ -39,6 +39,6 @@ func (this *MComp_Configure) LoadMultiConfigure(confs map[string]interface{}) (e } //读取配置数据 -func (this *MComp_Configure) GetConfigure(name string) (v interface{}, err error) { +func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) { return configure.GetConfigure(name) } diff --git a/modules/gate_comp.go b/modules/comp_gate.go similarity index 86% rename from modules/gate_comp.go rename to modules/comp_gate.go index 89ba53cf0..e2a0bc3e6 100644 --- a/modules/gate_comp.go +++ b/modules/comp_gate.go @@ -28,7 +28,7 @@ var typeOfError = reflect.TypeOf((*error)(nil)).Elem() /* 模块 网关组件 接收处理用户传递消息 */ -type MComp_GateComp struct { +type MCompGate struct { cbase.ModuleCompBase service base.IRPCXService //rpc服务对象 module core.IModule //当前业务模块 @@ -37,7 +37,7 @@ type MComp_GateComp struct { } //组件初始化接口 -func (this *MComp_GateComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { +func (this *MCompGate) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.ModuleCompBase.Init(service, module, comp, options) this.service = service.(base.IRPCXService) this.module = module @@ -46,7 +46,7 @@ func (this *MComp_GateComp) Init(service core.IService, module core.IModule, com } //组件启动接口,启动时将自己接收用户消息的处理函数注册到services/comp_gateroute.go 对象中 -func (this *MComp_GateComp) Start() (err error) { +func (this *MCompGate) Start() (err error) { if err = this.ModuleCompBase.Start(); err != nil { return } @@ -61,7 +61,7 @@ func (this *MComp_GateComp) Start() (err error) { } //反射注册相关接口道services/comp_gateroute.go 对象中 -func (this *MComp_GateComp) suitableMethods(typ reflect.Type) { +func (this *MCompGate) suitableMethods(typ reflect.Type) { for m := 0; m < typ.NumMethod(); m++ { method := typ.Method(m) this.reflectionRouteHandle(method) @@ -70,7 +70,7 @@ func (this *MComp_GateComp) suitableMethods(typ reflect.Type) { } //反射注册路由处理函数 -func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) { +func (this *MCompGate) reflectionRouteHandle(method reflect.Method) { mtype := method.Type mname := method.Name if method.PkgPath != "" { @@ -105,7 +105,7 @@ func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) { } //反射注册路由校验函数 -func (this *MComp_GateComp) reflectionRouteCheck(method reflect.Method) { +func (this *MCompGate) reflectionRouteCheck(method reflect.Method) { mtype := method.Type mname := strings.Split(method.Name, "_") if len(mname) != 2 || mname[1] != "Check" { @@ -142,14 +142,14 @@ func (this *MComp_GateComp) reflectionRouteCheck(method reflect.Method) { this.scomp.RegisterRouteCheck(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname[0])), reflect.ValueOf(this.comp), replyType, method) } -func (this *MComp_GateComp) isExportedOrBuiltinType(t reflect.Type) bool { +func (this *MCompGate) isExportedOrBuiltinType(t reflect.Type) bool { for t.Kind() == reflect.Ptr { t = t.Elem() } return this.isExported(t.Name()) || t.PkgPath() == "" } -func (this *MComp_GateComp) isExported(name string) bool { +func (this *MCompGate) isExported(name string) bool { rune, _ := utf8.DecodeRuneInString(name) return unicode.IsUpper(rune) } diff --git a/modules/model_comp.go b/modules/comp_model.go similarity index 88% rename from modules/model_comp.go rename to modules/comp_model.go index 289172ccf..473023f51 100644 --- a/modules/model_comp.go +++ b/modules/comp_model.go @@ -23,7 +23,7 @@ import ( 基础组件 缓存组件 读写缓存数据 DB组件也封装进来 */ -type Model_Comp struct { +type MCompModel struct { cbase.ModuleCompBase Redis redis.ISys DB mgo.ISys @@ -35,25 +35,25 @@ const ( ) //组件初始化接口 -func (this *Model_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { +func (this *MCompModel) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.ModuleCompBase.Init(service, module, comp, options) this.Redis = cache.Redis() this.DB = db.Mgo() return } -func (this *Model_Comp) Start() (err error) { +func (this *MCompModel) Start() (err error) { err = this.ModuleCompBase.Start() return } -func (this *Model_Comp) ukey(uid string) string { +func (this *MCompModel) ukey(uid string) string { return fmt.Sprintf("%s:%s", this.TableName, uid) } -func (this *Model_Comp) ukeylist(uid string, id string) string { +func (this *MCompModel) ukeylist(uid string, id string) string { return fmt.Sprintf("%s:%s-%s", this.TableName, uid, id) } -func (this *Model_Comp) InsertModelLogs(table string, uID string, target interface{}) (err error) { +func (this *MCompModel) InsertModelLogs(table string, uID string, target interface{}) (err error) { data := &comm.Autogenerated{ ID: primitive.NewObjectID().Hex(), @@ -70,7 +70,7 @@ func (this *Model_Comp) InsertModelLogs(table string, uID string, target interfa return err } -func (this *Model_Comp) DeleteModelLogs(table string, uID string, where interface{}) (err error) { +func (this *MCompModel) DeleteModelLogs(table string, uID string, where interface{}) (err error) { data := &comm.Autogenerated{ ID: primitive.NewObjectID().Hex(), @@ -88,7 +88,7 @@ func (this *Model_Comp) DeleteModelLogs(table string, uID string, where interfac return err } -func (this *Model_Comp) UpdateModelLogs(table string, uID string, where bson.M, target interface{}) (err error) { +func (this *MCompModel) UpdateModelLogs(table string, uID string, where bson.M, target interface{}) (err error) { data := &comm.Autogenerated{ ID: primitive.NewObjectID().Hex(), @@ -108,7 +108,7 @@ func (this *Model_Comp) UpdateModelLogs(table string, uID string, where bson.M, } //添加新的数据 -func (this *Model_Comp) Add(uid string, data interface{}, attrs ...*cache.OperationAttr) (err error) { +func (this *MCompModel) Add(uid string, data interface{}, attrs ...*cache.OperationAttr) (err error) { if err = this.Redis.HMSet(this.ukey(uid), data); err != nil { return } @@ -122,7 +122,7 @@ func (this *Model_Comp) Add(uid string, data interface{}, attrs ...*cache.Operat } //添加新的数据到列表 -func (this *Model_Comp) AddList(uid string, id string, data interface{}, attrs ...*cache.OperationAttr) (err error) { +func (this *MCompModel) AddList(uid string, id string, data interface{}, attrs ...*cache.OperationAttr) (err error) { key := this.ukeylist(uid, id) if err = this.Redis.HMSet(key, data); err != nil { return @@ -140,7 +140,7 @@ func (this *Model_Comp) AddList(uid string, id string, data interface{}, attrs . } //添加新的多个数据到列表 data map[string]type -func (this *Model_Comp) AddLists(uid string, data interface{}, attrs ...*cache.OperationAttr) (err error) { +func (this *MCompModel) AddLists(uid string, data interface{}, attrs ...*cache.OperationAttr) (err error) { vof := reflect.ValueOf(data) if !vof.IsValid() { return fmt.Errorf("Model_Comp: AddLists(nil)") @@ -180,7 +180,7 @@ func (this *Model_Comp) AddLists(uid string, data interface{}, attrs ...*cache.O } //修改数据多个字段 uid 作为主键 -func (this *Model_Comp) Change(uid string, data map[string]interface{}, attrs ...*cache.OperationAttr) (err error) { +func (this *MCompModel) Change(uid string, data map[string]interface{}, attrs ...*cache.OperationAttr) (err error) { if err = this.Redis.HMSet(this.ukey(uid), data); err != nil { return } @@ -194,7 +194,7 @@ func (this *Model_Comp) Change(uid string, data map[string]interface{}, attrs .. } //修改数据多个字段 uid 作为主键 -func (this *Model_Comp) ChangeList(uid string, _id string, data map[string]interface{}, attrs ...*cache.OperationAttr) (err error) { +func (this *MCompModel) ChangeList(uid string, _id string, data map[string]interface{}, attrs ...*cache.OperationAttr) (err error) { if err = this.Redis.HMSet(this.ukeylist(uid, _id), data); err != nil { return } @@ -208,7 +208,7 @@ func (this *Model_Comp) ChangeList(uid string, _id string, data map[string]inter } //读取全部数据 -func (this *Model_Comp) Get(uid string, data interface{}) (err error) { +func (this *MCompModel) Get(uid string, data interface{}) (err error) { if err = this.Redis.HGetAll(this.ukey(uid), data); err != nil { return } @@ -223,7 +223,7 @@ func (this *Model_Comp) Get(uid string, data interface{}) (err error) { } //获取列表数据 注意 data 必须啊转 切片的指针 *[]type -func (this *Model_Comp) GetList(uid string, data interface{}) (err error) { +func (this *MCompModel) GetList(uid string, data interface{}) (err error) { var keys map[string]string = make(map[string]string) var c *mongo.Cursor t := reflect.TypeOf(data) @@ -314,25 +314,25 @@ func (this *Model_Comp) GetList(uid string, data interface{}) (err error) { } //读取单个数据中 多个字段数据 -func (this *Model_Comp) GetFields(uid string, data interface{}, fields ...string) (err error) { +func (this *MCompModel) GetFields(uid string, data interface{}, fields ...string) (err error) { this.Redis.HMGet(this.ukey(uid), data, fields...) return } //读取List列表中单个数据中 多个字段数据 -func (this *Model_Comp) GetListFields(uid string, id string, data interface{}, fields ...string) (err error) { +func (this *MCompModel) GetListFields(uid string, id string, data interface{}, fields ...string) (err error) { this.Redis.HMGet(this.ukeylist(uid, id), data, fields...) return } //读取列表数据中单个数据 -func (this *Model_Comp) GetListObj(uid string, id string, data interface{}) (err error) { +func (this *MCompModel) GetListObj(uid string, id string, data interface{}) (err error) { err = this.Redis.HGetAll(this.ukeylist(uid, id), data) return } //删除用户数据 -func (this *Model_Comp) Del(uid string) (err error) { +func (this *MCompModel) Del(uid string) (err error) { err = this.Redis.Delete(this.ukey(uid)) if err != nil { return err @@ -342,7 +342,7 @@ func (this *Model_Comp) Del(uid string) (err error) { } //删除多条数据 -func (this *Model_Comp) DelListlds(uid string, ids ...string) (err error) { +func (this *MCompModel) DelListlds(uid string, ids ...string) (err error) { listkey := this.ukey(uid) for _, v := range ids { key := this.ukeylist(uid, v) @@ -357,7 +357,7 @@ func (this *Model_Comp) DelListlds(uid string, ids ...string) (err error) { } //日志操作可选项 -func (this *Model_Comp) logOpt(uid string, data interface{}, attrs ...*cache.OperationAttr) error { +func (this *MCompModel) logOpt(uid string, data interface{}, attrs ...*cache.OperationAttr) error { ret := cache.OperationAttrs(attrs).Find(cache.ATTR_MGOLOG).Unwrap_Or(nil) if ret == nil { //启用mgolog ir := cache.OperationAttrs(attrs).Find(cache.ATTR_INSERT).Unwrap_Or(nil) diff --git a/modules/dbservice/db_comp.go b/modules/dbservice/db_comp.go index 24383fe2f..7ce216013 100644 --- a/modules/dbservice/db_comp.go +++ b/modules/dbservice/db_comp.go @@ -14,20 +14,20 @@ import ( ) type DB_Comp struct { - modules.Model_Comp + modules.MCompModel task chan string isInit bool } func (this *DB_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - this.Model_Comp.Init(service, module, comp, options) + this.MCompModel.Init(service, module, comp, options) this.task = make(chan string, TaskMaxNum) return } func (this *DB_Comp) Start() (err error) { - err = this.Model_Comp.Start() + err = this.MCompModel.Start() model_count := this.Model_TotalCount() if model_count > 0 { //1000 this.Redis.Set(comm.DBService_Status, true, -1) diff --git a/modules/equipment/api.go b/modules/equipment/api.go index 992842bdc..ae992f1a5 100644 --- a/modules/equipment/api.go +++ b/modules/equipment/api.go @@ -9,21 +9,21 @@ import ( /* 装备模块 API */ -type Api_Comp struct { - modules.MComp_GateComp +type ApiComp struct { + modules.MCompGate service core.IService module *Equipment } //组件初始化接口 -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) +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.(*Equipment) this.service = service return } -func (this *Api_Comp) Start() (err error) { - err = this.MComp_GateComp.Start() +func (this *ApiComp) Start() (err error) { + err = this.MCompGate.Start() return } diff --git a/modules/equipment/api_equip.go b/modules/equipment/api_equip.go index bea0f569f..69c4148e6 100644 --- a/modules/equipment/api_equip.go +++ b/modules/equipment/api_equip.go @@ -8,7 +8,7 @@ import ( ) //参数校验 -func (this *Api_Comp) Equip_Check(session comm.IUserSession, req *pb.Equipment_Equip_Req) (result map[string]interface{}, code comm.ErrorCode) { +func (this *ApiComp) Equip_Check(session comm.IUserSession, req *pb.Equipment_Equip_Req) (result map[string]interface{}, code comm.ErrorCode) { var ( err error errorCode pb.ErrorCode @@ -20,12 +20,12 @@ func (this *Api_Comp) Equip_Check(session comm.IUserSession, req *pb.Equipment_E equipments = make([]*pb.DB_Equipment, len(req.EquipmentId)) for i, v := range req.EquipmentId { if v != "" { - if equipments[i], err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsById(session.GetUserId(), v); err != nil { + if equipments[i], err = this.module.modelequipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil { log.Errorf("Equip_Check err:%v", err) code.Code = pb.ErrorCode_EquipmentOnFoundEquipment return } - if confs[i], err = this.module.configure_comp.GetEquipmentConfigureById(equipments[i].CId); err != nil { + if confs[i], err = this.module.configure.GetEquipmentConfigureById(equipments[i].CId); err != nil { log.Errorf("Equip_Check err:%v", err) code.Code = pb.ErrorCode_EquipmentOnFoundEquipment return @@ -46,7 +46,7 @@ func (this *Api_Comp) Equip_Check(session comm.IUserSession, req *pb.Equipment_E } ///英雄挂在装备 -func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_Equip_Req) (code pb.ErrorCode) { +func (this *ApiComp) Equip(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_Equip_Req) (code pb.ErrorCode) { var ( err error confs []*cfg.Game_equipData @@ -55,11 +55,7 @@ func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface updatequipment []*pb.DB_Equipment hero *pb.DB_HeroData ) - defer func() { - if code == pb.ErrorCode_Success { - session.SendMsg(string(this.module.GetType()), "", &pb.Equipment_Equip_Resp{}) - } - }() + confs = agrs["conf"].([]*cfg.Game_equipData) equipments = agrs["equipment"].([]*pb.DB_Equipment) updatequipment = make([]*pb.DB_Equipment, 0) @@ -68,7 +64,7 @@ func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface for i, v := range hero.EquipID { if v != "" { if equipments[i] != nil && v != equipments[i].Id { - if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsById(session.GetUserId(), v); err != nil { + if equipment, err = this.module.modelequipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil { log.Errorf("Equip reader uid:%s equipment:%s err:%v", session.GetUserId(), v, err) code = pb.ErrorCode_SystemError return @@ -77,7 +73,7 @@ func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface equipments[i].HeroId = hero.Id updatequipment = append(updatequipment, equipment, equipments[i]) } else if equipments[i] == nil { - if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsById(session.GetUserId(), v); err != nil { + if equipment, err = this.module.modelequipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil { log.Errorf("Equip reader uid:%s equipment:%s err:%v", session.GetUserId(), v, err) code = pb.ErrorCode_SystemError return @@ -100,7 +96,7 @@ func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface } } if code = this.module.hero.UpdateEquipment(hero, equipments); code == pb.ErrorCode_Success { - if err = this.module.model_equipment_comp.Equipment_UpdateByHeroId(session.GetUserId(), updatequipment...); err != nil { + if err = this.module.modelequipment.UpdateByHeroId(session.GetUserId(), updatequipment...); err != nil { log.Errorf("Equip err%v", err) code = pb.ErrorCode_SystemError return diff --git a/modules/equipment/api_getlist.go b/modules/equipment/api_getlist.go index 89b79a60f..9de1c44ae 100644 --- a/modules/equipment/api_getlist.go +++ b/modules/equipment/api_getlist.go @@ -7,26 +7,27 @@ import ( ) //参数校验 -func (this *Api_Comp) Getlist_Check(session comm.IUserSession, req *pb.Equipment_GetList_Req) (result map[string]interface{}, code comm.ErrorCode) { +func (this *ApiComp) Getlist_Check(session comm.IUserSession, req *pb.Equipment_GetList_Req) (result map[string]interface{}, code comm.ErrorCode) { return } ///获取用户装备列表 -func (this *Api_Comp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_GetList_Req) (code pb.ErrorCode) { +func (this *ApiComp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_GetList_Req, resp *pb.Equipment_GetList_Resp) (code pb.ErrorCode) { var ( err error items []*pb.DB_Equipment ) - defer func() { - if code == pb.ErrorCode_Success { - session.SendMsg(string(this.module.GetType()), "", &pb.Equipment_GetList_Resp{Equipments: items}) - } - }() - if items, err = this.module.model_equipment_comp.Equipment_QueryUserEquipments(session.GetUserId()); err != nil { + // defer func() { + // if code == pb.ErrorCode_Success { + // session.SendMsg(string(this.module.GetType()), "", &pb.Equipment_GetList_Resp{Equipments: items}) + // } + // }() + if items, err = this.module.modelequipment.QueryUserEquipments(session.GetUserId()); err != nil { log.Errorf("QueryUserPackReq err:%v", err) code = pb.ErrorCode_CacheReadError return } + resp.Equipments = items return } diff --git a/modules/equipment/api_upgrade.go b/modules/equipment/api_upgrade.go index da605b8e7..6b98ff2cc 100644 --- a/modules/equipment/api_upgrade.go +++ b/modules/equipment/api_upgrade.go @@ -12,7 +12,7 @@ import ( ) //参数校验 -func (this *Api_Comp) Upgrade_Check(session comm.IUserSession, req *pb.Equipment_Upgrade_Req) (result map[string]interface{}, code comm.ErrorCode) { +func (this *ApiComp) Upgrade_Check(session comm.IUserSession, req *pb.Equipment_Upgrade_Req) (result map[string]interface{}, code comm.ErrorCode) { var ( err error conf *cfg.Game_equipData @@ -24,18 +24,18 @@ func (this *Api_Comp) Upgrade_Check(session comm.IUserSession, req *pb.Equipment code.Code = pb.ErrorCode_ReqParameterError return } - if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsById(session.GetUserId(), req.EquipmentId); err != nil { + if equipment, err = this.module.modelequipment.QueryUserEquipmentsById(session.GetUserId(), req.EquipmentId); err != nil { log.Errorf("Equip_Check err:%v", err) code.Code = pb.ErrorCode_EquipmentOnFoundEquipment return } - if conf, err = this.module.configure_comp.GetEquipmentConfigureById(equipment.CId); err != nil { + if conf, err = this.module.configure.GetEquipmentConfigureById(equipment.CId); err != nil { log.Errorf("Equip_Check err:%v", err) code.Code = pb.ErrorCode_EquipmentOnFoundEquipment return } //找到下一个等级的相关配置 - if intensify, err = this.module.configure_comp.GetEquipmentIntensifyConfigureById(equipment.Lv); err != nil { + if intensify, err = this.module.configure.GetEquipmentIntensifyConfigureById(equipment.Lv); err != nil { log.Errorf("Equip_Check err:%v", err) code.Code = pb.ErrorCode_EquipmentLvlimitReached return @@ -49,7 +49,7 @@ func (this *Api_Comp) Upgrade_Check(session comm.IUserSession, req *pb.Equipment } ///英雄挂在装备 -func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_Upgrade_Req) (code pb.ErrorCode) { +func (this *ApiComp) Upgrade(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_Upgrade_Req) (code pb.ErrorCode) { var ( err error conf *cfg.Game_equipData @@ -85,7 +85,7 @@ func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interfa //叠加装备 拆分处理 if equipment.IsInitialState && equipment.OverlayNum > 1 { equipment.OverlayNum-- - if err = this.module.model_equipment_comp.ChangeList(session.GetUserId(), equipment.Id, map[string]interface{}{ + if err = this.module.modelequipment.ChangeList(session.GetUserId(), equipment.Id, map[string]interface{}{ "overlayNum": equipment.OverlayNum, "heroId": "", }); err != nil { @@ -97,24 +97,24 @@ func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interfa equipment.Id = primitive.NewObjectID().Hex() equipment.IsInitialState = false equipment.OverlayNum = 1 - if err = this.module.model_equipment_comp.upgradeEquipment(equipment, conf, intensify); err != nil { + if err = this.module.modelequipment.upgradeEquipment(equipment, conf, intensify); err != nil { code = pb.ErrorCode_SystemError log.Errorf("Upgrade err:%v", err) return } - if err = this.module.model_equipment_comp.AddList(session.GetUserId(), equipment.Id, equipment); err != nil { + if err = this.module.modelequipment.AddList(session.GetUserId(), equipment.Id, equipment); err != nil { log.Errorf("Upgrade err:%v", err) code = pb.ErrorCode_SystemError return } } else { equipment.IsInitialState = false - if err = this.module.model_equipment_comp.upgradeEquipment(equipment, conf, intensify); err != nil { + if err = this.module.modelequipment.upgradeEquipment(equipment, conf, intensify); err != nil { code = pb.ErrorCode_SystemError log.Errorf("Upgrade err:%v", err) return } - if err = this.module.model_equipment_comp.ChangeList(session.GetUserId(), equipment.Id, map[string]interface{}{ + if err = this.module.modelequipment.ChangeList(session.GetUserId(), equipment.Id, map[string]interface{}{ "lv": equipment.Lv, "mainEntry": equipment.MainEntry, "adverbEntry": equipment.AdverbEntry, @@ -136,7 +136,7 @@ func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interfa for i, v := range hero.EquipID { if v != "" { if v != equipment.Id { - if equipments[i], err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsById(session.GetUserId(), v); err != nil { + if equipments[i], err = this.module.modelequipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil { log.Errorf("Upgrade err:%v", err) code = pb.ErrorCode_EquipmentOnFoundEquipment return diff --git a/modules/equipment/configure_comp.go b/modules/equipment/configure.go similarity index 75% rename from modules/equipment/configure_comp.go rename to modules/equipment/configure.go index fc8e81615..19085ec81 100644 --- a/modules/equipment/configure_comp.go +++ b/modules/equipment/configure.go @@ -17,12 +17,12 @@ const ( ) ///背包配置管理组件 -type Configure_Comp struct { - modules.MComp_Configure +type ConfigureComp struct { + modules.MCompConfigure } //组件初始化接口 -func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { +func (this *ConfigureComp) 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_equip, cfg.NewGame_equip) this.LoadConfigure(equip_attrlibrary, cfg.NewGame_equipAttrlibrary) @@ -30,7 +30,7 @@ func (this *Configure_Comp) Init(service core.IService, module core.IModule, com } //获取装备配置数据 -func (this *Configure_Comp) GetEquipmentConfigure() (configure *cfg.Game_equip, err error) { +func (this *ConfigureComp) GetEquipmentConfigure() (configure *cfg.Game_equip, err error) { var ( v interface{} ok bool @@ -49,7 +49,7 @@ func (this *Configure_Comp) GetEquipmentConfigure() (configure *cfg.Game_equip, } //获取装备配置数据 -func (this *Configure_Comp) GetEquipmentConfigureById(equipmentId int32) (configure *cfg.Game_equipData, err error) { +func (this *ConfigureComp) GetEquipmentConfigureById(equipmentId int32) (configure *cfg.Game_equipData, err error) { var ( v interface{} ok bool @@ -68,7 +68,7 @@ func (this *Configure_Comp) GetEquipmentConfigureById(equipmentId int32) (config } //获取装备属性表 -func (this *Configure_Comp) GetEquipmentAttrlibraryConfigure() (configure *cfg.Game_equipAttrlibrary, err error) { +func (this *ConfigureComp) GetEquipmentAttrlibraryConfigure() (configure *cfg.Game_equipAttrlibrary, err error) { var ( v interface{} ok bool @@ -87,7 +87,7 @@ func (this *Configure_Comp) GetEquipmentAttrlibraryConfigure() (configure *cfg.G } //获取属性词列表 -func (this *Configure_Comp) GetEquipmentAttrlibraryConfigureByKey(key int32) (configure *cfg.Game_equipAttrlibraryData, err error) { +func (this *ConfigureComp) GetEquipmentAttrlibraryConfigureByKey(key int32) (configure *cfg.Game_equipAttrlibraryData, err error) { var ( v interface{} ok bool @@ -106,7 +106,7 @@ func (this *Configure_Comp) GetEquipmentAttrlibraryConfigureByKey(key int32) (co } //获取属性词列表 -func (this *Configure_Comp) GetEquipmentAttrlibraryConfigureById(Id int32) (configure []*cfg.Game_equipAttrlibraryData, err error) { +func (this *ConfigureComp) GetEquipmentAttrlibraryConfigureById(Id int32) (configure []*cfg.Game_equipAttrlibraryData, err error) { var ( v interface{} ) @@ -125,7 +125,7 @@ func (this *Configure_Comp) GetEquipmentAttrlibraryConfigureById(Id int32) (conf } //获取武器等级消耗表 -func (this *Configure_Comp) GetEquipmentIntensifyConfigure() (configure *cfg.Game_equipIntensify, err error) { +func (this *ConfigureComp) GetEquipmentIntensifyConfigure() (configure *cfg.Game_equipIntensify, err error) { var ( v interface{} ok bool @@ -144,7 +144,7 @@ func (this *Configure_Comp) GetEquipmentIntensifyConfigure() (configure *cfg.Gam } //获取武器等级消耗表 -func (this *Configure_Comp) GetEquipmentIntensifyConfigureById(Id int32) (configure *cfg.Game_equipIntensifyData, err error) { +func (this *ConfigureComp) GetEquipmentIntensifyConfigureById(Id int32) (configure *cfg.Game_equipIntensifyData, err error) { var ( v interface{} ok bool diff --git a/modules/equipment/model_equipment_comp.go b/modules/equipment/model_equipment.go similarity index 72% rename from modules/equipment/model_equipment_comp.go rename to modules/equipment/model_equipment.go index 92b0941ea..a7a911885 100644 --- a/modules/equipment/model_equipment_comp.go +++ b/modules/equipment/model_equipment.go @@ -15,14 +15,14 @@ import ( ) ///装备 数据组件 -type Model_Equipment_Comp struct { - modules.Model_Comp +type ModelEquipmentComp struct { + modules.MCompModel module *Equipment } //组件初始化接口 -func (this *Model_Equipment_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { - this.Model_Comp.Init(service, module, comp, opt) +func (this *ModelEquipmentComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { + this.MCompModel.Init(service, module, comp, opt) this.module = module.(*Equipment) this.TableName = "equipment" //创建uid索引 @@ -33,27 +33,27 @@ func (this *Model_Equipment_Comp) Init(service core.IService, module core.IModul } //查询用户装备数据 -func (this *Model_Equipment_Comp) Equipment_QueryUserEquipmentsById(uId, id string) (equipment *pb.DB_Equipment, err error) { +func (this *ModelEquipmentComp) QueryUserEquipmentsById(uId, id string) (equipment *pb.DB_Equipment, err error) { equipment = &pb.DB_Equipment{} err = this.GetListObj(uId, id, equipment) return } ///查询用户的武器背包 -func (this *Model_Equipment_Comp) Equipment_QueryUserEquipments(uId string) (equipments []*pb.DB_Equipment, err error) { +func (this *ModelEquipmentComp) QueryUserEquipments(uId string) (equipments []*pb.DB_Equipment, err error) { equipments = make([]*pb.DB_Equipment, 0) err = this.GetList(uId, &equipments) return } ///查询目标卡片数量 -func (this *Model_Equipment_Comp) QueryEquipmentAmount(uid string, equipmentId int32) (amount uint32) { +func (this *ModelEquipmentComp) QueryEquipmentAmount(uid string, equipmentId int32) (amount uint32) { var ( equipments []*pb.DB_Equipment err error ) amount = 0 - if equipments, err = this.Equipment_QueryUserEquipments(uid); err != nil { + if equipments, err = this.QueryUserEquipments(uid); err != nil { return } for _, v := range equipments { @@ -65,7 +65,7 @@ func (this *Model_Equipment_Comp) QueryEquipmentAmount(uid string, equipmentId i } //添加装备 -func (this *Model_Equipment_Comp) Equipment_AddEquipments(uId string, cIds map[int32]uint32) (err error) { +func (this *ModelEquipmentComp) AddEquipments(uId string, cIds map[int32]uint32) (err error) { var ( configure *cfg.Game_equip equipments []*pb.DB_Equipment @@ -73,10 +73,10 @@ func (this *Model_Equipment_Comp) Equipment_AddEquipments(uId string, cIds map[i add map[string]*pb.DB_Equipment update map[string]*pb.DB_Equipment ) - if configure, err = this.module.configure_comp.GetEquipmentConfigure(); err != nil { + if configure, err = this.module.configure.GetEquipmentConfigure(); err != nil { return } - if equipments, err = this.Equipment_QueryUserEquipments(uId); err != nil { + if equipments, err = this.QueryUserEquipments(uId); err != nil { return } add = make(map[string]*pb.DB_Equipment) @@ -115,7 +115,7 @@ func (this *Model_Equipment_Comp) Equipment_AddEquipments(uId string, cIds map[i } //更新武器挂载信息 -func (this *Model_Equipment_Comp) Equipment_UpdateByHeroId(uid string, equipments ...*pb.DB_Equipment) (err error) { +func (this *ModelEquipmentComp) UpdateByHeroId(uid string, equipments ...*pb.DB_Equipment) (err error) { for _, v := range equipments { if err = this.ChangeList(uid, v.Id, map[string]interface{}{ "heroId": v.HeroId, @@ -128,7 +128,7 @@ func (this *Model_Equipment_Comp) Equipment_UpdateByHeroId(uid string, equipment } //创建新的武器对象 -func (this *Model_Equipment_Comp) newEquipment(uid string, conf *cfg.Game_equipData, num uint32) (equipment *pb.DB_Equipment, err error) { +func (this *ModelEquipmentComp) newEquipment(uid string, conf *cfg.Game_equipData, num uint32) (equipment *pb.DB_Equipment, err error) { var ( mattr []*cfg.Game_equipAttrlibraryData sattr []*cfg.Game_equipAttrlibraryData @@ -144,7 +144,7 @@ func (this *Model_Equipment_Comp) newEquipment(uid string, conf *cfg.Game_equipD IsInitialState: true, AdverbEntry: make([]*pb.EquipmentAttributeEntry, 0), } - if mattr, err = this.module.configure_comp.GetEquipmentAttrlibraryConfigureById(conf.Leadlibrary); err != nil || len(mattr) == 0 { + if mattr, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(conf.Leadlibrary); err != nil || len(mattr) == 0 { return } equipment.MainEntry = &pb.EquipmentAttributeEntry{ @@ -154,7 +154,7 @@ func (this *Model_Equipment_Comp) newEquipment(uid string, conf *cfg.Game_equipD AttrName: mattr[0].Attrkey, Value: mattr[0].Attrvar, } - if sattr, err = this.module.configure_comp.GetEquipmentAttrlibraryConfigureById(conf.Addlibrary); err != nil || len(mattr) == 0 { + if sattr, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(conf.Addlibrary); err != nil || len(mattr) == 0 { return } @@ -184,7 +184,7 @@ func (this *Model_Equipment_Comp) newEquipment(uid string, conf *cfg.Game_equipD } //升级武器 -func (this *Model_Equipment_Comp) upgradeEquipment(equipment *pb.DB_Equipment, equip *cfg.Game_equipData, intensify *cfg.Game_equipIntensifyData) (err error) { +func (this *ModelEquipmentComp) upgradeEquipment(equipment *pb.DB_Equipment, equip *cfg.Game_equipData, intensify *cfg.Game_equipIntensifyData) (err error) { equipment.Lv++ equipment.MainEntry.Lv++ equipment.MainEntry.Value += equipment.MainEntry.Value * (intensify.Bonus / 1000.0) @@ -194,7 +194,7 @@ func (this *Model_Equipment_Comp) upgradeEquipment(equipment *pb.DB_Equipment, e if len(equipment.AdverbEntry) < 4 { //去随机副词条 var temp []*cfg.Game_equipAttrlibraryData var sattr []*cfg.Game_equipAttrlibraryData - if temp, err = this.module.configure_comp.GetEquipmentAttrlibraryConfigureById(equip.Addlibrary); err != nil || len(temp) == 0 { + if temp, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(equip.Addlibrary); err != nil || len(temp) == 0 { log.Errorf("升级服务错误 读取副词条配置错误!") return } @@ -224,7 +224,7 @@ func (this *Model_Equipment_Comp) upgradeEquipment(equipment *pb.DB_Equipment, e r := rand.New(rand.NewSource(time.Now().Unix())) index := r.Perm(len(equipment.AdverbEntry))[0] - if attrlibrary, err = this.module.configure_comp.GetEquipmentAttrlibraryConfigureByKey(equipment.AdverbEntry[index].Id); err != nil { + if attrlibrary, err = this.module.configure.GetEquipmentAttrlibraryConfigureByKey(equipment.AdverbEntry[index].Id); err != nil { return } equipment.AdverbEntry[index].Value += attrlibrary.Addition[equipment.AdverbEntry[index].Lv-1] / 1000.0 * attrlibrary.Attrvar diff --git a/modules/equipment/module.go b/modules/equipment/module.go index dbacf2ca0..5bb3b92c7 100644 --- a/modules/equipment/module.go +++ b/modules/equipment/module.go @@ -22,11 +22,11 @@ func NewModule() core.IModule { type Equipment struct { modules.ModuleBase - service core.IService - api_comp *Api_Comp - configure_comp *Configure_Comp - model_equipment_comp *Model_Equipment_Comp - hero comm.IHero + service core.IService + api *ApiComp + configure *ConfigureComp + modelequipment *ModelEquipmentComp + hero comm.IHero } //模块名 @@ -56,16 +56,16 @@ func (this *Equipment) Start() (err error) { //装备组件 func (this *Equipment) OnInstallComp() { this.ModuleBase.OnInstallComp() - this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) - this.model_equipment_comp = this.RegisterComp(new(Model_Equipment_Comp)).(*Model_Equipment_Comp) - this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) + this.api = this.RegisterComp(new(ApiComp)).(*ApiComp) + this.modelequipment = this.RegisterComp(new(ModelEquipmentComp)).(*ModelEquipmentComp) + this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp) } //IEquipment------------------------------------------------------------------------------------------------------------------------------- //查询武器信息 func (this *Equipment) QueryEquipment(source *comm.ModuleCallSource, uid string, Id string) (equipment *pb.DB_Equipment, code pb.ErrorCode) { var err error - if equipment, err = this.model_equipment_comp.Equipment_QueryUserEquipmentsById(uid, Id); err != nil { + if equipment, err = this.modelequipment.QueryUserEquipmentsById(uid, Id); err != nil { if err == redis.Nil { code = pb.ErrorCode_EquipmentOnFoundEquipment } else { @@ -77,14 +77,14 @@ func (this *Equipment) QueryEquipment(source *comm.ModuleCallSource, uid string, //查询卡片数量 func (this *Equipment) QueryEquipmentAmount(source *comm.ModuleCallSource, uid string, equipmentId int32) (amount uint32) { - amount = this.model_equipment_comp.QueryEquipmentAmount(uid, equipmentId) + amount = this.modelequipment.QueryEquipmentAmount(uid, equipmentId) return } //添加武器 func (this *Equipment) AddNewEquipments(source *comm.ModuleCallSource, uid string, cIds map[int32]uint32) (code pb.ErrorCode) { var err error - if err = this.model_equipment_comp.Equipment_AddEquipments(uid, cIds); err != nil { + if err = this.modelequipment.AddEquipments(uid, cIds); err != nil { log.Errorf("err%v", err) code = pb.ErrorCode_SystemError } diff --git a/modules/equipment/module_test.go b/modules/equipment/module_test.go index d30f57b02..811d65168 100644 --- a/modules/equipment/module_test.go +++ b/modules/equipment/module_test.go @@ -1,4 +1,4 @@ -package equipment +package equipment_test import ( "fmt" @@ -7,6 +7,7 @@ import ( "go_dreamfactory/lego/base/rpcx" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" + "go_dreamfactory/modules/equipment" "go_dreamfactory/modules/hero" "go_dreamfactory/services" "go_dreamfactory/sys/cache" @@ -50,7 +51,7 @@ func (this *TestService) InitSys() { var service core.IService var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp() -var module = new(Equipment) +var module = new(equipment.Equipment) //测试环境下初始化db和cache 系统 func TestMain(m *testing.M) { diff --git a/modules/game/module.go b/modules/game/module.go index 0d62a9443..54a4bf566 100644 --- a/modules/game/module.go +++ b/modules/game/module.go @@ -18,8 +18,8 @@ func NewModule() core.IModule { type Game struct { modules.ModuleBase - api_comp *Api_Comp - configure_comp *Configure_Comp + api *ApiComp + configure *ConfigureComp } //模块名 @@ -36,6 +36,6 @@ func (this *Game) Init(service core.IService, module core.IModule, options core. //装备组件 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) + this.api = this.RegisterComp(new(ApiComp)).(*ApiComp) + this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp) } diff --git a/modules/gateway/agentmgr_comp.go b/modules/gateway/agentmgr_comp.go index 56c73e7b0..d9c22f9c3 100644 --- a/modules/gateway/agentmgr_comp.go +++ b/modules/gateway/agentmgr_comp.go @@ -16,13 +16,13 @@ import ( /* 用户代理对象管理组件 */ -type AgentMgr_Comp struct { +type AgentMgrComp struct { cbase.ModuleCompBase 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) { +func (this *AgentMgrComp) 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) @@ -30,12 +30,12 @@ func (this *AgentMgr_Comp) Init(service core.IService, module core.IModule, comp } //加入新的用户 -func (this *AgentMgr_Comp) Connect(a IAgent) { +func (this *AgentMgrComp) Connect(a IAgent) { this.agents.Store(a.SessionId(), a) } //移除断开的用户 -func (this *AgentMgr_Comp) DisConnect(a IAgent) { +func (this *AgentMgrComp) DisConnect(a IAgent) { this.agents.Delete(a.SessionId()) if a.UserId() != "" { //登录用户 通知业务服务处理玩家离线相关 reply := &pb.RPCMessageReply{} @@ -48,7 +48,7 @@ func (this *AgentMgr_Comp) DisConnect(a IAgent) { } //用户登录绑定Id -func (this *AgentMgr_Comp) Bind(ctx context.Context, args *pb.AgentBuildReq, reply *pb.RPCMessageReply) error { +func (this *AgentMgrComp) Bind(ctx context.Context, args *pb.AgentBuildReq, reply *pb.RPCMessageReply) error { if a, ok := this.agents.Load(args.UserSessionId); ok { a.(IAgent).Bind(args.UserId, args.WorkerId) } else { @@ -59,7 +59,7 @@ func (this *AgentMgr_Comp) Bind(ctx context.Context, args *pb.AgentBuildReq, rep } //用户登录解绑Id -func (this *AgentMgr_Comp) UnBind(ctx context.Context, args *pb.AgentUnBuildReq, reply *pb.RPCMessageReply) error { +func (this *AgentMgrComp) UnBind(ctx context.Context, args *pb.AgentUnBuildReq, reply *pb.RPCMessageReply) error { if a, ok := this.agents.Load(args.UserSessionId); ok { a.(IAgent).UnBind() } else { @@ -70,7 +70,7 @@ func (this *AgentMgr_Comp) UnBind(ctx context.Context, args *pb.AgentUnBuildReq, } //向用户发送消息 -func (this *AgentMgr_Comp) SendMsgToAgent(ctx context.Context, args *pb.AgentSendMessageReq, reply *pb.RPCMessageReply) error { +func (this *AgentMgrComp) SendMsgToAgent(ctx context.Context, args *pb.AgentSendMessageReq, reply *pb.RPCMessageReply) error { if a, ok := this.agents.Load(args.UserSessionId); ok { a.(IAgent).WriteMsg(&pb.UserMessage{ MainType: args.MainType, @@ -85,7 +85,7 @@ func (this *AgentMgr_Comp) SendMsgToAgent(ctx context.Context, args *pb.AgentSen } //向多个户发送消息 -func (this *AgentMgr_Comp) SendMsgToAgents(ctx context.Context, args *pb.BatchMessageReq, reply *pb.RPCMessageReply) error { +func (this *AgentMgrComp) SendMsgToAgents(ctx context.Context, args *pb.BatchMessageReq, reply *pb.RPCMessageReply) error { msg := &pb.UserMessage{ MainType: args.MainType, SubType: args.SubType, @@ -100,7 +100,7 @@ func (this *AgentMgr_Comp) SendMsgToAgents(ctx context.Context, args *pb.BatchMe } //向所有户发送消息 -func (this *AgentMgr_Comp) SendMsgToAllAgent(ctx context.Context, args *pb.BroadCastMessageReq, reply *pb.RPCMessageReply) error { +func (this *AgentMgrComp) SendMsgToAllAgent(ctx context.Context, args *pb.BroadCastMessageReq, reply *pb.RPCMessageReply) error { msg := &pb.UserMessage{ MainType: args.MainType, SubType: args.SubType, @@ -114,7 +114,7 @@ func (this *AgentMgr_Comp) SendMsgToAllAgent(ctx context.Context, args *pb.Broad } //关闭代理 -func (this *AgentMgr_Comp) CloseAgent(ctx context.Context, args *pb.AgentCloseeReq, reply *pb.RPCMessageReply) error { +func (this *AgentMgrComp) CloseAgent(ctx context.Context, args *pb.AgentCloseeReq, reply *pb.RPCMessageReply) error { if a, ok := this.agents.Load(args.UserSessionId); ok { a.(IAgent).Close() } else { diff --git a/modules/gateway/module.go b/modules/gateway/module.go index ec6f45569..b2c452f95 100644 --- a/modules/gateway/module.go +++ b/modules/gateway/module.go @@ -21,10 +21,10 @@ func NewModule() core.IModule { type Gateway struct { modules.ModuleBase - service base.IRPCXService - wsservice_comp *WSService_Comp //websocket 服务组件 提供websocket服务监听 - agentmgr_comp *AgentMgr_Comp //用户代理对象管理组件 管理用户socekt对象 - configure_comp *Configure_Comp + service base.IRPCXService + wsservice *WSServiceComp //websocket 服务组件 提供websocket服务监听 + agentmgr *AgentMgrComp //用户代理对象管理组件 管理用户socekt对象 + configure *ConfigureComp } //模块名 @@ -52,17 +52,17 @@ func (this *Gateway) Init(service core.IService, module core.IModule, options co //模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务 func (this *Gateway) Start() (err error) { //注册用户绑定uid接口 登录成功后触发 - this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentBind), this.agentmgr_comp.Bind) + this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentBind), this.agentmgr.Bind) //注册用户解绑uid接口 登出或则切换账号是触发 - this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentUnBind), this.agentmgr_comp.UnBind) + this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentUnBind), this.agentmgr.UnBind) //向用户发送消息接口 - this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentSendMsg), this.agentmgr_comp.SendMsgToAgent) + this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentSendMsg), this.agentmgr.SendMsgToAgent) //向多个用户对象发送消息接口 - this.service.RegisterFunctionName(string(comm.Rpc_GatewaySendBatchMsg), this.agentmgr_comp.SendMsgToAgents) + this.service.RegisterFunctionName(string(comm.Rpc_GatewaySendBatchMsg), this.agentmgr.SendMsgToAgents) //向所有用户发送消息接口 - this.service.RegisterFunctionName(string(comm.Rpc_GatewaySendRadioMsg), this.agentmgr_comp.SendMsgToAllAgent) + this.service.RegisterFunctionName(string(comm.Rpc_GatewaySendRadioMsg), this.agentmgr.SendMsgToAllAgent) //关闭用户socket连接接口 - this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentClose), this.agentmgr_comp.CloseAgent) + this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentClose), this.agentmgr.CloseAgent) err = this.ModuleBase.Start() return } @@ -70,24 +70,24 @@ func (this *Gateway) Start() (err error) { //装备组件 func (this *Gateway) OnInstallComp() { this.ModuleBase.OnInstallComp() - this.agentmgr_comp = this.RegisterComp(new(AgentMgr_Comp)).(*AgentMgr_Comp) - this.wsservice_comp = this.RegisterComp(new(WSService_Comp)).(*WSService_Comp) - this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) + this.agentmgr = this.RegisterComp(new(AgentMgrComp)).(*AgentMgrComp) + this.wsservice = this.RegisterComp(new(WSServiceComp)).(*WSServiceComp) + this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp) } //有新的连接对象进入 func (this *Gateway) Connect(a IAgent) { log.Debugf("[Module.Gateway] have new connect:Ip[%s] SessionId:[%s]", a.IP(), a.SessionId()) - this.agentmgr_comp.Connect(a) + this.agentmgr.Connect(a) } //有用户断开连接 func (this *Gateway) DisConnect(a IAgent) { log.Debugf("[Module.Gateway] have disConnect:Ip[%s] SessionId:[%s] uid:[%s]", a.IP(), a.SessionId(), a.UserId()) - this.agentmgr_comp.DisConnect(a) + this.agentmgr.DisConnect(a) } //读取消息分发规则 func (this *Gateway) GetMsgDistribRule(mtype, stype string) (rule string, ok bool) { - return this.configure_comp.GetMsgDistribRule(mtype, stype) + return this.configure.GetMsgDistribRule(mtype, stype) } diff --git a/modules/gateway/wservice_comp.go b/modules/gateway/wservice_comp.go index be7304e2a..0a75bd650 100644 --- a/modules/gateway/wservice_comp.go +++ b/modules/gateway/wservice_comp.go @@ -12,7 +12,7 @@ import ( "github.com/gorilla/websocket" ) -type WSService_Comp struct { +type WSServiceComp struct { cbase.ModuleCompBase options *Options @@ -20,7 +20,7 @@ type WSService_Comp struct { gin gin.ISys } -func (this *WSService_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { +func (this *WSServiceComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.ModuleCompBase.Init(service, module, comp, options) this.options = options.(*Options) this.module = module.(IGateway) @@ -29,7 +29,7 @@ func (this *WSService_Comp) Init(service core.IService, module core.IModule, com return } -func (this *WSService_Comp) ws(c *engine.Context) { +func (this *WSServiceComp) ws(c *engine.Context) { upGrader := websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true diff --git a/modules/items/api.go b/modules/items/api.go index 6ceb880fe..47aca6bf4 100644 --- a/modules/items/api.go +++ b/modules/items/api.go @@ -15,21 +15,21 @@ const ( //消息回复的头名称 /* 背包 处理用户的请求组件 必须继承 modules.MComp_GateComp */ -type Api_Comp struct { - modules.MComp_GateComp +type apiComp struct { + modules.MCompGate service core.IService module *Items } //组件初始化接口 -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) +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.(*Items) this.service = service return } -func (this *Api_Comp) Start() (err error) { - err = this.MComp_GateComp.Start() +func (this *apiComp) Start() (err error) { + err = this.MCompGate.Start() return } diff --git a/modules/items/api_getlist.go b/modules/items/api_getlist.go index 22fdc282a..12d5d6a9a 100644 --- a/modules/items/api_getlist.go +++ b/modules/items/api_getlist.go @@ -8,13 +8,13 @@ import ( ) //参数校验 -func (this *Api_Comp) Getlist_Check(session comm.IUserSession, req *pb.Items_Getlist_Req) (result map[string]interface{}, code comm.ErrorCode) { +func (this *apiComp) Getlist_Check(session comm.IUserSession, req *pb.Items_Getlist_Req) (result map[string]interface{}, code comm.ErrorCode) { result = map[string]interface{}{"ce": 123} return } ///获取用户道具 -func (this *Api_Comp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_Getlist_Req) (code pb.ErrorCode) { +func (this *apiComp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_Getlist_Req) (code pb.ErrorCode) { var ( err error items []*pb.DB_UserItemData @@ -28,18 +28,18 @@ func (this *Api_Comp) Getlist(session comm.IUserSession, agrs map[string]interfa session.SendMsg(string(this.module.GetType()), GetlistResp, &pb.Items_Getlist_Resp{Grids: grids}) if code == pb.ErrorCode_Success { go func() { //异步处理修改数据 - this.module.model_pack_comp.Pack_UpdateUserPack(session.GetUserId(), modifys...) - this.module.model_pack_comp.Pack_DeleteUserPack(session.GetUserId(), dels...) + this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...) + this.module.modelItems.Pack_DeleteUserPack(session.GetUserId(), dels...) }() } }() - if items, err = this.module.model_pack_comp.Pack_QueryUserPack(session.GetUserId()); err != nil { + if items, err = this.module.modelItems.Pack_QueryUserPack(session.GetUserId()); err != nil { log.Errorf("QueryUserPackReq err:%v", err) code = pb.ErrorCode_CacheReadError return } else { - tempgrids = this.module.configure_comp.GetPackItemByType(items, req.IType) + tempgrids = this.module.configure.GetPackItemByType(items, req.IType) modifys = make([]*pb.DB_UserItemData, 0, len(tempgrids)) dels = make([]string, 0, len(tempgrids)) grids = make([]*pb.DB_UserItemData, 0, len(grids)) diff --git a/modules/items/api_sellItem.go b/modules/items/api_sellItem.go index 4b803e69f..84310d85f 100644 --- a/modules/items/api_sellItem.go +++ b/modules/items/api_sellItem.go @@ -6,13 +6,13 @@ import ( ) //参数校验 -func (this *Api_Comp) SellItem_Check(session comm.IUserSession, req *pb.Items_SellItem_Req) (result map[string]interface{}, code comm.ErrorCode) { +func (this *apiComp) SellItem_Check(session comm.IUserSession, req *pb.Items_SellItem_Req) (result map[string]interface{}, code comm.ErrorCode) { return } //出售道具 -func (this *Api_Comp) SellItem(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_SellItem_Req) (code pb.ErrorCode) { +func (this *apiComp) SellItem(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_SellItem_Req) (code pb.ErrorCode) { defer func() { session.SendMsg(string(this.module.GetType()), SellItemResp, &pb.Items_SellItem_Resp{}) }() diff --git a/modules/items/api_useItem.go b/modules/items/api_useItem.go index 59cfc9113..828bf9d41 100644 --- a/modules/items/api_useItem.go +++ b/modules/items/api_useItem.go @@ -6,13 +6,13 @@ import ( ) //参数校验 -func (this *Api_Comp) Useitem_Check(session comm.IUserSession, req *pb.Items_UseItem_Req) (result map[string]interface{}, code comm.ErrorCode) { +func (this *apiComp) Useitem_Check(session comm.IUserSession, req *pb.Items_UseItem_Req) (result map[string]interface{}, code comm.ErrorCode) { return } //使用道具 -func (this *Api_Comp) Useitem(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_UseItem_Req) (code pb.ErrorCode) { +func (this *apiComp) Useitem(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_UseItem_Req) (code pb.ErrorCode) { defer func() { session.SendMsg(string(this.module.GetType()), UseItemResp, &pb.Items_UseItem_Resp{}) }() diff --git a/modules/items/configure_comp.go b/modules/items/configure.go similarity index 75% rename from modules/items/configure_comp.go rename to modules/items/configure.go index 147e9c006..a7b7fe730 100644 --- a/modules/items/configure_comp.go +++ b/modules/items/configure.go @@ -15,19 +15,19 @@ const ( ) ///背包配置管理组件 -type Configure_Comp struct { - modules.MComp_Configure +type ConfigureComp struct { + modules.MCompConfigure } //组件初始化接口 -func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { +func (this *ConfigureComp) 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_item, cfg.NewGame_item) return } //读取物品配置 -func (this *Configure_Comp) GetItemConfigure(id int32) (item *cfg.Game_itemData, err error) { +func (this *ConfigureComp) GetItemConfigure(id int32) (item *cfg.Game_itemData, err error) { var ( v interface{} ok bool @@ -44,7 +44,7 @@ func (this *Configure_Comp) GetItemConfigure(id int32) (item *cfg.Game_itemData, } //获取指定类型的物品列表 -func (this *Configure_Comp) GetPackItemByType(itmes []*pb.DB_UserItemData, usetype int32) (result []*pb.DB_UserItemData) { +func (this *ConfigureComp) GetPackItemByType(itmes []*pb.DB_UserItemData, usetype int32) (result []*pb.DB_UserItemData) { result = make([]*pb.DB_UserItemData, 0, len(itmes)) var ( v interface{} diff --git a/modules/items/model_pack_comp.go b/modules/items/modelitems.go similarity index 80% rename from modules/items/model_pack_comp.go rename to modules/items/modelitems.go index 982f8170e..b33c6951f 100644 --- a/modules/items/model_pack_comp.go +++ b/modules/items/modelitems.go @@ -12,14 +12,14 @@ import ( ) ///背包缓存数据管理组件 -type Model_Pack_Comp struct { - modules.Model_Comp +type ModelItemsComp struct { + modules.MCompModel module *Items } //组件初始化接口 -func (this *Model_Pack_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { - this.Model_Comp.Init(service, module, comp, opt) +func (this *ModelItemsComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { + this.MCompModel.Init(service, module, comp, opt) this.module = module.(*Items) this.TableName = "items" //创建uid索引 @@ -30,21 +30,21 @@ func (this *Model_Pack_Comp) Init(service core.IService, module core.IModule, co } ///查询用户背包数据 -func (this *Model_Pack_Comp) Pack_QueryUserPack(uId string) (itmes []*pb.DB_UserItemData, err error) { +func (this *ModelItemsComp) Pack_QueryUserPack(uId string) (itmes []*pb.DB_UserItemData, err error) { itmes = make([]*pb.DB_UserItemData, 0) err = this.GetList(uId, &itmes) return } ///查询用户指定格子的物品数据 -func (this *Model_Pack_Comp) Pack_QueryUserPackByGridId(uId string, grid string) (itme *pb.DB_UserItemData, err error) { +func (this *ModelItemsComp) Pack_QueryUserPackByGridId(uId string, grid string) (itme *pb.DB_UserItemData, err error) { itme = &pb.DB_UserItemData{} err = this.GetListObj(uId, grid, itme) return } //更新用户的背包信息 -func (this *Model_Pack_Comp) Pack_AddUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) { +func (this *ModelItemsComp) Pack_AddUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) { for _, v := range itmes { this.AddList(uId, v.GridId, v) } @@ -52,13 +52,13 @@ func (this *Model_Pack_Comp) Pack_AddUserPack(uId string, itmes ...*pb.DB_UserIt } //更新用户的背包信息 -func (this *Model_Pack_Comp) Pack_DelUserPack(uId string, ids ...string) (err error) { +func (this *ModelItemsComp) Pack_DelUserPack(uId string, ids ...string) (err error) { err = this.DelListlds(uId, ids...) return } //更新用户的背包信息 -func (this *Model_Pack_Comp) Pack_UpdateUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) { +func (this *ModelItemsComp) Pack_UpdateUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) { for _, v := range itmes { this.ChangeList(uId, v.GridId, map[string]interface{}{ "amount": v.Amount, @@ -68,13 +68,13 @@ func (this *Model_Pack_Comp) Pack_UpdateUserPack(uId string, itmes ...*pb.DB_Use } //更新用户的背包信息 -func (this *Model_Pack_Comp) Pack_DeleteUserPack(uId string, gridIds ...string) (err error) { +func (this *ModelItemsComp) Pack_DeleteUserPack(uId string, gridIds ...string) (err error) { err = this.DelListlds(uId, gridIds...) return } //查询用户背包物品数量 -func (this *Model_Pack_Comp) Pack_QueryUserPackItemsAmount(uId string, itemid ...int32) (result map[int32]uint32) { +func (this *ModelItemsComp) Pack_QueryUserPackItemsAmount(uId string, itemid ...int32) (result map[int32]uint32) { var ( itmes []*pb.DB_UserItemData err error @@ -94,7 +94,7 @@ func (this *Model_Pack_Comp) Pack_QueryUserPackItemsAmount(uId string, itemid .. } ///添加或则减少物品到用户背包 -func (this *Model_Pack_Comp) Pack_AddItemToUserPack(uId string, itemId int32, addnum int32) (err error) { +func (this *ModelItemsComp) Pack_AddItemToUserPack(uId string, itemId int32, addnum int32) (err error) { var ( itmes []*pb.DB_UserItemData add []*pb.DB_UserItemData @@ -136,7 +136,7 @@ func (this *Model_Pack_Comp) Pack_AddItemToUserPack(uId string, itemId int32, ad } ///添加或则减少多个物品到用户背包 -func (this *Model_Pack_Comp) Pack_AddItemsToUserPack(uId string, items map[int32]int32) (err error) { +func (this *ModelItemsComp) Pack_AddItemsToUserPack(uId string, items map[int32]int32) (err error) { var ( itmes []*pb.DB_UserItemData add []*pb.DB_UserItemData @@ -176,7 +176,7 @@ func (this *Model_Pack_Comp) Pack_AddItemsToUserPack(uId string, items map[int32 } ///修改指定格子的物品数量 -func (this *Model_Pack_Comp) Pack_AddItemToUserPackByGrid(uId string, gridid string, itemId int32, addnum int32) (err error) { +func (this *ModelItemsComp) Pack_AddItemToUserPackByGrid(uId string, gridid string, itemId int32, addnum int32) (err error) { var ( itme *pb.DB_UserItemData grid *pb.DB_UserItemData @@ -211,7 +211,7 @@ func (this *Model_Pack_Comp) Pack_AddItemToUserPackByGrid(uId string, gridid str } ///添加移除物品到用户背包 -func (this *Model_Pack_Comp) pack_addItemToUserPack(items []*pb.DB_UserItemData, itemId int32, addnum int32) (add, update []*pb.DB_UserItemData, del []string, leftnum int64) { +func (this *ModelItemsComp) pack_addItemToUserPack(items []*pb.DB_UserItemData, itemId int32, addnum int32) (add, update []*pb.DB_UserItemData, del []string, leftnum int64) { var ( num int64 isNew bool diff --git a/modules/items/module.go b/modules/items/module.go index 8c95f3ab5..af4122aa2 100644 --- a/modules/items/module.go +++ b/modules/items/module.go @@ -21,10 +21,9 @@ func NewModule() core.IModule { type Items struct { modules.ModuleBase - api_comp *Api_Comp - model_pack_comp *Model_Pack_Comp - // db_comp *DB_Comp - configure_comp *Configure_Comp + api *apiComp + modelItems *ModelItemsComp + configure *ConfigureComp } //模块名称 @@ -41,9 +40,9 @@ func (this *Items) Init(service core.IService, module core.IModule, options core //装备组件 func (this *Items) OnInstallComp() { this.ModuleBase.OnInstallComp() - this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) - this.model_pack_comp = this.RegisterComp(new(Model_Pack_Comp)).(*Model_Pack_Comp) - this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) + this.api = this.RegisterComp(new(apiComp)).(*apiComp) + this.modelItems = this.RegisterComp(new(ModelItemsComp)).(*ModelItemsComp) + this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp) } //IItems------------------------------------------------------------------------------------------------------------------------------- @@ -51,7 +50,7 @@ func (this *Items) OnInstallComp() { func (this *Items) QueryItemAmount(source *comm.ModuleCallSource, uId string, itemid int32) (amount uint32) { defer log.Debugf("获取物品 uId:%s itemid:%d addnum:%d ", uId, itemid, amount) amount = 0 - if result := this.model_pack_comp.Pack_QueryUserPackItemsAmount(uId, itemid); result != nil && len(result) > 0 { + if result := this.modelItems.Pack_QueryUserPackItemsAmount(uId, itemid); result != nil && len(result) > 0 { return result[itemid] } return @@ -59,7 +58,7 @@ func (this *Items) QueryItemAmount(source *comm.ModuleCallSource, uId string, it ///查询用户背包多个物品数量 func (this *Items) QueryItemsAmount(source *comm.ModuleCallSource, uId string, itemid ...int32) (result map[int32]uint32) { - result = this.model_pack_comp.Pack_QueryUserPackItemsAmount(uId, itemid...) + result = this.modelItems.Pack_QueryUserPackItemsAmount(uId, itemid...) return } @@ -67,7 +66,7 @@ func (this *Items) QueryItemsAmount(source *comm.ModuleCallSource, uId string, i func (this *Items) AddItem(source *comm.ModuleCallSource, 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 { + if err = this.modelItems.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_ItemsNoEnough @@ -84,7 +83,7 @@ func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, ad func (this *Items) AddItems(source *comm.ModuleCallSource, uId string, items map[int32]int32) (code pb.ErrorCode) { var err error defer log.Debugf("给用户添加物品 uId:%s items:%d items:%v", uId, items, err == nil) - if err = this.model_pack_comp.Pack_AddItemsToUserPack(uId, items); err != nil { + if err = this.modelItems.Pack_AddItemsToUserPack(uId, items); err != nil { log.Errorf("给用户添加物品 uId:%s items:%d err:%v", uId, items, err) if err == ItemNotEnoughError { code = pb.ErrorCode_ItemsNoEnough diff --git a/modules/items/module_test.go b/modules/items/module_test.go index c7ded52de..0b774f5e5 100644 --- a/modules/items/module_test.go +++ b/modules/items/module_test.go @@ -1,4 +1,4 @@ -package items +package items_test import ( "context" @@ -8,6 +8,7 @@ import ( "go_dreamfactory/lego/base/rpcx" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" + "go_dreamfactory/modules/items" "go_dreamfactory/pb" "go_dreamfactory/services" "go_dreamfactory/sys/cache" @@ -53,7 +54,7 @@ func (this *TestService) InitSys() { var service core.IService var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp() -var module = new(Items) +var module = new(items.Items) //测试环境下初始化db和cache 系统 func TestMain(m *testing.M) { diff --git a/pb/proto/comm.proto b/pb/proto/comm.proto index a04259393..36eb64791 100644 --- a/pb/proto/comm.proto +++ b/pb/proto/comm.proto @@ -25,8 +25,9 @@ message AgentMessage { // RPC 服务固定回复结构 message RPCMessageReply { ErrorCode Code = 1; - string Message = 2; - string Data = 3; + string ErrorMessage = 2; + string ErrorData = 3; + UserMessage Reply = 4; } //用户代理绑定Uid请求 diff --git a/services/comp_gateroute.go b/services/comp_gateroute.go index 8d3a0f969..d6d9287ff 100644 --- a/services/comp_gateroute.go +++ b/services/comp_gateroute.go @@ -27,7 +27,7 @@ import ( */ func NewGateRouteComp() comm.ISC_GateRouteComp { - comp := new(SComp_GateRouteComp) + comp := new(SCompGateRoute) return comp } @@ -39,7 +39,7 @@ type msghandle struct { } //服务网关组件 -type SComp_GateRouteComp struct { +type SCompGateRoute struct { cbase.ServiceCompBase service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口 mrlock sync.RWMutex //msghandles 对象的锁 @@ -48,12 +48,12 @@ type SComp_GateRouteComp struct { } //设置服务组件名称 方便业务模块中获取此组件对象 -func (this *SComp_GateRouteComp) GetName() core.S_Comps { +func (this *SCompGateRoute) GetName() core.S_Comps { return comm.SC_ServiceGateRouteComp } //组件初始化函数 -func (this *SComp_GateRouteComp) Init(service core.IService, comp core.IServiceComp, options core.ICompOptions) (err error) { +func (this *SCompGateRoute) Init(service core.IService, comp core.IServiceComp, options core.ICompOptions) (err error) { err = this.ServiceCompBase.Init(service, comp, options) this.service = service.(base.IRPCXService) this.msgcheck = make(map[string]*msghandle) @@ -62,7 +62,7 @@ func (this *SComp_GateRouteComp) Init(service core.IService, comp core.IServiceC } // //组件启动时注册rpc服务监听 -func (this *SComp_GateRouteComp) Start() (err error) { +func (this *SCompGateRoute) Start() (err error) { this.service.RegisterFunctionName(string(comm.Rpc_GatewayRoute), this.ReceiveMsg) //注册网关路由接收接口 this.service.RegisterFunctionName(string(comm.Rpc_NoticeUserClose), this.NoticeUserClose) //注册用户离线通知 err = this.ServiceCompBase.Start() @@ -84,7 +84,7 @@ func (this *SComp_GateRouteComp) Start() (err error) { } //业务模块注册用户消息处理路由 -func (this *SComp_GateRouteComp) RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) { +func (this *SCompGateRoute) RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) { log.Debugf("注册用户路由【%s】", methodName) this.mrlock.RLock() _, ok := this.msghandles[methodName] @@ -103,7 +103,7 @@ func (this *SComp_GateRouteComp) RegisterRoute(methodName string, comp reflect.V } //业务模块注册用户消息处理路由 -func (this *SComp_GateRouteComp) RegisterRouteCheck(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) { +func (this *SCompGateRoute) RegisterRouteCheck(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) { log.Debugf("注册用户路由校验[%s]", methodName) this.mrlock.RLock() _, ok := this.msgcheck[methodName] @@ -122,7 +122,7 @@ func (this *SComp_GateRouteComp) RegisterRouteCheck(methodName string, comp refl } //Rpc_GatewayRoute服务接口的接收函数 -func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error { +func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error { defer func() { //程序异常 收集异常信息传递给前端显示 if r := recover(); r != nil { buf := make([]byte, 1024) @@ -132,7 +132,7 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM log.Errorf("HandleUserMsg:%s err:%s", args.Method, reply.Message) } }() - log.Debugf("SComp_GateRouteComp ReceiveMsg agent:%s uId:%s MessageDistribution msg:%s", args.UserSessionId, args.UserId, args.Method) + log.Debugf("SCompGateRoute ReceiveMsg agent:%s uId:%s MessageDistribution msg:%s", args.UserSessionId, args.UserId, args.Method) //获取用户消息处理函数 this.mrlock.RLock() msghandle, ok := this.msghandles[args.Method] @@ -184,7 +184,7 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM } //RPC_NoticeUserClose 接收用户离线通知 -func (this *SComp_GateRouteComp) NoticeUserClose(ctx context.Context, args *pb.NoticeUserCloseReq, reply *pb.RPCMessageReply) error { +func (this *SCompGateRoute) NoticeUserClose(ctx context.Context, args *pb.NoticeUserCloseReq, reply *pb.RPCMessageReply) error { event.TriggerEvent(comm.Event_UserOffline, args.UserId) return nil }