From c341b8a09d3c02b23988084c1f2a58364292e981 Mon Sep 17 00:00:00 2001 From: NorthLan <6995syu@163.com> Date: Wed, 4 May 2022 00:27:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=8E=92=E8=A1=8C?= =?UTF-8?q?=E6=A6=9C=E4=BB=BB=E5=8A=A1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/user_center/genModel.bat | 3 +- app/user_center/model/rank_pvp_model.go | 91 ++ app/user_center/model/rank_pvp_model_gen.go | 103 +++ app/user_center/model/statistics_pvp_model.go | 155 ++++ .../model/statistics_pvp_model_gen.go | 98 +++ app/user_center/model/user_platform_model.go | 47 +- app/user_center/rpc/etc/user_center-dev.yaml | 16 + app/user_center/rpc/etc/user_center.yaml | 9 +- app/user_center/rpc/internal/config/config.go | 21 +- .../platform_user/platform_user_retrieve.go | 40 +- .../rpc/internal/logic/rank/rank_job.go | 246 ++++++ .../rpc/internal/logic/rank/rank_job_test.go | 26 + .../rpc/internal/logic/rank/rank_pvp_logic.go | 28 + .../logic/statistics/stat_pvp_damage_logic.go | 66 ++ .../statistics/stat_pvp_first_blood_logic.go | 62 ++ .../logic/statistics/stat_pvp_kill_logic.go | 69 ++ .../statistics/stat_pvp_kill_unit_logic.go | 65 ++ .../logic/statistics/stat_pvp_report_logic.go | 50 ++ .../rpc/internal/logic/statistics/vars.go | 6 + .../rpc/internal/server/user_center_server.go | 36 +- .../rpc/internal/svc/service_context.go | 29 +- app/user_center/rpc/pb/generate.go | 2 +- app/user_center/rpc/pb/user_center.pb.go | 820 +++++++++++++++++- app/user_center/rpc/pb/user_center.proto | 64 ++ app/user_center/rpc/pb/user_center_grpc.pb.go | 224 ++++- app/user_center/rpc/user_center.go | 3 + app/user_center/rpc/usercenter/user_center.go | 57 +- go.mod | 1 + go.sum | 4 + 29 files changed, 2357 insertions(+), 84 deletions(-) create mode 100644 app/user_center/model/rank_pvp_model.go create mode 100644 app/user_center/model/rank_pvp_model_gen.go create mode 100644 app/user_center/model/statistics_pvp_model.go create mode 100644 app/user_center/model/statistics_pvp_model_gen.go create mode 100644 app/user_center/rpc/etc/user_center-dev.yaml create mode 100644 app/user_center/rpc/internal/logic/rank/rank_job.go create mode 100644 app/user_center/rpc/internal/logic/rank/rank_job_test.go create mode 100644 app/user_center/rpc/internal/logic/rank/rank_pvp_logic.go create mode 100644 app/user_center/rpc/internal/logic/statistics/stat_pvp_damage_logic.go create mode 100644 app/user_center/rpc/internal/logic/statistics/stat_pvp_first_blood_logic.go create mode 100644 app/user_center/rpc/internal/logic/statistics/stat_pvp_kill_logic.go create mode 100644 app/user_center/rpc/internal/logic/statistics/stat_pvp_kill_unit_logic.go create mode 100644 app/user_center/rpc/internal/logic/statistics/stat_pvp_report_logic.go create mode 100644 app/user_center/rpc/internal/logic/statistics/vars.go diff --git a/app/user_center/genModel.bat b/app/user_center/genModel.bat index 147a430..72cfbcc 100644 --- a/app/user_center/genModel.bat +++ b/app/user_center/genModel.bat @@ -1,7 +1,8 @@ @echo off @echo ?????????????? -set tables=user,user_platform +::set tables=user,user_platform +set tables=rank_pvp set targetDir=.\model set templateDir=..\..\doc\template diff --git a/app/user_center/model/rank_pvp_model.go b/app/user_center/model/rank_pvp_model.go new file mode 100644 index 0000000..d039a8c --- /dev/null +++ b/app/user_center/model/rank_pvp_model.go @@ -0,0 +1,91 @@ +package model + +import ( + "context" + "fmt" + "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc" + "gorm.io/gorm" +) + +var _ RankPvpModel = (*customRankPvpModel)(nil) + +const ( + RankTypeDamage = iota + 1 + RankTypeGeneral + RankTypeKillUnit + RankTypeKillPlayer +) + +const MaxRankN = 50 + +type ( + // RankPvpModel is an interface to be customized, add more methods here, + // and implement the added methods in customRankPvpModel. + RankPvpModel interface { + rankPvpModel + RankListByType(ctx context.Context, rankType, topN int32) ([]RankPvpWithPlatformUser, error) + UpdateRank(ctx context.Context, rankType int32, data []RankPvp) error + } + + customRankPvpModel struct { + *defaultRankPvpModel + } + + RankPvpWithPlatformUser struct { + RankPvp + Platform string // 平台类型 + PUname string // 平台用户名 + PAvatar string // 平台用户头像地址 + } +) + +// NewRankPvpModel returns a model for the database table. +func NewRankPvpModel(conn *gorm.DB) RankPvpModel { + return &customRankPvpModel{ + defaultRankPvpModel: newRankPvpModel(conn), + } +} + +func (m *customRankPvpModel) RankListByType(ctx context.Context, rankType, topN int32) ([]RankPvpWithPlatformUser, error) { + db := m.conn.WithContext(ctx) + limit := topN + if limit > MaxRankN { + limit = MaxRankN + } + var result []RankPvpWithPlatformUser + err := db.Model(&RankPvpWithPlatformUser{}). + Select(fmt.Sprintf("%s.*, UP.platform, UP.p_uname, UP.p_avatar", m.table)). + Joins(fmt.Sprintf("LEFT JOIN user_platform UP ON UP.user_id = %s.user_id", m.table)). + Where("rank_type = ?", rankType). + Limit(int(limit)). + Order("score desc"). // score 排名 + Find(&result).Error + switch err { + case nil: + return result, nil + case gormc.ErrNotFound: + return nil, ErrNotFound + default: + return nil, err + } +} + +func (m *customRankPvpModel) UpdateRank(ctx context.Context, rankType int32, data []RankPvp) error { + db := m.conn.WithContext(ctx) //.Session(&gorm.Session{DryRun: true}) + return db.Transaction(func(tx *gorm.DB) error { + var err error + // delete all by rank_type + if err = tx. + Table(m.table). + Where("rank_type = ?", rankType). + Delete(&RankPvp{}).Error; err != nil { + return err + } + // add all + if err = tx. + Create(data).Error; err != nil { + return err + } + return nil + }) +} diff --git a/app/user_center/model/rank_pvp_model_gen.go b/app/user_center/model/rank_pvp_model_gen.go new file mode 100644 index 0000000..2109fa6 --- /dev/null +++ b/app/user_center/model/rank_pvp_model_gen.go @@ -0,0 +1,103 @@ +// Code generated by goctl. DO NOT EDIT! + +package model + +import ( + "context" + "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc" + "strings" + "time" + + "github.com/zeromicro/go-zero/core/stores/builder" + "github.com/zeromicro/go-zero/core/stringx" + "gorm.io/gorm" +) + +var ( + rankPvpFieldNames = builder.RawFieldNames(&RankPvp{}) + rankPvpRows = strings.Join(rankPvpFieldNames, ",") + rankPvpRowsExpectAutoSet = strings.Join(stringx.Remove(rankPvpFieldNames, "`create_time`", "`update_time`"), ",") + rankPvpRowsWithPlaceHolder = strings.Join(stringx.Remove(rankPvpFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?" +) + +type ( + rankPvpModel interface { + Insert(ctx context.Context, data *RankPvp) error + FindOne(ctx context.Context, id int64) (*RankPvp, error) + FindOneByUserIdRankType(ctx context.Context, userId int64, rankType int64) (*RankPvp, error) + Update(ctx context.Context, data *RankPvp) error + Delete(ctx context.Context, id int64) error + } + + defaultRankPvpModel struct { + conn *gorm.DB + table string + } + + RankPvp struct { + Id int64 `gorm:"column:id"` // 主键 + UserId int64 `gorm:"column:user_id"` // 用户ID + RankType int64 `gorm:"column:rank_type"` // 类型 1: 伤害 2: 名将次数 3: 击杀单位 4: 击杀玩家 + Score int64 `gorm:"column:score"` // 伤害量 + CreateTime time.Time `gorm:"column:create_time;default:null"` // 创建时间 + UpdateTime time.Time `gorm:"column:update_time;default:null"` // 更新时间 + } +) + +func newRankPvpModel(conn *gorm.DB) *defaultRankPvpModel { + return &defaultRankPvpModel{ + conn: conn, + table: "`rank_pvp`", + } +} + +func (m *defaultRankPvpModel) Insert(ctx context.Context, data *RankPvp) error { + err := m.conn.WithContext(ctx).Create(&data).Error + return err +} + +func (m *defaultRankPvpModel) FindOne(ctx context.Context, id int64) (*RankPvp, error) { + var resp RankPvp + err := m.conn.WithContext(ctx).Model(&RankPvp{}).Where("`id` = ?", id).Take(&resp).Error + switch err { + case nil: + return &resp, nil + case gormc.ErrNotFound: + return nil, ErrNotFound + default: + return nil, err + } +} + +func (m *defaultRankPvpModel) FindOneByUserIdRankType(ctx context.Context, userId int64, rankType int64) (*RankPvp, error) { + var resp RankPvp + err := m.conn.WithContext(ctx).Model(&RankPvp{}).Where("`user_id` = ? and `rank_type` = ?", userId, rankType).Take(&resp).Error + switch err { + case nil: + return &resp, nil + case gormc.ErrNotFound: + return nil, ErrNotFound + default: + return nil, err + } +} + +func (m *defaultRankPvpModel) Update(ctx context.Context, data *RankPvp) error { + err := m.conn.WithContext(ctx).Save(data).Error + return err +} + +func (m *defaultRankPvpModel) Delete(ctx context.Context, id int64) error { + err := m.conn.WithContext(ctx).Delete(&RankPvp{}, id).Error + + return err +} + +func (m *defaultRankPvpModel) tableName() string { + return m.table +} + +func (RankPvp) TableName() string { + model := newRankPvpModel(nil) + return model.tableName() +} diff --git a/app/user_center/model/statistics_pvp_model.go b/app/user_center/model/statistics_pvp_model.go new file mode 100644 index 0000000..8c66573 --- /dev/null +++ b/app/user_center/model/statistics_pvp_model.go @@ -0,0 +1,155 @@ +package model + +import ( + "context" + "fmt" + "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc" + "github.com/zeromicro/go-zero/core/logx" + "gorm.io/gorm" +) + +var _ StatisticsPvpModel = (*customStatisticsPvpModel)(nil) + +type ScoreType string + +const ( + ScoreTypeDamage ScoreType = "damage" + ScoreTypeGeneral = "general_count" + ScoreTypeKillUnit = "kill_unit_count" + ScoreTypeKillPlayer = "kill_player_count" +) + +type ( + // StatisticsPvpModel is an interface to be customized, add more methods here, + // and implement the added methods in customStatisticsPvpModel. + StatisticsPvpModel interface { + statisticsPvpModel + Exists(ctx context.Context, userId int64) (bool, error) + UpdateRecord(ctx context.Context, userId int64, props *UpdateRecordProps) error + RecordPvp(ctx context.Context, winUids, lostUids []int64) error + // FindGreaterByScore 找到比给定分数大的用户id以及具体分数 + FindGreaterByScore(ctx context.Context, score int64, scoreType ScoreType) ([]UserAndScore, error) + } + + UserAndScore struct { + UserId int64 + Score int64 + } + + UpdateRecordProps struct { + KillUnit bool // 是否击杀单位 + DeKillUnit bool // 是否单位被击杀 + KillPlayer bool // 是否击杀玩家 + DeKillPlayer bool // 是否玩家被击杀 + General bool // 是否拿到名将 + DeGeneral bool // 是否名将罗马 + FirstBlood bool // 是否拿到一血 + DeFirstBlood bool // 是否被拿一血 + Damage *int64 // 伤害 + DeDamage *int64 // 被伤害 + } + + customStatisticsPvpModel struct { + *defaultStatisticsPvpModel + } +) + +// NewStatisticsPvpModel returns a model for the database table. +func NewStatisticsPvpModel(conn *gorm.DB) StatisticsPvpModel { + return &customStatisticsPvpModel{ + defaultStatisticsPvpModel: newStatisticsPvpModel(conn), + } +} + +func (m *customStatisticsPvpModel) Exists(ctx context.Context, userId int64) (bool, error) { + var count int64 + err := m.conn.WithContext(ctx).Model(&StatisticsPvp{}).Where("user_id = ?", userId).Count(&count).Error + switch err { + case nil: + return count > 0, nil + case gormc.ErrNotFound: + return false, ErrNotFound + default: + return false, err + } +} + +func (m *customStatisticsPvpModel) UpdateRecord(ctx context.Context, userId int64, props *UpdateRecordProps) error { + // 条件构建 + db := m.conn.WithContext(ctx).Model(&StatisticsPvp{}).Where("user_id = ?", userId) + data := make(map[string]interface{}) + if props.Damage != nil { + data["damage"] = gorm.Expr("damage + ?", *props.Damage) + } + if props.DeDamage != nil { + data["de_damage"] = gorm.Expr("de_damage + ?", *props.DeDamage) + } + if props.KillUnit { + data["kill_unit_count"] = gorm.Expr("kill_unit_count + 1") + } + if props.DeKillUnit { + data["de_kill_unit_count"] = gorm.Expr("de_kill_unit_count + 1") + } + if props.KillPlayer { + data["kill_player_count"] = gorm.Expr("kill_player_count + 1") + } + if props.DeKillPlayer { + data["de_kill_player_count"] = gorm.Expr("de_kill_player_count + 1") + } + if props.General { + data["general_count"] = gorm.Expr("general_count + 1") + } + if props.DeGeneral { + data["de_general_count"] = gorm.Expr("de_general_count + 1") + } + if props.FirstBlood { + data["first_blood_count"] = gorm.Expr("first_blood_count + 1") + } + if props.DeFirstBlood { + data["de_first_blood_count"] = gorm.Expr("de_first_blood_count + 1") + } + return db.Updates(data).Error +} + +func (m *customStatisticsPvpModel) RecordPvp(ctx context.Context, winUids, lostUids []int64) error { + return m.conn.Transaction(func(tx *gorm.DB) error { + err := tx.WithContext(ctx).Model(&StatisticsPvp{}). + Where("user_id in (?)", winUids). + Update("win_count", gorm.Expr("win_count + 1")). + Error + if err != nil { + logx.Error("更新PvP胜场失败 %+v", err) + } + err = tx.WithContext(ctx).Model(&StatisticsPvp{}). + Where("user_id in (?)", lostUids). + Update("lost_count", gorm.Expr("lost_count + 1")). + Error + if err != nil { + logx.Error("更新PvP败失败 %+v", err) + } + return err + }) +} + +func (m *customStatisticsPvpModel) FindGreaterByScore(ctx context.Context, score int64, scoreType ScoreType) ([]UserAndScore, error) { + db := m.conn.WithContext(ctx) + + whereSql := fmt.Sprintf("%s.%s >= %d", m.table, scoreType, score) + // 0 不入榜 + if score == 0 { + whereSql = fmt.Sprintf("%s.%s > %d", m.table, scoreType, score) + } + var result []UserAndScore + err := db.Table(m.table). + Select(fmt.Sprintf("%s.user_id, %s.%s AS score", m.table, m.table, scoreType)). + Where(whereSql). + Limit(MaxRankN).Find(&result).Error + switch err { + case nil: + return result, nil + case gormc.ErrNotFound: + return nil, ErrNotFound + default: + return nil, err + } +} diff --git a/app/user_center/model/statistics_pvp_model_gen.go b/app/user_center/model/statistics_pvp_model_gen.go new file mode 100644 index 0000000..e251c8c --- /dev/null +++ b/app/user_center/model/statistics_pvp_model_gen.go @@ -0,0 +1,98 @@ +// Code generated by goctl. DO NOT EDIT! + +package model + +import ( + "context" + "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc" + "strings" + "time" + + "github.com/zeromicro/go-zero/core/stores/builder" + "github.com/zeromicro/go-zero/core/stringx" + "gorm.io/gorm" +) + +var ( + statisticsPvpFieldNames = builder.RawFieldNames(&StatisticsPvp{}) + statisticsPvpRows = strings.Join(statisticsPvpFieldNames, ",") + statisticsPvpRowsExpectAutoSet = strings.Join(stringx.Remove(statisticsPvpFieldNames, "`create_time`", "`update_time`"), ",") + statisticsPvpRowsWithPlaceHolder = strings.Join(stringx.Remove(statisticsPvpFieldNames, "`user_id`", "`create_time`", "`update_time`"), "=?,") + "=?" +) + +type ( + statisticsPvpModel interface { + Insert(ctx context.Context, data *StatisticsPvp) error + FindOne(ctx context.Context, userId int64) (*StatisticsPvp, error) + Update(ctx context.Context, data *StatisticsPvp) error + Delete(ctx context.Context, userId int64) error + } + + defaultStatisticsPvpModel struct { + conn *gorm.DB + table string + } + + StatisticsPvp struct { + UserId int64 `gorm:"column:user_id;primaryKey"` // 用户ID + WinCount int64 `gorm:"column:win_count"` // 胜利次数 + LostCount int64 `gorm:"column:lost_count"` // 失败次数 + Damage int64 `gorm:"column:damage"` // 伤害量 + DeDamage int64 `gorm:"column:de_damage"` // 承受伤害量 + KillUnitCount int64 `gorm:"column:kill_unit_count"` // 击杀单位数量 + DeKillUnitCount int64 `gorm:"column:de_kill_unit_count"` // 被击杀单位数量 + KillPlayerCount int64 `gorm:"column:kill_player_count"` // 击杀玩家兵营数量 + DeKillPlayerCount int64 `gorm:"column:de_kill_player_count"` // 被击杀次数 + GeneralCount int64 `gorm:"column:general_count"` // 获得名将次数 + DeGeneralCount int64 `gorm:"column:de_general_count"` // 名将落马次数 + FirstBloodCount int64 `gorm:"column:first_blood_count"` // 一血次数 + DeFirstBloodCount int64 `gorm:"column:de_first_blood_count"` // 被拿一血次数 + CreateTime time.Time `gorm:"column:create_time;default:null"` + UpdateTime time.Time `gorm:"column:update_time;default:null"` + } +) + +func newStatisticsPvpModel(conn *gorm.DB) *defaultStatisticsPvpModel { + return &defaultStatisticsPvpModel{ + conn: conn, + table: "`statistics_pvp`", + } +} + +func (m *defaultStatisticsPvpModel) Insert(ctx context.Context, data *StatisticsPvp) error { + err := m.conn.WithContext(ctx).Create(&data).Error + return err +} + +func (m *defaultStatisticsPvpModel) FindOne(ctx context.Context, userId int64) (*StatisticsPvp, error) { + var resp StatisticsPvp + err := m.conn.WithContext(ctx).Model(&StatisticsPvp{}).Where("`user_id` = ?", userId).Take(&resp).Error + switch err { + case nil: + return &resp, nil + case gormc.ErrNotFound: + return nil, ErrNotFound + default: + return nil, err + } +} + +func (m *defaultStatisticsPvpModel) Update(ctx context.Context, data *StatisticsPvp) error { + err := m.conn.WithContext(ctx).Save(data).Error + return err +} + +func (m *defaultStatisticsPvpModel) Delete(ctx context.Context, userId int64) error { + err := m.conn.WithContext(ctx).Delete(&StatisticsPvp{}, userId).Error + + return err +} + +func (m *defaultStatisticsPvpModel) tableName() string { + return m.table +} + +func (StatisticsPvp) TableName() string { + model := newStatisticsPvpModel(nil) + return model.tableName() +} diff --git a/app/user_center/model/user_platform_model.go b/app/user_center/model/user_platform_model.go index ec4a620..3618782 100644 --- a/app/user_center/model/user_platform_model.go +++ b/app/user_center/model/user_platform_model.go @@ -2,6 +2,7 @@ package model import ( "context" + "fmt" "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc" "gorm.io/gorm" ) @@ -15,7 +16,18 @@ type ( userPlatformModel // FindOneByPlatformAndPUid 查询平台用户 FindOneByPlatformAndPUid(ctx context.Context, platform, pUid string) (*UserPlatform, error) + // FindEmptyList 查询从未更新过平台信息的用户 + FindEmptyList(ctx context.Context, num int64) ([]UserPlatform, error) + // FindUpdatableList 查询过期需要更新信息的用户 FindUpdatableList(ctx context.Context, duration int64, num int64) ([]UserPlatform, error) + // FindOneForRankByUserId 查找用户信息 用于排行榜展示 + FindOneForRankByUserId(ctx context.Context, uid int64) (*UserPlatformForRank, error) + } + + UserPlatformForRank struct { + UserId int64 // 用户ID + PUname string // 平台用户名 + PAvatar string // 平台用户头像地址 } customUserPlatformModel struct { @@ -43,11 +55,27 @@ func (m *customUserPlatformModel) FindOneByPlatformAndPUid(ctx context.Context, } } +func (m *customUserPlatformModel) FindEmptyList(ctx context.Context, num int64) ([]UserPlatform, error) { + var resp []UserPlatform + err := m.conn.WithContext(ctx). + Table(m.tableName()). + Where("JSON_LENGTH(`p_info`) = 0 LIMIT ?", num). + Find(&resp).Error + switch err { + case nil: + return resp, nil + case gormc.ErrNotFound: + return nil, ErrNotFound + default: + return nil, err + } +} + func (m *customUserPlatformModel) FindUpdatableList(ctx context.Context, duration int64, num int64) ([]UserPlatform, error) { var resp []UserPlatform err := m.conn.WithContext(ctx). Table(m.tableName()). - Where("JSON_LENGTH(`p_info`) = 0 OR `update_time` < (NOW() - INTERVAL ? HOUR) LIMIT ?", duration, num). + Where("`update_time` < (NOW() - INTERVAL ? HOUR) LIMIT ?", duration, num). Find(&resp).Error switch err { case nil: @@ -58,3 +86,20 @@ func (m *customUserPlatformModel) FindUpdatableList(ctx context.Context, duratio return nil, err } } + +func (m *customUserPlatformModel) FindOneForRankByUserId(ctx context.Context, uid int64) (*UserPlatformForRank, error) { + var resp UserPlatformForRank + err := m.conn.WithContext(ctx). + Table(m.table). + Select(fmt.Sprintf("%s.user_id, %s.p_uname, %s.p_avatar", m.table, m.table, m.table)). + Where("user_id = ?", uid). + Take(&resp).Error + switch err { + case nil: + return &resp, nil + case gormc.ErrNotFound: + return nil, ErrNotFound + default: + return nil, err + } +} diff --git a/app/user_center/rpc/etc/user_center-dev.yaml b/app/user_center/rpc/etc/user_center-dev.yaml new file mode 100644 index 0000000..c50d161 --- /dev/null +++ b/app/user_center/rpc/etc/user_center-dev.yaml @@ -0,0 +1,16 @@ +Name: usercenter.rpc +ListenOn: 127.0.0.1:30001 +Etcd: + Hosts: + - 127.0.0.1:2379 + Key: usercenter.rpc.dev + NonBlock: true +DB: + #DataSource: root:root@tcp(192.168.1.100:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true + DataSource: root:root@tcp(127.0.0.1:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true +User: + UpdateDuration: 720 # 720 hours = 30 Day = 1 Month +Log: + Mode: console + KeepDays: 7 + Level: info \ No newline at end of file diff --git a/app/user_center/rpc/etc/user_center.yaml b/app/user_center/rpc/etc/user_center.yaml index 1d4284c..f798b7f 100644 --- a/app/user_center/rpc/etc/user_center.yaml +++ b/app/user_center/rpc/etc/user_center.yaml @@ -8,15 +8,8 @@ Etcd: DB: #DataSource: root:root@tcp(192.168.1.100:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true DataSource: root:root@tcp(127.0.0.1:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true -Danmaku: - Kafka: - Addr: [ "127.0.0.1:9093" ] - Topic: "danmaku" - ConsumerGroupId: "msgToDb" - Command: - Keys: [ "j", "加入","加入游戏" ] User: - UpdateDuration: 72 # 72 hours + UpdateDuration: 720 # 720 hours = 30 Day = 1 Month Log: Mode: file KeepDays: 7 diff --git a/app/user_center/rpc/internal/config/config.go b/app/user_center/rpc/internal/config/config.go index b621d73..9dca925 100644 --- a/app/user_center/rpc/internal/config/config.go +++ b/app/user_center/rpc/internal/config/config.go @@ -6,11 +6,15 @@ import ( ) type ( - Kafka struct { - Addr []string - Topic string - ConsumerGroupId string - } + /* + Kafka struct { + Addr []string + Topic string + ConsumerGroupId string + } + */ + + // Config 配置 Config struct { zrpc.RpcServerConf Log logx.LogConf @@ -18,13 +22,6 @@ type ( DataSource string } - Danmaku struct { - Kafka Kafka - Command struct { - Keys []string - } - } - User struct { UpdateDuration int64 // 用户信息更新最短间隔 单位 h } diff --git a/app/user_center/rpc/internal/logic/platform_user/platform_user_retrieve.go b/app/user_center/rpc/internal/logic/platform_user/platform_user_retrieve.go index 64d0406..07f807c 100644 --- a/app/user_center/rpc/internal/logic/platform_user/platform_user_retrieve.go +++ b/app/user_center/rpc/internal/logic/platform_user/platform_user_retrieve.go @@ -5,7 +5,9 @@ import ( "github.com/robfig/cron/v3" "github.com/zeromicro/go-zero/core/logx" pbMq "live-service/app/pb/mq" + "live-service/app/user_center/model" "live-service/app/user_center/rpc/internal/svc" + "time" ) // PlatformUser 仅提取需要的部分,其余的json后装到p_info @@ -58,23 +60,37 @@ func (r *UserRetriever) retrieveUser(platform, pUid string) *PlatformUser { } func (r *UserRetriever) Scheduler() { + logx.Info("开启用户数据采集服务...") c := cron.New() - _, _ = c.AddFunc("@every 300ms", func() { - list, err := r.svcCtx.UserPlatformModel.FindUpdatableList(r.ctx, r.svcCtx.Config.User.UpdateDuration, 10) - if err != nil { + _, _ = c.AddFunc("@every 1s", func() { + var list []model.UserPlatform + var err error + if list, err = r.svcCtx.UserPlatformModel.FindEmptyList(r.ctx, 5); err != nil { + r.Logger.Errorf("db err", err) return } - r.Logger.Info("list", list) - for _, dbModel := range list { - pUser := r.retrieveUser(dbModel.Platform, dbModel.PUid) - if pUser.PInfo == "{}" { - continue + r.retrieveList(list) + // 优先加载空信息用户 + if len(list) <= 0 { + if list, err = r.svcCtx.UserPlatformModel.FindUpdatableList(r.ctx, r.svcCtx.Config.User.UpdateDuration, 5); err != nil { + return } - dbModel.PUname = pUser.PName - dbModel.PAvatar = pUser.PAvatar - dbModel.PInfo = pUser.PInfo - _ = r.svcCtx.UserPlatformModel.Update(r.ctx, &dbModel) + r.retrieveList(list) } }) c.Start() } + +func (r *UserRetriever) retrieveList(list []model.UserPlatform) { + for _, dbModel := range list { + pUser := r.retrieveUser(dbModel.Platform, dbModel.PUid) + if pUser.PInfo == "{}" { + continue + } + dbModel.PUname = pUser.PName + dbModel.PAvatar = pUser.PAvatar + dbModel.PInfo = pUser.PInfo + dbModel.UpdateTime = time.Now() + _ = r.svcCtx.UserPlatformModel.Update(r.ctx, &dbModel) + } +} diff --git a/app/user_center/rpc/internal/logic/rank/rank_job.go b/app/user_center/rpc/internal/logic/rank/rank_job.go new file mode 100644 index 0000000..9ec7fe6 --- /dev/null +++ b/app/user_center/rpc/internal/logic/rank/rank_job.go @@ -0,0 +1,246 @@ +package rank + +import ( + "context" + "git.noahlan.cn/northlan/ntools-go/uuid" + lru "github.com/hashicorp/golang-lru" + zset "github.com/longzhiri/gozset" + "github.com/pkg/errors" + "github.com/robfig/cron/v3" + "github.com/zeromicro/go-zero/core/logx" + "live-service/app/user_center/model" + "live-service/app/user_center/rpc/internal/svc" + "live-service/app/user_center/rpc/pb" +) + +var Service *Job + +type ( + CachedUserInfo struct { + UserId int64 + Username string + Avatar string + } + Job struct { + ctx context.Context + svcCtx *svc.ServiceContext + + // 实时排行榜(定期读取,半实时) + damageRank *zset.ZSetInt + generalRank *zset.ZSetInt + killUnitRank *zset.ZSetInt + killPlayerRank *zset.ZSetInt + + // 用户数据表内存缓存 + userCache *lru.Cache + } +) + +func InitRankJob(svcCtx *svc.ServiceContext) { + lessFunc := func(l, r int32) bool { + return l > r + } + uc, _ := lru.New(4*model.MaxRankN + 1000) + Service = &Job{ + ctx: context.Background(), + svcCtx: svcCtx, + damageRank: zset.NewZSetInt(lessFunc, model.MaxRankN), + generalRank: zset.NewZSetInt(lessFunc, model.MaxRankN), + killUnitRank: zset.NewZSetInt(lessFunc, model.MaxRankN), + killPlayerRank: zset.NewZSetInt(lessFunc, model.MaxRankN), + userCache: uc, + } + Service.initJob() +} + +// InitJob 初始化RankJob,启动时加载 +// 1. 读取落地的排行榜数据,并Add到榜内(读取 用户数据) +// 2. 开启任务 定时读取 分数大于排行榜最后一位的数据,存在则Update +// 3. 开启任务 定时落库 +func (j *Job) initJob() { + logx.Info("开启排行榜服务...") + j.initByType(model.RankTypeDamage) + j.initByType(model.RankTypeGeneral) + j.initByType(model.RankTypeKillUnit) + j.initByType(model.RankTypeKillPlayer) + + // job read and update + c1 := cron.New() + _, _ = c1.AddFunc("@every 1s", func() { + go j.readAndUpdate(model.RankTypeDamage) + go j.readAndUpdate(model.RankTypeGeneral) + go j.readAndUpdate(model.RankTypeKillUnit) + go j.readAndUpdate(model.RankTypeKillPlayer) + }) + c2 := cron.New() + _, _ = c2.AddFunc("@every 10min", func() { + go j.persistence(model.RankTypeDamage) + go j.persistence(model.RankTypeGeneral) + go j.persistence(model.RankTypeKillUnit) + go j.persistence(model.RankTypeKillPlayer) + }) + c1.Start() + c2.Start() +} + +func (j *Job) RangeRankByType(rankType, topN int32) *pb.RankPvpResp { + result := &pb.RankPvpResp{ + Type: rankType, + } + rankZSet, _, err := j.getRankInstanceAndScoreType(rankType) + if err != nil { + return result + } + if topN > model.MaxRankN { + topN = model.MaxRankN + } + rank := rankZSet.RangeByRank(1, uint32(topN)) + + // 这里make 减少扩容次数 + result.Items = make([]*pb.RankPvpResp_Item, 0, len(rank)) + for _, r := range rank { + uid := r[0] + score := r[1] + + var item pb.RankPvpResp_Item + if c, ok := j.userCache.Get(uid); ok { + cached := c.(CachedUserInfo) + item = pb.RankPvpResp_Item{ + Uid: cached.UserId, + Uname: cached.Username, + Score: score, + Avatar: cached.Avatar, + } + } else { + dbUser, err := j.svcCtx.UserPlatformModel.FindOneForRankByUserId(j.ctx, uid) + if err != nil { + item = pb.RankPvpResp_Item{ + Uid: uid, + Score: score, + } + } else { + item = pb.RankPvpResp_Item{ + Uid: uid, + Uname: dbUser.PUname, + Score: score, + Avatar: dbUser.PAvatar, + } + } + } + result.Items = append(result.Items, &item) + } + return result +} + +func (j *Job) initByType(rankType int32) { + list, err := j.svcCtx.RankPvpModel.RankListByType(j.ctx, rankType, model.MaxRankN) + if err != nil { + return + } + for _, user := range list { + // 缓存用户信息 + j.userCache.Add(user.UserId, CachedUserInfo{ + UserId: user.UserId, + Username: user.PUname, + Avatar: user.PAvatar, + }) + switch rankType { + case model.RankTypeDamage: + j.damageRank.Add(user.UserId, int32(user.Score)) + case model.RankTypeGeneral: + j.generalRank.Add(user.UserId, int32(user.Score)) + case model.RankTypeKillUnit: + j.killUnitRank.Add(user.UserId, int32(user.Score)) + case model.RankTypeKillPlayer: + j.killPlayerRank.Add(user.UserId, int32(user.Score)) + } + } +} + +func (j *Job) readAndUpdate(rankType int32) { + rankZSet, scoreType, err := j.getRankInstanceAndScoreType(rankType) + if err != nil { + return + } + rank := rankZSet.RangeByRank(1, model.MaxRankN) + + var score int64 + if len(rank) == 0 { + score = 0 + } else { + last := rank[len(rank)-1] + score = last[1] + } + + // 末位 score + byScore, err := j.svcCtx.StatisticsPvpModel.FindGreaterByScore(j.ctx, score, scoreType) + if err != nil { + return + } + for _, s := range byScore { + // 缓存用户信息 + if ok := j.userCache.Contains(s.UserId); !ok { + if dbUser, err := j.svcCtx.UserPlatformModel.FindOneForRankByUserId(j.ctx, s.UserId); err == nil { + j.userCache.Add(dbUser.UserId, CachedUserInfo{ + UserId: dbUser.UserId, + Username: dbUser.PUname, + Avatar: dbUser.PAvatar, + }) + } + } + + if _, ok := rankZSet.Score(s.UserId); ok { + rankZSet.Update(s.UserId, int32(s.Score)) + } else { + rankZSet.Add(s.UserId, int32(s.Score)) + } + } +} + +func (j *Job) persistence(rankType int32) { + rankZSet, _, err := j.getRankInstanceAndScoreType(rankType) + if err != nil { + return + } + rank := rankZSet.RangeByRank(1, model.MaxRankN) + dbModel := make([]model.RankPvp, 0, len(rank)) + for _, r := range rank { + uid := r[0] + score := r[1] + dbModel = append(dbModel, model.RankPvp{ + Id: uuid.NextId(), + UserId: uid, + RankType: int64(rankType), + Score: score, + }) + } + if len(dbModel) > 0 { + if err = j.svcCtx.RankPvpModel.UpdateRank(j.ctx, rankType, dbModel); err != nil { + logx.Error("更新排行榜错误", err) + return + } + } +} + +func (j *Job) getRankInstanceAndScoreType(rankType int32) (*zset.ZSetInt, model.ScoreType, error) { + var rankZSet *zset.ZSetInt + scoreType := model.ScoreTypeDamage + switch rankType { + case model.RankTypeDamage: + rankZSet = j.damageRank + scoreType = model.ScoreTypeDamage + case model.RankTypeGeneral: + rankZSet = j.generalRank + scoreType = model.ScoreTypeGeneral + case model.RankTypeKillUnit: + rankZSet = j.killUnitRank + scoreType = model.ScoreTypeKillUnit + case model.RankTypeKillPlayer: + rankZSet = j.killPlayerRank + scoreType = model.ScoreTypeKillPlayer + } + if rankZSet == nil { + return nil, scoreType, errors.Errorf("没有此类型 [%d] 的排行榜", rankType) + } + return rankZSet, scoreType, nil +} diff --git a/app/user_center/rpc/internal/logic/rank/rank_job_test.go b/app/user_center/rpc/internal/logic/rank/rank_job_test.go new file mode 100644 index 0000000..6571c7a --- /dev/null +++ b/app/user_center/rpc/internal/logic/rank/rank_job_test.go @@ -0,0 +1,26 @@ +package rank + +import ( + "fmt" + zset "github.com/longzhiri/gozset" + "testing" +) + +func TestA(t *testing.T) { + //zs := zset.NewSkipListInt(func(l, r zset.IntOrderedKey) bool { + // return l.Score() > r.Score() + //}) + + z := zset.NewZSetInt(func(l, r int32) bool { + return l > r + }, 100) + + z.Add(1, 2) + z.Add(2, 100) + + z.Update(3, 20) + z.Add(2, 3000) + + a := z.RangeByRank(1, 100) + fmt.Printf("aaa: %+v", a) +} diff --git a/app/user_center/rpc/internal/logic/rank/rank_pvp_logic.go b/app/user_center/rpc/internal/logic/rank/rank_pvp_logic.go new file mode 100644 index 0000000..78313e1 --- /dev/null +++ b/app/user_center/rpc/internal/logic/rank/rank_pvp_logic.go @@ -0,0 +1,28 @@ +package rank + +import ( + "context" + "live-service/app/user_center/rpc/internal/svc" + "live-service/app/user_center/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type RankPvpLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewRankPvpLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RankPvpLogic { + return &RankPvpLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// rank +func (l *RankPvpLogic) RankPvp(in *pb.RankPvpReq) (*pb.RankPvpResp, error) { + return Service.RangeRankByType(in.Type, in.TopN), nil +} diff --git a/app/user_center/rpc/internal/logic/statistics/stat_pvp_damage_logic.go b/app/user_center/rpc/internal/logic/statistics/stat_pvp_damage_logic.go new file mode 100644 index 0000000..fcc47bc --- /dev/null +++ b/app/user_center/rpc/internal/logic/statistics/stat_pvp_damage_logic.go @@ -0,0 +1,66 @@ +package statistics + +import ( + "context" + "github.com/pkg/errors" + "live-service/app/user_center/model" + "live-service/app/user_center/rpc/internal/svc" + "live-service/app/user_center/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type StatPvpDamageLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewStatPvpDamageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatPvpDamageLogic { + return &StatPvpDamageLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// statistics +func (l *StatPvpDamageLogic) StatPvpDamage(in *pb.StatPvPDamageReq) (*pb.Empty, error) { + damage64 := int64(in.Damage) + exists, _ := l.svcCtx.StatisticsPvpModel.Exists(l.ctx, in.Uid) + if !exists { + dbModel := &model.StatisticsPvp{ + UserId: in.Uid, + Damage: damage64, + } + if err := l.svcCtx.StatisticsPvpModel.Insert(l.ctx, dbModel); err != nil { + return nil, errors.Wrapf(err, ErrInsertErr, err) + } + return &pb.Empty{}, nil + } + // 原始记录存在,直接更新,提高效率 + if err := l.svcCtx.StatisticsPvpModel.UpdateRecord(l.ctx, in.Uid, &model.UpdateRecordProps{Damage: &damage64}); err != nil { + return nil, errors.Wrapf(err, ErrUpdateErr, err) + } + // 承伤 + if in.TargetUid != nil { + tUid := *in.TargetUid + exists, _ = l.svcCtx.StatisticsPvpModel.Exists(l.ctx, tUid) + if !exists { + dbModel := &model.StatisticsPvp{ + UserId: tUid, + DeDamage: int64(in.Damage), + } + if err := l.svcCtx.StatisticsPvpModel.Insert(l.ctx, dbModel); err != nil { + return nil, errors.Wrapf(err, ErrInsertErr, err) + } + return &pb.Empty{}, nil + } + // 原始记录存在,直接更新,提高效率 + if err := l.svcCtx.StatisticsPvpModel.UpdateRecord(l.ctx, tUid, &model.UpdateRecordProps{DeDamage: &damage64}); err != nil { + return nil, errors.Wrapf(err, ErrUpdateErr, err) + } + } + + return &pb.Empty{}, nil +} diff --git a/app/user_center/rpc/internal/logic/statistics/stat_pvp_first_blood_logic.go b/app/user_center/rpc/internal/logic/statistics/stat_pvp_first_blood_logic.go new file mode 100644 index 0000000..af9f6c1 --- /dev/null +++ b/app/user_center/rpc/internal/logic/statistics/stat_pvp_first_blood_logic.go @@ -0,0 +1,62 @@ +package statistics + +import ( + "context" + "github.com/pkg/errors" + "live-service/app/user_center/model" + "live-service/app/user_center/rpc/internal/svc" + "live-service/app/user_center/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type StatPvpFirstBloodLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewStatPvpFirstBloodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatPvpFirstBloodLogic { + return &StatPvpFirstBloodLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +const ( + TypeFirstBlood = 1 + TypeDeFirstBlood = 2 +) + +func (l *StatPvpFirstBloodLogic) StatPvpFirstBlood(in *pb.StatPvPFirstBloodReq) (*pb.Empty, error) { + exists, _ := l.svcCtx.StatisticsPvpModel.Exists(l.ctx, in.Uid) + if !exists { + dbModel := &model.StatisticsPvp{ + UserId: in.Uid, + } + if in.Type == TypeFirstBlood { + dbModel.FirstBloodCount = 1 + } else if in.Type == TypeDeFirstBlood { + dbModel.DeFirstBloodCount = 1 + } + if err := l.svcCtx.StatisticsPvpModel.Insert(l.ctx, dbModel); err != nil { + return nil, errors.Wrapf(err, ErrInsertErr, err) + } + return &pb.Empty{}, nil + } + // 原始记录存在,直接更新,提高效率 + props := &model.UpdateRecordProps{} + if in.Type == TypeFirstBlood { + props.FirstBlood = true + } else if in.Type == TypeDeFirstBlood { + props.DeFirstBlood = true + } else { + l.Logger.Error("是否拿到一血 Type 有问题,不是1或2?") + return &pb.Empty{}, nil + } + if err := l.svcCtx.StatisticsPvpModel.UpdateRecord(l.ctx, in.Uid, props); err != nil { + return nil, errors.Wrapf(err, ErrUpdateErr, err) + } + return &pb.Empty{}, nil +} diff --git a/app/user_center/rpc/internal/logic/statistics/stat_pvp_kill_logic.go b/app/user_center/rpc/internal/logic/statistics/stat_pvp_kill_logic.go new file mode 100644 index 0000000..677e53b --- /dev/null +++ b/app/user_center/rpc/internal/logic/statistics/stat_pvp_kill_logic.go @@ -0,0 +1,69 @@ +package statistics + +import ( + "context" + "github.com/pkg/errors" + "live-service/app/user_center/model" + + "live-service/app/user_center/rpc/internal/svc" + "live-service/app/user_center/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type StatPvpKillLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewStatPvpKillLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatPvpKillLogic { + return &StatPvpKillLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *StatPvpKillLogic) StatPvpKill(in *pb.StatPvPKillReq) (*pb.Empty, error) { + exists, _ := l.svcCtx.StatisticsPvpModel.Exists(l.ctx, in.Uid) + if !exists { + dbModel := &model.StatisticsPvp{ + UserId: in.Uid, + KillPlayerCount: 1, + } + if err := l.svcCtx.StatisticsPvpModel.Insert(l.ctx, dbModel); err != nil { + return nil, errors.Wrapf(err, ErrInsertErr, err) + } + return &pb.Empty{}, nil + } + props := model.UpdateRecordProps{} + if err := l.svcCtx.StatisticsPvpModel.UpdateRecord(l.ctx, in.Uid, &props); err != nil { + return nil, errors.Wrapf(err, ErrUpdateErr, err) + } + // 被杀 + exists, _ = l.svcCtx.StatisticsPvpModel.Exists(l.ctx, in.TargetUid) + if !exists { + dbModel := &model.StatisticsPvp{ + UserId: in.TargetUid, + DeKillUnitCount: 1, + } + if in.IsGeneral { + dbModel.DeGeneralCount = 1 + } + if err := l.svcCtx.StatisticsPvpModel.Insert(l.ctx, dbModel); err != nil { + return nil, errors.Wrapf(err, ErrInsertErr, err) + } + return &pb.Empty{}, nil + } + props = model.UpdateRecordProps{ + DeKillPlayer: true, + } + if in.IsGeneral { + props.DeGeneral = true + } + if err := l.svcCtx.StatisticsPvpModel.UpdateRecord(l.ctx, in.TargetUid, &props); err != nil { + return nil, errors.Wrapf(err, ErrUpdateErr, err) + } + return &pb.Empty{}, nil +} diff --git a/app/user_center/rpc/internal/logic/statistics/stat_pvp_kill_unit_logic.go b/app/user_center/rpc/internal/logic/statistics/stat_pvp_kill_unit_logic.go new file mode 100644 index 0000000..cad5561 --- /dev/null +++ b/app/user_center/rpc/internal/logic/statistics/stat_pvp_kill_unit_logic.go @@ -0,0 +1,65 @@ +package statistics + +import ( + "context" + "github.com/pkg/errors" + "live-service/app/user_center/model" + + "live-service/app/user_center/rpc/internal/svc" + "live-service/app/user_center/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type StatPvpKillUnitLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewStatPvpKillUnitLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatPvpKillUnitLogic { + return &StatPvpKillUnitLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *StatPvpKillUnitLogic) StatPvpKillUnit(in *pb.StatPvPKillUnitReq) (*pb.Empty, error) { + exists, _ := l.svcCtx.StatisticsPvpModel.Exists(l.ctx, in.Uid) + if !exists { + dbModel := &model.StatisticsPvp{ + UserId: in.Uid, + KillUnitCount: 1, + } + if err := l.svcCtx.StatisticsPvpModel.Insert(l.ctx, dbModel); err != nil { + return nil, errors.Wrapf(err, ErrInsertErr, err) + } + return &pb.Empty{}, nil + } + // 原始记录存在,直接更新,提高效率 + if err := l.svcCtx.StatisticsPvpModel.UpdateRecord(l.ctx, in.Uid, &model.UpdateRecordProps{KillUnit: true}); err != nil { + return nil, errors.Wrapf(err, ErrUpdateErr, err) + } + // 被击杀 + if in.TargetUid != nil { + tUid := *in.TargetUid + exists, _ = l.svcCtx.StatisticsPvpModel.Exists(l.ctx, tUid) + if !exists { + dbModel := &model.StatisticsPvp{ + UserId: tUid, + DeKillUnitCount: 1, + } + if err := l.svcCtx.StatisticsPvpModel.Insert(l.ctx, dbModel); err != nil { + return nil, errors.Wrapf(err, ErrInsertErr, err) + } + return &pb.Empty{}, nil + } + // 原始记录存在,直接更新,提高效率 + if err := l.svcCtx.StatisticsPvpModel.UpdateRecord(l.ctx, tUid, &model.UpdateRecordProps{DeKillUnit: true}); err != nil { + return nil, errors.Wrapf(err, ErrUpdateErr, err) + } + } + + return &pb.Empty{}, nil +} diff --git a/app/user_center/rpc/internal/logic/statistics/stat_pvp_report_logic.go b/app/user_center/rpc/internal/logic/statistics/stat_pvp_report_logic.go new file mode 100644 index 0000000..cd4ceef --- /dev/null +++ b/app/user_center/rpc/internal/logic/statistics/stat_pvp_report_logic.go @@ -0,0 +1,50 @@ +package statistics + +import ( + "context" + "github.com/pkg/errors" + "live-service/app/user_center/model" + + "live-service/app/user_center/rpc/internal/svc" + "live-service/app/user_center/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type StatPvpReportLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewStatPvpReportLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatPvpReportLogic { + return &StatPvpReportLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *StatPvpReportLogic) StatPvpReport(in *pb.StatPvPReportReq) (*pb.Empty, error) { + // 名将 + exists, _ := l.svcCtx.StatisticsPvpModel.Exists(l.ctx, in.GeneralUid) + if !exists { + dbModel := &model.StatisticsPvp{ + UserId: in.GeneralUid, + GeneralCount: 1, + } + if err := l.svcCtx.StatisticsPvpModel.Insert(l.ctx, dbModel); err != nil { + return nil, errors.Wrapf(err, ErrInsertErr, err) + } + return &pb.Empty{}, nil + } + if err := l.svcCtx.StatisticsPvpModel.UpdateRecord(l.ctx, in.GeneralUid, &model.UpdateRecordProps{General: true}); err != nil { + return nil, errors.Wrapf(err, ErrUpdateErr, err) + } + // 获胜记录 + // 战败记录 + if err := l.svcCtx.StatisticsPvpModel.RecordPvp(l.ctx, in.WinUids, in.LostUids); err != nil { + return nil, errors.Wrapf(err, ErrUpdateErr, err) + } + return &pb.Empty{}, nil +} diff --git a/app/user_center/rpc/internal/logic/statistics/vars.go b/app/user_center/rpc/internal/logic/statistics/vars.go new file mode 100644 index 0000000..5bb0270 --- /dev/null +++ b/app/user_center/rpc/internal/logic/statistics/vars.go @@ -0,0 +1,6 @@ +package statistics + +const ( + ErrInsertErr = "新建玩家PvP战斗数据失败: %v" + ErrUpdateErr = "更新玩家PvP战斗数据失败: %v" +) diff --git a/app/user_center/rpc/internal/server/user_center_server.go b/app/user_center/rpc/internal/server/user_center_server.go index 6560ba2..43a5bb0 100644 --- a/app/user_center/rpc/internal/server/user_center_server.go +++ b/app/user_center/rpc/internal/server/user_center_server.go @@ -1,10 +1,12 @@ // Code generated by goctl. DO NOT EDIT! -// Source: gift.proto +// Source: user_center.proto package server import ( "context" + "live-service/app/user_center/rpc/internal/logic/rank" + "live-service/app/user_center/rpc/internal/logic/statistics" "live-service/app/user_center/rpc/internal/logic" "live-service/app/user_center/rpc/internal/svc" @@ -27,3 +29,35 @@ func (s *UserCenterServer) RetrievePlatformUser(ctx context.Context, in *pb.Plat l := logic.NewRetrievePlatformUserLogic(ctx, s.svcCtx) return l.RetrievePlatformUser(in) } + +// statistics +func (s *UserCenterServer) StatPvpDamage(ctx context.Context, in *pb.StatPvPDamageReq) (*pb.Empty, error) { + l := statistics.NewStatPvpDamageLogic(ctx, s.svcCtx) + return l.StatPvpDamage(in) +} + +func (s *UserCenterServer) StatPvpKillUnit(ctx context.Context, in *pb.StatPvPKillUnitReq) (*pb.Empty, error) { + l := statistics.NewStatPvpKillUnitLogic(ctx, s.svcCtx) + return l.StatPvpKillUnit(in) +} + +func (s *UserCenterServer) StatPvpKill(ctx context.Context, in *pb.StatPvPKillReq) (*pb.Empty, error) { + l := statistics.NewStatPvpKillLogic(ctx, s.svcCtx) + return l.StatPvpKill(in) +} + +func (s *UserCenterServer) StatPvpFirstBlood(ctx context.Context, in *pb.StatPvPFirstBloodReq) (*pb.Empty, error) { + l := statistics.NewStatPvpFirstBloodLogic(ctx, s.svcCtx) + return l.StatPvpFirstBlood(in) +} + +func (s *UserCenterServer) StatPvpReport(ctx context.Context, in *pb.StatPvPReportReq) (*pb.Empty, error) { + l := statistics.NewStatPvpReportLogic(ctx, s.svcCtx) + return l.StatPvpReport(in) +} + +// rank +func (s *UserCenterServer) RankPvp(ctx context.Context, in *pb.RankPvpReq) (*pb.RankPvpResp, error) { + l := rank.NewRankPvpLogic(ctx, s.svcCtx) + return l.RankPvp(in) +} diff --git a/app/user_center/rpc/internal/svc/service_context.go b/app/user_center/rpc/internal/svc/service_context.go index 0e90a51..1b1b7b3 100644 --- a/app/user_center/rpc/internal/svc/service_context.go +++ b/app/user_center/rpc/internal/svc/service_context.go @@ -3,26 +3,43 @@ package svc import ( "gorm.io/driver/mysql" "gorm.io/gorm" + "gorm.io/gorm/logger" "live-service/app/user_center/model" "live-service/app/user_center/rpc/internal/config" "log" + "os" + "time" ) type ServiceContext struct { Config config.Config - UserModel model.UserModel - UserPlatformModel model.UserPlatformModel + UserModel model.UserModel + UserPlatformModel model.UserPlatformModel + StatisticsPvpModel model.StatisticsPvpModel + RankPvpModel model.RankPvpModel } func NewServiceContext(c config.Config) *ServiceContext { - gormDb, err := gorm.Open(mysql.Open(c.DB.DataSource), &gorm.Config{}) + gormDb, err := gorm.Open(mysql.Open(c.DB.DataSource), &gorm.Config{ + Logger: logger.New( + log.New(os.Stdout, "\r\n", log.LstdFlags), + logger.Config{ + SlowThreshold: 1 * time.Second, + LogLevel: logger.Warn, + IgnoreRecordNotFoundError: true, + Colorful: true, + }, + ), + }) if err != nil { log.Fatal(err) } return &ServiceContext{ - Config: c, - UserModel: model.NewUserModel(gormDb), - UserPlatformModel: model.NewUserPlatformModel(gormDb), + Config: c, + UserModel: model.NewUserModel(gormDb), + UserPlatformModel: model.NewUserPlatformModel(gormDb), + StatisticsPvpModel: model.NewStatisticsPvpModel(gormDb), + RankPvpModel: model.NewRankPvpModel(gormDb), } } diff --git a/app/user_center/rpc/pb/generate.go b/app/user_center/rpc/pb/generate.go index dbb41e0..12c2758 100644 --- a/app/user_center/rpc/pb/generate.go +++ b/app/user_center/rpc/pb/generate.go @@ -1,3 +1,3 @@ package pb -//go:generate goctl rpc protoc gift.proto --style=go_zero --go_out=../ --go-grpc_out=../ --zrpc_out=../ +//go:generate goctl rpc protoc user_center.proto --style=go_zero --go_out=../ --go-grpc_out=../ --zrpc_out=../ diff --git a/app/user_center/rpc/pb/user_center.pb.go b/app/user_center/rpc/pb/user_center.pb.go index 2fa3604..224c6c7 100644 --- a/app/user_center/rpc/pb/user_center.pb.go +++ b/app/user_center/rpc/pb/user_center.pb.go @@ -1,8 +1,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.0 +// protoc-gen-go v1.27.1 // protoc v3.19.4 -// source: gift.proto +// source: user_center.proto package pb @@ -117,6 +117,44 @@ func (x *User) GetPInfo() string { return "" } +type Empty struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Empty) Reset() { + *x = Empty{} + if protoimpl.UnsafeEnabled { + mi := &file_user_center_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Empty) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Empty) ProtoMessage() {} + +func (x *Empty) ProtoReflect() protoreflect.Message { + mi := &file_user_center_proto_msgTypes[1] + 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 Empty.ProtoReflect.Descriptor instead. +func (*Empty) Descriptor() ([]byte, []int) { + return file_user_center_proto_rawDescGZIP(), []int{1} +} + // req type PlatformUserReq struct { state protoimpl.MessageState @@ -130,7 +168,7 @@ type PlatformUserReq struct { func (x *PlatformUserReq) Reset() { *x = PlatformUserReq{} if protoimpl.UnsafeEnabled { - mi := &file_user_center_proto_msgTypes[1] + mi := &file_user_center_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -143,7 +181,7 @@ func (x *PlatformUserReq) String() string { func (*PlatformUserReq) ProtoMessage() {} func (x *PlatformUserReq) ProtoReflect() protoreflect.Message { - mi := &file_user_center_proto_msgTypes[1] + mi := &file_user_center_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -156,7 +194,7 @@ func (x *PlatformUserReq) ProtoReflect() protoreflect.Message { // Deprecated: Use PlatformUserReq.ProtoReflect.Descriptor instead. func (*PlatformUserReq) Descriptor() ([]byte, []int) { - return file_user_center_proto_rawDescGZIP(), []int{1} + return file_user_center_proto_rawDescGZIP(), []int{2} } func (x *PlatformUserReq) GetPlatform() string { @@ -184,7 +222,7 @@ type PlatformUserResp struct { func (x *PlatformUserResp) Reset() { *x = PlatformUserResp{} if protoimpl.UnsafeEnabled { - mi := &file_user_center_proto_msgTypes[2] + mi := &file_user_center_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -197,7 +235,7 @@ func (x *PlatformUserResp) String() string { func (*PlatformUserResp) ProtoMessage() {} func (x *PlatformUserResp) ProtoReflect() protoreflect.Message { - mi := &file_user_center_proto_msgTypes[2] + mi := &file_user_center_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -210,7 +248,7 @@ func (x *PlatformUserResp) ProtoReflect() protoreflect.Message { // Deprecated: Use PlatformUserResp.ProtoReflect.Descriptor instead. func (*PlatformUserResp) Descriptor() ([]byte, []int) { - return file_user_center_proto_rawDescGZIP(), []int{2} + return file_user_center_proto_rawDescGZIP(), []int{3} } func (x *PlatformUserResp) GetUser() *User { @@ -220,6 +258,516 @@ func (x *PlatformUserResp) GetUser() *User { return nil } +// 通知-PvP伤害 statistics.pvp.damage +type StatPvPDamageReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uid int64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"` // 造成伤害的用户ID + TargetUid *int64 `protobuf:"varint,2,opt,name=targetUid,proto3,oneof" json:"targetUid,omitempty"` // 目标用户ID(可能是基地,不一定有) + Damage float32 `protobuf:"fixed32,3,opt,name=damage,proto3" json:"damage,omitempty"` // 伤害量 +} + +func (x *StatPvPDamageReq) Reset() { + *x = StatPvPDamageReq{} + if protoimpl.UnsafeEnabled { + mi := &file_user_center_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StatPvPDamageReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatPvPDamageReq) ProtoMessage() {} + +func (x *StatPvPDamageReq) ProtoReflect() protoreflect.Message { + mi := &file_user_center_proto_msgTypes[4] + 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 StatPvPDamageReq.ProtoReflect.Descriptor instead. +func (*StatPvPDamageReq) Descriptor() ([]byte, []int) { + return file_user_center_proto_rawDescGZIP(), []int{4} +} + +func (x *StatPvPDamageReq) GetUid() int64 { + if x != nil { + return x.Uid + } + return 0 +} + +func (x *StatPvPDamageReq) GetTargetUid() int64 { + if x != nil && x.TargetUid != nil { + return *x.TargetUid + } + return 0 +} + +func (x *StatPvPDamageReq) GetDamage() float32 { + if x != nil { + return x.Damage + } + return 0 +} + +// 通知-PvP击杀单位 statistics.pvp.killunit +type StatPvPKillUnitReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uid int64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"` // 用户ID + TargetUid *int64 `protobuf:"varint,2,opt,name=targetUid,proto3,oneof" json:"targetUid,omitempty"` // 目标用户 + Attacker string `protobuf:"bytes,3,opt,name=attacker,proto3" json:"attacker,omitempty"` // 造成击杀东西(building:兵营 U0001:xxx兵 S0001: 技能) + Victim string `protobuf:"bytes,4,opt,name=victim,proto3" json:"victim,omitempty"` // 被击杀的东西(U0001:xxx兵) +} + +func (x *StatPvPKillUnitReq) Reset() { + *x = StatPvPKillUnitReq{} + if protoimpl.UnsafeEnabled { + mi := &file_user_center_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StatPvPKillUnitReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatPvPKillUnitReq) ProtoMessage() {} + +func (x *StatPvPKillUnitReq) ProtoReflect() protoreflect.Message { + mi := &file_user_center_proto_msgTypes[5] + 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 StatPvPKillUnitReq.ProtoReflect.Descriptor instead. +func (*StatPvPKillUnitReq) Descriptor() ([]byte, []int) { + return file_user_center_proto_rawDescGZIP(), []int{5} +} + +func (x *StatPvPKillUnitReq) GetUid() int64 { + if x != nil { + return x.Uid + } + return 0 +} + +func (x *StatPvPKillUnitReq) GetTargetUid() int64 { + if x != nil && x.TargetUid != nil { + return *x.TargetUid + } + return 0 +} + +func (x *StatPvPKillUnitReq) GetAttacker() string { + if x != nil { + return x.Attacker + } + return "" +} + +func (x *StatPvPKillUnitReq) GetVictim() string { + if x != nil { + return x.Victim + } + return "" +} + +// 通知-PvP杀兵营(人) statistics.pvp.kill +type StatPvPKillReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uid int64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"` // 用户ID + TargetUid int64 `protobuf:"varint,2,opt,name=targetUid,proto3" json:"targetUid,omitempty"` // 目标用户 + IsGeneral bool `protobuf:"varint,3,opt,name=isGeneral,proto3" json:"isGeneral,omitempty"` // targetUid是否名将 +} + +func (x *StatPvPKillReq) Reset() { + *x = StatPvPKillReq{} + if protoimpl.UnsafeEnabled { + mi := &file_user_center_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StatPvPKillReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatPvPKillReq) ProtoMessage() {} + +func (x *StatPvPKillReq) ProtoReflect() protoreflect.Message { + mi := &file_user_center_proto_msgTypes[6] + 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 StatPvPKillReq.ProtoReflect.Descriptor instead. +func (*StatPvPKillReq) Descriptor() ([]byte, []int) { + return file_user_center_proto_rawDescGZIP(), []int{6} +} + +func (x *StatPvPKillReq) GetUid() int64 { + if x != nil { + return x.Uid + } + return 0 +} + +func (x *StatPvPKillReq) GetTargetUid() int64 { + if x != nil { + return x.TargetUid + } + return 0 +} + +func (x *StatPvPKillReq) GetIsGeneral() bool { + if x != nil { + return x.IsGeneral + } + return false +} + +// 通知-PvP一血 statistics.pvp.first +type StatPvPFirstBloodReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uid int64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"` // 用户ID + Type int32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` // 1-拿到一血 2-被破一血 +} + +func (x *StatPvPFirstBloodReq) Reset() { + *x = StatPvPFirstBloodReq{} + if protoimpl.UnsafeEnabled { + mi := &file_user_center_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StatPvPFirstBloodReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatPvPFirstBloodReq) ProtoMessage() {} + +func (x *StatPvPFirstBloodReq) ProtoReflect() protoreflect.Message { + mi := &file_user_center_proto_msgTypes[7] + 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 StatPvPFirstBloodReq.ProtoReflect.Descriptor instead. +func (*StatPvPFirstBloodReq) Descriptor() ([]byte, []int) { + return file_user_center_proto_rawDescGZIP(), []int{7} +} + +func (x *StatPvPFirstBloodReq) GetUid() int64 { + if x != nil { + return x.Uid + } + return 0 +} + +func (x *StatPvPFirstBloodReq) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + +// 通知-PvP战报 statistics.pvp.report +type StatPvPReportReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + WinCamp int32 `protobuf:"varint,1,opt,name=winCamp,proto3" json:"winCamp,omitempty"` // 获胜阵营 1-蓝 2-红 + GeneralUid int64 `protobuf:"varint,2,opt,name=generalUid,proto3" json:"generalUid,omitempty"` // 名将UID + WinUids []int64 `protobuf:"varint,3,rep,packed,name=winUids,proto3" json:"winUids,omitempty"` // 战胜方玩家列表 + LostUids []int64 `protobuf:"varint,4,rep,packed,name=lostUids,proto3" json:"lostUids,omitempty"` // 战败方玩家列表 +} + +func (x *StatPvPReportReq) Reset() { + *x = StatPvPReportReq{} + if protoimpl.UnsafeEnabled { + mi := &file_user_center_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StatPvPReportReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatPvPReportReq) ProtoMessage() {} + +func (x *StatPvPReportReq) ProtoReflect() protoreflect.Message { + mi := &file_user_center_proto_msgTypes[8] + 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 StatPvPReportReq.ProtoReflect.Descriptor instead. +func (*StatPvPReportReq) Descriptor() ([]byte, []int) { + return file_user_center_proto_rawDescGZIP(), []int{8} +} + +func (x *StatPvPReportReq) GetWinCamp() int32 { + if x != nil { + return x.WinCamp + } + return 0 +} + +func (x *StatPvPReportReq) GetGeneralUid() int64 { + if x != nil { + return x.GeneralUid + } + return 0 +} + +func (x *StatPvPReportReq) GetWinUids() []int64 { + if x != nil { + return x.WinUids + } + return nil +} + +func (x *StatPvPReportReq) GetLostUids() []int64 { + if x != nil { + return x.LostUids + } + return nil +} + +// rank +type RankPvpReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Type int32 `protobuf:"varint,1,opt,name=type,proto3" json:"type,omitempty"` // rank类型 + TopN int32 `protobuf:"varint,2,opt,name=topN,proto3" json:"topN,omitempty"` // TopN +} + +func (x *RankPvpReq) Reset() { + *x = RankPvpReq{} + if protoimpl.UnsafeEnabled { + mi := &file_user_center_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RankPvpReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RankPvpReq) ProtoMessage() {} + +func (x *RankPvpReq) ProtoReflect() protoreflect.Message { + mi := &file_user_center_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 RankPvpReq.ProtoReflect.Descriptor instead. +func (*RankPvpReq) Descriptor() ([]byte, []int) { + return file_user_center_proto_rawDescGZIP(), []int{9} +} + +func (x *RankPvpReq) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + +func (x *RankPvpReq) GetTopN() int32 { + if x != nil { + return x.TopN + } + return 0 +} + +type RankPvpResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Type int32 `protobuf:"varint,1,opt,name=type,proto3" json:"type,omitempty"` // rank类型 + Items []*RankPvpResp_Item `protobuf:"bytes,2,rep,name=items,proto3" json:"items,omitempty"` // rank数据 +} + +func (x *RankPvpResp) Reset() { + *x = RankPvpResp{} + if protoimpl.UnsafeEnabled { + mi := &file_user_center_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RankPvpResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RankPvpResp) ProtoMessage() {} + +func (x *RankPvpResp) ProtoReflect() protoreflect.Message { + mi := &file_user_center_proto_msgTypes[10] + 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 RankPvpResp.ProtoReflect.Descriptor instead. +func (*RankPvpResp) Descriptor() ([]byte, []int) { + return file_user_center_proto_rawDescGZIP(), []int{10} +} + +func (x *RankPvpResp) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + +func (x *RankPvpResp) GetItems() []*RankPvpResp_Item { + if x != nil { + return x.Items + } + return nil +} + +type RankPvpResp_Item struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uid int64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"` + Uname string `protobuf:"bytes,2,opt,name=uname,proto3" json:"uname,omitempty"` + Score int64 `protobuf:"varint,3,opt,name=score,proto3" json:"score,omitempty"` + Avatar string `protobuf:"bytes,4,opt,name=avatar,proto3" json:"avatar,omitempty"` +} + +func (x *RankPvpResp_Item) Reset() { + *x = RankPvpResp_Item{} + if protoimpl.UnsafeEnabled { + mi := &file_user_center_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RankPvpResp_Item) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RankPvpResp_Item) ProtoMessage() {} + +func (x *RankPvpResp_Item) ProtoReflect() protoreflect.Message { + mi := &file_user_center_proto_msgTypes[11] + 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 RankPvpResp_Item.ProtoReflect.Descriptor instead. +func (*RankPvpResp_Item) Descriptor() ([]byte, []int) { + return file_user_center_proto_rawDescGZIP(), []int{10, 0} +} + +func (x *RankPvpResp_Item) GetUid() int64 { + if x != nil { + return x.Uid + } + return 0 +} + +func (x *RankPvpResp_Item) GetUname() string { + if x != nil { + return x.Uname + } + return "" +} + +func (x *RankPvpResp_Item) GetScore() int64 { + if x != nil { + return x.Score + } + return 0 +} + +func (x *RankPvpResp_Item) GetAvatar() string { + if x != nil { + return x.Avatar + } + return "" +} + var File_user_center_proto protoreflect.FileDescriptor var file_user_center_proto_rawDesc = []byte{ @@ -235,20 +783,88 @@ var file_user_center_proto_rawDesc = []byte{ 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70, - 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x41, 0x0a, 0x0f, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, - 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, - 0x6f, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, - 0x6f, 0x72, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x55, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x70, 0x55, 0x69, 0x64, 0x22, 0x30, 0x0a, 0x10, 0x50, 0x6c, 0x61, 0x74, 0x66, - 0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1c, 0x0a, 0x04, 0x75, - 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, - 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x32, 0x4f, 0x0a, 0x0a, 0x75, 0x73, 0x65, - 0x72, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x41, 0x0a, 0x14, 0x72, 0x65, 0x74, 0x72, 0x69, - 0x65, 0x76, 0x65, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x12, - 0x13, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65, - 0x72, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, - 0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, - 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x41, 0x0a, + 0x0f, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x12, 0x0a, 0x04, + 0x70, 0x55, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x55, 0x69, 0x64, + 0x22, 0x30, 0x0a, 0x10, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, + 0x52, 0x65, 0x73, 0x70, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, + 0x65, 0x72, 0x22, 0x6d, 0x0a, 0x10, 0x53, 0x74, 0x61, 0x74, 0x50, 0x76, 0x50, 0x44, 0x61, 0x6d, + 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x21, 0x0a, 0x09, 0x74, 0x61, 0x72, 0x67, + 0x65, 0x74, 0x55, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, 0x09, 0x74, + 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64, 0x88, 0x01, 0x01, 0x12, 0x16, 0x0a, 0x06, 0x64, + 0x61, 0x6d, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x02, 0x52, 0x06, 0x64, 0x61, 0x6d, + 0x61, 0x67, 0x65, 0x42, 0x0c, 0x0a, 0x0a, 0x5f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, + 0x64, 0x22, 0x8b, 0x01, 0x0a, 0x12, 0x53, 0x74, 0x61, 0x74, 0x50, 0x76, 0x50, 0x4b, 0x69, 0x6c, + 0x6c, 0x55, 0x6e, 0x69, 0x74, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x21, 0x0a, 0x09, 0x74, 0x61, + 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, + 0x09, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64, 0x88, 0x01, 0x01, 0x12, 0x1a, 0x0a, + 0x08, 0x61, 0x74, 0x74, 0x61, 0x63, 0x6b, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x61, 0x74, 0x74, 0x61, 0x63, 0x6b, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x76, 0x69, 0x63, + 0x74, 0x69, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x76, 0x69, 0x63, 0x74, 0x69, + 0x6d, 0x42, 0x0c, 0x0a, 0x0a, 0x5f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64, 0x22, + 0x5e, 0x0a, 0x0e, 0x53, 0x74, 0x61, 0x74, 0x50, 0x76, 0x50, 0x4b, 0x69, 0x6c, 0x6c, 0x52, 0x65, + 0x71, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, + 0x75, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, + 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x73, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x22, + 0x3c, 0x0a, 0x14, 0x53, 0x74, 0x61, 0x74, 0x50, 0x76, 0x50, 0x46, 0x69, 0x72, 0x73, 0x74, 0x42, + 0x6c, 0x6f, 0x6f, 0x64, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x82, 0x01, + 0x0a, 0x10, 0x53, 0x74, 0x61, 0x74, 0x50, 0x76, 0x50, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, + 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x77, 0x69, 0x6e, 0x43, 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x07, 0x77, 0x69, 0x6e, 0x43, 0x61, 0x6d, 0x70, 0x12, 0x1e, 0x0a, 0x0a, + 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x55, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x0a, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x55, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, + 0x77, 0x69, 0x6e, 0x55, 0x69, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x03, 0x52, 0x07, 0x77, + 0x69, 0x6e, 0x55, 0x69, 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x6f, 0x73, 0x74, 0x55, 0x69, + 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x03, 0x52, 0x08, 0x6c, 0x6f, 0x73, 0x74, 0x55, 0x69, + 0x64, 0x73, 0x22, 0x34, 0x0a, 0x0a, 0x52, 0x61, 0x6e, 0x6b, 0x50, 0x76, 0x70, 0x52, 0x65, 0x71, + 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, + 0x74, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x6f, 0x70, 0x4e, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x04, 0x74, 0x6f, 0x70, 0x4e, 0x22, 0xab, 0x01, 0x0a, 0x0b, 0x52, 0x61, 0x6e, + 0x6b, 0x50, 0x76, 0x70, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x2a, 0x0a, 0x05, + 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x70, 0x62, + 0x2e, 0x52, 0x61, 0x6e, 0x6b, 0x50, 0x76, 0x70, 0x52, 0x65, 0x73, 0x70, 0x2e, 0x49, 0x74, 0x65, + 0x6d, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x1a, 0x5c, 0x0a, 0x04, 0x49, 0x74, 0x65, 0x6d, + 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, + 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x75, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x05, 0x75, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x16, + 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x32, 0xfd, 0x02, 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x43, + 0x65, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x41, 0x0a, 0x14, 0x72, 0x65, 0x74, 0x72, 0x69, 0x65, 0x76, + 0x65, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x12, 0x13, 0x2e, + 0x70, 0x62, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x52, + 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, + 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x30, 0x0a, 0x0d, 0x73, 0x74, 0x61, 0x74, + 0x50, 0x76, 0x70, 0x44, 0x61, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x14, 0x2e, 0x70, 0x62, 0x2e, 0x53, + 0x74, 0x61, 0x74, 0x50, 0x76, 0x50, 0x44, 0x61, 0x6d, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x1a, + 0x09, 0x2e, 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x34, 0x0a, 0x0f, 0x73, 0x74, + 0x61, 0x74, 0x50, 0x76, 0x70, 0x4b, 0x69, 0x6c, 0x6c, 0x55, 0x6e, 0x69, 0x74, 0x12, 0x16, 0x2e, + 0x70, 0x62, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x50, 0x76, 0x50, 0x4b, 0x69, 0x6c, 0x6c, 0x55, 0x6e, + 0x69, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x09, 0x2e, 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x12, 0x2c, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x74, 0x50, 0x76, 0x70, 0x4b, 0x69, 0x6c, 0x6c, 0x12, + 0x12, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x50, 0x76, 0x50, 0x4b, 0x69, 0x6c, 0x6c, + 0x52, 0x65, 0x71, 0x1a, 0x09, 0x2e, 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x38, + 0x0a, 0x11, 0x73, 0x74, 0x61, 0x74, 0x50, 0x76, 0x70, 0x46, 0x69, 0x72, 0x73, 0x74, 0x42, 0x6c, + 0x6f, 0x6f, 0x64, 0x12, 0x18, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x50, 0x76, 0x50, + 0x46, 0x69, 0x72, 0x73, 0x74, 0x42, 0x6c, 0x6f, 0x6f, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x09, 0x2e, + 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x30, 0x0a, 0x0d, 0x73, 0x74, 0x61, 0x74, + 0x50, 0x76, 0x70, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x14, 0x2e, 0x70, 0x62, 0x2e, 0x53, + 0x74, 0x61, 0x74, 0x50, 0x76, 0x50, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x65, 0x71, 0x1a, + 0x09, 0x2e, 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x2a, 0x0a, 0x07, 0x72, 0x61, + 0x6e, 0x6b, 0x50, 0x76, 0x70, 0x12, 0x0e, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x61, 0x6e, 0x6b, 0x50, + 0x76, 0x70, 0x52, 0x65, 0x71, 0x1a, 0x0f, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x61, 0x6e, 0x6b, 0x50, + 0x76, 0x70, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -263,21 +879,43 @@ func file_user_center_proto_rawDescGZIP() []byte { return file_user_center_proto_rawDescData } -var file_user_center_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_user_center_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_user_center_proto_goTypes = []interface{}{ - (*User)(nil), // 0: pb.User - (*PlatformUserReq)(nil), // 1: pb.PlatformUserReq - (*PlatformUserResp)(nil), // 2: pb.PlatformUserResp + (*User)(nil), // 0: pb.User + (*Empty)(nil), // 1: pb.Empty + (*PlatformUserReq)(nil), // 2: pb.PlatformUserReq + (*PlatformUserResp)(nil), // 3: pb.PlatformUserResp + (*StatPvPDamageReq)(nil), // 4: pb.StatPvPDamageReq + (*StatPvPKillUnitReq)(nil), // 5: pb.StatPvPKillUnitReq + (*StatPvPKillReq)(nil), // 6: pb.StatPvPKillReq + (*StatPvPFirstBloodReq)(nil), // 7: pb.StatPvPFirstBloodReq + (*StatPvPReportReq)(nil), // 8: pb.StatPvPReportReq + (*RankPvpReq)(nil), // 9: pb.RankPvpReq + (*RankPvpResp)(nil), // 10: pb.RankPvpResp + (*RankPvpResp_Item)(nil), // 11: pb.RankPvpResp.Item } var file_user_center_proto_depIdxs = []int32{ - 0, // 0: pb.PlatformUserResp.user:type_name -> pb.User - 1, // 1: pb.userCenter.retrievePlatformUser:input_type -> pb.PlatformUserReq - 2, // 2: pb.userCenter.retrievePlatformUser:output_type -> pb.PlatformUserResp - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] 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 + 0, // 0: pb.PlatformUserResp.user:type_name -> pb.User + 11, // 1: pb.RankPvpResp.items:type_name -> pb.RankPvpResp.Item + 2, // 2: pb.userCenter.retrievePlatformUser:input_type -> pb.PlatformUserReq + 4, // 3: pb.userCenter.statPvpDamage:input_type -> pb.StatPvPDamageReq + 5, // 4: pb.userCenter.statPvpKillUnit:input_type -> pb.StatPvPKillUnitReq + 6, // 5: pb.userCenter.statPvpKill:input_type -> pb.StatPvPKillReq + 7, // 6: pb.userCenter.statPvpFirstBlood:input_type -> pb.StatPvPFirstBloodReq + 8, // 7: pb.userCenter.statPvpReport:input_type -> pb.StatPvPReportReq + 9, // 8: pb.userCenter.rankPvp:input_type -> pb.RankPvpReq + 3, // 9: pb.userCenter.retrievePlatformUser:output_type -> pb.PlatformUserResp + 1, // 10: pb.userCenter.statPvpDamage:output_type -> pb.Empty + 1, // 11: pb.userCenter.statPvpKillUnit:output_type -> pb.Empty + 1, // 12: pb.userCenter.statPvpKill:output_type -> pb.Empty + 1, // 13: pb.userCenter.statPvpFirstBlood:output_type -> pb.Empty + 1, // 14: pb.userCenter.statPvpReport:output_type -> pb.Empty + 10, // 15: pb.userCenter.rankPvp:output_type -> pb.RankPvpResp + 9, // [9:16] is the sub-list for method output_type + 2, // [2:9] 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_user_center_proto_init() } @@ -299,7 +937,7 @@ func file_user_center_proto_init() { } } file_user_center_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PlatformUserReq); i { + switch v := v.(*Empty); i { case 0: return &v.state case 1: @@ -311,6 +949,18 @@ func file_user_center_proto_init() { } } file_user_center_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PlatformUserReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_user_center_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PlatformUserResp); i { case 0: return &v.state @@ -322,14 +972,112 @@ func file_user_center_proto_init() { return nil } } + file_user_center_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StatPvPDamageReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_user_center_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StatPvPKillUnitReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_user_center_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StatPvPKillReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_user_center_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StatPvPFirstBloodReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_user_center_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StatPvPReportReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_user_center_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RankPvpReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_user_center_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RankPvpResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_user_center_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RankPvpResp_Item); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } + file_user_center_proto_msgTypes[4].OneofWrappers = []interface{}{} + file_user_center_proto_msgTypes[5].OneofWrappers = []interface{}{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_user_center_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 12, NumExtensions: 0, NumServices: 1, }, diff --git a/app/user_center/rpc/pb/user_center.proto b/app/user_center/rpc/pb/user_center.proto index 2ffe8a0..465f618 100644 --- a/app/user_center/rpc/pb/user_center.proto +++ b/app/user_center/rpc/pb/user_center.proto @@ -16,6 +16,8 @@ message User { string pInfo = 7; } +message Empty {} + // req message PlatformUserReq { string platform = 1; @@ -26,8 +28,70 @@ message PlatformUserResp { User user = 1; } +// 通知-PvP伤害 statistics.pvp.damage +message StatPvPDamageReq { + int64 uid = 1; // 造成伤害的用户ID + optional int64 targetUid = 2; // 目标用户ID(可能是基地,不一定有) + float damage = 3; // 伤害量 +} + +// 通知-PvP击杀单位 statistics.pvp.killunit +message StatPvPKillUnitReq { + int64 uid = 1; // 用户ID + optional int64 targetUid = 2; // 目标用户 + string attacker = 3; // 造成击杀东西(building:兵营 U0001:xxx兵 S0001: 技能) + string victim = 4; // 被击杀的东西(U0001:xxx兵) +} + +// 通知-PvP杀兵营(人) statistics.pvp.kill +message StatPvPKillReq { + int64 uid = 1; // 用户ID + int64 targetUid = 2; // 目标用户 + bool isGeneral = 3; // targetUid是否名将 +} + +// 通知-PvP一血 statistics.pvp.first +message StatPvPFirstBloodReq { + int64 uid = 1; // 用户ID + int32 type = 2; // 1-拿到一血 2-被破一血 +} + +// 通知-PvP战报 statistics.pvp.report +message StatPvPReportReq { + int32 winCamp = 1; // 获胜阵营 1-蓝 2-红 + int64 generalUid = 2; // 名将UID + repeated int64 winUids = 3; // 战胜方玩家列表 + repeated int64 lostUids = 4; // 战败方玩家列表 +} + +// rank +message RankPvpReq { + int32 type = 1; // rank类型 + int32 topN = 2; // TopN +} + +message RankPvpResp { + message Item { + int64 uid = 1; + string uname = 2; + int64 score = 3; + string avatar = 4; + } + int32 type = 1; // rank类型 + repeated Item items = 2; // rank数据 +} service userCenter { // user rpc retrievePlatformUser(PlatformUserReq) returns (PlatformUserResp); + + // statistics + rpc statPvpDamage(StatPvPDamageReq) returns (Empty); + rpc statPvpKillUnit(StatPvPKillUnitReq) returns (Empty); + rpc statPvpKill(StatPvPKillReq) returns (Empty); + rpc statPvpFirstBlood(StatPvPFirstBloodReq) returns (Empty); + rpc statPvpReport(StatPvPReportReq) returns (Empty); + + // rank + rpc rankPvp(RankPvpReq) returns(RankPvpResp); } \ No newline at end of file diff --git a/app/user_center/rpc/pb/user_center_grpc.pb.go b/app/user_center/rpc/pb/user_center_grpc.pb.go index dbb0ad5..35dd5b7 100644 --- a/app/user_center/rpc/pb/user_center_grpc.pb.go +++ b/app/user_center/rpc/pb/user_center_grpc.pb.go @@ -2,7 +2,7 @@ // versions: // - protoc-gen-go-grpc v1.2.0 // - protoc v3.19.4 -// source: gift.proto +// source: user_center.proto package pb @@ -24,6 +24,14 @@ const _ = grpc.SupportPackageIsVersion7 type UserCenterClient interface { // user RetrievePlatformUser(ctx context.Context, in *PlatformUserReq, opts ...grpc.CallOption) (*PlatformUserResp, error) + // statistics + StatPvpDamage(ctx context.Context, in *StatPvPDamageReq, opts ...grpc.CallOption) (*Empty, error) + StatPvpKillUnit(ctx context.Context, in *StatPvPKillUnitReq, opts ...grpc.CallOption) (*Empty, error) + StatPvpKill(ctx context.Context, in *StatPvPKillReq, opts ...grpc.CallOption) (*Empty, error) + StatPvpFirstBlood(ctx context.Context, in *StatPvPFirstBloodReq, opts ...grpc.CallOption) (*Empty, error) + StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*Empty, error) + // rank + RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error) } type userCenterClient struct { @@ -43,12 +51,74 @@ func (c *userCenterClient) RetrievePlatformUser(ctx context.Context, in *Platfor return out, nil } +func (c *userCenterClient) StatPvpDamage(ctx context.Context, in *StatPvPDamageReq, opts ...grpc.CallOption) (*Empty, error) { + out := new(Empty) + err := c.cc.Invoke(ctx, "/pb.userCenter/statPvpDamage", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *userCenterClient) StatPvpKillUnit(ctx context.Context, in *StatPvPKillUnitReq, opts ...grpc.CallOption) (*Empty, error) { + out := new(Empty) + err := c.cc.Invoke(ctx, "/pb.userCenter/statPvpKillUnit", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *userCenterClient) StatPvpKill(ctx context.Context, in *StatPvPKillReq, opts ...grpc.CallOption) (*Empty, error) { + out := new(Empty) + err := c.cc.Invoke(ctx, "/pb.userCenter/statPvpKill", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *userCenterClient) StatPvpFirstBlood(ctx context.Context, in *StatPvPFirstBloodReq, opts ...grpc.CallOption) (*Empty, error) { + out := new(Empty) + err := c.cc.Invoke(ctx, "/pb.userCenter/statPvpFirstBlood", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *userCenterClient) StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*Empty, error) { + out := new(Empty) + err := c.cc.Invoke(ctx, "/pb.userCenter/statPvpReport", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *userCenterClient) RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error) { + out := new(RankPvpResp) + err := c.cc.Invoke(ctx, "/pb.userCenter/rankPvp", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // UserCenterServer is the server API for UserCenter service. // All implementations must embed UnimplementedUserCenterServer // for forward compatibility type UserCenterServer interface { // user RetrievePlatformUser(context.Context, *PlatformUserReq) (*PlatformUserResp, error) + // statistics + StatPvpDamage(context.Context, *StatPvPDamageReq) (*Empty, error) + StatPvpKillUnit(context.Context, *StatPvPKillUnitReq) (*Empty, error) + StatPvpKill(context.Context, *StatPvPKillReq) (*Empty, error) + StatPvpFirstBlood(context.Context, *StatPvPFirstBloodReq) (*Empty, error) + StatPvpReport(context.Context, *StatPvPReportReq) (*Empty, error) + // rank + RankPvp(context.Context, *RankPvpReq) (*RankPvpResp, error) mustEmbedUnimplementedUserCenterServer() } @@ -59,6 +129,24 @@ type UnimplementedUserCenterServer struct { func (UnimplementedUserCenterServer) RetrievePlatformUser(context.Context, *PlatformUserReq) (*PlatformUserResp, error) { return nil, status.Errorf(codes.Unimplemented, "method RetrievePlatformUser not implemented") } +func (UnimplementedUserCenterServer) StatPvpDamage(context.Context, *StatPvPDamageReq) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method StatPvpDamage not implemented") +} +func (UnimplementedUserCenterServer) StatPvpKillUnit(context.Context, *StatPvPKillUnitReq) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method StatPvpKillUnit not implemented") +} +func (UnimplementedUserCenterServer) StatPvpKill(context.Context, *StatPvPKillReq) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method StatPvpKill not implemented") +} +func (UnimplementedUserCenterServer) StatPvpFirstBlood(context.Context, *StatPvPFirstBloodReq) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method StatPvpFirstBlood not implemented") +} +func (UnimplementedUserCenterServer) StatPvpReport(context.Context, *StatPvPReportReq) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method StatPvpReport not implemented") +} +func (UnimplementedUserCenterServer) RankPvp(context.Context, *RankPvpReq) (*RankPvpResp, error) { + return nil, status.Errorf(codes.Unimplemented, "method RankPvp not implemented") +} func (UnimplementedUserCenterServer) mustEmbedUnimplementedUserCenterServer() {} // UnsafeUserCenterServer may be embedded to opt out of forward compatibility for this service. @@ -90,6 +178,114 @@ func _UserCenter_RetrievePlatformUser_Handler(srv interface{}, ctx context.Conte return interceptor(ctx, in, info, handler) } +func _UserCenter_StatPvpDamage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatPvPDamageReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserCenterServer).StatPvpDamage(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pb.userCenter/statPvpDamage", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserCenterServer).StatPvpDamage(ctx, req.(*StatPvPDamageReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _UserCenter_StatPvpKillUnit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatPvPKillUnitReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserCenterServer).StatPvpKillUnit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pb.userCenter/statPvpKillUnit", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserCenterServer).StatPvpKillUnit(ctx, req.(*StatPvPKillUnitReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _UserCenter_StatPvpKill_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatPvPKillReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserCenterServer).StatPvpKill(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pb.userCenter/statPvpKill", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserCenterServer).StatPvpKill(ctx, req.(*StatPvPKillReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _UserCenter_StatPvpFirstBlood_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatPvPFirstBloodReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserCenterServer).StatPvpFirstBlood(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pb.userCenter/statPvpFirstBlood", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserCenterServer).StatPvpFirstBlood(ctx, req.(*StatPvPFirstBloodReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _UserCenter_StatPvpReport_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatPvPReportReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserCenterServer).StatPvpReport(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pb.userCenter/statPvpReport", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserCenterServer).StatPvpReport(ctx, req.(*StatPvPReportReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _UserCenter_RankPvp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RankPvpReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserCenterServer).RankPvp(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pb.userCenter/rankPvp", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserCenterServer).RankPvp(ctx, req.(*RankPvpReq)) + } + return interceptor(ctx, in, info, handler) +} + // UserCenter_ServiceDesc is the grpc.ServiceDesc for UserCenter service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -101,7 +297,31 @@ var UserCenter_ServiceDesc = grpc.ServiceDesc{ MethodName: "retrievePlatformUser", Handler: _UserCenter_RetrievePlatformUser_Handler, }, + { + MethodName: "statPvpDamage", + Handler: _UserCenter_StatPvpDamage_Handler, + }, + { + MethodName: "statPvpKillUnit", + Handler: _UserCenter_StatPvpKillUnit_Handler, + }, + { + MethodName: "statPvpKill", + Handler: _UserCenter_StatPvpKill_Handler, + }, + { + MethodName: "statPvpFirstBlood", + Handler: _UserCenter_StatPvpFirstBlood_Handler, + }, + { + MethodName: "statPvpReport", + Handler: _UserCenter_StatPvpReport_Handler, + }, + { + MethodName: "rankPvp", + Handler: _UserCenter_RankPvp_Handler, + }, }, Streams: []grpc.StreamDesc{}, - Metadata: "gift.proto", + Metadata: "user_center.proto", } diff --git a/app/user_center/rpc/user_center.go b/app/user_center/rpc/user_center.go index 15a2586..64c95e2 100644 --- a/app/user_center/rpc/user_center.go +++ b/app/user_center/rpc/user_center.go @@ -5,6 +5,7 @@ import ( "fmt" "live-service/app/user_center/rpc/internal/config" "live-service/app/user_center/rpc/internal/logic/platform_user" + "live-service/app/user_center/rpc/internal/logic/rank" "live-service/app/user_center/rpc/internal/server" "live-service/app/user_center/rpc/internal/svc" "live-service/app/user_center/rpc/pb" @@ -29,6 +30,8 @@ func main() { platformUserRetriever := platform_user.NewUserRetriever(ctx) platformUserRetriever.Scheduler() + rank.InitRankJob(ctx) + s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { pb.RegisterUserCenterServer(grpcServer, svr) diff --git a/app/user_center/rpc/usercenter/user_center.go b/app/user_center/rpc/usercenter/user_center.go index bd794b8..d7aeccd 100644 --- a/app/user_center/rpc/usercenter/user_center.go +++ b/app/user_center/rpc/usercenter/user_center.go @@ -1,5 +1,5 @@ // Code generated by goctl. DO NOT EDIT! -// Source: gift.proto +// Source: user_center.proto package usercenter @@ -13,13 +13,30 @@ import ( ) type ( - PlatformUserReq = pb.PlatformUserReq - PlatformUserResp = pb.PlatformUserResp - User = pb.User + Empty = pb.Empty + PlatformUserReq = pb.PlatformUserReq + PlatformUserResp = pb.PlatformUserResp + RankPvpReq = pb.RankPvpReq + RankPvpResp = pb.RankPvpResp + RankPvpResp_Item = pb.RankPvpResp_Item + StatPvPDamageReq = pb.StatPvPDamageReq + StatPvPFirstBloodReq = pb.StatPvPFirstBloodReq + StatPvPKillReq = pb.StatPvPKillReq + StatPvPKillUnitReq = pb.StatPvPKillUnitReq + StatPvPReportReq = pb.StatPvPReportReq + User = pb.User UserCenter interface { // user RetrievePlatformUser(ctx context.Context, in *PlatformUserReq, opts ...grpc.CallOption) (*PlatformUserResp, error) + // statistics + StatPvpDamage(ctx context.Context, in *StatPvPDamageReq, opts ...grpc.CallOption) (*Empty, error) + StatPvpKillUnit(ctx context.Context, in *StatPvPKillUnitReq, opts ...grpc.CallOption) (*Empty, error) + StatPvpKill(ctx context.Context, in *StatPvPKillReq, opts ...grpc.CallOption) (*Empty, error) + StatPvpFirstBlood(ctx context.Context, in *StatPvPFirstBloodReq, opts ...grpc.CallOption) (*Empty, error) + StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*Empty, error) + // rank + RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error) } defaultUserCenter struct { @@ -38,3 +55,35 @@ func (m *defaultUserCenter) RetrievePlatformUser(ctx context.Context, in *Platfo client := pb.NewUserCenterClient(m.cli.Conn()) return client.RetrievePlatformUser(ctx, in, opts...) } + +// statistics +func (m *defaultUserCenter) StatPvpDamage(ctx context.Context, in *StatPvPDamageReq, opts ...grpc.CallOption) (*Empty, error) { + client := pb.NewUserCenterClient(m.cli.Conn()) + return client.StatPvpDamage(ctx, in, opts...) +} + +func (m *defaultUserCenter) StatPvpKillUnit(ctx context.Context, in *StatPvPKillUnitReq, opts ...grpc.CallOption) (*Empty, error) { + client := pb.NewUserCenterClient(m.cli.Conn()) + return client.StatPvpKillUnit(ctx, in, opts...) +} + +func (m *defaultUserCenter) StatPvpKill(ctx context.Context, in *StatPvPKillReq, opts ...grpc.CallOption) (*Empty, error) { + client := pb.NewUserCenterClient(m.cli.Conn()) + return client.StatPvpKill(ctx, in, opts...) +} + +func (m *defaultUserCenter) StatPvpFirstBlood(ctx context.Context, in *StatPvPFirstBloodReq, opts ...grpc.CallOption) (*Empty, error) { + client := pb.NewUserCenterClient(m.cli.Conn()) + return client.StatPvpFirstBlood(ctx, in, opts...) +} + +func (m *defaultUserCenter) StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*Empty, error) { + client := pb.NewUserCenterClient(m.cli.Conn()) + return client.StatPvpReport(ctx, in, opts...) +} + +// rank +func (m *defaultUserCenter) RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error) { + client := pb.NewUserCenterClient(m.cli.Conn()) + return client.RankPvp(ctx, in, opts...) +} diff --git a/go.mod b/go.mod index 888e68a..35a3c34 100644 --- a/go.mod +++ b/go.mod @@ -48,6 +48,7 @@ require ( github.com/jinzhu/now v1.1.5 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.15.1 // indirect + github.com/longzhiri/gozset v0.0.0-20210113140059-91f2d281daf1 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/go.sum b/go.sum index 1124443..7bda044 100644 --- a/go.sum +++ b/go.sum @@ -312,6 +312,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/longzhiri/gozset v0.0.0-20210113140059-91f2d281daf1 h1:fCVAFg3S0Q/jm7xiEsuIyz01R5tnlQrNUnIwG7Jo2XA= +github.com/longzhiri/gozset v0.0.0-20210113140059-91f2d281daf1/go.mod h1:BlQbuXS7HqF9F+ZfnUG+GXrKndMZXa0xspzG/wY3IGk= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= @@ -403,6 +405,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sniperHW/rank v0.0.0-20210526024650-8d7b0052d89e h1:Ex3Pju8BLLoYUU3cVRRmkg9PiBor7deKJZT1IqjTzH8= +github.com/sniperHW/rank v0.0.0-20210526024650-8d7b0052d89e/go.mod h1:WdhKwu4WacRJmjPwKlRKXGrRDcH6teZqpa7QtRPirsw= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=