From 28921649c5c2baec515ec969ea29d67a5d26eafc Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Wed, 14 Aug 2024 11:12:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worldsrv/action_game.go | 972 +--------------------------------------- worldsrv/player.go | 2 +- 2 files changed, 13 insertions(+), 961 deletions(-) diff --git a/worldsrv/action_game.go b/worldsrv/action_game.go index 280177e..a1524f6 100644 --- a/worldsrv/action_game.go +++ b/worldsrv/action_game.go @@ -1,25 +1,22 @@ package main import ( - "errors" "fmt" "math/rand" "time" - webapi_proto "mongo.games.com/game/protocol/webapi" + "mongo.games.com/goserver/core/basic" + "mongo.games.com/goserver/core/logger" + "mongo.games.com/goserver/core/netlib" + "mongo.games.com/goserver/core/task" "mongo.games.com/game/common" "mongo.games.com/game/model" "mongo.games.com/game/proto" "mongo.games.com/game/protocol/gamehall" - "mongo.games.com/game/protocol/player" "mongo.games.com/game/protocol/server" + webapiproto "mongo.games.com/game/protocol/webapi" "mongo.games.com/game/srvdata" - "mongo.games.com/game/webapi" - "mongo.games.com/goserver/core/basic" - "mongo.games.com/goserver/core/logger" - "mongo.games.com/goserver/core/netlib" - "mongo.games.com/goserver/core/task" ) type CSEnterRoomPacketFactory struct { @@ -49,7 +46,7 @@ func (this *CSEnterRoomHandler) Process(s *netlib.Session, packetid int, data in var roomId int var gameId int var gameMode int - var cfg *webapi_proto.GameFree + var cfg *webapiproto.GameFree oldPlatform := p.Platform // 进入原来的房间 @@ -199,7 +196,7 @@ func (this *CSAudienceEnterRoomHandler) Process(s *netlib.Session, packetid int, var code = gamehall.OpResultCode_Game_OPRC_Sucess_Game var sp ScenePolicy var dbGameFree *server.DB_GameFree - var cfg *webapi_proto.GameFree + var cfg *webapiproto.GameFree scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId())) if scene == nil { code = gamehall.OpResultCode_Game_OPRC_RoomNotExist_Game @@ -341,906 +338,6 @@ func (this *CSReturnRoomHandler) Process(s *netlib.Session, packetid int, data i return nil } -type CSJoinGamePacketFactory struct { -} -type CSJoinGameHandler struct { -} - -func (this *CSJoinGamePacketFactory) CreatePacket() interface{} { - pack := &gamehall.CSJoinGame{} - return pack -} -func (this *CSJoinGameHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { - logger.Logger.Trace("CSJoinGameHandler Process recv ", data) - if msg, ok := data.(*gamehall.CSJoinGame); ok { - p := PlayerMgrSington.GetPlayer(sid) - if p == nil { - logger.Logger.Warn("CSJoinGameHandler p == nil") - return nil - } - if p.scene == nil { - logger.Logger.Warn("CSJoinGameHandler scene == nil") - return nil - } - - newPlayer := PlayerMgrSington.GetPlayerBySnId(msg.GetSnId()) - if newPlayer != nil { - pack := &gamehall.SCJoinGame{ - MsgType: proto.Int32(msg.GetMsgType()), - OpRetCode: gamehall.OpResultCode_Game(0), - } - if !p.scene.IsTestScene() { - // 入场限额检查 - if p.scene.dbGameFree.GetLimitCoin() != 0 && int64(p.scene.dbGameFree.GetLimitCoin()) > p.Coin { - pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_MoneyNotEnough_Game - newPlayer.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_JOINGAME), pack) - return nil - } - // 携带金币检查 - if p.scene.dbGameFree.GetMaxCoinLimit() != 0 && int64(p.scene.dbGameFree.GetMaxCoinLimit()) < p.Coin && !p.IsRob { - pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_CoinTooMore_Game - newPlayer.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_JOINGAME), pack) - return nil - } - } - // 是否还有空座位 - if p.scene.IsFull() { - pack.OpRetCode = gamehall.OpResultCode_Game(1) - newPlayer.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_JOINGAME), pack) - return nil - } - p.scene.AudienceSit(newPlayer, -1) - newPlayer.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_JOINGAME), pack) - } - } - return nil -} - -type CSGetDataLogPacketFactory struct { -} -type CSGetDataLogHandler struct { -} - -func (this *CSGetDataLogPacketFactory) CreatePacket() interface{} { - pack := &player.CSGetDataLog{} - return pack -} - -func (this *CSGetDataLogHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { - logger.Logger.Trace("CSGetDataLogHandler Process recv ", data) - if msg, ok := data.(*player.CSGetDataLog); ok { - p := PlayerMgrSington.GetPlayer(sid) - if p == nil { - logger.Logger.Warn("CSGetDataLogHandler p == nil") - return nil - } - ts := int64(msg.GetVer()) - if ts == 0 { - ts = time.Now().Unix() - } - type LogData struct { - datas []model.CoinLog - err error - } - task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - datas, err := model.GetCoinLogBySnidAndLessTs(p.Platform, p.SnId, ts) - return &LogData{datas: datas, err: err} - }), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) { - if d, ok := data.(*LogData); ok { - if d != nil && d.err == nil { - pack := &player.SCGetDataLog{ - DataType: msg.DataType, - } - ver := msg.GetVer() - for i := 0; i < len(d.datas); i++ { - ts := d.datas[i].Time.Unix() - if int32(ts) < ver { - ver = int32(ts) - } - pack.Datas = append(pack.Datas, &player.DataLog{ - LogType: proto.Int32(d.datas[i].LogType), - ChangeCount: proto.Int64(d.datas[i].Count), - RestCount: proto.Int64(d.datas[i].RestCount), - Remark: proto.String(d.datas[i].Remark), - Ts: proto.Int32(int32(ts)), - }) - } - pack.Ver = proto.Int32(ver) - proto.SetDefaults(pack) - p.SendToClient(int(player.PlayerPacketID_PACKET_SC_GETDATALOG), pack) - } - } - }), "GetCoinLogBySnidAndLessTs").StartByFixExecutor("coinlog_r") - } - return nil -} - -// 第三方-->系统 -func _LeaveTransferThird2SystemTask(p *Player) { - - if p.thrscene == 0 { - logger.Logger.Tracef("player snid=%v TransferThird2SystemTask p.thrscene == 0 return", p.SnId) - return - } - - //if p.thrscene.sceneMode != int(common.SceneMode_Thr) { - // logger.Logger.Infof("player snid=%v TransferThird2SystemTask p.scene == thrID return", p.SnId) - // return - //} - - if p.thridBalanceRefreshReqing { - logger.Logger.Tracef("player snid=%v TransferThird2SystemTask p.thridBalanceRefreshReqing == true return", p.SnId) - return - } - gainway := common.GainWay_Transfer_Thrid2System - plt := webapi.ThridPlatformMgrSington.FindPlatformByPlatformBaseGameId(p.thrscene) - if plt == nil { - logger.Logger.Tracef("player snid=%v TransferThird2SystemTask plt == nil return", p.SnId) - return - } - - oper := plt.GetPlatformBase().Name + "2System" - amount := int64(0) - timeStamp := time.Now().UnixNano() - p.thridBalanceRefreshReqing = true - //timeout := false - task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - for i := int32(0); i < model.GameParamData.ThirdPltTransferMaxTry; { - var err error - var coinLog *model.PayCoinLog - var coinlogex *model.CoinLog - //var apiHasTransfer = false - remark := plt.GetPlatformBase().Name + "转出到系统" - //allow := plt.ReqIsAllowTransfer(p.SnId, p.Platform, p.Channel) - //if !allow { - // goto Rollback - //} - err, amount = plt.ReqLeaveGame(p.SnId, fmt.Sprintf("%v", p.thrscene), p.Ip, p.Platform, p.Channel) - if err != nil { - goto Rollback - } - if amount <= 0 { - return nil - } - if plt.GetPlatformBase().TransferInteger { - amount = (amount / 100) * 100 - if amount <= 0 { - return nil - } - } - timeStamp = time.Now().UnixNano() - //如果請求超時的話資金就不能從三方出來,玩家的錢只會少 - //err, timeout = plt.ReqTransfer(p.SnId, -amount, strconv.FormatInt(timeStamp, 10), p.Platform, p.Channel, p.Ip) - //if err != nil || timeout { - // goto Rollback - //} - //apiHasTransfer = true - coinLog = model.NewPayCoinLog(timeStamp, int32(p.SnId), amount, int32(gainway), oper, model.PayCoinLogType_Coin, 0) - timeStamp = coinLog.TimeStamp - err = model.InsertPayCoinLogs(p.Platform, coinLog) - if err != nil { - goto Rollback - } - coinlogex = model.NewCoinLogEx(&model.CoinLogParam{ - Platform: p.Platform, - SnID: p.SnId, - Channel: p.Channel, - ChangeType: common.BillTypeCoin, - ChangeNum: amount, - RemainNum: p.Coin + amount, - Add: 0, - LogType: int32(gainway), - GameID: 0, - GameFreeID: 0, - BaseCoin: 0, - Operator: oper, - Remark: remark, - }) - err = model.InsertCoinLog(coinlogex) - if err != nil { - goto Rollback - } - return nil - Rollback: - if coinLog != nil { - model.RemovePayCoinLog(p.Platform, coinLog.LogId) - } - if coinlogex != nil { - model.RemoveCoinLogOne(coinlogex.Platform, coinlogex.LogId) - } - //如果發現有任何一個超時,則就不在往下執行,因為不知道數據是否正確 - /* - if timeout { - logger.Logger.Errorf("player snid=%v third->system transfer %v timeout at try %v times,then stop try!", p.SnId, -amount, i+1) - break - } - if apiHasTransfer { - err, timeout = plt.ReqTransfer(p.SnId, amount, strconv.FormatInt(time.Now().UnixNano(), 10), p.Platform, p.Channel, p.Ip) - if err != nil { - logger.Logger.Errorf("player snid=%v third->system transfer rollback fail at try %v times", p.SnId, i+1) - } - } - //如果发现有任何一個超时,則就不在往下执行,因为不知道数据是否在三方已经处理 - if timeout { - logger.Logger.Errorf("player snid=%v third->system rollback transfer %v timeout at try %v times,then stop try!", p.SnId, amount, i+1) - break - } - */ - logger.Logger.Tracef("player snid=%v third->system transfer rollback at try %v times", p.SnId, i+1) - i++ - if i < model.GameParamData.ThirdPltTransferMaxTry { - time.Sleep(time.Duration(model.GameParamData.ThirdPltTransferInterval) * time.Second) - } - } - return errors.New("third->system transfer error >max try times!") - }), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) { - statePack := &gamehall.SCThridGameBalanceUpdateState{} - if data != nil { - p.thirdBalanceRefreshMark[plt.GetPlatformBase().Name] = false - p.thridBalanceReqIsSucces = false - statePack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Error_Game - logger.Logger.Trace("SCThridAccountTransferHandler third->system transfer error:", data) - } else { - p.thridBalanceReqIsSucces = true - statePack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Sucess_Game - // p.thrscene = nil - p.Coin += amount - p.SetPayTs(timeStamp) - p.thirdBalanceRefreshMark[plt.GetPlatformBase().Name] = true - //ThirdPlatformMgrSington.AddThirdPlatformCoin(p.Platform, plt.GetPlatformBase().Tag, thirdBalance) - } - p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_THRIDGAMEBALANCEUPDATESTATE), statePack) - p.dirty = true - - if statePack.OpRetCode == gamehall.OpResultCode_Game_OPRC_Sucess_Game { - //退出成功 重置场景状态 - if p.thrscene != 0 { - p.thrscene = 0 - p.scene = nil - } - } - - p.thridBalanceRefreshReqing = false - p.diffData.Coin = -1 //强制更新金币 - p.SendDiffData() - return - }), "ThridAccountTransfer").Start() -} - -// 进入三方 -//type CSEnterThridGamePacketFactory struct { -//} -//type CSEnterThridGameHandler struct { -//} - -//func (this *CSEnterThridGamePacketFactory) CreatePacket() interface{} { -// pack := &gamehall.CSEnterThridGame{} -// return pack -//} - -//func (this *CSEnterThridGameHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { -// logger.Logger.Trace("CSEnterThridGameHandler Process recv ", data) -// p := PlayerMgrSington.GetPlayer(sid) -// if p == nil { -// logger.Logger.Warn("CSEnterThridGameHandler p == nil") -// return nil -// } -// -// if msg, ok := data.(*gamehall.CSEnterThridGame); ok { -// // msg.ThridGameId = proto.Int32(9010001) -// returnErrorCodeFunc := func(code gamehall.OpResultCode_Game) { -// pack := &gamehall.SCEnterThridGame{} -// pack.OpRetCode = code -// pack.ThridGameId = msg.ThridGameId -// p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_ENTERTHRIDGAME), pack) -// logger.Trace(pack) -// } -// //正在请求刷新余额中不能进入三方 -// if p.thridBalanceRefreshReqing { -// logger.Logger.Warn("CSEnterThridGameHandler client req thridBalanceRefreshReqing", p.SnId) -// returnErrorCodeFunc(gamehall.OpResultCode_Game_OPRC_ThirdPltProcessing_Game) -// return nil -// } -// //msg.ThridGameId=proto.Int32(430010001) -// -// //找到对应的平台 -// thridPltGameItem, plt := ThirdPltGameMappingConfig.FindThirdInfoBySystemGameId(msg.ThridGameId) -// if thridPltGameItem == nil || plt == nil { -// logger.Logger.Infof("Player %v no platform", p.SnId) -// returnErrorCodeFunc(gamehall.OpResultCode_Game_OPRC_RoomHadClosed_Game) -// return nil -// } -// -// if p.thrscene != 0 && p.thrscene != plt.GetPlatformBase().BaseGameID { -// logger.Logger.Infof("Player %v in game.", p.SnId) -// returnErrorCodeFunc(gamehall.OpResultCode_Game_OPRC_ThirdPltProcessing_Game) -// return nil -// } -// if p.isDelete { -// returnErrorCodeFunc(gamehall.OpResultCode_Game_OPRC_RoomHadClosed_Game) -// return nil -// } -// //pt := PlatformMgrSingleton.GetPackageTag(p.PackageID) -// //if pt != nil && pt.IsForceBind == 1 { -// // if p.BeUnderAgentCode == "" || p.BeUnderAgentCode == "0" { -// // returnErrorCodeFunc(gamehall.OpResultCode_Game_OPRC_MustBindPromoter_Game) -// // return nil -// // } -// //} -// -// //检测房间状态是否开启 -// gps := PlatformMgrSingleton.GetGameFree(p.Platform, msg.GetThridGameId()) -// if gps == nil { -// logger.Logger.Infof("Player %v no cfg room close", p.SnId) -// -// returnErrorCodeFunc(gamehall.OpResultCode_Game_OPRC_RoomHadClosed_Game) -// return nil -// } -// dbGameFree := gps.DbGameFree -// if dbGameFree == nil { -// logger.Logger.Infof("Player %v no gamefree", p.SnId) -// returnErrorCodeFunc(gamehall.OpResultCode_Game_OPRC_RoomHadClosed_Game) -// return nil -// } -// pfConfig := PlatformMgrSingleton.GetPlatform(p.Platform) -// if pfConfig == nil || pfConfig.ThirdGameMerchant == nil || pfConfig.ThirdGameMerchant[int32(plt.GetPlatformBase().BaseGameID)] == 0 { -// logger.Logger.Infof("Player %v no pfcfg", p.SnId) -// -// // returnErrorCodeFunc(gamehall.OpResultCode_Game_OPRC_RoomHadClosed_Game) -// // return nil -// } -// -// //检查限额,金额不足 -// if dbGameFree.GetLimitCoin() != 0 && p.GetCoin() < int64(dbGameFree.GetLimitCoin()) { -// returnErrorCodeFunc(gamehall.OpResultCode_Game_OPRC_CoinNotEnough_Game) -// return nil -// } -// -// //检查平台配额是否足够 -// /*if plt.GetPlatformBase().IsNeedCheckQuota { -// dgQuota := ThirdPlatformMgrSington.GetThirdPlatformCoin(p.Platform, plt.GetPlatformBase().Tag) -// if dgQuota <= 0 || dgQuota <= p.GetCoin() { -// logger.Logger.Infof("Player snid %v %v platfrom Quota of game not enough.", p.SnId, plt.GetPlatformBase().Name) -// returnErrorCodeFunc(gamehall.OpResultCode_Game_OPRC_Dg_QuotaNotEnough_Game) -// return nil -// } -// }*/ -// -// //检查场景是否开放或者存在,预设数据 -// //scene := SceneMgrSingleton.GetThirdScene(plt) -// //if scene != nil { -// p.thrscene = plt.GetPlatformBase().BaseGameID -// //检查场景是否开放或者存在,预设数据 -// scene := SceneMgrSingleton.GetThirdScene(plt) //仅用于占位 -// if scene != nil { -// p.scene = scene -// } -// //} else { -// // logger.Logger.Infof("Player %v no scene", p.SnId) -// -// // returnErrorCodeFunc(gamehall.OpResultCode_Game_OPRC_RoomHadClosed_Game) -// // return nil -// //} -// -// AskEnterThridGame(p, plt, thridPltGameItem, s) -// } -// return nil -//} -//func AskEnterThridGame(p *Player, plt webapi.IThirdPlatform, thridPltGameItem *server.DB_ThirdPlatformGameMapping, -// s *netlib.Session) { -// pack := &gamehall.SCEnterThridGame{} -// pack.ThridGameId = thridPltGameItem.SystemGameID -// amount := p.GetCoin() -// if plt.GetPlatformBase().TransferInteger { -// amount = (amount / 100) * 100 -// } -// p.Coin = p.GetCoin() - amount -// gainway := common.GainWay_Transfer_System2Thrid -// oper := "System2" + plt.GetPlatformBase().Name -// timeStamp := time.Now().UnixNano() -// p.thridBalanceRefreshReqing = true -// transferTimeOut := false -// task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { -// var err error -// //var ok bool -// url := "" -// remark := "转入" + plt.GetPlatformBase().Name + thridPltGameItem.GetDesc() -// //thridPlatformCoin := int64(0) -// var coinLog *model.PayCoinLog -// var coinlogex *model.CoinLog -// /*err = ensureThridPltUserName(plt, p, amount, s.RemoteAddr()) -// if err != nil && err != webapi.ErrNoCreated { -// goto Rollback -// }*/ -// //ok = utils.RunPanicless(func() { -// err, url = enterThridPltUserName(plt, p, amount, thridPltGameItem.GetThirdGameID(), s.RemoteAddr()) -// //err, url = plt.ReqEnterGame(p.SnId, thridGameId, s.RemoteAddr(), p.Platform, p.Channel, p.Ip) -// //}) -// if err == webapi.ErrRequestTimeout { // 超时 -// transferTimeOut = true -// } -// //ok = true -// if err != nil && !transferTimeOut { -// logger.Logger.Errorf("plt.ReqEnterGame() snid:%v error: %v", p.SnId, err) -// if thrErr, ok := err.(webapi.ThirdError); ok { -// if thrErr.IsClose() { -// pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Thr_GameClose_Game -// } else { -// pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Error_Game -// } -// } else { -// pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Error_Game -// } -// goto Rollback -// } -// coinLog = model.NewPayCoinLog(timeStamp, int32(p.SnId), -amount, int32(gainway), oper, model.PayCoinLogType_Coin, 0) -// timeStamp = coinLog.TimeStamp -// err = model.InsertPayCoinLogs(p.Platform, coinLog) -// if err != nil { -// goto Rollback -// } -// coinlogex = model.NewCoinLogEx(&model.CoinLogParam{ -// Platform: p.Platform, -// SnID: p.SnId, -// ChangeType: common.BillTypeCoin, -// ChangeNum: -amount, -// RemainNum: p.Coin, -// Add: 0, -// LogType: int32(gainway), -// GameID: 0, -// GameFreeID: 0, -// BaseCoin: 0, -// Operator: oper, -// Remark: remark, -// }) -// err = model.InsertCoinLog(coinlogex) -// if err != nil { -// goto Rollback -// } -// // -// //err, transferTimeOut = plt.ReqTransfer(p.SnId, amount, strconv.FormatInt(timeStamp, 10), p.Platform, p.Channel, p.Ip) -// if transferTimeOut { -// logger.Logger.Errorf("plt.ReqTransfer() snid:%v error:%v", p.SnId, err) -// pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Error_Game -// goto Rollback -// } -// pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Sucess_Game -// pack.ScreenOrientationType = proto.Int32(thridPltGameItem.GetScreenOrientationType()) -// pack.EnterUrl = proto.String(url) -// return nil -// Rollback: -// pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Error_Game -// if coinLog != nil { -// model.RemovePayCoinLog(p.Platform, coinLog.LogId) -// } -// if coinlogex != nil { -// if transferTimeOut { -// err2 := model.UpdateCoinLogRemark(coinlogex.Platform, coinlogex.LogId, plt.GetPlatformBase().Name+"需人工处理") -// if err2 != nil { -// logger.Logger.Errorf("thr UpdateCoinLogRemark(%v) error: %v", coinlogex.LogId, err2) -// } -// } else { -// model.RemoveCoinLogOne(coinlogex.Platform, coinlogex.LogId) -// } -// -// } -// return errors.New("system->third transfer rollback!") -// }), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) { -// if pack.GetOpRetCode() == gamehall.OpResultCode_Game_OPRC_Sucess_Game { -// // ThirdPlatformMgrSington.AddThirdPlatformCoin(p.Platform, plt.GetPlatformBase().Tag, -amount) -// p.SetPayTs(timeStamp) -// } else { -// //如帐变出现问题,就在日志里面查下面的输出信息!!! -// //如果转账超时,三方的转账是否成功就是未知的,这时不能将金币再加到玩家身上。 -// //如果出现超时问题,就需要人工对账。 -// //注意:这个地方说的超时已经包含CG工程Check订单后的超时 -// if transferTimeOut { -// logger.Logger.Errorf("CSEnterThridGameHandler player snid:%v transfer %v to %v timeout:", p.SnId, amount, plt.GetPlatformBase().Name) -// } else { -// p.Coin += amount -// } -// p.thrscene = 0 -// pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Error_Game -// logger.Logger.Trace("enterThridPltUserName system->third transfer error:", data) -// } -// p.dirty = true -// p.thirdBalanceRefreshMark[plt.GetPlatformBase().Name] = false -// -// p.SendDiffData() -// p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_ENTERTHRIDGAME), pack) -// p.thridBalanceRefreshReqing = false -// logger.Logger.Trace("CSEnterThridGameHandler send client:", pack) -// return -// }), "CSEnterThridGameHandler").Start() -//} -// -//func ensureThridPltUserName(pltform webapi.IThirdPlatform, p *Player, amount int64, ip string) error { -// var err error -// err = pltform.ReqCreateAccount(p.SnId, p.Platform, p.Channel, p.GetIP()) -// if err != nil { -// if err != webapi.ErrNoCreated { -// logger.Logger.Errorf("Snid=%v Plt=%v ReqCreateAccount error:%v", p.SnId, pltform.GetPlatformBase().Name, err) -// } -// return err -// } -// return nil -//} - -//func enterThridPltUserName(pltform webapi.IThirdPlatform, p *Player, amount int64, gameId, ip string) (err error, url string) { -// // (snId int32, gameId string, clientIP string, platform, channel string, amount int64) -// err, url = pltform.ReqEnterGame(p.SnId, "", p.GetIP(), p.Platform, p.Channel, amount) -// if err != nil { -// if err != webapi.ErrNoCreated { -// logger.Logger.Errorf("Snid=%v Plt=%v ReqEnterGame error:%v", p.SnId, pltform.GetPlatformBase().Name, err) -// } -// return err, "" -// } -// return -//} - -// 离开三方 -//type CSLeaveThridGamePacketFactory struct { -//} -//type CSLeaveThridGameHandler struct { -//} -// -//func (this *CSLeaveThridGamePacketFactory) CreatePacket() interface{} { -// pack := &gamehall.CSLeaveThridGame{} -// return pack -//} -// -//func (this *CSLeaveThridGameHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { -// if _, ok := data.(*gamehall.CSLeaveThridGame); ok { -// p := PlayerMgrSington.GetPlayer(sid) -// if p == nil { -// logger.Logger.Warn("CSLeaveThridGameHandler p == nil") -// return nil -// } -// logger.Logger.Trace("CSLeaveThridGameHandler Process recv ", p.SnId) -// _LeaveTransferThird2SystemTask(p) -// pack := &gamehall.SCLeaveThridGame{} -// pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Sucess_Game -// p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_LEAVETHRIDGAME), pack) -// } -// return nil -//} - -// 刷新 -type CSThridBalanceRefreshPacketFactory struct { -} -type CSThridBalanceRefreshHandler struct { -} - -func (this *CSThridBalanceRefreshPacketFactory) CreatePacket() interface{} { - pack := &gamehall.CSThridGameBalanceUpdate{} - return pack -} -func (this *CSThridBalanceRefreshHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { - logger.Logger.Trace("CSThridBalanceRefreshHandler Process recv ", data) - if _, ok := data.(*gamehall.CSThridGameBalanceUpdate); ok { - p := PlayerMgrSington.GetPlayer(sid) - if p == nil { - logger.Logger.Warn("CSThridBalanceRefreshHandler p == nil") - return nil - } - //if p.scene != nil { - // logger.Logger.Tracef("player snid=%v CSThridBalanceRefreshHandler p.scene != nil return", p.SnId) - // return nil - //} - - //请求太快,不做处理,给API减轻一些压力 - if p.thridBalanceRefreshReqing { - logger.Logger.Warn("CSThridBalanceRefreshHandler client req too fast") - pack := &gamehall.SCThridGameBalanceUpdate{ - OpRetCode: gamehall.OpResultCode_Game_OPRC_Error_Game, - } - p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_THRIDGAMEBALANCEUPDATE), pack) - return nil - } - // p.thridBalanceRefreshReqing = true - RefreshTransferThird2SystemTask(p) - /* - gainway := common.GainWay_Transfer_Thrid2System - waitgroup := webapi.ThridPlatformMgrSington.AllPlatformCount() - isSucces := true - timeout := false - - webapi.ThridPlatformMgrSington.ThridPlatformMap.Range(func(key, value interface{}) bool { - plt := value.(webapi.IThirdPlatform) - if stateOk, exist := p.thirdBalanceRefreshMark[plt.GetPlatformBase().Name]; exist && stateOk { - waitgroup-- - if 0 == waitgroup { - statePack := &gamehall.SCThridGameBalanceUpdateState{} - pack := &gamehall.SCThridGameBalanceUpdate{} - pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Sucess_Game - p.thridBalanceReqIsSucces = true - statePack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Sucess_Game - p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_THRIDGAMEBALANCEUPDATESTATE), statePack) - pack.Coin = proto.Int64(p.Coin) - p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_THRIDGAMEBALANCEUPDATE), pack) - p.thridBalanceRefreshReqing = false - } - return true - } - var tsk task.Task - tsk = task.New(nil, - task.CallableWrapper(func(o *basic.Object) interface{} { - plt := tsk.GetEnv("plt").(webapi.IThirdPlatform) - tsk.PutEnv("timeStamp", time.Now().UnixNano()) - var err error - var coinLog *model.PayCoinLog - var coinlogex *model.CoinLog - var apiHasTransfer = false - remark := "刷新" + plt.GetPlatformBase().Name + "转出到系统" - thirdBalance := int64(0) - //allow := false - if plt == nil { - logger.Logger.Tracef("player snid=%v CSThridBalanceRefreshHandler plt == nil return", p.SnId) - return int64(-1) - } - - pfConfig := PlatformMgrSingleton.GetPlatform(p.Platform) - if pfConfig == nil { - return int64(0) - } - - if pfConfig.ThirdGameMerchant == nil || pfConfig.ThirdGameMerchant[int32(plt.GetPlatformBase().BaseGameID)] == 0 { - return int64(0) - } - - oper := plt.GetPlatformBase().Name + "2System" - err = ensureThridPltUserName(plt, p, thirdBalance, s.RemoteAddr()) - if err != nil { - if err == webapi.ErrNoCreated { - return int64(0) - } - logger.Logger.Tracef("player snid=%v at %v ensureThridPltUserName() err: %v", p.SnId, plt.GetPlatformBase().Name, err) - goto Rollback - } - //allow = plt.ReqIsAllowTransfer(p.SnId, p.Platform, p.Channel) - //if !allow { - // logger.Logger.Tracef("player snid=%v at %v is not allow Transfer", p.SnId, plt.GetPlatformBase().Name) - // goto Rollback - //} - err, thirdBalance = plt.ReqUserBalance(p.SnId, p.Platform, p.Channel, p.Ip) - if err != nil { - logger.Logger.Tracef("player snid=%v at %v plt.ReqUserBalance() err: %v", p.SnId, plt.GetPlatformBase().Name, err) - goto Rollback - } - if thirdBalance <= 0 { - return int64(0) - } - if plt.GetPlatformBase().TransferInteger { - thirdBalance = (thirdBalance / 100) * 100 - if thirdBalance <= 0 { - return int64(0) - } - } - err, timeout = plt.ReqTransfer(p.SnId, -thirdBalance, strconv.FormatInt(time.Now().UnixNano(), 10), p.Platform, p.Channel, p.Ip) - if err != nil || timeout { - logger.Logger.Tracef("player snid=%v at %v plt.ReqTransfer() err: %v", p.SnId, plt.GetPlatformBase().Name, err) - goto Rollback - } - apiHasTransfer = true - coinLog = model.NewPayCoinLog(time.Now().UnixNano(), int32(p.SnId), thirdBalance, int32(gainway), oper, model.PayCoinLogType_Coin, 0) - tsk.PutEnv("timeStamp", coinLog.TimeStamp) - err = model.InsertPayCoinLogs(p.Platform, coinLog) - if err != nil { - logger.Logger.Tracef("player snid=%v at %v model.InsertPayCoinLogs() err: %v", p.SnId, plt.GetPlatformBase().Name, err) - goto Rollback - } - coinlogex = model.NewCoinLogEx(p.SnId, thirdBalance, p.Coin+thirdBalance, p.SafeBoxCoin, 0, int32(gainway), - 0, oper, remark, p.Platform, p.Channel, p.BeUnderAgentCode, 0, p.PackageID, int32(plt.GetPlatformBase().VultGameID)) - err = model.InsertCoinLog(coinlogex) - if err != nil { - logger.Logger.Tracef("player snid=%v at %v model.InsertCoinLogs() err: %v", p.SnId, plt.GetPlatformBase().Name, err) - goto Rollback - } - tsk.PutEnv("plt", plt) - return thirdBalance - Rollback: - if coinLog != nil { - model.RemovePayCoinLog(p.Platform, coinLog.LogId) - } - if coinlogex != nil { - model.RemoveCoinLogOne(coinlogex.Platform, coinlogex.LogId) - } - if timeout { - logger.Logger.Errorf("player snid=%v CSThridBalanceRefreshHandler transfer %v to %v timeout!", p.SnId, -thirdBalance, plt.GetPlatformBase().Name) - return int64(-1) - } - if apiHasTransfer { - err, timeout = plt.ReqTransfer(p.SnId, thirdBalance, strconv.FormatInt(time.Now().UnixNano(), 10), p.Platform, p.Channel, p.Ip) - if timeout { - logger.Logger.Errorf("player snid=%v CSThridBalanceRefreshHandler transfer rollback %v to %v timeout!", p.SnId, thirdBalance, plt.GetPlatformBase().Name) - } - } - return int64(-1) - }), - task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) { - thirdBalance := data.(int64) - plt := tsk.GetEnv("plt").(webapi.IThirdPlatform) - timeStamp := tsk.GetEnv("timeStamp").(int64) - if thirdBalance < 0 { - isSucces = false - logger.Logger.Tracef("player snid=%v at platform=%v CSThridBalanceRefreshHandler third->system transfer fail", p.SnId, plt.GetPlatformBase().Name) - } else if thirdBalance > 0 { - p.thirdBalanceRefreshMark[plt.GetPlatformBase().Name] = true - p.Coin += thirdBalance - p.SetPayTs(timeStamp) - //ThirdPlatformMgrSington.AddThirdPlatformCoin(p.Platform, plt.GetPlatformBase().Tag, thirdBalance) - p.dirty = true - logger.Logger.Tracef("player snid=%v at platform=%v CSThridBalanceRefreshHandler third->system transfer succes", p.SnId, plt.GetPlatformBase().Name) - } else { - p.thirdBalanceRefreshMark[plt.GetPlatformBase().Name] = true - } - if atomic.AddInt32(&waitgroup, -1) == 0 { - p.diffData.Coin = -1 - p.SendDiffData() - statePack := &gamehall.SCThridGameBalanceUpdateState{} - pack := &gamehall.SCThridGameBalanceUpdate{} - if isSucces { - pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Sucess_Game - p.thridBalanceReqIsSucces = true - statePack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Sucess_Game - } else { - pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Error_Game - p.thridBalanceReqIsSucces = false - statePack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Error_Game - } - p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_THRIDGAMEBALANCEUPDATESTATE), statePack) - pack.Coin = proto.Int64(p.Coin) - p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_THRIDGAMEBALANCEUPDATE), pack) - p.thridBalanceRefreshReqing = false - logger.Logger.Tracef("SendToClient() player snid=%v at CSThridBalanceRefreshHandler() pack:%v", p.SnId, pack.String()) - } - }), "ThridAccount") - tsk.PutEnv("plt", value) - tsk.Start() - return true - })*/ - } - return nil -} - -// 刷新 第三方-->系统 -func RefreshTransferThird2SystemTask(p *Player) { - - /*if p.thrscene == 0 { - logger.Logger.Tracef("player snid=%v RefreshTransferThird2SystemTask p.thrscene == 0 return", p.SnId) - return - }*/ - - if p.thridBalanceRefreshReqing { - logger.Logger.Tracef("player snid=%v RefreshTransferThird2SystemTask p.thridBalanceRefreshReqing == true return", p.SnId) - return - } - gainway := common.GainWay_Transfer_Thrid2System - - amount := int64(0) - timeStamp := time.Now().UnixNano() - p.thridBalanceRefreshReqing = true - //timeout := false - webapi.ThridPlatformMgrSington.ThridPlatformMap.Range(func(key, value interface{}) bool { - // plt := value.(webapi.IThirdPlatform) - - var tsk task.Task - tsk = task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - // plt := webapi.ThridPlatformMgrSington.FindPlatformByPlatformBaseGameId(p.thrscene) - plt := tsk.GetEnv("plt").(webapi.IThirdPlatform) - if plt == nil { - logger.Logger.Tracef("player snid=%v RefreshTransferThird2SystemTask plt == nil return", p.SnId) - return errors.New("third->system plt is nil") - } - for i := int32(0); i < model.GameParamData.ThirdPltTransferMaxTry; { - var err error - var coinLog *model.PayCoinLog - var coinlogex *model.CoinLog - - oper := plt.GetPlatformBase().Name + "2System" - remark := "刷新" + plt.GetPlatformBase().Name + "转出到系统" - err, amount = plt.ReqUserBalance(p.SnId, p.Platform, p.Channel, p.Ip) - - // err, amount = plt.ReqLeaveGame(p.SnId, fmt.Sprintf("%v", p.thrscene), p.Ip, p.Platform, p.Channel) - if err != nil { - goto Rollback - } - if amount <= 0 { - return nil - } - if plt.GetPlatformBase().TransferInteger { - amount = (amount / 100) * 100 - if amount <= 0 { - return nil - } - } - timeStamp = time.Now().UnixNano() - - coinLog = model.NewPayCoinLog(timeStamp, int32(p.SnId), amount, int32(gainway), oper, model.PayCoinLogType_Coin, 0) - timeStamp = coinLog.TimeStamp - err = model.InsertPayCoinLogs(p.Platform, coinLog) - if err != nil { - goto Rollback - } - coinlogex = model.NewCoinLogEx(&model.CoinLogParam{ - Platform: p.Platform, - SnID: p.SnId, - Channel: p.Channel, - ChangeType: common.BillTypeCoin, - ChangeNum: amount, - RemainNum: p.Coin + amount, - Add: 0, - LogType: int32(gainway), - GameID: 0, - GameFreeID: 0, - BaseCoin: 0, - Operator: oper, - Remark: remark, - }) - err = model.InsertCoinLog(coinlogex) - if err != nil { - goto Rollback - } - return nil - Rollback: - if coinLog != nil { - model.RemovePayCoinLog(p.Platform, coinLog.LogId) - } - if coinlogex != nil { - model.RemoveCoinLogOne(coinlogex.Platform, coinlogex.LogId) - } - - logger.Logger.Tracef("player snid=%v third->system transfer rollback at try %v times", p.SnId, i+1) - i++ - if i < model.GameParamData.ThirdPltTransferMaxTry { - time.Sleep(time.Duration(model.GameParamData.ThirdPltTransferInterval) * time.Duration(time.Second)) - } - } - return errors.New("third->system transfer error >max try times!") - }), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) { - statePack := &gamehall.SCThridGameBalanceUpdateState{} - pack := &gamehall.SCThridGameBalanceUpdate{} - plt := tsk.GetEnv("plt").(webapi.IThirdPlatform) - if data != nil { - p.thirdBalanceRefreshMark[plt.GetPlatformBase().Name] = false - p.thridBalanceReqIsSucces = false - statePack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Error_Game - pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Error_Game - logger.Logger.Trace("SCThridAccountTransferHandler third->system transfer error:", data) - } else { - p.thridBalanceReqIsSucces = true - statePack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Sucess_Game - pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Sucess_Game - // p.thrscene = nil - p.Coin += amount - p.SetPayTs(timeStamp) - p.thirdBalanceRefreshMark[plt.GetPlatformBase().Name] = true - //ThirdPlatformMgrSington.AddThirdPlatformCoin(p.Platform, plt.GetPlatformBase().Tag, thirdBalance) - } - p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_THRIDGAMEBALANCEUPDATESTATE), statePack) - - p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_THRIDGAMEBALANCEUPDATESTATE), statePack) - pack.Coin = proto.Int64(p.Coin) - p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_THRIDGAMEBALANCEUPDATE), pack) - p.dirty = true - - //这个地方虽然说拉取失败,但是为了不影响玩家玩其他的游戏,还是可以进入其它场景 - //后面玩家自己通过手动刷新余额 - if p.thrscene != 0 { - p.thrscene = 0 - p.scene = nil - } - p.thridBalanceRefreshReqing = false - p.diffData.Coin = -1 //强制更新金币 - p.SendDiffData() - return - }), "ThridAccountRefresh") - tsk.PutEnv("plt", value) - tsk.Start() - return true - }) -} - type CSQueryRoomInfoPacketFactory struct { } type CSQueryRoomInfoHandler struct { @@ -1324,30 +421,6 @@ func (this *CSQueryRoomInfoHandler) ProcessLocalGame(s *netlib.Session, packetid return nil } -type CSLotteryLogPacketFactory struct { -} -type CSLotteryLogHandler struct { -} - -func (this *CSLotteryLogPacketFactory) CreatePacket() interface{} { - pack := &gamehall.CSLotteryLog{} - return pack -} - -func (this *CSLotteryLogHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { - logger.Logger.Trace("CSLotteryLogHandler Process recv ", data) - //if msg, ok := data.(*gamehall.CSLotteryLog); ok { - // p := PlayerMgrSington.GetPlayer(sid) - // if p == nil { - // logger.Logger.Warn("CSLotteryLogHandler p == nil") - // return nil - // } - // - // LotteryMgrSington.FetchLotteryLog(p, msg.GetGameFreeId()) - //} - return nil -} - // 获取指定游戏配置 包括分场信息 type CSGetGameConfigPacketFactory struct { } @@ -1754,7 +827,7 @@ func (this *CSCreateRoomHandler) ProcessLocalGame(s *netlib.Session, packetid in var gameSite int32 var csp *CoinScenePool var baseScore int32 - var gps *webapi_proto.GameFree + var gps *webapiproto.GameFree //根据携带金额取可创房间 DB_Createroom arrs := srvdata.PBDB_CreateroomMgr.Datas.Arr @@ -1907,7 +980,7 @@ func (this *CSCreateRoomHandler) ProcessThirteen(s *netlib.Session, packetid int var baseScore = msg.GetBaseCoin() var sp ScenePolicy var gamefreeId = msg.GetId() - var gps *webapi_proto.GameFree + var gps *webapiproto.GameFree var maxPlayerNum = int(msg.GetMaxPlayerNum()) var csp *CoinScenePool var roomId int @@ -2157,27 +1230,9 @@ func init() { // 返回房间 common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_RETURNROOM), &CSReturnRoomHandler{}) netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_RETURNROOM), &CSReturnRoomPacketFactory{}) - - common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_JOINGAME), &CSJoinGameHandler{}) - netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_JOINGAME), &CSJoinGamePacketFactory{}) - - common.RegisterHandler(int(player.PlayerPacketID_PACKET_CS_GETDATALOG), &CSGetDataLogHandler{}) - netlib.RegisterFactory(int(player.PlayerPacketID_PACKET_CS_GETDATALOG), &CSGetDataLogPacketFactory{}) - - //common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_ENTERTHRIDGAME), &CSEnterThridGameHandler{}) - //netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_ENTERTHRIDGAME), &CSEnterThridGamePacketFactory{}) - - //common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_LEAVETHRIDGAME), &CSLeaveThridGameHandler{}) - //netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_LEAVETHRIDGAME), &CSLeaveThridGamePacketFactory{}) - - //common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_THRIDGAMEBALANCEUPDATE), &CSThridBalanceRefreshHandler{}) - //netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_THRIDGAMEBALANCEUPDATE), &CSThridBalanceRefreshPacketFactory{}) - - //common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_GETPRIVATEROOMHISTORY), &CSGetPrivateRoomHistoryHandler{}) - //netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_GETPRIVATEROOMHISTORY), &CSGetPrivateRoomHistoryPacketFactory{}) - - common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_LOTTERYLOG), &CSLotteryLogHandler{}) - netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_LOTTERYLOG), &CSLotteryLogPacketFactory{}) + //观众坐下 + common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_AUDIENCESIT), &CSAudienceSitHandler{}) + netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_AUDIENCESIT), &CSAudienceSitPacketFactory{}) //获取指定游戏配置 包括分场信息 common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_GETGAMECONFIG), &CSGetGameConfigHandler{}) netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_GETGAMECONFIG), &CSGetGameConfigPacketFactory{}) @@ -2196,9 +1251,6 @@ func init() { //查询公共房间列表 common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_QUERYROOMINFO), &CSQueryRoomInfoHandler{}) netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_QUERYROOMINFO), &CSQueryRoomInfoPacketFactory{}) - //观众坐下 - common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_AUDIENCESIT), &CSAudienceSitHandler{}) - netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_AUDIENCESIT), &CSAudienceSitPacketFactory{}) //我的游戏信息及平台公告 common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_COMNOTICE), &CSRecordAndNoticeHandler{}) netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_COMNOTICE), &CSRecordAndNoticePacketFactory{}) diff --git a/worldsrv/player.go b/worldsrv/player.go index 9d9f81e..883a4d0 100644 --- a/worldsrv/player.go +++ b/worldsrv/player.go @@ -1594,7 +1594,7 @@ func (this *Player) DgGameLogout() { } func (this *Player) ThirdGameLogout() { - _LeaveTransferThird2SystemTask(this) + } func (this *Player) IsOnLine() bool {