diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d406e6b..0e529e9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,9 +6,9 @@ stages: - unlock variables: - ProjectPath: "mongo.games.com/game" - BetaBinPath: "/home/game/" - DevelopBinPath: "/home/game/" + ProjectPath: "mongo.games.com/game" # 项目相对于GOPATH的路径 + BetaBinPath: "/home/game/" # beta环境部署路径 + DevelopBinPath: "/home/game/" # develop环境部署路径 default: tags: @@ -35,15 +35,19 @@ build-job: script: - git checkout $CI_COMMIT_REF_NAME - git pull origin $CI_COMMIT_REF_NAME + - if [ ! -z "$(git status --porcelain go.mod go.sum)" ]; then + GOMODTIDY=1; + fi # 拷贝到GOPATH - echo '拷贝到GOPATH' - - rsync -rvz --delete ./* $GOPATH/src/$ProjectPath + - rsync -rvc --no-perms --delete ./* $GOPATH/src/$ProjectPath # 进入项目目录 - cd $GOPATH/src/$ProjectPath # 编译 - echo '编译' - - go env -w GO111MODULE='on' - - go mod tidy + - if [ "$GOMODTIDY" == 1 ]; then + go mod tidy; + fi - | while IFS= read -r line || [[ -n $line ]] do diff --git a/dbproxy/svc/l_lotteryuser.go b/dbproxy/svc/l_lotteryuser.go new file mode 100644 index 0000000..a948fae --- /dev/null +++ b/dbproxy/svc/l_lotteryuser.go @@ -0,0 +1,47 @@ +package svc + +import ( + "errors" + "github.com/globalsign/mgo" + "github.com/globalsign/mgo/bson" + "mongo.games.com/game/dbproxy/mongo" +) + +var ( + LotteryUserLogDBErr = errors.New("log_lotteryuser db open failed.") +) + +type LotteryUserLog struct { + Platform string `bson:"-"` + CId int64 + SnId int32 + StartTs int64 + CostCard int64 +} + +func LotteryUserLogsCollection(plt string) *mongo.Collection { + s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, "log") + if s != nil { + c, first := s.DB().C("log_lotteryuser") + if first { + c.EnsureIndex(mgo.Index{Key: []string{"cid"}, Background: true, Sparse: true}) + c.EnsureIndex(mgo.Index{Key: []string{"snid"}, Background: true, Sparse: true}) + c.EnsureIndex(mgo.Index{Key: []string{"startts"}, Background: true, Sparse: true}) + c.EnsureIndex(mgo.Index{Key: []string{"cid", "startts", "snid"}, Background: true, Sparse: true}) + } + return c + } + return nil +} + +func UpsertLotteryUserLog(log *LotteryUserLog) error { + c := LotteryUserLogsCollection(log.Platform) + if c == nil { + return LotteryUserLogDBErr + } + _, err := c.Upsert(bson.M{"cid": log.CId, "snid": log.SnId, "startts": log.StartTs}, log) + if err != nil { + return err + } + return nil +} diff --git a/dbproxy/svc/u_lottery.go b/dbproxy/svc/u_lottery.go index baac3d0..c977e15 100644 --- a/dbproxy/svc/u_lottery.go +++ b/dbproxy/svc/u_lottery.go @@ -2,6 +2,7 @@ package svc import ( "errors" + "mongo.games.com/goserver/core/logger" "net/rpc" "github.com/globalsign/mgo" @@ -59,6 +60,16 @@ func UpsertLottery(plt string, item []*model.Lottery) (err error) { if err != nil { return } + err = UpsertLotteryUserLog(&LotteryUserLog{ + Platform: plt, + CId: v.CId, + SnId: v.SnId, + StartTs: v.StartTs, + CostCard: v.CostCard, + }) + if err != nil { + logger.Logger.Warnf("UpsertLotteryUserLog error: %v", err) + } } return } diff --git a/model/player.go b/model/player.go index 38a125a..5686106 100644 --- a/model/player.go +++ b/model/player.go @@ -131,6 +131,7 @@ const ( ActivityLog_PigBank // 购买存钱罐 ActivityLog_Shop //商城购买 ActivityLog_Exchange //商城兑换 + ActivityLog_CoinPigBank //金币存钱罐 ) type PlayerGameCtrlData struct { diff --git a/mongo/export.go b/mongo/export.go index 312e905..b464133 100644 --- a/mongo/export.go +++ b/mongo/export.go @@ -42,6 +42,27 @@ func Close() { internal.Close(_manager) } +// GetDatabase 获取数据库 +// platform: 平台id +// database: 数据库名称 +func GetDatabase(platform, database string) (*Database, error) { + if _manager == nil { + return nil, errors.New("mongo manager is nil, please call Init() first") + } + + return _manager.GetDatabase(platform, database) +} + +// GetGlobalDatabase 获取全局库 +// database: 数据库名称 +func GetGlobalDatabase(database string) (*Database, error) { + if _manager == nil { + return nil, errors.New("mongo manager is nil, please call Init() first") + } + + return _manager.GetDatabase("global", database) +} + // GetGlobalCollection 获取全局库 // database: 数据库名称 // collection: 集合名称 diff --git a/mongo/internal/mongo.go b/mongo/internal/mongo.go index 1c2282f..9d54b9c 100644 --- a/mongo/internal/mongo.go +++ b/mongo/internal/mongo.go @@ -98,6 +98,14 @@ type Manager struct { } func (m *Manager) GetCollection(key, database, collection string) (*Collection, error) { + d, err := m.GetDatabase(key, database) + if err != nil { + return nil, err + } + return d.GetCollection(collection) +} + +func (m *Manager) GetDatabase(key, database string) (*Database, error) { switch key { case "global": v, ok := m.global.Load(database) @@ -113,7 +121,7 @@ func (m *Manager) GetCollection(key, database, collection string) (*Collection, m.global.Store(database, v) } d, _ := v.(*Database) - return d.GetCollection(collection) + return d, nil default: var mp *sync.Map @@ -137,7 +145,7 @@ func (m *Manager) GetCollection(key, database, collection string) (*Collection, mp.Store(database, v) } d, _ := v.(*Database) - return d.GetCollection(collection) + return d, nil } } diff --git a/worldsrv/scenemgr.go b/worldsrv/scenemgr.go index a546d0b..7ca93a1 100644 --- a/worldsrv/scenemgr.go +++ b/worldsrv/scenemgr.go @@ -26,6 +26,7 @@ var SceneMgrSingleton = &SceneMgr{ coinSceneAutoId: common.CoinSceneStartId, hundredSceneAutoId: common.HundredSceneStartId, password: make(map[string]struct{}), + pushList: make(map[int]struct{}), } // SceneMgr 房间管理器 @@ -38,6 +39,8 @@ type SceneMgr struct { coinSceneAutoId int // 金币场房间号 hundredSceneAutoId int // 百人场房间号 password map[string]struct{} // 密码 + pushList map[int]struct{} // 已经推荐过的房间列表 + lastPushSceneId int // 最后推荐的房间id } // AllocReplayCode 获取回访码 @@ -407,10 +410,10 @@ func (m *SceneMgr) FindCustomInviteRoom(p *Player) *Scene { return false } iN, jN := ret[i].GetMaxPlayerNum()-ret[i].GetPlayerCnt(), ret[j].GetMaxPlayerNum()-ret[j].GetPlayerCnt() - if iN > jN { + if iN < jN { return true } - if iN < jN { + if iN > jN { return false } if ret[i].RecruitTimes > ret[j].RecruitTimes { @@ -422,7 +425,49 @@ func (m *SceneMgr) FindCustomInviteRoom(p *Player) *Scene { return ret[i].createTime.Unix() < ret[j].createTime.Unix() }) + // 删除没有的房间 + var list []*Scene + var pushList = map[int]struct{}{} + for k := range m.pushList { + var has bool + for _, v := range ret { + if v.sceneId == k { + has = true + break + } + } + if has { + pushList[k] = struct{}{} + } + } + m.pushList = pushList + + // 删除推荐过的房间 + for _, v := range ret { + if _, ok := m.pushList[v.sceneId]; !ok { + list = append(list, v) + } + } + + if len(list) > 0 { + m.pushList[list[0].sceneId] = struct{}{} + return list[0] + } + if len(ret) > 0 { + // 全都推荐过了,循环推荐房间 + var b bool + for _, v := range ret { + if b { + m.lastPushSceneId = v.sceneId + return v + } + if v.sceneId == m.lastPushSceneId { + b = true + } + } + // 没找到,从头开始 + m.lastPushSceneId = ret[0].sceneId return ret[0] } diff --git a/worldsrv/task_login.go b/worldsrv/task_login.go index c215258..0c52e59 100644 --- a/worldsrv/task_login.go +++ b/worldsrv/task_login.go @@ -354,12 +354,12 @@ func SCLogin(s *netlib.Session, sid int64, csLogin *login_proto.CSLogin, acc *mo ClientParam: string(model.ClinetBuf), NextDayTs: common.GetDayNextStartTs(time.Now().Unix()), IsNewUser: isFirstLogin, - SnId: acc.SnId, } if acc != nil { now := time.Now() sclogin.AccId = proto.String(acc.AccountId.Hex()) sclogin.SrvTs = proto.Int64(now.Unix()) + sclogin.SnId = acc.SnId if code == login_proto.OpResultCode_OPRC_Sucess { acc.LastLoginTime = now acc.LoginTimes++ diff --git a/worldsrv/welfmgr.go b/worldsrv/welfmgr.go index 95960ad..c14348e 100644 --- a/worldsrv/welfmgr.go +++ b/worldsrv/welfmgr.go @@ -1856,7 +1856,7 @@ func (this *WelfareMgr) PigbankTakeCoin(p *Player) { pack.Price = int64(infoData.CoinPrice) logger.Logger.Tracef("PigbankTakeCoin snid: %v pack: %v", p.SnId, pack) p.SendToClient(int(welfare.SPacketID_PACKET_SCPigbankTakeCoin), pack) - + mq.Write(model.GenerateActivityLog(p.SnId, p.Platform, model.ActivityLog_CoinPigBank, 1)) } }