Compare commits

..

No commits in common. "bcbc162549eddb934d35044af9e27522a6a18d8d" and "4d65851083ada20e2fbf3f2f2d998c4cf71835da" have entirely different histories.

14 changed files with 80 additions and 132 deletions

View File

@ -7,7 +7,6 @@ import (
"math/rand" "math/rand"
"time" "time"
"go.mongodb.org/mongo-driver/bson/primitive"
rawproto "google.golang.org/protobuf/proto" rawproto "google.golang.org/protobuf/proto"
"mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/core/netlib"
@ -642,15 +641,15 @@ func (this *Player) ReportGameEvent(param *ReportGameEventParam) *ReportGameEven
var gameTimes, gameFreeTimes int64 var gameTimes, gameFreeTimes int64
data, ok := this.GDatas[this.scene.KeyGamefreeId] data, ok := this.GDatas[this.scene.KeyGamefreeId]
if ok { if ok {
gameFreeFirstTime = data.FirstTime gameFirstTime = data.FirstTime
gameFreeTimes = data.Statics.GameTimes gameTimes = data.Statics.GameTimes
} }
// 记录玩家 首次参与该游戏时间 游戏次数(不区分场次) // 记录玩家 首次参与该游戏时间 游戏次数(不区分场次)
dataGame, ok := this.GDatas[this.scene.KeyGameId] dataGame, ok := this.GDatas[this.scene.KeyGameId]
if ok { if ok {
gameFirstTime = dataGame.FirstTime gameFreeFirstTime = dataGame.FirstTime
gameTimes = dataGame.Statics.GameTimes gameFreeTimes = dataGame.Statics.GameTimes
} }
isNew := int32(0) isNew := int32(0)
@ -669,13 +668,12 @@ func (this *Player) ReportGameEvent(param *ReportGameEventParam) *ReportGameEven
var ret ReportGameEventOnly var ret ReportGameEventOnly
ret.Param = param ret.Param = param
log := &model.PlayerGameRecEvent{ log := &model.PlayerGameRecEvent{
Id: primitive.NewObjectID().Hex(), Platform: this.Platform,
Platform: this.Platform, RecordId: this.scene.GetRecordId(),
RecordId: this.scene.GetRecordId(), SnId: this.GetSnId(),
SnId: this.GetSnId(), Channel: this.Channel,
Channel: this.Channel, ChannelId: this.ChannelId,
ChannelId: this.ChannelId, City: this.City,
//City: this.City,
OS: this.DeviceOS, OS: this.DeviceOS,
GameId: this.scene.GameId, GameId: this.scene.GameId,
ModeId: this.scene.GameMode, ModeId: this.scene.GameMode,
@ -688,12 +686,12 @@ func (this *Player) ReportGameEvent(param *ReportGameEventParam) *ReportGameEven
IsNew: isNew, IsNew: isNew,
GameFreeID: this.scene.GetGameFreeId(), GameFreeID: this.scene.GetGameFreeId(),
GamingTime: int32(param.GameTime), GamingTime: int32(param.GameTime),
FirstTime: gameFreeFirstTime.Unix(), FirstTime: gameFirstTime.Unix(),
PlayTimes: gameFreeTimes, PlayTimes: gameTimes,
FirstGameTime: gameFirstTime.Unix(), FirstGameTime: gameFreeFirstTime.Unix(),
PlayGameTimes: gameTimes, PlayGameTimes: gameFreeTimes,
LastLoginTime: this.LastLoginTime.Unix(), LastLoginTime: this.LastLoginTime.Unix(),
//DeviceId: this.DeviceId, DeviceId: this.DeviceId,
} }
if param.OnlyLog { if param.OnlyLog {
ret.Log = append(ret.Log, log) ret.Log = append(ret.Log, log)

View File

@ -245,36 +245,34 @@ func CreatePlayerLoginEvent(snid int32, channel, promoter, platform, city, os, i
// 玩家游戏记录 // 玩家游戏记录
type PlayerGameRecEvent struct { type PlayerGameRecEvent struct {
Id string //id RecordId string //游戏记录ID
RecordId string //游戏记录ID SnId int32 //用户ID
SnId int32 //用户ID Channel string //包类型
Channel string //包类型 Promoter string //推广
Platform string //平台 Platform string //平台
OS string //操作系统 City string //城市
GameId int32 //游戏id OS string //操作系统
ModeId int32 //游戏模式 TelephonePromoter int32 //电销标记
Tax int64 //税收 GameId int32 //游戏id
Amount int64 //金币变化,税后(正值为赢;负值为输) ModeId int32 //游戏模式
CreateTime int64 //创建时间 Tax int64 //税收
CreateDayTime int64 //账号创建时间0点 Amount int64 //金币变化(正值为赢;负值为输)
Out int64 //产出 CreateTime int64 //创建时间
In int64 //投入 CreateDayTime int64 //账号创建时间0点
IsNew int32 //是否是新人 ValidBet int64 //有效下注数量
GameFreeID int32 //游戏freeid ValidFlow int64 //有效流水数量
GamingTime int32 //游戏开始到玩家结算的时长 单位:秒 Out int64 //产出
In int64 //投入
GameDif int32 // 游戏分组 IsNew int32 //是否是新人
FirstGameDifTime int64 // 首次游戏分组时间 GameFreeID int32 //游戏freeid
GameDifTimes int64 // 游戏分组游戏次数 GamingTime int32 //游戏开始到玩家结算的时长 单位:秒
FirstTime int64 //首次玩该场次游戏时间
FirstTime int64 //首次玩该场次游戏时间 PlayTimes int64 //该场次游戏次数
PlayTimes int64 //该场次游戏次数 FirstGameTime int64 //首次玩游戏时间
PlayGameTimes int64 //该游戏总次数
FirstGameTime int64 //首次玩游戏时间 LastLoginTime int64 //最后登录时间
PlayGameTimes int64 //该游戏总次数 DeviceId string //设备id
ChannelId string //推广渠道id
LastLoginTime int64 //最后登录时间
ChannelId string //推广渠道id
} }
// 玩家游戏记录 // 玩家游戏记录

View File

@ -30,12 +30,12 @@ import (
func init() { func init() {
common.RegisterClockFunc(&common.ClockFunc{ common.RegisterClockFunc(&common.ClockFunc{
OnHourTimerFunc: func() { OnHourTimerFunc: func() {
ClientMgrSingleton.AccountReplace() ClientMgrSingleton.HourChange()
logger.Logger.Info(ClientMgrSingleton.GetState()) logger.Logger.Infof("client state: %+v", ClientMgrSingleton.GetState())
}, },
OnDayTimerFunc: func() { OnDayTimerFunc: func() {
ClientMgrSingleton.AccountDeletePolicy() ClientMgrSingleton.DayChange()
}, },
}) })
} }
@ -110,17 +110,13 @@ func (this *ClientMgr) UnRegisterSession(acc string) {
delete(this.sessionPool, acc) delete(this.sessionPool, acc)
} }
// AccountReplace 账号替换 func (this *ClientMgr) HourChange() {
func (this *ClientMgr) AccountReplace() {
fileModify := false fileModify := false
eventArr := this.CycleTimeEvent[time.Now().Hour()] eventArr := this.CycleTimeEvent[time.Now().Hour()]
for _, event := range eventArr { for _, event := range eventArr {
accChan[event.newAcc] = true //使用新的账号 accChan[event.newAcc] = true //使用新的账号
cfg := NewSessionConfig()
//创建新的连接 netlib.Connect(cfg) //创建新的连接
NewSession()
// 关闭旧的连接
if session, ok := this.sessionPool[event.oldAcc]; ok && session != nil { if session, ok := this.sessionPool[event.oldAcc]; ok && session != nil {
//删除旧有账号数据 //删除旧有账号数据
pack := &serverproto.RWAccountInvalid{ pack := &serverproto.RWAccountInvalid{
@ -132,7 +128,6 @@ func (this *ClientMgr) AccountReplace() {
//关闭连接 //关闭连接
session.Close() session.Close()
} }
//更新本地账号数据信息 //更新本地账号数据信息
for key, value := range accPool { for key, value := range accPool {
if value.Acc == event.oldAcc { if value.Acc == event.oldAcc {
@ -161,8 +156,7 @@ func (this *ClientMgr) AccountReplace() {
} }
} }
// AccountDeletePolicy 账号删除策略 func (this *ClientMgr) DayChange() {
func (this *ClientMgr) AccountDeletePolicy() {
invalidCount := 0 //过期账号数量 invalidCount := 0 //过期账号数量
updateLimit := len(accPool) * model.GameParamData.InvalidRobotAccRate / 100 //可更新的账号数量 updateLimit := len(accPool) * model.GameParamData.InvalidRobotAccRate / 100 //可更新的账号数量
invalidAccs := []InvalidAcc{} invalidAccs := []InvalidAcc{}
@ -207,10 +201,6 @@ type ClientState struct {
Event map[int]int Event map[int]int
} }
func (c *ClientState) String() string {
return fmt.Sprintf("ClientMgrState 连接总数:%v, 每小时账号替换数量:%v", c.SessionNum, c.Event)
}
func (this *ClientMgr) GetState() *ClientState { func (this *ClientMgr) GetState() *ClientState {
ret := &ClientState{ ret := &ClientState{
SessionNum: len(this.sessionPool), SessionNum: len(this.sessionPool),

View File

@ -18,19 +18,12 @@ var (
WaitConnectSessions []*netlib.SessionConfig WaitConnectSessions []*netlib.SessionConfig
) )
// NewSession 新建session func NewSessionConfig() *netlib.SessionConfig {
// id 连接id, 默认自动分配 BenchMarkModule.idx++
func NewSession(id ...int) {
cfg := Config.Connects cfg := Config.Connects
if len(id) > 0 && id[0] > 0 { cfg.Id = BenchMarkModule.idx
cfg.Id = id[0]
} else {
BenchMarkModule.idx++
cfg.Id = BenchMarkModule.idx
}
cfg.Init() cfg.Init()
logger.Logger.Info("waite connect session id=", cfg.Id) return &cfg
WaitConnectSessions = append(WaitConnectSessions, &cfg)
} }
type BenchMark struct { type BenchMark struct {
@ -44,7 +37,9 @@ func (m *BenchMark) ModuleName() string {
func (m *BenchMark) Init() { func (m *BenchMark) Init() {
m.idx = RobotSessionStartId m.idx = RobotSessionStartId
for i := 0; i < Config.Count; i++ { for i := 0; i < Config.Count; i++ {
NewSession() cfg := NewSessionConfig()
logger.Logger.Info("waite connect session id=", cfg.Id)
WaitConnectSessions = append(WaitConnectSessions, cfg)
} }
} }

View File

@ -62,7 +62,10 @@ func (g *GateSessionHandler) OnSessionClosed(s *netlib.Session) {
StopSessionPingTimer(s) StopSessionPingTimer(s)
if reconnect { if reconnect {
logger.Logger.Infof("账号重连 sessionID:%v account:%v", s.Id, accIdParam) logger.Logger.Infof("账号重连 sessionID:%v account:%v", s.Id, accIdParam)
NewSession(s.GetSessionConfig().Id) cfg := Config.Connects
cfg.Id = s.GetSessionConfig().Id
cfg.Init()
WaitConnectSessions = append(WaitConnectSessions, &cfg)
} }
} }

View File

@ -16,9 +16,9 @@ type AccountData struct {
} }
var ( var (
// 待登录的账号,将要建立连接 // 待使用的账号,将要建立连接
accChan = make(map[string]bool) accChan = make(map[string]bool)
// 账号池,当前正在使用的机器人账号 // 账号池,当前正在使用的机器人
accPool []*AccountData accPool []*AccountData
) )
var accountFileName = "robotaccount.json" var accountFileName = "robotaccount.json"

View File

@ -1,13 +1,12 @@
package base package base
import ( import (
"fmt"
"math/rand" "math/rand"
"mongo.games.com/game/common"
"mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/core/netlib"
"mongo.games.com/game/common"
"mongo.games.com/game/proto" "mongo.games.com/game/proto"
hall_proto "mongo.games.com/game/protocol/gamehall" hall_proto "mongo.games.com/game/protocol/gamehall"
player_proto "mongo.games.com/game/protocol/player" player_proto "mongo.games.com/game/protocol/player"
@ -21,9 +20,6 @@ func init() {
OnMiniTimerFunc: func() { OnMiniTimerFunc: func() {
PlayerMgrSingleton.OnMiniTimer() PlayerMgrSingleton.OnMiniTimer()
}, },
OnHourTimerFunc: func() {
logger.Logger.Info(PlayerMgrSingleton.GetState())
},
}) })
} }
@ -177,22 +173,3 @@ func (pm *PlayerMgr) OnSecondTimer() {
func (pm *PlayerMgr) OnMiniTimer() { func (pm *PlayerMgr) OnMiniTimer() {
pm.ProcessCheckRobotNum() pm.ProcessCheckRobotNum()
} }
type PlayerMgrState struct {
PlayerNum int
NormalSessionNum int
MatchSessionNum int
}
func (p *PlayerMgrState) String() string {
return fmt.Sprintf("PlayerMgrState 玩家总数:%v, 普通场连接数:%v, 比赛场连接数:%v", p.PlayerNum, p.NormalSessionNum, p.MatchSessionNum)
}
func (pm *PlayerMgr) GetState() *PlayerMgrState {
ret := &PlayerMgrState{
PlayerNum: len(pm.playersMapSnId),
NormalSessionNum: len(pm.playersSession),
MatchSessionNum: len(pm.playersMatchSession),
}
return ret
}

View File

@ -1,7 +1,6 @@
package base package base
import ( import (
"fmt"
"time" "time"
"mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/logger"
@ -17,7 +16,11 @@ func init() {
common.RegisterClockFunc(&common.ClockFunc{ common.RegisterClockFunc(&common.ClockFunc{
OnHourTimerFunc: func() { OnHourTimerFunc: func() {
logger.Logger.Info(SceneMgrSingleton.GetState()) sceneState := map[int32]int{}
for _, v := range SceneMgrSingleton.Scenes {
sceneState[v.GetGameId()]++
}
logger.Logger.Infof("sceneState: %v", sceneState)
}, },
}) })
} }
@ -68,22 +71,6 @@ func (sm *SceneMgr) IsFreeMode(sceneId int32) bool {
return false return false
} }
type SceneMgrState struct {
Num map[int32]int
}
func (s *SceneMgrState) String() string {
return fmt.Sprintf("SceneMgrState 每个游戏的房间数量 [游戏id:房间数量]: %v", s.Num)
}
func (sm *SceneMgr) GetState() *SceneMgrState {
m := make(map[int32]int)
for _, v := range sm.Scenes {
m[v.GetGameId()]++
}
return &SceneMgrState{Num: m}
}
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////
// / Module Implement [beg] // / Module Implement [beg]
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////

View File

@ -99,7 +99,6 @@ func SCPlayerFlag(s *netlib.Session, packetid int, data interface{}) error {
return nil return nil
} }
// 更新房间里玩家的状态
if scene, ok := GetScene(s).(IScene); ok && scene != nil { if scene, ok := GetScene(s).(IScene); ok && scene != nil {
p := scene.GetPlayerBySnid(msg.GetPlayerId()) p := scene.GetPlayerBySnid(msg.GetPlayerId())
if p != nil { if p != nil {

View File

@ -52,7 +52,6 @@ func SCDestroyRoom(s *netlib.Session, packid int, pack interface{}) error {
if msg.GetOpRetCode() == gamehallproto.OpResultCode_Game_OPRC_Sucess_Game { if msg.GetOpRetCode() == gamehallproto.OpResultCode_Game_OPRC_Sucess_Game {
cleanRoomState(s) cleanRoomState(s)
SceneMgrSingleton.DelScene(msg.GetRoomId())
return nil return nil
} }

View File

@ -341,7 +341,10 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool {
//离场金币 //离场金币
leaverng := this.dbGameFree.GetRobotLimitCoin() leaverng := this.dbGameFree.GetRobotLimitCoin()
if len(leaverng) >= 2 { if len(leaverng) >= 2 {
leaveCoin = int64(common.RandInt(int(leaverng[0]), int(leaverng[1]))) rangeValue := leaverng[1] - leaverng[0]
if rangeValue > 0 {
leaveCoin = leaverng[0] + rand.Int63n(rangeValue)
}
} }
} }

View File

@ -34,14 +34,13 @@ type SceneMgr struct {
common.BaseClockSinker // 驱动时间事件 common.BaseClockSinker // 驱动时间事件
scenes map[int]*Scene // 房间id: Scene scenes map[int]*Scene // 房间id: Scene
privateAutoId int // 私人房房间号 privateAutoId int // 私人房房间号
matchAutoId int // 比赛场房间号 matchAutoId int // 比赛场房间号
coinSceneAutoId int // 金币场房间号 coinSceneAutoId int // 金币场房间号
hundredSceneAutoId int // 百人场房间号 hundredSceneAutoId int // 百人场房间号
password map[string]struct{} // 密码
password map[string]struct{} // 密码 pushList map[int]struct{} // 已经推荐过的房间列表
pushList map[int]struct{} // 已经推荐过的房间列表 lastPushSceneId int // 最后推荐的房间id
lastPushSceneId int // 最后推荐的房间id
} }
// AllocReplayCode 获取回访码 // AllocReplayCode 获取回访码