This commit is contained in:
meixiongfeng 2022-06-28 17:13:42 +08:00
commit 95f071b3bc
50 changed files with 1400 additions and 1715 deletions

File diff suppressed because it is too large Load Diff

View File

@ -495,7 +495,7 @@
"level": 15, "level": 15,
"need": [], "need": [],
"bonus": 4500, "bonus": 4500,
"activation": false, "activation": true,
"probability": 250, "probability": 250,
"num": 16 "num": 16
}, },
@ -559,7 +559,7 @@
} }
], ],
"bonus": 900, "bonus": 900,
"activation": false, "activation": true,
"probability": 850, "probability": 850,
"num": 4 "num": 4
}, },
@ -607,7 +607,7 @@
} }
], ],
"bonus": 1800, "bonus": 1800,
"activation": false, "activation": true,
"probability": 700, "probability": 700,
"num": 7 "num": 7
}, },
@ -655,7 +655,7 @@
} }
], ],
"bonus": 2700, "bonus": 2700,
"activation": false, "activation": true,
"probability": 550, "probability": 550,
"num": 10 "num": 10
}, },
@ -703,7 +703,7 @@
} }
], ],
"bonus": 3600, "bonus": 3600,
"activation": false, "activation": true,
"probability": 400, "probability": 400,
"num": 13 "num": 13
}, },
@ -745,7 +745,7 @@
"level": 15, "level": 15,
"need": [], "need": [],
"bonus": 4500, "bonus": 4500,
"activation": false, "activation": true,
"probability": 250, "probability": 250,
"num": 16 "num": 16
}, },
@ -809,7 +809,7 @@
} }
], ],
"bonus": 900, "bonus": 900,
"activation": false, "activation": true,
"probability": 850, "probability": 850,
"num": 4 "num": 4
}, },
@ -857,7 +857,7 @@
} }
], ],
"bonus": 1800, "bonus": 1800,
"activation": false, "activation": true,
"probability": 700, "probability": 700,
"num": 7 "num": 7
}, },
@ -905,7 +905,7 @@
} }
], ],
"bonus": 2700, "bonus": 2700,
"activation": false, "activation": true,
"probability": 550, "probability": 550,
"num": 10 "num": 10
}, },
@ -953,7 +953,7 @@
} }
], ],
"bonus": 3600, "bonus": 3600,
"activation": false, "activation": true,
"probability": 400, "probability": 400,
"num": 13 "num": 13
}, },
@ -995,7 +995,7 @@
"level": 15, "level": 15,
"need": [], "need": [],
"bonus": 4500, "bonus": 4500,
"activation": false, "activation": true,
"probability": 250, "probability": 250,
"num": 16 "num": 16
}, },
@ -1059,7 +1059,7 @@
} }
], ],
"bonus": 900, "bonus": 900,
"activation": false, "activation": true,
"probability": 850, "probability": 850,
"num": 4 "num": 4
}, },
@ -1107,7 +1107,7 @@
} }
], ],
"bonus": 1800, "bonus": 1800,
"activation": false, "activation": true,
"probability": 700, "probability": 700,
"num": 7 "num": 7
}, },
@ -1155,7 +1155,7 @@
} }
], ],
"bonus": 2700, "bonus": 2700,
"activation": false, "activation": true,
"probability": 550, "probability": 550,
"num": 10 "num": 10
}, },
@ -1203,7 +1203,7 @@
} }
], ],
"bonus": 3600, "bonus": 3600,
"activation": false, "activation": true,
"probability": 400, "probability": 400,
"num": 13 "num": 13
}, },
@ -1245,7 +1245,7 @@
"level": 15, "level": 15,
"need": [], "need": [],
"bonus": 4500, "bonus": 4500,
"activation": false, "activation": true,
"probability": 250, "probability": 250,
"num": 16 "num": 16
}, },
@ -1309,7 +1309,7 @@
} }
], ],
"bonus": 900, "bonus": 900,
"activation": false, "activation": true,
"probability": 850, "probability": 850,
"num": 4 "num": 4
}, },
@ -1357,7 +1357,7 @@
} }
], ],
"bonus": 1800, "bonus": 1800,
"activation": false, "activation": true,
"probability": 700, "probability": 700,
"num": 7 "num": 7
}, },
@ -1405,7 +1405,7 @@
} }
], ],
"bonus": 2700, "bonus": 2700,
"activation": false, "activation": true,
"probability": 550, "probability": 550,
"num": 10 "num": 10
}, },
@ -1453,7 +1453,7 @@
} }
], ],
"bonus": 3600, "bonus": 3600,
"activation": false, "activation": true,
"probability": 400, "probability": 400,
"num": 13 "num": 13
}, },
@ -1495,7 +1495,7 @@
"level": 15, "level": 15,
"need": [], "need": [],
"bonus": 4500, "bonus": 4500,
"activation": false, "activation": true,
"probability": 250, "probability": 250,
"num": 16 "num": 16
} }

View File

@ -16,8 +16,7 @@ import (
type ISC_GateRouteComp interface { type ISC_GateRouteComp interface {
core.IServiceComp core.IServiceComp
ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error
RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, check, handle reflect.Method)
RegisterRouteCheck(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method)
} }
//游戏类资源类型 //游戏类资源类型
@ -35,8 +34,6 @@ type Autogenerated struct {
D []interface{} D []interface{}
} }
const ( const (
HeroStarLvRatio int32 = 10 // 卡牌等级上限系数(星级*10 HeroStarLvRatio int32 = 10 // 卡牌等级上限系数(星级*10
) )
@ -57,6 +54,7 @@ type IUserSession interface {
Bind(uid string, wokerId string) (err error) Bind(uid string, wokerId string) (err error)
UnBind() (err error) UnBind() (err error)
SendMsg(mainType, subType string, msg proto.Message) (err error) SendMsg(mainType, subType string, msg proto.Message) (err error)
Polls() []*pb.UserMessage
Close() (err error) Close() (err error)
ToString() string ToString() string
} }

View File

@ -59,10 +59,10 @@ type (
//武器模块 //武器模块
IEquipment interface { IEquipment interface {
//查询服务资源数量 db id //查询服务资源数量 db id
QueryEquipment(source *ModuleCallSource, uid string, Id int32) (equipment pb.DB_Equipment, code pb.ErrorCode) QueryEquipment(source *ModuleCallSource, uid string, Id string) (equipment *pb.DB_Equipment, code pb.ErrorCode)
//查询服务资源数量 参数武器配置id //查询服务资源数量 参数武器配置id
QueryEquipmentAmount(source *ModuleCallSource, uid string, equipmentId int32) (amount uint32) QueryEquipmentAmount(source *ModuleCallSource, uid string, equipmentId int32) (amount uint32)
//武器 //添加新武器
AddNewEquipments(source *ModuleCallSource, uid string, eid int, add int32) (code pb.ErrorCode) AddNewEquipments(source *ModuleCallSource, uid string, cIds map[int32]uint32) (code pb.ErrorCode)
} }
) )

View File

@ -22,6 +22,7 @@ func NewUserSession(service base.IRPCXService, ip, sessionId, gatewayServiceId s
SessionId: sessionId, SessionId: sessionId,
GatewayServiceId: gatewayServiceId, GatewayServiceId: gatewayServiceId,
UserId: uid, UserId: uid,
msgqueue: make([]*pb.UserMessage, 0),
service: service, service: service,
} }
} }
@ -32,6 +33,7 @@ type UserSession struct {
GatewayServiceId string //用户所在网关服务 GatewayServiceId string //用户所在网关服务
UserId string UserId string
service base.IRPCXService service base.IRPCXService
msgqueue []*pb.UserMessage
} }
//获取用户的会话id //获取用户的会话id
@ -87,17 +89,24 @@ func (this *UserSession) UnBind() (err error) {
//向用户发送消息 //向用户发送消息
func (this *UserSession) SendMsg(mainType, subType string, msg proto.Message) (err error) { func (this *UserSession) SendMsg(mainType, subType string, msg proto.Message) (err error) {
reply := &pb.RPCMessageReply{}
data, _ := anypb.New(msg)
log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Data: %v", this.UserId, msg) log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Data: %v", this.UserId, msg)
if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{ data, _ := anypb.New(msg)
UserSessionId: this.SessionId, this.msgqueue = append(this.msgqueue, &pb.UserMessage{
MainType: mainType, MainType: mainType,
SubType: subType, SubType: subType,
Data: data, Data: data,
}, reply); err != nil { })
log.Errorf("SendMsg:%s UserSession:%s UserId:%s err:%v", mainType, this.SessionId, this.UserId, err) // reply := &pb.RPCMessageReply{}
} // data, _ := anypb.New(msg)
// log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Data: %v", this.UserId, msg)
// if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{
// UserSessionId: this.SessionId,
// MainType: mainType,
// SubType: subType,
// Data: data,
// }, reply); err != nil {
// log.Errorf("SendMsg:%s UserSession:%s UserId:%s err:%v", mainType, this.SessionId, this.UserId, err)
// }
return return
} }
@ -112,6 +121,13 @@ func (this *UserSession) Close() (err error) {
return return
} }
//清空消息队列
func (this *UserSession) Polls() []*pb.UserMessage {
msgs := this.msgqueue
this.msgqueue = this.msgqueue[:0]
return msgs
}
//打印日志需要 //打印日志需要
func (this *UserSession) ToString() string { func (this *UserSession) ToString() string {
return fmt.Sprintf("SessionId:%s UserId:%s GatewayServiceId:%s", this.SessionId, this.UserId, this.GatewayServiceId) return fmt.Sprintf("SessionId:%s UserId:%s GatewayServiceId:%s", this.SessionId, this.UserId, this.GatewayServiceId)

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"log"
"reflect" "reflect"
"strings" "strings"
"unicode" "unicode"
@ -28,7 +29,7 @@ var typeOfError = reflect.TypeOf((*error)(nil)).Elem()
/* /*
模块 网关组件 接收处理用户传递消息 模块 网关组件 接收处理用户传递消息
*/ */
type MComp_GateComp struct { type MCompGate struct {
cbase.ModuleCompBase cbase.ModuleCompBase
service base.IRPCXService //rpc服务对象 service base.IRPCXService //rpc服务对象
module core.IModule //当前业务模块 module core.IModule //当前业务模块
@ -37,7 +38,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.ModuleCompBase.Init(service, module, comp, options)
this.service = service.(base.IRPCXService) this.service = service.(base.IRPCXService)
this.module = module this.module = module
@ -46,7 +47,7 @@ func (this *MComp_GateComp) Init(service core.IService, module core.IModule, com
} }
//组件启动接口启动时将自己接收用户消息的处理函数注册到services/comp_gateroute.go 对象中 //组件启动接口启动时将自己接收用户消息的处理函数注册到services/comp_gateroute.go 对象中
func (this *MComp_GateComp) Start() (err error) { func (this *MCompGate) Start() (err error) {
if err = this.ModuleCompBase.Start(); err != nil { if err = this.ModuleCompBase.Start(); err != nil {
return return
} }
@ -56,21 +57,21 @@ func (this *MComp_GateComp) Start() (err error) {
return return
} }
this.scomp = comp.(comm.ISC_GateRouteComp) this.scomp = comp.(comm.ISC_GateRouteComp)
this.suitableMethods(reflect.TypeOf(this.comp)) this.suitableMethods()
return return
} }
//反射注册相关接口道services/comp_gateroute.go 对象中 //反射注册相关接口道services/comp_gateroute.go 对象中
func (this *MComp_GateComp) suitableMethods(typ reflect.Type) { func (this *MCompGate) suitableMethods() {
typ := reflect.TypeOf(this.comp)
for m := 0; m < typ.NumMethod(); m++ { for m := 0; m < typ.NumMethod(); m++ {
method := typ.Method(m) method := typ.Method(m)
this.reflectionRouteHandle(method) this.reflectionRouteHandle(typ, method)
this.reflectionRouteCheck(method)
} }
} }
//反射注册路由处理函数 //反射注册路由处理函数
func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) { func (this *MCompGate) reflectionRouteHandle(typ reflect.Type, method reflect.Method) {
mtype := method.Type mtype := method.Type
mname := method.Name mname := method.Name
if method.PkgPath != "" { if method.PkgPath != "" {
@ -87,13 +88,14 @@ func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) {
if !argType.Implements(typeOfMapStringIntface) { if !argType.Implements(typeOfMapStringIntface) {
return return
} }
replyType := mtype.In(3) agrType := mtype.In(3)
if replyType.Kind() != reflect.Ptr { if agrType.Kind() != reflect.Ptr {
return return
} }
if !this.isExportedOrBuiltinType(replyType) { if !this.isExportedOrBuiltinType(agrType) {
return return
} }
if mtype.NumOut() != 1 { if mtype.NumOut() != 1 {
return return
} }
@ -101,55 +103,61 @@ func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) {
if returnCodeType != typeOfErrorCode { if returnCodeType != typeOfErrorCode {
return return
} }
this.scomp.RegisterRoute(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname)), reflect.ValueOf(this.comp), replyType, method)
//寻找校验函数
check, ok := typ.MethodByName(mname + "Check")
if !ok {
log.Panicf("反射注册用户处理函数错误 [%s-%s]没有对应的校验函数", this.module.GetType(), mname)
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)
} else {
log.Panicf("反射注册用户处理函数错误 [%s-%s]校验函数格式异常:%v", this.module.GetType(), mname, err)
return
}
} }
//反射注册路由校验函数 //反射注册路由校验函数
func (this *MComp_GateComp) reflectionRouteCheck(method reflect.Method) { func (this *MCompGate) reflectionRouteCheck(method reflect.Method, msgtype reflect.Type) error {
mtype := method.Type mtype := method.Type
mname := strings.Split(method.Name, "_")
if len(mname) != 2 || mname[1] != "Check" {
return
}
if method.PkgPath != "" { if method.PkgPath != "" {
return return fmt.Errorf("method.PkgPath:%v", method.PkgPath)
} }
if mtype.NumIn() != 3 { if mtype.NumIn() != 3 {
return return fmt.Errorf("mtype.NumIn():%v", mtype.NumIn())
} }
ctxType := mtype.In(1) ctxType := mtype.In(1)
if !ctxType.Implements(typeOfSession) { if !ctxType.Implements(typeOfSession) {
return return fmt.Errorf("ctxType:%T", ctxType)
} }
replyType := mtype.In(2) replyType := mtype.In(2)
if replyType.Kind() != reflect.Ptr { if replyType != msgtype {
return return fmt.Errorf("replyType:%T", replyType)
}
if !this.isExportedOrBuiltinType(replyType) {
return
} }
if mtype.NumOut() != 2 { if mtype.NumOut() != 2 {
return return fmt.Errorf("mtype.NumOut():%d", mtype.NumOut())
} }
returnMapType := mtype.Out(0) returnMapType := mtype.Out(0)
if !returnMapType.Implements(typeOfMapStringIntface) { if !returnMapType.Implements(typeOfMapStringIntface) {
return return fmt.Errorf("returnMapType:%T", returnMapType)
} }
returnCodeType := mtype.Out(1) returnCodeType := mtype.Out(1)
if returnCodeType != typeOfCode { if returnCodeType != typeOfCode {
return return fmt.Errorf("returnCodeType:%T", returnCodeType)
} }
this.scomp.RegisterRouteCheck(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname[0])), reflect.ValueOf(this.comp), replyType, method) return nil
} }
func (this *MComp_GateComp) isExportedOrBuiltinType(t reflect.Type) bool { func (this *MCompGate) isExportedOrBuiltinType(t reflect.Type) bool {
for t.Kind() == reflect.Ptr { for t.Kind() == reflect.Ptr {
t = t.Elem() t = t.Elem()
} }
return this.isExported(t.Name()) || t.PkgPath() == "" 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) rune, _ := utf8.DecodeRuneInString(name)
return unicode.IsUpper(rune) return unicode.IsUpper(rune)
} }

View File

@ -23,7 +23,7 @@ import (
基础组件 缓存组件 读写缓存数据 基础组件 缓存组件 读写缓存数据
DB组件也封装进来 DB组件也封装进来
*/ */
type Model_Comp struct { type MCompModel struct {
cbase.ModuleCompBase cbase.ModuleCompBase
Redis redis.ISys Redis redis.ISys
DB mgo.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.ModuleCompBase.Init(service, module, comp, options)
this.Redis = cache.Redis() this.Redis = cache.Redis()
this.DB = db.Mgo() this.DB = db.Mgo()
return return
} }
func (this *Model_Comp) Start() (err error) { func (this *MCompModel) Start() (err error) {
err = this.ModuleCompBase.Start() err = this.ModuleCompBase.Start()
return return
} }
func (this *Model_Comp) ukey(uid string) string { func (this *MCompModel) ukey(uid string) string {
return fmt.Sprintf("%s:%s", this.TableName, uid) 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) 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{ data := &comm.Autogenerated{
ID: primitive.NewObjectID().Hex(), ID: primitive.NewObjectID().Hex(),
@ -70,7 +70,7 @@ func (this *Model_Comp) InsertModelLogs(table string, uID string, target interfa
return err 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{ data := &comm.Autogenerated{
ID: primitive.NewObjectID().Hex(), ID: primitive.NewObjectID().Hex(),
@ -88,7 +88,7 @@ func (this *Model_Comp) DeleteModelLogs(table string, uID string, where interfac
return err 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{ data := &comm.Autogenerated{
ID: primitive.NewObjectID().Hex(), 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 { if err = this.Redis.HMSet(this.ukey(uid), data); err != nil {
return 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) key := this.ukeylist(uid, id)
if err = this.Redis.HMSet(key, data); err != nil { if err = this.Redis.HMSet(key, data); err != nil {
return return
@ -134,13 +134,13 @@ func (this *Model_Comp) AddList(uid string, id string, data interface{}, attrs .
this.Redis.Expire(this.ukey(uid), ret.(time.Duration)) this.Redis.Expire(this.ukey(uid), ret.(time.Duration))
} }
if ret := cache.OperationAttrs(attrs).Find(cache.ATTR_MGOLOG).Unwrap_Or(nil); ret == nil { if ret := cache.OperationAttrs(attrs).Find(cache.ATTR_MGOLOG).Unwrap_Or(nil); ret == nil {
err = this.InsertModelLogs(this.TableName, uid, data) err = this.InsertModelLogs(this.TableName, uid, []interface{}{data})
} }
return return
} }
//添加新的多个数据到列表 data map[string]type //添加新的多个数据到列表 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) vof := reflect.ValueOf(data)
if !vof.IsValid() { if !vof.IsValid() {
return fmt.Errorf("Model_Comp: AddLists(nil)") return fmt.Errorf("Model_Comp: AddLists(nil)")
@ -180,7 +180,7 @@ func (this *Model_Comp) AddLists(uid string, data interface{}, attrs ...*cache.O
} }
//修改数据多个字段 uid 作为主键 //修改数据多个字段 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 { if err = this.Redis.HMSet(this.ukey(uid), data); err != nil {
return return
} }
@ -194,7 +194,7 @@ func (this *Model_Comp) Change(uid string, data map[string]interface{}, attrs ..
} }
//修改数据多个字段 uid 作为主键 //修改数据多个字段 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 { if err = this.Redis.HMSet(this.ukeylist(uid, _id), data); err != nil {
return 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 { if err = this.Redis.HGetAll(this.ukey(uid), data); err != nil {
return return
} }
@ -223,7 +223,7 @@ func (this *Model_Comp) Get(uid string, data interface{}) (err error) {
} }
//获取列表数据 注意 data 必须啊转 切片的指针 *[]type //获取列表数据 注意 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 keys map[string]string = make(map[string]string)
var c *mongo.Cursor var c *mongo.Cursor
t := reflect.TypeOf(data) t := reflect.TypeOf(data)
@ -294,6 +294,9 @@ func (this *Model_Comp) GetList(uid string, data interface{}) (err error) {
} }
temp[_id] = elem.Elem().Addr().Interface() temp[_id] = elem.Elem().Addr().Interface()
} }
if len(temp) == 0 { //没有数据自己返回
return
}
for k, v := range temp { for k, v := range temp {
key := this.ukeylist(uid, k) key := this.ukeylist(uid, k)
if err = this.Redis.HMSet(key, v); err != nil { if err = this.Redis.HMSet(key, v); err != nil {
@ -311,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...) this.Redis.HMGet(this.ukey(uid), data, fields...)
return return
} }
//读取List列表中单个数据中 多个字段数据 //读取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...) this.Redis.HMGet(this.ukeylist(uid, id), data, fields...)
return 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) err = this.Redis.HGetAll(this.ukeylist(uid, id), data)
return 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)) err = this.Redis.Delete(this.ukey(uid))
if err != nil { if err != nil {
return err return err
@ -339,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) listkey := this.ukey(uid)
for _, v := range ids { for _, v := range ids {
key := this.ukeylist(uid, v) key := this.ukeylist(uid, v)
@ -354,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) ret := cache.OperationAttrs(attrs).Find(cache.ATTR_MGOLOG).Unwrap_Or(nil)
if ret == nil { //启用mgolog if ret == nil { //启用mgolog
ir := cache.OperationAttrs(attrs).Find(cache.ATTR_INSERT).Unwrap_Or(nil) ir := cache.OperationAttrs(attrs).Find(cache.ATTR_INSERT).Unwrap_Or(nil)

View File

@ -8,14 +8,14 @@ import (
) )
///配置管理基础组件 ///配置管理基础组件
type MComp_Configure struct { type MCompConfigure struct {
cbase.ModuleCompBase cbase.ModuleCompBase
S base.IRPCXService //rpc服务对象 S base.IRPCXService //rpc服务对象
M IModule //当前业务模块 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.ModuleCompBase.Init(service, module, comp, options)
this.S = service.(base.IRPCXService) this.S = service.(base.IRPCXService)
this.M = module.(IModule) 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) 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 { for k, v := range confs {
err = configure.RegisterConfigure(k, v) err = configure.RegisterConfigure(k, v)
if err != nil { 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) return configure.GetConfigure(name)
} }

View File

@ -14,20 +14,20 @@ import (
) )
type DB_Comp struct { type DB_Comp struct {
modules.Model_Comp modules.MCompModel
task chan string task chan string
isInit bool isInit bool
} }
func (this *DB_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { 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) this.task = make(chan string, TaskMaxNum)
return return
} }
func (this *DB_Comp) Start() (err error) { func (this *DB_Comp) Start() (err error) {
err = this.Model_Comp.Start() err = this.MCompModel.Start()
model_count := this.Model_TotalCount() model_count := this.Model_TotalCount()
if model_count > 0 { //1000 if model_count > 0 { //1000
this.Redis.Set(comm.DBService_Status, true, -1) this.Redis.Set(comm.DBService_Status, true, -1)

View File

@ -9,21 +9,21 @@ import (
/* /*
装备模块 API 装备模块 API
*/ */
type Api_Comp struct { type apiComp struct {
modules.MComp_GateComp modules.MCompGate
service core.IService service core.IService
module *Equipment module *Equipment
} }
//组件初始化接口 //组件初始化接口
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MCompGate.Init(service, module, comp, options)
this.module = module.(*Equipment) this.module = module.(*Equipment)
this.service = service this.service = service
return return
} }
func (this *Api_Comp) Start() (err error) { func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start() err = this.MCompGate.Start()
return return
} }

View File

@ -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 ( var (
err error err error
errorCode pb.ErrorCode 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)) equipments = make([]*pb.DB_Equipment, len(req.EquipmentId))
for i, v := range req.EquipmentId { for i, v := range req.EquipmentId {
if v != "" { if v != "" {
if equipments[i], err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPackById(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) log.Errorf("Equip_Check err:%v", err)
code.Code = pb.ErrorCode_EquipmentOnFoundEquipment code.Code = pb.ErrorCode_EquipmentOnFoundEquipment
return 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) log.Errorf("Equip_Check err:%v", err)
code.Code = pb.ErrorCode_EquipmentOnFoundEquipment code.Code = pb.ErrorCode_EquipmentOnFoundEquipment
return 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 ( var (
err error err error
confs []*cfg.Game_equipData confs []*cfg.Game_equipData
@ -55,11 +55,7 @@ func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface
updatequipment []*pb.DB_Equipment updatequipment []*pb.DB_Equipment
hero *pb.DB_HeroData 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) confs = agrs["conf"].([]*cfg.Game_equipData)
equipments = agrs["equipment"].([]*pb.DB_Equipment) equipments = agrs["equipment"].([]*pb.DB_Equipment)
updatequipment = make([]*pb.DB_Equipment, 0) 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 { for i, v := range hero.EquipID {
if v != "" { if v != "" {
if equipments[i] != nil && v != equipments[i].Id { if equipments[i] != nil && v != equipments[i].Id {
if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPackById(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) log.Errorf("Equip reader uid:%s equipment:%s err:%v", session.GetUserId(), v, err)
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return
@ -77,7 +73,7 @@ func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface
equipments[i].HeroId = hero.Id equipments[i].HeroId = hero.Id
updatequipment = append(updatequipment, equipment, equipments[i]) updatequipment = append(updatequipment, equipment, equipments[i])
} else if equipments[i] == nil { } else if equipments[i] == nil {
if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPackById(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) log.Errorf("Equip reader uid:%s equipment:%s err:%v", session.GetUserId(), v, err)
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return 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 code = this.module.hero.UpdateEquipment(hero, equipments); code == pb.ErrorCode_Success {
if err = this.module.model_equipment_comp.Equipment_UpdateIsEquip(session.GetUserId(), updatequipment...); err != nil { if err = this.module.modelEquipment.UpdateByHeroId(session.GetUserId(), updatequipment...); err != nil {
log.Errorf("Equip err%v", err) log.Errorf("Equip err%v", err)
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return

View File

@ -7,13 +7,13 @@ 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 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) (code pb.ErrorCode) {
var ( var (
err error err error
items []*pb.DB_Equipment items []*pb.DB_Equipment
@ -23,7 +23,7 @@ func (this *Api_Comp) Getlist(session comm.IUserSession, agrs map[string]interfa
session.SendMsg(string(this.module.GetType()), "", &pb.Equipment_GetList_Resp{Equipments: items}) session.SendMsg(string(this.module.GetType()), "", &pb.Equipment_GetList_Resp{Equipments: items})
} }
}() }()
if items, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPack(session.GetUserId()); err != nil { if items, err = this.module.modelequipment.QueryUserEquipments(session.GetUserId()); err != nil {
log.Errorf("QueryUserPackReq err:%v", err) log.Errorf("QueryUserPackReq err:%v", err)
code = pb.ErrorCode_CacheReadError code = pb.ErrorCode_CacheReadError
return return

View File

@ -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 ( var (
err error err error
conf *cfg.Game_equipData 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 code.Code = pb.ErrorCode_ReqParameterError
return return
} }
if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPackById(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) log.Errorf("Equip_Check err:%v", err)
code.Code = pb.ErrorCode_EquipmentOnFoundEquipment code.Code = pb.ErrorCode_EquipmentOnFoundEquipment
return 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) log.Errorf("Equip_Check err:%v", err)
code.Code = pb.ErrorCode_EquipmentOnFoundEquipment code.Code = pb.ErrorCode_EquipmentOnFoundEquipment
return return
} }
//找到下一个等级的相关配置 //找到下一个等级的相关配置
if intensify, err = this.module.configure_comp.GetEquipmentIntensifyConfigureById(equipment.Lv + 1); err != nil { if intensify, err = this.module.configure.GetEquipmentIntensifyConfigureById(equipment.Lv); err != nil {
log.Errorf("Equip_Check err:%v", err) log.Errorf("Equip_Check err:%v", err)
code.Code = pb.ErrorCode_EquipmentLvlimitReached code.Code = pb.ErrorCode_EquipmentLvlimitReached
return 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 ( var (
err error err error
conf *cfg.Game_equipData 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 { if equipment.IsInitialState && equipment.OverlayNum > 1 {
equipment.OverlayNum-- 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, "overlayNum": equipment.OverlayNum,
"heroId": "", "heroId": "",
}); err != nil { }); err != nil {
@ -97,17 +97,27 @@ func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interfa
equipment.Id = primitive.NewObjectID().Hex() equipment.Id = primitive.NewObjectID().Hex()
equipment.IsInitialState = false equipment.IsInitialState = false
equipment.OverlayNum = 1 equipment.OverlayNum = 1
equipment.Lv++ if err = this.module.modelEquipment.upgradeEquipment(equipment, conf, intensify); err != nil {
if err = this.module.model_equipment_comp.AddList(session.GetUserId(), equipment.Id, equipment); err != nil { code = pb.ErrorCode_SystemError
log.Errorf("Upgrade err:%v", err)
return
}
if err = this.module.modelEquipment.AddList(session.GetUserId(), equipment.Id, equipment); err != nil {
log.Errorf("Upgrade err:%v", err) log.Errorf("Upgrade err:%v", err)
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return
} }
} else { } else {
equipment.IsInitialState = false equipment.IsInitialState = false
equipment.Lv++ if err = this.module.modelEquipment.upgradeEquipment(equipment, conf, intensify); err != nil {
if err = this.module.model_equipment_comp.ChangeList(session.GetUserId(), equipment.Id, map[string]interface{}{ code = pb.ErrorCode_SystemError
log.Errorf("Upgrade err:%v", err)
return
}
if err = this.module.modelEquipment.ChangeList(session.GetUserId(), equipment.Id, map[string]interface{}{
"lv": equipment.Lv, "lv": equipment.Lv,
"mainEntry": equipment.MainEntry,
"adverbEntry": equipment.AdverbEntry,
"isInitialState": false, "isInitialState": false,
}); err != nil { }); err != nil {
log.Errorf("Upgrade err:%v", err) log.Errorf("Upgrade err:%v", err)
@ -126,7 +136,7 @@ func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interfa
for i, v := range hero.EquipID { for i, v := range hero.EquipID {
if v != "" { if v != "" {
if v != equipment.Id { if v != equipment.Id {
if equipments[i], err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPackById(session.GetUserId(), v); err != nil { if equipments[i], err = this.module.modelEquipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil {
log.Errorf("Upgrade err:%v", err) log.Errorf("Upgrade err:%v", err)
code = pb.ErrorCode_EquipmentOnFoundEquipment code = pb.ErrorCode_EquipmentOnFoundEquipment
return return

View File

@ -6,22 +6,23 @@ import (
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
) )
const ( const (
game_equip = "game_equip.json" //装备信息表 game_equip = "game_equip.json" //装备信息表
equip_attrlibrary = "equip_attrlibrary.json" //装备属性配置表 equip_attrlibrary = "game_equipattrlibrary.json" //装备属性配置表
equip_intensify = "equip_intensify.json" //装备等级消耗表 equip_intensify = "game_equipintensify.json" //装备等级消耗表
equip_suit = "equip_suit.json" //装备套装表 equip_suit = "game_equipsuit.json" //装备套装表
) )
///背包配置管理组件 ///背包配置管理组件
type Configure_Comp struct { type configureComp struct {
modules.MComp_Configure 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.ModuleCompBase.Init(service, module, comp, options)
this.LoadConfigure(game_equip, cfg.NewGame_equip) this.LoadConfigure(game_equip, cfg.NewGame_equip)
this.LoadConfigure(equip_attrlibrary, cfg.NewGame_equipAttrlibrary) this.LoadConfigure(equip_attrlibrary, cfg.NewGame_equipAttrlibrary)
@ -29,16 +30,18 @@ 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 ( var (
v interface{} v interface{}
ok bool ok bool
) )
if v, err = this.GetConfigure(game_equip); err != nil { if v, err = this.GetConfigure(game_equip); err != nil {
log.Errorf("err:%v", err)
return return
} else { } else {
if configure, ok = v.(*cfg.Game_equip); !ok { if configure, ok = v.(*cfg.Game_equip); !ok {
err = fmt.Errorf("%T no is *cfg.Game_equipment", v) err = fmt.Errorf("%T no is *cfg.Game_equipment", v)
log.Errorf("err:%v", err)
return return
} }
} }
@ -46,16 +49,18 @@ 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 ( var (
v interface{} v interface{}
ok bool ok bool
) )
if v, err = this.GetConfigure(game_equip); err != nil { if v, err = this.GetConfigure(game_equip); err != nil {
log.Errorf("err:%v", err)
return return
} else { } else {
if configure, ok = v.(*cfg.Game_equip).GetDataMap()[equipmentId]; !ok { if configure, ok = v.(*cfg.Game_equip).GetDataMap()[equipmentId]; !ok {
err = fmt.Errorf("EquipmentConfigure not found:%d ", equipmentId) err = fmt.Errorf("EquipmentConfigure not found:%d ", equipmentId)
log.Errorf("err:%v", err)
return return
} }
} }
@ -63,16 +68,18 @@ 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 ( var (
v interface{} v interface{}
ok bool ok bool
) )
if v, err = this.GetConfigure(equip_attrlibrary); err != nil { if v, err = this.GetConfigure(equip_attrlibrary); err != nil {
log.Errorf("err:%v", err)
return return
} else { } else {
if configure, ok = v.(*cfg.Game_equipAttrlibrary); !ok { if configure, ok = v.(*cfg.Game_equipAttrlibrary); !ok {
err = fmt.Errorf("%T no is *cfg.Game_equipment", v) err = fmt.Errorf("%T no is *cfg.Game_equipment", v)
log.Errorf("err:%v", err)
return return
} }
} }
@ -80,11 +87,31 @@ func (this *Configure_Comp) GetEquipmentAttrlibraryConfigure() (configure *cfg.G
} }
//获取属性词列表 //获取属性词列表
func (this *Configure_Comp) GetEquipmentAttrlibraryConfigureById(Id int32) (configure []*cfg.Game_equipAttrlibraryData, err error) { func (this *configureComp) GetEquipmentAttrlibraryConfigureByKey(key int32) (configure *cfg.Game_equipAttrlibraryData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(equip_attrlibrary); err != nil {
log.Errorf("err:%v", err)
return
} else {
if configure, ok = v.(*cfg.Game_equipAttrlibrary).GetDataMap()[key]; !ok {
err = fmt.Errorf("EquipmentConfigure GetEquipmentAttrlibraryConfigureByKey not found:%d ", key)
log.Errorf("err:%v", err)
return
}
}
return
}
//获取属性词列表
func (this *configureComp) GetEquipmentAttrlibraryConfigureById(Id int32) (configure []*cfg.Game_equipAttrlibraryData, err error) {
var ( var (
v interface{} v interface{}
) )
if v, err = this.GetConfigure(equip_attrlibrary); err != nil { if v, err = this.GetConfigure(equip_attrlibrary); err != nil {
log.Errorf("err:%v", err)
return return
} else { } else {
configure = make([]*cfg.Game_equipAttrlibraryData, 0) configure = make([]*cfg.Game_equipAttrlibraryData, 0)
@ -98,16 +125,18 @@ 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 ( var (
v interface{} v interface{}
ok bool ok bool
) )
if v, err = this.GetConfigure(equip_intensify); err != nil { if v, err = this.GetConfigure(equip_intensify); err != nil {
log.Errorf("err:%v", err)
return return
} else { } else {
if configure, ok = v.(*cfg.Game_equipIntensify); !ok { if configure, ok = v.(*cfg.Game_equipIntensify); !ok {
err = fmt.Errorf("%T no is *cfg.Game_equipment", v) err = fmt.Errorf("%T no is *cfg.Game_equipment", v)
log.Errorf("err:%v", err)
return return
} }
} }
@ -115,16 +144,18 @@ 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 ( var (
v interface{} v interface{}
ok bool ok bool
) )
if v, err = this.GetConfigure(equip_intensify); err != nil { if v, err = this.GetConfigure(equip_intensify); err != nil {
log.Errorf("err:%v", err)
return return
} else { } else {
if configure, ok = v.(*cfg.Game_equipIntensify).GetDataMap()[Id]; !ok { if configure, ok = v.(*cfg.Game_equipIntensify).GetDataMap()[Id]; !ok {
err = fmt.Errorf("EquipmentConfigure not found:%d ", Id) err = fmt.Errorf("EquipmentConfigure not found:%d ", Id)
log.Errorf("err:%v", err)
return return
} }
} }

View File

@ -0,0 +1,234 @@
package equipment
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"math/rand"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
///装备 数据组件
type modelEquipmentComp struct {
modules.MCompModel
module *Equipment
}
//组件初始化接口
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索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
//查询用户装备数据
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 *modelEquipmentComp) QueryUserEquipments(uId string) (equipments []*pb.DB_Equipment, err error) {
equipments = make([]*pb.DB_Equipment, 0)
err = this.GetList(uId, &equipments)
return
}
///查询目标卡片数量
func (this *modelEquipmentComp) QueryEquipmentAmount(uid string, equipmentId int32) (amount uint32) {
var (
equipments []*pb.DB_Equipment
err error
)
amount = 0
if equipments, err = this.QueryUserEquipments(uid); err != nil {
return
}
for _, v := range equipments {
if v.CId == equipmentId {
amount += v.OverlayNum
}
}
return
}
//添加装备
func (this *modelEquipmentComp) AddEquipments(uId string, cIds map[int32]uint32) (err error) {
var (
configure *cfg.Game_equip
equipments []*pb.DB_Equipment
iskeep bool
add map[string]*pb.DB_Equipment
update map[string]*pb.DB_Equipment
)
if configure, err = this.module.configure.GetEquipmentConfigure(); err != nil {
return
}
if equipments, err = this.QueryUserEquipments(uId); err != nil {
return
}
add = make(map[string]*pb.DB_Equipment)
update = make(map[string]*pb.DB_Equipment)
for k, v := range cIds {
iskeep = false
for _, equipment := range equipments {
if equipment.CId == k && equipment.IsInitialState {
update[equipment.Id] = equipment
equipment.OverlayNum += v
iskeep = true
break
}
}
if !iskeep {
if c, ok := configure.GetDataMap()[k]; ok {
if equipment, err := this.newEquipment(uId, c, v); err != nil {
return err
} else {
add[equipment.Id] = equipment
}
}
}
}
if err = this.AddLists(uId, add); err != nil {
log.Errorf("err:%v", err)
return
}
for _, v := range update {
if err = this.ChangeList(uId, v.Id, map[string]interface{}{"overlayNum": v.OverlayNum}); err != nil {
log.Errorf("err:%v", err)
return
}
}
return
}
//更新武器挂载信息
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,
}); err != nil {
log.Errorf("err:%v", err)
return
}
}
return
}
//创建新的武器对象
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
total int
satterNum int32
)
equipment = &pb.DB_Equipment{
Id: primitive.NewObjectID().Hex(),
CId: conf.Id,
Lv: 1,
UId: uid,
OverlayNum: num,
IsInitialState: true,
AdverbEntry: make([]*pb.EquipmentAttributeEntry, 0),
}
if mattr, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(conf.Leadlibrary); err != nil || len(mattr) == 0 {
return
}
equipment.MainEntry = &pb.EquipmentAttributeEntry{
Id: mattr[0].Key,
Libraryid: mattr[0].Libraryid,
Lv: 1,
AttrName: mattr[0].Attrkey,
Value: mattr[0].Attrvar,
}
if sattr, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(conf.Addlibrary); err != nil || len(mattr) == 0 {
return
}
for _, v := range conf.Addattrnump {
total += int(v)
}
n := rand.Intn(total)
for i, v := range conf.Addattrnump {
if int32(n) <= v {
satterNum = conf.Addattrnum[i]
break
}
}
if satterNum > 0 && satterNum <= 4 {
r := rand.New(rand.NewSource(time.Now().Unix()))
for _, v := range r.Perm(len(sattr))[:satterNum] {
equipment.AdverbEntry = append(equipment.AdverbEntry, &pb.EquipmentAttributeEntry{
Id: sattr[v].Key,
Libraryid: sattr[v].Libraryid,
Lv: 1,
AttrName: sattr[v].Attrkey,
Value: sattr[v].Attrvar,
})
}
}
return
}
//升级武器
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)
if !intensify.Activation { //不触发副词条变化
return
}
if len(equipment.AdverbEntry) < 4 { //去随机副词条
var temp []*cfg.Game_equipAttrlibraryData
var sattr []*cfg.Game_equipAttrlibraryData
if temp, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(equip.Addlibrary); err != nil || len(temp) == 0 {
log.Errorf("升级服务错误 读取副词条配置错误!")
return
}
//检索出未使用的词条
for _, v := range sattr {
iskeep := false
for _, v1 := range equipment.AdverbEntry {
if v.Key == v1.Id {
iskeep = true
}
}
if !iskeep {
sattr = append(sattr, v)
}
}
r := rand.New(rand.NewSource(time.Now().Unix()))
index := r.Perm(len(sattr))[0]
equipment.AdverbEntry = append(equipment.AdverbEntry, &pb.EquipmentAttributeEntry{
Id: sattr[index].Key,
Libraryid: sattr[index].Libraryid,
Lv: 1,
AttrName: sattr[index].Attrkey,
Value: sattr[index].Attrvar,
})
} else { //随机一个副词条 强化
var attrlibrary *cfg.Game_equipAttrlibraryData
r := rand.New(rand.NewSource(time.Now().Unix()))
index := r.Perm(len(equipment.AdverbEntry))[0]
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
equipment.AdverbEntry[index].Lv++
}
return
}

View File

@ -1,165 +0,0 @@
package equipment
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"math/rand"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
///装备 数据组件
type Model_Equipment_Comp struct {
modules.Model_Comp
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)
this.module = module.(*Equipment)
this.TableName = "equipment"
//创建uid索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
//查询用户装备数据
func (this *Model_Equipment_Comp) Equipment_QueryUserEquipmentsPackById(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_QueryUserEquipmentsPack(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) Equipment_AddEquipmentsToPack(uId string, cIds map[int32]uint32) (err error) {
var (
configure *cfg.Game_equip
equipments []*pb.DB_Equipment
iskeep bool
add map[string]*pb.DB_Equipment
update map[string]*pb.DB_Equipment
)
if configure, err = this.module.configure_comp.GetEquipmentConfigure(); err != nil {
return
}
if equipments, err = this.Equipment_QueryUserEquipmentsPack(uId); err != nil {
return
}
add = make(map[string]*pb.DB_Equipment)
update = make(map[string]*pb.DB_Equipment)
for k, v := range cIds {
iskeep = false
for _, equipment := range equipments {
if equipment.CId == k && equipment.IsInitialState {
update[equipment.Id] = equipment
equipment.OverlayNum += v
iskeep = true
break
}
}
if !iskeep {
if c, ok := configure.GetDataMap()[k]; ok {
if equipment, err := this.newEquipment(uId, c, v); err != nil {
return err
} else {
add[equipment.Id] = equipment
}
}
}
}
if err = this.AddLists(uId, add); err != nil {
log.Errorf("[Equipment] Equipment_AddEquipmentsToPack err:%v", err)
return
}
for _, v := range update {
if err = this.ChangeList(uId, v.Id, map[string]interface{}{"overlayNum": v.OverlayNum}); err != nil {
log.Errorf("[Equipment] Equipment_AddEquipmentsToPack err:%v", err)
return
}
}
return
}
func (this *Model_Equipment_Comp) Equipment_UpdateIsEquip(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,
}); err != nil {
log.Errorf("Equipment_UpdateIsEquip err:%v", err)
return
}
}
return
}
//创建新的武器对象
func (this *Model_Equipment_Comp) newEquipment(uid string, conf *cfg.Game_equipData, num uint32) (equipment *pb.DB_Equipment, err error) {
var (
mattr []*cfg.Game_equipAttrlibraryData
sattr []*cfg.Game_equipAttrlibraryData
total int
satterNum int32
)
equipment = &pb.DB_Equipment{
Id: primitive.NewObjectID().Hex(),
CId: conf.Id,
UId: uid,
OverlayNum: num,
IsInitialState: true,
AdverbEntry: make([]*pb.EquipmentAttributeEntry, 4),
}
if mattr, err = this.module.configure_comp.GetEquipmentAttrlibraryConfigureById(conf.Leadlibrary); err != nil || len(mattr) == 0 {
return
}
equipment.MainEntry = &pb.EquipmentAttributeEntry{
Id: mattr[0].Key,
Libraryid: mattr[0].Libraryid,
Lv: 0,
AttrName: mattr[0].Attr[0],
Value: 0,
}
if sattr, err = this.module.configure_comp.GetEquipmentAttrlibraryConfigureById(conf.Addlibrary); err != nil || len(mattr) == 0 {
return
}
for _, v := range conf.Addattrnump {
total += int(v)
}
n := rand.Intn(total)
for i, v := range conf.Addattrnump {
if int32(n) <= v {
satterNum = conf.Addattrnum[i]
break
}
}
if satterNum > 0 {
r := rand.New(rand.NewSource(time.Now().Unix()))
for i, v := range r.Perm(len(sattr))[:satterNum] {
equipment.AdverbEntry[i] = &pb.EquipmentAttributeEntry{
Id: sattr[v].Key,
Libraryid: sattr[v].Libraryid,
Lv: 0,
AttrName: sattr[v].Attr[0],
Value: 0,
}
}
}
return
}

View File

@ -4,7 +4,9 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb"
"github.com/go-redis/redis/v8"
"github.com/smallnest/rpcx/log" "github.com/smallnest/rpcx/log"
) )
@ -20,11 +22,11 @@ func NewModule() core.IModule {
type Equipment struct { type Equipment struct {
modules.ModuleBase modules.ModuleBase
service core.IService service core.IService
api_comp *Api_Comp api *apiComp
configure_comp *Configure_Comp configure *configureComp
model_equipment_comp *Model_Equipment_Comp modelEquipment *modelEquipmentComp
hero comm.IHero hero comm.IHero
} }
//模块名 //模块名
@ -54,7 +56,37 @@ func (this *Equipment) Start() (err error) {
//装备组件 //装备组件
func (this *Equipment) OnInstallComp() { func (this *Equipment) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.model_equipment_comp = this.RegisterComp(new(Model_Equipment_Comp)).(*Model_Equipment_Comp) this.modelEquipment = this.RegisterComp(new(modelEquipmentComp)).(*modelEquipmentComp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) 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.modelEquipment.QueryUserEquipmentsById(uid, Id); err != nil {
if err == redis.Nil {
code = pb.ErrorCode_EquipmentOnFoundEquipment
} else {
code = pb.ErrorCode_SystemError
}
}
return
}
//查询卡片数量
func (this *Equipment) QueryEquipmentAmount(source *comm.ModuleCallSource, uid string, equipmentId int32) (amount uint32) {
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.modelEquipment.AddEquipments(uid, cIds); err != nil {
log.Errorf("err%v", err)
code = pb.ErrorCode_SystemError
}
return
} }

View File

@ -1,4 +1,4 @@
package equipment package equipment_test
import ( import (
"fmt" "fmt"
@ -7,6 +7,8 @@ import (
"go_dreamfactory/lego/base/rpcx" "go_dreamfactory/lego/base/rpcx"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules/equipment"
"go_dreamfactory/modules/hero"
"go_dreamfactory/services" "go_dreamfactory/services"
"go_dreamfactory/sys/cache" "go_dreamfactory/sys/cache"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
@ -40,7 +42,7 @@ func (this *TestService) InitSys() {
} else { } else {
log.Infof("init sys.db success!") log.Infof("init sys.db success!")
} }
if err := configure.OnInit(this.GetSettings().Sys["configure"]); err != nil { if err := configure.OnInit(this.GetSettings().Sys["configure"], configure.SetConfigPath("F:/work/go/go_dreamfactory/bin/json")); err != nil {
panic(fmt.Sprintf("init sys.configure err: %s", err.Error())) panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
} else { } else {
log.Infof("init sys.configure success!") log.Infof("init sys.configure success!")
@ -49,7 +51,7 @@ func (this *TestService) InitSys() {
var service core.IService var service core.IService
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp() var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
var module = new(Equipment) var module = new(equipment.Equipment)
//测试环境下初始化db和cache 系统 //测试环境下初始化db和cache 系统
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
@ -63,6 +65,7 @@ func TestMain(m *testing.M) {
go func() { go func() {
lego.Run(service, //运行模块 lego.Run(service, //运行模块
module, module,
hero.NewModule(),
) )
}() }()
time.Sleep(time.Second * 3) time.Sleep(time.Second * 3)
@ -70,5 +73,10 @@ func TestMain(m *testing.M) {
} }
func Test_Module(t *testing.T) { func Test_Module(t *testing.T) {
code := module.AddNewEquipments(&comm.ModuleCallSource{
Module: "Test",
FuncName: "Test_Module",
Describe: "摸底测试",
}, "0_62b16dda909b2f8faeff788d", map[int32]uint32{10001: 1})
log.Debugf("Test_Module Code:%d", code)
} }

View File

@ -9,21 +9,21 @@ import (
/* /*
装备模块 API 装备模块 API
*/ */
type Api_Comp struct { type apiComp struct {
modules.MComp_GateComp modules.MCompGate
service core.IService service core.IService
module *Forum module *Forum
} }
//组件初始化接口 //组件初始化接口
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MCompGate.Init(service, module, comp, options)
this.module = module.(*Forum) this.module = module.(*Forum)
this.service = service this.service = service
return return
} }
func (this *Api_Comp) Start() (err error) { func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start() err = this.MCompGate.Start()
return return
} }

View File

@ -11,12 +11,12 @@ const (
) )
///背包配置管理组件 ///背包配置管理组件
type Configure_Comp struct { type configureComp struct {
modules.MComp_Configure 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.ModuleCompBase.Init(service, module, comp, options)
return return

View File

@ -9,14 +9,14 @@ import (
) )
///论坛 数据组件 ///论坛 数据组件
type Model_Forum_Comp struct { type modelForumComp struct {
modules.Model_Comp modules.MCompModel
module *Forum module *Forum
} }
//组件初始化接口 //组件初始化接口
func (this *Model_Forum_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { func (this *modelForumComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.Model_Comp.Init(service, module, comp, opt) this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Forum) this.module = module.(*Forum)
this.TableName = "forum" this.TableName = "forum"
//创建uid索引 //创建uid索引

View File

@ -18,9 +18,9 @@ func NewModule() core.IModule {
type Forum struct { type Forum struct {
modules.ModuleBase modules.ModuleBase
api_comp *Api_Comp api_comp *apiComp
configure_comp *Configure_Comp configure_comp *configureComp
model_forum_comp *Model_Forum_Comp model_forum_comp *modelForumComp
} }
//模块名 //模块名
@ -37,7 +37,7 @@ func (this *Forum) Init(service core.IService, module core.IModule, options core
//装备组件 //装备组件
func (this *Forum) OnInstallComp() { func (this *Forum) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp)
this.model_forum_comp = this.RegisterComp(new(Model_Forum_Comp)).(*Model_Forum_Comp) this.model_forum_comp = this.RegisterComp(new(modelForumComp)).(*modelForumComp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) this.configure_comp = this.RegisterComp(new(configureComp)).(*configureComp)
} }

View File

@ -18,12 +18,12 @@ const (
) )
type apiComp struct { type apiComp struct {
modules.MComp_GateComp modules.MCompGate
module *Friend module *Friend
} }
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MCompGate.Init(service, module, comp, options)
this.module = module.(*Friend) this.module = module.(*Friend)
return return
} }

View File

@ -15,7 +15,7 @@ const (
) )
type ModelFriend struct { type ModelFriend struct {
modules.Model_Comp modules.MCompModel
} }
func (this *ModelFriend) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *ModelFriend) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {

View File

@ -18,8 +18,8 @@ func NewModule() core.IModule {
type Game struct { type Game struct {
modules.ModuleBase modules.ModuleBase
api_comp *Api_Comp api *ApiComp
configure_comp *Configure_Comp configure *ConfigureComp
} }
//模块名 //模块名
@ -36,6 +36,6 @@ func (this *Game) Init(service core.IService, module core.IModule, options core.
//装备组件 //装备组件
func (this *Game) OnInstallComp() { func (this *Game) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) this.api = this.RegisterComp(new(ApiComp)).(*ApiComp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp)
} }

View File

@ -208,7 +208,7 @@ func (this *Agent) Close() {
} }
//分发用户消息 //分发用户消息
func (this *Agent) messageDistribution(msg *pb.UserMessage) error { func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
reply := &pb.RPCMessageReply{} reply := &pb.RPCMessageReply{}
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType) log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
servicePath := comm.Service_Worker servicePath := comm.Service_Worker
@ -219,25 +219,32 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) error {
servicePath = fmt.Sprintf("%s/%s", comm.Service_Worker, this.wId) servicePath = fmt.Sprintf("%s/%s", comm.Service_Worker, this.wId)
} }
} }
if err := this.gateway.Service().RpcCall(context.Background(), servicePath, string(comm.Rpc_GatewayRoute), &pb.AgentMessage{ if err = this.gateway.Service().RpcCall(context.Background(), servicePath, string(comm.Rpc_GatewayRoute), &pb.AgentMessage{
Ip: this.IP(), Ip: this.IP(),
UserSessionId: this.sessionId, UserSessionId: this.sessionId,
UserId: this.uId, UserId: this.uId,
GatewayServiceId: this.gateway.Service().GetId(), GatewayServiceId: this.gateway.Service().GetId(),
Method: fmt.Sprintf("%s.%s", msg.MainType, msg.SubType), MainType: msg.MainType,
SubType: msg.SubType,
Message: msg.Data, Message: msg.Data,
}, reply); err != nil { }, reply); err != nil {
log.Errorf("agent:%s uId:%s MessageDistribution err:%v", this.sessionId, this.uId, err) log.Errorf("agent:%s uId:%s MessageDistribution err:%v", this.sessionId, this.uId, err)
return err return
} }
if reply.Code != pb.ErrorCode_Success { if reply.Code != pb.ErrorCode_Success {
data, _ := anypb.New(&pb.ErrorNotify{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: pb.ErrorCode(reply.Code.Number())}) data, _ := anypb.New(&pb.ErrorNotify{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: pb.ErrorCode(reply.Code.Number())})
err := this.WriteMsg(&pb.UserMessage{ err = this.WriteMsg(&pb.UserMessage{
MainType: comm.MainType_Notify, MainType: comm.MainType_Notify,
SubType: comm.SubType_ErrorNotify, SubType: comm.SubType_ErrorNotify,
Data: data, Data: data,
}) })
return err return
} else {
for _, v := range reply.Reply {
if err = this.WriteMsg(v); err != nil {
return
}
}
} }
return nil return nil
} }

View File

@ -16,13 +16,13 @@ import (
/* /*
用户代理对象管理组件 用户代理对象管理组件
*/ */
type AgentMgr_Comp struct { type AgentMgrComp struct {
cbase.ModuleCompBase cbase.ModuleCompBase
service base.IRPCXService service base.IRPCXService
agents *sync.Map 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) err = this.ModuleCompBase.Init(service, module, comp, options)
this.service = service.(base.IRPCXService) this.service = service.(base.IRPCXService)
this.agents = new(sync.Map) 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) this.agents.Store(a.SessionId(), a)
} }
//移除断开的用户 //移除断开的用户
func (this *AgentMgr_Comp) DisConnect(a IAgent) { func (this *AgentMgrComp) DisConnect(a IAgent) {
this.agents.Delete(a.SessionId()) this.agents.Delete(a.SessionId())
if a.UserId() != "" { //登录用户 通知业务服务处理玩家离线相关 if a.UserId() != "" { //登录用户 通知业务服务处理玩家离线相关
reply := &pb.RPCMessageReply{} reply := &pb.RPCMessageReply{}
@ -48,29 +48,29 @@ func (this *AgentMgr_Comp) DisConnect(a IAgent) {
} }
//用户登录绑定Id //用户登录绑定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 { if a, ok := this.agents.Load(args.UserSessionId); ok {
a.(IAgent).Bind(args.UserId, args.WorkerId) a.(IAgent).Bind(args.UserId, args.WorkerId)
} else { } else {
reply.Code = pb.ErrorCode_UserSessionNobeing reply.Code = pb.ErrorCode_UserSessionNobeing
reply.Message = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing) reply.ErrorMessage = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing)
} }
return nil return nil
} }
//用户登录解绑Id //用户登录解绑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 { if a, ok := this.agents.Load(args.UserSessionId); ok {
a.(IAgent).UnBind() a.(IAgent).UnBind()
} else { } else {
reply.Code = pb.ErrorCode_UserSessionNobeing reply.Code = pb.ErrorCode_UserSessionNobeing
reply.Message = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing) reply.ErrorMessage = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing)
} }
return nil return nil
} }
//向用户发送消息 //向用户发送消息
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 { if a, ok := this.agents.Load(args.UserSessionId); ok {
a.(IAgent).WriteMsg(&pb.UserMessage{ a.(IAgent).WriteMsg(&pb.UserMessage{
MainType: args.MainType, MainType: args.MainType,
@ -79,13 +79,13 @@ func (this *AgentMgr_Comp) SendMsgToAgent(ctx context.Context, args *pb.AgentSen
}) })
} else { } else {
reply.Code = pb.ErrorCode_UserSessionNobeing reply.Code = pb.ErrorCode_UserSessionNobeing
reply.Message = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing) reply.ErrorMessage = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing)
} }
return nil return nil
} }
//向多个户发送消息 //向多个户发送消息
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{ msg := &pb.UserMessage{
MainType: args.MainType, MainType: args.MainType,
SubType: args.SubType, 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{ msg := &pb.UserMessage{
MainType: args.MainType, MainType: args.MainType,
SubType: args.SubType, SubType: args.SubType,
@ -114,12 +114,12 @@ 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 { if a, ok := this.agents.Load(args.UserSessionId); ok {
a.(IAgent).Close() a.(IAgent).Close()
} else { } else {
reply.Code = pb.ErrorCode_UserSessionNobeing reply.Code = pb.ErrorCode_UserSessionNobeing
reply.Message = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing) reply.ErrorMessage = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing)
} }
return nil return nil
} }

View File

@ -21,10 +21,10 @@ func NewModule() core.IModule {
type Gateway struct { type Gateway struct {
modules.ModuleBase modules.ModuleBase
service base.IRPCXService service base.IRPCXService
wsservice_comp *WSService_Comp //websocket 服务组件 提供websocket服务监听 wsservice *WSServiceComp //websocket 服务组件 提供websocket服务监听
agentmgr_comp *AgentMgr_Comp //用户代理对象管理组件 管理用户socekt对象 agentmgr *AgentMgrComp //用户代理对象管理组件 管理用户socekt对象
configure_comp *Configure_Comp configure *ConfigureComp
} }
//模块名 //模块名
@ -52,17 +52,17 @@ func (this *Gateway) Init(service core.IService, module core.IModule, options co
//模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务 //模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务
func (this *Gateway) Start() (err error) { func (this *Gateway) Start() (err error) {
//注册用户绑定uid接口 登录成功后触发 //注册用户绑定uid接口 登录成功后触发
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentBind), this.agentmgr_comp.Bind) this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentBind), this.agentmgr.Bind)
//注册用户解绑uid接口 登出或则切换账号是触发 //注册用户解绑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连接接口 //关闭用户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() err = this.ModuleBase.Start()
return return
} }
@ -70,24 +70,24 @@ func (this *Gateway) Start() (err error) {
//装备组件 //装备组件
func (this *Gateway) OnInstallComp() { func (this *Gateway) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.agentmgr_comp = this.RegisterComp(new(AgentMgr_Comp)).(*AgentMgr_Comp) this.agentmgr = this.RegisterComp(new(AgentMgrComp)).(*AgentMgrComp)
this.wsservice_comp = this.RegisterComp(new(WSService_Comp)).(*WSService_Comp) this.wsservice = this.RegisterComp(new(WSServiceComp)).(*WSServiceComp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp)
} }
//有新的连接对象进入 //有新的连接对象进入
func (this *Gateway) Connect(a IAgent) { func (this *Gateway) Connect(a IAgent) {
log.Debugf("[Module.Gateway] have new connect:Ip[%s] SessionId:[%s]", a.IP(), a.SessionId()) 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) { func (this *Gateway) DisConnect(a IAgent) {
log.Debugf("[Module.Gateway] have disConnect:Ip[%s] SessionId:[%s] uid:[%s]", a.IP(), a.SessionId(), a.UserId()) 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) { func (this *Gateway) GetMsgDistribRule(mtype, stype string) (rule string, ok bool) {
return this.configure_comp.GetMsgDistribRule(mtype, stype) return this.configure.GetMsgDistribRule(mtype, stype)
} }

View File

@ -12,7 +12,7 @@ import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
) )
type WSService_Comp struct { type WSServiceComp struct {
cbase.ModuleCompBase cbase.ModuleCompBase
options *Options options *Options
@ -20,7 +20,7 @@ type WSService_Comp struct {
gin gin.ISys 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) err = this.ModuleCompBase.Init(service, module, comp, options)
this.options = options.(*Options) this.options = options.(*Options)
this.module = module.(IGateway) this.module = module.(IGateway)
@ -29,7 +29,7 @@ func (this *WSService_Comp) Init(service core.IService, module core.IModule, com
return return
} }
func (this *WSService_Comp) ws(c *engine.Context) { func (this *WSServiceComp) ws(c *engine.Context) {
upGrader := websocket.Upgrader{ upGrader := websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { CheckOrigin: func(r *http.Request) bool {
return true return true

View File

@ -7,7 +7,7 @@ import (
) )
type apiComp struct { type apiComp struct {
modules.MComp_GateComp modules.MCompGate
service core.IService service core.IService
moduleHero *Hero moduleHero *Hero
user comm.IUser user comm.IUser
@ -21,14 +21,14 @@ const ( //消息回复的头名称
//组件初始化接口 //组件初始化接口
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MCompGate.Init(service, module, comp, options)
this.moduleHero = module.(*Hero) this.moduleHero = module.(*Hero)
this.service = service this.service = service
return return
} }
func (this *apiComp) Start() (err error) { func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start() err = this.MCompGate.Start()
var module core.IModule var module core.IModule

View File

@ -19,13 +19,13 @@ const (
///配置管理组件 ///配置管理组件
type configureComp struct { type configureComp struct {
modules.MComp_Configure modules.MCompConfigure
} }
//组件初始化接口 //组件初始化接口
func (this *configureComp) 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) {
err = this.MComp_Configure.Init(service, module, comp, options) err = this.MCompConfigure.Init(service, module, comp, options)
err = this.LoadMultiConfigure(map[string]interface{}{ err = this.LoadMultiConfigure(map[string]interface{}{
new_hero: cfg.NewGame_newHero, new_hero: cfg.NewGame_newHero,
hero_stargrow: cfg.NewGame_heroStargrow, hero_stargrow: cfg.NewGame_heroStargrow,

View File

@ -15,12 +15,12 @@ import (
) )
type ModelHero struct { type ModelHero struct {
modules.Model_Comp modules.MCompModel
moduleHero *Hero moduleHero *Hero
} }
func (this *ModelHero) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *ModelHero) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.Model_Comp.Init(service, module, comp, options) err = this.MCompModel.Init(service, module, comp, options)
this.moduleHero = module.(*Hero) this.moduleHero = module.(*Hero)
this.TableName = "hero" this.TableName = "hero"
return return

View File

@ -15,21 +15,21 @@ const ( //消息回复的头名称
/* /*
背包 处理用户的请求组件 必须继承 modules.MComp_GateComp 背包 处理用户的请求组件 必须继承 modules.MComp_GateComp
*/ */
type Api_Comp struct { type apiComp struct {
modules.MComp_GateComp modules.MCompGate
service core.IService service core.IService
module *Items module *Items
} }
//组件初始化接口 //组件初始化接口
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MCompGate.Init(service, module, comp, options)
this.module = module.(*Items) this.module = module.(*Items)
this.service = service this.service = service
return return
} }
func (this *Api_Comp) Start() (err error) { func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start() err = this.MCompGate.Start()
return return
} }

View File

@ -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} result = map[string]interface{}{"ce": 123}
return 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 ( var (
err error err error
items []*pb.DB_UserItemData 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}) session.SendMsg(string(this.module.GetType()), GetlistResp, &pb.Items_Getlist_Resp{Grids: grids})
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
go func() { //异步处理修改数据 go func() { //异步处理修改数据
this.module.model_pack_comp.Pack_UpdateUserPack(session.GetUserId(), modifys...) this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...)
this.module.model_pack_comp.Pack_DeleteUserPack(session.GetUserId(), dels...) 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) log.Errorf("QueryUserPackReq err:%v", err)
code = pb.ErrorCode_CacheReadError code = pb.ErrorCode_CacheReadError
return return
} else { } 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)) modifys = make([]*pb.DB_UserItemData, 0, len(tempgrids))
dels = make([]string, 0, len(tempgrids)) dels = make([]string, 0, len(tempgrids))
grids = make([]*pb.DB_UserItemData, 0, len(grids)) grids = make([]*pb.DB_UserItemData, 0, len(grids))

View File

@ -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 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() { defer func() {
session.SendMsg(string(this.module.GetType()), SellItemResp, &pb.Items_SellItem_Resp{}) session.SendMsg(string(this.module.GetType()), SellItemResp, &pb.Items_SellItem_Resp{})
}() }()

View File

@ -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 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() { defer func() {
session.SendMsg(string(this.module.GetType()), UseItemResp, &pb.Items_UseItem_Resp{}) session.SendMsg(string(this.module.GetType()), UseItemResp, &pb.Items_UseItem_Resp{})
}() }()

View File

@ -15,19 +15,19 @@ const (
) )
///背包配置管理组件 ///背包配置管理组件
type Configure_Comp struct { type ConfigureComp struct {
modules.MComp_Configure 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.ModuleCompBase.Init(service, module, comp, options)
this.LoadConfigure(game_item, cfg.NewGame_item) this.LoadConfigure(game_item, cfg.NewGame_item)
return 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 ( var (
v interface{} v interface{}
ok bool 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)) result = make([]*pb.DB_UserItemData, 0, len(itmes))
var ( var (
v interface{} v interface{}

View File

@ -12,14 +12,14 @@ import (
) )
///背包缓存数据管理组件 ///背包缓存数据管理组件
type Model_Pack_Comp struct { type ModelItemsComp struct {
modules.Model_Comp modules.MCompModel
module *Items module *Items
} }
//组件初始化接口 //组件初始化接口
func (this *Model_Pack_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { func (this *ModelItemsComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.Model_Comp.Init(service, module, comp, opt) this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Items) this.module = module.(*Items)
this.TableName = "items" this.TableName = "items"
//创建uid索引 //创建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) itmes = make([]*pb.DB_UserItemData, 0)
err = this.GetList(uId, &itmes) err = this.GetList(uId, &itmes)
return 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{} itme = &pb.DB_UserItemData{}
err = this.GetListObj(uId, grid, itme) err = this.GetListObj(uId, grid, itme)
return 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 { for _, v := range itmes {
this.AddList(uId, v.GridId, v) 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...) err = this.DelListlds(uId, ids...)
return 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 { for _, v := range itmes {
this.ChangeList(uId, v.GridId, map[string]interface{}{ this.ChangeList(uId, v.GridId, map[string]interface{}{
"amount": v.Amount, "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...) err = this.DelListlds(uId, gridIds...)
return 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 ( var (
itmes []*pb.DB_UserItemData itmes []*pb.DB_UserItemData
err error 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 ( var (
itmes []*pb.DB_UserItemData itmes []*pb.DB_UserItemData
add []*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 ( var (
itmes []*pb.DB_UserItemData itmes []*pb.DB_UserItemData
add []*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 ( var (
itme *pb.DB_UserItemData itme *pb.DB_UserItemData
grid *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 ( var (
num int64 num int64
isNew bool isNew bool

View File

@ -21,10 +21,9 @@ func NewModule() core.IModule {
type Items struct { type Items struct {
modules.ModuleBase modules.ModuleBase
api_comp *Api_Comp api *apiComp
model_pack_comp *Model_Pack_Comp modelItems *ModelItemsComp
// db_comp *DB_Comp configure *ConfigureComp
configure_comp *Configure_Comp
} }
//模块名称 //模块名称
@ -41,17 +40,17 @@ func (this *Items) Init(service core.IService, module core.IModule, options core
//装备组件 //装备组件
func (this *Items) OnInstallComp() { func (this *Items) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.model_pack_comp = this.RegisterComp(new(Model_Pack_Comp)).(*Model_Pack_Comp) this.modelItems = this.RegisterComp(new(ModelItemsComp)).(*ModelItemsComp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp)
} }
//IPack------------------------------------------------------------------------------------------------------------------------------- //IItems-------------------------------------------------------------------------------------------------------------------------------
///查询用户背包物品数量 ///查询用户背包物品数量
func (this *Items) QueryItemAmount(source *comm.ModuleCallSource, uId string, itemid int32) (amount uint32) { 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) defer log.Debugf("获取物品 uId:%s itemid:%d addnum:%d ", uId, itemid, amount)
amount = 0 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 result[itemid]
} }
return 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) { 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 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) { func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, addnum int32) (code pb.ErrorCode) {
var err error var err error
defer log.Debugf("给用户添加物品 uId:%s itemid:%d addnum:%d issucc:%v", uId, itemid, addnum, err == nil) 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) log.Errorf("给用户添加物品 uId:%s itemid:%d addnum:%d err:%v", uId, itemid, addnum, err)
if err == ItemNotEnoughError { if err == ItemNotEnoughError {
code = pb.ErrorCode_ItemsNoEnough 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) { func (this *Items) AddItems(source *comm.ModuleCallSource, uId string, items map[int32]int32) (code pb.ErrorCode) {
var err error var err error
defer log.Debugf("给用户添加物品 uId:%s items:%d items:%v", uId, items, err == nil) 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) log.Errorf("给用户添加物品 uId:%s items:%d err:%v", uId, items, err)
if err == ItemNotEnoughError { if err == ItemNotEnoughError {
code = pb.ErrorCode_ItemsNoEnough code = pb.ErrorCode_ItemsNoEnough

View File

@ -1,4 +1,4 @@
package items package items_test
import ( import (
"context" "context"
@ -8,6 +8,7 @@ import (
"go_dreamfactory/lego/base/rpcx" "go_dreamfactory/lego/base/rpcx"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules/items"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/services" "go_dreamfactory/services"
"go_dreamfactory/sys/cache" "go_dreamfactory/sys/cache"
@ -53,7 +54,7 @@ func (this *TestService) InitSys() {
var service core.IService var service core.IService
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp() var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
var module = new(Items) var module = new(items.Items)
//测试环境下初始化db和cache 系统 //测试环境下初始化db和cache 系统
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
@ -75,7 +76,7 @@ func TestMain(m *testing.M) {
func Test_Modules(t *testing.T) { func Test_Modules(t *testing.T) {
data, _ := ptypes.MarshalAny(&pb.Items_Getlist_Req{}) data, _ := ptypes.MarshalAny(&pb.Items_Getlist_Req{})
s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{Method: "pack.getlist", Message: data}, &pb.RPCMessageReply{}) s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{MainType: "pack", SubType: "getlist", Message: data}, &pb.RPCMessageReply{})
// items, err := module.db_comp.Pack_QueryUserPack("liwei1dao") // items, err := module.db_comp.Pack_QueryUserPack("liwei1dao")
// log.Debugf("item:%v err:%v", items, err) // log.Debugf("item:%v err:%v", items, err)
} }

View File

@ -16,14 +16,14 @@ const (
) )
type apiComp struct { type apiComp struct {
modules.MComp_GateComp modules.MCompGate
service core.IService service core.IService
module *Mail module *Mail
items comm.IItems items comm.IItems
} }
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MCompGate.Init(service, module, comp, options)
this.service = service this.service = service
this.module = module.(*Mail) this.module = module.(*Mail)
@ -31,7 +31,7 @@ func (this *apiComp) Init(service core.IService, module core.IModule, comp core.
} }
func (this *apiComp) Start() (err error) { func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start() err = this.MCompGate.Start()
var module core.IModule var module core.IModule
if module, err = this.service.GetModule(comm.SM_ItemsModule); err != nil { if module, err = this.service.GetModule(comm.SM_ItemsModule); err != nil {

View File

@ -57,7 +57,7 @@ func (this *Mail) CreateNewMail(uId string) {
} }
// 通知玩家 // 通知玩家
var _cache = &pb.Cache_UserData{} var _cache = &pb.Cache_UserData{}
err = this.modelMail.Model_Comp.Get(uId, _cache) err = this.modelMail.MCompModel.Get(uId, _cache)
if err == nil { if err == nil {
return return
} }

View File

@ -80,36 +80,36 @@ func (this *ModuleBase) SendMsgToUsers(mainType, subType string, msg proto.Messa
//校验消耗资源 //校验消耗资源
func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code pb.ErrorCode) { func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code pb.ErrorCode) {
var ( var (
module core.IModule module core.IModule
err error err error
resID int resID int
amount int32 amount int32
user comm.IUser //用户模块 user comm.IUser //用户模块
items comm.IItems //道具背包模块 items comm.IItems //道具背包模块
hero comm.IHero //英雄模块 hero comm.IHero //英雄模块
equipment comm.IEquipment //装备模块 // equipment comm.IEquipment //装备模块
) )
if module, err = this.service.GetModule(comm.SM_UserModule); err == nil { if module, err = this.service.GetModule(comm.SM_UserModule); err == nil {
return return
} }
user = module.(comm.IUser) user = module.(comm.IUser)
if module, err = this.service.GetModule(comm.SM_UserModule); err == nil { if module, err = this.service.GetModule(comm.SM_ItemsModule); err == nil {
return return
} }
items = module.(comm.IItems) items = module.(comm.IItems)
if module, err = this.service.GetModule(comm.SM_UserModule); err == nil { if module, err = this.service.GetModule(comm.SM_HeroModule); err == nil {
return return
} }
hero = module.(comm.IHero) hero = module.(comm.IHero)
if module, err = this.service.GetModule(comm.SM_UserModule); err == nil { // if module, err = this.service.GetModule(comm.SM_EquipmentModule); err == nil {
return // return
} // }
// equipment = module.(comm.IEquipment)
source := &comm.ModuleCallSource{ source := &comm.ModuleCallSource{
Module: string(this.module.GetType()), Module: string(this.module.GetType()),
FuncName: "CheckConsumeRes", FuncName: "CheckConsumeRes",
Describe: "消耗资源", Describe: "消耗资源",
} }
equipment = module.(comm.IEquipment)
//校验消费资源是否充足 //校验消费资源是否充足
for _, v := range res { for _, v := range res {
if v.A == comm.AttrType { //用户属性资源 if v.A == comm.AttrType { //用户属性资源
@ -135,16 +135,18 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
code = pb.ErrorCode_ResNoEnough code = pb.ErrorCode_ResNoEnough
return return
} }
} else if v.A == comm.EquipmentType {
if resID, err = strconv.Atoi(v.T); err != nil {
code = pb.ErrorCode_ConfigurationException
return
}
if amount = int32(equipment.QueryEquipmentAmount(source, uid, int32(resID))); amount < v.N {
code = pb.ErrorCode_ResNoEnough
return
}
} }
//不存在消耗武器的情况
// } else if v.A == comm.EquipmentType {
// if resID, err = strconv.Atoi(v.T); err != nil {
// code = pb.ErrorCode_ConfigurationException
// return
// }
// if amount = int32(equipment.QueryEquipmentAmount(source, uid, int32(resID))); amount < v.N {
// code = pb.ErrorCode_ResNoEnough
// return
// }
// }
} }
for _, v := range res { for _, v := range res {
@ -156,10 +158,11 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
} else if v.A == comm.CardType { //卡片资源 } else if v.A == comm.CardType { //卡片资源
resID, _ = strconv.Atoi(v.T) resID, _ = strconv.Atoi(v.T)
hero.ChangeCard(uid, int32(resID), -1*v.N) hero.ChangeCard(uid, int32(resID), -1*v.N)
} else if v.A == comm.EquipmentType {
resID, _ = strconv.Atoi(v.T)
equipment.AddNewEquipments(source, uid, resID, -1*v.N)
} }
// } else if v.A == comm.EquipmentType {
// resID, _ = strconv.Atoi(v.T)
// equipment.AddNewEquipments(source, uid, resID, -1*v.N)
// }
} }
return return

View File

@ -15,21 +15,21 @@ const (
) )
type apiComp struct { type apiComp struct {
modules.MComp_GateComp modules.MCompGate
service base.IRPCXService service base.IRPCXService
module *User module *User
hero comm.IHero hero comm.IHero
} }
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MCompGate.Init(service, module, comp, options)
this.service = service.(base.IRPCXService) this.service = service.(base.IRPCXService)
this.module = module.(*User) this.module = module.(*User)
return return
} }
func (this *apiComp) Start() (err error) { func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start() err = this.MCompGate.Start()
var module core.IModule var module core.IModule
//get module hero //get module hero

View File

@ -6,11 +6,11 @@ import (
) )
type ModelSession struct { type ModelSession struct {
modules.Model_Comp modules.MCompModel
} }
func (this *ModelSession) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *ModelSession) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.Model_Comp.Init(service, module, comp, options) err = this.MCompModel.Init(service, module, comp, options)
this.TableName = "session" this.TableName = "session"
return return
} }

View File

@ -17,11 +17,11 @@ const ( //Redis
) )
type ModelUser struct { type ModelUser struct {
modules.Model_Comp modules.MCompModel
} }
func (this *ModelUser) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *ModelUser) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.Model_Comp.Init(service, module, comp, options) err = this.MCompModel.Init(service, module, comp, options)
this.TableName = "user" this.TableName = "user"
return return
} }

View File

@ -160,8 +160,9 @@ type AgentMessage struct {
UserSessionId string `protobuf:"bytes,2,opt,name=UserSessionId,proto3" json:"UserSessionId"` UserSessionId string `protobuf:"bytes,2,opt,name=UserSessionId,proto3" json:"UserSessionId"`
UserId string `protobuf:"bytes,3,opt,name=UserId,proto3" json:"UserId"` UserId string `protobuf:"bytes,3,opt,name=UserId,proto3" json:"UserId"`
GatewayServiceId string `protobuf:"bytes,4,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId"` GatewayServiceId string `protobuf:"bytes,4,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId"`
Method string `protobuf:"bytes,5,opt,name=Method,proto3" json:"Method"` MainType string `protobuf:"bytes,5,opt,name=MainType,proto3" json:"MainType"`
Message *anypb.Any `protobuf:"bytes,6,opt,name=Message,proto3" json:"Message"` SubType string `protobuf:"bytes,6,opt,name=SubType,proto3" json:"SubType"`
Message *anypb.Any `protobuf:"bytes,7,opt,name=Message,proto3" json:"Message"`
} }
func (x *AgentMessage) Reset() { func (x *AgentMessage) Reset() {
@ -224,9 +225,16 @@ func (x *AgentMessage) GetGatewayServiceId() string {
return "" return ""
} }
func (x *AgentMessage) GetMethod() string { func (x *AgentMessage) GetMainType() string {
if x != nil { if x != nil {
return x.Method return x.MainType
}
return ""
}
func (x *AgentMessage) GetSubType() string {
if x != nil {
return x.SubType
} }
return "" return ""
} }
@ -244,9 +252,10 @@ type RPCMessageReply struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code"` Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code"`
Message string `protobuf:"bytes,2,opt,name=Message,proto3" json:"Message"` ErrorMessage string `protobuf:"bytes,2,opt,name=ErrorMessage,proto3" json:"ErrorMessage"`
Data string `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data"` ErrorData string `protobuf:"bytes,3,opt,name=ErrorData,proto3" json:"ErrorData"`
Reply []*UserMessage `protobuf:"bytes,4,rep,name=Reply,proto3" json:"Reply"`
} }
func (x *RPCMessageReply) Reset() { func (x *RPCMessageReply) Reset() {
@ -288,20 +297,27 @@ func (x *RPCMessageReply) GetCode() ErrorCode {
return ErrorCode_Success return ErrorCode_Success
} }
func (x *RPCMessageReply) GetMessage() string { func (x *RPCMessageReply) GetErrorMessage() string {
if x != nil { if x != nil {
return x.Message return x.ErrorMessage
} }
return "" return ""
} }
func (x *RPCMessageReply) GetData() string { func (x *RPCMessageReply) GetErrorData() string {
if x != nil { if x != nil {
return x.Data return x.ErrorData
} }
return "" return ""
} }
func (x *RPCMessageReply) GetReply() []*UserMessage {
if x != nil {
return x.Reply
}
return nil
}
//用户代理绑定Uid请求 //用户代理绑定Uid请求
type AgentBuildReq struct { type AgentBuildReq struct {
state protoimpl.MessageState state protoimpl.MessageState
@ -732,7 +748,7 @@ var file_comm_proto_rawDesc = []byte{
0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x04, 0x64, 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, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e,
0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x65, 0x63, 0x18, 0x04, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x65, 0x63, 0x18, 0x04,
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x65, 0x63, 0x22, 0xd0, 0x01, 0x0a, 0x0c, 0x41, 0x67, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x65, 0x63, 0x22, 0xee, 0x01, 0x0a, 0x0c, 0x41, 0x67,
0x65, 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x70, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x70,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x49, 0x70, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x49, 0x70, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73,
0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
@ -741,66 +757,72 @@ var file_comm_proto_rawDesc = []byte{
0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65,
0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01,
0x28, 0x09, 0x52, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x28, 0x09, 0x52, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x05, 0x63, 0x65, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65,
0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x2e, 0x0a, 0x07, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65,
0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28,
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,
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, 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, 0x5f, 0x0a, 0x0f, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x36, 0x0a, 0x0e, 0x41, 0x67, 0x65,
0x52, 0x50, 0x43, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x6e, 0x74, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55,
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,
0x18, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74,
0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 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, 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, 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, 0x64, 0x22, 0x2c, 0x0a, 0x12, 0x4e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x43,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49,
0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x2a,
0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x43, 0x0a, 0x12, 0x48, 0x65, 0x72, 0x6f, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65,
0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x06, 0x0a, 0x02, 0x48, 0x70, 0x10, 0x00, 0x12, 0x07, 0x0a,
0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x03, 0x41, 0x74, 0x6b, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x44, 0x65, 0x66, 0x10, 0x02, 0x12,
0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x09, 0x0a, 0x05, 0x53, 0x70, 0x65, 0x65, 0x64, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x43, 0x72,
0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x69, 0x74, 0x10, 0x04, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x6f, 0x74, 0x6f, 0x33,
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, 0x2c, 0x0a, 0x12, 0x4e, 0x6f,
0x74, 0x69, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x71,
0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 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 ( var (
@ -836,14 +858,15 @@ var file_comm_proto_depIdxs = []int32{
11, // 0: UserMessage.data:type_name -> google.protobuf.Any 11, // 0: UserMessage.data:type_name -> google.protobuf.Any
11, // 1: AgentMessage.Message:type_name -> google.protobuf.Any 11, // 1: AgentMessage.Message:type_name -> google.protobuf.Any
12, // 2: RPCMessageReply.Code:type_name -> ErrorCode 12, // 2: RPCMessageReply.Code:type_name -> ErrorCode
11, // 3: AgentSendMessageReq.Data:type_name -> google.protobuf.Any 1, // 3: RPCMessageReply.Reply:type_name -> UserMessage
11, // 4: BatchMessageReq.Data:type_name -> google.protobuf.Any 11, // 4: AgentSendMessageReq.Data:type_name -> google.protobuf.Any
11, // 5: BroadCastMessageReq.Data:type_name -> google.protobuf.Any 11, // 5: BatchMessageReq.Data:type_name -> google.protobuf.Any
6, // [6:6] is the sub-list for method output_type 11, // 6: BroadCastMessageReq.Data:type_name -> google.protobuf.Any
6, // [6:6] is the sub-list for method input_type 7, // [7:7] is the sub-list for method output_type
6, // [6:6] is the sub-list for extension type_name 7, // [7:7] is the sub-list for method input_type
6, // [6:6] is the sub-list for extension extendee 7, // [7:7] is the sub-list for extension type_name
0, // [0:6] is the sub-list for field type_name 7, // [7:7] is the sub-list for extension extendee
0, // [0:7] is the sub-list for field type_name
} }
func init() { file_comm_proto_init() } func init() { file_comm_proto_init() }

View File

@ -18,15 +18,17 @@ message AgentMessage {
string UserSessionId = 2; string UserSessionId = 2;
string UserId = 3; string UserId = 3;
string GatewayServiceId = 4; string GatewayServiceId = 4;
string Method = 5; string MainType = 5;
google.protobuf.Any Message = 6; string SubType = 6;
google.protobuf.Any Message = 7;
} }
// RPC // RPC
message RPCMessageReply { message RPCMessageReply {
ErrorCode Code = 1; ErrorCode Code = 1;
string Message = 2; string ErrorMessage = 2;
string Data = 3; string ErrorData = 3;
repeated UserMessage Reply = 4;
} }
//Uid请求 //Uid请求

View File

@ -27,64 +27,49 @@ import (
*/ */
func NewGateRouteComp() comm.ISC_GateRouteComp { func NewGateRouteComp() comm.ISC_GateRouteComp {
comp := new(SComp_GateRouteComp) comp := new(SCompGateRoute)
return comp return comp
} }
//用户协议处理函数注册的反射对象 //用户协议处理函数注册的反射对象
type msghandle struct { type msghandle struct {
rcvr reflect.Value rcvr reflect.Value
msgType reflect.Type msgType reflect.Type //消息请求类型
fn reflect.Method check reflect.Method //校验函数
handle reflect.Method //处理函数
} }
//服务网关组件 //服务网关组件
type SComp_GateRouteComp struct { type SCompGateRoute struct {
cbase.ServiceCompBase cbase.ServiceCompBase
service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口 service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口
mrlock sync.RWMutex //msghandles 对象的锁 mrlock sync.RWMutex //msghandles 对象的锁
msgcheck map[string]*msghandle //处理函数的校验接口
msghandles map[string]*msghandle //处理函数的管理对象 msghandles map[string]*msghandle //处理函数的管理对象
} }
//设置服务组件名称 方便业务模块中获取此组件对象 //设置服务组件名称 方便业务模块中获取此组件对象
func (this *SComp_GateRouteComp) GetName() core.S_Comps { func (this *SCompGateRoute) GetName() core.S_Comps {
return comm.SC_ServiceGateRouteComp 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) err = this.ServiceCompBase.Init(service, comp, options)
this.service = service.(base.IRPCXService) this.service = service.(base.IRPCXService)
this.msgcheck = make(map[string]*msghandle)
this.msghandles = make(map[string]*msghandle) this.msghandles = make(map[string]*msghandle)
return err return err
} // } //
//组件启动时注册rpc服务监听 //组件启动时注册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_GatewayRoute), this.ReceiveMsg) //注册网关路由接收接口
this.service.RegisterFunctionName(string(comm.Rpc_NoticeUserClose), this.NoticeUserClose) //注册用户离线通知 this.service.RegisterFunctionName(string(comm.Rpc_NoticeUserClose), this.NoticeUserClose) //注册用户离线通知
err = this.ServiceCompBase.Start() err = this.ServiceCompBase.Start()
event.RegisterGO(core.Event_ServiceStartEnd, func() {
for k, v := range this.msghandles {
if v1, ok := this.msgcheck[k]; !ok {
log.Panicf("注册用户消息处理函数:%s 没有实现参数校验接口", k)
return
} else if v.msgType != v1.msgType {
log.Panicf("注册用户消息处理函数:%s 实现参数校验接口不一致 请检查代码!", k)
return
}
}
})
event.RegisterGO(core.Event_FindNewService, func() {
log.Debugf("find new service")
})
return return
} }
//业务模块注册用户消息处理路由 //业务模块注册用户消息处理路由
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, check, handele reflect.Method) {
log.Debugf("注册用户路由【%s】", methodName) log.Debugf("注册用户路由【%s】", methodName)
this.mrlock.RLock() this.mrlock.RLock()
_, ok := this.msghandles[methodName] _, ok := this.msghandles[methodName]
@ -97,46 +82,28 @@ func (this *SComp_GateRouteComp) RegisterRoute(methodName string, comp reflect.V
this.msghandles[methodName] = &msghandle{ this.msghandles[methodName] = &msghandle{
rcvr: comp, rcvr: comp,
msgType: msg, msgType: msg,
fn: fn, check: check,
} handle: handele,
this.mrlock.Unlock()
}
//业务模块注册用户消息处理路由
func (this *SComp_GateRouteComp) RegisterRouteCheck(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) {
log.Debugf("注册用户路由校验[%s]", methodName)
this.mrlock.RLock()
_, ok := this.msgcheck[methodName]
this.mrlock.RUnlock()
if ok {
log.Errorf("重复 注册用户路由校验[%s]", methodName)
return
}
this.mrlock.Lock()
this.msgcheck[methodName] = &msghandle{
rcvr: comp,
msgType: msg,
fn: fn,
} }
this.mrlock.Unlock() this.mrlock.Unlock()
} }
//Rpc_GatewayRoute服务接口的接收函数 //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() { //程序异常 收集异常信息传递给前端显示 defer func() { //程序异常 收集异常信息传递给前端显示
if r := recover(); r != nil { if r := recover(); r != nil {
buf := make([]byte, 1024) buf := make([]byte, 1024)
l := runtime.Stack(buf, false) l := runtime.Stack(buf, false)
reply.Code = pb.ErrorCode_Exception reply.Code = pb.ErrorCode_Exception
reply.Message = fmt.Sprintf("%v: %s", r, buf[:l]) reply.ErrorMessage = fmt.Sprintf("%v: %s", r, buf[:l])
log.Errorf("HandleUserMsg:%s err:%s", args.Method, reply.Message) log.Errorf("HandleUserMsg:[%s-%s] err:%s", args.MainType, args.SubType, reply.ErrorMessage)
} }
}() }()
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:[%s-%s]", args.UserSessionId, args.UserId, args.MainType, args.SubType)
method := fmt.Sprintf("%s.%s", args.MainType, args.SubType)
//获取用户消息处理函数 //获取用户消息处理函数
this.mrlock.RLock() this.mrlock.RLock()
msghandle, ok := this.msghandles[args.Method] msghandle, ok := this.msghandles[method]
msgcheck := this.msgcheck[args.Method]
this.mrlock.RUnlock() this.mrlock.RUnlock()
if ok { if ok {
//封装用户会话 //封装用户会话
@ -144,24 +111,24 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM
//序列化用户消息对象 //序列化用户消息对象
msg := reflect.New(msghandle.msgType.Elem()).Interface() msg := reflect.New(msghandle.msgType.Elem()).Interface()
if err := ptypes.UnmarshalAny(args.Message, msg.(proto.Message)); err != nil { if err := ptypes.UnmarshalAny(args.Message, msg.(proto.Message)); err != nil {
log.Errorf("UserMessage:%s Unmarshal err:%v", args.Method, err) log.Errorf("UserMessage:%s Unmarshal err:%v", method, err)
return err return err
} }
//调用校验接口 //调用校验接口
checkreturn := msgcheck.fn.Func.Call([]reflect.Value{msgcheck.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)}) checkreturn := msghandle.check.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)})
//读取校验结果 有错误直接返回错误码给用户 //读取校验结果 有错误直接返回错误码给用户
code := checkreturn[1].Interface().(comm.ErrorCode) code := checkreturn[1].Interface().(comm.ErrorCode)
if code.Code != pb.ErrorCode_Success { if code.Code != pb.ErrorCode_Success {
log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code) log.Errorf("HandleUserMsg:%s msg:%v code:%d", method, msg, code)
reply.Code = code.Code reply.Code = code.Code
reply.Message = pb.GetErrorCodeMsg(code.Code) reply.ErrorMessage = pb.GetErrorCodeMsg(code.Code)
if code.Data != nil { //处理错误附加数据 采用json 序列化为string if code.Data != nil { //处理错误附加数据 采用json 序列化为string
if d, err := jsoniter.Marshal(code.Data); err != nil { if d, err := jsoniter.Marshal(code.Data); err != nil {
log.Errorf("HandleUserMsg:%s msg:%v code:%d err:%v", args.Method, msg, code, err) log.Errorf("HandleUserMsg:%s msg:%v code:%d err:%v", method, msg, code, err)
return nil return nil
} else { } else {
reply.Data = codec.BytesToString(d) reply.ErrorData = codec.BytesToString(d)
} }
} }
return nil return nil
@ -169,13 +136,15 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM
//校验结果成功 处理临时数据转移 //校验结果成功 处理临时数据转移
result := checkreturn[0].Interface().(map[string]interface{}) result := checkreturn[0].Interface().(map[string]interface{})
//调用用户处理函数 //调用用户处理函数
handlereturn := msghandle.fn.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(result), reflect.ValueOf(msg)})
errcode := pb.ErrorCode(handlereturn[0].Int()) errcode := pb.ErrorCode(handlereturn[0].Int())
if errcode != pb.ErrorCode_Success { //处理返货错误码 返回用户错误信息 if errcode != pb.ErrorCode_Success { //处理返货错误码 返回用户错误信息
log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code) log.Errorf("HandleUserMsg:%s msg:%v code:%d", method, msg, code)
reply.Code = errcode reply.Code = errcode
reply.Message = pb.GetErrorCodeMsg(errcode) reply.ErrorMessage = pb.GetErrorCodeMsg(errcode)
return nil return nil
} else {
reply.Reply = session.Polls()
} }
} else { //未找到消息处理函数 } else { //未找到消息处理函数
reply.Code = pb.ErrorCode_ReqParameterError reply.Code = pb.ErrorCode_ReqParameterError
@ -184,7 +153,8 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM
} }
//RPC_NoticeUserClose 接收用户离线通知 //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) event.TriggerEvent(comm.Event_UserOffline, args.UserId)
return nil return nil
} }

View File

@ -1,4 +1,3 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
@ -11,49 +10,87 @@ package cfg
import "errors" import "errors"
type Game_equipAttrlibraryData struct { type Game_equipAttrlibraryData struct {
Key int32 Key int32
Libraryid int32 Libraryid int32
Attr []string Attrkey string
Probability int32 Attrvar int32
Addition []int32 Probability int32
Addition []int32
} }
func (Game_equipAttrlibraryData) GetTypeId() int { func (Game_equipAttrlibraryData) GetTypeId() int {
return -437457248 return -437457248
} }
func NewGame_equipAttrlibraryData(_buf map[string]interface{}) (_v *Game_equipAttrlibraryData, err error) { func NewGame_equipAttrlibraryData(_buf map[string]interface{}) (_v *Game_equipAttrlibraryData, err error) {
_v = &Game_equipAttrlibraryData{} _v = &Game_equipAttrlibraryData{}
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["key"].(float64); !_ok_ { err = errors.New("key error"); return }; _v.Key = int32(_tempNum_) } {
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["libraryid"].(float64); !_ok_ { err = errors.New("libraryid error"); return }; _v.Libraryid = int32(_tempNum_) } var _ok_ bool
{ var _tempNum_ float64
var _arr_ []interface{} if _tempNum_, _ok_ = _buf["key"].(float64); !_ok_ {
var _ok_ bool err = errors.New("key error")
if _arr_, _ok_ = _buf["attr"].([]interface{}); !_ok_ { err = errors.New("attr error"); return } return
}
_v.Key = int32(_tempNum_)
}
{
var _ok_ bool
var _tempNum_ float64
if _tempNum_, _ok_ = _buf["libraryid"].(float64); !_ok_ {
err = errors.New("libraryid error")
return
}
_v.Libraryid = int32(_tempNum_)
}
{
var _ok_ bool
if _v.Attrkey, _ok_ = _buf["attrkey"].(string); !_ok_ {
err = errors.New("attrkey error")
return
}
}
{
var _ok_ bool
var _tempNum_ float64
if _tempNum_, _ok_ = _buf["attrvar"].(float64); !_ok_ {
err = errors.New("attrvar error")
return
}
_v.Attrvar = int32(_tempNum_)
}
{
var _ok_ bool
var _tempNum_ float64
if _tempNum_, _ok_ = _buf["probability"].(float64); !_ok_ {
err = errors.New("probability error")
return
}
_v.Probability = int32(_tempNum_)
}
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["Addition"].([]interface{}); !_ok_ {
err = errors.New("Addition error")
return
}
_v.Attr = make([]string, 0, len(_arr_)) _v.Addition = make([]int32, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ string
{ if _list_v_, _ok_ = _e_.(string); !_ok_ { err = errors.New("_list_v_ error"); return } }
_v.Attr = append(_v.Attr, _list_v_)
}
}
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["probability"].(float64); !_ok_ { err = errors.New("probability error"); return }; _v.Probability = int32(_tempNum_) } for _, _e_ := range _arr_ {
{ var _list_v_ int32
var _arr_ []interface{} {
var _ok_ bool var _ok_ bool
if _arr_, _ok_ = _buf["Addition"].([]interface{}); !_ok_ { err = errors.New("Addition error"); return } var _x_ float64
if _x_, _ok_ = _e_.(float64); !_ok_ {
err = errors.New("_list_v_ error")
return
}
_list_v_ = int32(_x_)
}
_v.Addition = append(_v.Addition, _list_v_)
}
}
_v.Addition = make([]int32, 0, len(_arr_)) return
for _, _e_ := range _arr_ {
var _list_v_ int32
{ var _ok_ bool; var _x_ float64; if _x_, _ok_ = _e_.(float64); !_ok_ { err = errors.New("_list_v_ error"); return }; _list_v_ = int32(_x_) }
_v.Addition = append(_v.Addition, _list_v_)
}
}
return
} }