diff --git a/comm/core.go b/comm/core.go index 7cbc4bf3d..e2dc21b4d 100644 --- a/comm/core.go +++ b/comm/core.go @@ -16,7 +16,7 @@ import ( type ISC_GateRouteComp interface { core.IServiceComp ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error - RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, check, handle reflect.Method) + RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, handle reflect.Method) } //游戏类资源类型 diff --git a/modules/comp_gate.go b/modules/comp_gate.go index 99c9fc565..23c1b2999 100644 --- a/modules/comp_gate.go +++ b/modules/comp_gate.go @@ -13,6 +13,8 @@ import ( "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" + + "google.golang.org/protobuf/proto" ) /* @@ -21,8 +23,7 @@ import ( // var typeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem() var typeOfSession = reflect.TypeOf((*comm.IUserSession)(nil)).Elem() -var typeOfMapStringIntface = reflect.TypeOf((map[string]interface{})(nil)).Elem() -var typeOfCode = reflect.TypeOf((*comm.ErrorCode)(nil)).Elem() +var typeOfMessage = reflect.TypeOf((*proto.Message)(nil)).Elem() var typeOfErrorCode = reflect.TypeOf((*pb.ErrorCode)(nil)).Elem() var typeOfError = reflect.TypeOf((*error)(nil)).Elem() @@ -77,33 +78,35 @@ func (this *MCompGate) reflectionRouteHandle(typ reflect.Type, method reflect.Me if method.PkgPath != "" { return } - if mtype.NumIn() != 4 { + if mtype.NumIn() != 3 { return } - ctxType := mtype.In(1) - if !ctxType.Implements(typeOfSession) { + sessionType := mtype.In(1) + if !sessionType.Implements(typeOfSession) { return } - argType := mtype.In(2) - if !argType.Implements(typeOfMapStringIntface) { - return - } - agrType := mtype.In(3) - if agrType.Kind() != reflect.Ptr { - return - } - if !this.isExportedOrBuiltinType(agrType) { + agrType := mtype.In(2) + if !agrType.Implements(typeOfMessage) { return } + // if agrType.Kind() != reflect.Ptr { + // return + // } + // if !this.isExportedOrBuiltinType(agrType) { + // return + // } - if mtype.NumOut() != 1 { + if mtype.NumOut() != 2 { return } returnCodeType := mtype.Out(0) if returnCodeType != typeOfErrorCode { return } - + returnDataType := mtype.Out(1) + if !returnDataType.Implements(typeOfMessage) { + return + } //寻找校验函数 check, ok := typ.MethodByName(mname + "Check") if !ok { @@ -111,7 +114,7 @@ func (this *MCompGate) reflectionRouteHandle(typ reflect.Type, method reflect.Me return } if err := this.reflectionRouteCheck(check, agrType); err == nil { - this.scomp.RegisterRoute(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname)), reflect.ValueOf(this.comp), agrType, check, method) + this.scomp.RegisterRoute(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname)), reflect.ValueOf(this.comp), agrType, method) } else { log.Panicf("反射注册用户处理函数错误 [%s-%s]校验函数格式异常:%v", this.module.GetType(), mname, err) return @@ -128,23 +131,19 @@ func (this *MCompGate) reflectionRouteCheck(method reflect.Method, msgtype refle if mtype.NumIn() != 3 { return fmt.Errorf("mtype.NumIn():%v", mtype.NumIn()) } - ctxType := mtype.In(1) - if !ctxType.Implements(typeOfSession) { - return fmt.Errorf("ctxType:%T", ctxType) + sessionType := mtype.In(1) + if !sessionType.Implements(typeOfSession) { + return fmt.Errorf("sessionType:%T", sessionType) } - replyType := mtype.In(2) - if replyType != msgtype { - return fmt.Errorf("replyType:%T", replyType) + agrType := mtype.In(2) + if agrType != msgtype { + return fmt.Errorf("replyType:%T msgtype:%T", agrType, msgtype) } - if mtype.NumOut() != 2 { + if mtype.NumOut() != 1 { return fmt.Errorf("mtype.NumOut():%d", mtype.NumOut()) } - returnMapType := mtype.Out(0) - if !returnMapType.Implements(typeOfMapStringIntface) { - return fmt.Errorf("returnMapType:%T", returnMapType) - } - returnCodeType := mtype.Out(1) - if returnCodeType != typeOfCode { + returnCodeType := mtype.Out(0) + if returnCodeType != typeOfErrorCode { return fmt.Errorf("returnCodeType:%T", returnCodeType) } return nil diff --git a/modules/equipment/api_equip.go b/modules/equipment/api_equip.go index 825e54930..00b05b147 100644 --- a/modules/equipment/api_equip.go +++ b/modules/equipment/api_equip.go @@ -5,48 +5,17 @@ import ( "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" + + "google.golang.org/protobuf/proto" ) //参数校验 -func (this *apiComp) EquipCheck(session comm.IUserSession, req *pb.EquipmentEquipReq) (result map[string]interface{}, code comm.ErrorCode) { - var ( - err error - errorCode pb.ErrorCode - confs []*cfg.Game_equipData - equipments []*pb.DB_Equipment - hero *pb.DBHero - ) - confs = make([]*cfg.Game_equipData, len(req.EquipmentId)) - equipments = make([]*pb.DB_Equipment, len(req.EquipmentId)) - for i, v := range req.EquipmentId { - if v != "" { - 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.GetEquipmentConfigureById(equipments[i].CId); err != nil { - log.Errorf("Equip_Check err:%v", err) - code.Code = pb.ErrorCode_EquipmentOnFoundEquipment - return - } - } - } - - if hero, errorCode = this.module.hero.GetHero(session.GetUserId(), req.HeroCardId); errorCode != pb.ErrorCode_Success { - code.Code = errorCode - return - } - result = map[string]interface{}{ - "confs": confs, - "equipments": equipments, - "hero": hero, - } +func (this *apiComp) EquipCheck(session comm.IUserSession, req *pb.EquipmentEquipReq) (code pb.ErrorCode) { return } -///英雄挂在装备 -func (this *apiComp) Equip(session comm.IUserSession, agrs map[string]interface{}, req *pb.EquipmentEquipReq) (code pb.ErrorCode) { +///英雄挂在装备 code 错误码信息 data 错误附加数据 +func (this *apiComp) Equip(session comm.IUserSession, req *pb.EquipmentEquipReq) (code pb.ErrorCode, data proto.Message) { var ( err error confs []*cfg.Game_equipData @@ -61,12 +30,28 @@ func (this *apiComp) Equip(session comm.IUserSession, agrs map[string]interface{ session.SendMsg(string(this.module.GetType()), "equip", &pb.EquipmentEquipResp{Equipments: equipments}) } }() - - confs = agrs["conf"].([]*cfg.Game_equipData) - equipments = agrs["equipment"].([]*pb.DB_Equipment) - updatequipment = make([]*pb.DB_Equipment, 0) - hero = agrs["hero"].(*pb.DBHero) - + //校验数据 + confs = make([]*cfg.Game_equipData, len(req.EquipmentId)) + equipments = make([]*pb.DB_Equipment, len(req.EquipmentId)) + for i, v := range req.EquipmentId { + if v != "" { + if equipments[i], err = this.module.modelEquipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil { + log.Errorf("Equip_Check err:%v", err) + code = pb.ErrorCode_EquipmentOnFoundEquipment + return + } + if confs[i], err = this.module.configure.GetEquipmentConfigureById(equipments[i].CId); err != nil { + log.Errorf("Equip_Check err:%v", err) + code = pb.ErrorCode_EquipmentOnFoundEquipment + return + } + } + } + //获取英雄数据 + if hero, code = this.module.hero.GetHero(session.GetUserId(), req.HeroCardId); code != pb.ErrorCode_Success { + return + } + //读取英雄原装备 for i, v := range hero.EquipID { if v != "" { if equipments[i] != nil && v != equipments[i].Id { diff --git a/modules/equipment/api_getlist.go b/modules/equipment/api_getlist.go index bef372007..8656cf0b7 100644 --- a/modules/equipment/api_getlist.go +++ b/modules/equipment/api_getlist.go @@ -4,16 +4,18 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" ) //参数校验 -func (this *apiComp) GetlistCheck(session comm.IUserSession, req *pb.EquipmentGetListReq) (result map[string]interface{}, code comm.ErrorCode) { +func (this *apiComp) GetlistCheck(session comm.IUserSession, req *pb.EquipmentGetListReq) (code pb.ErrorCode) { return } ///获取用户装备列表 -func (this *apiComp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.EquipmentGetListReq) (code pb.ErrorCode) { +func (this *apiComp) Getlist(session comm.IUserSession, req *pb.EquipmentGetListReq) (code pb.ErrorCode, data proto.Message) { var ( err error items []*pb.DB_Equipment diff --git a/modules/equipment/api_upgrade.go b/modules/equipment/api_upgrade.go index 22d3810a4..ac6261a46 100644 --- a/modules/equipment/api_upgrade.go +++ b/modules/equipment/api_upgrade.go @@ -9,47 +9,22 @@ import ( "math/big" "go.mongodb.org/mongo-driver/bson/primitive" + "google.golang.org/protobuf/proto" ) //参数校验 -func (this *apiComp) UpgradeCheck(session comm.IUserSession, req *pb.EquipmentUpgradeReq) (result map[string]interface{}, code comm.ErrorCode) { - var ( - err error - conf *cfg.Game_equipData - intensify *cfg.Game_equipIntensifyData - equipment *pb.DB_Equipment - ) +func (this *apiComp) UpgradeCheck(session comm.IUserSession, req *pb.EquipmentUpgradeReq) (code pb.ErrorCode) { + if req.EquipmentId == "" { log.Errorf("Upgrade 请求参数错误 req:%v", req) - code.Code = pb.ErrorCode_ReqParameterError + code = pb.ErrorCode_ReqParameterError return } - 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.GetEquipmentConfigureById(equipment.CId); err != nil { - log.Errorf("Equip_Check err:%v", err) - code.Code = pb.ErrorCode_EquipmentOnFoundEquipment - return - } - //找到下一个等级的相关配置 - if intensify, err = this.module.configure.GetEquipmentIntensifyConfigureById(equipment.Lv); err != nil { - log.Errorf("Equip_Check err:%v", err) - code.Code = pb.ErrorCode_EquipmentLvlimitReached - return - } - result = map[string]interface{}{ - "equipment": equipment, - "conf": conf, - "intensify": intensify, - } return } ///英雄挂在装备 -func (this *apiComp) Upgrade(session comm.IUserSession, agrs map[string]interface{}, req *pb.EquipmentUpgradeReq) (code pb.ErrorCode) { +func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.EquipmentUpgradeReq) (code pb.ErrorCode, data proto.Message) { var ( err error conf *cfg.Game_equipData @@ -65,9 +40,26 @@ func (this *apiComp) Upgrade(session comm.IUserSession, agrs map[string]interfac session.SendMsg(string(this.module.GetType()), "upgrade", &pb.EquipmentUpgradeResp{IsSucc: issucc, Equipment: modifyequipments}) } }() - conf = agrs["conf"].(*cfg.Game_equipData) - intensify = agrs["intensify"].(*cfg.Game_equipIntensifyData) - equipment = agrs["equipment"].(*pb.DB_Equipment) + if code = this.UpgradeCheck(session, req); code != pb.ErrorCode_Success { + return + } + if equipment, err = this.module.modelEquipment.QueryUserEquipmentsById(session.GetUserId(), req.EquipmentId); err != nil { + log.Errorf("Equip_Check err:%v", err) + code = pb.ErrorCode_EquipmentOnFoundEquipment + return + } + if conf, err = this.module.configure.GetEquipmentConfigureById(equipment.CId); err != nil { + log.Errorf("Equip_Check err:%v", err) + code = pb.ErrorCode_EquipmentOnFoundEquipment + return + } + //找到下一个等级的相关配置 + if intensify, err = this.module.configure.GetEquipmentIntensifyConfigureById(equipment.Lv); err != nil { + log.Errorf("Equip_Check err:%v", err) + code = pb.ErrorCode_EquipmentLvlimitReached + return + } + if equipment.KeepFailNum >= intensify.Num { //没有达到保底次数 根据概率随机成功失败 issucc = true } else { //随机 千分比 diff --git a/modules/gateway/agent.go b/modules/gateway/agent.go index a6a266b8e..06a0801e6 100644 --- a/modules/gateway/agent.go +++ b/modules/gateway/agent.go @@ -251,5 +251,6 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) { } } } + return nil } diff --git a/pb/comm.pb.go b/pb/comm.pb.go index 2466829b2..390bbaaf8 100644 --- a/pb/comm.pb.go +++ b/pb/comm.pb.go @@ -254,7 +254,7 @@ type RPCMessageReply struct { Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code"` ErrorMessage string `protobuf:"bytes,2,opt,name=ErrorMessage,proto3" json:"ErrorMessage"` - ErrorData string `protobuf:"bytes,3,opt,name=ErrorData,proto3" json:"ErrorData"` + ErrorData *anypb.Any `protobuf:"bytes,3,opt,name=ErrorData,proto3" json:"ErrorData"` Reply []*UserMessage `protobuf:"bytes,4,rep,name=Reply,proto3" json:"Reply"` } @@ -304,11 +304,11 @@ func (x *RPCMessageReply) GetErrorMessage() string { return "" } -func (x *RPCMessageReply) GetErrorData() string { +func (x *RPCMessageReply) GetErrorData() *anypb.Any { if x != nil { return x.ErrorData } - return "" + return nil } func (x *RPCMessageReply) GetReply() []*UserMessage { @@ -771,68 +771,69 @@ var file_comm_proto_rawDesc = []byte{ 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, - 0x79, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x97, 0x01, 0x0a, 0x0f, 0x52, + 0x79, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xad, 0x01, 0x0a, 0x0f, 0x52, 0x50, 0x43, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1e, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, - 0x67, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x44, 0x61, 0x74, 0x61, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x44, 0x61, 0x74, 0x61, - 0x12, 0x22, 0x0a, 0x05, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x0c, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x05, 0x52, - 0x65, 0x70, 0x6c, 0x79, 0x22, 0x69, 0x0a, 0x0d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x42, 0x75, 0x69, - 0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, - 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, - 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55, - 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, - 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x57, 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x49, 0x64, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x57, 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x49, 0x64, 0x22, - 0x37, 0x0a, 0x0f, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x55, 0x6e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, - 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, - 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x9b, 0x01, 0x0a, 0x13, 0x41, 0x67, 0x65, - 0x6e, 0x74, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, - 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, - 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, - 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, - 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, - 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, - 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x99, 0x01, 0x0a, 0x0f, 0x42, 0x61, 0x74, 0x63, 0x68, - 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x26, 0x0a, 0x0e, 0x55, 0x73, - 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, - 0x28, 0x09, 0x52, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, - 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, - 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, - 0x74, 0x61, 0x22, 0x75, 0x0a, 0x13, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x73, 0x74, 0x4d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, - 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, - 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, - 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x36, 0x0a, 0x0e, 0x41, 0x67, 0x65, - 0x6e, 0x74, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, + 0x67, 0x65, 0x12, 0x32, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x44, 0x61, 0x74, 0x61, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x09, 0x45, 0x72, 0x72, + 0x6f, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x22, 0x0a, 0x05, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x18, + 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x52, 0x05, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x69, 0x0a, 0x0d, 0x41, 0x67, + 0x65, 0x6e, 0x74, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, - 0x64, 0x22, 0x52, 0x0a, 0x12, 0x4e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x43, - 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, - 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, - 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, - 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, - 0x73, 0x65, 0x72, 0x49, 0x64, 0x2a, 0x43, 0x0a, 0x12, 0x48, 0x65, 0x72, 0x6f, 0x41, 0x74, 0x74, - 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x06, 0x0a, 0x02, 0x48, - 0x70, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x74, 0x6b, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, - 0x44, 0x65, 0x66, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x70, 0x65, 0x65, 0x64, 0x10, 0x03, - 0x12, 0x08, 0x0a, 0x04, 0x43, 0x72, 0x69, 0x74, 0x10, 0x04, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, - 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x57, 0x6f, 0x72, + 0x6b, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x57, 0x6f, 0x72, + 0x6b, 0x65, 0x72, 0x49, 0x64, 0x22, 0x37, 0x0a, 0x0f, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x55, 0x6e, + 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, + 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x9b, + 0x01, 0x0a, 0x13, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, + 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, + 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, + 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, + 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, + 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x99, 0x01, 0x0a, + 0x0f, 0x42, 0x61, 0x74, 0x63, 0x68, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, + 0x12, 0x26, 0x0a, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, + 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, + 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, + 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, + 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x75, 0x0a, 0x13, 0x42, 0x72, 0x6f, 0x61, + 0x64, 0x43, 0x61, 0x73, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, + 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, + 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, + 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, + 0x36, 0x0a, 0x0e, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x65, 0x52, 0x65, + 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, + 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x52, 0x0a, 0x12, 0x4e, 0x6f, 0x74, 0x69, 0x63, + 0x65, 0x55, 0x73, 0x65, 0x72, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, + 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, + 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x2a, 0x43, 0x0a, 0x12, 0x48, + 0x65, 0x72, 0x6f, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x06, 0x0a, 0x02, 0x48, 0x70, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x74, 0x6b, + 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x44, 0x65, 0x66, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x53, + 0x70, 0x65, 0x65, 0x64, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x43, 0x72, 0x69, 0x74, 0x10, 0x04, + 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -868,15 +869,16 @@ var file_comm_proto_depIdxs = []int32{ 11, // 0: UserMessage.data:type_name -> google.protobuf.Any 11, // 1: AgentMessage.Message:type_name -> google.protobuf.Any 12, // 2: RPCMessageReply.Code:type_name -> ErrorCode - 1, // 3: RPCMessageReply.Reply:type_name -> UserMessage - 11, // 4: AgentSendMessageReq.Data:type_name -> google.protobuf.Any - 11, // 5: BatchMessageReq.Data:type_name -> google.protobuf.Any - 11, // 6: BroadCastMessageReq.Data:type_name -> google.protobuf.Any - 7, // [7:7] is the sub-list for method output_type - 7, // [7:7] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 11, // 3: RPCMessageReply.ErrorData:type_name -> google.protobuf.Any + 1, // 4: RPCMessageReply.Reply:type_name -> UserMessage + 11, // 5: AgentSendMessageReq.Data:type_name -> google.protobuf.Any + 11, // 6: BatchMessageReq.Data:type_name -> google.protobuf.Any + 11, // 7: BroadCastMessageReq.Data:type_name -> google.protobuf.Any + 8, // [8:8] is the sub-list for method output_type + 8, // [8:8] is the sub-list for method input_type + 8, // [8:8] is the sub-list for extension type_name + 8, // [8:8] is the sub-list for extension extendee + 0, // [0:8] is the sub-list for field type_name } func init() { file_comm_proto_init() } diff --git a/pb/proto/comm.proto b/pb/proto/comm.proto index 41e4797e2..bbd896913 100644 --- a/pb/proto/comm.proto +++ b/pb/proto/comm.proto @@ -27,7 +27,7 @@ message AgentMessage { message RPCMessageReply { ErrorCode Code = 1; string ErrorMessage = 2; - string ErrorData = 3; + google.protobuf.Any ErrorData = 3; repeated UserMessage Reply = 4; } diff --git a/services/comp_gateroute.go b/services/comp_gateroute.go index 3b06fb344..81b87b482 100644 --- a/services/comp_gateroute.go +++ b/services/comp_gateroute.go @@ -9,17 +9,14 @@ import ( "runtime" "sync" - jsoniter "github.com/json-iterator/go" - "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/event" "go_dreamfactory/lego/sys/log" - "go_dreamfactory/lego/utils/codec" - "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/ptypes" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" ) /* @@ -35,7 +32,6 @@ func NewGateRouteComp() comm.ISC_GateRouteComp { type msghandle struct { rcvr reflect.Value msgType reflect.Type //消息请求类型 - check reflect.Method //校验函数 handle reflect.Method //处理函数 } @@ -72,7 +68,7 @@ func (this *SCompGateRoute) Start() (err error) { } //业务模块注册用户消息处理路由 -func (this *SCompGateRoute) RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, check, handele reflect.Method) { +func (this *SCompGateRoute) RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, handele reflect.Method) { log.Debugf("注册用户路由【%s】", methodName) this.mrlock.RLock() _, ok := this.msghandles[methodName] @@ -85,14 +81,13 @@ func (this *SCompGateRoute) RegisterRoute(methodName string, comp reflect.Value, this.msghandles[methodName] = &msghandle{ rcvr: comp, msgType: msg, - check: check, handle: handele, } this.mrlock.Unlock() } //Rpc_GatewayRoute服务接口的接收函数 -func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error { +func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) (err error) { defer func() { //程序异常 收集异常信息传递给前端显示 if r := recover(); r != nil { buf := make([]byte, 1024) @@ -120,39 +115,23 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag this.sessionslock.Unlock() } //序列化用户消息对象 - msg := reflect.New(msghandle.msgType.Elem()).Interface() - if err := ptypes.UnmarshalAny(args.Message, msg.(proto.Message)); err != nil { + var msg proto.Message + if msg, err = args.Message.UnmarshalNew(); err != nil { log.Errorf("UserMessage:%s Unmarshal err:%v", method, err) return err } + + //执行处理流 log.Debugf("ReceiveMsg Message:[%s-%s]-%v user[%s-%s]", args.MainType, args.SubType, msg, args.UserSessionId, args.UserId) - //调用校验接口 - checkreturn := msghandle.check.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)}) - //读取校验结果 有错误直接返回错误码给用户 - code := checkreturn[1].Interface().(comm.ErrorCode) - if code.Code != pb.ErrorCode_Success { - log.Errorf("HandleUserMsg:%s msg:%v code:%d", method, msg, code) - reply.Code = code.Code - reply.ErrorMessage = pb.GetErrorCodeMsg(code.Code) - if code.Data != nil { //处理错误附加数据 采用json 序列化为string - if d, err := jsoniter.Marshal(code.Data); err != nil { - log.Errorf("HandleUserMsg:%s msg:%v code:%d err:%v", method, msg, code, err) - return nil - } else { - reply.ErrorData = codec.BytesToString(d) - } - } - return nil - } - //校验结果成功 处理临时数据转移 - result := checkreturn[0].Interface().(map[string]interface{}) - //调用用户处理函数 - handlereturn := msghandle.handle.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(result), reflect.ValueOf(msg)}) + handlereturn := msghandle.handle.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)}) errcode := pb.ErrorCode(handlereturn[0].Int()) + errdata := handlereturn[0].Interface().(proto.Message) + data, _ := anypb.New(errdata) if errcode != pb.ErrorCode_Success { //处理返货错误码 返回用户错误信息 - log.Errorf("HandleUserMsg:%s msg:%v code:%d", method, msg, code) + log.Errorf("HandleUserMsg:%s msg:%v code:%d", method, msg, errcode) reply.Code = errcode reply.ErrorMessage = pb.GetErrorCodeMsg(errcode) + reply.ErrorData = data return nil } else { reply.Reply = session.Polls() diff --git a/sys/configure/configure.go b/sys/configure/configure.go index f97e9d94f..11255c011 100644 --- a/sys/configure/configure.go +++ b/sys/configure/configure.go @@ -70,7 +70,7 @@ func (this *Configure) RegisterConfigure(name string, fn interface{}) (err error _, ok := this.configurehandles[name] this.hlock.RUnlock() if ok { - err = fmt.Errorf("重复 注册配置【%s】", name) + // err = fmt.Errorf("重复 注册配置【%s】", name) return } fnvalue := reflect.ValueOf(fn)