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)
......
...@@ -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