Commit 285f6717 authored by pengjun's avatar pengjun Committed by vipwzw

pokerbull add time log

parent 9b5c0ca6
......@@ -16,6 +16,7 @@ import (
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
pkt "github.com/33cn/plugin/plugin/dapp/pokerbull/types"
"time"
)
// Action 斗牛action结构
......@@ -484,7 +485,7 @@ func (action *Action) newGame(gameID string, start *pkt.PBGameStart) (*pkt.Poker
game = &pkt.PokerBull{
GameId: gameID,
Status: pkt.PBGameActionStart,
StartTime: action.blocktime,
StartTime: time.Unix(action.blocktime, 0).Format("2006-01-02 15:04:05"),
StartTxHash: gameID,
Value: start.GetValue(),
Poker: NewPoker(),
......@@ -497,7 +498,7 @@ func (action *Action) newGame(gameID string, start *pkt.PBGameStart) (*pkt.Poker
}
Shuffle(game.Poker, action.blocktime) //洗牌
logger.Debug(fmt.Sprintf("Start a new game %s for player %s", game.GameId, action.fromaddr))
logger.Info(fmt.Sprintf("Create a new game %s for player %s", game.GameId, action.fromaddr))
return game, nil
}
......@@ -560,7 +561,7 @@ func (action *Action) GameStart(start *pkt.PBGameStart) (*types.Receipt, error)
var logs []*types.ReceiptLog
var kv []*types.KeyValue
logger.Debug(fmt.Sprintf("Pokerbull game start for %s", action.fromaddr))
logger.Info(fmt.Sprintf("Pokerbull game match for %s", action.fromaddr))
if start.PlayerNum > pkt.MaxPlayerNum {
logger.Error("GameStart", "addr", action.fromaddr, "execaddr", action.execaddr,
"err", fmt.Sprintf("The maximum player number is %d", pkt.MaxPlayerNum))
......@@ -599,7 +600,7 @@ func (action *Action) GameStart(start *pkt.PBGameStart) (*types.Receipt, error)
return nil, err
}
}
logger.Debug(fmt.Sprintf("Match a new game %s for player %s", game.GameId, action.fromaddr))
logger.Info(fmt.Sprintf("Match a new game %s for player %s", game.GameId, action.fromaddr))
}
//发牌随机数取txhash
......@@ -613,11 +614,12 @@ func (action *Action) GameStart(start *pkt.PBGameStart) (*types.Receipt, error)
Address: action.fromaddr,
TxHash: txrng,
Ready: false,
MatchTime:time.Unix(action.blocktime, 0).Format("2006-01-02 15:04:05"),
})
// 如果人数达标,则发牌计算斗牛结果
if len(game.Players) == int(game.PlayerNum) {
logger.Debug(fmt.Sprintf("Game start: %s", game.GameId))
logger.Info(fmt.Sprintf("Game starting: %s round: %d", game.GameId, game.Round))
logsH, kvH, err := action.settleAccount(action.fromaddr, game)
if err != nil {
return nil, err
......@@ -631,7 +633,7 @@ func (action *Action) GameStart(start *pkt.PBGameStart) (*types.Receipt, error)
game.PreStatus = pkt.PBGameActionStart
game.IsWaiting = false
} else {
logger.Debug(fmt.Sprintf("Game waiting: %s", game.GameId))
logger.Info(fmt.Sprintf("Game waiting: %s round: %d", game.GameId, game.Round))
receipt, err := action.coinsAccount.ExecFrozen(action.fromaddr, action.execaddr, start.GetValue()*PokerbullLeverageMax) //冻结子账户资金, 最后一位玩家不需要冻结
if err != nil {
logger.Error("GameCreate.ExecFrozen", "addr", action.fromaddr, "execaddr", action.execaddr, "amount", start.GetValue(), "err", err.Error())
......@@ -683,7 +685,7 @@ func (action *Action) GameContinue(pbcontinue *pkt.PBGameContinue) (*types.Recei
pbcontinue.GetGameId())
return nil, err
}
logger.Debug(fmt.Sprintf("Pokerbull game %s continue for %s", game.GameId, action.fromaddr))
logger.Info(fmt.Sprintf("Continue pokerbull game %s from %s", game.GameId, action.fromaddr))
// 检查余额,庄家检查闲家数量倍数的资金
checkValue := game.GetValue() * PokerbullLeverageMax
......@@ -716,9 +718,10 @@ func (action *Action) GameContinue(pbcontinue *pkt.PBGameContinue) (*types.Recei
}
pbplayer.TxHash = txrng
pbplayer.Ready = true
pbplayer.MatchTime = time.Unix(action.blocktime, 0).Format("2006-01-02 15:04:05")
if getReadyPlayerNum(game.Players) == int(game.PlayerNum) {
logger.Debug(fmt.Sprintf("Game start: %s", game.GameId))
logger.Info(fmt.Sprintf("Game starting: %s round: %d", game.GameId, game.Round))
logsH, kvH, err := action.settleAccount(action.fromaddr, game)
if err != nil {
return nil, err
......@@ -730,7 +733,7 @@ func (action *Action) GameContinue(pbcontinue *pkt.PBGameContinue) (*types.Recei
game.IsWaiting = false
game.PreStatus = pkt.PBGameActionContinue
} else {
logger.Debug(fmt.Sprintf("Game waiting: %s", game.GameId))
logger.Info(fmt.Sprintf("Game waiting: %s round: %d", game.GameId))
// 回合数加一次
if !game.IsWaiting {
game.Round++
......@@ -799,7 +802,7 @@ func (action *Action) GameQuit(pbend *pkt.PBGameQuit) (*types.Receipt, error) {
game.Status = pkt.PBGameActionQuit
game.PrevIndex = game.Index
game.Index = action.getIndex(game)
game.QuitTime = action.blocktime
game.QuitTime = time.Unix(action.blocktime, 0).Format("2006-01-02 15:04:05")
game.QuitTxHash = common.ToHex(action.txhash)
receiptLog := action.GetReceiptLog(game)
......
......@@ -6,7 +6,7 @@ package types;
message PokerBull {
string gameId = 1; //默认是由创建这局游戏的txHash作为gameId
int32 status = 2; // Start 1 -> Continue 2 -> Quit 3
int64 startTime = 3; //开始时间
string startTime = 3; //开始时间
string startTxHash = 4; //游戏启动交易hash
int64 value = 5; //赌注
PBPoker poker = 6; //扑克牌
......@@ -15,7 +15,7 @@ message PokerBull {
repeated PBResult results = 9; //游戏结果集
int64 index = 10; //索引
int64 prevIndex = 11; //上级索引
int64 quitTime = 12; //游戏结束时间
string quitTime = 12; //游戏结束时间
string quitTxHash = 13; //游戏结束交易hash
string dealerAddr = 14; //下局庄家地址
bool isWaiting = 15; //游戏是否处于等待状态
......@@ -30,6 +30,7 @@ message PBHand {
string address = 3; //玩家地址
bool isWin = 4; //是否赢庄家
int32 leverage = 5; //赌注倍数
string roundTime = 6; //本回合开始时间
}
//玩家
......@@ -37,7 +38,8 @@ message PBPlayer {
repeated PBHand hands = 1; //历史发牌和斗牛结果
string address = 2; //玩家地址
int64 txHash = 3; //发牌随机数因子txhash的整数格式
bool ready = 4; // continue状态下,是否ready
bool ready = 4; //continue状态下,是否ready
string matchTime = 5; //玩家匹配时间
}
//本局游戏结果
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment