diff --git a/cmd/gameserver/gmaction/GmAction.go b/cmd/gameserver/gmaction/GmAction.go index 7df9ea3..11e9c11 100644 --- a/cmd/gameserver/gmaction/GmAction.go +++ b/cmd/gameserver/gmaction/GmAction.go @@ -59,15 +59,18 @@ func (gm *GmAction) UpdatePackLimit(role *models.RoleModel, params GMParams) { update := make(map[string]interface{}, 3) c, ok := params["clotheslimit"] if ok { - update["clotheslimit"], _ = strconv.Atoi(c) + l, _ := strconv.Atoi(c) + update["clotheslimit"] = uint32(l) } w := params["weaponslimit"] if ok { - update["weaponslimit"], _ = strconv.Atoi(w) + l, _ := strconv.Atoi(w) + update["weaponslimit"] = uint32(l) } o := params["otherlimit"] if ok { - update["otherlimit"], _ = strconv.Atoi(o) + l, _ := strconv.Atoi(o) + update["otherlimit"] = uint32(l) } role.UpdateProperties(update, true) } diff --git a/cmd/gameserver/service/gm.go b/cmd/gameserver/service/gm.go index 1b57152..66af485 100644 --- a/cmd/gameserver/service/gm.go +++ b/cmd/gameserver/service/gm.go @@ -3,7 +3,7 @@ package service import ( "github.com/gin-gonic/gin" "net/http" - "pro2d/cmd/gameserver/action" + "pro2d/cmd/gameserver/gmaction" "pro2d/common/components" "pro2d/common/logger" "pro2d/models" @@ -79,7 +79,7 @@ func (s *GmServer) HandlerFuncObj(tvl, obj reflect.Value) gin.HandlerFunc { func (s *GmServer) Start() error { s.SetHandlerFuncCallback(s.HandlerFuncObj) - s.BindHandler(&action.GmAction{}) + s.BindHandler(&gmaction.GmAction{}) //gin.SetMode(gin.ReleaseMode) return s.IHttp.Start() } diff --git a/models/role.go b/models/role.go index 57a213e..4f8c76f 100644 --- a/models/role.go +++ b/models/role.go @@ -196,6 +196,7 @@ func (m *RoleModel) UpdateProperties(property map[string]interface{}, notify boo } role := &pb.Role{} + ids := m.ParseFields(role.ProtoReflect(), property) if len(ids) == 0 { logger.Error("ParseFields err, len is 0") diff --git a/models/schema.go b/models/schema.go index 1ad08be..003be24 100644 --- a/models/schema.go +++ b/models/schema.go @@ -1,6 +1,7 @@ package models import ( + "github.com/golang/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" "pro2d/common/components" "pro2d/common/db/mongoproxy" @@ -24,6 +25,7 @@ type Schema struct { db components.IDB reflectValue *reflect.Value reflectIndex map[string]int + protoIndex map[string]int cacheFields map[string]interface{} @@ -41,14 +43,20 @@ func NewSchema(key string, schema interface{}) *Schema { cacheFields: make(map[string]interface{}), schema: schema, reflectIndex: make(map[string]int), + protoIndex: make(map[string]int), } + proto.MessageReflect(schema.(proto.Message)).Range(func(des protoreflect.FieldDescriptor, value protoreflect.Value) bool { + sch.protoIndex[strings.ToLower(des.JSONName())] = des.Index() + return true + }) + for i := 0; i < s.Type().NumField(); i++ { name := s.Type().Field(i).Name if strings.Compare(name[0:1], strings.ToLower(name[0:1])) == 0 { continue } - sch.reflectIndex[strings.ToLower(strings.ToLower(name))] = i + sch.reflectIndex[strings.ToLower(name)] = i } sch.db = mongoproxy.NewMongoColl(sch.GetSchemaName(), sch) @@ -195,13 +203,21 @@ func (s *Schema) IncrProperty(key string, val int64) int64 { func (s *Schema) ParseFields(message protoreflect.Message, properties map[string]interface{}) []int32 { ids := make([]int32, 0, len(properties)) + for k, v := range properties { - field := message.Descriptor().Fields().ByName(protoreflect.Name(strings.ToLower(k))) + idx, ok := s.protoIndex[strings.ToLower(k)] + if !ok { + continue + } + field := message.Descriptor().Fields().Get(idx) if field == nil { continue } ids = append(ids, int32(field.Index())) + + field.Kind() + message.Set(field, protoreflect.ValueOf(v)) s.SetProperty(k, v) -- libgit2 0.21.2