Commit 0c401767 authored by pengjun's avatar pengjun Committed by vipwzw

pokerbull代码的linter告警整改

parent f2a39b71
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// PokerBullCmd 斗牛游戏命令行
func PokerBullCmd() *cobra.Command { func PokerBullCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "pokerbull", Use: "pokerbull",
...@@ -31,6 +32,7 @@ func PokerBullCmd() *cobra.Command { ...@@ -31,6 +32,7 @@ func PokerBullCmd() *cobra.Command {
return cmd return cmd
} }
// PokerBullStartRawTxCmd 生成开始交易命令行
func PokerBullStartRawTxCmd() *cobra.Command { func PokerBullStartRawTxCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "start", Use: "start",
...@@ -69,6 +71,7 @@ func pokerbullStart(cmd *cobra.Command, args []string) { ...@@ -69,6 +71,7 @@ func pokerbullStart(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
// PokerBullContinueRawTxCmd 生成继续游戏命令行
func PokerBullContinueRawTxCmd() *cobra.Command { func PokerBullContinueRawTxCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "continue", Use: "continue",
...@@ -101,6 +104,7 @@ func pokerbullContinue(cmd *cobra.Command, args []string) { ...@@ -101,6 +104,7 @@ func pokerbullContinue(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
// PokerBullQuitRawTxCmd 生成继续游戏命令行
func PokerBullQuitRawTxCmd() *cobra.Command { func PokerBullQuitRawTxCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "quit", Use: "quit",
...@@ -133,6 +137,7 @@ func pokerbullQuit(cmd *cobra.Command, args []string) { ...@@ -133,6 +137,7 @@ func pokerbullQuit(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
// PokerBullQueryResultRawTxCmd 查询命令行
func PokerBullQueryResultRawTxCmd() *cobra.Command { func PokerBullQueryResultRawTxCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "query", Use: "query",
...@@ -171,22 +176,22 @@ func pokerbullQuery(cmd *cobra.Command, args []string) { ...@@ -171,22 +176,22 @@ func pokerbullQuery(cmd *cobra.Command, args []string) {
} }
params.Payload = req params.Payload = req
if gameID != "" { if gameID != "" {
params.FuncName = pkt.FuncName_QueryGameById params.FuncName = pkt.FuncNameQueryGameById
var res pkt.ReplyPBGame var res pkt.ReplyPBGame
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res) ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run() ctx.Run()
} else if address != "" { } else if address != "" {
params.FuncName = pkt.FuncName_QueryGameByAddr params.FuncName = pkt.FuncNameQueryGameByAddr
var res pkt.PBGameRecords var res pkt.PBGameRecords
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res) ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run() ctx.Run()
} else if statusStr != "" { } else if statusStr != "" {
params.FuncName = pkt.FuncName_QueryGameByStatus params.FuncName = pkt.FuncNameQueryGameByStatus
var res pkt.PBGameRecords var res pkt.PBGameRecords
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res) ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run() ctx.Run()
} else if gameIDs != "" { } else if gameIDs != "" {
params.FuncName = pkt.FuncName_QueryGameListByIds params.FuncName = pkt.FuncNameQueryGameListByIds
var gameIDsS []string var gameIDsS []string
gameIDsS = append(gameIDsS, gameIDs) gameIDsS = append(gameIDsS, gameIDs)
gameIDsS = append(gameIDsS, gameIDs) gameIDsS = append(gameIDsS, gameIDs)
......
...@@ -9,16 +9,19 @@ import ( ...@@ -9,16 +9,19 @@ import (
pkt "github.com/33cn/plugin/plugin/dapp/pokerbull/types" pkt "github.com/33cn/plugin/plugin/dapp/pokerbull/types"
) )
// Exec_Start 开始游戏交易执行
func (c *PokerBull) Exec_Start(payload *pkt.PBGameStart, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *PokerBull) Exec_Start(payload *pkt.PBGameStart, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(c, tx, index) action := NewAction(c, tx, index)
return action.GameStart(payload) return action.GameStart(payload)
} }
// Exec_Continue 继续游戏交易执行
func (c *PokerBull) Exec_Continue(payload *pkt.PBGameContinue, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *PokerBull) Exec_Continue(payload *pkt.PBGameContinue, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(c, tx, index) action := NewAction(c, tx, index)
return action.GameContinue(payload) return action.GameContinue(payload)
} }
// Exec_Quit 退出游戏交易执行
func (c *PokerBull) Exec_Quit(payload *pkt.PBGameQuit, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *PokerBull) Exec_Quit(payload *pkt.PBGameQuit, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(c, tx, index) action := NewAction(c, tx, index)
return action.GameQuit(payload) return action.GameQuit(payload)
......
...@@ -42,14 +42,17 @@ func (g *PokerBull) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDB ...@@ -42,14 +42,17 @@ func (g *PokerBull) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDB
return dbSet, nil return dbSet, nil
} }
// ExecDelLocal_Start 开始游戏交易回滚
func (g *PokerBull) ExecDelLocal_Start(payload *pkt.PBGameStart, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *PokerBull) ExecDelLocal_Start(payload *pkt.PBGameStart, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execDelLocal(receiptData) return g.execDelLocal(receiptData)
} }
// ExecDelLocal_Continue 继续游戏交易回滚
func (g *PokerBull) ExecDelLocal_Continue(payload *pkt.PBGameContinue, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *PokerBull) ExecDelLocal_Continue(payload *pkt.PBGameContinue, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execDelLocal(receiptData) return g.execDelLocal(receiptData)
} }
// ExecDelLocal_Quit 退出游戏交易回滚
func (g *PokerBull) ExecDelLocal_Quit(payload *pkt.PBGameQuit, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *PokerBull) ExecDelLocal_Quit(payload *pkt.PBGameQuit, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execDelLocal(receiptData) return g.execDelLocal(receiptData)
} }
...@@ -73,14 +73,17 @@ func (c *PokerBull) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, er ...@@ -73,14 +73,17 @@ func (c *PokerBull) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, er
return dbSet, nil return dbSet, nil
} }
// ExecLocal_Start 开始游戏交易local执行
func (c *PokerBull) ExecLocal_Start(payload *pkt.PBGameStart, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (c *PokerBull) ExecLocal_Start(payload *pkt.PBGameStart, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return c.execLocal(receiptData) return c.execLocal(receiptData)
} }
// ExecLocal_Continue 继续游戏交易local执行
func (c *PokerBull) ExecLocal_Continue(payload *pkt.PBGameContinue, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (c *PokerBull) ExecLocal_Continue(payload *pkt.PBGameContinue, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return c.execLocal(receiptData) return c.execLocal(receiptData)
} }
// ExecLocal_Quit 退出游戏交易local执行
func (c *PokerBull) ExecLocal_Quit(payload *pkt.PBGameQuit, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (c *PokerBull) ExecLocal_Quit(payload *pkt.PBGameQuit, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return c.execLocal(receiptData) return c.execLocal(receiptData)
} }
...@@ -12,58 +12,67 @@ import ( ...@@ -12,58 +12,67 @@ import (
"github.com/33cn/plugin/plugin/dapp/pokerbull/types" "github.com/33cn/plugin/plugin/dapp/pokerbull/types"
) )
var POKER_CARD_NUM = 52 //4 * 13 不带大小王 // 牌数,4 * 13 不带大小王
var COLOR_OFFSET uint32 = 8 var PokerCardNum = 52
var COLOR_BIT_MAST = 0xFF
var COLOR_NUM = 4 // 牌花色偏移
var CARD_NUM_PER_COLOR = 13 var ColorOffset uint32 = 8
var CARD_NUM_PER_GAME = 5
// 牌花色bit掩码
var ColorBitMask = 0xFF
// 每种花色的牌数
var CardNumPerColor = 13
// 一手牌的牌数
var CardNumPerGame = 5
const ( const (
POKERBULL_RESULT_X1 = 1 PokerbullResultX1 = 1
POKERBULL_RESULT_X2 = 2 PokerbullResultX2 = 2
POKERBULL_RESULT_X3 = 3 PokerbullResultX3 = 3
POKERBULL_RESULT_X4 = 4 PokerbullResultX4 = 4
POKERBULL_RESULT_X5 = 5 PokerbullResultX5 = 5
POKERBULL_LEVERAGE_MAX = POKERBULL_RESULT_X1 PokerbullLeverageMax = PokerbullResultX1
) )
// NewPoker 创建一副牌
func NewPoker() *types.PBPoker { func NewPoker() *types.PBPoker {
poker := new(types.PBPoker) poker := new(types.PBPoker)
poker.Cards = make([]int32, POKER_CARD_NUM) poker.Cards = make([]int32, PokerCardNum)
poker.Pointer = int32(POKER_CARD_NUM - 1) poker.Pointer = int32(PokerCardNum - 1)
for i := 0; i < POKER_CARD_NUM; i++ { for i := 0; i < PokerCardNum; i++ {
color := i / CARD_NUM_PER_COLOR color := i / CardNumPerColor
num := i%CARD_NUM_PER_COLOR + 1 num := i%CardNumPerColor + 1
poker.Cards[i] = int32(color<<COLOR_OFFSET + num) poker.Cards[i] = int32(color<<ColorOffset + num)
} }
return poker return poker
} }
// 洗牌 // Shuffle 洗牌
func Shuffle(poker *types.PBPoker, rng int64) { func Shuffle(poker *types.PBPoker, rng int64) {
rndn := rand.New(rand.NewSource(rng)) rndn := rand.New(rand.NewSource(rng))
for i := 0; i < POKER_CARD_NUM; i++ { for i := 0; i < PokerCardNum; i++ {
idx := rndn.Intn(POKER_CARD_NUM - 1) idx := rndn.Intn(PokerCardNum - 1)
tmpV := poker.Cards[idx] tmpV := poker.Cards[idx]
poker.Cards[idx] = poker.Cards[POKER_CARD_NUM-i-1] poker.Cards[idx] = poker.Cards[PokerCardNum-i-1]
poker.Cards[POKER_CARD_NUM-i-1] = tmpV poker.Cards[PokerCardNum-i-1] = tmpV
} }
poker.Pointer = int32(POKER_CARD_NUM - 1) poker.Pointer = int32(PokerCardNum - 1)
} }
// 发牌 // Deal 发牌
func Deal(poker *types.PBPoker, rng int64) []int32 { func Deal(poker *types.PBPoker, rng int64) []int32 {
if poker.Pointer < int32(CARD_NUM_PER_GAME) { if poker.Pointer < int32(CardNumPerGame) {
logger.Error(fmt.Sprintf("Wait to be shuffled: deal cards [%d], left [%d]", CARD_NUM_PER_GAME, poker.Pointer+1)) logger.Error(fmt.Sprintf("Wait to be shuffled: deal cards [%d], left [%d]", CardNumPerGame, poker.Pointer+1))
Shuffle(poker, rng+int64(poker.Cards[0])) Shuffle(poker, rng+int64(poker.Cards[0]))
} }
rndn := rand.New(rand.NewSource(rng)) rndn := rand.New(rand.NewSource(rng))
res := make([]int32, CARD_NUM_PER_GAME) res := make([]int32, CardNumPerGame)
for i := 0; i < CARD_NUM_PER_GAME; i++ { for i := 0; i < CardNumPerGame; i++ {
idx := rndn.Intn(int(poker.Pointer)) idx := rndn.Intn(int(poker.Pointer))
tmpV := poker.Cards[poker.Pointer] tmpV := poker.Cards[poker.Pointer]
res[i] = poker.Cards[idx] res[i] = poker.Cards[idx]
...@@ -75,7 +84,7 @@ func Deal(poker *types.PBPoker, rng int64) []int32 { ...@@ -75,7 +84,7 @@ func Deal(poker *types.PBPoker, rng int64) []int32 {
return res return res
} }
// 计算斗牛结果 // Result 计算斗牛结果
func Result(cards []int32) int32 { func Result(cards []int32) int32 {
temp := 0 temp := 0
r := -1 //是否有牛标志 r := -1 //是否有牛标志
...@@ -125,45 +134,45 @@ func Result(cards []int32) int32 { ...@@ -125,45 +134,45 @@ func Result(cards []int32) int32 {
return int32(result[0]) return int32(result[0])
} }
// 计算结果倍数 // Leverage 计算结果倍数
func Leverage(hand *types.PBHand) int32 { func Leverage(hand *types.PBHand) int32 {
result := hand.Result result := hand.Result
// 小牛 [1, 6] // 小牛 [1, 6]
if result < 7 { if result < 7 {
return POKERBULL_RESULT_X1 return PokerbullResultX1
} }
// 大牛 [7, 9] // 大牛 [7, 9]
if result >= 7 && result < 10 { if result >= 7 && result < 10 {
return POKERBULL_RESULT_X2 return PokerbullResultX2
} }
var flowers = 0 var flowers = 0
if result == 10 { if result == 10 {
for _, card := range hand.Cards { for _, card := range hand.Cards {
if (int(card) & COLOR_BIT_MAST) > 10 { if (int(card) & ColorBitMask) > 10 {
flowers++ flowers++
} }
} }
// 牛牛 // 牛牛
if flowers < 4 { if flowers < 4 {
return POKERBULL_RESULT_X3 return PokerbullResultX3
} }
// 四花 // 四花
if flowers == 4 { if flowers == 4 {
return POKERBULL_RESULT_X4 return PokerbullResultX4
} }
// 五花 // 五花
if flowers == 5 { if flowers == 5 {
return POKERBULL_RESULT_X5 return PokerbullResultX5
} }
} }
return POKERBULL_RESULT_X1 return PokerbullResultX1
} }
type pokerCard struct { type pokerCard struct {
...@@ -193,14 +202,15 @@ func (p colorCardSlice) Less(i, j int) bool { ...@@ -193,14 +202,15 @@ func (p colorCardSlice) Less(i, j int) bool {
func newcolorCard(a []int32) colorCardSlice { func newcolorCard(a []int32) colorCardSlice {
var cardS []*pokerCard var cardS []*pokerCard
for i := 0; i < len(a); i++ { for i := 0; i < len(a); i++ {
num := int(a[i]) & COLOR_BIT_MAST num := int(a[i]) & ColorBitMask
color := int(a[i]) >> COLOR_OFFSET color := int(a[i]) >> ColorOffset
cardS = append(cardS, &pokerCard{num, color}) cardS = append(cardS, &pokerCard{num, color})
} }
return cardS return cardS
} }
// CompareResult 两手牌比较结果
func CompareResult(i, j *types.PBHand) bool { func CompareResult(i, j *types.PBHand) bool {
if i.Result < j.Result { if i.Result < j.Result {
return true return true
...@@ -213,6 +223,7 @@ func CompareResult(i, j *types.PBHand) bool { ...@@ -213,6 +223,7 @@ func CompareResult(i, j *types.PBHand) bool {
return false return false
} }
// Compare 比较两手牌的斗牛结果
func Compare(a []int32, b []int32) bool { func Compare(a []int32, b []int32) bool {
cardA := newcolorCard(a) cardA := newcolorCard(a)
cardB := newcolorCard(b) cardB := newcolorCard(b)
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
var logger = log.New("module", "execs.pokerbull") var logger = log.New("module", "execs.pokerbull")
// Init 执行器初始化
func Init(name string, sub []byte) { func Init(name string, sub []byte) {
drivers.Register(newPBGame().GetName(), newPBGame, types.GetDappFork(driverName, "Enable")) drivers.Register(newPBGame().GetName(), newPBGame, types.GetDappFork(driverName, "Enable"))
} }
...@@ -26,6 +27,7 @@ func init() { ...@@ -26,6 +27,7 @@ func init() {
ety.InitFuncList(types.ListMethod(&PokerBull{})) ety.InitFuncList(types.ListMethod(&PokerBull{}))
} }
// PokerBull 斗牛执行器结构
type PokerBull struct { type PokerBull struct {
drivers.DriverBase drivers.DriverBase
} }
...@@ -37,10 +39,12 @@ func newPBGame() drivers.Driver { ...@@ -37,10 +39,12 @@ func newPBGame() drivers.Driver {
return t return t
} }
// GetName 获取斗牛执行器名
func GetName() string { func GetName() string {
return newPBGame().GetName() return newPBGame().GetName()
} }
// GetDriverName 获取斗牛执行器名
func (g *PokerBull) GetDriverName() string { func (g *PokerBull) GetDriverName() string {
return pkt.PokerBullX return pkt.PokerBullX
} }
...@@ -118,11 +122,11 @@ func delPBGameAddrIndexKey(addr string, index int64) *types.KeyValue { ...@@ -118,11 +122,11 @@ func delPBGameAddrIndexKey(addr string, index int64) *types.KeyValue {
return kv return kv
} }
func addPBGameStatusAndPlayer(status int32, player int32, value, index int64, gameId string) *types.KeyValue { func addPBGameStatusAndPlayer(status int32, player int32, value, index int64, gameID string) *types.KeyValue {
kv := &types.KeyValue{} kv := &types.KeyValue{}
kv.Key = calcPBGameStatusAndPlayerKey(status, player, value, index) kv.Key = calcPBGameStatusAndPlayerKey(status, player, value, index)
record := &pkt.PBGameIndexRecord{ record := &pkt.PBGameIndexRecord{
GameId: gameId, GameId: gameID,
Index: index, Index: index,
} }
kv.Value = types.Encode(record) kv.Value = types.Encode(record)
......
...@@ -19,15 +19,16 @@ import ( ...@@ -19,15 +19,16 @@ import (
) )
const ( const (
// ListDESC 降序
ListDESC = int32(0) ListDESC = int32(0)
ListASC = int32(1)
DefaultCount = int32(20) //默认一次取多少条记录 DefaultCount = int32(20) //默认一次取多少条记录
MAX_PLAYER_NUM = 5 MaxPlayerNum = 5
MIN_PLAY_VALUE = 10 * types.Coin MinPlayValue = 10 * types.Coin
DefaultStyle = pkt.PlayStyleDefault DefaultStyle = pkt.PlayStyleDefault
) )
// Action 斗牛action结构
type Action struct { type Action struct {
coinsAccount *account.DB coinsAccount *account.DB
db dbm.KV db dbm.KV
...@@ -39,7 +40,7 @@ type Action struct { ...@@ -39,7 +40,7 @@ type Action struct {
localDB dbm.Lister localDB dbm.Lister
index int index int
} }
// NewAction 创建action
func NewAction(pb *PokerBull, tx *types.Transaction, index int) *Action { func NewAction(pb *PokerBull, tx *types.Transaction, index int) *Action {
hash := tx.Hash() hash := tx.Hash()
fromaddr := tx.From() fromaddr := tx.From()
...@@ -48,10 +49,11 @@ func NewAction(pb *PokerBull, tx *types.Transaction, index int) *Action { ...@@ -48,10 +49,11 @@ func NewAction(pb *PokerBull, tx *types.Transaction, index int) *Action {
pb.GetBlockTime(), pb.GetHeight(), dapp.ExecAddress(string(tx.Execer)), pb.GetLocalDB(), index} pb.GetBlockTime(), pb.GetHeight(), dapp.ExecAddress(string(tx.Execer)), pb.GetLocalDB(), index}
} }
// CheckExecAccountBalance 检查账户余额
func (action *Action) CheckExecAccountBalance(fromAddr string, ToFrozen, ToActive int64) bool { func (action *Action) CheckExecAccountBalance(fromAddr string, ToFrozen, ToActive int64) bool {
// 赌注为零,按照最小赌注冻结 // 赌注为零,按照最小赌注冻结
if ToFrozen == 0 { if ToFrozen == 0 {
ToFrozen = MIN_PLAY_VALUE ToFrozen = MinPlayValue
} }
acc := action.coinsAccount.LoadExecAccount(fromAddr, action.execaddr) acc := action.coinsAccount.LoadExecAccount(fromAddr, action.execaddr)
...@@ -61,6 +63,7 @@ func (action *Action) CheckExecAccountBalance(fromAddr string, ToFrozen, ToActiv ...@@ -61,6 +63,7 @@ func (action *Action) CheckExecAccountBalance(fromAddr string, ToFrozen, ToActiv
return false return false
} }
// Key 获取key值
func Key(id string) (key []byte) { func Key(id string) (key []byte) {
key = append(key, []byte("mavl-"+types.ExecName(pkt.PokerBullX)+"-")...) key = append(key, []byte("mavl-"+types.ExecName(pkt.PokerBullX)+"-")...)
key = append(key, []byte(id)...) key = append(key, []byte(id)...)
...@@ -83,19 +86,7 @@ func readGame(db dbm.KV, id string) (*pkt.PokerBull, error) { ...@@ -83,19 +86,7 @@ func readGame(db dbm.KV, id string) (*pkt.PokerBull, error) {
return &game, nil return &game, nil
} }
//安全批量查询方式,防止因为脏数据导致查询接口奔溃 // Infos 获取gameinfo
func GetGameList(db dbm.KV, values []string) []*pkt.PokerBull {
var games []*pkt.PokerBull
for _, value := range values {
game, err := readGame(db, value)
if err != nil {
continue
}
games = append(games, game)
}
return games
}
func Infos(db dbm.KV, infos *pkt.QueryPBGameInfos) (types.Message, error) { func Infos(db dbm.KV, infos *pkt.QueryPBGameInfos) (types.Message, error) {
var games []*pkt.PokerBull var games []*pkt.PokerBull
for i := 0; i < len(infos.GameIds); i++ { for i := 0; i < len(infos.GameIds); i++ {
...@@ -189,6 +180,7 @@ func (action *Action) getIndex(game *pkt.PokerBull) int64 { ...@@ -189,6 +180,7 @@ func (action *Action) getIndex(game *pkt.PokerBull) int64 {
return action.height*types.MaxTxsPerBlock + int64(action.index) return action.height*types.MaxTxsPerBlock + int64(action.index)
} }
// GetReceiptLog 获取receipt日志
func (action *Action) GetReceiptLog(game *pkt.PokerBull) *types.ReceiptLog { func (action *Action) GetReceiptLog(game *pkt.PokerBull) *types.ReceiptLog {
log := &types.ReceiptLog{} log := &types.ReceiptLog{}
r := &pkt.ReceiptPBGame{} r := &pkt.ReceiptPBGame{}
...@@ -343,7 +335,7 @@ func (action *Action) settleDealerAccount(lastAddress string, game *pkt.PokerBul ...@@ -343,7 +335,7 @@ func (action *Action) settleDealerAccount(lastAddress string, game *pkt.PokerBul
for _, hand := range result.Hands { for _, hand := range result.Hands {
// 最后一名玩家没有冻结 // 最后一名玩家没有冻结
if hand.Address != lastAddress { if hand.Address != lastAddress {
receipt, err := action.coinsAccount.ExecActive(hand.Address, action.execaddr, game.GetValue()*POKERBULL_LEVERAGE_MAX) receipt, err := action.coinsAccount.ExecActive(hand.Address, action.execaddr, game.GetValue()*PokerbullLeverageMax)
if err != nil { if err != nil {
logger.Error("GameSettleDealer.ExecActive", "addr", hand.Address, "execaddr", action.execaddr, "amount", game.GetValue(), logger.Error("GameSettleDealer.ExecActive", "addr", hand.Address, "execaddr", action.execaddr, "amount", game.GetValue(),
"err", err) "err", err)
...@@ -391,10 +383,10 @@ func (action *Action) settleDefaultAccount(lastAddress string, game *pkt.PokerBu ...@@ -391,10 +383,10 @@ func (action *Action) settleDefaultAccount(lastAddress string, game *pkt.PokerBu
for _, player := range game.Players { for _, player := range game.Players {
// 最后一名玩家没有冻结 // 最后一名玩家没有冻结
if player.Address != lastAddress { if player.Address != lastAddress {
receipt, err := action.coinsAccount.ExecActive(player.GetAddress(), action.execaddr, game.GetValue()*POKERBULL_LEVERAGE_MAX) receipt, err := action.coinsAccount.ExecActive(player.GetAddress(), action.execaddr, game.GetValue()*PokerbullLeverageMax)
if err != nil { if err != nil {
logger.Error("GameSettleDefault.ExecActive", "addr", player.GetAddress(), "execaddr", action.execaddr, logger.Error("GameSettleDefault.ExecActive", "addr", player.GetAddress(), "execaddr", action.execaddr,
"amount", game.GetValue()*POKERBULL_LEVERAGE_MAX, "err", err) "amount", game.GetValue()*PokerbullLeverageMax, "err", err)
return nil, nil, err return nil, nil, err
} }
logs = append(logs, receipt.Logs...) logs = append(logs, receipt.Logs...)
...@@ -421,9 +413,8 @@ func (action *Action) settleDefaultAccount(lastAddress string, game *pkt.PokerBu ...@@ -421,9 +413,8 @@ func (action *Action) settleDefaultAccount(lastAddress string, game *pkt.PokerBu
func (action *Action) settleAccount(lastAddress string, game *pkt.PokerBull) ([]*types.ReceiptLog, []*types.KeyValue, error) { func (action *Action) settleAccount(lastAddress string, game *pkt.PokerBull) ([]*types.ReceiptLog, []*types.KeyValue, error) {
if DefaultStyle == pkt.PlayStyleDealer { if DefaultStyle == pkt.PlayStyleDealer {
return action.settleDealerAccount(lastAddress, game) return action.settleDealerAccount(lastAddress, game)
} else {
return action.settleDefaultAccount(lastAddress, game)
} }
return action.settleDefaultAccount(lastAddress, game)
} }
func (action *Action) genTxRnd(txhash []byte) (int64, error) { func (action *Action) genTxRnd(txhash []byte) (int64, error) {
...@@ -453,28 +444,28 @@ func (action *Action) checkDupPlayerAddress(id string, pbPlayers []*pkt.PBPlayer ...@@ -453,28 +444,28 @@ func (action *Action) checkDupPlayerAddress(id string, pbPlayers []*pkt.PBPlayer
} }
// 新建一局游戏 // 新建一局游戏
func (action *Action) newGame(gameId string, start *pkt.PBGameStart) (*pkt.PokerBull, error) { func (action *Action) newGame(gameID string, start *pkt.PBGameStart) (*pkt.PokerBull, error) {
var game *pkt.PokerBull var game *pkt.PokerBull
// 不指定赌注,默认按照最低赌注 // 不指定赌注,默认按照最低赌注
if start.GetValue() == 0 { if start.GetValue() == 0 {
start.Value = MIN_PLAY_VALUE start.Value = MinPlayValue
} }
//TODO 庄家检查闲家数量倍数的资金 //TODO 庄家检查闲家数量倍数的资金
if DefaultStyle == pkt.PlayStyleDealer { if DefaultStyle == pkt.PlayStyleDealer {
if !action.CheckExecAccountBalance(action.fromaddr, start.GetValue()*POKERBULL_LEVERAGE_MAX*int64(start.PlayerNum-1), 0) { if !action.CheckExecAccountBalance(action.fromaddr, start.GetValue()*PokerbullLeverageMax*int64(start.PlayerNum-1), 0) {
logger.Error("GameStart", "addr", action.fromaddr, "execaddr", action.execaddr, "id", logger.Error("GameStart", "addr", action.fromaddr, "execaddr", action.execaddr, "id",
gameId, "err", types.ErrNoBalance) gameID, "err", types.ErrNoBalance)
return nil, types.ErrNoBalance return nil, types.ErrNoBalance
} }
} }
game = &pkt.PokerBull{ game = &pkt.PokerBull{
GameId: gameId, GameId: gameID,
Status: pkt.PBGameActionStart, Status: pkt.PBGameActionStart,
StartTime: action.blocktime, StartTime: action.blocktime,
StartTxHash: gameId, StartTxHash: gameID,
Value: start.GetValue(), Value: start.GetValue(),
Poker: NewPoker(), Poker: NewPoker(),
PlayerNum: start.PlayerNum, PlayerNum: start.PlayerNum,
...@@ -491,7 +482,7 @@ func (action *Action) newGame(gameId string, start *pkt.PBGameStart) (*pkt.Poker ...@@ -491,7 +482,7 @@ func (action *Action) newGame(gameId string, start *pkt.PBGameStart) (*pkt.Poker
// 筛选合适的牌局 // 筛选合适的牌局
func (action *Action) selectGameFromIds(ids []string, value int64) *pkt.PokerBull { func (action *Action) selectGameFromIds(ids []string, value int64) *pkt.PokerBull {
var gameRet *pkt.PokerBull = nil var gameRet *pkt.PokerBull
for _, id := range ids { for _, id := range ids {
game, err := action.readGame(id) game, err := action.readGame(id)
if err != nil { if err != nil {
...@@ -505,7 +496,7 @@ func (action *Action) selectGameFromIds(ids []string, value int64) *pkt.PokerBul ...@@ -505,7 +496,7 @@ func (action *Action) selectGameFromIds(ids []string, value int64) *pkt.PokerBul
} }
//选择合适赌注的游戏 //选择合适赌注的游戏
if value == 0 && game.GetValue() != MIN_PLAY_VALUE { if value == 0 && game.GetValue() != MinPlayValue {
if !action.CheckExecAccountBalance(action.fromaddr, game.GetValue(), 0) { if !action.CheckExecAccountBalance(action.fromaddr, game.GetValue(), 0) {
logger.Error("GameStart", "addr", action.fromaddr, "execaddr", action.execaddr, "id", id, "err", types.ErrNoBalance) logger.Error("GameStart", "addr", action.fromaddr, "execaddr", action.execaddr, "id", id, "err", types.ErrNoBalance)
continue continue
...@@ -536,19 +527,20 @@ func (action *Action) checkPlayerExistInGame() bool { ...@@ -536,19 +527,20 @@ func (action *Action) checkPlayerExistInGame() bool {
return true return true
} }
// GameStart 游戏开始
func (action *Action) GameStart(start *pkt.PBGameStart) (*types.Receipt, error) { func (action *Action) GameStart(start *pkt.PBGameStart) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kv []*types.KeyValue var kv []*types.KeyValue
if start.PlayerNum > MAX_PLAYER_NUM { if start.PlayerNum > MaxPlayerNum {
logger.Error("GameStart", "addr", action.fromaddr, "execaddr", action.execaddr, logger.Error("GameStart", "addr", action.fromaddr, "execaddr", action.execaddr,
"err", fmt.Sprintf("The maximum player number is %d", MAX_PLAYER_NUM)) "err", fmt.Sprintf("The maximum player number is %d", MaxPlayerNum))
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
gameId := common.ToHex(action.txhash) gameID := common.ToHex(action.txhash)
if !action.CheckExecAccountBalance(action.fromaddr, start.GetValue()*POKERBULL_LEVERAGE_MAX, 0) { if !action.CheckExecAccountBalance(action.fromaddr, start.GetValue()*PokerbullLeverageMax, 0) {
logger.Error("GameStart", "addr", action.fromaddr, "execaddr", action.execaddr, "id", gameId, "err", types.ErrNoBalance) logger.Error("GameStart", "addr", action.fromaddr, "execaddr", action.execaddr, "id", gameID, "err", types.ErrNoBalance)
return nil, types.ErrNoBalance return nil, types.ErrNoBalance
} }
...@@ -557,14 +549,14 @@ func (action *Action) GameStart(start *pkt.PBGameStart) (*types.Receipt, error) ...@@ -557,14 +549,14 @@ func (action *Action) GameStart(start *pkt.PBGameStart) (*types.Receipt, error)
return nil, fmt.Errorf("Address is already in a game") return nil, fmt.Errorf("Address is already in a game")
} }
var game *pkt.PokerBull = nil var game *pkt.PokerBull
ids, err := queryGameListByStatusAndPlayer(action.localDB, pkt.PBGameActionStart, start.PlayerNum, start.Value) ids, err := queryGameListByStatusAndPlayer(action.localDB, pkt.PBGameActionStart, start.PlayerNum, start.Value)
if err != nil || len(ids) == 0 { if err != nil || len(ids) == 0 {
if err != types.ErrNotFound { if err != types.ErrNotFound {
return nil, err return nil, err
} }
game, err = action.newGame(gameId, start) game, err = action.newGame(gameID, start)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -572,7 +564,7 @@ func (action *Action) GameStart(start *pkt.PBGameStart) (*types.Receipt, error) ...@@ -572,7 +564,7 @@ func (action *Action) GameStart(start *pkt.PBGameStart) (*types.Receipt, error)
game = action.selectGameFromIds(ids, start.GetValue()) game = action.selectGameFromIds(ids, start.GetValue())
if game == nil { if game == nil {
// 如果也没有匹配到游戏,则按照最低赌注创建 // 如果也没有匹配到游戏,则按照最低赌注创建
game, err = action.newGame(gameId, start) game, err = action.newGame(gameID, start)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -607,7 +599,7 @@ func (action *Action) GameStart(start *pkt.PBGameStart) (*types.Receipt, error) ...@@ -607,7 +599,7 @@ func (action *Action) GameStart(start *pkt.PBGameStart) (*types.Receipt, error)
game.PreStatus = pkt.PBGameActionStart game.PreStatus = pkt.PBGameActionStart
game.IsWaiting = false game.IsWaiting = false
} else { } else {
receipt, err := action.coinsAccount.ExecFrozen(action.fromaddr, action.execaddr, start.GetValue()*POKERBULL_LEVERAGE_MAX) //冻结子账户资金, 最后一位玩家不需要冻结 receipt, err := action.coinsAccount.ExecFrozen(action.fromaddr, action.execaddr, start.GetValue()*PokerbullLeverageMax) //冻结子账户资金, 最后一位玩家不需要冻结
if err != nil { if err != nil {
logger.Error("GameCreate.ExecFrozen", "addr", action.fromaddr, "execaddr", action.execaddr, "amount", start.GetValue(), "err", err.Error()) logger.Error("GameCreate.ExecFrozen", "addr", action.fromaddr, "execaddr", action.execaddr, "amount", start.GetValue(), "err", err.Error())
return nil, err return nil, err
...@@ -641,6 +633,7 @@ func getPlayerFromAddress(players []*pkt.PBPlayer, addr string) *pkt.PBPlayer { ...@@ -641,6 +633,7 @@ func getPlayerFromAddress(players []*pkt.PBPlayer, addr string) *pkt.PBPlayer {
return nil return nil
} }
// GameContinue 继续游戏
func (action *Action) GameContinue(pbcontinue *pkt.PBGameContinue) (*types.Receipt, error) { func (action *Action) GameContinue(pbcontinue *pkt.PBGameContinue) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kv []*types.KeyValue var kv []*types.KeyValue
...@@ -659,7 +652,7 @@ func (action *Action) GameContinue(pbcontinue *pkt.PBGameContinue) (*types.Recei ...@@ -659,7 +652,7 @@ func (action *Action) GameContinue(pbcontinue *pkt.PBGameContinue) (*types.Recei
} }
// 检查余额,庄家检查闲家数量倍数的资金 // 检查余额,庄家检查闲家数量倍数的资金
checkValue := game.GetValue() * POKERBULL_LEVERAGE_MAX checkValue := game.GetValue() * PokerbullLeverageMax
if action.fromaddr == game.DealerAddr { if action.fromaddr == game.DealerAddr {
checkValue = checkValue * int64(game.PlayerNum-1) checkValue = checkValue * int64(game.PlayerNum-1)
} }
...@@ -702,7 +695,7 @@ func (action *Action) GameContinue(pbcontinue *pkt.PBGameContinue) (*types.Recei ...@@ -702,7 +695,7 @@ func (action *Action) GameContinue(pbcontinue *pkt.PBGameContinue) (*types.Recei
game.IsWaiting = false game.IsWaiting = false
game.PreStatus = pkt.PBGameActionContinue game.PreStatus = pkt.PBGameActionContinue
} else { } else {
receipt, err := action.coinsAccount.ExecFrozen(action.fromaddr, action.execaddr, game.GetValue()*POKERBULL_LEVERAGE_MAX) //冻结子账户资金,最后一位玩家不需要冻结 receipt, err := action.coinsAccount.ExecFrozen(action.fromaddr, action.execaddr, game.GetValue()*PokerbullLeverageMax) //冻结子账户资金,最后一位玩家不需要冻结
if err != nil { if err != nil {
logger.Error("GameCreate.ExecFrozen", "addr", action.fromaddr, "execaddr", action.execaddr, "amount", game.GetValue(), "err", err.Error()) logger.Error("GameCreate.ExecFrozen", "addr", action.fromaddr, "execaddr", action.execaddr, "amount", game.GetValue(), "err", err.Error())
return nil, err return nil, err
...@@ -719,6 +712,7 @@ func (action *Action) GameContinue(pbcontinue *pkt.PBGameContinue) (*types.Recei ...@@ -719,6 +712,7 @@ func (action *Action) GameContinue(pbcontinue *pkt.PBGameContinue) (*types.Recei
return &types.Receipt{types.ExecOk, kv, logs}, nil return &types.Receipt{types.ExecOk, kv, logs}, nil
} }
// GameQuit 退出游戏
func (action *Action) GameQuit(pbend *pkt.PBGameQuit) (*types.Receipt, error) { func (action *Action) GameQuit(pbend *pkt.PBGameQuit) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kv []*types.KeyValue var kv []*types.KeyValue
...@@ -734,7 +728,7 @@ func (action *Action) GameQuit(pbend *pkt.PBGameQuit) (*types.Receipt, error) { ...@@ -734,7 +728,7 @@ func (action *Action) GameQuit(pbend *pkt.PBGameQuit) (*types.Receipt, error) {
if game.IsWaiting { if game.IsWaiting {
if game.Status == pkt.PBGameActionStart { if game.Status == pkt.PBGameActionStart {
for _, player := range game.Players { for _, player := range game.Players {
receipt, err := action.coinsAccount.ExecActive(player.Address, action.execaddr, game.GetValue()*POKERBULL_LEVERAGE_MAX) receipt, err := action.coinsAccount.ExecActive(player.Address, action.execaddr, game.GetValue()*PokerbullLeverageMax)
if err != nil { if err != nil {
logger.Error("GameSettleDealer.ExecActive", "addr", player.Address, "execaddr", action.execaddr, "amount", game.GetValue(), logger.Error("GameSettleDealer.ExecActive", "addr", player.Address, "execaddr", action.execaddr, "amount", game.GetValue(),
"err", err) "err", err)
...@@ -749,7 +743,7 @@ func (action *Action) GameQuit(pbend *pkt.PBGameQuit) (*types.Receipt, error) { ...@@ -749,7 +743,7 @@ func (action *Action) GameQuit(pbend *pkt.PBGameQuit) (*types.Receipt, error) {
continue continue
} }
receipt, err := action.coinsAccount.ExecActive(player.Address, action.execaddr, game.GetValue()*POKERBULL_LEVERAGE_MAX) receipt, err := action.coinsAccount.ExecActive(player.Address, action.execaddr, game.GetValue()*PokerbullLeverageMax)
if err != nil { if err != nil {
logger.Error("GameSettleDealer.ExecActive", "addr", player.Address, "execaddr", action.execaddr, "amount", game.GetValue(), logger.Error("GameSettleDealer.ExecActive", "addr", player.Address, "execaddr", action.execaddr, "amount", game.GetValue(),
"err", err) "err", err)
...@@ -774,6 +768,7 @@ func (action *Action) GameQuit(pbend *pkt.PBGameQuit) (*types.Receipt, error) { ...@@ -774,6 +768,7 @@ func (action *Action) GameQuit(pbend *pkt.PBGameQuit) (*types.Receipt, error) {
return &types.Receipt{types.ExecOk, kv, logs}, nil return &types.Receipt{types.ExecOk, kv, logs}, nil
} }
// HandSlice 一手牌
type HandSlice []*pkt.PBHand type HandSlice []*pkt.PBHand
func (h HandSlice) Len() int { func (h HandSlice) Len() int {
......
...@@ -9,10 +9,12 @@ import ( ...@@ -9,10 +9,12 @@ import (
pkt "github.com/33cn/plugin/plugin/dapp/pokerbull/types" pkt "github.com/33cn/plugin/plugin/dapp/pokerbull/types"
) )
// Query_QueryGameListByIds 根据id列表查询游戏
func (g *PokerBull) Query_QueryGameListByIds(in *pkt.QueryPBGameInfos) (types.Message, error) { func (g *PokerBull) Query_QueryGameListByIds(in *pkt.QueryPBGameInfos) (types.Message, error) {
return Infos(g.GetStateDB(), in) return Infos(g.GetStateDB(), in)
} }
// Query_QueryGameById 根据id查询游戏
func (g *PokerBull) Query_QueryGameById(in *pkt.QueryPBGameInfo) (types.Message, error) { func (g *PokerBull) Query_QueryGameById(in *pkt.QueryPBGameInfo) (types.Message, error) {
game, err := readGame(g.GetStateDB(), in.GetGameId()) game, err := readGame(g.GetStateDB(), in.GetGameId())
if err != nil { if err != nil {
...@@ -21,6 +23,7 @@ func (g *PokerBull) Query_QueryGameById(in *pkt.QueryPBGameInfo) (types.Message, ...@@ -21,6 +23,7 @@ func (g *PokerBull) Query_QueryGameById(in *pkt.QueryPBGameInfo) (types.Message,
return &pkt.ReplyPBGame{game}, nil return &pkt.ReplyPBGame{game}, nil
} }
// Query_QueryGameByAddr 根据地址查询游戏
func (g *PokerBull) Query_QueryGameByAddr(in *pkt.QueryPBGameInfo) (types.Message, error) { func (g *PokerBull) Query_QueryGameByAddr(in *pkt.QueryPBGameInfo) (types.Message, error) {
gameIds, err := getGameListByAddr(g.GetLocalDB(), in.Addr, in.Index) gameIds, err := getGameListByAddr(g.GetLocalDB(), in.Addr, in.Index)
if err != nil { if err != nil {
...@@ -30,6 +33,7 @@ func (g *PokerBull) Query_QueryGameByAddr(in *pkt.QueryPBGameInfo) (types.Messag ...@@ -30,6 +33,7 @@ func (g *PokerBull) Query_QueryGameByAddr(in *pkt.QueryPBGameInfo) (types.Messag
return gameIds, nil return gameIds, nil
} }
// Query_QueryGameByStatus 根据状态查询游戏
func (g *PokerBull) Query_QueryGameByStatus(in *pkt.QueryPBGameInfo) (types.Message, error) { func (g *PokerBull) Query_QueryGameByStatus(in *pkt.QueryPBGameInfo) (types.Message, error) {
gameIds, err := getGameListByStatus(g.GetLocalDB(), in.Status, in.Index) gameIds, err := getGameListByStatus(g.GetLocalDB(), in.Status, in.Index)
if err != nil { if err != nil {
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
pb "github.com/33cn/plugin/plugin/dapp/pokerbull/types" pb "github.com/33cn/plugin/plugin/dapp/pokerbull/types"
) )
// PokerBullStartTx 创建游戏开始交易
func (c *Jrpc) PokerBullStartTx(parm *pb.PBStartTxReq, result *interface{}) error { func (c *Jrpc) PokerBullStartTx(parm *pb.PBStartTxReq, result *interface{}) error {
if parm == nil { if parm == nil {
return types.ErrInvalidParam return types.ErrInvalidParam
...@@ -28,6 +29,7 @@ func (c *Jrpc) PokerBullStartTx(parm *pb.PBStartTxReq, result *interface{}) erro ...@@ -28,6 +29,7 @@ func (c *Jrpc) PokerBullStartTx(parm *pb.PBStartTxReq, result *interface{}) erro
return nil return nil
} }
// PokerBullContinueTx 创建游戏继续交易
func (c *Jrpc) PokerBullContinueTx(parm *pb.PBContinueTxReq, result *interface{}) error { func (c *Jrpc) PokerBullContinueTx(parm *pb.PBContinueTxReq, result *interface{}) error {
if parm == nil { if parm == nil {
return types.ErrInvalidParam return types.ErrInvalidParam
...@@ -46,6 +48,7 @@ func (c *Jrpc) PokerBullContinueTx(parm *pb.PBContinueTxReq, result *interface{} ...@@ -46,6 +48,7 @@ func (c *Jrpc) PokerBullContinueTx(parm *pb.PBContinueTxReq, result *interface{}
return nil return nil
} }
// PokerBullQuitTx 创建游戏推出交易
func (c *Jrpc) PokerBullQuitTx(parm *pb.PBQuitTxReq, result *interface{}) error { func (c *Jrpc) PokerBullQuitTx(parm *pb.PBQuitTxReq, result *interface{}) error {
if parm == nil { if parm == nil {
return types.ErrInvalidParam return types.ErrInvalidParam
...@@ -63,6 +66,7 @@ func (c *Jrpc) PokerBullQuitTx(parm *pb.PBQuitTxReq, result *interface{}) error ...@@ -63,6 +66,7 @@ func (c *Jrpc) PokerBullQuitTx(parm *pb.PBQuitTxReq, result *interface{}) error
return nil return nil
} }
// PokerBullQueryTx 创建游戏查询交易
func (c *Jrpc) PokerBullQueryTx(parm *pb.PBQueryReq, result *interface{}) error { func (c *Jrpc) PokerBullQueryTx(parm *pb.PBQueryReq, result *interface{}) error {
if parm == nil { if parm == nil {
return types.ErrInvalidParam return types.ErrInvalidParam
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
) )
func (c *channelClient) Start(ctx context.Context, head *pb.PBGameStart) (*types.UnsignTx, error) { func (c *channelClient) Start(ctx context.Context, head *pb.PBGameStart) (*types.UnsignTx, error) {
if head.PlayerNum > executor.MAX_PLAYER_NUM { if head.PlayerNum > executor.MaxPlayerNum {
return nil, errors.New("Player number should be maximum 5") return nil, errors.New("Player number should be maximum 5")
} }
......
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rpc
type PokerBullStartTx struct {
Value int64 `json:"value"`
PlayerNum int32 `json:"playerNum"`
Fee int64 `json:"fee"`
}
type PBContinueTxReq struct {
GameId string `json:"gameId"`
Fee int64 `json:"fee"`
}
type PBQuitTxReq struct {
GameId string `json:"gameId"`
Fee int64 `json:"fee"`
}
type PBQueryReq struct {
GameId string `json:"GameId"`
Fee int64 `json:"fee"`
}
...@@ -8,10 +8,12 @@ import ( ...@@ -8,10 +8,12 @@ import (
"github.com/33cn/chain33/rpc/types" "github.com/33cn/chain33/rpc/types"
) )
// Jrpc jrpc句柄
type Jrpc struct { type Jrpc struct {
cli *channelClient cli *channelClient
} }
// Grpc grpc句柄
type Grpc struct { type Grpc struct {
*channelClient *channelClient
} }
...@@ -20,6 +22,7 @@ type channelClient struct { ...@@ -20,6 +22,7 @@ type channelClient struct {
types.ChannelClient types.ChannelClient
} }
// Init 初始化rpc
func Init(name string, s types.RPCServer) { func Init(name string, s types.RPCServer) {
cli := &channelClient{} cli := &channelClient{}
grpc := &Grpc{channelClient: cli} grpc := &Grpc{channelClient: cli}
......
...@@ -13,12 +13,13 @@ const ( ...@@ -13,12 +13,13 @@ const (
) )
const ( const (
// PlayStyleDefault 游戏类型
PlayStyleDefault = iota + 1 PlayStyleDefault = iota + 1
PlayStyleDealer PlayStyleDealer
) )
const ( const (
//log for PBgame // TyLogPBGameStart log for PBgame
TyLogPBGameStart = 721 TyLogPBGameStart = 721
TyLogPBGameContinue = 722 TyLogPBGameContinue = 722
TyLogPBGameQuit = 723 TyLogPBGameQuit = 723
...@@ -35,9 +36,10 @@ var ( ...@@ -35,9 +36,10 @@ var (
) )
const ( const (
//查询方法名 // FuncNameQueryGameListByIds 根据id列表查询game列表
FuncName_QueryGameListByIds = "QueryGameListByIds" FuncNameQueryGameListByIds = "QueryGameListByIds"
FuncName_QueryGameById = "QueryGameById" // FuncNameQueryGameById 根据id查询game
FuncName_QueryGameByAddr = "QueryGameByAddr" FuncNameQueryGameById = "QueryGameById"
FuncName_QueryGameByStatus = "QueryGameByStatus" FuncNameQueryGameByAddr = "QueryGameByAddr"
FuncNameQueryGameByStatus = "QueryGameByStatus"
) )
...@@ -17,21 +17,24 @@ func init() { ...@@ -17,21 +17,24 @@ func init() {
types.RegisterDappFork(PokerBullX, "Enable", 0) types.RegisterDappFork(PokerBullX, "Enable", 0)
} }
// exec // PokerBullType 斗牛执行器类型
type PokerBullType struct { type PokerBullType struct {
types.ExecTypeBase types.ExecTypeBase
} }
// NewType 创建pokerbull执行器类型
func NewType() *PokerBullType { func NewType() *PokerBullType {
c := &PokerBullType{} c := &PokerBullType{}
c.SetChild(c) c.SetChild(c)
return c return c
} }
// GetPayload 获取payload
func (t *PokerBullType) GetPayload() types.Message { func (t *PokerBullType) GetPayload() types.Message {
return &PBGameAction{} return &PBGameAction{}
} }
// GetTypeMap 获取类型map
func (t *PokerBullType) GetTypeMap() map[string]int32 { func (t *PokerBullType) GetTypeMap() map[string]int32 {
return map[string]int32{ return map[string]int32{
"Start": PBGameActionStart, "Start": PBGameActionStart,
...@@ -41,6 +44,7 @@ func (t *PokerBullType) GetTypeMap() map[string]int32 { ...@@ -41,6 +44,7 @@ func (t *PokerBullType) GetTypeMap() map[string]int32 {
} }
} }
// GetLogMap 获取日志map
func (t *PokerBullType) GetLogMap() map[int64]*types.LogInfo { func (t *PokerBullType) GetLogMap() map[int64]*types.LogInfo {
return map[int64]*types.LogInfo{ return map[int64]*types.LogInfo{
TyLogPBGameStart: {reflect.TypeOf(ReceiptPBGame{}), "TyLogPBGameStart"}, TyLogPBGameStart: {reflect.TypeOf(ReceiptPBGame{}), "TyLogPBGameStart"},
......
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