diff --git a/DesignerConfigs b/DesignerConfigs index 8e21a91..815945c 160000 --- a/DesignerConfigs +++ b/DesignerConfigs @@ -1 +1 @@ -Subproject commit 8e21a91c0930bc6690a06824013c51f6bbda350b +Subproject commit 815945c2f56281d9808f542a9320b400dfb9301e diff --git a/Makefile b/Makefile index ca9e078..baef80a 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ gen: test: go run cmd/test/client.go http: - go run $(race) cmd/httpserver/http.go cmd/httpserver/AccountAction.go + go run $(race) cmd/httpserver/main.go game: go run -race cmd/gameserver/*.go @@ -27,5 +27,8 @@ plugin: cd bin && rm -rf ./plugin*.so && cd - go build $(race) $(DEBUG) --buildmode=plugin -o bin/$(pname).so cmd/gameserver/plugin/*.go #--ldflags="-pluginpath=$(pname)" cd bin && ln -s $(pname).so plugin.so && cd - +doc: + godoc -http=:8980 -goroot="." -play + open localhost:8980/pkg/pro2d/cmd/gameserver/action/#pkg-index -.PHONY: all build protos test cert plugin \ No newline at end of file +.PHONY: all build protos test cert plugin doc \ No newline at end of file diff --git a/cmd/gameserver/action/GmAction.go b/cmd/gameserver/action/GmAction.go index 93a239a..d19cd17 100644 --- a/cmd/gameserver/action/GmAction.go +++ b/cmd/gameserver/action/GmAction.go @@ -1,31 +1,73 @@ +// GM系统API package action import ( - "pro2d/common/logger" "pro2d/models" "pro2d/pb" "strconv" ) -type GmAction struct { -} +type GmAction struct{} + +// GMParams GM系统API请求参数的基础类型 +type GMParams map[string]string -func (gm *GmAction) AddExp(role *models.RoleModel, params ...interface{}) { - logger.Debug(params) - expIncrease, _ := strconv.Atoi(params[0].(string)) +/* +AddExp 增加经验 + exp 增加经验数量 +*/ +func (gm *GmAction) AddExp(role *models.RoleModel, params GMParams) { + expIncrease, _ := strconv.Atoi(params["exp"]) exp := role.IncrProperty("exp", int64(expIncrease)) role.UpdateProperty("exp", exp, true) } -func (gm *GmAction) AddEquip(role *models.RoleModel, params ...interface{}) { - logger.Debug(params) +/* +AddEquip 添加装备 + id: 装备id +*/ +func (gm *GmAction) AddEquip(role *models.RoleModel, params GMParams) { //TODO 验证装备是否存在 equip := &pb.Equipment{ Id: role.IncreEquipByKey(1), RoleId: role.Role.Id, - Type: params[0].(string), + Type: params["id"], Quality: 1, } role.AddEquip(equip) } + +/* +AddItem 添加物品 + id: 物品id + count: 物品数量 +*/ +func (gm *GmAction) AddItem(role *models.RoleModel, params GMParams) { + id := params["id"] + count, _ := strconv.Atoi(params["count"]) + role.AddItem(id, int32(count)) +} + +/* +UpdatePackLimit 更新背包限制 + clotheslimit: 服饰限制数 + weaponslimit: 武器限制数 + otherlimit: 其他限制数 +*/ +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) + } + w := params["weaponslimit"] + if ok { + update["weaponslimit"], _ = strconv.Atoi(w) + } + o := params["otherlimit"] + if ok { + update["otherlimit"], _ = strconv.Atoi(o) + } + role.UpdateProperties(update, true) +} diff --git a/cmd/gameserver/action/RoleAction.go b/cmd/gameserver/action/RoleAction.go index b0a9f96..6f3f8ce 100644 --- a/cmd/gameserver/action/RoleAction.go +++ b/cmd/gameserver/action/RoleAction.go @@ -1,3 +1,4 @@ +// Package action 游戏服角色相关操作 package action import ( @@ -12,11 +13,13 @@ import ( "pro2d/pb" ) +// HeartRpc 心跳请求 func HeartRpc(role *models.RoleModel, msg components.IMessage) (int32, interface{}) { //msg.Conn.SetLastHeartCheckTime() return 0, nil } +// getRandomName 随机名字 func getRandomName() string { name := "" for { @@ -36,6 +39,11 @@ func getRandomName() string { return name } +/* +CreateRpc 创建角色请求 + 1: proto解析错误 + 2: 角色不存在 +*/ func CreateRpc(role1 *models.RoleModel, msg components.IMessage) (int32, interface{}) { req := pb.CreateReq{} if err := proto.Unmarshal(msg.GetData(), &req); err != nil { @@ -63,6 +71,7 @@ func CreateRpc(role1 *models.RoleModel, msg components.IMessage) (int32, interfa return 0, nil } +// ChangeTeamRpc 阵容变换 func ChangeTeamRpc(role *models.RoleModel, msg components.IMessage) (int32, interface{}) { req := pb.ChangeTeamReq{} if err := proto.Unmarshal(msg.GetData(), &req); err != nil { @@ -74,6 +83,10 @@ func ChangeTeamRpc(role *models.RoleModel, msg components.IMessage) (int32, inte return 0, nil } +/* +HeroEquipReferRpc 穿戴/脱 装备 + 2: 装备不存在 +*/ func HeroEquipReferRpc(role *models.RoleModel, msg components.IMessage) (int32, interface{}) { req := pb.HeroEquipReferReq{} if err := proto.Unmarshal(msg.GetData(), &req); err != nil { @@ -118,6 +131,10 @@ func HeroEquipReferRpc(role *models.RoleModel, msg components.IMessage) (int32, return 0, nil } +/* +RoleClearItemsRpc 删除物品 + 2 删除失败 +*/ func RoleClearItemsRpc(role *models.RoleModel, msg components.IMessage) (int32, interface{}) { req := pb.RoleClearItemsReq{} if err := proto.Unmarshal(msg.GetData(), &req); err != nil { @@ -132,6 +149,10 @@ func RoleClearItemsRpc(role *models.RoleModel, msg components.IMessage) (int32, return 0, nil } +/* +EquipmentDelRpc 删除装备 + 2 删除失败 +*/ func EquipmentDelRpc(role *models.RoleModel, msg components.IMessage) (int32, interface{}) { req := pb.EquipmentDelReq{} if err := proto.Unmarshal(msg.GetData(), &req); err != nil { diff --git a/cmd/gameserver/plugin/plugin.go b/cmd/gameserver/plugin/plugin.go index a7cd429..e69d284 100644 --- a/cmd/gameserver/plugin/plugin.go +++ b/cmd/gameserver/plugin/plugin.go @@ -1,3 +1,4 @@ +// plugin 热更插件 package main import ( diff --git a/cmd/gameserver/service/agent.go b/cmd/gameserver/service/agent.go index 029ed7d..b4f6049 100644 --- a/cmd/gameserver/service/agent.go +++ b/cmd/gameserver/service/agent.go @@ -58,6 +58,9 @@ func (c *Agent) OnConnection(conn components.IConnection) { c.IConnection = conn } +/*OnLoginQuery 登录请求 +2 角色不存在 +*/ func (c *Agent) OnLoginQuery(msg components.IMessage) (int32, proto.Message) { //logger.Debug("11111111cmd: %v, msg: %s", msg.GetHeader().GetMsgID(), msg.GetData()) req := pb.LoginReq{} diff --git a/cmd/gameserver/service/gm.go b/cmd/gameserver/service/gm.go index 3a92229..1b57152 100644 --- a/cmd/gameserver/service/gm.go +++ b/cmd/gameserver/service/gm.go @@ -5,6 +5,7 @@ import ( "net/http" "pro2d/cmd/gameserver/action" "pro2d/common/components" + "pro2d/common/logger" "pro2d/models" "reflect" ) @@ -25,19 +26,20 @@ func (s *GmServer) HandlerFuncObj(tvl, obj reflect.Value) gin.HandlerFunc { return func(c *gin.Context) { var roleId string var ok bool - properties := make([]interface{}, 2) + properties := make(map[string]string, 2) //请求类型,以及 format 参数 if c.Request.Method == "POST" { c.Request.ParseForm() - for _, v := range c.Request.PostForm { - properties = append(properties, v[0]) + for k, v := range c.Request.PostForm { + properties[k] = v[0] } roleId, ok = c.GetPostForm("role_id") } else if c.Request.Method == "GET" { roleId, ok = c.GetQuery("role_id") - for _, v := range c.Request.URL.Query() { - properties = append(properties, v[0]) + logger.Debug(c.Request.URL.Query()) + for k, v := range c.Request.URL.Query() { + properties[k] = v[0] } } else { c.JSON(http.StatusOK, gin.H{"code": -101, "message": "not support method"}) @@ -53,6 +55,7 @@ func (s *GmServer) HandlerFuncObj(tvl, obj reflect.Value) gin.HandlerFunc { conn := s.Server.GetConnManage().GetConnByRID(roleId) var role *models.RoleModel callback := func() { + logger.Debug(properties) tvl.Call([]reflect.Value{obj, reflect.ValueOf(role), reflect.ValueOf(properties)}) role.SaveRoleData(0) } diff --git a/cmd/httpserver/AccountAction.go b/cmd/httpserver/AccountAction.go deleted file mode 100644 index ca655c8..0000000 --- a/cmd/httpserver/AccountAction.go +++ /dev/null @@ -1,108 +0,0 @@ -package main - -import ( - "fmt" - "github.com/garyburd/redigo/redis" - "github.com/gin-gonic/gin" - "pro2d/common" - "pro2d/common/db/redisproxy" - "pro2d/common/etcd" - "pro2d/common/logger" - "pro2d/common/sms" - "pro2d/models" - "pro2d/pb" -) - -type AccountAction struct { - HttpServer *AccountServer -} - -func (h *AccountAction) Register(c *gin.Context) (int, interface{}) { - var register pb.Register - if err := c.ShouldBindJSON(®ister); err != nil { - return 1, err.Error() - } - - key := fmt.Sprintf(common.SMSCode, register.Phone) - - relay, err := redisproxy.GET(key) - code, err := redis.String(relay, err) - if err != nil { - return 2, err.Error() - } - - logger.Debug("register: phone %s, code: %s", register.Phone, code) - - if register.Code != code && register.Code != "0000" { - return 3, "code error" - } - - account := models.NewAccount(register.Phone) - if err := account.Load(); err == nil { - return 4, "account exists: " + register.Phone - } - - uid, err := common.GetNextUId() - if err != nil { - return 5, "uid get error: " + err.Error() - } - account.Uid = uid - account.Password = common.Md5V(register.Password) - if err = account.Create(); err != nil { - return 6, "account register err: " + err.Error() - } - account.Password = register.Password - return 0, "success" -} - -func (h *AccountAction) Login(c *gin.Context) (int, interface{}) { - var login pb.Account - if err := c.ShouldBindJSON(&login); err != nil { - return 1, err.Error() - } - account := models.NewAccount(login.Phone) - if err := account.Load(); err != nil { - return 2, err.Error() - } - - if common.Md5V(login.Password) != account.Password { - return 3, "password error" - } - - var gs []*pb.ServiceInfo - for k, v := range etcd.GEtcdClient().GetByPrefix(common.GlobalConf.GameConf.Name) { - gs = append(gs, &pb.ServiceInfo{ - Id: k, - Name: common.GlobalConf.GameConf.Name, - Address: v, - }) - } - rsp := &pb.LoginRsp{ - Token: account.Uid, - GameService: gs, - } - return 0, rsp -} - -func (h *AccountAction) Sms(c *gin.Context) (int, interface{}) { - phone, ok := c.GetQuery("phone") - if !ok { - return 1, "phone not exists" - } - code := common.RandomCode() - key := fmt.Sprintf(common.SMSCode, phone) - - relay, err := redisproxy.SETNX(key, code) - if relay.(int64) == 0 { - return 2, "send frequently" - } - redisproxy.ExpireKey(key, 60) - - err = sms.SendSms(phone, code) - if err != nil { - redisproxy.DEL(key) - return 3, err.Error() - } - - return 0, nil -} diff --git a/cmd/httpserver/action/AccountAction.go b/cmd/httpserver/action/AccountAction.go new file mode 100644 index 0000000..0f666f6 --- /dev/null +++ b/cmd/httpserver/action/AccountAction.go @@ -0,0 +1,125 @@ +// Account 账号系统API +package action + +import ( + "fmt" + "github.com/garyburd/redigo/redis" + "github.com/gin-gonic/gin" + "pro2d/cmd/httpserver/service" + "pro2d/common" + "pro2d/common/db/redisproxy" + "pro2d/common/etcd" + "pro2d/common/logger" + "pro2d/common/sms" + "pro2d/models" + "pro2d/pb" +) + +type AccountAction struct { + HttpServer *service.AccountServer +} + +/*Register 账号注册 +2 验证码转化为string错误 +3 验证码错误 +4 手机号已存在,不用重复注册 +5 uid get error +6 mongo create error +*/ +func (h *AccountAction) Register(c *gin.Context) (int, interface{}) { + var register pb.Register + if err := c.ShouldBindJSON(®ister); err != nil { + return 1, err.Error() + } + + key := fmt.Sprintf(common.SMSCode, register.Phone) + + relay, err := redisproxy.GET(key) + code, err := redis.String(relay, err) + if err != nil { + return 2, err.Error() + } + + logger.Debug("register: phone %s, code: %s", register.Phone, code) + + if register.Code != code && register.Code != "0000" { + return 3, "code error" + } + + account := models.NewAccount(register.Phone) + if err := account.Load(); err == nil { + return 4, "account exists: " + register.Phone + } + + uid, err := common.GetNextUId() + if err != nil { + return 5, "uid get error: " + err.Error() + } + account.Uid = uid + account.Password = common.Md5V(register.Password) + if err = account.Create(); err != nil { + return 6, "account register err: " + err.Error() + } + account.Password = register.Password + return 0, "success" +} + +/*Login 登录 +2 账号不存在 +3 密码错误 +*/ +func (h *AccountAction) Login(c *gin.Context) (int, interface{}) { + var login pb.Account + if err := c.ShouldBindJSON(&login); err != nil { + return 1, err.Error() + } + account := models.NewAccount(login.Phone) + if err := account.Load(); err != nil { + return 2, "account not exists" + } + + if common.Md5V(login.Password) != account.Password { + return 3, "password error" + } + + var gs []*pb.ServiceInfo + for k, v := range etcd.GEtcdClient().GetByPrefix(common.GlobalConf.GameConf.Name) { + gs = append(gs, &pb.ServiceInfo{ + Id: k, + Name: common.GlobalConf.GameConf.Name, + Address: v, + }) + } + rsp := &pb.LoginRsp{ + Token: account.Uid, + GameService: gs, + } + return 0, rsp +} + +/*Sms 发短信 +2 发送太频繁 +3 发送失败 +*/ +func (h *AccountAction) Sms(c *gin.Context) (int, interface{}) { + phone, ok := c.GetQuery("phone") + if !ok { + return 1, "phone not exists" + } + code := common.RandomCode() + key := fmt.Sprintf(common.SMSCode, phone) + + relay, err := redisproxy.SETNX(key, code) + if relay.(int64) == 0 { + return 2, "send frequently" + } + redisproxy.ExpireKey(key, 60) + + err = sms.SendSms(phone, code) + if err != nil { + redisproxy.DEL(key) + return 3, err.Error() + } + + return 0, nil +} diff --git a/cmd/httpserver/http.go b/cmd/httpserver/http.go deleted file mode 100644 index 9e3a9c5..0000000 --- a/cmd/httpserver/http.go +++ /dev/null @@ -1,94 +0,0 @@ -package main - -import ( - "fmt" - "math/rand" - "os" - "os/signal" - "pro2d/common" - "pro2d/common/components" - "pro2d/common/db/mongoproxy" - "pro2d/common/db/redisproxy" - "pro2d/common/etcd" - "pro2d/common/logger" - "pro2d/models" - "syscall" - "time" -) - -type AccountServer struct { - components.IHttp - Sconf *common.SConf -} - -func NewAccountServer(version string, port ...string) *AccountServer { - return &AccountServer{IHttp: components.NewHttpServer(version, port...)} -} - -func (s *AccountServer) Init(sconf *common.SConf) error { - s.Sconf = sconf - - //mgo init - err := mongoproxy.ConnectMongo(sconf.MongoConf, sconf.ID) - - //redis init - if err = redisproxy.ConnectRedis(sconf.RedisConf.DB, sconf.RedisConf.Auth, sconf.RedisConf.Address); err != nil { - return err - } - - //Etcd 初始化 - err = etcd.NewEtcdClient(common.GlobalConf.Etcd) - if err != nil { - return err - } - etcd.PutWithLeasePrefix(sconf.Name, fmt.Sprintf("%d", sconf.ID), fmt.Sprintf("%s:%d", sconf.IP, sconf.Port), 5) - - models.NewDBSeed(sconf.ID).InitServerDatabase(models.AccountModels()) - models.DBSeedS().InitAutoIncreUidTable(models.AccountModels()) - return nil -} - -func (s *AccountServer) TimeOut() { - models.DBSeedS().SaveAutoincrementTimer(models.AccountModels()) - - components.TimeOut(1*time.Second, s.TimeOut) -} - -func (s *AccountServer) Start() error { - if err := s.Init(common.GlobalConf.AccountConf); err != nil { - return err - } - //设置随机种子 - rand.Seed(time.Now().Unix()) - //开始定时器 - s.TimeOut() - - return s.IHttp.Start() -} - -func (s *AccountServer) Stop() { - s.IHttp.Stop() - etcd.CloseEtcd() -} - -func main() { - err := make(chan error) - stopChan := make(chan os.Signal) - signal.Notify(stopChan, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL) - - common.GlobalSconf = common.GlobalConf.AccountConf - - web := NewAccountServer("v1", fmt.Sprintf(":%d", common.GlobalSconf.Port)) - web.BindHandler(&AccountAction{HttpServer: web}) - go func() { - err <- web.Start() - }() - - select { - case e := <-err: - logger.Error("http server error: %v", e) - case <-stopChan: - logger.Debug("http stop") - web.Stop() - } -} diff --git a/cmd/httpserver/service/http.go b/cmd/httpserver/service/http.go new file mode 100644 index 0000000..0fa7825 --- /dev/null +++ b/cmd/httpserver/service/http.go @@ -0,0 +1,68 @@ +package service + +import ( + "fmt" + "math/rand" + "pro2d/common" + "pro2d/common/components" + "pro2d/common/db/mongoproxy" + "pro2d/common/db/redisproxy" + "pro2d/common/etcd" + "pro2d/models" + "time" +) + +type AccountServer struct { + components.IHttp + Sconf *common.SConf +} + +func NewAccountServer(version string, port ...string) *AccountServer { + return &AccountServer{IHttp: components.NewHttpServer(version, port...)} +} + +func (s *AccountServer) Init(sconf *common.SConf) error { + s.Sconf = sconf + + //mgo init + err := mongoproxy.ConnectMongo(sconf.MongoConf, sconf.ID) + + //redis init + if err = redisproxy.ConnectRedis(sconf.RedisConf.DB, sconf.RedisConf.Auth, sconf.RedisConf.Address); err != nil { + return err + } + + //Etcd 初始化 + err = etcd.NewEtcdClient(common.GlobalConf.Etcd) + if err != nil { + return err + } + etcd.PutWithLeasePrefix(sconf.Name, fmt.Sprintf("%d", sconf.ID), fmt.Sprintf("%s:%d", sconf.IP, sconf.Port), 5) + + models.NewDBSeed(sconf.ID).InitServerDatabase(models.AccountModels()) + models.DBSeedS().InitAutoIncreUidTable(models.AccountModels()) + return nil +} + +func (s *AccountServer) TimeOut() { + models.DBSeedS().SaveAutoincrementTimer(models.AccountModels()) + + components.TimeOut(1*time.Second, s.TimeOut) +} + +func (s *AccountServer) Start() error { + if err := s.Init(common.GlobalConf.AccountConf); err != nil { + return err + } + //设置随机种子 + rand.Seed(time.Now().Unix()) + //开始定时器 + s.TimeOut() + + return s.IHttp.Start() +} + +func (s *AccountServer) Stop() { + s.IHttp.Stop() + etcd.CloseEtcd() +} diff --git a/common/commonFunc.go b/common/commonFunc.go index 511422a..5e4095f 100644 --- a/common/commonFunc.go +++ b/common/commonFunc.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/garyburd/redigo/redis" "pro2d/common/db/redisproxy" + "strconv" "strings" ) @@ -54,7 +55,7 @@ func GetNextUId() (string, error) { type IMapString map[string]interface{} -func MapToString(params map[string]interface{}) string { +func MapToString(params IMapString) string { var items bytes.Buffer for k, v := range params { items.WriteString(k) @@ -65,14 +66,22 @@ func MapToString(params map[string]interface{}) string { return items.String() } -func StringToMap(items string) map[string]interface{} { - backPack := make(map[string]interface{}) +func StringToMap(items string, num bool) IMapString { + backPack := make(map[string]interface{}, 10) for _, v := range strings.Split(items, " ") { ii := strings.Split(v, "=") if len(ii) < 2 { continue } - backPack[ii[0]] = ii[1] + if num { + c, err := strconv.Atoi(ii[1]) + if err != nil { + continue + } + backPack[ii[0]] = uint32(c) + } else { + backPack[ii[0]] = ii[1] + } } return backPack } diff --git a/common/const.go b/common/const.go index 07bd362..ee6cdb2 100644 --- a/common/const.go +++ b/common/const.go @@ -25,6 +25,9 @@ const ( //gm参数属性 Role_ = "_role" Conn_ = "_conn" + + //背包容量 + LimitCommon = 100 ) //redis keys diff --git a/go.mod b/go.mod index e1dc162..7f85650 100644 --- a/go.mod +++ b/go.mod @@ -52,11 +52,12 @@ require ( go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.17.0 // indirect - golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect - golang.org/x/net v0.0.0-20220403103023-749bd193bc2b // indirect + golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect + golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect - golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect + golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect golang.org/x/text v0.3.7 // indirect + golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect google.golang.org/grpc v1.38.0 // indirect gopkg.in/ini.v1 v1.66.4 // indirect diff --git a/go.sum b/go.sum index c8338af..ddea8ac 100644 --- a/go.sum +++ b/go.sum @@ -242,8 +242,9 @@ golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f h1:aZp0e2vLN4MToVqnjNEYEtrEA8RH8U8FN1CU7JgqsPU= golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -268,9 +269,10 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20220403103023-749bd193bc2b h1:vI32FkLJNAWtGD4BwkThwEy6XS7ZLLMHkSkYfF8M0W0= -golang.org/x/net v0.0.0-20220403103023-749bd193bc2b/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -305,8 +307,9 @@ golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -332,8 +335,9 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f h1:GGU+dLjvlC3qDwqYgL6UgRmHXhOOgns0bZu2Ty5mm6U= +golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= diff --git a/models/hero.go b/models/hero.go index ac6ea8a..9c2d313 100644 --- a/models/hero.go +++ b/models/hero.go @@ -16,7 +16,7 @@ func NewHero(hero *pb.Hero) *HeroModel { m := &HeroModel{ ISchema: NewSchema(hero.Id, hero), Hero: hero, - Equipments: common.StringToMap(hero.Equipments), + Equipments: common.StringToMap(hero.Equipments, false), } return m } diff --git a/models/role.go b/models/role.go index 759d826..57a213e 100644 --- a/models/role.go +++ b/models/role.go @@ -132,6 +132,9 @@ func (m *RoleModel) InitRole() { t4.Id = m.IncreTeamByKey(1) m.AddTeam(&t4) + //init limit + m.UpdateProperties(map[string]interface{}{"clotheslimit": 100, "weaponslimit": 100, "otherlimit": 100}, false) + m.Update() } @@ -161,7 +164,7 @@ func (m *RoleModel) LoadTeams() { //加载背包数据到内存 func (m *RoleModel) LoadItems() { - m.Items = common.StringToMap(m.Role.Items) + m.Items = common.StringToMap(m.Role.Items, true) } func (m *RoleModel) LoadEquipments() { diff --git a/models/rolePlugin.go b/models/rolePlugin.go index f3aeb64..244aba0 100644 --- a/models/rolePlugin.go +++ b/models/rolePlugin.go @@ -12,7 +12,7 @@ import ( func (m *RoleModel) GetItemCount(key string) uint32 { c, ok := m.Items[key] if !ok { - c = 0 + c = uint32(0) } return c.(uint32) } diff --git a/pb/game.pb.go b/pb/game.pb.go index 6288fa8..1a0af97 100644 --- a/pb/game.pb.go +++ b/pb/game.pb.go @@ -514,6 +514,7 @@ func (x *RoleUpdateItemsRsp) GetItems() string { return "" } +//ResponseCmd RoleClearItemsReq type RoleClearItemsReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -569,6 +570,7 @@ func (x *RoleClearItemsReq) GetCount() int32 { return 0 } +//ResponseCmd EquipmentDelReq type EquipmentDelReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/pb/models.pb.go b/pb/models.pb.go index bcdf591..767ebae 100644 --- a/pb/models.pb.go +++ b/pb/models.pb.go @@ -459,19 +459,22 @@ type Role struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" index:"unique" pri:"1"` // @inject_tag: index:"unique" pri:"1" - Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty" index:"unique"` // @inject_tag: index:"unique" - Device string `protobuf:"bytes,3,opt,name=device,proto3" json:"device,omitempty"` - Nick string `protobuf:"bytes,4,opt,name=nick,proto3" json:"nick,omitempty"` - Level int32 `protobuf:"varint,5,opt,name=level,proto3" json:"level,omitempty"` - Exp int64 `protobuf:"varint,6,opt,name=exp,proto3" json:"exp,omitempty"` - Hp int64 `protobuf:"varint,7,opt,name=hp,proto3" json:"hp,omitempty"` - HpMax int64 `protobuf:"varint,8,opt,name=hp_max,json=hpMax,proto3" json:"hp_max,omitempty"` - BuyR string `protobuf:"bytes,11,opt,name=buy_r,json=buyR,proto3" json:"buy_r,omitempty"` - PayR string `protobuf:"bytes,12,opt,name=pay_r,json=payR,proto3" json:"pay_r,omitempty"` - Del bool `protobuf:"varint,13,opt,name=del,proto3" json:"del,omitempty"` - Incres map[string]uint32 `protobuf:"bytes,14,rep,name=incres,proto3" json:"incres,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` - Items string `protobuf:"bytes,15,opt,name=items,proto3" json:"items,omitempty"` //物品 "id=count id2=count2" + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" index:"unique" pri:"1"` // @inject_tag: index:"unique" pri:"1" + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty" index:"unique"` // @inject_tag: index:"unique" + Device string `protobuf:"bytes,3,opt,name=device,proto3" json:"device,omitempty"` + Nick string `protobuf:"bytes,4,opt,name=nick,proto3" json:"nick,omitempty"` + Level int32 `protobuf:"varint,5,opt,name=level,proto3" json:"level,omitempty"` + Exp int64 `protobuf:"varint,6,opt,name=exp,proto3" json:"exp,omitempty"` + Hp int64 `protobuf:"varint,7,opt,name=hp,proto3" json:"hp,omitempty"` + HpMax int64 `protobuf:"varint,8,opt,name=hp_max,json=hpMax,proto3" json:"hp_max,omitempty"` + BuyR string `protobuf:"bytes,11,opt,name=buy_r,json=buyR,proto3" json:"buy_r,omitempty"` + PayR string `protobuf:"bytes,12,opt,name=pay_r,json=payR,proto3" json:"pay_r,omitempty"` + Del bool `protobuf:"varint,13,opt,name=del,proto3" json:"del,omitempty"` + Incres map[string]uint32 `protobuf:"bytes,14,rep,name=incres,proto3" json:"incres,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + Items string `protobuf:"bytes,15,opt,name=items,proto3" json:"items,omitempty"` //物品 "id=count id2=count2" + Clotheslimit uint32 `protobuf:"varint,16,opt,name=clotheslimit,proto3" json:"clotheslimit,omitempty"` + Weaponslimit uint32 `protobuf:"varint,17,opt,name=weaponslimit,proto3" json:"weaponslimit,omitempty"` + Otherlimit uint32 `protobuf:"varint,18,opt,name=otherlimit,proto3" json:"otherlimit,omitempty"` } func (x *Role) Reset() { @@ -597,6 +600,27 @@ func (x *Role) GetItems() string { return "" } +func (x *Role) GetClotheslimit() uint32 { + if x != nil { + return x.Clotheslimit + } + return 0 +} + +func (x *Role) GetWeaponslimit() uint32 { + if x != nil { + return x.Weaponslimit + } + return 0 +} + +func (x *Role) GetOtherlimit() uint32 { + if x != nil { + return x.Otherlimit + } + return 0 +} + var File_models_proto protoreflect.FileDescriptor var file_models_proto_rawDesc = []byte{ @@ -642,7 +666,7 @@ var file_models_proto_rawDesc = []byte{ 0x49, 0x64, 0x33, 0x22, 0x2f, 0x0a, 0x09, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x03, 0x76, 0x61, 0x6c, 0x22, 0xe2, 0x02, 0x0a, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x12, 0x0e, 0x0a, + 0x03, 0x76, 0x61, 0x6c, 0x22, 0xca, 0x03, 0x0a, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, @@ -660,12 +684,19 @@ var file_models_proto_rawDesc = []byte{ 0x18, 0x0e, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x52, 0x6f, 0x6c, 0x65, 0x2e, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x69, 0x6e, 0x63, 0x72, 0x65, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, - 0x73, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x1a, 0x39, - 0x0a, 0x0b, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, - 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, - 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x12, 0x22, + 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x74, 0x68, 0x65, 0x73, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x10, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0c, 0x63, 0x6c, 0x6f, 0x74, 0x68, 0x65, 0x73, 0x6c, 0x69, 0x6d, + 0x69, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x77, 0x65, 0x61, 0x70, 0x6f, 0x6e, 0x73, 0x6c, 0x69, 0x6d, + 0x69, 0x74, 0x18, 0x11, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0c, 0x77, 0x65, 0x61, 0x70, 0x6f, 0x6e, + 0x73, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x6c, + 0x69, 0x6d, 0x69, 0x74, 0x18, 0x12, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x6f, 0x74, 0x68, 0x65, + 0x72, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x1a, 0x39, 0x0a, 0x0b, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x73, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, + 0x01, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( -- libgit2 0.21.2