From d8b971481d385fdccfc50a55cc2f9ee10d277fee Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Sat, 18 Jan 2025 13:19:04 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=8E=A8=E5=B8=81=E6=9C=BA=E5=A5=96?= =?UTF-8?q?=E6=B1=A0=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/internal/push_coin_pool.go | 277 +++++++++++++++++++++++++++++++ dao/push_coin_pool.go | 67 ++++++++ dbproxy/svc/l_pushcoin.go | 54 ++++++ model/pushcoin.go | 77 +++++++++ protocol/activity/pushcoin.pb.go | 169 ++++++++++++++----- protocol/activity/pushcoin.proto | 8 + worldsrv/action_pushcoin.go | 12 +- worldsrv/activity_pushcoin.go | 50 +++--- 8 files changed, 646 insertions(+), 68 deletions(-) create mode 100644 dao/internal/push_coin_pool.go create mode 100644 dao/push_coin_pool.go create mode 100644 dbproxy/svc/l_pushcoin.go create mode 100644 model/pushcoin.go diff --git a/dao/internal/push_coin_pool.go b/dao/internal/push_coin_pool.go new file mode 100644 index 0000000..7bbe7f6 --- /dev/null +++ b/dao/internal/push_coin_pool.go @@ -0,0 +1,277 @@ +// -------------------------------------------------------------------------------------------- +// The following code is automatically generated by the mongo-dao-generator tool. +// Please do not modify this code manually to avoid being overwritten in the next generation. +// For more tool details, please click the link to view https://github.com/dobyte/mongo-dao-generator +// -------------------------------------------------------------------------------------------- + +package internal + +import ( + "context" + "errors" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + modelpkg "mongo.games.com/game/model" +) + +type PushCoinPoolFilterFunc func(cols *PushCoinPoolColumns) interface{} +type PushCoinPoolUpdateFunc func(cols *PushCoinPoolColumns) interface{} +type PushCoinPoolPipelineFunc func(cols *PushCoinPoolColumns) interface{} +type PushCoinPoolCountOptionsFunc func(cols *PushCoinPoolColumns) *options.CountOptions +type PushCoinPoolAggregateOptionsFunc func(cols *PushCoinPoolColumns) *options.AggregateOptions +type PushCoinPoolFindOneOptionsFunc func(cols *PushCoinPoolColumns) *options.FindOneOptions +type PushCoinPoolFindManyOptionsFunc func(cols *PushCoinPoolColumns) *options.FindOptions +type PushCoinPoolUpdateOptionsFunc func(cols *PushCoinPoolColumns) *options.UpdateOptions +type PushCoinPoolDeleteOptionsFunc func(cols *PushCoinPoolColumns) *options.DeleteOptions +type PushCoinPoolInsertOneOptionsFunc func(cols *PushCoinPoolColumns) *options.InsertOneOptions +type PushCoinPoolInsertManyOptionsFunc func(cols *PushCoinPoolColumns) *options.InsertManyOptions + +type PushCoinPool struct { + Columns *PushCoinPoolColumns + Database *mongo.Database + Collection *mongo.Collection +} + +type PushCoinPoolColumns struct { + ID string + Pool1 string + Pool2 string + Pool3 string +} + +var pushCoinPoolColumns = &PushCoinPoolColumns{ + ID: "_id", + Pool1: "pool1", + Pool2: "pool2", + Pool3: "pool3", +} + +func NewPushCoinPool() *PushCoinPool { + return &PushCoinPool{ + Columns: pushCoinPoolColumns, + } +} + +// Count returns the number of documents in the collection. +func (dao *PushCoinPool) Count(ctx context.Context, filterFunc PushCoinPoolFilterFunc, optionsFunc ...PushCoinPoolCountOptionsFunc) (int64, error) { + var ( + opts *options.CountOptions + filter = filterFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.CountDocuments(ctx, filter, opts) +} + +// Aggregate executes an aggregate command against the collection and returns a cursor over the resulting documents. +func (dao *PushCoinPool) Aggregate(ctx context.Context, pipelineFunc PushCoinPoolPipelineFunc, optionsFunc ...PushCoinPoolAggregateOptionsFunc) (*mongo.Cursor, error) { + var ( + opts *options.AggregateOptions + pipeline = pipelineFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.Aggregate(ctx, pipeline, opts) +} + +// InsertOne executes an insert command to insert a single document into the collection. +func (dao *PushCoinPool) InsertOne(ctx context.Context, model *modelpkg.PushCoinPool, optionsFunc ...PushCoinPoolInsertOneOptionsFunc) (*mongo.InsertOneResult, error) { + if model == nil { + return nil, errors.New("model is nil") + } + + if err := dao.autofill(ctx, model); err != nil { + return nil, err + } + + var opts *options.InsertOneOptions + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.InsertOne(ctx, model, opts) +} + +// InsertMany executes an insert command to insert multiple documents into the collection. +func (dao *PushCoinPool) InsertMany(ctx context.Context, models []*modelpkg.PushCoinPool, optionsFunc ...PushCoinPoolInsertManyOptionsFunc) (*mongo.InsertManyResult, error) { + if len(models) == 0 { + return nil, errors.New("models is empty") + } + + documents := make([]interface{}, 0, len(models)) + for i := range models { + model := models[i] + if err := dao.autofill(ctx, model); err != nil { + return nil, err + } + documents = append(documents, model) + } + + var opts *options.InsertManyOptions + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.InsertMany(ctx, documents, opts) +} + +// UpdateOne executes an update command to update at most one document in the collection. +func (dao *PushCoinPool) UpdateOne(ctx context.Context, filterFunc PushCoinPoolFilterFunc, updateFunc PushCoinPoolUpdateFunc, optionsFunc ...PushCoinPoolUpdateOptionsFunc) (*mongo.UpdateResult, error) { + var ( + opts *options.UpdateOptions + filter = filterFunc(dao.Columns) + update = updateFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.UpdateOne(ctx, filter, update, opts) +} + +// UpdateOneByID executes an update command to update at most one document in the collection. +func (dao *PushCoinPool) UpdateOneByID(ctx context.Context, id string, updateFunc PushCoinPoolUpdateFunc, optionsFunc ...PushCoinPoolUpdateOptionsFunc) (*mongo.UpdateResult, error) { + objectID, err := primitive.ObjectIDFromHex(id) + if err != nil { + return nil, err + } + + return dao.UpdateOne(ctx, func(cols *PushCoinPoolColumns) interface{} { + return bson.M{"_id": objectID} + }, updateFunc, optionsFunc...) +} + +// UpdateMany executes an update command to update documents in the collection. +func (dao *PushCoinPool) UpdateMany(ctx context.Context, filterFunc PushCoinPoolFilterFunc, updateFunc PushCoinPoolUpdateFunc, optionsFunc ...PushCoinPoolUpdateOptionsFunc) (*mongo.UpdateResult, error) { + var ( + opts *options.UpdateOptions + filter = filterFunc(dao.Columns) + update = updateFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.UpdateMany(ctx, filter, update, opts) +} + +// FindOne executes a find command and returns a model for one document in the collection. +func (dao *PushCoinPool) FindOne(ctx context.Context, filterFunc PushCoinPoolFilterFunc, optionsFunc ...PushCoinPoolFindOneOptionsFunc) (*modelpkg.PushCoinPool, error) { + var ( + opts *options.FindOneOptions + model = &modelpkg.PushCoinPool{} + filter = filterFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + err := dao.Collection.FindOne(ctx, filter, opts).Decode(model) + if err != nil { + if err == mongo.ErrNoDocuments { + return nil, nil + } + return nil, err + } + + return model, nil +} + +// FindOneByID executes a find command and returns a model for one document in the collection. +func (dao *PushCoinPool) FindOneByID(ctx context.Context, id string, optionsFunc ...PushCoinPoolFindOneOptionsFunc) (*modelpkg.PushCoinPool, error) { + objectID, err := primitive.ObjectIDFromHex(id) + if err != nil { + return nil, err + } + + return dao.FindOne(ctx, func(cols *PushCoinPoolColumns) interface{} { + return bson.M{"_id": objectID} + }, optionsFunc...) +} + +// FindMany executes a find command and returns many models the matching documents in the collection. +func (dao *PushCoinPool) FindMany(ctx context.Context, filterFunc PushCoinPoolFilterFunc, optionsFunc ...PushCoinPoolFindManyOptionsFunc) ([]*modelpkg.PushCoinPool, error) { + var ( + opts *options.FindOptions + filter = filterFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + cur, err := dao.Collection.Find(ctx, filter, opts) + if err != nil { + return nil, err + } + + models := make([]*modelpkg.PushCoinPool, 0) + + if err = cur.All(ctx, &models); err != nil { + return nil, err + } + + return models, nil +} + +// DeleteOne executes a delete command to delete at most one document from the collection. +func (dao *PushCoinPool) DeleteOne(ctx context.Context, filterFunc PushCoinPoolFilterFunc, optionsFunc ...PushCoinPoolDeleteOptionsFunc) (*mongo.DeleteResult, error) { + var ( + opts *options.DeleteOptions + filter = filterFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.DeleteOne(ctx, filter, opts) +} + +// DeleteOneByID executes a delete command to delete at most one document from the collection. +func (dao *PushCoinPool) DeleteOneByID(ctx context.Context, id string, optionsFunc ...PushCoinPoolDeleteOptionsFunc) (*mongo.DeleteResult, error) { + objectID, err := primitive.ObjectIDFromHex(id) + if err != nil { + return nil, err + } + + return dao.DeleteOne(ctx, func(cols *PushCoinPoolColumns) interface{} { + return bson.M{"_id": objectID} + }, optionsFunc...) +} + +// DeleteMany executes a delete command to delete documents from the collection. +func (dao *PushCoinPool) DeleteMany(ctx context.Context, filterFunc PushCoinPoolFilterFunc, optionsFunc ...PushCoinPoolDeleteOptionsFunc) (*mongo.DeleteResult, error) { + var ( + opts *options.DeleteOptions + filter = filterFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.DeleteMany(ctx, filter, opts) +} + +// autofill when inserting data +func (dao *PushCoinPool) autofill(ctx context.Context, model *modelpkg.PushCoinPool) error { + if model.ID.IsZero() { + model.ID = primitive.NewObjectID() + } + + return nil +} diff --git a/dao/push_coin_pool.go b/dao/push_coin_pool.go new file mode 100644 index 0000000..ca4e4f1 --- /dev/null +++ b/dao/push_coin_pool.go @@ -0,0 +1,67 @@ +package dao + +import ( + "context" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + "mongo.games.com/goserver/core/logger" + "mongo.games.com/goserver/core/mongox" + + "mongo.games.com/game/dao/internal" + modelpkg "mongo.games.com/game/model" +) + +var ( + _ = context.Background() + _ = logger.Logger + _ = bson.M{} + _ = mongo.Database{} +) + +type PushCoinPoolColumns = internal.PushCoinPoolColumns + +type PushCoinPool struct { + *internal.PushCoinPool +} + +func GetPushCoinPool(key string) (*PushCoinPool, error) { + return mongox.GetDao(key, NewPushCoinPool) +} + +func NewPushCoinPool(db *mongo.Database, c *mongo.Collection) (*PushCoinPool, any) { + if db == nil || c == nil { + return &PushCoinPool{}, &modelpkg.PushCoinPool{} + } + + v := internal.NewPushCoinPool() + v.Database = db + v.Collection = c + + return &PushCoinPool{PushCoinPool: v}, &modelpkg.PushCoinPool{} +} + +func (p *PushCoinPool) Load() (*modelpkg.PushCoinPool, error) { + ret, err := p.FindOne(context.Background(), func(cols *internal.PushCoinPoolColumns) interface{} { + return bson.M{} + }) + if err != nil { + logger.Logger.Errorf("PushCoinPool FindOne error: %v", err) + return nil, err + } + + return ret, nil +} + +func (p *PushCoinPool) Save(data *modelpkg.PushCoinPool) error { + _, err := p.UpdateOneByID(context.Background(), data.ID.Hex(), func(cols *internal.PushCoinPoolColumns) interface{} { + return bson.M{"$set": data} + }, func(cols *internal.PushCoinPoolColumns) *options.UpdateOptions { + return options.Update().SetUpsert(true) + }) + if err != nil { + logger.Logger.Error("PushCoinPool.Save ", err) + return err + } + return nil +} diff --git a/dbproxy/svc/l_pushcoin.go b/dbproxy/svc/l_pushcoin.go new file mode 100644 index 0000000..f5212ba --- /dev/null +++ b/dbproxy/svc/l_pushcoin.go @@ -0,0 +1,54 @@ +package svc + +import ( + "mongo.games.com/game/dao" + "mongo.games.com/game/model" + "mongo.games.com/goserver/core/logger" + "net/rpc" +) + +var PushCoinSvc = new(PushCoinService) + +type PushCoinService struct { +} + +func (p *PushCoinService) Load(plt *string, ret *model.PushCoinPool) error { + m, err := dao.GetPushCoinPool(*plt) + if err != nil { + logger.Logger.Errorf("PushCoinPool dao error: %v", err) + return err + } + + r, err := m.Load() + if err != nil { + logger.Logger.Errorf("PushCoinPool Load error: %v", err) + return err + } + + if r != nil { + *ret = *r + } + + return nil +} + +func (p *PushCoinService) Save(d *model.PushCoinPool, ret *bool) error { + m, err := dao.GetPushCoinPool(d.Platform) + if err != nil { + logger.Logger.Errorf("PushCoinPool dao error: %v", err) + return err + } + + if err = m.Save(d); err != nil { + logger.Logger.Errorf("PushCoinPool Save error: %v", err) + return err + } + + *ret = true + + return nil +} + +func init() { + rpc.Register(PushCoinSvc) +} diff --git a/model/pushcoin.go b/model/pushcoin.go new file mode 100644 index 0000000..b188ec6 --- /dev/null +++ b/model/pushcoin.go @@ -0,0 +1,77 @@ +package model + +import ( + "errors" + "go.mongodb.org/mongo-driver/bson/primitive" + "mongo.games.com/goserver/core/logger" + "time" +) + +//go:generate mongoctl -model-dir=. -model-names=PushCoinPool -dao-dir=../dao/ +type PushCoinPool struct { + Platform string `bson:"-"` + ID primitive.ObjectID `bson:"_id" gen:"autoFill"` + Pool1 *PushCoinPoolInfo `bson:"pool1"` + Pool2 *PushCoinPoolInfo `bson:"pool2"` + Pool3 *PushCoinPoolInfo `bson:"pool3"` +} + +type PushCoinPoolInfo struct { + CurCoin int64 `bson:"curcoin"` // 当前金币 + Remain int64 `bson:"remain"` // 剩余金币 + Version int64 `bson:"version"` // 版本号, 达到上限后更新 +} + +func NewPushCoinPool(plt string) *PushCoinPool { + return &PushCoinPool{ + Platform: plt, + ID: primitive.NewObjectID(), + Pool1: &PushCoinPoolInfo{}, + Pool2: &PushCoinPoolInfo{}, + Pool3: &PushCoinPoolInfo{}, + } + +} + +func (p *PushCoinPool) TableName() string { + return "pushcoin_pool" +} + +func (p *PushCoinPool) DatabaseName() string { + return "log" +} + +func PushCoinLoad(plt string) (*PushCoinPool, error) { + if rpcCli == nil { + logger.Logger.Error("model.PushCoinLoad rpcCli == nil") + return nil, errors.New("rpc client is nil") + } + + res := &PushCoinPool{} + err := rpcCli.CallWithTimeout("PushCoinService.Load", &plt, res, time.Second*30) + if err != nil { + logger.Logger.Errorf("PushCoinLoad error: %v", err) + return nil, err + } + if res.ID.IsZero() { + res = NewPushCoinPool(plt) + } + + return res, nil +} + +func PushCoinSave(data *PushCoinPool) error { + if rpcCli == nil { + logger.Logger.Error("model.PushCoinSave rpcCli == nil") + return errors.New("rpc client is nil") + } + + ret := false + err := rpcCli.CallWithTimeout("PushCoinService.Save", data, &ret, time.Second*30) + if err != nil { + logger.Logger.Errorf("PushCoinSave error: %v", err) + return err + } + + return nil +} diff --git a/protocol/activity/pushcoin.pb.go b/protocol/activity/pushcoin.pb.go index b9dd293..d355bf9 100644 --- a/protocol/activity/pushcoin.pb.go +++ b/protocol/activity/pushcoin.pb.go @@ -30,6 +30,7 @@ const ( PushCoinPacketID_PACKET_SCPushCoinPlayerOp PushCoinPacketID = 2683 // 玩家操作返回 PushCoinPacketID_PACKET_NotifyPowerLine PushCoinPacketID = 2684 // 通知能量值 PushCoinPacketID_PACKET_NotifyDrawInfo PushCoinPacketID = 2685 // 抽奖信息 + PushCoinPacketID_PACKET_NotifyAward PushCoinPacketID = 2686 // 广播中奖信息 ) // Enum value maps for PushCoinPacketID. @@ -42,6 +43,7 @@ var ( 2683: "PACKET_SCPushCoinPlayerOp", 2684: "PACKET_NotifyPowerLine", 2685: "PACKET_NotifyDrawInfo", + 2686: "PACKET_NotifyAward", } PushCoinPacketID_value = map[string]int32{ "PACKET_PushCoin_ZERO": 0, @@ -51,6 +53,7 @@ var ( "PACKET_SCPushCoinPlayerOp": 2683, "PACKET_NotifyPowerLine": 2684, "PACKET_NotifyDrawInfo": 2685, + "PACKET_NotifyAward": 2686, } ) @@ -781,6 +784,63 @@ func (x *NotifyPowerLine) GetPowerLineMax() int64 { return 0 } +//广播中奖信息 +//PACKET_NotifyAward +type NotifyAward struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Draw *DrawInfo `protobuf:"bytes,1,opt,name=Draw,proto3" json:"Draw,omitempty"` // 中奖信息 + Name string `protobuf:"bytes,2,opt,name=Name,proto3" json:"Name,omitempty"` // 玩家名字 +} + +func (x *NotifyAward) Reset() { + *x = NotifyAward{} + if protoimpl.UnsafeEnabled { + mi := &file_protocol_activity_pushcoin_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *NotifyAward) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NotifyAward) ProtoMessage() {} + +func (x *NotifyAward) ProtoReflect() protoreflect.Message { + mi := &file_protocol_activity_pushcoin_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 NotifyAward.ProtoReflect.Descriptor instead. +func (*NotifyAward) Descriptor() ([]byte, []int) { + return file_protocol_activity_pushcoin_proto_rawDescGZIP(), []int{9} +} + +func (x *NotifyAward) GetDraw() *DrawInfo { + if x != nil { + return x.Draw + } + return nil +} + +func (x *NotifyAward) GetName() string { + if x != nil { + return x.Name + } + return "" +} + var File_protocol_activity_pushcoin_proto protoreflect.FileDescriptor var file_protocol_activity_pushcoin_proto_rawDesc = []byte{ @@ -858,43 +918,50 @@ var file_protocol_activity_pushcoin_proto_rawDesc = []byte{ 0x4c, 0x69, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x4c, 0x69, 0x6e, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x4c, 0x69, 0x6e, 0x65, 0x4d, 0x61, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x50, 0x6f, 0x77, - 0x65, 0x72, 0x4c, 0x69, 0x6e, 0x65, 0x4d, 0x61, 0x78, 0x2a, 0xdd, 0x01, 0x0a, 0x10, 0x50, 0x75, - 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x49, 0x44, 0x12, 0x18, - 0x0a, 0x14, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, - 0x6e, 0x5f, 0x5a, 0x45, 0x52, 0x4f, 0x10, 0x00, 0x12, 0x1a, 0x0a, 0x15, 0x50, 0x41, 0x43, 0x4b, - 0x45, 0x54, 0x5f, 0x43, 0x53, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x49, 0x6e, 0x66, - 0x6f, 0x10, 0xf8, 0x14, 0x12, 0x1a, 0x0a, 0x15, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x53, - 0x43, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x10, 0xf9, 0x14, - 0x12, 0x1e, 0x0a, 0x19, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x43, 0x53, 0x50, 0x75, 0x73, - 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x4f, 0x70, 0x10, 0xfa, 0x14, - 0x12, 0x1e, 0x0a, 0x19, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x53, 0x43, 0x50, 0x75, 0x73, - 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x4f, 0x70, 0x10, 0xfb, 0x14, - 0x12, 0x1b, 0x0a, 0x16, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4e, 0x6f, 0x74, 0x69, 0x66, - 0x79, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x4c, 0x69, 0x6e, 0x65, 0x10, 0xfc, 0x14, 0x12, 0x1a, 0x0a, - 0x15, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x44, 0x72, - 0x61, 0x77, 0x49, 0x6e, 0x66, 0x6f, 0x10, 0xfd, 0x14, 0x2a, 0x5e, 0x0a, 0x07, 0x4f, 0x70, 0x43, - 0x6f, 0x64, 0x65, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x4f, 0x50, 0x5f, 0x5a, 0x65, 0x72, 0x6f, 0x10, - 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x4f, 0x50, 0x5f, 0x42, 0x65, 0x74, 0x10, 0x01, 0x12, 0x0b, 0x0a, - 0x07, 0x4f, 0x50, 0x5f, 0x47, 0x61, 0x69, 0x6e, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x4f, 0x50, - 0x5f, 0x53, 0x68, 0x61, 0x6b, 0x65, 0x10, 0x03, 0x12, 0x0e, 0x0a, 0x0a, 0x4f, 0x50, 0x5f, 0x52, - 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x10, 0x04, 0x12, 0x0f, 0x0a, 0x0b, 0x4f, 0x50, 0x5f, 0x45, - 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x10, 0x05, 0x2a, 0xd2, 0x01, 0x0a, 0x14, 0x4f, 0x70, - 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x43, 0x6f, - 0x64, 0x65, 0x12, 0x19, 0x0a, 0x15, 0x4f, 0x50, 0x52, 0x43, 0x5f, 0x50, 0x75, 0x73, 0x68, 0x43, - 0x6f, 0x69, 0x6e, 0x5f, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x17, 0x0a, - 0x13, 0x4f, 0x50, 0x52, 0x43, 0x5f, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x5f, 0x45, - 0x72, 0x72, 0x6f, 0x72, 0x10, 0x01, 0x12, 0x1e, 0x0a, 0x1a, 0x4f, 0x50, 0x52, 0x43, 0x5f, 0x50, - 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x5f, 0x42, 0x65, 0x74, 0x4e, 0x6f, 0x74, 0x45, 0x6e, - 0x6f, 0x75, 0x67, 0x68, 0x10, 0x02, 0x12, 0x23, 0x0a, 0x1f, 0x4f, 0x50, 0x52, 0x43, 0x5f, 0x50, - 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x5f, 0x45, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x4e, 0x6f, 0x74, 0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0x03, 0x12, 0x20, 0x0a, 0x1c, 0x4f, - 0x50, 0x52, 0x43, 0x5f, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x5f, 0x53, 0x68, 0x61, - 0x6b, 0x65, 0x4e, 0x6f, 0x74, 0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0x04, 0x12, 0x1f, 0x0a, - 0x1b, 0x4f, 0x50, 0x52, 0x43, 0x5f, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x5f, 0x49, - 0x74, 0x65, 0x6d, 0x4e, 0x6f, 0x74, 0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0x05, 0x42, 0x28, - 0x5a, 0x26, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x2e, 0x67, 0x61, 0x6d, 0x65, 0x73, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, - 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x72, 0x4c, 0x69, 0x6e, 0x65, 0x4d, 0x61, 0x78, 0x22, 0x49, 0x0a, 0x0b, 0x4e, 0x6f, 0x74, + 0x69, 0x66, 0x79, 0x41, 0x77, 0x61, 0x72, 0x64, 0x12, 0x26, 0x0a, 0x04, 0x44, 0x72, 0x61, 0x77, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, + 0x79, 0x2e, 0x44, 0x72, 0x61, 0x77, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x44, 0x72, 0x61, 0x77, + 0x12, 0x12, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x4e, 0x61, 0x6d, 0x65, 0x2a, 0xf6, 0x01, 0x0a, 0x10, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, + 0x6e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x49, 0x44, 0x12, 0x18, 0x0a, 0x14, 0x50, 0x41, 0x43, + 0x4b, 0x45, 0x54, 0x5f, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x5f, 0x5a, 0x45, 0x52, + 0x4f, 0x10, 0x00, 0x12, 0x1a, 0x0a, 0x15, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x43, 0x53, + 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x10, 0xf8, 0x14, 0x12, + 0x1a, 0x0a, 0x15, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x53, 0x43, 0x50, 0x75, 0x73, 0x68, + 0x43, 0x6f, 0x69, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x10, 0xf9, 0x14, 0x12, 0x1e, 0x0a, 0x19, 0x50, + 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x43, 0x53, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, + 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x4f, 0x70, 0x10, 0xfa, 0x14, 0x12, 0x1e, 0x0a, 0x19, 0x50, + 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x53, 0x43, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, + 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x4f, 0x70, 0x10, 0xfb, 0x14, 0x12, 0x1b, 0x0a, 0x16, 0x50, + 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x50, 0x6f, 0x77, 0x65, + 0x72, 0x4c, 0x69, 0x6e, 0x65, 0x10, 0xfc, 0x14, 0x12, 0x1a, 0x0a, 0x15, 0x50, 0x41, 0x43, 0x4b, + 0x45, 0x54, 0x5f, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x44, 0x72, 0x61, 0x77, 0x49, 0x6e, 0x66, + 0x6f, 0x10, 0xfd, 0x14, 0x12, 0x17, 0x0a, 0x12, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4e, + 0x6f, 0x74, 0x69, 0x66, 0x79, 0x41, 0x77, 0x61, 0x72, 0x64, 0x10, 0xfe, 0x14, 0x2a, 0x5e, 0x0a, + 0x07, 0x4f, 0x70, 0x43, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x4f, 0x50, 0x5f, 0x5a, + 0x65, 0x72, 0x6f, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x4f, 0x50, 0x5f, 0x42, 0x65, 0x74, 0x10, + 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x4f, 0x50, 0x5f, 0x47, 0x61, 0x69, 0x6e, 0x10, 0x02, 0x12, 0x0c, + 0x0a, 0x08, 0x4f, 0x50, 0x5f, 0x53, 0x68, 0x61, 0x6b, 0x65, 0x10, 0x03, 0x12, 0x0e, 0x0a, 0x0a, + 0x4f, 0x50, 0x5f, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x10, 0x04, 0x12, 0x0f, 0x0a, 0x0b, + 0x4f, 0x50, 0x5f, 0x45, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x10, 0x05, 0x2a, 0xd2, 0x01, + 0x0a, 0x14, 0x4f, 0x70, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, + 0x69, 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x19, 0x0a, 0x15, 0x4f, 0x50, 0x52, 0x43, 0x5f, 0x50, + 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x5f, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, + 0x00, 0x12, 0x17, 0x0a, 0x13, 0x4f, 0x50, 0x52, 0x43, 0x5f, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, + 0x69, 0x6e, 0x5f, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x01, 0x12, 0x1e, 0x0a, 0x1a, 0x4f, 0x50, + 0x52, 0x43, 0x5f, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x5f, 0x42, 0x65, 0x74, 0x4e, + 0x6f, 0x74, 0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0x02, 0x12, 0x23, 0x0a, 0x1f, 0x4f, 0x50, + 0x52, 0x43, 0x5f, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, 0x5f, 0x45, 0x78, 0x63, 0x68, + 0x61, 0x6e, 0x67, 0x65, 0x4e, 0x6f, 0x74, 0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0x03, 0x12, + 0x20, 0x0a, 0x1c, 0x4f, 0x50, 0x52, 0x43, 0x5f, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, 0x69, 0x6e, + 0x5f, 0x53, 0x68, 0x61, 0x6b, 0x65, 0x4e, 0x6f, 0x74, 0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, + 0x04, 0x12, 0x1f, 0x0a, 0x1b, 0x4f, 0x50, 0x52, 0x43, 0x5f, 0x50, 0x75, 0x73, 0x68, 0x43, 0x6f, + 0x69, 0x6e, 0x5f, 0x49, 0x74, 0x65, 0x6d, 0x4e, 0x6f, 0x74, 0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, + 0x10, 0x05, 0x42, 0x28, 0x5a, 0x26, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x2e, 0x67, 0x61, 0x6d, 0x65, + 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x63, 0x6f, 0x6c, 0x2f, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -910,7 +977,7 @@ func file_protocol_activity_pushcoin_proto_rawDescGZIP() []byte { } var file_protocol_activity_pushcoin_proto_enumTypes = make([]protoimpl.EnumInfo, 3) -var file_protocol_activity_pushcoin_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_protocol_activity_pushcoin_proto_msgTypes = make([]protoimpl.MessageInfo, 10) var file_protocol_activity_pushcoin_proto_goTypes = []interface{}{ (PushCoinPacketID)(0), // 0: activity.PushCoinPacketID (OpCodes)(0), // 1: activity.OpCodes @@ -924,6 +991,7 @@ var file_protocol_activity_pushcoin_proto_goTypes = []interface{}{ (*CSPushCoinPlayerOp)(nil), // 9: activity.CSPushCoinPlayerOp (*SCPushCoinPlayerOp)(nil), // 10: activity.SCPushCoinPlayerOp (*NotifyPowerLine)(nil), // 11: activity.NotifyPowerLine + (*NotifyAward)(nil), // 12: activity.NotifyAward } var file_protocol_activity_pushcoin_proto_depIdxs = []int32{ 6, // 0: activity.SCPushCoinInfo.ExchangeList:type_name -> activity.ExchangeInfo @@ -938,11 +1006,12 @@ var file_protocol_activity_pushcoin_proto_depIdxs = []int32{ 2, // 9: activity.SCPushCoinPlayerOp.OpRetCode:type_name -> activity.OpResultPushCoinCode 1, // 10: activity.SCPushCoinPlayerOp.OpCode:type_name -> activity.OpCodes 6, // 11: activity.SCPushCoinPlayerOp.Exchange:type_name -> activity.ExchangeInfo - 12, // [12:12] is the sub-list for method output_type - 12, // [12:12] is the sub-list for method input_type - 12, // [12:12] is the sub-list for extension type_name - 12, // [12:12] is the sub-list for extension extendee - 0, // [0:12] is the sub-list for field type_name + 7, // 12: activity.NotifyAward.Draw:type_name -> activity.DrawInfo + 13, // [13:13] is the sub-list for method output_type + 13, // [13:13] is the sub-list for method input_type + 13, // [13:13] is the sub-list for extension type_name + 13, // [13:13] is the sub-list for extension extendee + 0, // [0:13] is the sub-list for field type_name } func init() { file_protocol_activity_pushcoin_proto_init() } @@ -1059,6 +1128,18 @@ func file_protocol_activity_pushcoin_proto_init() { return nil } } + file_protocol_activity_pushcoin_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*NotifyAward); 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{ @@ -1066,7 +1147,7 @@ func file_protocol_activity_pushcoin_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_protocol_activity_pushcoin_proto_rawDesc, NumEnums: 3, - NumMessages: 9, + NumMessages: 10, NumExtensions: 0, NumServices: 0, }, diff --git a/protocol/activity/pushcoin.proto b/protocol/activity/pushcoin.proto index 1f961f0..40eb6f8 100644 --- a/protocol/activity/pushcoin.proto +++ b/protocol/activity/pushcoin.proto @@ -10,6 +10,7 @@ enum PushCoinPacketID { PACKET_SCPushCoinPlayerOp = 2683; // 玩家操作返回 PACKET_NotifyPowerLine = 2684; // 通知能量值 PACKET_NotifyDrawInfo = 2685; // 抽奖信息 + PACKET_NotifyAward = 2686; // 广播中奖信息 } //信息 @@ -92,4 +93,11 @@ message SCPushCoinPlayerOp { message NotifyPowerLine { int64 PowerLine = 1; // 当前能量值 int64 PowerLineMax = 2; // 能量值上限 +} + +//广播中奖信息 +//PACKET_NotifyAward +message NotifyAward { + DrawInfo Draw = 1; // 中奖信息 + string Name = 2; // 玩家名字 } \ No newline at end of file diff --git a/worldsrv/action_pushcoin.go b/worldsrv/action_pushcoin.go index cce2dfc..904f684 100644 --- a/worldsrv/action_pushcoin.go +++ b/worldsrv/action_pushcoin.go @@ -475,7 +475,7 @@ func PushCoinDraw(p *Player) { } // fp 奖池返奖,返回是否成功 - fp := func(i int, poolInfo *PushCoinPoolInfo) bool { + fp := func(i int, poolInfo *model.PushCoinPoolInfo) bool { // 是否返奖 if poolInfo == nil || poolInfo.Remain <= 0 { return false @@ -661,6 +661,16 @@ func PushCoinDraw(p *Player) { p.SendToClient(int(activity.PushCoinPacketID_PACKET_NotifyDrawInfo), pack) logger.Logger.Trace("NotifyDrawInfo: ", pack) + if slices.Contains(PoolIndex, int(draw.GetId())) { + pk := &activity.NotifyAward{ + Draw: draw, + Name: p.GetName(), + } + // 广播抽奖信息 + PlatformMgrSingleton.Broadcast(int(activity.PushCoinPacketID_PACKET_NotifyAward), pk, nil, 0) + logger.Logger.Trace("Broadcast NotifyAward: ", pk) + } + // 刷新能量条 PushCoinAddPower(p, 0) } diff --git a/worldsrv/activity_pushcoin.go b/worldsrv/activity_pushcoin.go index ec731d3..d418651 100644 --- a/worldsrv/activity_pushcoin.go +++ b/worldsrv/activity_pushcoin.go @@ -1,12 +1,14 @@ package main import ( - "mongo.games.com/game/common" - "mongo.games.com/game/protocol/webapi" - "mongo.games.com/goserver/core/logger" "time" + "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/module" + + "mongo.games.com/game/common" + "mongo.games.com/game/model" + "mongo.games.com/game/protocol/webapi" ) var ( @@ -15,27 +17,15 @@ var ( ) var PushCoinPoolMangerInstance = &PushCoinPoolManager{ - PlatformConfig: map[string]*PushCoinPool{}, + PlatformConfig: map[string]*model.PushCoinPool{}, } func init() { module.RegisteModule(PushCoinPoolMangerInstance, time.Hour, 0) } -type PushCoinPool struct { - Pool1 *PushCoinPoolInfo - Pool2 *PushCoinPoolInfo - Pool3 *PushCoinPoolInfo -} - -type PushCoinPoolInfo struct { - CurCoin int64 // 当前金币 - Remain int64 // 剩余金币 - Version int64 // 版本号, 达到上限后更新 -} - type PushCoinPoolManager struct { - PlatformConfig map[string]*PushCoinPool + PlatformConfig map[string]*model.PushCoinPool } func (p *PushCoinPoolManager) ModuleName() string { @@ -44,6 +34,21 @@ func (p *PushCoinPoolManager) ModuleName() string { func (p *PushCoinPoolManager) Init() { // 加载水池 + for _, v := range PlatformMgrSingleton.GetPlatforms() { + d, err := model.PushCoinLoad(v.IdStr) + if err != nil { + panic(err) + } + d.Platform = v.IdStr + p.PlatformConfig[v.IdStr] = d + } +} + +func (p *PushCoinPoolManager) save(d *model.PushCoinPool) { + err := model.PushCoinSave(d) + if err != nil { + logger.Logger.Errorf("save PushCoinPool error: %v", err) + } } func (p *PushCoinPoolManager) Update() { @@ -52,17 +57,16 @@ func (p *PushCoinPoolManager) Update() { func (p *PushCoinPoolManager) Shutdown() { // 保存水池 + for _, v := range p.PlatformConfig { + p.save(v) + } module.UnregisteModule(p) } func (p *PushCoinPoolManager) Add(platform string, val int64) { cfg, ok := p.PlatformConfig[platform] if !ok { - cfg = &PushCoinPool{ - Pool1: &PushCoinPoolInfo{}, - Pool2: &PushCoinPoolInfo{}, - Pool3: &PushCoinPoolInfo{}, - } + cfg = model.NewPushCoinPool(platform) p.PlatformConfig[platform] = cfg } @@ -71,7 +75,7 @@ func (p *PushCoinPoolManager) Add(platform string, val int64) { return } - f := func(i int, poolInfo *PushCoinPoolInfo, pool *webapi.PushCoinPool, rate float64) { + f := func(i int, poolInfo *model.PushCoinPoolInfo, pool *webapi.PushCoinPool, rate float64) { if pool != nil && pool.GetOn() == common.On { change := int64(float64(val) * rate) poolInfo.CurCoin += change