Commit c18f93fb authored by pengjun's avatar pengjun Committed by vipwzw

pokerbull添加play交易执行

parent 285f6717
...@@ -28,6 +28,7 @@ func PokerBullCmd() *cobra.Command { ...@@ -28,6 +28,7 @@ func PokerBullCmd() *cobra.Command {
PokerBullContinueRawTxCmd(), PokerBullContinueRawTxCmd(),
PokerBullQuitRawTxCmd(), PokerBullQuitRawTxCmd(),
PokerBullQueryResultRawTxCmd(), PokerBullQueryResultRawTxCmd(),
PokerBullPlayRawTxCmd(),
) )
return cmd return cmd
...@@ -45,7 +46,7 @@ func PokerBullStartRawTxCmd() *cobra.Command { ...@@ -45,7 +46,7 @@ func PokerBullStartRawTxCmd() *cobra.Command {
} }
func addPokerbullStartFlags(cmd *cobra.Command) { func addPokerbullStartFlags(cmd *cobra.Command) {
cmd.Flags().Uint64P("value", "a", 0, "value") cmd.Flags().Uint64P("value", "v", 0, "value")
cmd.MarkFlagRequired("value") cmd.MarkFlagRequired("value")
cmd.Flags().Uint32P("playerCount", "p", 0, "player count") cmd.Flags().Uint32P("playerCount", "p", 0, "player count")
...@@ -121,7 +122,7 @@ func pokerbullQuit(cmd *cobra.Command, args []string) { ...@@ -121,7 +122,7 @@ func pokerbullQuit(cmd *cobra.Command, args []string) {
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pkt.PokerBullX), Execer: types.ExecName(pkt.PokerBullX),
ActionName: pkt.CreatequitTx, ActionName: pkt.CreateQuitTx,
Payload: []byte(fmt.Sprintf("{\"gameId\":\"%s\"}", gameID)), Payload: []byte(fmt.Sprintf("{\"gameId\":\"%s\"}", gameID)),
} }
...@@ -130,6 +131,54 @@ func pokerbullQuit(cmd *cobra.Command, args []string) { ...@@ -130,6 +131,54 @@ func pokerbullQuit(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
// PokerBullPlayRawTxCmd 生成已匹配玩家游戏命令行
func PokerBullPlayRawTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "play",
Short: "Play game",
Run: pokerbullPlay,
}
addPokerbullPlayFlags(cmd)
return cmd
}
func addPokerbullPlayFlags(cmd *cobra.Command) {
cmd.Flags().StringP("gameID", "g", "", "game ID")
cmd.MarkFlagRequired("gameID")
cmd.Flags().Uint32P("round", "r", 0, "round")
cmd.MarkFlagRequired("round")
cmd.Flags().Uint64P("value", "v", 0, "value")
cmd.MarkFlagRequired("value")
cmd.Flags().StringArrayP("address", "a", nil, "address")
cmd.MarkFlagRequired("address")
}
func pokerbullPlay(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
gameID, _ := cmd.Flags().GetString("gameID")
round, _ := cmd.Flags().GetUint32("round")
value, _ := cmd.Flags().GetUint64("value")
address, _ := cmd.Flags().GetStringArray("address")
payload := &pkt.PBGamePlay{
GameId: gameID,
Value: int64(value)*types.Coin,
Round: int32(round),
}
payload.Address = make([]string, len(address))
copy(payload.Address, address)
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pkt.PokerBullX),
ActionName: pkt.CreatePlayTx,
Payload: types.MustPBToJSON(payload),
}
var res string
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, &res)
ctx.RunWithoutMarshal()
}
// PokerBullQueryResultRawTxCmd 查询命令行 // PokerBullQueryResultRawTxCmd 查询命令行
func PokerBullQueryResultRawTxCmd() *cobra.Command { func PokerBullQueryResultRawTxCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
......
...@@ -26,3 +26,9 @@ func (c *PokerBull) Exec_Quit(payload *pkt.PBGameQuit, tx *types.Transaction, in ...@@ -26,3 +26,9 @@ func (c *PokerBull) Exec_Quit(payload *pkt.PBGameQuit, tx *types.Transaction, in
action := NewAction(c, tx, index) action := NewAction(c, tx, index)
return action.GameQuit(payload) return action.GameQuit(payload)
} }
// Exec_Play 已匹配玩家直接开始游戏
func (c *PokerBull) Exec_Play(payload *pkt.PBGamePlay, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(c, tx, index)
return action.GamePlay(payload)
}
...@@ -57,7 +57,7 @@ func (c *PokerBull) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, er ...@@ -57,7 +57,7 @@ func (c *PokerBull) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, er
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
for i := 0; i < len(receipt.Logs); i++ { for i := 0; i < len(receipt.Logs); i++ {
item := receipt.Logs[i] item := receipt.Logs[i]
if item.Ty == pkt.TyLogPBGameStart || item.Ty == pkt.TyLogPBGameContinue || item.Ty == pkt.TyLogPBGameQuit { if item.Ty == pkt.TyLogPBGameStart || item.Ty == pkt.TyLogPBGameContinue || item.Ty == pkt.TyLogPBGameQuit || item.Ty == pkt.TyLogPBGamePlay {
var Gamelog pkt.ReceiptPBGame var Gamelog pkt.ReceiptPBGame
err := types.Decode(item.Log, &Gamelog) err := types.Decode(item.Log, &Gamelog)
if err != nil { if err != nil {
...@@ -84,3 +84,8 @@ func (c *PokerBull) ExecLocal_Continue(payload *pkt.PBGameContinue, tx *types.Tr ...@@ -84,3 +84,8 @@ func (c *PokerBull) ExecLocal_Continue(payload *pkt.PBGameContinue, tx *types.Tr
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)
} }
// ExecLocal_Play 已匹配游戏交易local执行
func (c *PokerBull) ExecLocal_Play(payload *pkt.PBGamePlay, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return c.execLocal(receiptData)
}
\ No newline at end of file
...@@ -60,10 +60,11 @@ message PBPoker { ...@@ -60,10 +60,11 @@ message PBPoker {
//游戏状态 //游戏状态
message PBGameAction { message PBGameAction {
oneof value { oneof value {
PBGameStart start = 1; PBGameStart start = 1;
PBGameContinue continue = 2; PBGameContinue continue = 2;
PBGameQuit quit = 3; PBGameQuit quit = 3;
PBGameQuery query = 4; PBGameQuery query = 4;
PBGamePlay play = 5;
} }
int32 ty = 10; int32 ty = 10;
} }
...@@ -89,6 +90,14 @@ message PBGameQuery { ...@@ -89,6 +90,14 @@ message PBGameQuery {
string gameId = 1; string gameId = 1;
} }
//已匹配玩家直接游戏
message PBGamePlay {
string gameId = 1; //游戏id
int32 round = 2; //当前游戏回合数
int64 value = 3; //当前游戏赌注
repeated string address = 4; //玩家地址
}
//根据状态和游戏人数查找 //根据状态和游戏人数查找
message QueryPBGameListByStatusAndPlayerNum { message QueryPBGameListByStatusAndPlayerNum {
int32 status = 1; int32 status = 1;
......
...@@ -97,7 +97,7 @@ func testQuitRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error { ...@@ -97,7 +97,7 @@ func testQuitRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
payload := &pty.PBGameQuit{GameId: "123"} payload := &pty.PBGameQuit{GameId: "123"}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pty.PokerBullX), Execer: types.ExecName(pty.PokerBullX),
ActionName: pty.CreatequitTx, ActionName: pty.CreateQuitTx,
Payload: types.MustPBToJSON(payload), Payload: types.MustPBToJSON(payload),
} }
var res string var res string
......
...@@ -12,6 +12,7 @@ const ( ...@@ -12,6 +12,7 @@ const (
PBGameActionContinue PBGameActionContinue
PBGameActionQuit PBGameActionQuit
PBGameActionQuery PBGameActionQuery
PBGameActionPlay
) )
const ( const (
...@@ -30,6 +31,8 @@ const ( ...@@ -30,6 +31,8 @@ const (
TyLogPBGameQuit = 723 TyLogPBGameQuit = 723
// TyLogPBGameQuery log for query PBgame // TyLogPBGameQuery log for query PBgame
TyLogPBGameQuery = 724 TyLogPBGameQuery = 724
// TyLogPBGamePlay log for play PBgame
TyLogPBGamePlay = 725
) )
//包的名字可以通过配置文件来配置 //包的名字可以通过配置文件来配置
...@@ -56,8 +59,10 @@ const ( ...@@ -56,8 +59,10 @@ const (
CreateStartTx = "Start" CreateStartTx = "Start"
// CreateContinueTx 创建继续交易 // CreateContinueTx 创建继续交易
CreateContinueTx = "Continue" CreateContinueTx = "Continue"
// CreatequitTx 创建退出交易 // CreateQuitTx 创建退出交易
CreatequitTx = "Quit" CreateQuitTx = "Quit"
// CreatePlayTx 创建已匹配玩家交易
CreatePlayTx = "Play"
) )
const ( const (
...@@ -67,6 +72,8 @@ const ( ...@@ -67,6 +72,8 @@ const (
DefaultCount = int32(20) DefaultCount = int32(20)
// MaxPlayerNum 最大玩家数 // MaxPlayerNum 最大玩家数
MaxPlayerNum = 5 MaxPlayerNum = 5
// MinPlayerNum 最小玩家数
MinPlayerNum = 2
// MinPlayValue 最小赌注 // MinPlayValue 最小赌注
MinPlayValue = 10 * types.Coin MinPlayValue = 10 * types.Coin
// DefaultStyle 默认游戏类型 // DefaultStyle 默认游戏类型
...@@ -81,4 +88,6 @@ const ( ...@@ -81,4 +88,6 @@ const (
DeveloperFee = int64(0.005 * float64(types.Coin)) DeveloperFee = int64(0.005 * float64(types.Coin))
// WinnerReturn 赢家回报率 // WinnerReturn 赢家回报率
WinnerReturn = types.Coin - DeveloperFee WinnerReturn = types.Coin - DeveloperFee
// PlatformSignAddress 平台签名地址
PlatformSignAddress = "1Geb4ppNiAwMKKyrJgcis3JA57FkqsXvdR"
) )
This diff is collapsed.
...@@ -46,6 +46,7 @@ func (t *PokerBullType) GetTypeMap() map[string]int32 { ...@@ -46,6 +46,7 @@ func (t *PokerBullType) GetTypeMap() map[string]int32 {
"Continue": PBGameActionContinue, "Continue": PBGameActionContinue,
"Quit": PBGameActionQuit, "Quit": PBGameActionQuit,
"Query": PBGameActionQuery, "Query": PBGameActionQuery,
"Play": PBGameActionPlay,
} }
} }
...@@ -56,5 +57,6 @@ func (t *PokerBullType) GetLogMap() map[int64]*types.LogInfo { ...@@ -56,5 +57,6 @@ func (t *PokerBullType) GetLogMap() map[int64]*types.LogInfo {
TyLogPBGameContinue: {Ty: reflect.TypeOf(ReceiptPBGame{}), Name: "TyLogPBGameContinue"}, TyLogPBGameContinue: {Ty: reflect.TypeOf(ReceiptPBGame{}), Name: "TyLogPBGameContinue"},
TyLogPBGameQuit: {Ty: reflect.TypeOf(ReceiptPBGame{}), Name: "TyLogPBGameQuit"}, TyLogPBGameQuit: {Ty: reflect.TypeOf(ReceiptPBGame{}), Name: "TyLogPBGameQuit"},
TyLogPBGameQuery: {Ty: reflect.TypeOf(ReceiptPBGame{}), Name: "TyLogPBGameQuery"}, TyLogPBGameQuery: {Ty: reflect.TypeOf(ReceiptPBGame{}), Name: "TyLogPBGameQuery"},
TyLogPBGamePlay: {Ty: reflect.TypeOf(ReceiptPBGame{}), Name: "TyLogPBGamePlay"},
} }
} }
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