From d1afed32c293354de48258e47c513077870f3e40 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Tue, 12 Nov 2024 10:51:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gamerule/tienlen/poker.go | 2 +- worldsrv/action_logout.go | 4 +- worldsrv/action_player.go | 76 +-- worldsrv/dbsaver.go | 2 +- worldsrv/etcd.go | 2 +- worldsrv/internal/playerlistener.go | 180 +++--- worldsrv/lotterymgr.go | 1 + worldsrv/player.go | 854 +++------------------------- worldsrv/playercache.go | 50 -- worldsrv/playermgr.go | 235 +++++--- worldsrv/promotermgr.go | 8 + worldsrv/trascate_webapi.go | 6 +- 12 files changed, 364 insertions(+), 1056 deletions(-) diff --git a/gamerule/tienlen/poker.go b/gamerule/tienlen/poker.go index 2c11101..48d0c3b 100644 --- a/gamerule/tienlen/poker.go +++ b/gamerule/tienlen/poker.go @@ -6,7 +6,7 @@ import ( "time" ) -//牌序- 2, A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3 +//牌序- 2, A, K, Q, J,10, 9, 8, 7, 6, 5, 4, 3 //红桃- 51,50,49,48,47,46,45,44,43,42,41,40,39 //方片- 38,37,36,35,34,33,32,31,30,29,28,27,26 //梅花- 25,24,23,22,21,20,19,18,17,16,15,14,13 diff --git a/worldsrv/action_logout.go b/worldsrv/action_logout.go index a41d9ef..829cfc2 100644 --- a/worldsrv/action_logout.go +++ b/worldsrv/action_logout.go @@ -18,13 +18,11 @@ func SessionLogout(sid int64, drop bool) bool { ls.state = LoginStateLogout p := PlayerMgrSington.GetOnlinePlayer(sid) if p != nil { - p.ThirdGameLogout() if drop { p.DropLine() - internal.FirePlayerDropLine(p) + internal.FirePlayerDropLine[*Player, *Scene](p) } else { p.Logout() - internal.FirePlayerLogouted(p) } } else { logger.Logger.Trace("SessionLogout p == nil") diff --git a/worldsrv/action_player.go b/worldsrv/action_player.go index 6a3debe..4da9ab1 100644 --- a/worldsrv/action_player.go +++ b/worldsrv/action_player.go @@ -29,6 +29,7 @@ import ( player_proto "mongo.games.com/game/protocol/player" webapi_proto "mongo.games.com/game/protocol/webapi" "mongo.games.com/game/webapi" + "mongo.games.com/game/worldsrv/internal" ) var reTelRule, _ = regexp.Compile(`^(1[3|4|5|6|7|8|9][0-9]\d{4,8})$`) @@ -2004,7 +2005,7 @@ func CSPlayerData(s *netlib.Session, packetid int, data interface{}, sid int64) if player.IsOnLine() { if player.sid != 0 && player.sid != sid { //Kick the exist player disconnect - player.Kickout(common.KickReason_OtherLogin) + player.Kick(common.KickReason_OtherLogin) } } @@ -2022,7 +2023,7 @@ func CSPlayerData(s *netlib.Session, packetid int, data interface{}, sid int64) proto.SetDefaults(scPlayerData) player.SendRawToClientIncOffLine(sid, s, int(player_proto.PlayerPacketID_PACKET_SC_PLAYERDATA), scPlayerData) //Kick the exist player disconnect - player.Kickout(common.KickReason_Freeze) + player.Kick(common.KickReason_Freeze) return nil } @@ -2036,7 +2037,7 @@ func CSPlayerData(s *netlib.Session, packetid int, data interface{}, sid int64) proto.SetDefaults(scPlayerData) player.SendRawToClientIncOffLine(sid, s, int(player_proto.PlayerPacketID_PACKET_SC_PLAYERDATA), scPlayerData) //Kick the exist player disconnect - player.Kickout(common.KickReason_Freeze) + player.Kick(common.KickReason_Freeze) return nil } @@ -2056,7 +2057,7 @@ func CSPlayerData(s *netlib.Session, packetid int, data interface{}, sid int64) proto.SetDefaults(scPlayerData) player.SendRawToClientIncOffLine(sid, s, int(player_proto.PlayerPacketID_PACKET_SC_PLAYERDATA), scPlayerData) //Kick the exist player disconnect - player.Kickout(common.KickReason_Freeze) + player.Kick(common.KickReason_Freeze) return nil } @@ -2068,40 +2069,18 @@ func CSPlayerData(s *netlib.Session, packetid int, data interface{}, sid int64) proto.SetDefaults(scPlayerData) player.SendRawToClientIncOffLine(sid, s, int(player_proto.PlayerPacketID_PACKET_SC_PLAYERDATA), scPlayerData) //Kick the exist player disconnect - player.Kickout(common.KickReason_Freeze) + player.Kick(common.KickReason_Freeze) return nil } } if !player.IsRob { if _, ok := BlackListMgrSington.CheckLogin(player.PlayerData); !ok { - //var msg string - //if bi != nil { - // msg = i18n.Tr("languages", "BlackListLimit2Args", player.SnId, bi.Id, player.SnId, bi.Id, player.SnId, bi.Id, player.SnId, bi.Id) - //} else { - // msg = i18n.Tr("languages", "BlackListLimit1Args", player.SnId, player.SnId, player.SnId, player.SnId) - //} - //common.SendSrvMsg(player, common.SRVMSG_CODE_DEFAULT, msg) - //scPlayerData := &player_proto.SCPlayerData{ - // OpRetCode: player_proto.OpResultCode_OPRC_InBlackList, - //} - //proto.SetDefaults(scPlayerData) - //player.SendToClient(int(player_proto.PlayerPacketID_PACKET_SC_PLAYERDATA), scPlayerData) - //Kick the exist player disconnect - player.Kickout(common.KickReason_Freeze) + player.Kick(common.KickReason_Freeze) return nil } } - // 给玩家发送三方余额状态 - //statePack := &gamehall_proto.SCThridGameBalanceUpdateState{} - //if player.thridBalanceReqIsSucces { - // statePack.OpRetCode = gamehall_proto.OpResultCode_Game_OPRC_Sucess_Game - //} else { - // statePack.OpRetCode = gamehall_proto.OpResultCode_Game_OPRC_Error_Game - //} - //player.SendRawToClientIncOffLine(sid, s, int(gamehall_proto.GameHallPacketID_PACKET_SC_THRIDGAMEBALANCEUPDATESTATE), statePack) - //抽奖次数兼容老玩家 if !player.IsRob && !player.InitLotteryStatus && WelfareMgrSington.GetPhoneLotteryStatus(player.Platform) == model.WelfareOpen { player.addLotteryCount(20) @@ -2114,6 +2093,7 @@ func CSPlayerData(s *netlib.Session, packetid int, data interface{}, sid int64) playerFunc(player, cspl) PlayerMgrSington.ReholdPlayer(player, sid, s) player.OnRehold() + internal.FirePlayerRehold[*Player, *Scene](player) player.SendPlayerInfo() return nil } @@ -2147,52 +2127,20 @@ func CSPlayerData(s *netlib.Session, packetid int, data interface{}, sid int64) return } + // 检查禁止登录 if !player.IsRob { if _, ok := BlackListMgrSington.CheckLogin(pd.PlayerData); !ok { //黑名单用户也需要调用一下onlogin,否则会导致数据无法刷新 player.OnLogined() - player.Kickout(common.KickReason_Freeze) + internal.FirePlayerLogined[*Player, *Scene](player) + player.Kick(common.KickReason_Freeze) return } } - var temp []byte - var ee error - di := cspl.GetDeviceInfo() - if di != "" { - var e common.Encryptor - e.Init(common.GetAppId(), player.PackageID, int32(cspl.GetTimeStamp())) - temp, ee = base64.StdEncoding.DecodeString(di) - if ee == nil { - e.Encrypt(temp, len(temp)) - } - } - - if isnew { //新用户赠送金币 - //首次创建账号事件 - //isBind := 0 - //if pd.Tel != "" { - // isBind = 1 - //} - //LogChannelSingleton.WriteMQData(model.GeneratePlayerEvent(model.WEBEVENT_LOGIN, pd.Platform, pd.PackageID, pd.SnId, pd.Channel, pd.BeUnderAgentCode, pd.PromoterTree, 1, 1, isBind, common.GetAppId())) - - //newbieCoin := player.GetRegisterPrize() - //if newbieCoin > 0 { - // player.AddCoin(int64(newbieCoin), common.GainWay_NewPlayer, "system", "") - // //增加泥码 - // player.AddDirtyCoin(0, int64(newbieCoin)) - // player.ReportSystemGiveEvent(newbieCoin, common.GainWay_NewPlayer, true) - // player.AddPayCoinLog(int64(newbieCoin), model.PayCoinLogType_Coin, "NewPlayer") - // LogChannelSingleton.WriteMQData(model.GenerateSystemFreeGive(pd.SnId, pd.Name, pd.Platform, model.SystemFreeGive_GiveType_NewPlayer, model.SystemFreeGive_CoinType_Coin, int64(newbieCoin))) - //} - //if player.InviterId > 0 { - // //actRandCoinMgr.OnPlayerInvite(player.Platform, player.InviterId) - //} - } - //测试代码 - playerFunc(player, cspl) player.OnLogined() + internal.FirePlayerLogined[*Player, *Scene](player) player.SendPlayerInfo() }, true) diff --git a/worldsrv/dbsaver.go b/worldsrv/dbsaver.go index 39db2ea..d79f3ee 100644 --- a/worldsrv/dbsaver.go +++ b/worldsrv/dbsaver.go @@ -9,7 +9,7 @@ import ( ) var DbSaveInst = &DbSaver{ - GroupNumber: 5, + GroupNumber: 600, } type DbSaver struct { diff --git a/worldsrv/etcd.go b/worldsrv/etcd.go index 12c81b6..17767f4 100644 --- a/worldsrv/etcd.go +++ b/worldsrv/etcd.go @@ -420,7 +420,7 @@ func handlerEvent(ctx context.Context, completeKey string, isInit bool, event *c } for _, p := range targetPlayer { if p.sid != 0 { - p.Kickout(int32(loginproto.SSDisconnectTypeCode_SSDTC_BlackList)) + p.Kick(int32(loginproto.SSDisconnectTypeCode_SSDTC_BlackList)) } else { LoginStateMgrSington.LogoutByAccount(p.AccountId) } diff --git a/worldsrv/internal/playerlistener.go b/worldsrv/internal/playerlistener.go index 12b128d..b7d71af 100644 --- a/worldsrv/internal/playerlistener.go +++ b/worldsrv/internal/playerlistener.go @@ -1,12 +1,10 @@ package internal -type Player any +import "mongo.games.com/game/common" -type Scene any +var _playerListeners []interface{} -var _playerListeners []PlayerListener - -func RegisterPlayerListener(l PlayerListener) { +func RegisterPlayerListener[Player, Scene any](l PlayerListener[Player, Scene]) { for _, ll := range _playerListeners { if ll == l { return @@ -15,144 +13,192 @@ func RegisterPlayerListener(l PlayerListener) { _playerListeners = append(_playerListeners, l) } -type PlayerListener interface { +type PlayerListener[Player, Scene any] interface { + common.ClockSinker // 登出相关 OnPlayerLogined(p Player) // 玩家登录时触发 OnPlayerLogouted(p Player) // 玩家登出时触发 OnPlayerDropLine(p Player) // 玩家掉线时触发 OnPlayerRehold(p Player) // 玩家重新连接时触发 - - // 时间相关 - OnPlayerSecTimer(p Player) // 每秒触发 - OnPlayerMiniTimer(p Player) // 每分钟触发 - OnPlayerHourTimer(p Player) // 每小时触发 - OnPlayerDayTimer(p Player, login, continuous bool) // 每天触发,login表示是否登录,continuous表示是否连续登录 - OnPlayerWeekTimer(p Player) // 每周触发 - OnPlayerMonthTimer(p Player) // 每月触发 - // 业务相关 - OnPlayerEnterScene(p Player, s Scene) // 玩家进入场景时触发 - OnPlayerLeaveScene(p Player, s Scene) // 玩家离开场景时触发 - OnPlayerReturnScene(p Player, s Scene) // 玩家返回房间时触发 + OnPlayerEnterSceneBefore(p Player, s Scene) // 玩家进入场景前触发 + OnPlayerEnterSceneAfter(p Player, s Scene) // 玩家进入场景后触发 + OnPlayerLeaveSceneBefore(p Player, s Scene) // 玩家离开场景前触发 + OnPlayerLeaveSceneAfter(p Player, s Scene) // 玩家离开场景后触发 + OnPlayerReturnSceneBefore(p Player, s Scene) // 玩家返回房间前触发 + OnPlayerReturnSceneAfter(p Player, s Scene) // 玩家返回房间后触发 } -func FirePlayerLogined(p Player) { +func FirePlayerLogined[Player, Scene any](p Player) { for _, l := range _playerListeners { if l != nil { - l.OnPlayerLogined(p) + l.(PlayerListener[Player, Scene]).OnPlayerLogined(p) } } } -func FirePlayerLogouted(p Player) { +func FirePlayerLogouted[Player, Scene any](p Player) { for _, l := range _playerListeners { if l != nil { - l.OnPlayerLogouted(p) + l.(PlayerListener[Player, Scene]).OnPlayerLogouted(p) } } } -func FirePlayerDropLine(p Player) { +func FirePlayerDropLine[Player, Scene any](p Player) { for _, l := range _playerListeners { if l != nil { - l.OnPlayerDropLine(p) + l.(PlayerListener[Player, Scene]).OnPlayerDropLine(p) } } } -func FirePlayerRehold(p Player) { +func FirePlayerRehold[Player, Scene any](p Player) { for _, l := range _playerListeners { if l != nil { - l.OnPlayerRehold(p) + l.(PlayerListener[Player, Scene]).OnPlayerRehold(p) } } } -func FirePlayerSecTimer(p Player) { +func FirePlayerEnterSceneBefore[Player, Scene any](p Player, s Scene) { for _, l := range _playerListeners { if l != nil { - l.OnPlayerSecTimer(p) + l.(PlayerListener[Player, Scene]).OnPlayerEnterSceneBefore(p, s) } } } -func FirePlayerMiniTimer(p Player) { +func FirePlayerEnterSceneAfter[Player, Scene any](p Player, s Scene) { for _, l := range _playerListeners { if l != nil { - l.OnPlayerMiniTimer(p) + l.(PlayerListener[Player, Scene]).OnPlayerEnterSceneAfter(p, s) } } } -func FirePlayerHourTimer(p Player) { +func FirePlayerLeaveSceneBefore[Player, Scene any](p Player, s Scene) { for _, l := range _playerListeners { if l != nil { - l.OnPlayerHourTimer(p) + l.(PlayerListener[Player, Scene]).OnPlayerLeaveSceneBefore(p, s) } } } -func FirePlayerDayTimer(p Player, login, continuous bool) { +func FirePlayerLeaveSceneAfter[Player, Scene any](p Player, s Scene) { for _, l := range _playerListeners { if l != nil { - l.OnPlayerDayTimer(p, login, continuous) + l.(PlayerListener[Player, Scene]).OnPlayerLeaveSceneAfter(p, s) } } } -func FirePlayerWeekTimer(p Player) { +func FirePlayerReturnSceneBefore[Player, Scene any](p Player, s Scene) { for _, l := range _playerListeners { if l != nil { - l.OnPlayerWeekTimer(p) + l.(PlayerListener[Player, Scene]).OnPlayerReturnSceneBefore(p, s) } } } -func FirePlayerMonthTimer(p Player) { +func FirePlayerReturnSceneAfter[Player, Scene any](p Player, s Scene) { for _, l := range _playerListeners { if l != nil { - l.OnPlayerMonthTimer(p) + l.(PlayerListener[Player, Scene]).OnPlayerReturnSceneAfter(p, s) } } } -func FirePlayerEnterScene(p Player, s Scene) { - for _, l := range _playerListeners { - if l != nil { - l.OnPlayerEnterScene(p, s) - } +type BasePlayerListener[Player, Scene any] struct { + common.ClockFunc +} + +func (l *BasePlayerListener[Player, Scene]) OnPlayerLogined(p Player) {} +func (l *BasePlayerListener[Player, Scene]) OnPlayerLogouted(p Player) {} +func (l *BasePlayerListener[Player, Scene]) OnPlayerDropLine(p Player) {} +func (l *BasePlayerListener[Player, Scene]) OnPlayerRehold(p Player) {} +func (l *BasePlayerListener[Player, Scene]) OnPlayerEnterSceneBefore(p Player, s Scene) {} +func (l *BasePlayerListener[Player, Scene]) OnPlayerEnterSceneAfter(p Player, s Scene) {} +func (l *BasePlayerListener[Player, Scene]) OnPlayerLeaveSceneBefore(p Player, s Scene) {} +func (l *BasePlayerListener[Player, Scene]) OnPlayerLeaveSceneAfter(p Player, s Scene) {} +func (l *BasePlayerListener[Player, Scene]) OnPlayerReturnSceneBefore(p Player, s Scene) {} +func (l *BasePlayerListener[Player, Scene]) OnPlayerReturnSceneAfter(p Player, s Scene) {} + +type PlayerListenerFunc[Player, Scene any] struct { + common.ClockFunc + OnPlayerLoginedFunc func(p Player) + OnPlayerLogoutedFunc func(p Player) + OnPlayerDropLineFunc func(p Player) + OnPlayerReholdFunc func(p Player) + OnPlayerEnterSceneBeforeFunc func(p Player, s Scene) + OnPlayerEnterSceneAfterFunc func(p Player, s Scene) + OnPlayerLeaveSceneBeforeFunc func(p Player, s Scene) + OnPlayerLeaveSceneAfterFunc func(p Player, s Scene) + OnPlayerReturnSceneBeforeFunc func(p Player, s Scene) + OnPlayerReturnSceneAfterFunc func(p Player, s Scene) +} + +func (l *PlayerListenerFunc[Player, Scene]) OnPlayerLogined(p Player) { + if l.OnPlayerLoginedFunc != nil { + l.OnPlayerLoginedFunc(p) } } -func FirePlayerLeaveScene(p Player, s Scene) { - for _, l := range _playerListeners { - if l != nil { - l.OnPlayerLeaveScene(p, s) - } +func (l *PlayerListenerFunc[Player, Scene]) OnPlayerLogouted(p Player) { + if l.OnPlayerLogoutedFunc != nil { + l.OnPlayerLogoutedFunc(p) } } -func FirePlayerReturnScene(p Player, s Scene) { - for _, l := range _playerListeners { - if l != nil { - l.OnPlayerReturnScene(p, s) - } +func (l *PlayerListenerFunc[Player, Scene]) OnPlayerDropLine(p Player) { + if l.OnPlayerDropLineFunc != nil { + l.OnPlayerDropLineFunc(p) } } -type BasePlayerListener struct { +func (l *PlayerListenerFunc[Player, Scene]) OnPlayerRehold(p Player) { + if l.OnPlayerReholdFunc != nil { + l.OnPlayerReholdFunc(p) + } } -func (l *BasePlayerListener) OnPlayerLogined(p Player) {} -func (l *BasePlayerListener) OnPlayerLogouted(p Player) {} -func (l *BasePlayerListener) OnPlayerDropLine(p Player) {} -func (l *BasePlayerListener) OnPlayerRehold(p Player) {} -func (l *BasePlayerListener) OnPlayerSecTimer(p Player) {} -func (l *BasePlayerListener) OnPlayerMiniTimer(p Player) {} -func (l *BasePlayerListener) OnPlayerHourTimer(p Player) {} -func (l *BasePlayerListener) OnPlayerDayTimer(p Player, login, continuous bool) {} -func (l *BasePlayerListener) OnPlayerWeekTimer(p Player) {} -func (l *BasePlayerListener) OnPlayerMonthTimer(p Player) {} -func (l *BasePlayerListener) OnPlayerEnterScene(p Player, s Scene) {} -func (l *BasePlayerListener) OnPlayerLeaveScene(p Player, s Scene) {} -func (l *BasePlayerListener) OnPlayerReturnScene(p Player, s Scene) {} +func (l *PlayerListenerFunc[Player, Scene]) OnPlayerEnterSceneBefore(p Player, s Scene) { + if l.OnPlayerEnterSceneBeforeFunc != nil { + l.OnPlayerEnterSceneBeforeFunc(p, s) + } +} + +func (l *PlayerListenerFunc[Player, Scene]) OnPlayerEnterSceneAfter(p Player, s Scene) { + if l.OnPlayerEnterSceneAfterFunc != nil { + l.OnPlayerEnterSceneAfterFunc(p, s) + } +} + +func (l *PlayerListenerFunc[Player, Scene]) OnPlayerLeaveSceneBefore(p Player, s Scene) { + if l.OnPlayerLeaveSceneBeforeFunc != nil { + l.OnPlayerLeaveSceneBeforeFunc(p, s) + } +} + +func (l *PlayerListenerFunc[Player, Scene]) OnPlayerLeaveSceneAfter(p Player, s Scene) { + if l.OnPlayerLeaveSceneAfterFunc != nil { + l.OnPlayerLeaveSceneAfterFunc(p, s) + } +} + +func (l *PlayerListenerFunc[Player, Scene]) OnPlayerReturnSceneBefore(p Player, s Scene) { + if l.OnPlayerReturnSceneBeforeFunc != nil { + l.OnPlayerReturnSceneBeforeFunc(p, s) + } +} + +func (l *PlayerListenerFunc[Player, Scene]) OnPlayerReturnSceneAfter(p Player, s Scene) { + if l.OnPlayerReturnSceneAfterFunc != nil { + l.OnPlayerReturnSceneAfterFunc(p, s) + } +} + +func RegisterPlayerListenerFunc[P, S any](l *PlayerListenerFunc[P, S]) { + common.RegisterClockFunc(&l.ClockFunc) + RegisterPlayerListener(l) +} diff --git a/worldsrv/lotterymgr.go b/worldsrv/lotterymgr.go index 77b7165..3833728 100644 --- a/worldsrv/lotterymgr.go +++ b/worldsrv/lotterymgr.go @@ -759,6 +759,7 @@ func (l *LotteryMgr) AddCostRoomCard(plt string, snid int32, n int64) { logger.Logger.Errorf("AddCostRoomCard snid:%v not found", snid) return } + PlayerMgrSington.AddPlayer(0, item.PlayerData, nil) f() }, false) return diff --git a/worldsrv/player.go b/worldsrv/player.go index 40f5be8..eb8db7c 100644 --- a/worldsrv/player.go +++ b/worldsrv/player.go @@ -9,7 +9,6 @@ import ( "io" "math" "math/rand" - "os" "slices" "strconv" "time" @@ -41,8 +40,9 @@ import ( // 对应到客户端的一个玩家对象. const ( - PlayerStateOnline int = iota - PlayerStateOffline + PlayerStateCache = iota // 缓存(没有登录过,只查询过玩家数据) + PlayerStateOnline // 在线 + PlayerStateOffline // 离线(登录后掉线) ) const ( @@ -61,14 +61,6 @@ const ( UpdateField_InviteScore ) -type ErrorString struct { - code string -} - -func (this *ErrorString) Error() string { - return this.code -} - type Player struct { *model.PlayerData //po 持久化对象 diffData model.PlayerDiffData //差异数据 @@ -156,6 +148,7 @@ func NewPlayer(sid int64, pd *model.PlayerData, s *netlib.Session) *Player { layered: make(map[int]bool), miniScene: make(map[int32]*Scene), TaskInviteList: make(map[int32]int), + state: PlayerStateCache, } if p.IsRob { p.RobotRandName() @@ -183,18 +176,6 @@ func (this *Player) init() bool { return true } -func (this *Player) GenCustomerToken() string { - if this.customerToken != "" { - return this.customerToken - } - - raw := fmt.Sprintf("%v%v%v%v%v", this.SnId, this.AccountId, this.sid, common.GetAppId(), time.Now().UnixNano()) - h := md5.New() - io.WriteString(h, raw) - token := hex.EncodeToString(h.Sum(nil)) - return token -} - func (this *Player) SyncBagData(itemInfo []*bag.ItemInfo) { pack := &bag.SCSyncBagData{ Infos: itemInfo, @@ -240,6 +221,7 @@ func (this *Player) SendToGame(packetid int, rawpack interface{}) bool { return this.scene.SendToGame(packetid, rawpack) } +// LoadAfter 玩家基础信息加载后加载其他数据 func (this *Player) LoadAfter() { var replays []*internal.PlayerLoadReplay task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { @@ -275,7 +257,6 @@ func (this *Player) OnLogined() { tNow := time.Now() tLastLogout := this.PlayerData.LastLogoutTime this.PlayerData.LastLoginTime = tNow - this.PlayerData.LastLogoutTime = tNow this.dirty = true if !common.InSameDay(tNow, tLastLogout) { //跨天 logger.Logger.Infof("(this *Player) OnLogined(%v) inSameDay LastLogoutTime(%v)", this.SnId, tLastLogout) @@ -338,7 +319,7 @@ func (this *Player) OnLogined() { this.SendJackPotInit() - this.GetShopInfo() + this.DealShopLog() PlayerOnlineSington.Check = true @@ -385,11 +366,6 @@ func (this *Player) OnRehold() { var gameid int if this.scene != nil && this.scene.gameSess != nil { - //if this.scene.sceneId == SceneMgrSingleton.GetDgSceneId() { - // // DG特殊处理 - // //如果是之前进入的是DG游戏,就退出DG游戏 - // this.DgGameLogout() - //} else { // 告诉游戏服务玩家重连 var gateSid int64 if this.gateSess != nil { @@ -424,7 +400,7 @@ func (this *Player) OnRehold() { this.SendJackPotInit() PlayerOnlineSington.Check = true - this.GetShopInfo() + this.DealShopLog() this.CheckShowRed() @@ -771,6 +747,7 @@ func (this *Player) DelMessage(id string, del int32) bool { } return false } + func (this *Player) MessageShowRed() { msgMap := make(map[int64]int) for _, msg := range this.msgs { @@ -794,60 +771,6 @@ func (this *Player) MessageShowRed() { } } -/* -func (this *Player) DelAllMessage() bool { - - var keys []string - args := &model.DelAllMsgArgs{} - pack := &msg_proto.SCMessageDel{} - for key, _ := range this.msgs { - if msg, exist := this.msgs[key]; exist { - if msg.State == model.MSGSTATE_REMOVEED { - break - } - msg.State = model.MSGSTATE_REMOVEED - // model.DelMessage(msg.Id, msg.Platform) - keys = append(keys, key) - pack.Ids = append(pack.Ids, msg.Id.Hex()) - args.Ids = append(args.Ids, msg.Id) - } - } - for _, key := range keys { - delete(this.msgs, key) - } - - task.New(nil, - task.CallableWrapper(func(o *basic.Object) interface{} { - return model.DelAllMessage(args) - }), - task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) { - if data == nil { - pack := &msg_proto.SCMessageDel{} - for _, id := range keys { - pack.Ids = append(pack.Ids, id) - delete(this.msgs, id) - } - proto.SetDefaults(pack) - this.SendToClient(int(msg_proto.MSGPacketID_PACKET_SC_MESSAGEDEL), pack) - for _, msg := range this.msgs { - if msg.State == model.MSGSTATE_REMOVEED { - break - } - msg.State = model.MSGSTATE_REMOVEED - } - - //删除此邮件 - - } - }), "DelMessage").StartByFixExecutor("logic_message") - - proto.SetDefaults(pack) - this.SendToClient(int(msg_proto.MSGPacketID_PACKET_SC_MESSAGEDEL), pack) - - return true - -}*/ - func (this *Player) AddMessage(msg *model.Message) { if msg == nil { return @@ -968,16 +891,6 @@ func (this *Player) verifyMessage(maxCreatTs int64) { } } -func (this *Player) EditMessage(msg *model.Message) { - if msg == nil { - return - } - - if _, exist := this.msgs[msg.Id.Hex()]; exist { - this.msgs[msg.Id.Hex()] = msg - } -} - func (this *Player) TestMail() { var newMsg *model.Message @@ -1017,9 +930,6 @@ func (this *Player) TestSubMail() { }), "TestSubSendMessage").Start() } -func (this *Player) ClubChangeCoin(gainWay int32, coin int64, remark string) { - this.AddCoin(coin, 0, gainWay, "", remark) -} func (this *Player) GetMessageAttach(id string) { if msg, exist := this.msgs[id]; exist { if msg.AttachState == model.MSGATTACHSTATE_DEFAULT && (msg.Coin > 0 || msg.Ticket > 0 || @@ -1208,20 +1118,44 @@ func (this *Player) GetMessageByGiftId(id string) *model.Message { return nil } -// 踢掉线 -func (this *Player) Kickout(reason int32) { +func (this *Player) IsOnLine() bool { + return this.state != PlayerStateOffline +} + +func (this *Player) SetOnline() { + this.state = PlayerStateOnline + this.UpdateLastLogoutTime() +} + +func (this *Player) IsOffline() bool { + return this.state == PlayerStateOffline +} + +func (this *Player) SetOffline() { + this.state = PlayerStateOffline + this.UpdateLastLogoutTime() +} + +func (this *Player) IsCacheState() bool { + return this.state == PlayerStateCache +} + +func (this *Player) UpdateLastLogoutTime() { + this.PlayerData.LastLogoutTime = time.Now() +} + +// Kick 踢掉线 +func (this *Player) Kick(reason int32) { if this.IsOnLine() { - logger.Logger.Trace("(this *Player) Kickout()", this.SnId) + logger.Logger.Trace("(this *Player) Kick()", this.SnId) scDisconnect := &loginproto.SSDisconnect{ SessionId: proto.Int64(this.sid), Type: proto.Int32(reason), } - proto.SetDefaults(scDisconnect) this.SendToClient(int(loginproto.GatePacketID_PACKET_SS_DICONNECT), scDisconnect) LoginStateMgrSington.LogoutBySid(this.sid) this.DropLine() - this.DgGameLogout() } TournamentMgr.ForceQuit(this.Platform, this.SnId) } @@ -1251,13 +1185,9 @@ func (this *Player) DropLine() { this.SendPlayerCoin() this.OnlineLogDrop() - PlayerOnlineSington.Check = true } - this.SetOffline() - this.PlayerData.LastLogoutTime = time.Now().Local() - FriendMgrSington.UpdateLogoutTime(this.Platform, this.SnId) if this.scene != nil && this.scene.gameSess != nil { pack := &serverproto.WGPlayerDropLine{ Id: proto.Int32(this.SnId), @@ -1266,111 +1196,43 @@ func (this *Player) DropLine() { proto.SetDefaults(pack) this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_PLAYERDROPLINE), pack) } + + FriendMgrSington.UpdateLogoutTime(this.Platform, this.SnId) PlayerMgrSington.DropPlayer(this) - this.sid = 0 - this.gateSess = nil - //统计在线时长日志 - //this.StatisticsOllen(this.PlayerData.LastLogoutTime) } -// 退出 +// Logout 主动登出 func (this *Player) Logout() { logger.Logger.Tracef("(this *Player) Logout() %v", this.SnId) - //退出比赛 - //this.QuitMatch(false) - // 在线奖励:累计在线时长 - //this.OnlineRewardAddUpOnlineDuration() - scLogout := &loginproto.SCLogout{ OpRetCode: loginproto.OpResultCode_OPRC_Sucess, } - proto.SetDefaults(scLogout) this.SendToClient(int(loginproto.LoginPacketID_PACKET_SC_LOGOUT), scLogout) - this.SetOffline() - this.LastLogoutTime = time.Now().Local() + FriendMgrSington.UpdateLogoutTime(this.Platform, this.SnId) - //clubManager.DropLinePlayer(this.SnId) PlayerMgrSington.DropPlayer(this) +} + +// OnLogoutFinish 玩家登出完成 +func (this *Player) OnLogoutFinish() { + logger.Logger.Tracef("(this *Player) OnLogoutFinish() %v", this.SnId) + if !this.IsRobot() { - PlayerOnlineSington.Check = true - } - this.sid = 0 - this.gateSess = nil - this.DgGameLogout() - this.OnlineLogLogout() -} - -func (this *Player) DgGameLogout() { - //if this.scene != nil { - // if this.scene.sceneId == SceneMgrSingleton.GetDgSceneId() { - // var agentName, agentKey, thirdPlf string - // if len(this.BakDgHboName) > 0 { - // if strings.Contains(this.BakDgHboName, "dg") { - // agentName, agentKey, thirdPlf = model.OnlyGetDgConfigByPlatform(this.Platform) - // } else { - // agentName, agentKey, thirdPlf = model.OnlyGetHboConfigByPlatform(this.Platform) - // } - // - // task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - // webapi.API_DgLogout(thirdPlf, common.GetAppId(), this.DgGame, this.DgPass, agentName, agentKey) - // return nil - // }), task.CompleteNotifyWrapper(func(data interface{}, t *task.Task) { - // this.scene = nil - // }), "DgGameLogout").Start() - // } - // - // } - //} -} - -func (this *Player) ThirdGameLogout() { - -} - -func (this *Player) IsOnLine() bool { - return this.state != PlayerStateOffline -} - -func (this *Player) SetOnline() { - this.state = PlayerStateOnline -} - -func (this *Player) IsOffline() bool { - return this.state == PlayerStateOffline -} - -func (this *Player) SetOffline() { - this.state = PlayerStateOffline -} - -// OnLogouted 玩家登出 -// 只能玩家管理器调用 -func (this *Player) OnLogouted() { - logger.Logger.Tracef("(this *Player) OnLogouted() %v", this.SnId) - - //在线时长日志 - //this.WriteOllenLog() - - if !this.IsRob { FriendUnreadMgrSington.SaveFriendUnreadData(this.Platform, this.SnId) - } + PlayerOnlineSington.Check = true - //登录日志 - logState := LoginStateMgrSington.GetLoginStateBySid(this.sid) - var clog *model.ClientLoginInfo - if logState != nil { - clog = logState.clog - } - //排除掉机器人 - if !this.IsRob { + //登录日志 + logState := LoginStateMgrSington.GetLoginStateBySid(this.sid) + var clog *model.ClientLoginInfo + if logState != nil { + clog = logState.clog + } mq.Write(model.NewLoginLog(this.SnId, common.LoginLogTypeLogout, this.Tel, this.Ip, this.Platform, this.Channel, this.BeUnderAgentCode, this.PackageID, this.City, clog, this.GetTotalCoin(), 0, 0, this.DeviceName, this.PackageName, this.AppVersion, this.BuildVersion, this.AppChannel, this.ChannelId, this.ClientVer)) + this.OnlineLogLogout() } - - //退出通知 - //ActMonitorMgrSington.SendActMonitorEvent(ActState_Login, this.SnId, this.Name, this.Platform, 0, 0, "", 1) } func (this *Player) MarshalData() (d []byte, e error) { @@ -1504,95 +1366,22 @@ func (this *Player) Time2Save() { return } - logger.Logger.Tracef("Time2Save Player %v", this.SnId) + isForce := false if common.Config.IsDevMode { - this.Save(true) + isForce = true // 开发模式下强制保存 } + PlayerMgrSington.SavePlayer(this, true, isForce) + if this.isDelete || (!this.IsOnLine() && !this.dirty && time.Now().Sub(this.lastSaved) > time.Minute*5 && this.scene == nil) { PlayerMgrSington.DelPlayer(this.SnId) } } -func (this *Player) Save(force bool) { - if this.isDelete { - return - } - - if this.IsRob { - return - } - - pd := model.ClonePlayerData(this.PlayerData) - this.SendPlayerCoin() - - if !this.dirty && !force { - return - } - - if pd == nil { - logger.Logger.Errorf("Player Time2Save() %v pd is nil", this.SnId) - return - } - logger.Logger.Infof("Player Time2Save() %v", this.SnId) - - this.dirty = true - // 跨天任务依赖LastLogoutTime的准确性,跨天任务是定时器common.ClockMgrSington触发的,所以这里要用定时器的触发时间 - pd.LastLogoutTime = common.ClockMgrSingleton.LastTickTime - - t := task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - if !model.SavePlayerData(pd) { - //save 失败先写到json里面 - model.BackupPlayerData(pd) - return false - } - for _, v := range internal.GetPlayerLoads() { - v.Save(pd.Platform, pd.SnId, true, force) - } - return true - }), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) { - if saved, ok := i.(bool); ok && saved { - bak := fmt.Sprintf("%v.json", pd.AccountId) - if exist, _ := common.PathExists(bak); exist { - os.Remove(bak) - } - this.dirty = false - } - }), "SavePlayerTask") - if b := t.StartByExecutor(fmt.Sprintf("Player%v", this.SnId)); b { - this.lastSaved = time.Now() - } -} - func (this *Player) GetCoin() int64 { return this.Coin } -//func (this *Player) TotalData(num int64, gainWay int32) { -// if this.IsRob { -// return -// } -// //num = int64(math.Abs(float64(num))) -// //sort := common.GetSortByGainWay(gainWay) -// //switch sort { -// //case common.GainWaySort_Act: -// // //活动金额累加 -// // this.ActivityCoin += int32(num) -// //case common.GainWaySort_Club: -// // switch gainWay { -// // case common.GainWay_ClubGiveCoin: //出账 -// // //俱乐部出账 -// // this.ClubOutCoin += num -// // case common.GainWay_ClubGetCoin: -// // //俱乐部入账 -// // this.ClubInCoin += num -// // } -// //case common.GainWaySort_Rebate: -// // //返利获取 也叫 手动洗码 -// // this.TotalRebateCoin += num -// //} -//} - // AddDiamond 添加钻石 // num 总数 // add num总数中有多少是加成获得 @@ -1758,25 +1547,6 @@ func (this *Player) AddCoinAsync(num, add int64, gainWay int32, oper, remark str return async } -//func (this *Player) AddClubCoin(num int64, gainWay int32, oper, remark string) { -// if num == 0 { -// return -// } -// this.TotalData(num, gainWay) -// this.ClubCoin += num -// -// if num != 0 { -// this.dirty = true -// this.SendDiffData() -// restCnt := this.ClubCoin -// log := model.NewCoinLogEx(this.SnId, num, restCnt, this.SafeBoxCoin, this.Ver, gainWay, 0, -// oper, remark, this.Platform, this.Channel, this.BeUnderAgentCode, 0, this.PackageID, 0) -// if log != nil { -// CoinLogChannelSington.Write(log) -// } -// } -//} - func (this *Player) AddTicket(num int64, gainWay int32, oper, remark string) { if num == 0 { return @@ -2403,217 +2173,6 @@ func (this *Player) GetPromoterKey() (string, error) { return GetPromoterKey(this.PromoterTree, this.BeUnderAgentCode, this.Channel) } -//计算流水可以兑换的值 返回 还需要多少流水 赠送扣除 强制费用 合计流水 -//func GetExchangeFlowTotal(pd *model.PlayerData, playerTotalFlow int64, givesInfo []*model.CoinGiveLog) (int64, -// int64, int64, int64) { -// //可兑换的流水 -// var flow int64 -// -// var giveLostCoin int64 //赠送扣除 -// var forceTax int64 //强制费用 -// var needTotalFlow int64 //需要的流水 -// var lockCoin int64 //多少金额无法兑换,如果兑换需要强制扣除行政费用 -// -// retIds := []string{} -// retAllIds := []string{} -// -// exchangeFlow := GetExchangeFlow(pd) -// exchangeGiveFlow := GetExchangeGiveFlow(pd) -// exchangeForceTax := GetExchangeForceTax(pd) -// -// if GetExchangeFlag(pd) > 0 { -// -// //逐笔计算兑换流水金额,从上到下 -// curTotalFlow := playerTotalFlow -// -// //按照时间排序 -// sort.Slice(givesInfo, func(i, j int) bool { return givesInfo[i].Ts > givesInfo[j].Ts }) -// -// for i := 0; i < len(givesInfo); i++ { -// info := givesInfo[i] -// if info.Ts > pd.LastExchangeTime { -// retAllIds = append(retAllIds, info.LogId.Hex()) -// //计算是否通过稽核 -// needFlow := int64(0) -// curTotalFlow += info.FLow -// //如果是系统赠送的,需要全部扣除 -// if info.RecType == model.COINGIVETYPE_SYSTEM { -// exchangeGiveFlowS := exchangeGiveFlow -// t := ActMgrSington.GetExchangeFlow(pd.Platform, info.LogType) -// if t != 0 { -// exchangeGiveFlowS = t -// } -// -// if info.NeedGiveFlowRate > 0 { -// exchangeGiveFlowS = info.NeedGiveFlowRate -// } -// -// needFlow = int64(math.Floor(float64(info.GiveCoin)*float64(exchangeGiveFlowS)/100)) * 100 -// -// if curTotalFlow < needFlow { -// //需要扣除 -// giveLostCoin += info.GiveCoin -// lockCoin += info.GiveCoin -// flow += needFlow - curTotalFlow -// curTotalFlow = 0 -// } else { -// curTotalFlow -= needFlow -// retIds = append(retIds, info.LogId.Hex()) -// } -// } else { -// exchangeGiveFlowS := exchangeGiveFlow -// t := ActMgrSington.GetExchangeFlow(pd.Platform, info.LogType) -// if t != 0 { -// exchangeGiveFlowS = t -// } -// if info.NeedGiveFlowRate > 0 { -// exchangeGiveFlowS = info.NeedGiveFlowRate -// } -// -// exchangePayFlowS := exchangeFlow -// if info.NeedFlowRate > 0 { -// exchangePayFlowS = info.NeedFlowRate -// } -// -// //分两部分扣除 -// needFlow = int64(math.Floor(float64(info.GiveCoin)*float64(exchangeGiveFlowS)/100)) * 100 -// needFlow += int64(math.Floor(float64(info.PayCoin)*float64(exchangePayFlowS)/100)) * 100 -// if curTotalFlow < needFlow { -// //需要扣除 -// giveLostCoin += info.GiveCoin -// //强制费用 -// forceTax += info.PayCoin * int64(exchangeForceTax) / 10000 -// lockCoin += info.GiveCoin -// lockCoin += info.PayCoin -// flow += needFlow - curTotalFlow -// curTotalFlow = 0 -// } else { -// curTotalFlow -= needFlow -// retIds = append(retIds, info.LogId.Hex()) -// } -// } -// needTotalFlow += needFlow -// } -// } -// } -// -// return flow, giveLostCoin, forceTax, needTotalFlow -//} -// -////pageNo 1开始 -//func GetExchangeFlowTotalPacket(playerTotalFlow int64, givesInfo []*model.CoinGiveLog, pd *model.PlayerData, -// pageNo, pageNum int32, isCheck bool) *shop_proto.SCGetPlayerPayFlowList { -// pack := &shop_proto.SCGetPlayerPayFlowList{} -// var giveLostCoin int64 //赠送扣除 -// var forceTax int64 //强制费用 -// var needTotalFlow int64 //需要的流水 -// startIndex := (pageNo - 1) * pageNum -// endIndex := pageNo * pageNum -// //platform := this.GetPlatform() -// exchangeFlow := GetExchangeFlow(pd) -// exchangeGiveFlow := GetExchangeGiveFlow(pd) -// exchangeForceTax := GetExchangeForceTax(pd) -// -// //按照时间排序 -// sort.Slice(givesInfo, func(i, j int) bool { return givesInfo[i].Ts > givesInfo[j].Ts }) -// //逐笔计算兑换流水金额,从上到下p -// curTotalFlow := playerTotalFlow -// -// index := int32(0) -// -// if GetExchangeFlag(pd) > 0 { -// for i := 0; i < len(givesInfo); i++ { -// info := givesInfo[i] -// if isCheck || info.Ts > pd.LastExchangeTime { -// tInfo := &shop_proto.PlayerPayFlowLog{} -// tInfo.Ts = proto.Int64(info.Ts) -// tInfo.PayType = proto.Int32(info.RecType) -// tInfo.PayCoin = proto.Int64(info.PayCoin) -// tInfo.GiveCoin = proto.Int64(info.GiveCoin) -// tInfo.FinishFlow = proto.Int64(info.FLow) -// tInfo.OrderID = proto.String(info.LogId.Hex()) -// //计算是否通过稽核 -// needFlow := int64(0) -// isPass := int32(0) -// curTotalFlow += info.FLow -// //如果是系统赠送的,需要全部扣除 -// if info.RecType == model.COINGIVETYPE_SYSTEM { -// exchangeGiveFlowS := exchangeGiveFlow -// t := ActMgrSington.GetExchangeFlow(pd.Platform, info.LogType) -// if t != 0 { -// exchangeGiveFlowS = t -// } -// if info.NeedGiveFlowRate > 0 { -// exchangeGiveFlowS = info.NeedGiveFlowRate -// } -// needFlow = int64(math.Floor(float64(info.GiveCoin)*float64(exchangeGiveFlowS)/100)) * 100 -// tInfo.GiveNeedFlow = proto.Int64(needFlow) -// if curTotalFlow < needFlow { -// //需要扣除 -// giveLostCoin += info.GiveCoin -// tInfo.ForceGiveCoin = proto.Int64(info.GiveCoin) -// -// curTotalFlow = 0 -// } else { -// curTotalFlow -= needFlow -// isPass = 1 -// } -// } else { -// exchangeGiveFlowS := exchangeGiveFlow -// t := ActMgrSington.GetExchangeFlow(pd.Platform, info.LogType) -// if t != 0 { -// exchangeGiveFlowS = t -// } -// -// if info.NeedGiveFlowRate > 0 { -// exchangeGiveFlowS = info.NeedGiveFlowRate -// } -// exchangePayFlowS := exchangeFlow -// if info.NeedFlowRate > 0 { -// exchangePayFlowS = info.NeedFlowRate -// } -// //分两部分扣除 -// needFlow = int64(math.Floor(float64(info.GiveCoin)*float64(exchangeGiveFlowS)/100)) * 100 -// tInfo.GiveNeedFlow = proto.Int64(needFlow) -// -// payNeedFlow := int64(math.Floor(float64(info.PayCoin)*float64(exchangePayFlowS)/100)) * 100 -// tInfo.PayNeedFlow = proto.Int64(payNeedFlow) -// needFlow += payNeedFlow -// -// if curTotalFlow < needFlow { -// //需要扣除 -// giveLostCoin += info.GiveCoin -// tInfo.ForceGiveCoin = proto.Int64(info.GiveCoin) -// -// //强制费用 -// forceTax += info.PayCoin * int64(exchangeForceTax) / 10000 -// tInfo.ForceTax = proto.Int64(info.PayCoin * int64(exchangeForceTax) / 10000) -// curTotalFlow = 0 -// } else { -// curTotalFlow -= needFlow -// isPass = 1 -// } -// } -// -// tInfo.IsPass = proto.Int32(isPass) -// needTotalFlow += needFlow -// -// if index >= startIndex && index < endIndex { -// pack.Data = append(pack.Data, tInfo) -// } -// -// index += 1 -// } -// } -// } -// pack.PageNo = proto.Int32(int32(pageNo)) -// pack.PageSum = proto.Int32(int32(math.Ceil(float64(index) / float64(pageNum)))) -// pack.PageSize = proto.Int32(pageNum) -// pack.TotalNum = proto.Int32(index) -// proto.SetDefaults(pack) -// return pack -//} - func (this *Player) SendPlayerInfo() { scPlayerData := &playerproto.SCPlayerData{ OpRetCode: playerproto.OpResultCode_OPRC_Sucess, @@ -2737,48 +2296,6 @@ func (this *Player) SendPlayerInfo() { this.SCDataConfig(common.DataConfigAll) } -//func (this *Player) SendJackpotInfo() { -// //通知所有的gamesrv向玩家发送奖池信息 -// if this.gateSess != nil { -// var gateSid int64 -// if srvInfo, ok := this.gateSess.GetAttribute(srvlib.SessionAttributeServerInfo).(*srvlibproto.SSSrvRegiste); ok && srvInfo != nil { -// sessionId := srvlib.NewSessionIdEx(srvInfo.GetAreaId(), srvInfo.GetType(), srvInfo.GetId(), 0) -// gateSid = sessionId.Get() -// } -// -// //查找当前平台下所以开放的游戏id -// info := make([]*server_proto.GameInfo, 0) -// gps := PlatformMgrSingleton.GetGameFrees(this.Platform) -// for _, v := range gps { -// if v.Status { -// if v.DbGameFree.GetGameRule() != 0 { -// //lgi := &server_proto.GameInfo{ -// // GameId: proto.Int32(v.DbGameFree.GetGameId()), -// // GameFreeId: proto.Int32(v.DbGameFree.GetId()), -// // GameType: proto.Int32(v.DbGameFree.GetGameType()), -// //} -// info = append(info, &server_proto.GameInfo{ -// GameId: proto.Int32(v.DbGameFree.GetGameId()), -// GameFreeId: proto.Int32(v.DbGameFree.GetId()), -// GameType: proto.Int32(v.DbGameFree.GetGameType()), -// }) -// } -// } -// } -// -// servers := GameSessMgrSington.GetAllGameSess() -// for _, v := range servers { -// pack := &server_proto.WGGameJackpot{ -// Sid: this.sid, -// GateSid: gateSid, -// Platform: this.Platform, -// Info: info, -// } -// v.Send(int(server_proto.SSPacketID_PACKET_WG_GAMEJACKPOT), pack) -// } -// } -//} - func (this *Player) IsGM() bool { if this.GMLevel > 0 { return true @@ -2876,15 +2393,6 @@ func (this *Player) ReportLoginEvent() { } } -func (this *Player) ReportBindPhoneEvent() { - //升级账号事件 - if !this.IsRob { - //LogChannelSingleton.WriteMQData(model.GenerateBindEvent(model.CreatePlayerBindPhoneEvent( - // this.SnId, this.Channel, this.BeUnderAgentCode, this.Platform, this.City, this.DeviceOS, - // this.CreateTime, this.TelephonePromoter))) - } -} - func (this *Player) ReportBindAlipayEvent() { //绑定支付宝事件 //if !this.IsRob { @@ -2899,55 +2407,6 @@ func (this *Player) ReportBindAlipayEvent() { //} } -// 破产事件 -func (this *Player) ReportBankRuptcy(gameid, gamemode, gamefreeid int32) { - //if !this.IsRob { - // d, e := model.MarshalBankruptcyEvent(2, this.SnId, this.TelephonePromoter, this.Channel, this.BeUnderAgentCode, - // this.Platform, this.City, this.CreateTime, gameid, gamemode, gamefreeid) - // if e == nil { - // rmd := model.NewInfluxDBData("hj.player_bankruptcy", d) - // if rmd != nil { - // InfluxDBDataChannelSington.Write(rmd) - // } - // } - //} -} - -func (this *Player) CheckType(gameid, gamefreeId int32) *serverproto.DB_PlayerType { - types := srvdata.PlayerTypeMgrSington.GetPlayerType(gamefreeId) - cnt := len(types) - if cnt > 0 { - var pgs model.PlayerGameStatics - if this.GDatas != nil { - if d, exist := this.GDatas[strconv.Itoa(int(gameid))]; exist { - pgs = d.Statics - } - } - - //赔率 产出/投入 万分比 - odds := int64(float64(float64(pgs.TotalOut+1)/float64(pgs.TotalIn+1)) * 10000) - if odds > 10000000 { - odds = 10000000 - } - for i := 0; i < cnt; i++ { - t := types[i] - logger.Logger.Warn("Player CheckType 0 ", this.CoinPayTotal, t.GetPayLowerLimit(), t.GetPayUpperLimit(), pgs.GameTimes, - t.GetGameTimeLowerLimit(), t.GetGameTimeUpperLimit(), pgs.TotalIn, t.GetTotalInLowerLimit(), t.GetTotalInUpperLimit(), - odds, t.GetOddsLowerLimit(), t.GetOddsUpperLimit()) - if t != nil { - if this.CoinPayTotal >= int64(t.GetPayLowerLimit()) && this.CoinPayTotal <= int64(t.GetPayUpperLimit()) && - pgs.GameTimes >= int64(t.GetGameTimeLowerLimit()) && pgs.GameTimes <= int64(t.GetGameTimeUpperLimit()) && - pgs.TotalIn >= int64(t.GetTotalInLowerLimit()) && pgs.TotalIn <= int64(t.GetTotalInUpperLimit()) && - odds >= int64(t.GetOddsLowerLimit()) && odds <= int64(t.GetOddsUpperLimit()) { - return t - } - } - } - } - return nil -} - -// 线程不安全,避免异步任务调用 func (this *Player) GetPlatform() *Platform { platform := PlatformMgrSingleton.GetPlatform(this.Platform) if platform != nil && platform.Isolated { @@ -2971,10 +2430,6 @@ func (this *Player) RobotRandName() { return } -func (this *Player) PlayerMacAbnormal() bool { - return false //s.HasSameIp(p.Ip) || s.HasSameMac() || s.HasSameTel() || s.HasSamePostion() -} - // 这个冲账记录不可随便写,需要加该日志时,请找lyk确认,暂定依据是金币直接加到身上,不依赖其他数据状态的可以写该日志 // 业务准则:先更新标记,再写冲账记录 func (this *Player) AddPayCoinLog(coin int64, coinType int32, oper string) { @@ -3007,162 +2462,6 @@ func (this *Player) AddPayCoinLog(coin int64, coinType int32, oper string) { } } -// 充值回调 -func (this *Player) SendPlayerRechargeAnswer(coin int64) { - if this.Tel == "" { - pack := &playerproto.SCPlayerRechargeAnswer{ - OpParam: proto.Int64(1), - AddCoin: proto.Int64(coin), - Coin: proto.Int64(this.Coin), - SafeBoxCoin: proto.Int64(this.SafeBoxCoin), - } - proto.SetDefaults(pack) - this.SendToClient(int(playerproto.PlayerPacketID_PACKET_SC_PLAYERRECHARGEANSWER), pack) - } -} - -// -//// 在线奖励: 重置, 清零在线时长及奖励领取信息 -//func (this *Player) OnlineRewardReset() { -// this.PlayerData.OnlineRewardData.OnlineDuration = 0 -// this.PlayerData.OnlineRewardData.RewardReceived = 0 -// this.PlayerData.OnlineRewardData.Ts = time.Now().Unix() -// this.dirty = true -//} -// -//// 在线奖励: (Logout时)累计在线时长 -//func (this *Player) OnlineRewardAddUpOnlineDuration() { -// if this.state != PlayerState_Online { -// return -// } -// -// tNow := time.Now() -// inSameDay := common.InSameDay(tNow, time.Unix(this.PlayerData.OnlineRewardData.Ts, 0)) -// if inSameDay { -// this.PlayerData.OnlineRewardData.OnlineDuration += uint32(tNow.Unix() - this.PlayerData.OnlineRewardData.Ts) -// } else { -// this.PlayerData.OnlineRewardData.OnlineDuration = uint32(tNow.Unix() - now.New(tNow).BeginningOfDay().Unix()) -// } -// -// this.PlayerData.OnlineRewardData.Ts = tNow.Unix() -// this.dirty = true -//} -// -//// 在线奖励: (实时)获取在线时长 -//func (this *Player) OnlineRewardGetOnlineDuration() uint32 { -// this.OnlineRewardAddUpOnlineDuration() -// return this.PlayerData.OnlineRewardData.OnlineDuration -//} - -// 幸运转盘 -//func (this *Player) LuckyTurntableSwitchScore(continuous bool) { -// if continuous { -// this.PlayerData.LuckyTurnTableData.Score = this.PlayerData.LuckyTurnTableData.TomorrowScore + -// int64(this.PlayerData.LuckyTurnTableData.TomorrowFloatScore/100) -// } else { -// this.PlayerData.LuckyTurnTableData.Score = 0 -// } -// -// this.PlayerData.LuckyTurnTableData.TomorrowScore = 0 -// this.PlayerData.LuckyTurnTableData.TomorrowFloatScore = 0 -// this.dirty = true -//} - -func (this *Player) SyncSafeBoxCoinToGame() { - pack := &serverproto.WGSyncPlayerSafeBoxCoin{ - SnId: proto.Int32(this.SnId), - SafeBoxCoin: proto.Int64(this.SafeBoxCoin), - } - proto.SetDefaults(pack) - this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_SyncPlayerSafeBoxCoin), pack) -} - -//func (this *Player) GetDgHboPlayerName(plt *Platform) (string, string) { -// if plt == nil { -// return "", "" -// } -// if plt.DgHboConfig == 0 { -// return this.DgGame, this.DgPass -// } else if plt.DgHboConfig == 1 { -// return this.StoreDgGame, this.StoreDgPass -// } else if plt.DgHboConfig == 2 { -// return this.StoreHboGame, this.StoreHboPass -// } -// return "", "" -//} -// -//func (this *Player) SetDgHboPlayerName(plt *Platform, name, pass string) { -// if plt == nil { -// return -// } -// -// if plt.DgHboConfig == 0 { -// this.DgGame = name -// this.DgPass = pass -// if strings.Contains(name, "dg") { -// this.StoreDgGame = name -// this.StoreDgPass = pass -// } else { -// this.StoreHboGame = name -// this.StoreHboPass = pass -// } -// } else if plt.DgHboConfig == 1 { -// this.StoreDgGame = name -// this.StoreDgPass = pass -// } else if plt.DgHboConfig == 2 { -// this.StoreHboGame = name -// this.StoreHboPass = pass -// } -// -//} - -func (this *Player) AddCoinPayTotal(coin int64) { - this.CoinPayTotal += coin -} - -func (this *Player) SendPlatformCanUsePromoterBind() { - state := int32(0) - plt := PlatformMgrSingleton.GetPlatform(this.Platform) - if plt != nil { - if plt.IsCanUserBindPromoter { - state = 1 - if this.BeUnderAgentCode != "" && this.BeUnderAgentCode != "0" { - state = 2 - } - } - } - - pack := &playerproto.SCBindPromoterState{ - BindState: proto.Int32(state), - } - - proto.SetDefaults(pack) - this.SendToClient(int(playerproto.PlayerPacketID_PACKET_SC_BINDPROMOTERSTATE), pack) -} - -func (this *Player) RedirectByGame(packetid int, rawpack interface{}) bool { - if this.scene == nil || this.scene.gameSess == nil || this.scene.gameSess.Session == nil { - logger.Logger.Tracef("[%v] sess == nil ", this.Name) - return false - } - if rawpack == nil { - logger.Logger.Trace(" rawpack == nil ") - return false - } - - data, err := netlib.MarshalPacket(packetid, rawpack) - if err == nil { - pack := &serverproto.SSRedirectToPlayer{ - SnId: proto.Int32(this.SnId), - PacketId: proto.Int(packetid), - Data: data, - } - proto.SetDefaults(pack) - return this.SendToGame(int(serverproto.SSPacketID_PACKET_SS_REDIRECTTOPLAYER), pack) - } - return false -} - // SyncPlayerDataToGateSrv 玩家信息同步到网关 func (this *Player) SyncPlayerDataToGateSrv(pd *model.PlayerData) { var buf bytes.Buffer @@ -3247,6 +2546,7 @@ func (this *Player) SyncGameCoin(sceneid int, enterts int64) { this.SendDiffData() }), "GetCoinWALBySnidAndInGameAndGreaterTs").Start() } + func (this *Player) SendShowRed(showType hallproto.ShowRedCode, showChild, isShow int32) { pack := &hallproto.SCShowRed{ ShowRed: &hallproto.ShowRed{ @@ -3260,18 +2560,6 @@ func (this *Player) SendShowRed(showType hallproto.ShowRedCode, showChild, isSho this.SendToClient(int(hallproto.HallPacketID_PACKET_SC_SHOWRED), pack) } -//func (this *Player) SCVIPBuy(buy int64) { -// //buy *= 10000 -// //this.AddMoneyPayTotal(buy) -// //this.GetVIPLevel(0) // 更新下vip等级 -// pack := &playerproto.SCVIPBuy{ -// OpRetCode: playerproto.OpResultCode_OPRC_Sucess, -// } -// pack.TolVipExp, pack.Money = this.GetCurrentVIPExp() // 获取经验会更新vip等级 -// pack.Vip = this.VIP -// this.SendToClient(int(playerproto.PlayerPacketID_PACKET_SC_VIPBUY), pack) -//} - func (this *Player) SCVIPInfo() { if this.IsRob { return @@ -3670,7 +2958,8 @@ func (this *Player) DoShopInfo(info *model.DbShop, isLogin bool) { } } -func (this *Player) GetShopInfo() { +// DealShopLog 处理订单 +func (this *Player) DealShopLog() { task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { info := model.GetDbShopLogsByState(this.Platform, this.SnId) if info != nil { @@ -3697,6 +2986,7 @@ func (this *Player) GetShopInfo() { })).StartByExecutor(fmt.Sprintf("Player%v", this.SnId)) } +// 奖池信息 func (this *Player) SendJackPotInit() { var pack = &hallproto.SCHundredSceneGetGameJackpot{} gameFreeIds := []int32{ @@ -3837,6 +3127,7 @@ func (this *Player) SendRankSeason() { logger.Logger.Trace("SCTMSeasonInfo:", pack) } +// 金币排行榜数据 func (this *Player) SendPlayerCoin() { mq.Write(&model.RankPlayerCoin{ Platform: this.Platform, @@ -3904,6 +3195,7 @@ func (this *Player) UnPlayerPowerListEx(powerId int32) { logger.Logger.Trace("通知客户端解锁炮台 snid = %v,解锁的炮台:%v,当前已有的炮台 = %v", this.SnId, powerId, this.PowerList) } } + func (this *Player) UpdatePlayerVipBag(shopId int32) { //判断是否是vip商品 更新数据 shopInfo := ShopMgrSington.GetShopInfo(shopId, this) @@ -4590,3 +3882,19 @@ func (this *Player) SCDataConfig(tp int) { logger.Logger.Tracef("SCDataConfig: %v", pack) } } + +func init() { + internal.RegisterPlayerListenerFunc(&internal.PlayerListenerFunc[*Player, *Scene]{ + ClockFunc: common.ClockFunc{}, + OnPlayerLoginedFunc: nil, + OnPlayerLogoutedFunc: nil, + OnPlayerDropLineFunc: nil, + OnPlayerReholdFunc: nil, + OnPlayerEnterSceneBeforeFunc: nil, + OnPlayerEnterSceneAfterFunc: nil, + OnPlayerLeaveSceneBeforeFunc: nil, + OnPlayerLeaveSceneAfterFunc: nil, + OnPlayerReturnSceneBeforeFunc: nil, + OnPlayerReturnSceneAfterFunc: nil, + }) +} diff --git a/worldsrv/playercache.go b/worldsrv/playercache.go index ee0b645..4fb0c5b 100644 --- a/worldsrv/playercache.go +++ b/worldsrv/playercache.go @@ -6,7 +6,6 @@ import ( "mongo.games.com/goserver/core" "mongo.games.com/goserver/core/basic" - "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/module" "mongo.games.com/goserver/core/task" @@ -193,49 +192,6 @@ func (c *PlayerCacheMgr) UnCacheInvalidPlayerId(snid int32) { delete(c.playerInvalidIds, snid) } -// 保存没有登录缓存的玩家数据 -func (c *PlayerCacheMgr) saveCache(p *PlayerCacheItem, isSync bool) { - if p == nil { - return - } - - saveFunc := func(v internal.PlayerLoader) { - if v == nil { - return - } - v.Save(p.Platform, p.SnId, true, true) - logger.Logger.Infof("PlayerCacheMgr SaveCache snid:%v", p.SnId) - } - releaseFunc := func(v internal.PlayerLoader) { - if v == nil { - return - } - if PlayerMgrSington.GetPlayerBySnId(p.SnId) == nil { - v.Release(p.Platform, p.SnId) - logger.Logger.Infof("PlayerCacheMgr SaveCache Release snid:%v", p.SnId) - } - } - - if PlayerMgrSington.GetPlayerBySnId(p.SnId) == nil { - if isSync { - for _, v := range internal.GetPlayerLoads() { - saveFunc(v) - releaseFunc(v) - } - } else { - for i := 0; i < len(internal.GetPlayerLoads()); i++ { - v := internal.GetPlayerLoads()[i] - task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - saveFunc(v) - return nil - }), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) { - releaseFunc(v) - })).StartByExecutor(fmt.Sprintf("Player%v", p.SnId)) - } - } - } -} - func (c *PlayerCacheMgr) ModuleName() string { return "PlayerCacheMgr" } @@ -249,16 +205,10 @@ func (c *PlayerCacheMgr) Update() { for _, p := range c.playerWaitClr { delete(c.playerMap, p.SnId) c.Pop(p) - - // 更新玩家数据 - c.saveCache(p, false) } c.playerWaitClr = c.playerWaitClr[0:0] } func (c *PlayerCacheMgr) Shutdown() { - for _, v := range c.playerMap { - c.saveCache(v, true) - } module.UnregisteModule(c) } diff --git a/worldsrv/playermgr.go b/worldsrv/playermgr.go index ab6d2d5..ca941ee 100644 --- a/worldsrv/playermgr.go +++ b/worldsrv/playermgr.go @@ -1,7 +1,9 @@ package main import ( + "fmt" "math/rand" + "os" "time" "mongo.games.com/goserver/core/basic" @@ -48,7 +50,7 @@ type PlayerMgr struct { // 平台id:snid:真实玩家 playerOfPlatform map[string]map[int32]*Player - loading map[string]*PlayerPendingData // accountid,控制访问频率 + loading map[string]*PlayerPendingData // accountid,控制访问频率;登录状态标记 } // PlayerStatics 在线统计 @@ -135,20 +137,76 @@ func (this *PlayerMgr) AddPlayer(sid int64, playerInfo *model.PlayerData, s *net this.playerOfPlatform[player.Platform] = pp } - logger.Logger.Tracef("###%v mount to DBSaver[AddPlayer]", player.Name) + logger.Logger.Tracef("###%v mount to DBSaver[AddPlayer]", player.SnId) if old != nil { //删除旧的玩家 DbSaveInst.UnregisterDbSaveTask(old) } DbSaveInst.RegisterDbSaverTask(player) } - internal.FirePlayerLogined(player) - return true } +func (this *PlayerMgr) SavePlayer(p *Player, isCopy, force bool) { + if p == nil || p.isDelete { + return + } + + if p.IsRob { + return + } + + if !p.dirty && !force { + return + } + + var pd *model.PlayerData + if isCopy { + pd = model.ClonePlayerData(p.PlayerData) + } else { + pd = p.PlayerData + } + if pd == nil { + logger.Logger.Errorf("Player Time2Save() %v pd is nil", p.SnId) + return + } + + t1 := time.Now() + + p.dirty = true + // 跨天任务依赖LastLogoutTime的准确性,跨天任务是定时器common.ClockMgrSington触发的,所以这里要用定时器的触发时间 + p.LastLogoutTime = common.ClockMgrSingleton.LastTickTime + pd.LastLogoutTime = common.ClockMgrSingleton.LastTickTime + + ok := true + t := task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { + if !model.SavePlayerData(pd) { + // save 失败先写到json里面 + model.BackupPlayerData(pd) + ok = false + } + for _, v := range internal.GetPlayerLoads() { + v.Save(pd.Platform, pd.SnId, true, force) + } + return ok + }), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) { + if saved, ok := i.(bool); ok && saved { + p.dirty = false + bak := fmt.Sprintf("%v.json", pd.AccountId) + if exist, _ := common.PathExists(bak); exist { + os.Remove(bak) + } + } + logger.Logger.Infof("Player Time2Save() %v take:%v isSuccess:%v", p.SnId, time.Now().Sub(t1), p.dirty == false) + }), "SavePlayerTask") + if b := t.StartByExecutor(fmt.Sprintf("Player%v", p.SnId)); b { + p.lastSaved = time.Now() + } +} + // DelPlayer 清除玩家缓存数据 -// 一般真人是数据持久化后删除或数据没有修改,机器人不用持久化(机器人数据没有主动删除) +// 真人数据持久化后删除,机器人不用持久化(机器人数据没有主动删除) +// needSave 是否需要保存数据; 自动删除玩家机制已经保存过数据,不需要再保存;手动删除玩家需要保存数据 func (this *PlayerMgr) DelPlayer(snid int32) bool { player, ok := this.snidMap[snid] if !ok || player == nil { @@ -178,14 +236,18 @@ func (this *PlayerMgr) DelPlayer(snid int32) bool { } } + if !player.IsCacheState() { + player.OnLogoutFinish() + internal.FirePlayerLogouted[*Player, *Scene](player) + } + + DbSaveInst.UnregisterDbSaveTask(player) + + // 再保存一次,防止数据丢失,可能脏标记没有设置 + this.SavePlayer(player, true, true) for _, v := range internal.GetPlayerLoads() { v.Release(player.Platform, player.SnId) } - - player.OnLogouted() - - DbSaveInst.UnregisterDbSaveTask(player) - player.Save(true) return true } @@ -194,6 +256,9 @@ func (this *PlayerMgr) DelPlayer(snid int32) bool { // 2.玩家网络断开 // 3.被踢掉线 func (this *PlayerMgr) DropPlayer(p *Player) { + p.SetOffline() + p.sid = 0 + p.gateSess = nil delete(this.sidMap, p.sid) } @@ -208,12 +273,20 @@ func (this *PlayerMgr) ReholdPlayer(p *Player, newSid int64, newSess *netlib.Ses logger.Logger.Errorf("(this *PlayerMgr) ReholdPlayer(snid=%v, new=%v)", p.SnId, newSid) } + p.SetOnline() p.sid = newSid p.gateSess = newSess - p.SetOnline() this.sidMap[newSid] = p } +func (this *PlayerMgr) KickByPlatform(name string) { + for _, p := range this.players { + if name == "" || p.Platform == name { + p.Kick(common.KickReason_Disconnection) + } + } +} + // GetOnlinePlayer 获取玩家数据(玩家在线) func (this *PlayerMgr) GetOnlinePlayer(id int64) *Player { if pi, ok := this.sidMap[id]; ok { @@ -398,98 +471,29 @@ func (this *PlayerMgr) BroadcastMessageToTarget(snIds []int32, packetid int, raw } } -// 感兴趣所有clock event -func (this *PlayerMgr) InterestClockEvent() int { - return (1 << common.ClockEventMax) - 1 -} - -func (this *PlayerMgr) OnSecTimer() { - for _, player := range this.players { - utils.CatchPanic(func() { - player.OnSecTimer() - }) - } -} - -func (this *PlayerMgr) OnMiniTimer() { - for _, player := range this.players { - utils.CatchPanic(func() { - player.OnMiniTimer() - }) - } -} - -func (this *PlayerMgr) OnHourTimer() { - for _, player := range this.players { - utils.CatchPanic(func() { - player.OnHourTimer() - }) - } -} - -func (this *PlayerMgr) OnDayTimer() { - for _, player := range this.players { - utils.CatchPanic(func() { - player.OnDayTimer(false, true, 1) - }) - } -} - -func (this *PlayerMgr) OnMonthTimer() { - for _, player := range this.players { - utils.CatchPanic(func() { - player.OnMonthTimer() - }) - } -} - -func (this *PlayerMgr) OnWeekTimer() { - for _, player := range this.players { - utils.CatchPanic(func() { - player.OnWeekTimer() - }) - } -} - -func (this *PlayerMgr) OnShutdown() { - this.SaveAll() -} - // SaveAll 保存所有数据,dirty=true func (this *PlayerMgr) SaveAll() { count := len(this.players) start := time.Now() saveCnt := 0 failCnt := 0 - nochangeCnt := 0 - logger.Logger.Info("===@PlayerMgr.SaveAll BEG@=== TotalCount:", count) + logger.Logger.Info("===@SaveAllPlayerBEGIN@=== TotalCount:", count) for i, p := range this.players { idx := i + 1 - if p.dirty { - if model.SavePlayerData(p.PlayerData) { - logger.Logger.Infof("===@SavePlayerData %v/%v snid:%v coin:%v safebox:%v coinpayts:%v safeboxts:%v gamets:%v save [ok] @=", idx, count, p.SnId, p.Coin, p.SafeBoxCoin, p.CoinPayTs, p.SafeBoxCoinTs, p.GameCoinTs) - saveCnt++ - } else { - logger.Logger.Warnf("===@SavePlayerData %v/%v snid:%v coin:%v safebox:%v coinpayts:%v safeboxts:%v gamets:%v save [error]@=", idx, count, p.SnId, p.Coin, p.SafeBoxCoin, p.CoinPayTs, p.SafeBoxCoinTs, p.GameCoinTs) - failCnt++ + if model.SavePlayerData(p.PlayerData) { + logger.Logger.Infof("===@SavePlayerData %v/%v snid:%v coin:%v safebox:%v coinpayts:%v safeboxts:%v gamets:%v save [ok] @=", + idx, count, p.SnId, p.Coin, p.SafeBoxCoin, p.CoinPayTs, p.SafeBoxCoinTs, p.GameCoinTs) + for _, v := range internal.GetPlayerLoads() { + v.Save(p.Platform, p.SnId, true, true) } + saveCnt++ } else { - logger.Logger.Infof("nochange===@SavePlayerData %v/%v snid:%v coin:%v safebox:%v coinpayts:%v safeboxts:%v gamets:%v nochange [ok]@=", idx, count, p.SnId, p.Coin, p.SafeBoxCoin, p.CoinPayTs, p.SafeBoxCoinTs, p.GameCoinTs) - nochangeCnt++ - } - for _, v := range internal.GetPlayerLoads() { - v.Save(p.Platform, p.SnId, true, true) - } - } - logger.Logger.Infof("===@PlayerMgr.SaveAll END@===, total:%v saveCnt:%v failCnt:%v nochangeCnt:%v take:%v", count, saveCnt, failCnt, nochangeCnt, time.Now().Sub(start)) -} - -func (this *PlayerMgr) KickByPlatform(name string) { - for _, p := range this.players { - if name == "" || p.Platform == name { - p.Kickout(common.KickReason_Disconnection) + logger.Logger.Warnf("===@SavePlayerData %v/%v snid:%v coin:%v safebox:%v coinpayts:%v safeboxts:%v gamets:%v save [error]@=", + idx, count, p.SnId, p.Coin, p.SafeBoxCoin, p.CoinPayTs, p.SafeBoxCoinTs, p.GameCoinTs) + failCnt++ } } + logger.Logger.Infof("===@SaveAllPlayerEND@===, total:%v saveCnt:%v failCnt:%v take:%v", count, saveCnt, failCnt, time.Now().Sub(start)) } // LoadRobots 预加载机器人数据 @@ -726,7 +730,6 @@ func (this *PlayerMgr) RecommendFriendRule(platform string, snid int32) []Recomm } func init() { - //BlackListMgrSington.RegisterObserver(PlayerMgrSington) PlayerSubjectSign.AttachName(PlayerMgrSington) PlayerSubjectSign.AttachHead(PlayerMgrSington) PlayerSubjectSign.AttachHeadOutline(PlayerMgrSington) @@ -736,5 +739,51 @@ func init() { PlayerSubjectSign.AttachHead(FriendMgrSington) // 定时器 - common.ClockMgrSingleton.RegisterSinker(PlayerMgrSington) + common.RegisterClockFunc(&common.ClockFunc{ + OnSecTimerFunc: func() { + for _, player := range PlayerMgrSington.players { + utils.CatchPanic(func() { + player.OnSecTimer() + }) + } + }, + OnMiniTimerFunc: func() { + for _, player := range PlayerMgrSington.players { + utils.CatchPanic(func() { + player.OnMiniTimer() + }) + } + }, + OnHourTimerFunc: func() { + for _, player := range PlayerMgrSington.players { + utils.CatchPanic(func() { + player.OnHourTimer() + }) + } + }, + OnDayTimerFunc: func() { + for _, player := range PlayerMgrSington.players { + utils.CatchPanic(func() { + player.OnDayTimer(false, true, 1) + }) + } + }, + OnWeekTimerFunc: func() { + for _, player := range PlayerMgrSington.players { + utils.CatchPanic(func() { + player.OnWeekTimer() + }) + } + }, + OnMonthTimerFunc: func() { + for _, player := range PlayerMgrSington.players { + utils.CatchPanic(func() { + player.OnMonthTimer() + }) + } + }, + OnShutdownFunc: func() { + PlayerMgrSington.SaveAll() + }, + }) } diff --git a/worldsrv/promotermgr.go b/worldsrv/promotermgr.go index fa5f64e..dae7b63 100644 --- a/worldsrv/promotermgr.go +++ b/worldsrv/promotermgr.go @@ -14,6 +14,14 @@ const ( PROMOTER_TYPE_PROMOTE = 3 //推广员 ) +type ErrorString struct { + code string +} + +func (e *ErrorString) Error() string { + return e.code +} + var PromoterMgrSington = &PromoterMgr{ PromoterConfigMap: make(map[string]*PromoterConfig), LastTicket: 0, diff --git a/worldsrv/trascate_webapi.go b/worldsrv/trascate_webapi.go index 0aeab5c..113786b 100644 --- a/worldsrv/trascate_webapi.go +++ b/worldsrv/trascate_webapi.go @@ -1036,7 +1036,7 @@ func init() { task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { return model.FreezeAccount(msg.Platform, player.AccountId, int(msg.Minute)) }), nil, "FreezeAccount").Start() - player.Kickout(common.KickReason_Freeze) + player.Kick(common.KickReason_Freeze) pack.Tag = webapiproto.TagCode_SUCCESS pack.Msg = "success" } else { @@ -1714,7 +1714,7 @@ func init() { //在线需要踢掉玩家 if uint(msg.BlacklistType)&BlackState_Login != 0 { logger.Logger.Infof("found platform:%v player:%d snid in blacklist", msg.Platform, player.SnId) - player.Kickout(int32(loginproto.SSDisconnectTypeCode_SSDTC_BlackList)) + player.Kick(int32(loginproto.SSDisconnectTypeCode_SSDTC_BlackList)) } return common.ResponseTag_Ok, pack } else { @@ -2427,7 +2427,7 @@ func init() { } } - p.Kickout(common.KickReason_Freeze) + p.Kick(common.KickReason_Freeze) PlayerMgrSington.DelPlayer(p.SnId) LoginStateMgrSington.DelAccountByAccid(p.AccountId) }