diff --git a/comm/imodule.go b/comm/imodule.go index 95b25e01f..fd437d1e9 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -26,9 +26,9 @@ type ( //查询用户背包多个物品数量 QueryItemsAmount(source *ModuleCallSource, uId string, itemid ...int32) (result map[int32]uint32) ///添加单个物品到背包 (可以加物品和减物品) - AddItem(source *ModuleCallSource, uId string, itemid, addnum int32) (code pb.ErrorCode) + AddItem(source *ModuleCallSource, uId string, itemid, addnum int32, bPush bool) (code pb.ErrorCode) ///添加多个物品到背包 (可以加物品和减物品) - AddItems(source *ModuleCallSource, uId string, items map[int32]int32) (code pb.ErrorCode) + AddItems(source *ModuleCallSource, uId string, items map[int32]int32, bPush bool) (code pb.ErrorCode) } //英雄 @@ -36,7 +36,7 @@ type ( //查询用户卡片数量 QueryHeroAmount(uId string, heroCfgId int32) (amount uint32) //创建新英雄 - CreateHero(uid string, heroCfgId ...int32) error + CreateHero(uid string, bPush bool, heroCfgId ...int32) error // 获取英雄 // heroId 英雄ID @@ -55,8 +55,8 @@ type ( GetUserSession(uid string) *pb.CacheUser //查询用户属性值 例如 金币 经验 QueryAttributeValue(uid string, attr string) (value int32) - //添加/减少属性值 - AddAttributeValue(uid string, attr string, add int32) (code pb.ErrorCode) + //添加/减少属性值 第四个参数控制是否推送给前端 + AddAttributeValue(uid string, attr string, add int32, bPush bool) (code pb.ErrorCode) } //武器模块 IEquipment interface { @@ -65,7 +65,7 @@ type ( //查询服务资源数量 参数武器配置id QueryEquipmentAmount(source *ModuleCallSource, uid string, equipmentId int32) (amount uint32) //添加新武器 - AddNewEquipments(source *ModuleCallSource, uid string, cIds map[int32]uint32) (code pb.ErrorCode) + AddNewEquipments(source *ModuleCallSource, uid string, cIds map[int32]uint32, bPush bool) (code pb.ErrorCode) } IStory interface { // 修改章节信息 diff --git a/lego/base/core.go b/lego/base/core.go index 3dc29c3d2..6a4b708f5 100644 --- a/lego/base/core.go +++ b/lego/base/core.go @@ -78,4 +78,6 @@ type IRPCXService interface { RegisterFunctionName(name string, fn interface{}) (err error) RpcCall(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) RpcGo(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (call *client.Call, err error) + AcrossClusterRpcCall(ctx context.Context, clusterTag string, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) + AcrossClusterRpcGo(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (call *client.Call, err error) } diff --git a/lego/base/rpcx/service.go b/lego/base/rpcx/service.go index 63677ed99..771fde1be 100644 --- a/lego/base/rpcx/service.go +++ b/lego/base/rpcx/service.go @@ -12,6 +12,7 @@ import ( "go_dreamfactory/lego/sys/event" "go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/rpcx" + "github.com/smallnest/rpcx/client" ) @@ -156,3 +157,25 @@ func (this *RPCXService) RpcCall(ctx context.Context, servicePath string, servic func (this *RPCXService) RpcGo(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (call *client.Call, err error) { return rpcx.Go(ctx, servicePath, serviceMethod, args, reply, nil) } + +///跨集群 同步 执行目标远程服务方法 +//clusterTag 集群标签 +///servicePath = worker 表示采用负载的方式调用 worker类型服务执行rpc方法 +///servicePath = worker/worker_1 表示寻找目标服务节点调用rpc方法 +///servicePath = worker/!worker_1 表示选择非worker_1的节点随机选择节点执行rpc方法 +///servicePath = worker/[worker_1,worker_2] 表示随机选择[]里面的服务节点执行rpc方法 +///servicePath = worker/![worker_1,worker_2] 表示随机选择非[]里面的服务节点执行rpc方法 +func (this *RPCXService) AcrossClusterRpcCall(ctx context.Context, clusterTag string, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) { + return rpcx.Call(ctx, servicePath, serviceMethod, args, reply) +} + +///跨集群 异步 执行目标远程服务方法 +//clusterTag 集群标签 +///servicePath = worker 表示采用负载的方式调用 worker类型服务执行rpc方法 +///servicePath = worker/worker_1 表示寻找目标服务节点调用rpc方法 +///servicePath = worker/!worker_1 表示选择非worker_1的节点随机选择节点执行rpc方法 +///servicePath = worker/[worker_1,worker_2] 表示随机选择[]里面的服务节点执行rpc方法 +///servicePath = worker/![worker_1,worker_2] 表示随机选择非[]里面的服务节点执行rpc方法 +func (this *RPCXService) AcrossClusterRpcGo(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (call *client.Call, err error) { + return rpcx.Go(ctx, servicePath, serviceMethod, args, reply, nil) +} diff --git a/lego/sys/redis/cluster/core.go b/lego/sys/redis/cluster/core.go index bfc85f786..ca771708e 100644 --- a/lego/sys/redis/cluster/core.go +++ b/lego/sys/redis/cluster/core.go @@ -89,3 +89,21 @@ func (this *Redis) UnLock(key string) (err error) { err = this.Delete(key) return } + +//lua Script +func (this *Redis) NewScript(src string) *redis.StringCmd { + script := redis.NewScript(src) + return script.Load(this.getContext(), this.client) +} +func (this *Redis) Eval(script string, keys []string, args ...interface{}) *redis.Cmd { + return this.client.Eval(this.getContext(), script, keys, args...) +} +func (this *Redis) EvalSha(sha1 string, keys []string, args ...interface{}) *redis.Cmd { + return this.client.EvalSha(this.getContext(), sha1, keys, args...) +} +func (this *Redis) ScriptExists(hashes ...string) *redis.BoolSliceCmd { + return this.client.ScriptExists(this.getContext(), hashes...) +} +func (this *Redis) ScriptLoad(script string) *redis.StringCmd { + return this.client.ScriptLoad(this.getContext(), script) +} diff --git a/lego/sys/redis/core.go b/lego/sys/redis/core.go index d07f5ab1c..dd4ab55a7 100644 --- a/lego/sys/redis/core.go +++ b/lego/sys/redis/core.go @@ -16,6 +16,7 @@ type ( Pipeline(ctx context.Context, fn func(pipe redis.Pipeliner) error) (err error) TxPipelined(ctx context.Context, fn func(pipe redis.Pipeliner) error) (err error) Watch(ctx context.Context, fn func(*redis.Tx) error, keys ...string) (err error) + /*Key*/ Delete(key string) (err error) ExistsKey(key string) (iskeep bool, err error) @@ -112,6 +113,12 @@ type ( ZScore(key string, member string) (result float64, err error) ZUnionStore(dest string, store *redis.ZStore) (result int64, err error) ZScan(key string, _cursor uint64, match string, count int64) (keys []string, cursor uint64, err error) + + /*Lua Script*/ + NewScript(src string) *redis.StringCmd + Eval(script string, keys []string, args ...interface{}) *redis.Cmd + EvalSha(sha1 string, keys []string, args ...interface{}) *redis.Cmd + ScriptExists(hashes ...string) *redis.BoolSliceCmd } ISys interface { @@ -445,3 +452,17 @@ func ZUnionStore(dest string, store *redis.ZStore) (result int64, err error) { func ZScan(key string, _cursor uint64, match string, count int64) (keys []string, cursor uint64, err error) { return defsys.ZScan(key, _cursor, match, count) } + +/*Lua Script*/ +func NewScript(src string) *redis.StringCmd { + return defsys.NewScript(src) +} +func Eval(script string, keys []string, args ...interface{}) *redis.Cmd { + return defsys.Eval(script, keys, args...) +} +func EvalSha(sha1 string, keys []string, args ...interface{}) *redis.Cmd { + return defsys.Eval(sha1, keys, args...) +} +func ScriptExists(hashes ...string) *redis.BoolSliceCmd { + return defsys.ScriptExists(hashes...) +} diff --git a/lego/sys/redis/redis.go b/lego/sys/redis/redis.go index 5ac350bbb..98fdacad0 100644 --- a/lego/sys/redis/redis.go +++ b/lego/sys/redis/redis.go @@ -45,7 +45,6 @@ func (this *Redis) init() (err error) { } return } - func (this *Redis) Close() (err error) { return this.client.Close() } @@ -67,15 +66,12 @@ func (this *Redis) Lock(key string, outTime int) (result bool, err error) { func (this *Redis) UnLock(key string) (err error) { return this.client.UnLock(key) } - func (this *Redis) Delete(key string) (err error) { return this.client.Delete(key) } - func (this *Redis) ExistsKey(key string) (iskeep bool, err error) { return this.client.ExistsKey(key) } - func (this *Redis) Expire(key string, expire time.Duration) (err error) { return this.client.Expire(key, expire) } @@ -106,8 +102,6 @@ func (this *Redis) RenameNX(oldkey string, newkey string) (err error) { func (this *Redis) Keys(pattern string) (keys []string, err error) { return this.client.Keys(pattern) } - -///获取键类型 func (this *Redis) Type(key string) (ty string, err error) { return this.client.Type(key) } @@ -355,6 +349,20 @@ func (this *Redis) ZScan(key string, _cursor uint64, match string, count int64) return this.client.ZScan(key, _cursor, match, count) } +//lua Script +func (this *Redis) NewScript(src string) *redis.StringCmd { + return this.client.NewScript(src) +} +func (this *Redis) Eval(script string, keys []string, args ...interface{}) *redis.Cmd { + return this.client.Eval(script, keys, args...) +} +func (this *Redis) EvalSha(sha1 string, keys []string, args ...interface{}) *redis.Cmd { + return this.client.EvalSha(sha1, keys, args...) +} +func (this *Redis) ScriptExists(hashes ...string) *redis.BoolSliceCmd { + return this.client.ScriptExists(hashes...) +} + //Codec--------------------------------------------------------------------------------------------------------------------------------------- func (this *Redis) Marshal(v interface{}) ([]byte, error) { if this.options.Codec != nil { diff --git a/lego/sys/redis/single/core.go b/lego/sys/redis/single/core.go index 58dd8c807..32944d43b 100644 --- a/lego/sys/redis/single/core.go +++ b/lego/sys/redis/single/core.go @@ -88,3 +88,21 @@ func (this *Redis) UnLock(key string) (err error) { err = this.Delete(key) return } + +//lua Script +func (this *Redis) NewScript(src string) *redis.StringCmd { + script := redis.NewScript(src) + return script.Load(this.getContext(), this.client) +} +func (this *Redis) Eval(script string, keys []string, args ...interface{}) *redis.Cmd { + return this.client.Eval(this.getContext(), script, keys, args...) +} +func (this *Redis) EvalSha(sha1 string, keys []string, args ...interface{}) *redis.Cmd { + return this.client.EvalSha(this.getContext(), sha1, keys, args...) +} +func (this *Redis) ScriptExists(hashes ...string) *redis.BoolSliceCmd { + return this.client.ScriptExists(this.getContext(), hashes...) +} +func (this *Redis) ScriptLoad(script string) *redis.StringCmd { + return this.client.ScriptLoad(this.getContext(), script) +} diff --git a/lego/sys/redis/sys_test.go b/lego/sys/redis/sys_test.go index 522ca0f87..aa1c08ae3 100644 --- a/lego/sys/redis/sys_test.go +++ b/lego/sys/redis/sys_test.go @@ -3,6 +3,7 @@ package redis_test import ( "encoding/json" "fmt" + "log" "os" "sync" "testing" @@ -181,25 +182,56 @@ func Test_Redis_Encoder_int(t *testing.T) { } func Test_Redis_Encoder_Hash(t *testing.T) { - // err := redis.HMSet("test:1005", &TestData{Name: "liwei1dao", Agr: 12, Sub: &TestAny{SubName: "test", Age: 20}}) - // fmt.Printf("err:%v\n", err) - - // data := &TestData{} - // err = redis.HGetAll("test:1005", data) - // fmt.Printf("data:%v err:%v\n", data, err) - - // redis.HSet("test:1003", "Name", "eeee") name := "" err := redis.HGet("test:103", "name", &name) if err != nil { fmt.Println(err) } fmt.Println(name) - - // data1 := map[string]*TestData{"li_1": {Name: "liwei2dao", Agr: 56}, "li_2": {Name: "liwei3dao", Agr: 78}} - // err := redis.HMSet("test:1004", data1) - // fmt.Printf("err:%v\n", err) - // data2 := make(map[string]*TestData) - // err = redis.HGetAll("test:1004", data2) - // fmt.Printf("data2:%v err:%v\n", data2, err) +} + +//测试redis lua 脚本 +func Test_Redis_Lua(t *testing.T) { + script := redis.NewScript(` + local goodsSurplus + local flag + local existUserIds = tostring(KEYS[1]) + local memberUid = tonumber(ARGV[1]) + local goodsSurplusKey = tostring(KEYS[2]) + local hasBuy = redis.call("sIsMember", existUserIds, memberUid) + + if hasBuy ~= 0 then + return 0 + end + + + goodsSurplus = redis.call("GET", goodsSurplusKey) + if goodsSurplus == false then + return 0 + end + + -- 没有剩余可抢购物品 + goodsSurplus = tonumber(goodsSurplus) + if goodsSurplus <= 0 then + return 0 + end + + flag = redis.call("SADD", existUserIds, memberUid) + flag = redis.call("DECR", goodsSurplusKey) + return 1 + `) + sha, err := script.Result() + if err != nil { + log.Fatalln(err) + } + ret := redis.EvalSha(sha, []string{ + "hadBuyUids", + "goodsSurplus", + }, "userId") + if result, err := ret.Result(); err != nil { + log.Fatalf("Execute Redis fail: %v", err.Error()) + } else { + fmt.Println("") + fmt.Printf("userid: %s, result: %d", "userId", result) + } } diff --git a/lego/sys/rpcx/client.go b/lego/sys/rpcx/client.go index 64c337669..f67c99b08 100644 --- a/lego/sys/rpcx/client.go +++ b/lego/sys/rpcx/client.go @@ -18,32 +18,34 @@ import ( "github.com/smallnest/rpcx/share" ) -func newClient(options Options) (sys *Client, err error) { +func newClient(options *Options) (sys *Client, err error) { sys = &Client{ - options: options, - metadata: fmt.Sprintf("stype=%s&sid=%s&version=%s&addr=%s", options.ServiceType, options.ServiceId, options.ServiceVersion, "tcp@"+options.ServiceAddr), - clients: make(map[string]client.XClient), - conns: make(map[string]net.Conn), - connecting: make(map[string]struct{}), - serviceMap: make(map[string]*service), - msgChan: make(chan *protocol.Message, 1000), + options: options, + metadata: fmt.Sprintf("stag=%s&stype=%s&sid=%s&version=%s&addr=%s", options.ServiceTag, options.ServiceType, options.ServiceId, options.ServiceVersion, "tcp@"+options.ServiceAddr), + clients: make(map[string]client.XClient), + otherClusterClients: make(map[string]map[string]client.XClient), + conns: make(map[string]net.Conn), + connecting: make(map[string]struct{}), + serviceMap: make(map[string]*service), + msgChan: make(chan *protocol.Message, 1000), } return } type Client struct { - options Options - metadata string - writeTimeout time.Duration - AsyncWrite bool - clients map[string]client.XClient - connsMapMu sync.RWMutex - conns map[string]net.Conn - connectMapMu sync.RWMutex - connecting map[string]struct{} - serviceMapMu sync.RWMutex - serviceMap map[string]*service - msgChan chan *protocol.Message // 接收rpcXServer推送消息 + options *Options + metadata string + writeTimeout time.Duration + AsyncWrite bool + clients map[string]client.XClient + otherClusterClients map[string]map[string]client.XClient //其他集群客户端 + connsMapMu sync.RWMutex + conns map[string]net.Conn + connectMapMu sync.RWMutex + connecting map[string]struct{} + serviceMapMu sync.RWMutex + serviceMap map[string]*service + msgChan chan *protocol.Message // 接收rpcXServer推送消息 } // DoMessage 服务端消息处理 @@ -132,9 +134,10 @@ func (this *Client) Call(ctx context.Context, servicePath string, serviceMethod this.clients[spath[0]] = c } ctx = context.WithValue(ctx, share.ReqMetaDataKey, map[string]string{ - CallRoutRulesKey: servicePath, - ServiceAddrKey: "tcp@" + this.options.ServiceAddr, - ServiceMetaKey: this.metadata, + ServiceClusterTag: this.options.ServiceTag, + CallRoutRulesKey: servicePath, + ServiceAddrKey: "tcp@" + this.options.ServiceAddr, + ServiceMetaKey: this.metadata, }) err = c.Call(ctx, serviceMethod, args, reply) return @@ -164,9 +167,93 @@ func (this *Client) Go(ctx context.Context, servicePath string, serviceMethod st this.clients[spath[0]] = c } ctx = context.WithValue(ctx, share.ReqMetaDataKey, map[string]string{ - CallRoutRulesKey: servicePath, - ServiceAddrKey: "tcp@" + this.options.ServiceAddr, - ServiceMetaKey: this.metadata, + ServiceClusterTag: this.options.ServiceTag, + CallRoutRulesKey: servicePath, + ServiceAddrKey: "tcp@" + this.options.ServiceAddr, + ServiceMetaKey: this.metadata, + }) + return c.Go(ctx, string(serviceMethod), args, reply, done) +} + +//跨集群 同步调用 +func (this *Client) AcrossClusterCall(ctx context.Context, clusterTag string, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) { + if servicePath == "" { + err = errors.New("servicePath no cant null") + return + } + var ( + spath []string + clients map[string]client.XClient + d *client.ConsulDiscovery + c client.XClient + ok bool + ) + spath = strings.Split(servicePath, "/") + if clients, ok = this.otherClusterClients[clusterTag]; !ok { + this.otherClusterClients[clusterTag] = make(map[string]client.XClient) + clients = this.otherClusterClients[clusterTag] + } else { + if c, ok = clients[spath[0]]; !ok { + if d, err = client.NewConsulDiscovery(clusterTag, spath[0], this.options.ConsulServers, nil); err != nil { + return + } + c = client.NewBidirectionalXClient(spath[0], client.Failfast, client.RandomSelect, d, client.DefaultOption, this.msgChan) + c.GetPlugins().Add(this) + if this.options.RpcxStartType == RpcxStartByClient && this.options.AutoConnect { + c.SetSelector(newSelector(this.UpdateServer)) + } else { + c.SetSelector(newSelector(nil)) + } + clients[spath[0]] = c + } + } + ctx = context.WithValue(ctx, share.ReqMetaDataKey, map[string]string{ + ServiceClusterTag: clusterTag, + CallRoutRulesKey: servicePath, + ServiceAddrKey: "tcp@" + this.options.ServiceAddr, + ServiceMetaKey: this.metadata, + }) + err = c.Call(ctx, serviceMethod, args, reply) + return +} + +//跨集群 异步调用 +func (this *Client) AcrossClusterGo(ctx context.Context, clusterTag string, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (call *client.Call, err error) { + if servicePath == "" { + err = errors.New("servicePath no cant null") + return + } + var ( + spath []string + clients map[string]client.XClient + d *client.ConsulDiscovery + c client.XClient + ok bool + ) + spath = strings.Split(servicePath, "/") + if clients, ok = this.otherClusterClients[clusterTag]; !ok { + this.otherClusterClients[clusterTag] = make(map[string]client.XClient) + clients = this.otherClusterClients[clusterTag] + } else { + if c, ok = clients[spath[0]]; !ok { + if d, err = client.NewConsulDiscovery(clusterTag, spath[0], this.options.ConsulServers, nil); err != nil { + return + } + c = client.NewBidirectionalXClient(spath[0], client.Failfast, client.RandomSelect, d, client.DefaultOption, this.msgChan) + c.GetPlugins().Add(this) + if this.options.RpcxStartType == RpcxStartByClient && this.options.AutoConnect { + c.SetSelector(newSelector(this.UpdateServer)) + } else { + c.SetSelector(newSelector(nil)) + } + clients[spath[0]] = c + } + } + ctx = context.WithValue(ctx, share.ReqMetaDataKey, map[string]string{ + ServiceClusterTag: this.options.ServiceTag, + CallRoutRulesKey: servicePath, + ServiceAddrKey: "tcp@" + this.options.ServiceAddr, + ServiceMetaKey: this.metadata, }) return c.Go(ctx, string(serviceMethod), args, reply, done) } diff --git a/lego/sys/rpcx/core.go b/lego/sys/rpcx/core.go index 848247357..b76d68227 100644 --- a/lego/sys/rpcx/core.go +++ b/lego/sys/rpcx/core.go @@ -10,9 +10,10 @@ import ( ) const ( - ServiceMetaKey = "smeta" - ServiceAddrKey = "addr" - CallRoutRulesKey = "callrules" + ServiceClusterTag = "ctag" + ServiceMetaKey = "smeta" + ServiceAddrKey = "addr" + CallRoutRulesKey = "callrules" ) const RpcX_ShakeHands = "RpcX_ShakeHands" //握手 @@ -26,6 +27,8 @@ type ( UnregisterAll() (err error) Call(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) Go(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (call *client.Call, err error) + AcrossClusterCall(ctx context.Context, clusterTag string, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) + AcrossClusterGo(ctx context.Context, clusterTag string, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (call *client.Call, err error) } ) @@ -33,18 +36,18 @@ var ( defsys ISys ) -func OnInit(config map[string]interface{}, option ...Option) (err error) { - var options Options - if options, err = newOptions(config, option...); err != nil { +func OnInit(config map[string]interface{}, opt ...Option) (err error) { + var options *Options + if options, err = newOptions(config, opt...); err != nil { return } defsys, err = newSys(options) return } -func NewSys(option ...Option) (sys ISys, err error) { - var options Options - if options, err = newOptionsByOption(option...); err != nil { +func NewSys(opt ...Option) (sys ISys, err error) { + var options *Options + if options, err = newOptionsByOption(opt...); err != nil { return } sys, err = newSys(options) @@ -92,6 +95,12 @@ func smetaToServiceNode(meta string) (node *ServiceNode, err error) { data[k] = v[0] } } + if stag, ok := data["stag"]; !ok { + err = fmt.Errorf("no found stag") + return + } else { + node.ServiceTag = stag + } if sid, ok := data["sid"]; !ok { err = fmt.Errorf("no found sid") return diff --git a/lego/sys/rpcx/options.go b/lego/sys/rpcx/options.go index c5cbae3d2..486a730c8 100644 --- a/lego/sys/rpcx/options.go +++ b/lego/sys/rpcx/options.go @@ -85,37 +85,45 @@ func SetLog(v log.ILog) Option { } } -func newOptions(config map[string]interface{}, opts ...Option) (Options, error) { - options := Options{ +func newOptions(config map[string]interface{}, opts ...Option) (options *Options, err error) { + options = &Options{ AutoConnect: true, SerializeType: protocol.MsgPack, - Debug: true, - Log: log.Clone(log.SetLoglayer(2)), } if config != nil { - mapstructure.Decode(config, &options) + mapstructure.Decode(config, options) } for _, o := range opts { - o(&options) + o(options) } if len(options.ServiceTag) == 0 || len(options.ServiceType) == 0 || len(options.ServiceId) == 0 || len(options.ConsulServers) == 0 { return options, errors.New("[Sys.RPCX] newOptions err: 启动参数异常") } + if options.Debug && options.Log == nil { + if options.Log = log.Clone(log.SetLoglayer(2)); options.Log == nil { + err = errors.New("log is nil") + } + } return options, nil } -func newOptionsByOption(opts ...Option) (Options, error) { - options := Options{ +func newOptionsByOption(opts ...Option) (options *Options, err error) { + options = &Options{ AutoConnect: true, SerializeType: protocol.MsgPack, Debug: true, Log: log.Clone(log.SetLoglayer(2)), } for _, o := range opts { - o(&options) + o(options) } if len(options.ServiceTag) == 0 || len(options.ServiceType) == 0 || len(options.ServiceId) == 0 || len(options.ConsulServers) == 0 { return options, errors.New("[Sys.RPCX] newOptions err: 启动参数异常") } + if options.Debug && options.Log == nil { + if options.Log = log.Clone(log.SetLoglayer(2)); options.Log == nil { + err = errors.New("log is nil") + } + } return options, nil } diff --git a/lego/sys/rpcx/rpcx.go b/lego/sys/rpcx/rpcx.go index 364189803..ba6e9a641 100644 --- a/lego/sys/rpcx/rpcx.go +++ b/lego/sys/rpcx/rpcx.go @@ -6,7 +6,7 @@ import ( "github.com/smallnest/rpcx/client" ) -func newSys(options Options) (sys ISys, err error) { +func newSys(options *Options) (sys ISys, err error) { if options.RpcxStartType == RpcxStartByService { //创建RPCX 服务端 sys, err = newService(options) return @@ -69,3 +69,13 @@ func (this *RPCX) Call(ctx context.Context, servicePath string, serviceMethod st func (this *RPCX) Go(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (call *client.Call, err error) { return this.client.Go(ctx, servicePath, serviceMethod, args, reply, done) } + +//跨服同步调用 +func (this *RPCX) AcrossClusterCall(ctx context.Context, clusterTag string, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) { + return this.client.AcrossClusterCall(ctx, clusterTag, servicePath, serviceMethod, args, reply) +} + +//跨服异步调用 +func (this *RPCX) AcrossClusterGo(ctx context.Context, clusterTag string, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (call *client.Call, err error) { + return this.client.AcrossClusterGo(ctx, clusterTag, servicePath, serviceMethod, args, reply, done) +} diff --git a/lego/sys/rpcx/selector.go b/lego/sys/rpcx/selector.go index abc89600c..bc00870c8 100644 --- a/lego/sys/rpcx/selector.go +++ b/lego/sys/rpcx/selector.go @@ -24,6 +24,7 @@ func newSelector(fn func(map[string]*ServiceNode)) *Selector { } type ServiceNode struct { + ServiceTag string `json:"stag"` //服务集群标签 ServiceId string `json:"sid"` //服务id ServiceType string `json:"stype"` //服务类型 Version string `json:"version"` //服务版本 diff --git a/lego/sys/rpcx/service.go b/lego/sys/rpcx/service.go index b8ee128d3..17da4c096 100644 --- a/lego/sys/rpcx/service.go +++ b/lego/sys/rpcx/service.go @@ -18,12 +18,12 @@ import ( "github.com/smallnest/rpcx/share" ) -func newService(options Options) (sys *Service, err error) { +func newService(options *Options) (sys *Service, err error) { sys = &Service{ options: options, - metadata: fmt.Sprintf("stype=%s&sid=%s&version=%s&addr=%s", options.ServiceType, options.ServiceId, options.ServiceVersion, "tcp@"+options.ServiceAddr), + metadata: fmt.Sprintf("stag=%s&stype=%s&sid=%s&version=%s&addr=%s", options.ServiceTag, options.ServiceType, options.ServiceId, options.ServiceVersion, "tcp@"+options.ServiceAddr), server: server.NewServer(), - selector: newSelector(nil), + selectors: make(map[string]client.Selector), clients: make(map[string]net.Conn), clientmeta: make(map[string]string), pending: make(map[uint64]*client.Call), @@ -46,10 +46,10 @@ func newService(options Options) (sys *Service, err error) { } type Service struct { - options Options + options *Options metadata string server *server.Server - selector client.Selector + selectors map[string]client.Selector clientmutex sync.Mutex clients map[string]net.Conn clientmeta map[string]string @@ -100,7 +100,7 @@ func (this *Service) Call(ctx context.Context, servicePath string, serviceMethod ) seq := new(uint64) ctx = context.WithValue(ctx, seqKey{}, seq) - if conn, done, err = this.call(ctx, servicePath, serviceMethod, args, reply, make(chan *client.Call, 1)); err != nil { + if conn, done, err = this.call(ctx, this.options.ServiceTag, servicePath, serviceMethod, args, reply, make(chan *client.Call, 1)); err != nil { return } select { @@ -130,26 +130,79 @@ func (this *Service) Call(ctx context.Context, servicePath string, serviceMethod //异步调用 远程服务 func (this *Service) Go(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (_call *client.Call, err error) { - _, _call, err = this.call(ctx, servicePath, serviceMethod, args, reply, done) + _, _call, err = this.call(ctx, this.options.ServiceTag, servicePath, serviceMethod, args, reply, done) + return +} + +//跨服 同步调用 远程服务 +func (this *Service) AcrossClusterCall(ctx context.Context, clusterTag string, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) { + var ( + done *client.Call + conn net.Conn + ) + seq := new(uint64) + ctx = context.WithValue(ctx, seqKey{}, seq) + if conn, done, err = this.call(ctx, clusterTag, servicePath, serviceMethod, args, reply, make(chan *client.Call, 1)); err != nil { + return + } + select { + case <-ctx.Done(): // cancel by context + this.mutex.Lock() + call := this.pending[*seq] + delete(this.pending, *seq) + this.mutex.Unlock() + if call != nil { + call.Error = ctx.Err() + call.Done <- call + } + return ctx.Err() + case call := <-done.Done: + err = call.Error + meta := ctx.Value(share.ResMetaDataKey) + if meta != nil && len(call.ResMetadata) > 0 { + resMeta := meta.(map[string]string) + for k, v := range call.ResMetadata { + resMeta[k] = v + } + resMeta[share.ServerAddress] = conn.RemoteAddr().String() + } + } + return +} + +//跨服 异步调用 远程服务 +func (this *Service) AcrossClusterGo(ctx context.Context, clusterTag, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (_call *client.Call, err error) { + _, _call, err = this.call(ctx, clusterTag, servicePath, serviceMethod, args, reply, done) return } //监听客户端链接到服务上 保存客户端的连接对象 func (this *Service) PreHandleRequest(ctx context.Context, r *protocol.Message) error { + var ( + stag string + selector client.Selector + ok bool + ) req_metadata := ctx.Value(share.ReqMetaDataKey).(map[string]string) - if addr, ok := req_metadata[ServiceAddrKey]; ok { - if _, ok = this.clientmeta[addr]; !ok { - if smeta, ok := req_metadata[ServiceMetaKey]; ok { - servers := make(map[string]string) - this.clientmutex.Lock() - this.clientmeta[addr] = smeta - this.clients[addr] = ctx.Value(server.RemoteConnContextKey).(net.Conn) - for k, v := range this.clientmeta { - servers[k] = v + if stag, ok = req_metadata[ServiceClusterTag]; ok { + if selector, ok = this.selectors[stag]; !ok { + this.selectors[stag] = newSelector(nil) + selector = this.selectors[stag] + } + if addr, ok := req_metadata[ServiceAddrKey]; ok { + if _, ok = this.clientmeta[addr]; !ok { + if smeta, ok := req_metadata[ServiceMetaKey]; ok { + servers := make(map[string]string) + this.clientmutex.Lock() + this.clientmeta[addr] = smeta + this.clients[addr] = ctx.Value(server.RemoteConnContextKey).(net.Conn) + for k, v := range this.clientmeta { + servers[k] = v + } + this.clientmutex.Unlock() + selector.UpdateServer(servers) + this.Debugf("fond new node addr:%s smeta:%s \n", addr, smeta) } - this.clientmutex.Unlock() - this.selector.UpdateServer(servers) - this.Debugf("fond new node addr:%s smeta:%s \n", addr, smeta) } } } @@ -247,11 +300,12 @@ func (this *Service) Fatalf(format string, a ...interface{}) { } //执行远程调用 -func (this *Service) call(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (conn net.Conn, _call *client.Call, err error) { +func (this *Service) call(ctx context.Context, clusterTag string, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (conn net.Conn, _call *client.Call, err error) { var ( spath []string clientaddr string metadata map[string]string + selector client.Selector ok bool ) if servicePath == "" { @@ -259,9 +313,10 @@ func (this *Service) call(ctx context.Context, servicePath string, serviceMethod return } metadata = map[string]string{ - CallRoutRulesKey: servicePath, - ServiceAddrKey: "tcp@" + this.options.ServiceAddr, - ServiceMetaKey: this.metadata, + ServiceClusterTag: clusterTag, + CallRoutRulesKey: servicePath, + ServiceAddrKey: "tcp@" + this.options.ServiceAddr, + ServiceMetaKey: this.metadata, } spath = strings.Split(servicePath, "/") ctx = context.WithValue(ctx, share.ReqMetaDataKey, map[string]string{ @@ -269,7 +324,10 @@ func (this *Service) call(ctx context.Context, servicePath string, serviceMethod ServiceAddrKey: "tcp@" + this.options.ServiceAddr, ServiceMetaKey: this.metadata, }) - if clientaddr = this.selector.Select(ctx, spath[0], serviceMethod, args); clientaddr == "" { + if selector, ok = this.selectors[clusterTag]; !ok { + err = fmt.Errorf("on found serviceTag:%s", clusterTag) + } + if clientaddr = selector.Select(ctx, spath[0], serviceMethod, args); clientaddr == "" { err = fmt.Errorf("on found servicePath:%s", servicePath) return } diff --git a/modules/equipment/api_upgrade.go b/modules/equipment/api_upgrade.go index bfba8cfd3..e29a2900f 100644 --- a/modules/equipment/api_upgrade.go +++ b/modules/equipment/api_upgrade.go @@ -71,7 +71,7 @@ func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.EquipmentUpgrade } } if issucc { - if code = this.module.CheckConsumeRes(session.GetUserId(), intensify.Need); code != pb.ErrorCode_Success { + if code = this.module.CheckConsumeRes(session.GetUserId(), intensify.Need, true); code != pb.ErrorCode_Success { return } modifyequipments = make([]*pb.DB_Equipment, 0) diff --git a/modules/equipment/model_equipment.go b/modules/equipment/modelEquipment.go similarity index 96% rename from modules/equipment/model_equipment.go rename to modules/equipment/modelEquipment.go index f19c0df18..ee66605bc 100644 --- a/modules/equipment/model_equipment.go +++ b/modules/equipment/modelEquipment.go @@ -65,7 +65,7 @@ func (this *modelEquipmentComp) QueryEquipmentAmount(uid string, equipmentId int } //添加装备 -func (this *modelEquipmentComp) AddEquipments(uId string, cIds map[int32]uint32) (err error) { +func (this *modelEquipmentComp) AddEquipments(uId string, cIds map[int32]uint32) (change []*pb.DB_Equipment, err error) { var ( configure *cfg.Game_equip equipments []*pb.DB_Equipment @@ -81,11 +81,13 @@ func (this *modelEquipmentComp) AddEquipments(uId string, cIds map[int32]uint32) } add = make(map[string]*pb.DB_Equipment) update = make(map[string]*pb.DB_Equipment) + change = make([]*pb.DB_Equipment, len(equipments)) for k, v := range cIds { iskeep = false for _, equipment := range equipments { if equipment.CId == k && equipment.IsInitialState { update[equipment.Id] = equipment + change = append(change, equipment) equipment.OverlayNum += v iskeep = true break @@ -94,9 +96,10 @@ func (this *modelEquipmentComp) AddEquipments(uId string, cIds map[int32]uint32) if !iskeep { if c, ok := configure.GetDataMap()[k]; ok { if equipment, err := this.newEquipment(uId, c, v); err != nil { - return err + return nil, err } else { add[equipment.Id] = equipment + change = append(change, equipment) } } } diff --git a/modules/equipment/module.go b/modules/equipment/module.go index 178335538..656f02fc4 100644 --- a/modules/equipment/module.go +++ b/modules/equipment/module.go @@ -80,11 +80,28 @@ func (this *Equipment) QueryEquipmentAmount(source *comm.ModuleCallSource, uid s } //添加武器 -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 { +func (this *Equipment) AddNewEquipments(source *comm.ModuleCallSource, uid string, cIds map[int32]uint32, bPush bool) (code pb.ErrorCode) { + var ( + err error + change []*pb.DB_Equipment + ) + if change, err = this.modelEquipment.AddEquipments(uid, cIds); err != nil { log.Errorf("err%v", err) code = pb.ErrorCode_SystemError + return + } + if len(change) > 0 && bPush { + this.equipmentsChangePush(uid, change) + } + return +} + +//Evens-------------------------------------------------------------------------------------------------------------------------------- +//推送道具变化消息 +func (this *Equipment) equipmentsChangePush(uid string, items []*pb.DB_Equipment) (err error) { + if session, ok := this.GetUserSession(uid); ok { + session.SendMsg(string(this.GetType()), "change", &pb.EquipmentChangePush{Equipments: items}) + err = session.Push() } return } diff --git a/modules/equipment/module_test.go b/modules/equipment/module_test.go index 751748d67..cf7d61e87 100644 --- a/modules/equipment/module_test.go +++ b/modules/equipment/module_test.go @@ -102,7 +102,7 @@ func Test_Module_AddNewEquipments(t *testing.T) { Module: "Test", FuncName: "Test_Module", Describe: "摸底测试", - }, "0_62b16dda909b2f8faeff788d", map[int32]uint32{10001: 1}) + }, "0_62b16dda909b2f8faeff788d", map[int32]uint32{10001: 1}, true) log.Debugf("Test_Module Code:%d", code) } diff --git a/modules/gateway/agent.go b/modules/gateway/agent.go index b4b28b990..28c69986d 100644 --- a/modules/gateway/agent.go +++ b/modules/gateway/agent.go @@ -7,6 +7,7 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/utils" + "strings" "sync" "sync/atomic" "time" @@ -64,13 +65,13 @@ func (this *Agent) readLoop() { locp: for { if _, data, err = this.wsConn.ReadMessage(); err != nil { - log.Errorf("agent:%s uId:%s ReadMessage err:%v", this.sessionId, this.uId, err) + this.gateway.Errorf("agent:%s uId:%s ReadMessage err:%v", this.sessionId, this.uId, err) go this.Close() break locp } if err = proto.Unmarshal(data, msg); err != nil { - log.Errorf("agent:%s uId:%s Unmarshal err:%v", this.sessionId, this.uId, err) + this.gateway.Errorf("agent:%s uId:%s Unmarshal err:%v", this.sessionId, this.uId, err) go this.Close() break locp } else { @@ -93,7 +94,7 @@ locp: } } } - log.Debugf("agent:%s uId:%s readLoop end!", this.sessionId, this.uId) + this.gateway.Debugf("agent:%s uId:%s readLoop end!", this.sessionId, this.uId) } func (this *Agent) writeLoop() { @@ -111,7 +112,7 @@ locp: if ok { data, err = proto.Marshal(msg) if err = this.wsConn.WriteMessage(websocket.BinaryMessage, data); err != nil { - log.Errorf("agent:%s uId:%d WriteMessage err:%v", this.sessionId, this.uId, err) + this.gateway.Errorf("agent:%s uId:%d WriteMessage err:%v", this.sessionId, this.uId, err) go this.Close() } } else { @@ -119,7 +120,7 @@ locp: } } } - log.Debugf("agent:%s uId:%s writeLoop end!", this.sessionId, this.uId) + this.gateway.Debugf("agent:%s uId:%s writeLoop end!", this.sessionId, this.uId) } //安全认证 所有协议 @@ -213,28 +214,58 @@ func (this *Agent) Close() { //分发用户消息 func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) { - reply := &pb.RPCMessageReply{} - log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType) + var ( + reply *pb.RPCMessageReply = &pb.RPCMessageReply{} + serviceTag string = "" + servicePath string = comm.Service_Worker + rule string + ok bool + ) - servicePath := comm.Service_Worker - if rule, ok := this.gateway.GetMsgDistribute(msg.MainType, msg.SubType); ok { - servicePath = rule + this.gateway.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType) + if rule, ok = this.gateway.GetMsgDistribute(msg.MainType, msg.SubType); ok { + paths := strings.Split(rule, "/") + if len(paths) == 3 { + serviceTag = paths[0] + servicePath = fmt.Sprintf("%s/%s", paths[1], paths[2]) + } else if len(paths) < 3 && len(paths) > 0 { + servicePath = rule + } else { + this.gateway.Errorf("messageDistribution rule is empty!") + return + } } else { - if len(this.wId) > 0 { + if len(this.wId) > 0 { //已经绑定worker 服务器 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{ - Ip: this.IP(), - UserSessionId: this.sessionId, - UserId: this.uId, - GatewayServiceId: this.gateway.Service().GetId(), - MainType: msg.MainType, - SubType: msg.SubType, - Message: msg.Data, - }, reply); err != nil { - log.Errorf("agent:%s uId:%s MessageDistribution err:%v", this.sessionId, this.uId, err) - return + + if len(serviceTag) == 0 { + if err = this.gateway.Service().RpcCall(context.Background(), servicePath, string(comm.Rpc_GatewayRoute), &pb.AgentMessage{ + Ip: this.IP(), + UserSessionId: this.sessionId, + UserId: this.uId, + GatewayServiceId: this.gateway.Service().GetId(), + MainType: msg.MainType, + SubType: msg.SubType, + Message: msg.Data, + }, reply); err != nil { + this.gateway.Errorf("agent:%s uId:%s MessageDistribution err:%v", this.sessionId, this.uId, err) + return + } + } else { //跨集群调用 + if err = this.gateway.Service().AcrossClusterRpcCall(context.Background(), serviceTag, servicePath, string(comm.Rpc_GatewayRoute), &pb.AgentMessage{ + Ip: this.IP(), + UserSessionId: this.sessionId, + UserId: this.uId, + GatewayServiceId: this.gateway.Service().GetId(), + MainType: msg.MainType, + SubType: msg.SubType, + Message: msg.Data, + }, reply); err != nil { + this.gateway.Errorf("agent:%s uId:%s MessageDistribution err:%v", this.sessionId, this.uId, err) + return + } } if reply.Code != pb.ErrorCode_Success { diff --git a/modules/gateway/core.go b/modules/gateway/core.go index 7fd4749a6..3605f84dd 100644 --- a/modules/gateway/core.go +++ b/modules/gateway/core.go @@ -5,6 +5,7 @@ import ( "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" ) type ( @@ -22,6 +23,7 @@ type ( // IGateway 网关模块 接口定义 IGateway interface { core.IModule + log.Ilogf Service() base.IRPCXService Connect(a IAgent) DisConnect(a IAgent) diff --git a/modules/gateway/module.go b/modules/gateway/module.go index 7e7019342..634689e6c 100644 --- a/modules/gateway/module.go +++ b/modules/gateway/module.go @@ -1,6 +1,7 @@ package gateway import ( + "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/base" @@ -22,6 +23,7 @@ func NewModule() core.IModule { type Gateway struct { cbase.ModuleBase + options *Options service base.IRPCXService // rpcx服务接口 主要client->server wsService *WSServiceComp // websocket服务 监听websocket连接 agentMgr *AgentMgrComp // 客户端websocket连接管理 @@ -46,6 +48,7 @@ func (this *Gateway) Service() base.IRPCXService { // Init 模块初始化函数 func (this *Gateway) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) + this.options = options.(*Options) this.service = service.(base.IRPCXService) return } @@ -98,3 +101,35 @@ func (this *Gateway) DisConnect(a IAgent) { func (this *Gateway) GetMsgDistribute(mtype, stype string) (rule string, ok bool) { return this.configure.GetMsgDistribute(mtype, stype) } + +//日志 +func (this *Gateway) Debugf(format string, a ...interface{}) { + if this.options.GetDebug() { + this.options.GetLog().Debugf(fmt.Sprintf("[Module:%s] ", this.GetType())+format, a...) + } +} +func (this *Gateway) Infof(format string, a ...interface{}) { + if this.options.GetDebug() { + this.options.GetLog().Infof(fmt.Sprintf("[Module:%s] ", this.GetType())+format, a...) + } +} +func (this *Gateway) Warnf(format string, a ...interface{}) { + if this.options.Debug { + this.options.GetLog().Warnf(fmt.Sprintf("[Module:%s] ", this.GetType())+format, a...) + } +} +func (this *Gateway) Errorf(format string, a ...interface{}) { + if this.options.GetLog() != nil { + this.options.GetLog().Errorf(fmt.Sprintf("[Module:%s] ", this.GetType())+format, a...) + } +} +func (this *Gateway) Panicf(format string, a ...interface{}) { + if this.options.GetLog() != nil { + this.options.GetLog().Panicf(fmt.Sprintf("[Module:%s] ", this.GetType())+format, a...) + } +} +func (this *Gateway) Fatalf(format string, a ...interface{}) { + if this.options.GetLog() != nil { + this.options.GetLog().Fatalf(fmt.Sprintf("[Module:%s] ", this.GetType())+format, a...) + } +} diff --git a/modules/gateway/options.go b/modules/gateway/options.go index 12075275f..6fb187a13 100644 --- a/modules/gateway/options.go +++ b/modules/gateway/options.go @@ -2,6 +2,7 @@ package gateway import ( "go_dreamfactory/lego/utils/mapstructure" + "go_dreamfactory/modules" ) /* @@ -10,7 +11,7 @@ import ( type ( Options struct { - Debug bool //日志开关 + modules.Options GinDebug bool //web引擎日志开关 ListenPort int //websocket 监听端口 } @@ -19,6 +20,9 @@ type ( // LoadConfig 配置文件序列化为Options func (this *Options) LoadConfig(settings map[string]interface{}) (err error) { if settings != nil { + if err = this.Options.LoadConfig(settings); err != nil { + return + } err = mapstructure.Decode(settings, this) } return diff --git a/modules/hero/api_awaken.go b/modules/hero/api_awaken.go index 0434f43fb..6cc332cac 100644 --- a/modules/hero/api_awaken.go +++ b/modules/hero/api_awaken.go @@ -54,7 +54,7 @@ func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (c return } // 消耗校验 - code = this.module.CheckConsumeRes(session.GetUserId(), awakenData.Phaseneed) + code = this.module.CheckConsumeRes(session.GetUserId(), awakenData.Phaseneed, true) if code != pb.ErrorCode_Success { return } diff --git a/modules/hero/api_chouka.go b/modules/hero/api_chouka.go index a310f149b..2f32f2f9e 100644 --- a/modules/hero/api_chouka.go +++ b/modules/hero/api_chouka.go @@ -27,7 +27,7 @@ func (this *apiComp) Chouka(session comm.IUserSession, req *pb.HeroChoukaReq) (c }() heroCfgIds := req.HeroIds - if err := this.module.modelHero.createMultiHero(session.GetUserId(), heroCfgIds...); err != nil { + if err := this.module.modelHero.createMultiHero(session.GetUserId(), false, heroCfgIds...); err != nil { code = pb.ErrorCode_HeroCreate return } diff --git a/modules/hero/api_resonance.go b/modules/hero/api_resonance.go index 0c045826f..f144698e3 100644 --- a/modules/hero/api_resonance.go +++ b/modules/hero/api_resonance.go @@ -93,7 +93,7 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR return } // 消耗校验 - code = this.module.CheckConsumeRes(session.GetUserId(), resonConfig.Need) + code = this.module.CheckConsumeRes(session.GetUserId(), resonConfig.Need, true) if code != pb.ErrorCode_Success { return } @@ -117,7 +117,7 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR return } for i := 0; i < int(v.N); i++ { // 有多少张加多少次 - this.module.modelHero.createOneHero(session.GetUserId(), int32(value)) + this.module.modelHero.createOneHero(session.GetUserId(), int32(value), true) } } } diff --git a/modules/hero/api_resonanceReset.go b/modules/hero/api_resonanceReset.go index bd13d0669..2dd4712f0 100644 --- a/modules/hero/api_resonanceReset.go +++ b/modules/hero/api_resonanceReset.go @@ -56,7 +56,7 @@ func (this *apiComp) ResonanceReset(session comm.IUserSession, req *pb.HeroReson return } // 消耗校验 - code = this.module.CheckConsumeRes(session.GetUserId(), _costConfig.Var) + code = this.module.CheckConsumeRes(session.GetUserId(), _costConfig.Var, true) if code != pb.ErrorCode_Success { return } diff --git a/modules/hero/api_starUp.go b/modules/hero/api_starUp.go index 5be07e57c..fc961d5a1 100644 --- a/modules/hero/api_starUp.go +++ b/modules/hero/api_starUp.go @@ -113,7 +113,7 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStr } // 消耗道具 - code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), "gold", -target.Gold) // 减少金币 + code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), "gold", -target.Gold, true) // 减少金币 if code != pb.ErrorCode_Success { this.module.Errorf("cost gold failed ,count = %d", target.Gold) code = pb.ErrorCode_GoldNoEnough diff --git a/modules/hero/api_strengthen.go b/modules/hero/api_strengthen.go index 9b6f7e3d0..2158b1103 100644 --- a/modules/hero/api_strengthen.go +++ b/modules/hero/api_strengthen.go @@ -129,7 +129,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren } // 消耗道具 for _, v := range costRes { - code = this.module.CheckConsumeRes(session.GetUserId(), v) + code = this.module.CheckConsumeRes(session.GetUserId(), v, true) if code != pb.ErrorCode_Success { return } diff --git a/modules/hero/hero_test.go b/modules/hero/hero_test.go index e0f1148f9..2156d8a71 100644 --- a/modules/hero/hero_test.go +++ b/modules/hero/hero_test.go @@ -70,7 +70,7 @@ func TestMain(m *testing.M) { //创建一个英雄s func TestCreateOneHero(t *testing.T) { - err := module.modelHero.createOneHero("u1", 25001) + err := module.modelHero.createOneHero("u1", 25001, true) fmt.Println(err) } diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 8e3baf794..9327198e1 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -85,7 +85,7 @@ func (this *ModelHero) initHeroSkill(hero *pb.DBHero) []*pb.SkillData { } //创建一个指定的英雄 -func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (err error) { +func (this *ModelHero) createOneHero(uid string, heroCfgId int32, bPush bool) (err error) { hero := this.initHero(uid, heroCfgId) if hero != nil { if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil { @@ -93,16 +93,24 @@ func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (err error) { return } } + // 创建英雄成功 向客户端推送数据 + if bPush { + if session, ok := this.moduleHero.GetUserSession(uid); ok { + session.SendMsg(string(this.moduleHero.GetType()), "addhero", &pb.AddNewHeroPush{Hero: hero}) + err = session.Push() + } + } + return nil } //创建多个指定的英雄 heroCfgIds可填入多个英雄ID -func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error { +func (this *ModelHero) createMultiHero(uid string, bPush bool, heroCfgIds ...int32) error { heroes := this.moduleHero.modelHero.getHeroList(uid) if len(heroes) == 0 { for _, v := range heroCfgIds { - if err := this.createOneHero(uid, v); err != nil { + if err := this.createOneHero(uid, v, bPush); err != nil { return err } } @@ -126,7 +134,7 @@ func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error { return err } } else { - if err := this.createOneHero(uid, v); err != nil { + if err := this.createOneHero(uid, v, bPush); err != nil { return err } } diff --git a/modules/hero/module.go b/modules/hero/module.go index 83683f0dc..285edebe9 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -39,8 +39,8 @@ func (this *Hero) OnInstallComp() { } //创建新英雄 -func (this *Hero) CreateHero(uid string, heroCfgId ...int32) error { - return this.modelHero.createMultiHero(uid, heroCfgId...) +func (this *Hero) CreateHero(uid string, bPush bool, heroCfgId ...int32) error { + return this.modelHero.createMultiHero(uid, bPush, heroCfgId...) } //获取英雄 diff --git a/modules/items/api_getlist.go b/modules/items/api_getlist.go index 6239280d1..1c93b4f75 100644 --- a/modules/items/api_getlist.go +++ b/modules/items/api_getlist.go @@ -23,7 +23,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ItemsGetlistReq) tempgrids []*pb.DB_UserItemData grids []*pb.DB_UserItemData modifys []*pb.DB_UserItemData - dels []string + dels []*pb.DB_UserItemData ) defer func() { session.SendMsg(string(this.module.GetType()), "getlist", &pb.ItemsGetlistResp{Grids: grids}) @@ -46,12 +46,12 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ItemsGetlistReq) } else { tempgrids = this.module.configure.GetPackItemByType(items, req.IType) modifys = make([]*pb.DB_UserItemData, 0, len(tempgrids)) - dels = make([]string, 0, len(tempgrids)) + dels = make([]*pb.DB_UserItemData, 0, len(tempgrids)) grids = make([]*pb.DB_UserItemData, 0, len(items)) nt = time.Now().Unix() for _, v := range tempgrids { if v.ETime > 0 && v.ETime < nt { //已经过期 - dels = append(dels, v.GridId) + dels = append(dels, v) } else { grids = append(grids, v) if v.IsNewItem { diff --git a/modules/items/modelitems.go b/modules/items/modelitems.go index d1a1b8e68..9970daa8b 100644 --- a/modules/items/modelitems.go +++ b/modules/items/modelitems.go @@ -76,7 +76,11 @@ func (this *ModelItemsComp) Pack_UpdateUserPack(uId string, itmes ...*pb.DB_User } //更新用户的背包信息 -func (this *ModelItemsComp) Pack_DeleteUserPack(uId string, gridIds ...string) (err error) { +func (this *ModelItemsComp) Pack_DeleteUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) { + gridIds := make([]string, len(itmes)) + for i, v := range itmes { + gridIds[i] = v.GridId + } if err = this.DelListlds(uId, gridIds...); err != nil { this.module.Errorf("err:%v", err) return @@ -106,11 +110,11 @@ func (this *ModelItemsComp) Pack_QueryUserPackItemsAmount(uId string, itemid ... } ///添加或则减少物品到用户背包 -func (this *ModelItemsComp) Pack_AddItemToUserPack(uId string, itemId int32, addnum int32) (err error) { +func (this *ModelItemsComp) Pack_AddItemToUserPack(uId string, itemId int32, addnum int32) (change []*pb.DB_UserItemData, err error) { var ( itmes []*pb.DB_UserItemData add []*pb.DB_UserItemData - del []string + del []*pb.DB_UserItemData update []*pb.DB_UserItemData leftnum int64 ) @@ -121,7 +125,8 @@ func (this *ModelItemsComp) Pack_AddItemToUserPack(uId string, itemId int32, add this.module.Errorf("err:%v", err) return } - add, update, del, leftnum = this.pack_addItemToUserPack(itmes, itemId, addnum) + change = make([]*pb.DB_UserItemData, len(itmes)) + add, update, del, leftnum = this.pack_addItemToUserPack(uId, itmes, itemId, addnum) if leftnum < 0 { err = ItemNotEnoughError return @@ -134,29 +139,31 @@ func (this *ModelItemsComp) Pack_AddItemToUserPack(uId string, itemId int32, add this.module.Errorf("err:%v", err) return } + change = append(change, add...) } if len(del) > 0 { if err = this.Pack_DeleteUserPack(uId, del...); err != nil { this.module.Errorf("err:%v", err) return } + change = append(change, del...) } if len(update) > 0 { if err = this.Pack_UpdateUserPack(uId, update...); err != nil { this.module.Errorf("err:%v", err) return } + change = append(change, update...) } - return } ///添加或则减少多个物品到用户背包 -func (this *ModelItemsComp) Pack_AddItemsToUserPack(uId string, items map[int32]int32) (err error) { +func (this *ModelItemsComp) Pack_AddItemsToUserPack(uId string, items map[int32]int32) (change []*pb.DB_UserItemData, err error) { var ( itmes []*pb.DB_UserItemData add []*pb.DB_UserItemData - del []string + del []*pb.DB_UserItemData update []*pb.DB_UserItemData leftnum int64 ) @@ -164,8 +171,9 @@ func (this *ModelItemsComp) Pack_AddItemsToUserPack(uId string, items map[int32] this.module.Errorf("err:%v", err) return } + change = make([]*pb.DB_UserItemData, len(itmes)) for k, v := range items { - add, update, del, leftnum = this.pack_addItemToUserPack(itmes, k, v) + add, update, del, leftnum = this.pack_addItemToUserPack(uId, itmes, k, v) if leftnum < 0 { err = ItemNotEnoughError return @@ -178,18 +186,21 @@ func (this *ModelItemsComp) Pack_AddItemsToUserPack(uId string, items map[int32] this.module.Errorf("err:%v", err) return } + change = append(change, add...) } if len(del) > 0 { if err = this.Pack_DeleteUserPack(uId, del...); err != nil { this.module.Errorf("err:%v", err) return } + change = append(change, del...) } if len(update) > 0 { if err = this.Pack_UpdateUserPack(uId, update...); err != nil { this.module.Errorf("err:%v", err) return } + change = append(change, update...) } } return @@ -237,7 +248,7 @@ func (this *ModelItemsComp) Pack_AddItemToUserPackByGrid(uId string, gridid stri } ///添加移除物品到用户背包 -func (this *ModelItemsComp) pack_addItemToUserPack(items []*pb.DB_UserItemData, itemId int32, addnum int32) (add, update []*pb.DB_UserItemData, del []string, leftnum int64) { +func (this *ModelItemsComp) pack_addItemToUserPack(uid string, items []*pb.DB_UserItemData, itemId int32, addnum int32) (add, update, del []*pb.DB_UserItemData, leftnum int64) { var ( err error conf *cfg.Game_itemData @@ -253,7 +264,7 @@ func (this *ModelItemsComp) pack_addItemToUserPack(items []*pb.DB_UserItemData, isNew = true leftnum = int64(addnum) add = make([]*pb.DB_UserItemData, 0) - del = make([]string, 0) + del = make([]*pb.DB_UserItemData, 0) update = make([]*pb.DB_UserItemData, 0) for _, v := range items { @@ -263,7 +274,7 @@ func (this *ModelItemsComp) pack_addItemToUserPack(items []*pb.DB_UserItemData, if num < 0 { leftnum += int64(v.Amount) v.Amount = 0 - del = append(del, v.GridId) + del = append(del, v) } else if num > 0 && num < int64(v.Amount) { leftnum = 0 v.Amount = uint32(num) @@ -285,7 +296,7 @@ func (this *ModelItemsComp) pack_addItemToUserPack(items []*pb.DB_UserItemData, } else if num == 0 { leftnum = 0 v.Amount = 0 - del = append(del, v.GridId) + del = append(del, v) } } } @@ -312,6 +323,7 @@ func (this *ModelItemsComp) pack_addItemToUserPack(items []*pb.DB_UserItemData, if leftnum <= int64(conf.Maxnum) { grid := &pb.DB_UserItemData{ GridId: primitive.NewObjectID().Hex(), + UId: uid, ItemId: itemId, Amount: uint32(leftnum), CTime: time.Now().Unix(), @@ -325,6 +337,7 @@ func (this *ModelItemsComp) pack_addItemToUserPack(items []*pb.DB_UserItemData, leftnum -= int64(conf.Maxnum) grid := &pb.DB_UserItemData{ GridId: primitive.NewObjectID().Hex(), + UId: uid, ItemId: itemId, Amount: uint32(conf.Maxnum), CTime: time.Now().Unix(), diff --git a/modules/items/module.go b/modules/items/module.go index 27a809184..ce2aab871 100644 --- a/modules/items/module.go +++ b/modules/items/module.go @@ -62,10 +62,13 @@ func (this *Items) QueryItemsAmount(source *comm.ModuleCallSource, uId string, i } ///添加单个物品到背包 (可以加物品和减物品) -func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, addnum int32) (code pb.ErrorCode) { - var err error +func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, addnum int32, bPush bool) (code pb.ErrorCode) { + var ( + err error + change []*pb.DB_UserItemData + ) defer this.Debugf("给用户添加物品 uId:%s itemid:%d addnum:%d issucc:%v", uId, itemid, addnum, err == nil) - if err = this.modelItems.Pack_AddItemToUserPack(uId, itemid, addnum); err != nil { + if change, err = this.modelItems.Pack_AddItemToUserPack(uId, itemid, addnum); err != nil { this.Errorf("给用户添加物品 uId:%s itemid:%d addnum:%d err:%v", uId, itemid, addnum, err) if err == ItemNotEnoughError { code = pb.ErrorCode_ItemsNoEnough @@ -74,15 +77,24 @@ func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, ad } else { code = pb.ErrorCode_Unknown } + return } + if bPush { + this.itemsChangePush(uId, change) //推送道具背包变化 + } + return } ///添加多个物品到背包 (可以加物品和减物品) -func (this *Items) AddItems(source *comm.ModuleCallSource, uId string, items map[int32]int32) (code pb.ErrorCode) { - var err error +func (this *Items) AddItems(source *comm.ModuleCallSource, uId string, items map[int32]int32, bPush bool) (code pb.ErrorCode) { + var ( + err error + change []*pb.DB_UserItemData + ) + defer this.Debugf("给用户添加物品 uId:%s items:%d items:%v", uId, items, err == nil) - if err = this.modelItems.Pack_AddItemsToUserPack(uId, items); err != nil { + if change, err = this.modelItems.Pack_AddItemsToUserPack(uId, items); err != nil { this.Errorf("给用户添加物品 uId:%s items:%d err:%v", uId, items, err) if err == ItemNotEnoughError { code = pb.ErrorCode_ItemsNoEnough @@ -91,8 +103,20 @@ func (this *Items) AddItems(source *comm.ModuleCallSource, uId string, items map } else { code = pb.ErrorCode_Unknown } + return + } + if len(change) > 0 && bPush { + this.itemsChangePush(uId, change) //推送道具背包变化 } return } //Evens-------------------------------------------------------------------------------------------------------------------------------- +//推送道具变化消息 +func (this *Items) itemsChangePush(uid string, items []*pb.DB_UserItemData) (err error) { + if session, ok := this.GetUserSession(uid); ok { + session.SendMsg(string(this.GetType()), "change", &pb.ItemsChangePush{Grids: items}) + err = session.Push() + } + return +} diff --git a/modules/items/module_test.go b/modules/items/module_test.go index 448ad187a..15e1fe472 100644 --- a/modules/items/module_test.go +++ b/modules/items/module_test.go @@ -94,6 +94,6 @@ func Test_Modules_AddItems(t *testing.T) { Module: "Test", FuncName: "Test_Modules_AddItems", Describe: "测试模块接口", - }, "0_62c259916d8cf3e4e06311a8", map[int32]int32{10001: 1000}) + }, "0_62c259916d8cf3e4e06311a8", map[int32]int32{10001: 1000}, true) log.Debugf("Test_Modules_AddItems code:%v", code) } diff --git a/modules/mail/api_getAttachment.go b/modules/mail/api_getAttachment.go index 5773360f7..eef1184ee 100644 --- a/modules/mail/api_getAttachment.go +++ b/modules/mail/api_getAttachment.go @@ -46,7 +46,7 @@ func (this *apiComp) GetUserMailAttachment(session comm.IUserSession, req *pb.Ma } res = append(res, d) } - code = this.module.api.module.CheckConsumeRes(session.GetUserId(), res) // 领取附件 + code = this.module.api.module.CheckConsumeRes(session.GetUserId(), res, true) // 领取附件 if code == pb.ErrorCode_Success { // 修改状态 this.module.modelMail.Mail_UpdateMailAttachmentState(req.ObjID) diff --git a/modules/mail/module.go b/modules/mail/module.go index 5f60c376f..a52dd2d20 100644 --- a/modules/mail/module.go +++ b/modules/mail/module.go @@ -36,17 +36,18 @@ func (this *Mail) OnInstallComp() { this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) } +// mail := &pb.DBMailData{ +// ObjId: primitive.NewObjectID().Hex(), +// Uid: uId, +// Title: "系统邮件", +// Contex: "恭喜获得专属礼包一份", +// CreateTime: uint64(time.Now().Unix()), +// DueTime: uint64(time.Now().Unix()) + 30*24*3600, // 30天需要走配置文件 +// Check: false, +// Reward: false, +// } func (this *Mail) CreateNewMail(uId string, mail *pb.DBMailData) bool { - // mail := &pb.DBMailData{ - // ObjId: primitive.NewObjectID().Hex(), - // Uid: uId, - // Title: "系统邮件", - // Contex: "恭喜获得专属礼包一份", - // CreateTime: uint64(time.Now().Unix()), - // DueTime: uint64(time.Now().Unix()) + 30*24*3600, // 30天需要走配置文件 - // Check: false, - // Reward: false, - // } + if mail == nil { return false } @@ -55,12 +56,16 @@ func (this *Mail) CreateNewMail(uId string, mail *pb.DBMailData) bool { this.ModuleBase.Errorf("create mail failed") } // 通知玩家 - var _cache = &pb.CacheUser{} - err = this.modelMail.MCompModel.Get(uId, _cache) - if err == nil { - return false - } + this.AddNewMailPush(uId, mail) - this.SendMsgToUser(string(this.GetType()), "newmail", mail, _cache) return true } + +// 获得新邮件 推送给玩家 +func (this *Mail) AddNewMailPush(uid string, mail *pb.DBMailData) (err error) { + if session, ok := this.GetUserSession(uid); ok { + session.SendMsg(string(this.GetType()), "newmail", &pb.MailGetNewMailPush{Mail: mail}) + err = session.Push() + } + return +} diff --git a/modules/mgolog/core.go b/modules/mgolog/core.go index 56bc17551..4cb2501b6 100644 --- a/modules/mgolog/core.go +++ b/modules/mgolog/core.go @@ -1,9 +1,5 @@ package mgolog -import ( - "go_dreamfactory/lego/core" -) - const ( WriteMaxNum uint32 = 1000 //一次性最处理条数 ErrorMaxNum uint32 = 5 // 数据库操作最大失败次数 @@ -13,7 +9,3 @@ const ( var ( ErrorLogCount = make(map[string]uint32, 0) ) - -const ( - DB_ModelTable core.SqlTable = "model_log" -) diff --git a/modules/mgolog/db_comp.go b/modules/mgolog/db_comp.go index 858810e0e..0dd434bb1 100644 --- a/modules/mgolog/db_comp.go +++ b/modules/mgolog/db_comp.go @@ -22,7 +22,7 @@ type DB_Comp struct { func (this *DB_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.MCompModel.Init(service, module, comp, options) this.task = make(chan string, TaskMaxNum) - + this.TableName = "model_log" return } @@ -60,12 +60,12 @@ func (this *DB_Comp) PushUserTask(uid string) { func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) { var _data *mongo.Cursor if uid == "" { - _data, err = this.DB.Find(DB_ModelTable, bson.M{}, options.Find().SetLimit(int64(WriteMaxNum))) + _data, err = this.DB.Find(core.SqlTable(this.TableName), bson.M{}, options.Find().SetLimit(int64(WriteMaxNum))) if err != nil { return err } } else { - _data, err = this.DB.Find(DB_ModelTable, bson.M{"uid": uid}, options.Find()) + _data, err = this.DB.Find(core.SqlTable(this.TableName), bson.M{"uid": uid}, options.Find()) if err != nil { return err } @@ -97,7 +97,7 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) { ErrorLogCount[data.ID]++ if ErrorLogCount[data.ID] >= ErrorMaxNum { // 实在是写失败了那就删除吧 log.Errorf("insert db err max num %s db err:%v", data.ID, err) - _, err = this.DB.DeleteOne(DB_ModelTable, bson.M{"_id": data.ID}) + _, err = this.DB.DeleteOne(core.SqlTable(this.TableName), bson.M{"_id": data.ID}) if err != nil { log.Errorf("insert %s db err:%+v", data.ID, err) } @@ -125,7 +125,7 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) { ErrorLogCount[data.ID]++ if ErrorLogCount[data.ID] >= ErrorMaxNum { // 实在是写失败了那就删除吧 log.Errorf("del db err max num %s db err:%v", data.ID, err) - _, err = this.DB.DeleteOne(DB_ModelTable, bson.M{"_id": data.ID}) + _, err = this.DB.DeleteOne(core.SqlTable(this.TableName), bson.M{"_id": data.ID}) if err != nil { log.Errorf("insert %s db err:%+v", data.ID, err) } @@ -154,7 +154,7 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) { ErrorLogCount[data.ID]++ if ErrorLogCount[data.ID] >= ErrorMaxNum { // 超过一定次数写失败了那就删除吧 log.Errorf("update db err max num %s db err:%v", data.ID, err) - _, err = this.DB.DeleteOne(DB_ModelTable, bson.M{"_id": data.ID}) + _, err = this.DB.DeleteOne(core.SqlTable(this.TableName), bson.M{"_id": data.ID}) if err != nil { log.Errorf("insert %s db err:%+v", data.ID, err) } @@ -166,7 +166,7 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) { } if len(_delID) > 0 { - _, err = this.DB.DeleteMany(DB_ModelTable, bson.M{"_id": bson.M{"$in": _delID}}, options.Delete()) // 批量删除已处理的数据 + _, err = this.DB.DeleteMany(core.SqlTable(this.TableName), bson.M{"_id": bson.M{"$in": _delID}}, options.Delete()) // 批量删除已处理的数据 if err != nil { log.Errorf("del err %v", err) } @@ -178,7 +178,7 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) { // 写入日志数据 func (this *DB_Comp) Model_InsertDBByLog(data *comm.Autogenerated) (err error) { - _, err = this.DB.InsertOne(DB_ModelTable, data) + _, err = this.DB.InsertOne(core.SqlTable(this.TableName), data) if err != nil { log.Errorf("insert model db err %v", err) } @@ -188,7 +188,7 @@ func (this *DB_Comp) Model_InsertDBByLog(data *comm.Autogenerated) (err error) { // 查询 当前日志列表还有没有处理完条数 func (this *DB_Comp) Model_TotalCount() int { - _data, err := this.DB.Find("DB_ModelTable", bson.M{}) + _data, err := this.DB.Find(core.SqlTable(this.TableName), bson.M{}) if err == nil { return _data.RemainingBatchLength() } diff --git a/modules/modulebase.go b/modules/modulebase.go index 52b611ccc..669243116 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -137,7 +137,7 @@ 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, bPush bool) (code pb.ErrorCode) { var ( err error resID int @@ -191,10 +191,10 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p for _, v := range res { if v.A == comm.AttrType { //用户属性资源 - this.ModuleUser.AddAttributeValue(uid, v.T, -1*v.N) + this.ModuleUser.AddAttributeValue(uid, v.T, -1*v.N, bPush) } else if v.A == comm.ItemType { //道具资源 resID, _ = strconv.Atoi(v.T) - this.ModuleItems.AddItem(source, uid, int32(resID), -1*v.N) + this.ModuleItems.AddItem(source, uid, int32(resID), -1*v.N, bPush) } // else if v.A == comm.HeroType { //卡片资源 // resID, _ = strconv.Atoi(v.T) @@ -210,7 +210,7 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p } //发放资源 -func (this *ModuleBase) DispenseRes(uid string, res []*cfg.Game_atn) (code pb.ErrorCode) { +func (this *ModuleBase) DispenseRes(uid string, res []*cfg.Game_atn, bPush bool) (code pb.ErrorCode) { var ( resID int ) @@ -221,16 +221,20 @@ func (this *ModuleBase) DispenseRes(uid string, res []*cfg.Game_atn) (code pb.Er } for _, v := range res { if v.A == comm.AttrType { //用户属性资源 - this.ModuleUser.AddAttributeValue(uid, v.T, v.N) + code = this.ModuleUser.AddAttributeValue(uid, v.T, v.N, bPush) + } else if v.A == comm.ItemType { //道具资源 resID, _ = strconv.Atoi(v.T) - this.ModuleItems.AddItem(source, uid, int32(resID), v.N) + code = this.ModuleItems.AddItem(source, uid, int32(resID), v.N, bPush) } else if v.A == comm.HeroType { //卡片资源 resID, _ = strconv.Atoi(v.T) - this.ModuleHero.CreateHero(uid, int32(resID), v.N) + err := this.ModuleHero.CreateHero(uid, bPush, int32(resID)) + if err != nil { + code = pb.ErrorCode_HeroMaxCount + } } else if v.A == comm.EquipmentType { resID, _ = strconv.Atoi(v.T) - this.ModuleEquipment.AddNewEquipments(source, uid, map[int32]uint32{int32(resID): uint32(v.N)}) + code = this.ModuleEquipment.AddNewEquipments(source, uid, map[int32]uint32{int32(resID): uint32(v.N)}, bPush) } } return @@ -253,11 +257,17 @@ func (this *ModuleBase) Warnf(format string, a ...interface{}) { } } func (this *ModuleBase) Errorf(format string, a ...interface{}) { - this.options.GetLog().Errorf(fmt.Sprintf("[Module:%s] ", this.module.GetType())+format, a...) + if this.options.GetLog() != nil { + this.options.GetLog().Errorf(fmt.Sprintf("[Module:%s] ", this.module.GetType())+format, a...) + } } func (this *ModuleBase) Panicf(format string, a ...interface{}) { - this.options.GetLog().Panicf(fmt.Sprintf("[Module:%s] ", this.module.GetType())+format, a...) + if this.options.GetLog() != nil { + this.options.GetLog().Panicf(fmt.Sprintf("[Module:%s] ", this.module.GetType())+format, a...) + } } func (this *ModuleBase) Fatalf(format string, a ...interface{}) { - this.options.GetLog().Fatalf(fmt.Sprintf("[Module:%s] ", this.module.GetType())+format, a...) + if this.options.GetLog() != nil { + this.options.GetLog().Fatalf(fmt.Sprintf("[Module:%s] ", this.module.GetType())+format, a...) + } } diff --git a/modules/shop/api_buy.go b/modules/shop/api_buy.go index 87d66264d..c551ba78e 100644 --- a/modules/shop/api_buy.go +++ b/modules/shop/api_buy.go @@ -45,10 +45,10 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.ShopBuyReq) (code pb } } - if code = this.module.CheckConsumeRes(session.GetUserId(), conf.Need); code != pb.ErrorCode_Success { + if code = this.module.CheckConsumeRes(session.GetUserId(), conf.Need, true); code != pb.ErrorCode_Success { return } - if code = this.module.DispenseRes(session.GetUserId(), conf.Iteminfo); code != pb.ErrorCode_Success { + if code = this.module.DispenseRes(session.GetUserId(), conf.Iteminfo, true); code != pb.ErrorCode_Success { return } shopitem.BuyNum++ diff --git a/modules/shop/api_getlist.go b/modules/shop/api_getlist.go index 8d5a0fd23..537ffbba7 100644 --- a/modules/shop/api_getlist.go +++ b/modules/shop/api_getlist.go @@ -94,7 +94,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq) } if req.IsManualRefresh && shopconf.Rtype == 1 { //可以手动刷新 - if code = this.module.CheckConsumeRes(session.GetUserId(), shopconf.Rneed); code != pb.ErrorCode_Success { + if code = this.module.CheckConsumeRes(session.GetUserId(), shopconf.Rneed, true); code != pb.ErrorCode_Success { return } var _items []*cfg.Game_shopitemData diff --git a/modules/story/api_challenge.go b/modules/story/api_challenge.go index 9af8faae7..da543d6db 100644 --- a/modules/story/api_challenge.go +++ b/modules/story/api_challenge.go @@ -2,6 +2,7 @@ package story import ( "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/redis" "go_dreamfactory/pb" "sort" @@ -30,7 +31,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallenge return // 参数校验失败直接返回 } list, err := this.module.modelStory.getStoryList(session.GetUserId()) - if err != nil { + if err != nil && err != redis.RedisNil { code = pb.ErrorCode_DBError return } @@ -60,7 +61,9 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallenge _data.Id = primitive.NewObjectID().Hex() _data.ChapterId = int32(req.ChapterId) _mData := make(map[string]interface{}, 0) + _data.Uid = session.GetUserId() _mData[_data.Id] = _data + this.module.modelStory.addNewChapter(session.GetUserId(), _mData) curChapter = _data //curChapter.StoryId = chaptConfig.Fubendata[0] // 第一次挑战 @@ -94,6 +97,9 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallenge "branchID": curChapter.BranchID, } err = this.module.modelStory.modifyStoryData(session.GetUserId(), curChapter.Id, update) + } else { + code = pb.ErrorCode_ReqParameterError + return } // 发奖 (奖励数据还没配置,后续补充) session.SendMsg(string(this.module.GetType()), StoryChallengeResp, &pb.StoryChallengeResp{Data: curChapter}) diff --git a/modules/task/api_activereceive.go b/modules/task/api_activereceive.go index b69603bc9..325dcd87c 100644 --- a/modules/task/api_activereceive.go +++ b/modules/task/api_activereceive.go @@ -50,6 +50,6 @@ func (this *apiComp) ActiveReceive(session comm.IUserSession, req *pb.TaskActive } //派发奖励 - code = this.moduleTask.DispenseRes(session.GetUserId(), conf.Reword) + code = this.moduleTask.DispenseRes(session.GetUserId(), conf.Reword, true) return } diff --git a/modules/task/api_receive.go b/modules/task/api_receive.go index 54247cfbf..6b0b1ba84 100644 --- a/modules/task/api_receive.go +++ b/modules/task/api_receive.go @@ -38,7 +38,7 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq) return } //奖励 - if code = this.moduleTask.CheckConsumeRes(session.GetUserId(), conf.Reword); code != pb.ErrorCode_Success { + if code = this.moduleTask.CheckConsumeRes(session.GetUserId(), conf.Reword, true); code != pb.ErrorCode_Success { return } diff --git a/modules/user/api_create.go b/modules/user/api_create.go index 3dc76159e..02582a6a4 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -69,7 +69,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c //初始化英雄卡 if val := this.module.configure.GetGlobalConf("init_hero"); val != "" { defaultHero := utils.TrInt32(val) - err = this.hero.CreateHero(session.GetUserId(), defaultHero...) + err = this.hero.CreateHero(session.GetUserId(), true, defaultHero...) if err != nil { code = pb.ErrorCode_HeroInitCreat return diff --git a/modules/user/api_res.go b/modules/user/api_res.go index 817abd5c8..4478273c4 100644 --- a/modules/user/api_res.go +++ b/modules/user/api_res.go @@ -41,7 +41,7 @@ func (this *apiComp) AddRes(session comm.IUserSession, req *pb.UserAddResReq) (c N: req.Res.N, } res = append(res, atn) - code = this.module.DispenseRes(session.GetUserId(), res) + code = this.module.DispenseRes(session.GetUserId(), res, true) rsp.Res = req.Res return } diff --git a/modules/user/module.go b/modules/user/module.go index 69731a1b0..11f74c78e 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -74,7 +74,7 @@ func (this *User) QueryAttributeValue(uid string, attr string) (value int32) { } //用户资源 -func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb.ErrorCode) { +func (this *User) AddAttributeValue(uid string, attr string, add int32, bPush bool) (code pb.ErrorCode) { if add == 0 { log.Errorf("attr no changed,uid: %s attr: %s add: %d", uid, attr, add) code = pb.ErrorCode_ReqParameterError @@ -86,6 +86,13 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb return } + _change := &pb.UserResChangePush{ + Gold: user.Gold, + Exp: user.Exp, + Lv: user.Lv, + Vip: user.Vip, + Diamond: user.Diamond, + } update := make(map[string]interface{}) switch attr { case comm.ResGold: @@ -95,6 +102,7 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb return } } + _change.Gold += add update[comm.ResGold] = user.Gold + add case comm.ResExp: if add < 0 { @@ -103,6 +111,7 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb return } } + _change.Exp += add update[comm.ResExp] = user.Exp + add case comm.ResDiamond: if add < 0 { @@ -111,6 +120,7 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb return } } + _change.Diamond += add update[comm.ResDiamond] = user.Diamond + add } @@ -121,5 +131,24 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb log.Errorf("AddAttributeValue err:%v", err) code = pb.ErrorCode_DBError } + data := &pb.UserResChangePush{} + var _cache = &pb.CacheUser{} + err := this.modelUser.MCompModel.Get(uid, _cache) + if err != nil { + this.SendMsgToUser(string(this.GetType()), "addres", data, _cache) + } + if bPush { + this.UserChangePush(uid, _change) // 推送玩家数据变化 + } + + return +} + +//推送玩家账号信息变化消息 +func (this *User) UserChangePush(uid string, resChange *pb.UserResChangePush) (err error) { + if session, ok := this.ModuleBase.GetUserSession(uid); ok { + session.SendMsg(string(this.GetType()), "userchange", resChange) + err = session.Push() + } return } diff --git a/pb/equipment_msg.pb.go b/pb/equipment_msg.pb.go index c9c67a1a1..30d2aea37 100644 --- a/pb/equipment_msg.pb.go +++ b/pb/equipment_msg.pb.go @@ -107,6 +107,54 @@ func (x *EquipmentGetListResp) GetEquipments() []*DB_Equipment { return nil } +//推送装备背包变化 +type EquipmentChangePush struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Equipments []*DB_Equipment `protobuf:"bytes,1,rep,name=Equipments,proto3" json:"Equipments"` //装备列表 +} + +func (x *EquipmentChangePush) Reset() { + *x = EquipmentChangePush{} + if protoimpl.UnsafeEnabled { + mi := &file_equipment_equipment_msg_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EquipmentChangePush) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EquipmentChangePush) ProtoMessage() {} + +func (x *EquipmentChangePush) ProtoReflect() protoreflect.Message { + mi := &file_equipment_equipment_msg_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EquipmentChangePush.ProtoReflect.Descriptor instead. +func (*EquipmentChangePush) Descriptor() ([]byte, []int) { + return file_equipment_equipment_msg_proto_rawDescGZIP(), []int{2} +} + +func (x *EquipmentChangePush) GetEquipments() []*DB_Equipment { + if x != nil { + return x.Equipments + } + return nil +} + //装备挂在到英雄上 type EquipmentEquipReq struct { state protoimpl.MessageState @@ -120,7 +168,7 @@ type EquipmentEquipReq struct { func (x *EquipmentEquipReq) Reset() { *x = EquipmentEquipReq{} if protoimpl.UnsafeEnabled { - mi := &file_equipment_equipment_msg_proto_msgTypes[2] + mi := &file_equipment_equipment_msg_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -133,7 +181,7 @@ func (x *EquipmentEquipReq) String() string { func (*EquipmentEquipReq) ProtoMessage() {} func (x *EquipmentEquipReq) ProtoReflect() protoreflect.Message { - mi := &file_equipment_equipment_msg_proto_msgTypes[2] + mi := &file_equipment_equipment_msg_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -146,7 +194,7 @@ func (x *EquipmentEquipReq) ProtoReflect() protoreflect.Message { // Deprecated: Use EquipmentEquipReq.ProtoReflect.Descriptor instead. func (*EquipmentEquipReq) Descriptor() ([]byte, []int) { - return file_equipment_equipment_msg_proto_rawDescGZIP(), []int{2} + return file_equipment_equipment_msg_proto_rawDescGZIP(), []int{3} } func (x *EquipmentEquipReq) GetHeroCardId() string { @@ -175,7 +223,7 @@ type EquipmentEquipResp struct { func (x *EquipmentEquipResp) Reset() { *x = EquipmentEquipResp{} if protoimpl.UnsafeEnabled { - mi := &file_equipment_equipment_msg_proto_msgTypes[3] + mi := &file_equipment_equipment_msg_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -188,7 +236,7 @@ func (x *EquipmentEquipResp) String() string { func (*EquipmentEquipResp) ProtoMessage() {} func (x *EquipmentEquipResp) ProtoReflect() protoreflect.Message { - mi := &file_equipment_equipment_msg_proto_msgTypes[3] + mi := &file_equipment_equipment_msg_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -201,7 +249,7 @@ func (x *EquipmentEquipResp) ProtoReflect() protoreflect.Message { // Deprecated: Use EquipmentEquipResp.ProtoReflect.Descriptor instead. func (*EquipmentEquipResp) Descriptor() ([]byte, []int) { - return file_equipment_equipment_msg_proto_rawDescGZIP(), []int{3} + return file_equipment_equipment_msg_proto_rawDescGZIP(), []int{4} } func (x *EquipmentEquipResp) GetEquipments() []*DB_Equipment { @@ -223,7 +271,7 @@ type EquipmentUpgradeReq struct { func (x *EquipmentUpgradeReq) Reset() { *x = EquipmentUpgradeReq{} if protoimpl.UnsafeEnabled { - mi := &file_equipment_equipment_msg_proto_msgTypes[4] + mi := &file_equipment_equipment_msg_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -236,7 +284,7 @@ func (x *EquipmentUpgradeReq) String() string { func (*EquipmentUpgradeReq) ProtoMessage() {} func (x *EquipmentUpgradeReq) ProtoReflect() protoreflect.Message { - mi := &file_equipment_equipment_msg_proto_msgTypes[4] + mi := &file_equipment_equipment_msg_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -249,7 +297,7 @@ func (x *EquipmentUpgradeReq) ProtoReflect() protoreflect.Message { // Deprecated: Use EquipmentUpgradeReq.ProtoReflect.Descriptor instead. func (*EquipmentUpgradeReq) Descriptor() ([]byte, []int) { - return file_equipment_equipment_msg_proto_rawDescGZIP(), []int{4} + return file_equipment_equipment_msg_proto_rawDescGZIP(), []int{5} } func (x *EquipmentUpgradeReq) GetEquipmentId() string { @@ -272,7 +320,7 @@ type EquipmentUpgradeResp struct { func (x *EquipmentUpgradeResp) Reset() { *x = EquipmentUpgradeResp{} if protoimpl.UnsafeEnabled { - mi := &file_equipment_equipment_msg_proto_msgTypes[5] + mi := &file_equipment_equipment_msg_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -285,7 +333,7 @@ func (x *EquipmentUpgradeResp) String() string { func (*EquipmentUpgradeResp) ProtoMessage() {} func (x *EquipmentUpgradeResp) ProtoReflect() protoreflect.Message { - mi := &file_equipment_equipment_msg_proto_msgTypes[5] + mi := &file_equipment_equipment_msg_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -298,7 +346,7 @@ func (x *EquipmentUpgradeResp) ProtoReflect() protoreflect.Message { // Deprecated: Use EquipmentUpgradeResp.ProtoReflect.Descriptor instead. func (*EquipmentUpgradeResp) Descriptor() ([]byte, []int) { - return file_equipment_equipment_msg_proto_rawDescGZIP(), []int{5} + return file_equipment_equipment_msg_proto_rawDescGZIP(), []int{6} } func (x *EquipmentUpgradeResp) GetIsSucc() bool { @@ -327,27 +375,32 @@ var file_equipment_equipment_msg_proto_rawDesc = []byte{ 0x74, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x2d, 0x0a, 0x0a, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x5f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, - 0x0a, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x55, 0x0a, 0x11, 0x45, - 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x45, 0x71, 0x75, 0x69, 0x70, 0x52, 0x65, 0x71, - 0x12, 0x1e, 0x0a, 0x0a, 0x48, 0x65, 0x72, 0x6f, 0x43, 0x61, 0x72, 0x64, 0x49, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x48, 0x65, 0x72, 0x6f, 0x43, 0x61, 0x72, 0x64, 0x49, 0x64, - 0x12, 0x20, 0x0a, 0x0b, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, - 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, - 0x49, 0x64, 0x22, 0x43, 0x0a, 0x12, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x45, - 0x71, 0x75, 0x69, 0x70, 0x52, 0x65, 0x73, 0x70, 0x12, 0x2d, 0x0a, 0x0a, 0x45, 0x71, 0x75, 0x69, - 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, - 0x42, 0x5f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x0a, 0x45, 0x71, 0x75, - 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x37, 0x0a, 0x13, 0x45, 0x71, 0x75, 0x69, 0x70, - 0x6d, 0x65, 0x6e, 0x74, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x12, 0x20, - 0x0a, 0x0b, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x0b, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, - 0x22, 0x5b, 0x0a, 0x14, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x55, 0x70, 0x67, - 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x73, 0x53, 0x75, - 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x49, 0x73, 0x53, 0x75, 0x63, 0x63, - 0x12, 0x2b, 0x0a, 0x09, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x5f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, - 0x6e, 0x74, 0x52, 0x09, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x42, 0x06, 0x5a, - 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x0a, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x44, 0x0a, 0x13, 0x45, + 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, + 0x73, 0x68, 0x12, 0x2d, 0x0a, 0x0a, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x73, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x5f, 0x45, 0x71, 0x75, 0x69, + 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x0a, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, + 0x73, 0x22, 0x55, 0x0a, 0x11, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x45, 0x71, + 0x75, 0x69, 0x70, 0x52, 0x65, 0x71, 0x12, 0x1e, 0x0a, 0x0a, 0x48, 0x65, 0x72, 0x6f, 0x43, 0x61, + 0x72, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x48, 0x65, 0x72, 0x6f, + 0x43, 0x61, 0x72, 0x64, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, + 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x45, 0x71, 0x75, + 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x43, 0x0a, 0x12, 0x45, 0x71, 0x75, 0x69, + 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x45, 0x71, 0x75, 0x69, 0x70, 0x52, 0x65, 0x73, 0x70, 0x12, 0x2d, + 0x0a, 0x0a, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x5f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, + 0x74, 0x52, 0x0a, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x37, 0x0a, + 0x13, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, + 0x65, 0x52, 0x65, 0x71, 0x12, 0x20, 0x0a, 0x0b, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, + 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x45, 0x71, 0x75, 0x69, 0x70, + 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x5b, 0x0a, 0x14, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, + 0x65, 0x6e, 0x74, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, + 0x0a, 0x06, 0x49, 0x73, 0x53, 0x75, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, + 0x49, 0x73, 0x53, 0x75, 0x63, 0x63, 0x12, 0x2b, 0x0a, 0x09, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, + 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x5f, 0x45, + 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x09, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, + 0x65, 0x6e, 0x74, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -362,25 +415,27 @@ func file_equipment_equipment_msg_proto_rawDescGZIP() []byte { return file_equipment_equipment_msg_proto_rawDescData } -var file_equipment_equipment_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_equipment_equipment_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_equipment_equipment_msg_proto_goTypes = []interface{}{ (*EquipmentGetListReq)(nil), // 0: EquipmentGetListReq (*EquipmentGetListResp)(nil), // 1: EquipmentGetListResp - (*EquipmentEquipReq)(nil), // 2: EquipmentEquipReq - (*EquipmentEquipResp)(nil), // 3: EquipmentEquipResp - (*EquipmentUpgradeReq)(nil), // 4: EquipmentUpgradeReq - (*EquipmentUpgradeResp)(nil), // 5: EquipmentUpgradeResp - (*DB_Equipment)(nil), // 6: DB_Equipment + (*EquipmentChangePush)(nil), // 2: EquipmentChangePush + (*EquipmentEquipReq)(nil), // 3: EquipmentEquipReq + (*EquipmentEquipResp)(nil), // 4: EquipmentEquipResp + (*EquipmentUpgradeReq)(nil), // 5: EquipmentUpgradeReq + (*EquipmentUpgradeResp)(nil), // 6: EquipmentUpgradeResp + (*DB_Equipment)(nil), // 7: DB_Equipment } var file_equipment_equipment_msg_proto_depIdxs = []int32{ - 6, // 0: EquipmentGetListResp.Equipments:type_name -> DB_Equipment - 6, // 1: EquipmentEquipResp.Equipments:type_name -> DB_Equipment - 6, // 2: EquipmentUpgradeResp.Equipment:type_name -> DB_Equipment - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 7, // 0: EquipmentGetListResp.Equipments:type_name -> DB_Equipment + 7, // 1: EquipmentChangePush.Equipments:type_name -> DB_Equipment + 7, // 2: EquipmentEquipResp.Equipments:type_name -> DB_Equipment + 7, // 3: EquipmentUpgradeResp.Equipment:type_name -> DB_Equipment + 4, // [4:4] is the sub-list for method output_type + 4, // [4:4] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_equipment_equipment_msg_proto_init() } @@ -415,7 +470,7 @@ func file_equipment_equipment_msg_proto_init() { } } file_equipment_equipment_msg_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EquipmentEquipReq); i { + switch v := v.(*EquipmentChangePush); i { case 0: return &v.state case 1: @@ -427,7 +482,7 @@ func file_equipment_equipment_msg_proto_init() { } } file_equipment_equipment_msg_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EquipmentEquipResp); i { + switch v := v.(*EquipmentEquipReq); i { case 0: return &v.state case 1: @@ -439,7 +494,7 @@ func file_equipment_equipment_msg_proto_init() { } } file_equipment_equipment_msg_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EquipmentUpgradeReq); i { + switch v := v.(*EquipmentEquipResp); i { case 0: return &v.state case 1: @@ -451,6 +506,18 @@ func file_equipment_equipment_msg_proto_init() { } } file_equipment_equipment_msg_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EquipmentUpgradeReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_equipment_equipment_msg_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*EquipmentUpgradeResp); i { case 0: return &v.state @@ -469,7 +536,7 @@ func file_equipment_equipment_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_equipment_equipment_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 6, + NumMessages: 7, NumExtensions: 0, NumServices: 0, }, diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go index de79ceab6..1810a18bd 100644 --- a/pb/errorcode.pb.go +++ b/pb/errorcode.pb.go @@ -83,6 +83,7 @@ const ( ErrorCode_HeroEquipUpdate ErrorCode = 1311 // 更新装备失败 ErrorCode_HeroMaxAwaken ErrorCode = 1312 // 达到最大觉醒等级 ErrorCode_HeroIsLock ErrorCode = 1313 // 英雄被锁定不能被消耗 + ErrorCode_HeroMaxCount ErrorCode = 1314 // 英雄达到最大数量 // equipment ErrorCode_EquipmentOnFoundEquipment ErrorCode = 1400 // 未找到武器 ErrorCode_EquipmentLvlimitReached ErrorCode = 1401 // 武器等级已达上限 @@ -158,6 +159,7 @@ var ( 1311: "HeroEquipUpdate", 1312: "HeroMaxAwaken", 1313: "HeroIsLock", + 1314: "HeroMaxCount", 1400: "EquipmentOnFoundEquipment", 1401: "EquipmentLvlimitReached", 1500: "StoryNotFindChapter", @@ -227,6 +229,7 @@ var ( "HeroEquipUpdate": 1311, "HeroMaxAwaken": 1312, "HeroIsLock": 1313, + "HeroMaxCount": 1314, "EquipmentOnFoundEquipment": 1400, "EquipmentLvlimitReached": 1401, "StoryNotFindChapter": 1500, @@ -272,7 +275,7 @@ var File_errorcode_proto protoreflect.FileDescriptor var file_errorcode_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2a, 0xf4, 0x0a, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, + 0x6f, 0x2a, 0x87, 0x0b, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12, 0x1b, 0x0a, 0x17, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, @@ -344,23 +347,24 @@ var file_errorcode_proto_rawDesc = []byte{ 0x45, 0x71, 0x75, 0x69, 0x70, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x10, 0x9f, 0x0a, 0x12, 0x12, 0x0a, 0x0d, 0x48, 0x65, 0x72, 0x6f, 0x4d, 0x61, 0x78, 0x41, 0x77, 0x61, 0x6b, 0x65, 0x6e, 0x10, 0xa0, 0x0a, 0x12, 0x0f, 0x0a, 0x0a, 0x48, 0x65, 0x72, 0x6f, 0x49, 0x73, 0x4c, 0x6f, 0x63, 0x6b, - 0x10, 0xa1, 0x0a, 0x12, 0x1e, 0x0a, 0x19, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, - 0x4f, 0x6e, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, - 0x10, 0xf8, 0x0a, 0x12, 0x1c, 0x0a, 0x17, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, - 0x4c, 0x76, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x61, 0x63, 0x68, 0x65, 0x64, 0x10, 0xf9, - 0x0a, 0x12, 0x18, 0x0a, 0x13, 0x53, 0x74, 0x6f, 0x72, 0x79, 0x4e, 0x6f, 0x74, 0x46, 0x69, 0x6e, - 0x64, 0x43, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x10, 0xdc, 0x0b, 0x12, 0x12, 0x0a, 0x0d, 0x53, - 0x74, 0x6f, 0x72, 0x79, 0x49, 0x44, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, 0xdd, 0x0b, 0x12, - 0x0d, 0x0a, 0x08, 0x54, 0x61, 0x73, 0x6b, 0x49, 0x6e, 0x69, 0x74, 0x10, 0xc0, 0x0c, 0x12, 0x0e, - 0x0a, 0x09, 0x54, 0x61, 0x73, 0x6b, 0x52, 0x65, 0x73, 0x65, 0x74, 0x10, 0xc1, 0x0c, 0x12, 0x0f, - 0x0a, 0x0a, 0x54, 0x61, 0x73, 0x6b, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x10, 0xc2, 0x0c, 0x12, - 0x11, 0x0a, 0x0c, 0x54, 0x61, 0x73, 0x6b, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x10, - 0xc3, 0x0c, 0x12, 0x13, 0x0a, 0x0e, 0x54, 0x61, 0x73, 0x6b, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, - 0x49, 0x6e, 0x69, 0x74, 0x10, 0xc6, 0x0c, 0x12, 0x16, 0x0a, 0x11, 0x54, 0x61, 0x73, 0x6b, 0x41, - 0x63, 0x74, 0x69, 0x76, 0x65, 0x4e, 0x6f, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x10, 0xc4, 0x0c, 0x12, - 0x17, 0x0a, 0x12, 0x54, 0x61, 0x73, 0x6b, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x4e, 0x6f, 0x65, - 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0xc5, 0x0c, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x10, 0xa1, 0x0a, 0x12, 0x11, 0x0a, 0x0c, 0x48, 0x65, 0x72, 0x6f, 0x4d, 0x61, 0x78, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x10, 0xa2, 0x0a, 0x12, 0x1e, 0x0a, 0x19, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, + 0x65, 0x6e, 0x74, 0x4f, 0x6e, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, + 0x65, 0x6e, 0x74, 0x10, 0xf8, 0x0a, 0x12, 0x1c, 0x0a, 0x17, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, + 0x65, 0x6e, 0x74, 0x4c, 0x76, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x61, 0x63, 0x68, 0x65, + 0x64, 0x10, 0xf9, 0x0a, 0x12, 0x18, 0x0a, 0x13, 0x53, 0x74, 0x6f, 0x72, 0x79, 0x4e, 0x6f, 0x74, + 0x46, 0x69, 0x6e, 0x64, 0x43, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x10, 0xdc, 0x0b, 0x12, 0x12, + 0x0a, 0x0d, 0x53, 0x74, 0x6f, 0x72, 0x79, 0x49, 0x44, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, + 0xdd, 0x0b, 0x12, 0x0d, 0x0a, 0x08, 0x54, 0x61, 0x73, 0x6b, 0x49, 0x6e, 0x69, 0x74, 0x10, 0xc0, + 0x0c, 0x12, 0x0e, 0x0a, 0x09, 0x54, 0x61, 0x73, 0x6b, 0x52, 0x65, 0x73, 0x65, 0x74, 0x10, 0xc1, + 0x0c, 0x12, 0x0f, 0x0a, 0x0a, 0x54, 0x61, 0x73, 0x6b, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x10, + 0xc2, 0x0c, 0x12, 0x11, 0x0a, 0x0c, 0x54, 0x61, 0x73, 0x6b, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, + 0x65, 0x64, 0x10, 0xc3, 0x0c, 0x12, 0x13, 0x0a, 0x0e, 0x54, 0x61, 0x73, 0x6b, 0x41, 0x63, 0x74, + 0x69, 0x76, 0x65, 0x49, 0x6e, 0x69, 0x74, 0x10, 0xc6, 0x0c, 0x12, 0x16, 0x0a, 0x11, 0x54, 0x61, + 0x73, 0x6b, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x4e, 0x6f, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x10, + 0xc4, 0x0c, 0x12, 0x17, 0x0a, 0x12, 0x54, 0x61, 0x73, 0x6b, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, + 0x4e, 0x6f, 0x65, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0xc5, 0x0c, 0x42, 0x06, 0x5a, 0x04, 0x2e, + 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pb/forum_db.pb.go b/pb/forum_db.pb.go new file mode 100644 index 000000000..fd88ace8b --- /dev/null +++ b/pb/forum_db.pb.go @@ -0,0 +1,61 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.20.0 +// source: forum/forum_db.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +var File_forum_forum_db_proto protoreflect.FileDescriptor + +var file_forum_forum_db_proto_rawDesc = []byte{ + 0x0a, 0x14, 0x66, 0x6f, 0x72, 0x75, 0x6d, 0x2f, 0x66, 0x6f, 0x72, 0x75, 0x6d, 0x5f, 0x64, 0x62, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var file_forum_forum_db_proto_goTypes = []interface{}{} +var file_forum_forum_db_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_forum_forum_db_proto_init() } +func file_forum_forum_db_proto_init() { + if File_forum_forum_db_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_forum_forum_db_proto_rawDesc, + NumEnums: 0, + NumMessages: 0, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_forum_forum_db_proto_goTypes, + DependencyIndexes: file_forum_forum_db_proto_depIdxs, + }.Build() + File_forum_forum_db_proto = out.File + file_forum_forum_db_proto_rawDesc = nil + file_forum_forum_db_proto_goTypes = nil + file_forum_forum_db_proto_depIdxs = nil +} diff --git a/pb/forum_msg.pb.go b/pb/forum_msg.pb.go new file mode 100644 index 000000000..253e5ff1c --- /dev/null +++ b/pb/forum_msg.pb.go @@ -0,0 +1,61 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.20.0 +// source: forum/forum_msg.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +var File_forum_forum_msg_proto protoreflect.FileDescriptor + +var file_forum_forum_msg_proto_rawDesc = []byte{ + 0x0a, 0x15, 0x66, 0x6f, 0x72, 0x75, 0x6d, 0x2f, 0x66, 0x6f, 0x72, 0x75, 0x6d, 0x5f, 0x6d, 0x73, + 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var file_forum_forum_msg_proto_goTypes = []interface{}{} +var file_forum_forum_msg_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_forum_forum_msg_proto_init() } +func file_forum_forum_msg_proto_init() { + if File_forum_forum_msg_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_forum_forum_msg_proto_rawDesc, + NumEnums: 0, + NumMessages: 0, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_forum_forum_msg_proto_goTypes, + DependencyIndexes: file_forum_forum_msg_proto_depIdxs, + }.Build() + File_forum_forum_msg_proto = out.File + file_forum_forum_msg_proto_rawDesc = nil + file_forum_forum_msg_proto_goTypes = nil + file_forum_forum_msg_proto_depIdxs = nil +} diff --git a/pb/hero_msg.pb.go b/pb/hero_msg.pb.go index 56377377a..d9b47f199 100644 --- a/pb/hero_msg.pb.go +++ b/pb/hero_msg.pb.go @@ -1323,6 +1323,54 @@ func (x *HeroLockResp) GetHero() *DBHero { return nil } +// 增加新英雄推送 +type AddNewHeroPush struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Hero *DBHero `protobuf:"bytes,1,opt,name=hero,proto3" json:"hero"` // 英雄对象 +} + +func (x *AddNewHeroPush) Reset() { + *x = AddNewHeroPush{} + if protoimpl.UnsafeEnabled { + mi := &file_hero_hero_msg_proto_msgTypes[25] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AddNewHeroPush) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddNewHeroPush) ProtoMessage() {} + +func (x *AddNewHeroPush) ProtoReflect() protoreflect.Message { + mi := &file_hero_hero_msg_proto_msgTypes[25] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AddNewHeroPush.ProtoReflect.Descriptor instead. +func (*AddNewHeroPush) Descriptor() ([]byte, []int) { + return file_hero_hero_msg_proto_rawDescGZIP(), []int{25} +} + +func (x *AddNewHeroPush) GetHero() *DBHero { + if x != nil { + return x.Hero + } + return nil +} + var File_hero_hero_msg_proto protoreflect.FileDescriptor var file_hero_hero_msg_proto_rawDesc = []byte{ @@ -1444,8 +1492,11 @@ var file_hero_hero_msg_proto_rawDesc = []byte{ 0x65, 0x72, 0x6f, 0x69, 0x64, 0x22, 0x2b, 0x0a, 0x0c, 0x48, 0x65, 0x72, 0x6f, 0x4c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1b, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x44, 0x42, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, - 0x72, 0x6f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x72, 0x6f, 0x22, 0x2d, 0x0a, 0x0e, 0x41, 0x64, 0x64, 0x4e, 0x65, 0x77, 0x48, 0x65, 0x72, 0x6f, + 0x50, 0x75, 0x73, 0x68, 0x12, 0x1b, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x44, 0x42, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72, + 0x6f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -1460,7 +1511,7 @@ func file_hero_hero_msg_proto_rawDescGZIP() []byte { return file_hero_hero_msg_proto_rawDescData } -var file_hero_hero_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 27) +var file_hero_hero_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 28) var file_hero_hero_msg_proto_goTypes = []interface{}{ (*HeroInfoReq)(nil), // 0: HeroInfoReq (*HeroInfoResp)(nil), // 1: HeroInfoResp @@ -1487,32 +1538,34 @@ var file_hero_hero_msg_proto_goTypes = []interface{}{ (*HeroProperty)(nil), // 22: HeroProperty (*HeroLockReq)(nil), // 23: HeroLockReq (*HeroLockResp)(nil), // 24: HeroLockResp - nil, // 25: HeroProperty.PropertyEntry - nil, // 26: HeroProperty.AddPropertyEntry - (*DBHero)(nil), // 27: DBHero + (*AddNewHeroPush)(nil), // 25: AddNewHeroPush + nil, // 26: HeroProperty.PropertyEntry + nil, // 27: HeroProperty.AddPropertyEntry + (*DBHero)(nil), // 28: DBHero } var file_hero_hero_msg_proto_depIdxs = []int32{ - 27, // 0: HeroInfoResp.base:type_name -> DBHero - 27, // 1: HeroListResp.list:type_name -> DBHero - 27, // 2: HeroStrengthenUplvResp.hero:type_name -> DBHero + 28, // 0: HeroInfoResp.base:type_name -> DBHero + 28, // 1: HeroListResp.list:type_name -> DBHero + 28, // 2: HeroStrengthenUplvResp.hero:type_name -> DBHero 7, // 3: HeroStrengthenUpStarReq.hero:type_name -> CostCardData 7, // 4: HeroStrengthenUpStarReq.heroRace:type_name -> CostCardData - 27, // 5: HeroStrengthenUpStarResp.hero:type_name -> DBHero - 27, // 6: HeroStrengthenUpSkillResp.hero:type_name -> DBHero - 27, // 7: HeroResonanceResp.hero:type_name -> DBHero - 27, // 8: HeroResonanceResp.upStarCard:type_name -> DBHero - 27, // 9: HeroResonanceResetResp.hero:type_name -> DBHero - 27, // 10: HeroResonanceUseEnergyResp.hero:type_name -> DBHero - 27, // 11: HeroAwakenResp.hero:type_name -> DBHero - 27, // 12: HeroChoukaResp.heroes:type_name -> DBHero - 25, // 13: HeroProperty.property:type_name -> HeroProperty.PropertyEntry - 26, // 14: HeroProperty.addProperty:type_name -> HeroProperty.AddPropertyEntry - 27, // 15: HeroLockResp.hero:type_name -> DBHero - 16, // [16:16] is the sub-list for method output_type - 16, // [16:16] is the sub-list for method input_type - 16, // [16:16] is the sub-list for extension type_name - 16, // [16:16] is the sub-list for extension extendee - 0, // [0:16] is the sub-list for field type_name + 28, // 5: HeroStrengthenUpStarResp.hero:type_name -> DBHero + 28, // 6: HeroStrengthenUpSkillResp.hero:type_name -> DBHero + 28, // 7: HeroResonanceResp.hero:type_name -> DBHero + 28, // 8: HeroResonanceResp.upStarCard:type_name -> DBHero + 28, // 9: HeroResonanceResetResp.hero:type_name -> DBHero + 28, // 10: HeroResonanceUseEnergyResp.hero:type_name -> DBHero + 28, // 11: HeroAwakenResp.hero:type_name -> DBHero + 28, // 12: HeroChoukaResp.heroes:type_name -> DBHero + 26, // 13: HeroProperty.property:type_name -> HeroProperty.PropertyEntry + 27, // 14: HeroProperty.addProperty:type_name -> HeroProperty.AddPropertyEntry + 28, // 15: HeroLockResp.hero:type_name -> DBHero + 28, // 16: AddNewHeroPush.hero:type_name -> DBHero + 17, // [17:17] is the sub-list for method output_type + 17, // [17:17] is the sub-list for method input_type + 17, // [17:17] is the sub-list for extension type_name + 17, // [17:17] is the sub-list for extension extendee + 0, // [0:17] is the sub-list for field type_name } func init() { file_hero_hero_msg_proto_init() } @@ -1822,6 +1875,18 @@ func file_hero_hero_msg_proto_init() { return nil } } + file_hero_hero_msg_proto_msgTypes[25].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AddNewHeroPush); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1829,7 +1894,7 @@ func file_hero_hero_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_hero_hero_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 27, + NumMessages: 28, NumExtensions: 0, NumServices: 0, }, diff --git a/pb/items_msg.pb.go b/pb/items_msg.pb.go index 82183d34f..52347d417 100644 --- a/pb/items_msg.pb.go +++ b/pb/items_msg.pb.go @@ -116,6 +116,54 @@ func (x *ItemsGetlistResp) GetGrids() []*DB_UserItemData { return nil } +//背包变化推送 +type ItemsChangePush struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Grids []*DB_UserItemData `protobuf:"bytes,1,rep,name=Grids,proto3" json:"Grids"` //变化数据 +} + +func (x *ItemsChangePush) Reset() { + *x = ItemsChangePush{} + if protoimpl.UnsafeEnabled { + mi := &file_items_items_msg_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ItemsChangePush) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ItemsChangePush) ProtoMessage() {} + +func (x *ItemsChangePush) ProtoReflect() protoreflect.Message { + mi := &file_items_items_msg_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ItemsChangePush.ProtoReflect.Descriptor instead. +func (*ItemsChangePush) Descriptor() ([]byte, []int) { + return file_items_items_msg_proto_rawDescGZIP(), []int{2} +} + +func (x *ItemsChangePush) GetGrids() []*DB_UserItemData { + if x != nil { + return x.Grids + } + return nil +} + //使用物品请求 type ItemsUseItemReq struct { state protoimpl.MessageState @@ -130,7 +178,7 @@ type ItemsUseItemReq struct { func (x *ItemsUseItemReq) Reset() { *x = ItemsUseItemReq{} if protoimpl.UnsafeEnabled { - mi := &file_items_items_msg_proto_msgTypes[2] + mi := &file_items_items_msg_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -143,7 +191,7 @@ func (x *ItemsUseItemReq) String() string { func (*ItemsUseItemReq) ProtoMessage() {} func (x *ItemsUseItemReq) ProtoReflect() protoreflect.Message { - mi := &file_items_items_msg_proto_msgTypes[2] + mi := &file_items_items_msg_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -156,7 +204,7 @@ func (x *ItemsUseItemReq) ProtoReflect() protoreflect.Message { // Deprecated: Use ItemsUseItemReq.ProtoReflect.Descriptor instead. func (*ItemsUseItemReq) Descriptor() ([]byte, []int) { - return file_items_items_msg_proto_rawDescGZIP(), []int{2} + return file_items_items_msg_proto_rawDescGZIP(), []int{3} } func (x *ItemsUseItemReq) GetGridId() string { @@ -190,7 +238,7 @@ type ItemsUseItemResp struct { func (x *ItemsUseItemResp) Reset() { *x = ItemsUseItemResp{} if protoimpl.UnsafeEnabled { - mi := &file_items_items_msg_proto_msgTypes[3] + mi := &file_items_items_msg_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -203,7 +251,7 @@ func (x *ItemsUseItemResp) String() string { func (*ItemsUseItemResp) ProtoMessage() {} func (x *ItemsUseItemResp) ProtoReflect() protoreflect.Message { - mi := &file_items_items_msg_proto_msgTypes[3] + mi := &file_items_items_msg_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -216,7 +264,7 @@ func (x *ItemsUseItemResp) ProtoReflect() protoreflect.Message { // Deprecated: Use ItemsUseItemResp.ProtoReflect.Descriptor instead. func (*ItemsUseItemResp) Descriptor() ([]byte, []int) { - return file_items_items_msg_proto_rawDescGZIP(), []int{3} + return file_items_items_msg_proto_rawDescGZIP(), []int{4} } //出售道具请求sailitem @@ -233,7 +281,7 @@ type ItemsSellItemReq struct { func (x *ItemsSellItemReq) Reset() { *x = ItemsSellItemReq{} if protoimpl.UnsafeEnabled { - mi := &file_items_items_msg_proto_msgTypes[4] + mi := &file_items_items_msg_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -246,7 +294,7 @@ func (x *ItemsSellItemReq) String() string { func (*ItemsSellItemReq) ProtoMessage() {} func (x *ItemsSellItemReq) ProtoReflect() protoreflect.Message { - mi := &file_items_items_msg_proto_msgTypes[4] + mi := &file_items_items_msg_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -259,7 +307,7 @@ func (x *ItemsSellItemReq) ProtoReflect() protoreflect.Message { // Deprecated: Use ItemsSellItemReq.ProtoReflect.Descriptor instead. func (*ItemsSellItemReq) Descriptor() ([]byte, []int) { - return file_items_items_msg_proto_rawDescGZIP(), []int{4} + return file_items_items_msg_proto_rawDescGZIP(), []int{5} } func (x *ItemsSellItemReq) GetGridId() string { @@ -293,7 +341,7 @@ type ItemsSellItemResp struct { func (x *ItemsSellItemResp) Reset() { *x = ItemsSellItemResp{} if protoimpl.UnsafeEnabled { - mi := &file_items_items_msg_proto_msgTypes[5] + mi := &file_items_items_msg_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -306,7 +354,7 @@ func (x *ItemsSellItemResp) String() string { func (*ItemsSellItemResp) ProtoMessage() {} func (x *ItemsSellItemResp) ProtoReflect() protoreflect.Message { - mi := &file_items_items_msg_proto_msgTypes[5] + mi := &file_items_items_msg_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -319,7 +367,7 @@ func (x *ItemsSellItemResp) ProtoReflect() protoreflect.Message { // Deprecated: Use ItemsSellItemResp.ProtoReflect.Descriptor instead. func (*ItemsSellItemResp) Descriptor() ([]byte, []int) { - return file_items_items_msg_proto_rawDescGZIP(), []int{5} + return file_items_items_msg_proto_rawDescGZIP(), []int{6} } var File_items_items_msg_proto protoreflect.FileDescriptor @@ -334,22 +382,25 @@ var file_items_items_msg_proto_rawDesc = []byte{ 0x65, 0x74, 0x6c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x26, 0x0a, 0x05, 0x47, 0x72, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x49, 0x74, 0x65, 0x6d, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x47, 0x72, 0x69, - 0x64, 0x73, 0x22, 0x59, 0x0a, 0x0f, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x55, 0x73, 0x65, 0x49, 0x74, - 0x65, 0x6d, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x12, 0x16, 0x0a, - 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x49, - 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x12, 0x0a, - 0x10, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x55, 0x73, 0x65, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x73, - 0x70, 0x22, 0x5a, 0x0a, 0x10, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x53, 0x65, 0x6c, 0x6c, 0x49, 0x74, - 0x65, 0x6d, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x12, 0x16, 0x0a, - 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x49, - 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x13, 0x0a, - 0x11, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x53, 0x65, 0x6c, 0x6c, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x65, - 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x64, 0x73, 0x22, 0x39, 0x0a, 0x0f, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x50, 0x75, 0x73, 0x68, 0x12, 0x26, 0x0a, 0x05, 0x47, 0x72, 0x69, 0x64, 0x73, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x49, 0x74, + 0x65, 0x6d, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x47, 0x72, 0x69, 0x64, 0x73, 0x22, 0x59, 0x0a, + 0x0f, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x55, 0x73, 0x65, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x71, + 0x12, 0x16, 0x0a, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d, + 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, + 0x12, 0x16, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x12, 0x0a, 0x10, 0x49, 0x74, 0x65, 0x6d, + 0x73, 0x55, 0x73, 0x65, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x22, 0x5a, 0x0a, 0x10, + 0x49, 0x74, 0x65, 0x6d, 0x73, 0x53, 0x65, 0x6c, 0x6c, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x71, + 0x12, 0x16, 0x0a, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d, + 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, + 0x12, 0x16, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x13, 0x0a, 0x11, 0x49, 0x74, 0x65, 0x6d, + 0x73, 0x53, 0x65, 0x6c, 0x6c, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, + 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -364,23 +415,25 @@ func file_items_items_msg_proto_rawDescGZIP() []byte { return file_items_items_msg_proto_rawDescData } -var file_items_items_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_items_items_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_items_items_msg_proto_goTypes = []interface{}{ (*ItemsGetlistReq)(nil), // 0: ItemsGetlistReq (*ItemsGetlistResp)(nil), // 1: ItemsGetlistResp - (*ItemsUseItemReq)(nil), // 2: ItemsUseItemReq - (*ItemsUseItemResp)(nil), // 3: ItemsUseItemResp - (*ItemsSellItemReq)(nil), // 4: ItemsSellItemReq - (*ItemsSellItemResp)(nil), // 5: ItemsSellItemResp - (*DB_UserItemData)(nil), // 6: DB_UserItemData + (*ItemsChangePush)(nil), // 2: ItemsChangePush + (*ItemsUseItemReq)(nil), // 3: ItemsUseItemReq + (*ItemsUseItemResp)(nil), // 4: ItemsUseItemResp + (*ItemsSellItemReq)(nil), // 5: ItemsSellItemReq + (*ItemsSellItemResp)(nil), // 6: ItemsSellItemResp + (*DB_UserItemData)(nil), // 7: DB_UserItemData } var file_items_items_msg_proto_depIdxs = []int32{ - 6, // 0: ItemsGetlistResp.Grids:type_name -> DB_UserItemData - 1, // [1:1] is the sub-list for method output_type - 1, // [1:1] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 7, // 0: ItemsGetlistResp.Grids:type_name -> DB_UserItemData + 7, // 1: ItemsChangePush.Grids:type_name -> DB_UserItemData + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_items_items_msg_proto_init() } @@ -415,7 +468,7 @@ func file_items_items_msg_proto_init() { } } file_items_items_msg_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ItemsUseItemReq); i { + switch v := v.(*ItemsChangePush); i { case 0: return &v.state case 1: @@ -427,7 +480,7 @@ func file_items_items_msg_proto_init() { } } file_items_items_msg_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ItemsUseItemResp); i { + switch v := v.(*ItemsUseItemReq); i { case 0: return &v.state case 1: @@ -439,7 +492,7 @@ func file_items_items_msg_proto_init() { } } file_items_items_msg_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ItemsSellItemReq); i { + switch v := v.(*ItemsUseItemResp); i { case 0: return &v.state case 1: @@ -451,6 +504,18 @@ func file_items_items_msg_proto_init() { } } file_items_items_msg_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ItemsSellItemReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_items_items_msg_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ItemsSellItemResp); i { case 0: return &v.state @@ -469,7 +534,7 @@ func file_items_items_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_items_items_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 6, + NumMessages: 7, NumExtensions: 0, NumServices: 0, }, diff --git a/pb/proto/equipment/equipment_msg.proto b/pb/proto/equipment/equipment_msg.proto index 22587d42f..ebedb3487 100644 --- a/pb/proto/equipment/equipment_msg.proto +++ b/pb/proto/equipment/equipment_msg.proto @@ -11,6 +11,11 @@ message EquipmentGetListResp { repeated DB_Equipment Equipments = 1; //装备列表 } +//推送装备背包变化 +message EquipmentChangePush { + repeated DB_Equipment Equipments = 1; //装备列表 +} + //装备挂在到英雄上 message EquipmentEquipReq{ string HeroCardId = 1; //英雄卡Id diff --git a/pb/proto/errorcode.proto b/pb/proto/errorcode.proto index 9f8b44fb9..19ad83a53 100644 --- a/pb/proto/errorcode.proto +++ b/pb/proto/errorcode.proto @@ -66,6 +66,7 @@ enum ErrorCode { HeroEquipUpdate = 1311; // 更新装备失败 HeroMaxAwaken = 1312; // 达到最大觉醒等级 HeroIsLock = 1313; // 英雄被锁定不能被消耗 + HeroMaxCount = 1314; // 英雄达到最大数量 // equipment EquipmentOnFoundEquipment = 1400; // 未找到武器 diff --git a/pb/proto/hero/hero_msg.proto b/pb/proto/hero/hero_msg.proto index bdbc9b2d6..431f626ae 100644 --- a/pb/proto/hero/hero_msg.proto +++ b/pb/proto/hero/hero_msg.proto @@ -124,4 +124,9 @@ message HeroLockReq{ // 英雄锁定返回 message HeroLockResp{ DBHero hero = 1; // 英雄对象 +} + +// 增加新英雄推送 +message AddNewHeroPush{ + DBHero hero = 1; // 英雄对象 } \ No newline at end of file diff --git a/pb/proto/items/items_msg.proto b/pb/proto/items/items_msg.proto index 83f52391c..820f2e23f 100644 --- a/pb/proto/items/items_msg.proto +++ b/pb/proto/items/items_msg.proto @@ -12,6 +12,11 @@ message ItemsGetlistResp { repeated DB_UserItemData Grids = 1; //用户背包列表 } +//背包变化推送 +message ItemsChangePush { + repeated DB_UserItemData Grids = 1; //变化数据 +} + //使用物品请求 message ItemsUseItemReq { string GridId = 1; //格子Id diff --git a/pb/proto/user/user_msg.proto b/pb/proto/user/user_msg.proto index 221e358e0..6568c976d 100644 --- a/pb/proto/user/user_msg.proto +++ b/pb/proto/user/user_msg.proto @@ -39,3 +39,11 @@ message UserAddResResp { UserAssets res = 1; //资源类型 } +// 玩家资源变更推送 +message UserResChangePush{ + int32 gold = 1; //@go_tags(`bson:"gold"`) 金币 + int32 exp = 2; //@go_tags(`bson:"exp"`) 经验 + int32 lv = 3; //@go_tags(`bson:"lv"`) 等级 + int32 vip = 4; //@go_tags(`bson:"vip"`) vip + int32 diamond = 5; //@go_tags(`bson:"diamond"`) 钻石 +} diff --git a/pb/user_msg.pb.go b/pb/user_msg.pb.go index 4115f7259..bc80f24d8 100644 --- a/pb/user_msg.pb.go +++ b/pb/user_msg.pb.go @@ -461,6 +461,86 @@ func (x *UserAddResResp) GetRes() *UserAssets { return nil } +// 玩家资源变更推送 +type UserResChangePush struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Gold int32 `protobuf:"varint,1,opt,name=gold,proto3" json:"gold" bson:"gold"` //金币 + Exp int32 `protobuf:"varint,2,opt,name=exp,proto3" json:"exp" bson:"exp"` //经验 + Lv int32 `protobuf:"varint,3,opt,name=lv,proto3" json:"lv" bson:"lv"` //等级 + Vip int32 `protobuf:"varint,4,opt,name=vip,proto3" json:"vip" bson:"vip"` // vip + Diamond int32 `protobuf:"varint,5,opt,name=diamond,proto3" json:"diamond" bson:"diamond"` // 钻石 +} + +func (x *UserResChangePush) Reset() { + *x = UserResChangePush{} + if protoimpl.UnsafeEnabled { + mi := &file_user_user_msg_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UserResChangePush) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UserResChangePush) ProtoMessage() {} + +func (x *UserResChangePush) ProtoReflect() protoreflect.Message { + mi := &file_user_user_msg_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UserResChangePush.ProtoReflect.Descriptor instead. +func (*UserResChangePush) Descriptor() ([]byte, []int) { + return file_user_user_msg_proto_rawDescGZIP(), []int{9} +} + +func (x *UserResChangePush) GetGold() int32 { + if x != nil { + return x.Gold + } + return 0 +} + +func (x *UserResChangePush) GetExp() int32 { + if x != nil { + return x.Exp + } + return 0 +} + +func (x *UserResChangePush) GetLv() int32 { + if x != nil { + return x.Lv + } + return 0 +} + +func (x *UserResChangePush) GetVip() int32 { + if x != nil { + return x.Vip + } + return 0 +} + +func (x *UserResChangePush) GetDiamond() int32 { + if x != nil { + return x.Diamond + } + return 0 +} + var File_user_user_msg_proto protoreflect.FileDescriptor var file_user_user_msg_proto_rawDesc = []byte{ @@ -496,8 +576,16 @@ var file_user_user_msg_proto_rawDesc = []byte{ 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x03, 0x72, 0x65, 0x73, 0x22, 0x2f, 0x0a, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1d, 0x0a, 0x03, 0x72, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x55, 0x73, - 0x65, 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x03, 0x72, 0x65, 0x73, 0x42, 0x06, 0x5a, - 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x03, 0x72, 0x65, 0x73, 0x22, 0x75, 0x0a, + 0x11, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, + 0x73, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x67, 0x6f, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x04, 0x67, 0x6f, 0x6c, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x78, 0x70, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x78, 0x70, 0x12, 0x0e, 0x0a, 0x02, 0x6c, 0x76, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x6c, 0x76, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x69, 0x70, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x69, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x69, + 0x61, 0x6d, 0x6f, 0x6e, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x64, 0x69, 0x61, + 0x6d, 0x6f, 0x6e, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -512,28 +600,29 @@ func file_user_user_msg_proto_rawDescGZIP() []byte { return file_user_user_msg_proto_rawDescData } -var file_user_user_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_user_user_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 10) var file_user_user_msg_proto_goTypes = []interface{}{ - (*UserLoginReq)(nil), // 0: UserLoginReq - (*UserLoginResp)(nil), // 1: UserLoginResp - (*UserRegisterReq)(nil), // 2: UserRegisterReq - (*UserRegisterResp)(nil), // 3: UserRegisterResp - (*UserLoadResp)(nil), // 4: UserLoadResp - (*UserCreateReq)(nil), // 5: UserCreateReq - (*UserCreateResp)(nil), // 6: UserCreateResp - (*UserAddResReq)(nil), // 7: UserAddResReq - (*UserAddResResp)(nil), // 8: UserAddResResp - (*DBUser)(nil), // 9: DBUser - (ErrorCode)(0), // 10: ErrorCode - (*CacheUser)(nil), // 11: CacheUser - (*UserAssets)(nil), // 12: UserAssets + (*UserLoginReq)(nil), // 0: UserLoginReq + (*UserLoginResp)(nil), // 1: UserLoginResp + (*UserRegisterReq)(nil), // 2: UserRegisterReq + (*UserRegisterResp)(nil), // 3: UserRegisterResp + (*UserLoadResp)(nil), // 4: UserLoadResp + (*UserCreateReq)(nil), // 5: UserCreateReq + (*UserCreateResp)(nil), // 6: UserCreateResp + (*UserAddResReq)(nil), // 7: UserAddResReq + (*UserAddResResp)(nil), // 8: UserAddResResp + (*UserResChangePush)(nil), // 9: UserResChangePush + (*DBUser)(nil), // 10: DBUser + (ErrorCode)(0), // 11: ErrorCode + (*CacheUser)(nil), // 12: CacheUser + (*UserAssets)(nil), // 13: UserAssets } var file_user_user_msg_proto_depIdxs = []int32{ - 9, // 0: UserLoginResp.data:type_name -> DBUser - 10, // 1: UserRegisterResp.Code:type_name -> ErrorCode - 11, // 2: UserLoadResp.data:type_name -> CacheUser - 12, // 3: UserAddResReq.res:type_name -> UserAssets - 12, // 4: UserAddResResp.res:type_name -> UserAssets + 10, // 0: UserLoginResp.data:type_name -> DBUser + 11, // 1: UserRegisterResp.Code:type_name -> ErrorCode + 12, // 2: UserLoadResp.data:type_name -> CacheUser + 13, // 3: UserAddResReq.res:type_name -> UserAssets + 13, // 4: UserAddResResp.res:type_name -> UserAssets 5, // [5:5] is the sub-list for method output_type 5, // [5:5] is the sub-list for method input_type 5, // [5:5] is the sub-list for extension type_name @@ -658,6 +747,18 @@ func file_user_user_msg_proto_init() { return nil } } + file_user_user_msg_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UserResChangePush); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -665,7 +766,7 @@ func file_user_user_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_user_user_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 9, + NumMessages: 10, NumExtensions: 0, NumServices: 0, }, diff --git a/utils/base64.go b/utils/base64.go index f67b82908..207ed098b 100644 --- a/utils/base64.go +++ b/utils/base64.go @@ -28,7 +28,7 @@ func ValidSecretKey(secStr string) bool { clientMd5Key := secStr[3:35] rawmsg := secStr[35:] - log.Debugf("data base: %s", rawmsg) - serverMd5Key := MD5Str(rawmsg) //这里可以再加上客户端和服务端的秘钥再MD5 + // log.Debugf("data base: %s", rawmsg) + serverMd5Key := MD5Str(rawmsg) //这里可以再加上客户端和服务端的秘钥再MD5 return strings.EqualFold(strings.ToLower(serverMd5Key), strings.ToLower(clientMd5Key)) }