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

pokerbull添加play交易执行

parent 285f6717
......@@ -28,6 +28,7 @@ func PokerBullCmd() *cobra.Command {
PokerBullContinueRawTxCmd(),
PokerBullQuitRawTxCmd(),
PokerBullQueryResultRawTxCmd(),
PokerBullPlayRawTxCmd(),
)
return cmd
......@@ -45,7 +46,7 @@ func PokerBullStartRawTxCmd() *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.Flags().Uint32P("playerCount", "p", 0, "player count")
......@@ -121,7 +122,7 @@ func pokerbullQuit(cmd *cobra.Command, args []string) {
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pkt.PokerBullX),
ActionName: pkt.CreatequitTx,
ActionName: pkt.CreateQuitTx,
Payload: []byte(fmt.Sprintf("{\"gameId\":\"%s\"}", gameID)),
}
......@@ -130,6 +131,54 @@ func pokerbullQuit(cmd *cobra.Command, args []string) {
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 查询命令行
func PokerBullQueryResultRawTxCmd() *cobra.Command {
cmd := &cobra.Command{
......
......@@ -26,3 +26,9 @@ func (c *PokerBull) Exec_Quit(payload *pkt.PBGameQuit, tx *types.Transaction, in
action := NewAction(c, tx, index)
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
dbSet := &types.LocalDBSet{}
for i := 0; i < len(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
err := types.Decode(item.Log, &Gamelog)
if err != nil {
......@@ -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) {
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
......@@ -64,6 +64,7 @@ message PBGameAction {
PBGameContinue continue = 2;
PBGameQuit quit = 3;
PBGameQuery query = 4;
PBGamePlay play = 5;
}
int32 ty = 10;
}
......@@ -89,6 +90,14 @@ message PBGameQuery {
string gameId = 1;
}
//已匹配玩家直接游戏
message PBGamePlay {
string gameId = 1; //游戏id
int32 round = 2; //当前游戏回合数
int64 value = 3; //当前游戏赌注
repeated string address = 4; //玩家地址
}
//根据状态和游戏人数查找
message QueryPBGameListByStatusAndPlayerNum {
int32 status = 1;
......
......@@ -97,7 +97,7 @@ func testQuitRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
payload := &pty.PBGameQuit{GameId: "123"}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pty.PokerBullX),
ActionName: pty.CreatequitTx,
ActionName: pty.CreateQuitTx,
Payload: types.MustPBToJSON(payload),
}
var res string
......
......@@ -12,6 +12,7 @@ const (
PBGameActionContinue
PBGameActionQuit
PBGameActionQuery
PBGameActionPlay
)
const (
......@@ -30,6 +31,8 @@ const (
TyLogPBGameQuit = 723
// TyLogPBGameQuery log for query PBgame
TyLogPBGameQuery = 724
// TyLogPBGamePlay log for play PBgame
TyLogPBGamePlay = 725
)
//包的名字可以通过配置文件来配置
......@@ -56,8 +59,10 @@ const (
CreateStartTx = "Start"
// CreateContinueTx 创建继续交易
CreateContinueTx = "Continue"
// CreatequitTx 创建退出交易
CreatequitTx = "Quit"
// CreateQuitTx 创建退出交易
CreateQuitTx = "Quit"
// CreatePlayTx 创建已匹配玩家交易
CreatePlayTx = "Play"
)
const (
......@@ -67,6 +72,8 @@ const (
DefaultCount = int32(20)
// MaxPlayerNum 最大玩家数
MaxPlayerNum = 5
// MinPlayerNum 最小玩家数
MinPlayerNum = 2
// MinPlayValue 最小赌注
MinPlayValue = 10 * types.Coin
// DefaultStyle 默认游戏类型
......@@ -81,4 +88,6 @@ const (
DeveloperFee = int64(0.005 * float64(types.Coin))
// WinnerReturn 赢家回报率
WinnerReturn = types.Coin - DeveloperFee
// PlatformSignAddress 平台签名地址
PlatformSignAddress = "1Geb4ppNiAwMKKyrJgcis3JA57FkqsXvdR"
)
This diff is collapsed.
......@@ -46,6 +46,7 @@ func (t *PokerBullType) GetTypeMap() map[string]int32 {
"Continue": PBGameActionContinue,
"Quit": PBGameActionQuit,
"Query": PBGameActionQuery,
"Play": PBGameActionPlay,
}
}
......@@ -56,5 +57,6 @@ func (t *PokerBullType) GetLogMap() map[int64]*types.LogInfo {
TyLogPBGameContinue: {Ty: reflect.TypeOf(ReceiptPBGame{}), Name: "TyLogPBGameContinue"},
TyLogPBGameQuit: {Ty: reflect.TypeOf(ReceiptPBGame{}), Name: "TyLogPBGameQuit"},
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