diff --git a/api/operation.go b/api/operation.go index 2562df5..d9690c2 100644 --- a/api/operation.go +++ b/api/operation.go @@ -18,7 +18,7 @@ var protoInstances = []proto.Message{ &Ping{}, &Pong{}, - + &ReqIdentity{}, &ResIdentity{}, @@ -29,7 +29,16 @@ var protoInstances = []proto.Message{ &ResCreateTable{}, &ReqJoinTable{}, - &ResJoinTable{}, + &ReqLeaveTable{}, + + &ReqGameAction{}, + &ResGameAction{}, + + &ReqGameStatus{}, + &ResGameStatus{}, + + &ReqReadyStart{}, + &ReqKickOutTable{}, } var ( diff --git a/api/poker.pb.go b/api/poker.pb.go index d9a8a14..df37af8 100644 --- a/api/poker.pb.go +++ b/api/poker.pb.go @@ -720,6 +720,8 @@ type ReqJoinTable struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + TableNo int32 `protobuf:"varint,1,opt,name=tableNo,proto3" json:"tableNo,omitempty"` } func (x *ReqJoinTable) Reset() { @@ -754,14 +756,22 @@ func (*ReqJoinTable) Descriptor() ([]byte, []int) { return file_poker_proto_rawDescGZIP(), []int{13} } -type ResJoinTable struct { +func (x *ReqJoinTable) GetTableNo() int32 { + if x != nil { + return x.TableNo + } + return 0 +} + +// 离开房间 +type ReqLeaveTable struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields } -func (x *ResJoinTable) Reset() { - *x = ResJoinTable{} +func (x *ReqLeaveTable) Reset() { + *x = ReqLeaveTable{} if protoimpl.UnsafeEnabled { mi := &file_poker_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -769,13 +779,13 @@ func (x *ResJoinTable) Reset() { } } -func (x *ResJoinTable) String() string { +func (x *ReqLeaveTable) String() string { return protoimpl.X.MessageStringOf(x) } -func (*ResJoinTable) ProtoMessage() {} +func (*ReqLeaveTable) ProtoMessage() {} -func (x *ResJoinTable) ProtoReflect() protoreflect.Message { +func (x *ReqLeaveTable) ProtoReflect() protoreflect.Message { mi := &file_poker_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -787,11 +797,467 @@ func (x *ResJoinTable) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use ResJoinTable.ProtoReflect.Descriptor instead. -func (*ResJoinTable) Descriptor() ([]byte, []int) { +// Deprecated: Use ReqLeaveTable.ProtoReflect.Descriptor instead. +func (*ReqLeaveTable) Descriptor() ([]byte, []int) { return file_poker_proto_rawDescGZIP(), []int{14} } +// 玩家准备开始 +type ReqReadyStart struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *ReqReadyStart) Reset() { + *x = ReqReadyStart{} + if protoimpl.UnsafeEnabled { + mi := &file_poker_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReqReadyStart) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReqReadyStart) ProtoMessage() {} + +func (x *ReqReadyStart) ProtoReflect() protoreflect.Message { + mi := &file_poker_proto_msgTypes[15] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReqReadyStart.ProtoReflect.Descriptor instead. +func (*ReqReadyStart) Descriptor() ([]byte, []int) { + return file_poker_proto_rawDescGZIP(), []int{15} +} + +// 房主踢人 +type ReqKickOutTable struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PlayerId int32 `protobuf:"varint,1,opt,name=playerId,proto3" json:"playerId,omitempty"` +} + +func (x *ReqKickOutTable) Reset() { + *x = ReqKickOutTable{} + if protoimpl.UnsafeEnabled { + mi := &file_poker_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReqKickOutTable) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReqKickOutTable) ProtoMessage() {} + +func (x *ReqKickOutTable) ProtoReflect() protoreflect.Message { + mi := &file_poker_proto_msgTypes[16] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReqKickOutTable.ProtoReflect.Descriptor instead. +func (*ReqKickOutTable) Descriptor() ([]byte, []int) { + return file_poker_proto_rawDescGZIP(), []int{16} +} + +func (x *ReqKickOutTable) GetPlayerId() int32 { + if x != nil { + return x.PlayerId + } + return 0 +} + +type ReqGameAction struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Action int32 `protobuf:"varint,1,opt,name=action,proto3" json:"action,omitempty"` // 4下大盲注,5下小盲注,6跟注,7弃牌 + Chip int32 `protobuf:"varint,2,opt,name=chip,proto3" json:"chip,omitempty"` // 押注金额 +} + +func (x *ReqGameAction) Reset() { + *x = ReqGameAction{} + if protoimpl.UnsafeEnabled { + mi := &file_poker_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReqGameAction) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReqGameAction) ProtoMessage() {} + +func (x *ReqGameAction) ProtoReflect() protoreflect.Message { + mi := &file_poker_proto_msgTypes[17] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReqGameAction.ProtoReflect.Descriptor instead. +func (*ReqGameAction) Descriptor() ([]byte, []int) { + return file_poker_proto_rawDescGZIP(), []int{17} +} + +func (x *ReqGameAction) GetAction() int32 { + if x != nil { + return x.Action + } + return 0 +} + +func (x *ReqGameAction) GetChip() int32 { + if x != nil { + return x.Chip + } + return 0 +} + +type ResGameAction struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *ResGameAction) Reset() { + *x = ResGameAction{} + if protoimpl.UnsafeEnabled { + mi := &file_poker_proto_msgTypes[18] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ResGameAction) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ResGameAction) ProtoMessage() {} + +func (x *ResGameAction) ProtoReflect() protoreflect.Message { + mi := &file_poker_proto_msgTypes[18] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ResGameAction.ProtoReflect.Descriptor instead. +func (*ResGameAction) Descriptor() ([]byte, []int) { + return file_poker_proto_rawDescGZIP(), []int{18} +} + +// 查询玩家当前游戏状态 +type ReqGameStatus struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *ReqGameStatus) Reset() { + *x = ReqGameStatus{} + if protoimpl.UnsafeEnabled { + mi := &file_poker_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReqGameStatus) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReqGameStatus) ProtoMessage() {} + +func (x *ReqGameStatus) ProtoReflect() protoreflect.Message { + mi := &file_poker_proto_msgTypes[19] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReqGameStatus.ProtoReflect.Descriptor instead. +func (*ReqGameStatus) Descriptor() ([]byte, []int) { + return file_poker_proto_rawDescGZIP(), []int{19} +} + +type ResGameStatus struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + InGame bool `protobuf:"varint,1,opt,name=inGame,proto3" json:"inGame,omitempty"` // 是否在游戏中 + TableNo int32 `protobuf:"varint,2,opt,name=tableNo,proto3" json:"tableNo,omitempty"` // 所在桌面编号 + GameStage int32 `protobuf:"varint,3,opt,name=gameStage,proto3" json:"gameStage,omitempty"` // 游戏阶段? + Players []*TablePlayer `protobuf:"bytes,10,rep,name=players,proto3" json:"players,omitempty"` +} + +func (x *ResGameStatus) Reset() { + *x = ResGameStatus{} + if protoimpl.UnsafeEnabled { + mi := &file_poker_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ResGameStatus) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ResGameStatus) ProtoMessage() {} + +func (x *ResGameStatus) ProtoReflect() protoreflect.Message { + mi := &file_poker_proto_msgTypes[20] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ResGameStatus.ProtoReflect.Descriptor instead. +func (*ResGameStatus) Descriptor() ([]byte, []int) { + return file_poker_proto_rawDescGZIP(), []int{20} +} + +func (x *ResGameStatus) GetInGame() bool { + if x != nil { + return x.InGame + } + return false +} + +func (x *ResGameStatus) GetTableNo() int32 { + if x != nil { + return x.TableNo + } + return 0 +} + +func (x *ResGameStatus) GetGameStage() int32 { + if x != nil { + return x.GameStage + } + return 0 +} + +func (x *ResGameStatus) GetPlayers() []*TablePlayer { + if x != nil { + return x.Players + } + return nil +} + +type TablePlayer struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Robot bool `protobuf:"varint,1,opt,name=robot,proto3" json:"robot,omitempty"` // 是否机器人 + Id int64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` + Username string `protobuf:"bytes,3,opt,name=username,proto3" json:"username,omitempty"` + Avatar string `protobuf:"bytes,4,opt,name=avatar,proto3" json:"avatar,omitempty"` + Chip int32 `protobuf:"varint,5,opt,name=chip,proto3" json:"chip,omitempty"` // 筹码 + Status int32 `protobuf:"varint,6,opt,name=status,proto3" json:"status,omitempty"` // 玩家状态: 1待准备开始,2已准备开始,已开始(3等待其他玩家动作,4待大盲注,5待小盲注,6待跟注,7已弃) + Master bool `protobuf:"varint,7,opt,name=master,proto3" json:"master,omitempty"` // 是否房主` + HandCard []*Card `protobuf:"bytes,8,rep,name=handCard,proto3" json:"handCard,omitempty"` // 手牌 + PublicCard []*Card `protobuf:"bytes,9,rep,name=publicCard,proto3" json:"publicCard,omitempty"` // 公共牌 +} + +func (x *TablePlayer) Reset() { + *x = TablePlayer{} + if protoimpl.UnsafeEnabled { + mi := &file_poker_proto_msgTypes[21] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TablePlayer) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TablePlayer) ProtoMessage() {} + +func (x *TablePlayer) ProtoReflect() protoreflect.Message { + mi := &file_poker_proto_msgTypes[21] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TablePlayer.ProtoReflect.Descriptor instead. +func (*TablePlayer) Descriptor() ([]byte, []int) { + return file_poker_proto_rawDescGZIP(), []int{21} +} + +func (x *TablePlayer) GetRobot() bool { + if x != nil { + return x.Robot + } + return false +} + +func (x *TablePlayer) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *TablePlayer) GetUsername() string { + if x != nil { + return x.Username + } + return "" +} + +func (x *TablePlayer) GetAvatar() string { + if x != nil { + return x.Avatar + } + return "" +} + +func (x *TablePlayer) GetChip() int32 { + if x != nil { + return x.Chip + } + return 0 +} + +func (x *TablePlayer) GetStatus() int32 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *TablePlayer) GetMaster() bool { + if x != nil { + return x.Master + } + return false +} + +func (x *TablePlayer) GetHandCard() []*Card { + if x != nil { + return x.HandCard + } + return nil +} + +func (x *TablePlayer) GetPublicCard() []*Card { + if x != nil { + return x.PublicCard + } + return nil +} + +type Card struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Dot int32 `protobuf:"varint,1,opt,name=dot,proto3" json:"dot,omitempty"` // 点数 + Suit int32 `protobuf:"varint,2,opt,name=suit,proto3" json:"suit,omitempty"` // 花色 +} + +func (x *Card) Reset() { + *x = Card{} + if protoimpl.UnsafeEnabled { + mi := &file_poker_proto_msgTypes[22] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Card) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Card) ProtoMessage() {} + +func (x *Card) ProtoReflect() protoreflect.Message { + mi := &file_poker_proto_msgTypes[22] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Card.ProtoReflect.Descriptor instead. +func (*Card) Descriptor() ([]byte, []int) { + return file_poker_proto_rawDescGZIP(), []int{22} +} + +func (x *Card) GetDot() int32 { + if x != nil { + return x.Dot + } + return 0 +} + +func (x *Card) GetSuit() int32 { + if x != nil { + return x.Suit + } + return 0 +} + var File_poker_proto protoreflect.FileDescriptor var file_poker_proto_rawDesc = []byte{ @@ -842,10 +1308,50 @@ var file_poker_proto_rawDesc = []byte{ 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x72, 0x6f, 0x62, 0x6f, 0x74, 0x73, 0x22, 0x2a, 0x0a, 0x0e, 0x52, 0x65, 0x73, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x4e, 0x6f, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x05, 0x52, 0x07, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x4e, 0x6f, 0x22, 0x0e, 0x0a, 0x0c, 0x52, - 0x65, 0x71, 0x4a, 0x6f, 0x69, 0x6e, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x0e, 0x0a, 0x0c, 0x52, - 0x65, 0x73, 0x4a, 0x6f, 0x69, 0x6e, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x42, 0x0b, 0x5a, 0x09, 0x2e, - 0x2f, 0x61, 0x70, 0x69, 0x3b, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x28, 0x05, 0x52, 0x07, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x4e, 0x6f, 0x22, 0x28, 0x0a, 0x0c, 0x52, + 0x65, 0x71, 0x4a, 0x6f, 0x69, 0x6e, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, + 0x61, 0x62, 0x6c, 0x65, 0x4e, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x74, 0x61, + 0x62, 0x6c, 0x65, 0x4e, 0x6f, 0x22, 0x0f, 0x0a, 0x0d, 0x52, 0x65, 0x71, 0x4c, 0x65, 0x61, 0x76, + 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x0f, 0x0a, 0x0d, 0x52, 0x65, 0x71, 0x52, 0x65, 0x61, + 0x64, 0x79, 0x53, 0x74, 0x61, 0x72, 0x74, 0x22, 0x2d, 0x0a, 0x0f, 0x52, 0x65, 0x71, 0x4b, 0x69, + 0x63, 0x6b, 0x4f, 0x75, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, + 0x61, 0x79, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x6c, + 0x61, 0x79, 0x65, 0x72, 0x49, 0x64, 0x22, 0x3b, 0x0a, 0x0d, 0x52, 0x65, 0x71, 0x47, 0x61, 0x6d, + 0x65, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x12, 0x0a, 0x04, 0x63, 0x68, 0x69, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, + 0x68, 0x69, 0x70, 0x22, 0x0f, 0x0a, 0x0d, 0x52, 0x65, 0x73, 0x47, 0x61, 0x6d, 0x65, 0x41, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x0f, 0x0a, 0x0d, 0x52, 0x65, 0x71, 0x47, 0x61, 0x6d, 0x65, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x8b, 0x01, 0x0a, 0x0d, 0x52, 0x65, 0x73, 0x47, 0x61, 0x6d, + 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x6e, 0x47, 0x61, 0x6d, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x6e, 0x47, 0x61, 0x6d, 0x65, 0x12, + 0x18, 0x0a, 0x07, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x4e, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x07, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x4e, 0x6f, 0x12, 0x1c, 0x0a, 0x09, 0x67, 0x61, 0x6d, + 0x65, 0x53, 0x74, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x67, 0x61, + 0x6d, 0x65, 0x53, 0x74, 0x61, 0x67, 0x65, 0x12, 0x2a, 0x0a, 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, + 0x72, 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x54, + 0x61, 0x62, 0x6c, 0x65, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x52, 0x07, 0x70, 0x6c, 0x61, 0x79, + 0x65, 0x72, 0x73, 0x22, 0xfd, 0x01, 0x0a, 0x0b, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x6c, 0x61, + 0x79, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x62, 0x6f, 0x74, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x05, 0x72, 0x6f, 0x62, 0x6f, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, 0x12, 0x0a, + 0x04, 0x63, 0x68, 0x69, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x68, 0x69, + 0x70, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x61, 0x73, + 0x74, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x6d, 0x61, 0x73, 0x74, 0x65, + 0x72, 0x12, 0x25, 0x0a, 0x08, 0x68, 0x61, 0x6e, 0x64, 0x43, 0x61, 0x72, 0x64, 0x18, 0x08, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x61, 0x72, 0x64, 0x52, 0x08, + 0x68, 0x61, 0x6e, 0x64, 0x43, 0x61, 0x72, 0x64, 0x12, 0x29, 0x0a, 0x0a, 0x70, 0x75, 0x62, 0x6c, + 0x69, 0x63, 0x43, 0x61, 0x72, 0x64, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, + 0x70, 0x69, 0x2e, 0x43, 0x61, 0x72, 0x64, 0x52, 0x0a, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x43, + 0x61, 0x72, 0x64, 0x22, 0x2c, 0x0a, 0x04, 0x43, 0x61, 0x72, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x64, + 0x6f, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x64, 0x6f, 0x74, 0x12, 0x12, 0x0a, + 0x04, 0x73, 0x75, 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x73, 0x75, 0x69, + 0x74, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x61, 0x70, 0x69, 0x3b, 0x61, 0x70, 0x69, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -860,32 +1366,43 @@ func file_poker_proto_rawDescGZIP() []byte { return file_poker_proto_rawDescData } -var file_poker_proto_msgTypes = make([]protoimpl.MessageInfo, 15) +var file_poker_proto_msgTypes = make([]protoimpl.MessageInfo, 23) var file_poker_proto_goTypes = []interface{}{ - (*ProtoWrap)(nil), // 0: api.ProtoWrap - (*Ping)(nil), // 1: api.Ping - (*Pong)(nil), // 2: api.Pong - (*ResSuccess)(nil), // 3: api.ResSuccess - (*ResFail)(nil), // 4: api.ResFail - (*ReqIdentity)(nil), // 5: api.ReqIdentity - (*ResIdentity)(nil), // 6: api.ResIdentity - (*ReqLobbyView)(nil), // 7: api.ReqLobbyView - (*ResLobbyView)(nil), // 8: api.ResLobbyView - (*LobbyTable)(nil), // 9: api.LobbyTable - (*LobbyPlayer)(nil), // 10: api.LobbyPlayer - (*ReqCreateTable)(nil), // 11: api.ReqCreateTable - (*ResCreateTable)(nil), // 12: api.ResCreateTable - (*ReqJoinTable)(nil), // 13: api.ReqJoinTable - (*ResJoinTable)(nil), // 14: api.ResJoinTable + (*ProtoWrap)(nil), // 0: api.ProtoWrap + (*Ping)(nil), // 1: api.Ping + (*Pong)(nil), // 2: api.Pong + (*ResSuccess)(nil), // 3: api.ResSuccess + (*ResFail)(nil), // 4: api.ResFail + (*ReqIdentity)(nil), // 5: api.ReqIdentity + (*ResIdentity)(nil), // 6: api.ResIdentity + (*ReqLobbyView)(nil), // 7: api.ReqLobbyView + (*ResLobbyView)(nil), // 8: api.ResLobbyView + (*LobbyTable)(nil), // 9: api.LobbyTable + (*LobbyPlayer)(nil), // 10: api.LobbyPlayer + (*ReqCreateTable)(nil), // 11: api.ReqCreateTable + (*ResCreateTable)(nil), // 12: api.ResCreateTable + (*ReqJoinTable)(nil), // 13: api.ReqJoinTable + (*ReqLeaveTable)(nil), // 14: api.ReqLeaveTable + (*ReqReadyStart)(nil), // 15: api.ReqReadyStart + (*ReqKickOutTable)(nil), // 16: api.ReqKickOutTable + (*ReqGameAction)(nil), // 17: api.ReqGameAction + (*ResGameAction)(nil), // 18: api.ResGameAction + (*ReqGameStatus)(nil), // 19: api.ReqGameStatus + (*ResGameStatus)(nil), // 20: api.ResGameStatus + (*TablePlayer)(nil), // 21: api.TablePlayer + (*Card)(nil), // 22: api.Card } var file_poker_proto_depIdxs = []int32{ 9, // 0: api.ResLobbyView.tables:type_name -> api.LobbyTable 10, // 1: api.LobbyTable.players:type_name -> api.LobbyPlayer - 2, // [2:2] is the sub-list for method output_type - 2, // [2:2] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 21, // 2: api.ResGameStatus.players:type_name -> api.TablePlayer + 22, // 3: api.TablePlayer.handCard:type_name -> api.Card + 22, // 4: api.TablePlayer.publicCard:type_name -> api.Card + 5, // [5:5] is the sub-list for method output_type + 5, // [5:5] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_poker_proto_init() } @@ -1063,7 +1580,103 @@ func file_poker_proto_init() { } } file_poker_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ResJoinTable); i { + switch v := v.(*ReqLeaveTable); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_poker_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReqReadyStart); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_poker_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReqKickOutTable); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_poker_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReqGameAction); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_poker_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ResGameAction); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_poker_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReqGameStatus); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_poker_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ResGameStatus); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_poker_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TablePlayer); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_poker_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Card); i { case 0: return &v.state case 1: @@ -1081,7 +1694,7 @@ func file_poker_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_poker_proto_rawDesc, NumEnums: 0, - NumMessages: 15, + NumMessages: 23, NumExtensions: 0, NumServices: 0, }, diff --git a/api/poker.proto b/api/poker.proto index 89dbf09..ca63493 100644 --- a/api/poker.proto +++ b/api/poker.proto @@ -85,6 +85,11 @@ message ReqJoinTable { int32 tableNo = 1; } +// 离开房间 +message ReqLeaveTable { + +} + // 玩家准备开始 message ReqReadyStart { } @@ -94,12 +99,12 @@ message ReqKickOutTable { int32 playerId = 1; } -message ReqAction { +message ReqGameAction { int32 action = 1; // 4下大盲注,5下小盲注,6跟注,7弃牌 int32 chip = 2; // 押注金额 } -message ResAction { +message ResGameAction { } @@ -121,7 +126,7 @@ message TablePlayer { string avatar = 4; int32 chip = 5; // 筹码 int32 status = 6; // 玩家状态: 1待准备开始,2已准备开始,已开始(3等待其他玩家动作,4待大盲注,5待小盲注,6待跟注,7已弃) - bool master = 7; // 是否房主 + bool master = 7; // 是否房主` repeated Card handCard = 8; // 手牌 repeated Card publicCard = 9; // 公共牌 } diff --git a/api/proto.js b/api/proto.js index e9b96bb..0cab031 100644 --- a/api/proto.js +++ b/api/proto.js @@ -2980,6 +2980,7 @@ export const api = $root.api = (() => { * Properties of a ReqJoinTable. * @memberof api * @interface IReqJoinTable + * @property {number|null} [tableNo] ReqJoinTable tableNo */ /** @@ -2997,6 +2998,14 @@ export const api = $root.api = (() => { this[keys[i]] = properties[keys[i]]; } + /** + * ReqJoinTable tableNo. + * @member {number} tableNo + * @memberof api.ReqJoinTable + * @instance + */ + ReqJoinTable.prototype.tableNo = 0; + /** * Creates a new ReqJoinTable instance using the specified properties. * @function create @@ -3021,6 +3030,8 @@ export const api = $root.api = (() => { ReqJoinTable.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); + if (message.tableNo != null && Object.hasOwnProperty.call(message, "tableNo")) + writer.uint32(/* id 1, wireType 0 =*/8).int32(message.tableNo); return writer; }; @@ -3055,6 +3066,10 @@ export const api = $root.api = (() => { while (reader.pos < end) { let tag = reader.uint32(); switch (tag >>> 3) { + case 1: { + message.tableNo = reader.int32(); + break; + } default: reader.skipType(tag & 7); break; @@ -3090,6 +3105,9 @@ export const api = $root.api = (() => { ReqJoinTable.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; + if (message.tableNo != null && message.hasOwnProperty("tableNo")) + if (!$util.isInteger(message.tableNo)) + return "tableNo: integer expected"; return null; }; @@ -3104,7 +3122,10 @@ export const api = $root.api = (() => { ReqJoinTable.fromObject = function fromObject(object) { if (object instanceof $root.api.ReqJoinTable) return object; - return new $root.api.ReqJoinTable(); + let message = new $root.api.ReqJoinTable(); + if (object.tableNo != null) + message.tableNo = object.tableNo | 0; + return message; }; /** @@ -3116,8 +3137,15 @@ export const api = $root.api = (() => { * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ - ReqJoinTable.toObject = function toObject() { - return {}; + ReqJoinTable.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.defaults) + object.tableNo = 0; + if (message.tableNo != null && message.hasOwnProperty("tableNo")) + object.tableNo = message.tableNo; + return object; }; /** @@ -3149,23 +3177,198 @@ export const api = $root.api = (() => { return ReqJoinTable; })(); - api.ResJoinTable = (function() { + api.ReqLeaveTable = (function() { + + /** + * Properties of a ReqLeaveTable. + * @memberof api + * @interface IReqLeaveTable + */ + + /** + * Constructs a new ReqLeaveTable. + * @memberof api + * @classdesc Represents a ReqLeaveTable. + * @implements IReqLeaveTable + * @constructor + * @param {api.IReqLeaveTable=} [properties] Properties to set + */ + function ReqLeaveTable(properties) { + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Creates a new ReqLeaveTable instance using the specified properties. + * @function create + * @memberof api.ReqLeaveTable + * @static + * @param {api.IReqLeaveTable=} [properties] Properties to set + * @returns {api.ReqLeaveTable} ReqLeaveTable instance + */ + ReqLeaveTable.create = function create(properties) { + return new ReqLeaveTable(properties); + }; + + /** + * Encodes the specified ReqLeaveTable message. Does not implicitly {@link api.ReqLeaveTable.verify|verify} messages. + * @function encode + * @memberof api.ReqLeaveTable + * @static + * @param {api.IReqLeaveTable} message ReqLeaveTable message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ReqLeaveTable.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + return writer; + }; + + /** + * Encodes the specified ReqLeaveTable message, length delimited. Does not implicitly {@link api.ReqLeaveTable.verify|verify} messages. + * @function encodeDelimited + * @memberof api.ReqLeaveTable + * @static + * @param {api.IReqLeaveTable} message ReqLeaveTable message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ReqLeaveTable.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a ReqLeaveTable message from the specified reader or buffer. + * @function decode + * @memberof api.ReqLeaveTable + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {api.ReqLeaveTable} ReqLeaveTable + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ReqLeaveTable.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.api.ReqLeaveTable(); + while (reader.pos < end) { + let tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a ReqLeaveTable message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof api.ReqLeaveTable + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {api.ReqLeaveTable} ReqLeaveTable + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ReqLeaveTable.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a ReqLeaveTable message. + * @function verify + * @memberof api.ReqLeaveTable + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ReqLeaveTable.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + return null; + }; + + /** + * Creates a ReqLeaveTable message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof api.ReqLeaveTable + * @static + * @param {Object.} object Plain object + * @returns {api.ReqLeaveTable} ReqLeaveTable + */ + ReqLeaveTable.fromObject = function fromObject(object) { + if (object instanceof $root.api.ReqLeaveTable) + return object; + return new $root.api.ReqLeaveTable(); + }; + + /** + * Creates a plain object from a ReqLeaveTable message. Also converts values to other types if specified. + * @function toObject + * @memberof api.ReqLeaveTable + * @static + * @param {api.ReqLeaveTable} message ReqLeaveTable + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ReqLeaveTable.toObject = function toObject() { + return {}; + }; + + /** + * Converts this ReqLeaveTable to JSON. + * @function toJSON + * @memberof api.ReqLeaveTable + * @instance + * @returns {Object.} JSON object + */ + ReqLeaveTable.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for ReqLeaveTable + * @function getTypeUrl + * @memberof api.ReqLeaveTable + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + ReqLeaveTable.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/api.ReqLeaveTable"; + }; + + return ReqLeaveTable; + })(); + + api.ReqReadyStart = (function() { /** - * Properties of a ResJoinTable. + * Properties of a ReqReadyStart. * @memberof api - * @interface IResJoinTable + * @interface IReqReadyStart */ /** - * Constructs a new ResJoinTable. + * Constructs a new ReqReadyStart. * @memberof api - * @classdesc Represents a ResJoinTable. - * @implements IResJoinTable + * @classdesc Represents a ReqReadyStart. + * @implements IReqReadyStart * @constructor - * @param {api.IResJoinTable=} [properties] Properties to set + * @param {api.IReqReadyStart=} [properties] Properties to set */ - function ResJoinTable(properties) { + function ReqReadyStart(properties) { if (properties) for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -3173,60 +3376,60 @@ export const api = $root.api = (() => { } /** - * Creates a new ResJoinTable instance using the specified properties. + * Creates a new ReqReadyStart instance using the specified properties. * @function create - * @memberof api.ResJoinTable + * @memberof api.ReqReadyStart * @static - * @param {api.IResJoinTable=} [properties] Properties to set - * @returns {api.ResJoinTable} ResJoinTable instance + * @param {api.IReqReadyStart=} [properties] Properties to set + * @returns {api.ReqReadyStart} ReqReadyStart instance */ - ResJoinTable.create = function create(properties) { - return new ResJoinTable(properties); + ReqReadyStart.create = function create(properties) { + return new ReqReadyStart(properties); }; /** - * Encodes the specified ResJoinTable message. Does not implicitly {@link api.ResJoinTable.verify|verify} messages. + * Encodes the specified ReqReadyStart message. Does not implicitly {@link api.ReqReadyStart.verify|verify} messages. * @function encode - * @memberof api.ResJoinTable + * @memberof api.ReqReadyStart * @static - * @param {api.IResJoinTable} message ResJoinTable message or plain object to encode + * @param {api.IReqReadyStart} message ReqReadyStart message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - ResJoinTable.encode = function encode(message, writer) { + ReqReadyStart.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); return writer; }; /** - * Encodes the specified ResJoinTable message, length delimited. Does not implicitly {@link api.ResJoinTable.verify|verify} messages. + * Encodes the specified ReqReadyStart message, length delimited. Does not implicitly {@link api.ReqReadyStart.verify|verify} messages. * @function encodeDelimited - * @memberof api.ResJoinTable + * @memberof api.ReqReadyStart * @static - * @param {api.IResJoinTable} message ResJoinTable message or plain object to encode + * @param {api.IReqReadyStart} message ReqReadyStart message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - ResJoinTable.encodeDelimited = function encodeDelimited(message, writer) { + ReqReadyStart.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** - * Decodes a ResJoinTable message from the specified reader or buffer. + * Decodes a ReqReadyStart message from the specified reader or buffer. * @function decode - * @memberof api.ResJoinTable + * @memberof api.ReqReadyStart * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand - * @returns {api.ResJoinTable} ResJoinTable + * @returns {api.ReqReadyStart} ReqReadyStart * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - ResJoinTable.decode = function decode(reader, length) { + ReqReadyStart.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - let end = length === undefined ? reader.len : reader.pos + length, message = new $root.api.ResJoinTable(); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.api.ReqReadyStart(); while (reader.pos < end) { let tag = reader.uint32(); switch (tag >>> 3) { @@ -3239,89 +3442,1837 @@ export const api = $root.api = (() => { }; /** - * Decodes a ResJoinTable message from the specified reader or buffer, length delimited. + * Decodes a ReqReadyStart message from the specified reader or buffer, length delimited. * @function decodeDelimited - * @memberof api.ResJoinTable + * @memberof api.ReqReadyStart * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @returns {api.ResJoinTable} ResJoinTable + * @returns {api.ReqReadyStart} ReqReadyStart * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - ResJoinTable.decodeDelimited = function decodeDelimited(reader) { + ReqReadyStart.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** - * Verifies a ResJoinTable message. + * Verifies a ReqReadyStart message. * @function verify - * @memberof api.ResJoinTable + * @memberof api.ReqReadyStart * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ - ResJoinTable.verify = function verify(message) { + ReqReadyStart.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; return null; }; /** - * Creates a ResJoinTable message from a plain object. Also converts values to their respective internal types. + * Creates a ReqReadyStart message from a plain object. Also converts values to their respective internal types. * @function fromObject - * @memberof api.ResJoinTable + * @memberof api.ReqReadyStart * @static * @param {Object.} object Plain object - * @returns {api.ResJoinTable} ResJoinTable + * @returns {api.ReqReadyStart} ReqReadyStart */ - ResJoinTable.fromObject = function fromObject(object) { - if (object instanceof $root.api.ResJoinTable) + ReqReadyStart.fromObject = function fromObject(object) { + if (object instanceof $root.api.ReqReadyStart) return object; - return new $root.api.ResJoinTable(); + return new $root.api.ReqReadyStart(); }; /** - * Creates a plain object from a ResJoinTable message. Also converts values to other types if specified. + * Creates a plain object from a ReqReadyStart message. Also converts values to other types if specified. * @function toObject - * @memberof api.ResJoinTable + * @memberof api.ReqReadyStart * @static - * @param {api.ResJoinTable} message ResJoinTable + * @param {api.ReqReadyStart} message ReqReadyStart * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ - ResJoinTable.toObject = function toObject() { + ReqReadyStart.toObject = function toObject() { return {}; }; /** - * Converts this ResJoinTable to JSON. + * Converts this ReqReadyStart to JSON. + * @function toJSON + * @memberof api.ReqReadyStart + * @instance + * @returns {Object.} JSON object + */ + ReqReadyStart.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for ReqReadyStart + * @function getTypeUrl + * @memberof api.ReqReadyStart + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + ReqReadyStart.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/api.ReqReadyStart"; + }; + + return ReqReadyStart; + })(); + + api.ReqKickOutTable = (function() { + + /** + * Properties of a ReqKickOutTable. + * @memberof api + * @interface IReqKickOutTable + * @property {number|null} [playerId] ReqKickOutTable playerId + */ + + /** + * Constructs a new ReqKickOutTable. + * @memberof api + * @classdesc Represents a ReqKickOutTable. + * @implements IReqKickOutTable + * @constructor + * @param {api.IReqKickOutTable=} [properties] Properties to set + */ + function ReqKickOutTable(properties) { + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * ReqKickOutTable playerId. + * @member {number} playerId + * @memberof api.ReqKickOutTable + * @instance + */ + ReqKickOutTable.prototype.playerId = 0; + + /** + * Creates a new ReqKickOutTable instance using the specified properties. + * @function create + * @memberof api.ReqKickOutTable + * @static + * @param {api.IReqKickOutTable=} [properties] Properties to set + * @returns {api.ReqKickOutTable} ReqKickOutTable instance + */ + ReqKickOutTable.create = function create(properties) { + return new ReqKickOutTable(properties); + }; + + /** + * Encodes the specified ReqKickOutTable message. Does not implicitly {@link api.ReqKickOutTable.verify|verify} messages. + * @function encode + * @memberof api.ReqKickOutTable + * @static + * @param {api.IReqKickOutTable} message ReqKickOutTable message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ReqKickOutTable.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.playerId != null && Object.hasOwnProperty.call(message, "playerId")) + writer.uint32(/* id 1, wireType 0 =*/8).int32(message.playerId); + return writer; + }; + + /** + * Encodes the specified ReqKickOutTable message, length delimited. Does not implicitly {@link api.ReqKickOutTable.verify|verify} messages. + * @function encodeDelimited + * @memberof api.ReqKickOutTable + * @static + * @param {api.IReqKickOutTable} message ReqKickOutTable message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ReqKickOutTable.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a ReqKickOutTable message from the specified reader or buffer. + * @function decode + * @memberof api.ReqKickOutTable + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {api.ReqKickOutTable} ReqKickOutTable + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ReqKickOutTable.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.api.ReqKickOutTable(); + while (reader.pos < end) { + let tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.playerId = reader.int32(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a ReqKickOutTable message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof api.ReqKickOutTable + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {api.ReqKickOutTable} ReqKickOutTable + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ReqKickOutTable.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a ReqKickOutTable message. + * @function verify + * @memberof api.ReqKickOutTable + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ReqKickOutTable.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.playerId != null && message.hasOwnProperty("playerId")) + if (!$util.isInteger(message.playerId)) + return "playerId: integer expected"; + return null; + }; + + /** + * Creates a ReqKickOutTable message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof api.ReqKickOutTable + * @static + * @param {Object.} object Plain object + * @returns {api.ReqKickOutTable} ReqKickOutTable + */ + ReqKickOutTable.fromObject = function fromObject(object) { + if (object instanceof $root.api.ReqKickOutTable) + return object; + let message = new $root.api.ReqKickOutTable(); + if (object.playerId != null) + message.playerId = object.playerId | 0; + return message; + }; + + /** + * Creates a plain object from a ReqKickOutTable message. Also converts values to other types if specified. + * @function toObject + * @memberof api.ReqKickOutTable + * @static + * @param {api.ReqKickOutTable} message ReqKickOutTable + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ReqKickOutTable.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.defaults) + object.playerId = 0; + if (message.playerId != null && message.hasOwnProperty("playerId")) + object.playerId = message.playerId; + return object; + }; + + /** + * Converts this ReqKickOutTable to JSON. + * @function toJSON + * @memberof api.ReqKickOutTable + * @instance + * @returns {Object.} JSON object + */ + ReqKickOutTable.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for ReqKickOutTable + * @function getTypeUrl + * @memberof api.ReqKickOutTable + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + ReqKickOutTable.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/api.ReqKickOutTable"; + }; + + return ReqKickOutTable; + })(); + + api.ReqGameAction = (function() { + + /** + * Properties of a ReqGameAction. + * @memberof api + * @interface IReqGameAction + * @property {number|null} [action] ReqGameAction action + * @property {number|null} [chip] ReqGameAction chip + */ + + /** + * Constructs a new ReqGameAction. + * @memberof api + * @classdesc Represents a ReqGameAction. + * @implements IReqGameAction + * @constructor + * @param {api.IReqGameAction=} [properties] Properties to set + */ + function ReqGameAction(properties) { + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * ReqGameAction action. + * @member {number} action + * @memberof api.ReqGameAction + * @instance + */ + ReqGameAction.prototype.action = 0; + + /** + * ReqGameAction chip. + * @member {number} chip + * @memberof api.ReqGameAction + * @instance + */ + ReqGameAction.prototype.chip = 0; + + /** + * Creates a new ReqGameAction instance using the specified properties. + * @function create + * @memberof api.ReqGameAction + * @static + * @param {api.IReqGameAction=} [properties] Properties to set + * @returns {api.ReqGameAction} ReqGameAction instance + */ + ReqGameAction.create = function create(properties) { + return new ReqGameAction(properties); + }; + + /** + * Encodes the specified ReqGameAction message. Does not implicitly {@link api.ReqGameAction.verify|verify} messages. + * @function encode + * @memberof api.ReqGameAction + * @static + * @param {api.IReqGameAction} message ReqGameAction message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ReqGameAction.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.action != null && Object.hasOwnProperty.call(message, "action")) + writer.uint32(/* id 1, wireType 0 =*/8).int32(message.action); + if (message.chip != null && Object.hasOwnProperty.call(message, "chip")) + writer.uint32(/* id 2, wireType 0 =*/16).int32(message.chip); + return writer; + }; + + /** + * Encodes the specified ReqGameAction message, length delimited. Does not implicitly {@link api.ReqGameAction.verify|verify} messages. + * @function encodeDelimited + * @memberof api.ReqGameAction + * @static + * @param {api.IReqGameAction} message ReqGameAction message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ReqGameAction.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a ReqGameAction message from the specified reader or buffer. + * @function decode + * @memberof api.ReqGameAction + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {api.ReqGameAction} ReqGameAction + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ReqGameAction.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.api.ReqGameAction(); + while (reader.pos < end) { + let tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.action = reader.int32(); + break; + } + case 2: { + message.chip = reader.int32(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a ReqGameAction message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof api.ReqGameAction + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {api.ReqGameAction} ReqGameAction + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ReqGameAction.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a ReqGameAction message. + * @function verify + * @memberof api.ReqGameAction + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ReqGameAction.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.action != null && message.hasOwnProperty("action")) + if (!$util.isInteger(message.action)) + return "action: integer expected"; + if (message.chip != null && message.hasOwnProperty("chip")) + if (!$util.isInteger(message.chip)) + return "chip: integer expected"; + return null; + }; + + /** + * Creates a ReqGameAction message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof api.ReqGameAction + * @static + * @param {Object.} object Plain object + * @returns {api.ReqGameAction} ReqGameAction + */ + ReqGameAction.fromObject = function fromObject(object) { + if (object instanceof $root.api.ReqGameAction) + return object; + let message = new $root.api.ReqGameAction(); + if (object.action != null) + message.action = object.action | 0; + if (object.chip != null) + message.chip = object.chip | 0; + return message; + }; + + /** + * Creates a plain object from a ReqGameAction message. Also converts values to other types if specified. + * @function toObject + * @memberof api.ReqGameAction + * @static + * @param {api.ReqGameAction} message ReqGameAction + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ReqGameAction.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.defaults) { + object.action = 0; + object.chip = 0; + } + if (message.action != null && message.hasOwnProperty("action")) + object.action = message.action; + if (message.chip != null && message.hasOwnProperty("chip")) + object.chip = message.chip; + return object; + }; + + /** + * Converts this ReqGameAction to JSON. + * @function toJSON + * @memberof api.ReqGameAction + * @instance + * @returns {Object.} JSON object + */ + ReqGameAction.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for ReqGameAction + * @function getTypeUrl + * @memberof api.ReqGameAction + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + ReqGameAction.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/api.ReqGameAction"; + }; + + return ReqGameAction; + })(); + + api.ResGameAction = (function() { + + /** + * Properties of a ResGameAction. + * @memberof api + * @interface IResGameAction + */ + + /** + * Constructs a new ResGameAction. + * @memberof api + * @classdesc Represents a ResGameAction. + * @implements IResGameAction + * @constructor + * @param {api.IResGameAction=} [properties] Properties to set + */ + function ResGameAction(properties) { + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Creates a new ResGameAction instance using the specified properties. + * @function create + * @memberof api.ResGameAction + * @static + * @param {api.IResGameAction=} [properties] Properties to set + * @returns {api.ResGameAction} ResGameAction instance + */ + ResGameAction.create = function create(properties) { + return new ResGameAction(properties); + }; + + /** + * Encodes the specified ResGameAction message. Does not implicitly {@link api.ResGameAction.verify|verify} messages. + * @function encode + * @memberof api.ResGameAction + * @static + * @param {api.IResGameAction} message ResGameAction message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ResGameAction.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + return writer; + }; + + /** + * Encodes the specified ResGameAction message, length delimited. Does not implicitly {@link api.ResGameAction.verify|verify} messages. + * @function encodeDelimited + * @memberof api.ResGameAction + * @static + * @param {api.IResGameAction} message ResGameAction message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ResGameAction.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a ResGameAction message from the specified reader or buffer. + * @function decode + * @memberof api.ResGameAction + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {api.ResGameAction} ResGameAction + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ResGameAction.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.api.ResGameAction(); + while (reader.pos < end) { + let tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a ResGameAction message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof api.ResGameAction + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {api.ResGameAction} ResGameAction + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ResGameAction.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a ResGameAction message. + * @function verify + * @memberof api.ResGameAction + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ResGameAction.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + return null; + }; + + /** + * Creates a ResGameAction message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof api.ResGameAction + * @static + * @param {Object.} object Plain object + * @returns {api.ResGameAction} ResGameAction + */ + ResGameAction.fromObject = function fromObject(object) { + if (object instanceof $root.api.ResGameAction) + return object; + return new $root.api.ResGameAction(); + }; + + /** + * Creates a plain object from a ResGameAction message. Also converts values to other types if specified. + * @function toObject + * @memberof api.ResGameAction + * @static + * @param {api.ResGameAction} message ResGameAction + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ResGameAction.toObject = function toObject() { + return {}; + }; + + /** + * Converts this ResGameAction to JSON. + * @function toJSON + * @memberof api.ResGameAction + * @instance + * @returns {Object.} JSON object + */ + ResGameAction.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for ResGameAction + * @function getTypeUrl + * @memberof api.ResGameAction + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + ResGameAction.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/api.ResGameAction"; + }; + + return ResGameAction; + })(); + + api.ReqGameStatus = (function() { + + /** + * Properties of a ReqGameStatus. + * @memberof api + * @interface IReqGameStatus + */ + + /** + * Constructs a new ReqGameStatus. + * @memberof api + * @classdesc Represents a ReqGameStatus. + * @implements IReqGameStatus + * @constructor + * @param {api.IReqGameStatus=} [properties] Properties to set + */ + function ReqGameStatus(properties) { + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Creates a new ReqGameStatus instance using the specified properties. + * @function create + * @memberof api.ReqGameStatus + * @static + * @param {api.IReqGameStatus=} [properties] Properties to set + * @returns {api.ReqGameStatus} ReqGameStatus instance + */ + ReqGameStatus.create = function create(properties) { + return new ReqGameStatus(properties); + }; + + /** + * Encodes the specified ReqGameStatus message. Does not implicitly {@link api.ReqGameStatus.verify|verify} messages. + * @function encode + * @memberof api.ReqGameStatus + * @static + * @param {api.IReqGameStatus} message ReqGameStatus message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ReqGameStatus.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + return writer; + }; + + /** + * Encodes the specified ReqGameStatus message, length delimited. Does not implicitly {@link api.ReqGameStatus.verify|verify} messages. + * @function encodeDelimited + * @memberof api.ReqGameStatus + * @static + * @param {api.IReqGameStatus} message ReqGameStatus message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ReqGameStatus.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a ReqGameStatus message from the specified reader or buffer. + * @function decode + * @memberof api.ReqGameStatus + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {api.ReqGameStatus} ReqGameStatus + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ReqGameStatus.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.api.ReqGameStatus(); + while (reader.pos < end) { + let tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a ReqGameStatus message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof api.ReqGameStatus + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {api.ReqGameStatus} ReqGameStatus + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ReqGameStatus.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a ReqGameStatus message. + * @function verify + * @memberof api.ReqGameStatus + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ReqGameStatus.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + return null; + }; + + /** + * Creates a ReqGameStatus message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof api.ReqGameStatus + * @static + * @param {Object.} object Plain object + * @returns {api.ReqGameStatus} ReqGameStatus + */ + ReqGameStatus.fromObject = function fromObject(object) { + if (object instanceof $root.api.ReqGameStatus) + return object; + return new $root.api.ReqGameStatus(); + }; + + /** + * Creates a plain object from a ReqGameStatus message. Also converts values to other types if specified. + * @function toObject + * @memberof api.ReqGameStatus + * @static + * @param {api.ReqGameStatus} message ReqGameStatus + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ReqGameStatus.toObject = function toObject() { + return {}; + }; + + /** + * Converts this ReqGameStatus to JSON. + * @function toJSON + * @memberof api.ReqGameStatus + * @instance + * @returns {Object.} JSON object + */ + ReqGameStatus.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for ReqGameStatus + * @function getTypeUrl + * @memberof api.ReqGameStatus + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + ReqGameStatus.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/api.ReqGameStatus"; + }; + + return ReqGameStatus; + })(); + + api.ResGameStatus = (function() { + + /** + * Properties of a ResGameStatus. + * @memberof api + * @interface IResGameStatus + * @property {boolean|null} [inGame] ResGameStatus inGame + * @property {number|null} [tableNo] ResGameStatus tableNo + * @property {number|null} [gameStage] ResGameStatus gameStage + * @property {Array.|null} [players] ResGameStatus players + */ + + /** + * Constructs a new ResGameStatus. + * @memberof api + * @classdesc Represents a ResGameStatus. + * @implements IResGameStatus + * @constructor + * @param {api.IResGameStatus=} [properties] Properties to set + */ + function ResGameStatus(properties) { + this.players = []; + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * ResGameStatus inGame. + * @member {boolean} inGame + * @memberof api.ResGameStatus + * @instance + */ + ResGameStatus.prototype.inGame = false; + + /** + * ResGameStatus tableNo. + * @member {number} tableNo + * @memberof api.ResGameStatus + * @instance + */ + ResGameStatus.prototype.tableNo = 0; + + /** + * ResGameStatus gameStage. + * @member {number} gameStage + * @memberof api.ResGameStatus + * @instance + */ + ResGameStatus.prototype.gameStage = 0; + + /** + * ResGameStatus players. + * @member {Array.} players + * @memberof api.ResGameStatus + * @instance + */ + ResGameStatus.prototype.players = $util.emptyArray; + + /** + * Creates a new ResGameStatus instance using the specified properties. + * @function create + * @memberof api.ResGameStatus + * @static + * @param {api.IResGameStatus=} [properties] Properties to set + * @returns {api.ResGameStatus} ResGameStatus instance + */ + ResGameStatus.create = function create(properties) { + return new ResGameStatus(properties); + }; + + /** + * Encodes the specified ResGameStatus message. Does not implicitly {@link api.ResGameStatus.verify|verify} messages. + * @function encode + * @memberof api.ResGameStatus + * @static + * @param {api.IResGameStatus} message ResGameStatus message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ResGameStatus.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.inGame != null && Object.hasOwnProperty.call(message, "inGame")) + writer.uint32(/* id 1, wireType 0 =*/8).bool(message.inGame); + if (message.tableNo != null && Object.hasOwnProperty.call(message, "tableNo")) + writer.uint32(/* id 2, wireType 0 =*/16).int32(message.tableNo); + if (message.gameStage != null && Object.hasOwnProperty.call(message, "gameStage")) + writer.uint32(/* id 3, wireType 0 =*/24).int32(message.gameStage); + if (message.players != null && message.players.length) + for (let i = 0; i < message.players.length; ++i) + $root.api.TablePlayer.encode(message.players[i], writer.uint32(/* id 10, wireType 2 =*/82).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified ResGameStatus message, length delimited. Does not implicitly {@link api.ResGameStatus.verify|verify} messages. + * @function encodeDelimited + * @memberof api.ResGameStatus + * @static + * @param {api.IResGameStatus} message ResGameStatus message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ResGameStatus.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a ResGameStatus message from the specified reader or buffer. + * @function decode + * @memberof api.ResGameStatus + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {api.ResGameStatus} ResGameStatus + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ResGameStatus.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.api.ResGameStatus(); + while (reader.pos < end) { + let tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.inGame = reader.bool(); + break; + } + case 2: { + message.tableNo = reader.int32(); + break; + } + case 3: { + message.gameStage = reader.int32(); + break; + } + case 10: { + if (!(message.players && message.players.length)) + message.players = []; + message.players.push($root.api.TablePlayer.decode(reader, reader.uint32())); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a ResGameStatus message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof api.ResGameStatus + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {api.ResGameStatus} ResGameStatus + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ResGameStatus.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a ResGameStatus message. + * @function verify + * @memberof api.ResGameStatus + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ResGameStatus.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.inGame != null && message.hasOwnProperty("inGame")) + if (typeof message.inGame !== "boolean") + return "inGame: boolean expected"; + if (message.tableNo != null && message.hasOwnProperty("tableNo")) + if (!$util.isInteger(message.tableNo)) + return "tableNo: integer expected"; + if (message.gameStage != null && message.hasOwnProperty("gameStage")) + if (!$util.isInteger(message.gameStage)) + return "gameStage: integer expected"; + if (message.players != null && message.hasOwnProperty("players")) { + if (!Array.isArray(message.players)) + return "players: array expected"; + for (let i = 0; i < message.players.length; ++i) { + let error = $root.api.TablePlayer.verify(message.players[i]); + if (error) + return "players." + error; + } + } + return null; + }; + + /** + * Creates a ResGameStatus message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof api.ResGameStatus + * @static + * @param {Object.} object Plain object + * @returns {api.ResGameStatus} ResGameStatus + */ + ResGameStatus.fromObject = function fromObject(object) { + if (object instanceof $root.api.ResGameStatus) + return object; + let message = new $root.api.ResGameStatus(); + if (object.inGame != null) + message.inGame = Boolean(object.inGame); + if (object.tableNo != null) + message.tableNo = object.tableNo | 0; + if (object.gameStage != null) + message.gameStage = object.gameStage | 0; + if (object.players) { + if (!Array.isArray(object.players)) + throw TypeError(".api.ResGameStatus.players: array expected"); + message.players = []; + for (let i = 0; i < object.players.length; ++i) { + if (typeof object.players[i] !== "object") + throw TypeError(".api.ResGameStatus.players: object expected"); + message.players[i] = $root.api.TablePlayer.fromObject(object.players[i]); + } + } + return message; + }; + + /** + * Creates a plain object from a ResGameStatus message. Also converts values to other types if specified. + * @function toObject + * @memberof api.ResGameStatus + * @static + * @param {api.ResGameStatus} message ResGameStatus + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ResGameStatus.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.arrays || options.defaults) + object.players = []; + if (options.defaults) { + object.inGame = false; + object.tableNo = 0; + object.gameStage = 0; + } + if (message.inGame != null && message.hasOwnProperty("inGame")) + object.inGame = message.inGame; + if (message.tableNo != null && message.hasOwnProperty("tableNo")) + object.tableNo = message.tableNo; + if (message.gameStage != null && message.hasOwnProperty("gameStage")) + object.gameStage = message.gameStage; + if (message.players && message.players.length) { + object.players = []; + for (let j = 0; j < message.players.length; ++j) + object.players[j] = $root.api.TablePlayer.toObject(message.players[j], options); + } + return object; + }; + + /** + * Converts this ResGameStatus to JSON. + * @function toJSON + * @memberof api.ResGameStatus + * @instance + * @returns {Object.} JSON object + */ + ResGameStatus.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for ResGameStatus + * @function getTypeUrl + * @memberof api.ResGameStatus + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + ResGameStatus.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/api.ResGameStatus"; + }; + + return ResGameStatus; + })(); + + api.TablePlayer = (function() { + + /** + * Properties of a TablePlayer. + * @memberof api + * @interface ITablePlayer + * @property {boolean|null} [robot] TablePlayer robot + * @property {number|Long|null} [id] TablePlayer id + * @property {string|null} [username] TablePlayer username + * @property {string|null} [avatar] TablePlayer avatar + * @property {number|null} [chip] TablePlayer chip + * @property {number|null} [status] TablePlayer status + * @property {boolean|null} [master] TablePlayer master + * @property {Array.|null} [handCard] TablePlayer handCard + * @property {Array.|null} [publicCard] TablePlayer publicCard + */ + + /** + * Constructs a new TablePlayer. + * @memberof api + * @classdesc Represents a TablePlayer. + * @implements ITablePlayer + * @constructor + * @param {api.ITablePlayer=} [properties] Properties to set + */ + function TablePlayer(properties) { + this.handCard = []; + this.publicCard = []; + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * TablePlayer robot. + * @member {boolean} robot + * @memberof api.TablePlayer + * @instance + */ + TablePlayer.prototype.robot = false; + + /** + * TablePlayer id. + * @member {number|Long} id + * @memberof api.TablePlayer + * @instance + */ + TablePlayer.prototype.id = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * TablePlayer username. + * @member {string} username + * @memberof api.TablePlayer + * @instance + */ + TablePlayer.prototype.username = ""; + + /** + * TablePlayer avatar. + * @member {string} avatar + * @memberof api.TablePlayer + * @instance + */ + TablePlayer.prototype.avatar = ""; + + /** + * TablePlayer chip. + * @member {number} chip + * @memberof api.TablePlayer + * @instance + */ + TablePlayer.prototype.chip = 0; + + /** + * TablePlayer status. + * @member {number} status + * @memberof api.TablePlayer + * @instance + */ + TablePlayer.prototype.status = 0; + + /** + * TablePlayer master. + * @member {boolean} master + * @memberof api.TablePlayer + * @instance + */ + TablePlayer.prototype.master = false; + + /** + * TablePlayer handCard. + * @member {Array.} handCard + * @memberof api.TablePlayer + * @instance + */ + TablePlayer.prototype.handCard = $util.emptyArray; + + /** + * TablePlayer publicCard. + * @member {Array.} publicCard + * @memberof api.TablePlayer + * @instance + */ + TablePlayer.prototype.publicCard = $util.emptyArray; + + /** + * Creates a new TablePlayer instance using the specified properties. + * @function create + * @memberof api.TablePlayer + * @static + * @param {api.ITablePlayer=} [properties] Properties to set + * @returns {api.TablePlayer} TablePlayer instance + */ + TablePlayer.create = function create(properties) { + return new TablePlayer(properties); + }; + + /** + * Encodes the specified TablePlayer message. Does not implicitly {@link api.TablePlayer.verify|verify} messages. + * @function encode + * @memberof api.TablePlayer + * @static + * @param {api.ITablePlayer} message TablePlayer message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TablePlayer.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.robot != null && Object.hasOwnProperty.call(message, "robot")) + writer.uint32(/* id 1, wireType 0 =*/8).bool(message.robot); + if (message.id != null && Object.hasOwnProperty.call(message, "id")) + writer.uint32(/* id 2, wireType 0 =*/16).int64(message.id); + if (message.username != null && Object.hasOwnProperty.call(message, "username")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.username); + if (message.avatar != null && Object.hasOwnProperty.call(message, "avatar")) + writer.uint32(/* id 4, wireType 2 =*/34).string(message.avatar); + if (message.chip != null && Object.hasOwnProperty.call(message, "chip")) + writer.uint32(/* id 5, wireType 0 =*/40).int32(message.chip); + if (message.status != null && Object.hasOwnProperty.call(message, "status")) + writer.uint32(/* id 6, wireType 0 =*/48).int32(message.status); + if (message.master != null && Object.hasOwnProperty.call(message, "master")) + writer.uint32(/* id 7, wireType 0 =*/56).bool(message.master); + if (message.handCard != null && message.handCard.length) + for (let i = 0; i < message.handCard.length; ++i) + $root.api.Card.encode(message.handCard[i], writer.uint32(/* id 8, wireType 2 =*/66).fork()).ldelim(); + if (message.publicCard != null && message.publicCard.length) + for (let i = 0; i < message.publicCard.length; ++i) + $root.api.Card.encode(message.publicCard[i], writer.uint32(/* id 9, wireType 2 =*/74).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified TablePlayer message, length delimited. Does not implicitly {@link api.TablePlayer.verify|verify} messages. + * @function encodeDelimited + * @memberof api.TablePlayer + * @static + * @param {api.ITablePlayer} message TablePlayer message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TablePlayer.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a TablePlayer message from the specified reader or buffer. + * @function decode + * @memberof api.TablePlayer + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {api.TablePlayer} TablePlayer + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TablePlayer.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.api.TablePlayer(); + while (reader.pos < end) { + let tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.robot = reader.bool(); + break; + } + case 2: { + message.id = reader.int64(); + break; + } + case 3: { + message.username = reader.string(); + break; + } + case 4: { + message.avatar = reader.string(); + break; + } + case 5: { + message.chip = reader.int32(); + break; + } + case 6: { + message.status = reader.int32(); + break; + } + case 7: { + message.master = reader.bool(); + break; + } + case 8: { + if (!(message.handCard && message.handCard.length)) + message.handCard = []; + message.handCard.push($root.api.Card.decode(reader, reader.uint32())); + break; + } + case 9: { + if (!(message.publicCard && message.publicCard.length)) + message.publicCard = []; + message.publicCard.push($root.api.Card.decode(reader, reader.uint32())); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a TablePlayer message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof api.TablePlayer + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {api.TablePlayer} TablePlayer + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TablePlayer.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a TablePlayer message. + * @function verify + * @memberof api.TablePlayer + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + TablePlayer.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.robot != null && message.hasOwnProperty("robot")) + if (typeof message.robot !== "boolean") + return "robot: boolean expected"; + if (message.id != null && message.hasOwnProperty("id")) + if (!$util.isInteger(message.id) && !(message.id && $util.isInteger(message.id.low) && $util.isInteger(message.id.high))) + return "id: integer|Long expected"; + if (message.username != null && message.hasOwnProperty("username")) + if (!$util.isString(message.username)) + return "username: string expected"; + if (message.avatar != null && message.hasOwnProperty("avatar")) + if (!$util.isString(message.avatar)) + return "avatar: string expected"; + if (message.chip != null && message.hasOwnProperty("chip")) + if (!$util.isInteger(message.chip)) + return "chip: integer expected"; + if (message.status != null && message.hasOwnProperty("status")) + if (!$util.isInteger(message.status)) + return "status: integer expected"; + if (message.master != null && message.hasOwnProperty("master")) + if (typeof message.master !== "boolean") + return "master: boolean expected"; + if (message.handCard != null && message.hasOwnProperty("handCard")) { + if (!Array.isArray(message.handCard)) + return "handCard: array expected"; + for (let i = 0; i < message.handCard.length; ++i) { + let error = $root.api.Card.verify(message.handCard[i]); + if (error) + return "handCard." + error; + } + } + if (message.publicCard != null && message.hasOwnProperty("publicCard")) { + if (!Array.isArray(message.publicCard)) + return "publicCard: array expected"; + for (let i = 0; i < message.publicCard.length; ++i) { + let error = $root.api.Card.verify(message.publicCard[i]); + if (error) + return "publicCard." + error; + } + } + return null; + }; + + /** + * Creates a TablePlayer message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof api.TablePlayer + * @static + * @param {Object.} object Plain object + * @returns {api.TablePlayer} TablePlayer + */ + TablePlayer.fromObject = function fromObject(object) { + if (object instanceof $root.api.TablePlayer) + return object; + let message = new $root.api.TablePlayer(); + if (object.robot != null) + message.robot = Boolean(object.robot); + if (object.id != null) + if ($util.Long) + (message.id = $util.Long.fromValue(object.id)).unsigned = false; + else if (typeof object.id === "string") + message.id = parseInt(object.id, 10); + else if (typeof object.id === "number") + message.id = object.id; + else if (typeof object.id === "object") + message.id = new $util.LongBits(object.id.low >>> 0, object.id.high >>> 0).toNumber(); + if (object.username != null) + message.username = String(object.username); + if (object.avatar != null) + message.avatar = String(object.avatar); + if (object.chip != null) + message.chip = object.chip | 0; + if (object.status != null) + message.status = object.status | 0; + if (object.master != null) + message.master = Boolean(object.master); + if (object.handCard) { + if (!Array.isArray(object.handCard)) + throw TypeError(".api.TablePlayer.handCard: array expected"); + message.handCard = []; + for (let i = 0; i < object.handCard.length; ++i) { + if (typeof object.handCard[i] !== "object") + throw TypeError(".api.TablePlayer.handCard: object expected"); + message.handCard[i] = $root.api.Card.fromObject(object.handCard[i]); + } + } + if (object.publicCard) { + if (!Array.isArray(object.publicCard)) + throw TypeError(".api.TablePlayer.publicCard: array expected"); + message.publicCard = []; + for (let i = 0; i < object.publicCard.length; ++i) { + if (typeof object.publicCard[i] !== "object") + throw TypeError(".api.TablePlayer.publicCard: object expected"); + message.publicCard[i] = $root.api.Card.fromObject(object.publicCard[i]); + } + } + return message; + }; + + /** + * Creates a plain object from a TablePlayer message. Also converts values to other types if specified. + * @function toObject + * @memberof api.TablePlayer + * @static + * @param {api.TablePlayer} message TablePlayer + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + TablePlayer.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.arrays || options.defaults) { + object.handCard = []; + object.publicCard = []; + } + if (options.defaults) { + object.robot = false; + if ($util.Long) { + let long = new $util.Long(0, 0, false); + object.id = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.id = options.longs === String ? "0" : 0; + object.username = ""; + object.avatar = ""; + object.chip = 0; + object.status = 0; + object.master = false; + } + if (message.robot != null && message.hasOwnProperty("robot")) + object.robot = message.robot; + if (message.id != null && message.hasOwnProperty("id")) + if (typeof message.id === "number") + object.id = options.longs === String ? String(message.id) : message.id; + else + object.id = options.longs === String ? $util.Long.prototype.toString.call(message.id) : options.longs === Number ? new $util.LongBits(message.id.low >>> 0, message.id.high >>> 0).toNumber() : message.id; + if (message.username != null && message.hasOwnProperty("username")) + object.username = message.username; + if (message.avatar != null && message.hasOwnProperty("avatar")) + object.avatar = message.avatar; + if (message.chip != null && message.hasOwnProperty("chip")) + object.chip = message.chip; + if (message.status != null && message.hasOwnProperty("status")) + object.status = message.status; + if (message.master != null && message.hasOwnProperty("master")) + object.master = message.master; + if (message.handCard && message.handCard.length) { + object.handCard = []; + for (let j = 0; j < message.handCard.length; ++j) + object.handCard[j] = $root.api.Card.toObject(message.handCard[j], options); + } + if (message.publicCard && message.publicCard.length) { + object.publicCard = []; + for (let j = 0; j < message.publicCard.length; ++j) + object.publicCard[j] = $root.api.Card.toObject(message.publicCard[j], options); + } + return object; + }; + + /** + * Converts this TablePlayer to JSON. + * @function toJSON + * @memberof api.TablePlayer + * @instance + * @returns {Object.} JSON object + */ + TablePlayer.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for TablePlayer + * @function getTypeUrl + * @memberof api.TablePlayer + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + TablePlayer.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/api.TablePlayer"; + }; + + return TablePlayer; + })(); + + api.Card = (function() { + + /** + * Properties of a Card. + * @memberof api + * @interface ICard + * @property {number|null} [dot] Card dot + * @property {number|null} [suit] Card suit + */ + + /** + * Constructs a new Card. + * @memberof api + * @classdesc Represents a Card. + * @implements ICard + * @constructor + * @param {api.ICard=} [properties] Properties to set + */ + function Card(properties) { + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Card dot. + * @member {number} dot + * @memberof api.Card + * @instance + */ + Card.prototype.dot = 0; + + /** + * Card suit. + * @member {number} suit + * @memberof api.Card + * @instance + */ + Card.prototype.suit = 0; + + /** + * Creates a new Card instance using the specified properties. + * @function create + * @memberof api.Card + * @static + * @param {api.ICard=} [properties] Properties to set + * @returns {api.Card} Card instance + */ + Card.create = function create(properties) { + return new Card(properties); + }; + + /** + * Encodes the specified Card message. Does not implicitly {@link api.Card.verify|verify} messages. + * @function encode + * @memberof api.Card + * @static + * @param {api.ICard} message Card message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Card.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.dot != null && Object.hasOwnProperty.call(message, "dot")) + writer.uint32(/* id 1, wireType 0 =*/8).int32(message.dot); + if (message.suit != null && Object.hasOwnProperty.call(message, "suit")) + writer.uint32(/* id 2, wireType 0 =*/16).int32(message.suit); + return writer; + }; + + /** + * Encodes the specified Card message, length delimited. Does not implicitly {@link api.Card.verify|verify} messages. + * @function encodeDelimited + * @memberof api.Card + * @static + * @param {api.ICard} message Card message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Card.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a Card message from the specified reader or buffer. + * @function decode + * @memberof api.Card + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {api.Card} Card + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Card.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.api.Card(); + while (reader.pos < end) { + let tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.dot = reader.int32(); + break; + } + case 2: { + message.suit = reader.int32(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a Card message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof api.Card + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {api.Card} Card + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Card.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a Card message. + * @function verify + * @memberof api.Card + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Card.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.dot != null && message.hasOwnProperty("dot")) + if (!$util.isInteger(message.dot)) + return "dot: integer expected"; + if (message.suit != null && message.hasOwnProperty("suit")) + if (!$util.isInteger(message.suit)) + return "suit: integer expected"; + return null; + }; + + /** + * Creates a Card message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof api.Card + * @static + * @param {Object.} object Plain object + * @returns {api.Card} Card + */ + Card.fromObject = function fromObject(object) { + if (object instanceof $root.api.Card) + return object; + let message = new $root.api.Card(); + if (object.dot != null) + message.dot = object.dot | 0; + if (object.suit != null) + message.suit = object.suit | 0; + return message; + }; + + /** + * Creates a plain object from a Card message. Also converts values to other types if specified. + * @function toObject + * @memberof api.Card + * @static + * @param {api.Card} message Card + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + Card.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.defaults) { + object.dot = 0; + object.suit = 0; + } + if (message.dot != null && message.hasOwnProperty("dot")) + object.dot = message.dot; + if (message.suit != null && message.hasOwnProperty("suit")) + object.suit = message.suit; + return object; + }; + + /** + * Converts this Card to JSON. * @function toJSON - * @memberof api.ResJoinTable + * @memberof api.Card * @instance * @returns {Object.} JSON object */ - ResJoinTable.prototype.toJSON = function toJSON() { + Card.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; /** - * Gets the default type url for ResJoinTable + * Gets the default type url for Card * @function getTypeUrl - * @memberof api.ResJoinTable + * @memberof api.Card * @static * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") * @returns {string} The default type url */ - ResJoinTable.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + Card.getTypeUrl = function getTypeUrl(typeUrlPrefix) { if (typeUrlPrefix === undefined) { typeUrlPrefix = "type.googleapis.com"; } - return typeUrlPrefix + "/api.ResJoinTable"; + return typeUrlPrefix + "/api.Card"; }; - return ResJoinTable; + return Card; })(); return api; diff --git a/etc/config.toml b/etc/config.toml index 38414d4..7af5265 100644 --- a/etc/config.toml +++ b/etc/config.toml @@ -15,5 +15,10 @@ ignoreUrl = [ captchaUrl = [ "/auth/authorize" ] + [sqlite] dbPath = "etc/texas-poker.db" + +[game] +# 新用户赠送筹码 +GiftChip = 10000 diff --git a/internal/conf/conf.go b/internal/conf/conf.go index 65c3a4e..6faa5be 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -34,6 +34,7 @@ type Config struct { Auth *Auth Http *Http Sqlite *Sqlite + Game *Game } type Auth struct { @@ -48,3 +49,7 @@ type Http struct { type Sqlite struct { DbPath string } + +type Game struct { + GiftChip int32 +} diff --git a/internal/dao/dao.go b/internal/dao/dao.go index 2813026..86948fa 100644 --- a/internal/dao/dao.go +++ b/internal/dao/dao.go @@ -16,6 +16,8 @@ func init() { Dao = &Persistent{ Sqlite: newSqlite(), } + + initUserDao() } func newSqlite() (db *gorm.DB) { diff --git a/internal/service/user.go b/internal/dao/user_dao.go similarity index 68% rename from internal/service/user.go rename to internal/dao/user_dao.go index 21faea3..c642c21 100644 --- a/internal/service/user.go +++ b/internal/dao/user_dao.go @@ -1,30 +1,30 @@ -package service +package dao import ( "fmt" "github.com/gin-gonic/gin" "gorm.io/gorm" "net/http" - "texas-poker-bk/internal/dao" "texas-poker-bk/internal/model/entity" ) -var userDao *User = &User{dao: dao.Dao.Sqlite} +var UserDao *User -func init() { - err := dao.Dao.Sqlite.AutoMigrate(&entity.User{}) +func initUserDao() { + UserDao = &User{DB: Dao.Sqlite} + err := Dao.Sqlite.AutoMigrate(&entity.User{}) if err != nil { fmt.Println("user table", err) } } type User struct { - dao *gorm.DB + DB *gorm.DB } func FindUserByName(ctx *gin.Context) { username := ctx.Param("username") - user := userDao.FindUserByName(username) + user := UserDao.FindUserByName(username) if user == nil { ctx.JSON(http.StatusOK, gin.H{ "msg": "not found", @@ -39,7 +39,7 @@ func FindUserByName(ctx *gin.Context) { func (u *User) FindUserByName(username string) *entity.User { user := &entity.User{} - tx := u.dao.Model(user).Where("username=?", username).Limit(1).Scan(user) + tx := u.DB.Model(user).Where("username=?", username).Limit(1).Scan(user) // 查询出结果时 tx.RowsAffected 固定=1 if tx.RowsAffected == 0 { return nil diff --git a/internal/game/player.go b/internal/game/player.go index 41e5cf4..d9e100c 100644 --- a/internal/game/player.go +++ b/internal/game/player.go @@ -1,13 +1,20 @@ package game +import ( + "texas-poker-bk/internal/letter" +) + // Player 游戏玩家 type Player struct { Id int64 Username string Avatar string Cards [2]*Card // 手牌 - Chip int // 玩家筹码 + Chip int32 // 玩家筹码 Status int32 // 状态: 1待准备开始,2已准备开始,3等待其他玩家动作,4待大盲注,5待小盲注,6待跟注,7已弃 + + GameTable *Table // 当前牌桌 + ProtoWriter *letter.ProtoWriter } func NewPlayer() *Player { diff --git a/internal/game/table.go b/internal/game/table.go index 38bf36c..890465c 100644 --- a/internal/game/table.go +++ b/internal/game/table.go @@ -1,12 +1,18 @@ package game +import ( + "errors" + "sync" + "texas-poker-bk/api" +) + type Table struct { TableNo int32 // 牌桌编号 - roundTimes int // 回合次数 - stage Stage // 游戏阶段 + RoundTimes int32 // 回合次数 + Stage int32 // 游戏阶段: 1等待玩家准备;2下大盲注;3下小盲注;4发公共牌;5发第四张公共牌,轮流下注;6发第五张公共牌,轮流下注 - chip int // 牌桌当前筹码 - robotChip int // 牌桌当前机器人下注筹码 + chip int32 // 牌桌当前筹码 + robotChip int32 // 牌桌当前机器人下注筹码 dealer *Dealer // 发牌员 publicCards [5]*Dealer // 公共牌 @@ -14,11 +20,32 @@ type Table struct { RobotNum int32 // 机器人数 Players []*Player // 玩家 Robots []*Robot - bigBlindsPos int // 大盲注位 + BigBlindsPos int32 // 大盲注位 + PlayerJoinLock *sync.Mutex + ChipLock *sync.Mutex // 桌面筹码更新锁 // TODO game logs7 } +func (t *Table) JoinPlayer(player *Player) error { + t.PlayerJoinLock.Lock() + defer t.PlayerJoinLock.Unlock() + for i := range t.Players { + // 找个空位坐下 + if t.Players[i] == nil { + t.Players[i] = player + return nil + } + } + return errors.New("牌桌玩家已满") +} + +func (t *Table) NoticeGameStatus() { + gameStatus := &api.ResGameStatus{} + gameStatus.TableNo = t.TableNo + +} + type Stage int func (s *Stage) String() string { diff --git a/internal/letter/proto_writer.go b/internal/letter/proto_writer.go new file mode 100644 index 0000000..890b4d4 --- /dev/null +++ b/internal/letter/proto_writer.go @@ -0,0 +1,7 @@ +package letter + +import "github.com/golang/protobuf/proto" + +type ProtoWriter interface { + Write(message proto.Message) +} diff --git a/internal/model/entity/user.go b/internal/model/entity/user.go index e118c55..9c965af 100644 --- a/internal/model/entity/user.go +++ b/internal/model/entity/user.go @@ -6,6 +6,7 @@ type User struct { Username string `gorm:"column:username" json:"username"` // comment:用户名 Password string `gorm:"column:password" json:"password"` // comment:密码 Nickname string `gorm:"column:nickname" json:"nickname"` // comment:昵称 + Balance int32 `gorm:"column:balance" json:"balance"` // comment:余额 Version int64 `gorm:"column:version" json:"version"` // comment:更新版本锁 } diff --git a/internal/server/route.go b/internal/server/route.go index a9bb956..4eefd69 100644 --- a/internal/server/route.go +++ b/internal/server/route.go @@ -4,6 +4,7 @@ import ( "github.com/gin-gonic/gin" "net/http" "texas-poker-bk/api" + "texas-poker-bk/internal/dao" "texas-poker-bk/internal/service" ) @@ -29,10 +30,9 @@ func NewServer() *gin.Engine { auth.POST("/authorize", service.Authorize) // 登录或注册认证 user := base.Group("/user") - user.GET("/findByName", service.FindUserByName) + user.GET("/findByName", dao.FindUserByName) - game := base.Group("/game") - game.GET("/lobby", service.GetLobbyView) // 游戏大厅 + _ = base.Group("/game") return server } diff --git a/internal/server/wsroute.go b/internal/server/wsroute.go index 4e0ebbb..9439443 100644 --- a/internal/server/wsroute.go +++ b/internal/server/wsroute.go @@ -4,33 +4,25 @@ import ( "github.com/golang/protobuf/proto" "reflect" "texas-poker-bk/api" + "texas-poker-bk/internal/game" "texas-poker-bk/internal/service" "texas-poker-bk/internal/session" ) var NetClientHandlers = make(map[int32]func(*session.NetClient, proto.Message) (proto.Message, error)) var NetAccountHandlers = make(map[int32]func(session.NetAccount, proto.Message) (proto.Message, error)) -var PlayerHandlers = make(map[int32]func(*session.Player, proto.Message) (proto.Message, error)) +var PlayerHandlers = make(map[int32]func(*game.Player, proto.Message) (proto.Message, error)) func init() { // 连接token认证 - HandleNetClientMsg(&api.ReqIdentity{}, func(client *session.NetClient, msg *api.ReqIdentity) (proto.Message, error) { - subject, err := service.DecodeSubject(msg.Token) - if err != nil { - // client.Close("authorize failed!") - return nil, err - } - account := &session.NetAccount{Id: subject.Id, UserName: subject.Name, Avatar: subject.Avatar, Client: client} - client.Account = account + HandleNetClientMsg(&api.ReqIdentity{}, service.HandleReqIdentity) + // 创建桌面 + HandleNetAccountMsg(&api.ReqCreateTable{}, service.HandleReqCreateTable) + // 查询所有游戏桌面 + HandleNetAccountMsg(&api.ReqLobbyView{}, service.HandleReqLobbyView) + // 加入桌面 + HandleNetAccountMsg(&api.ReqJoinTable{}, service.HandleJoinTable) - // response - res := &api.ResIdentity{Status: 200, Msg: "ok"} - // client.Write(res) - return res, nil - }) - - HandleNetAccountMsg(&api.ReqCreateTable{}, service.CreateNewTable) // 创建桌面 - HandleNetAccountMsg(&api.ReqLobbyView{}, service.GetLobbyView2) // 查询所有游戏桌面 } func checkExistsTypeHandler(op int32, err error) { @@ -59,10 +51,10 @@ func HandleNetAccountMsg[T proto.Message](msg T, f func(session.NetAccount, T) ( } } -func HandleNetPlayerMsg[T proto.Message](msg T, f func(*session.Player, T) (proto.Message, error)) { +func HandleNetPlayerMsg[T proto.Message](msg T, f func(*game.Player, T) (proto.Message, error)) { op, err := api.GetProtoOp(msg) checkExistsTypeHandler(op, err) - PlayerHandlers[op] = func(player *session.Player, msg proto.Message) (proto.Message, error) { + PlayerHandlers[op] = func(player *game.Player, msg proto.Message) (proto.Message, error) { return f(player, msg.(T)) } } diff --git a/internal/service/auth.go b/internal/service/auth.go index 2ad9200..712ef47 100644 --- a/internal/service/auth.go +++ b/internal/service/auth.go @@ -5,8 +5,11 @@ import ( "encoding/json" "fmt" "github.com/gin-gonic/gin" + "github.com/golang/protobuf/proto" "net/http" + "texas-poker-bk/api" "texas-poker-bk/internal/conf" + "texas-poker-bk/internal/dao" "texas-poker-bk/internal/model/entity" "texas-poker-bk/internal/session" "texas-poker-bk/tool/collect" @@ -41,7 +44,7 @@ func Authorize(ctx *gin.Context) { ctx.JSON(http.StatusBadRequest, gin.H{"msg": "用户名或密码不能为空"}) return } - user := userDao.FindUserByName(username) + user := dao.UserDao.FindUserByName(username) if user == nil { // 注册 user = registerUser(username, password) @@ -68,9 +71,10 @@ func registerUser(username string, password string) *entity.User { Username: username, Password: password, Nickname: username, + Balance: conf.Conf.Game.GiftChip, } // TODO error - userDao.dao.Save(user) + dao.UserDao.DB.Save(user) return user } @@ -152,3 +156,25 @@ func GetSubject(ctx *gin.Context) *session.Subject { } return subject.(*session.Subject) } + +func HandleReqIdentity(client *session.NetClient, msg *api.ReqIdentity) (proto.Message, error) { + subject, err := DecodeSubject(msg.Token) + if err != nil { + // client.Close("authorize failed!") + return nil, err + } + + account := &session.NetAccount{ + Id: subject.Id, + UserName: subject.Name, + Avatar: subject.Avatar, + Client: client, + Balance: 0, + } + client.Account = account + + // response + res := &api.ResIdentity{Status: 200, Msg: "ok"} + // client.Write(res) + return res, nil +} diff --git a/internal/service/store/store.go b/internal/service/store/store.go index dfe95de..5591983 100644 --- a/internal/service/store/store.go +++ b/internal/service/store/store.go @@ -3,12 +3,9 @@ package store import ( "errors" "fmt" - "sort" "sync" "sync/atomic" "texas-poker-bk/internal/game" - "texas-poker-bk/internal/model/vo" - "texas-poker-bk/tool/collect" ) var ( @@ -32,40 +29,3 @@ func SaveNewTable(table *game.Table) error { LobbyTables[table.TableNo] = table return nil } - -func GetLobbyTablesView() []*vo.TableVO { - if LobbyTables == nil || len(LobbyTables) == 0 { - return make([]*vo.TableVO, 0) - } - tables := make([]*vo.TableVO, len(LobbyTables)) - idx := 0 - for _, t := range LobbyTables { - tVO := &vo.TableVO{} - tVO.TableNo = t.TableNo - if collect.IsNotEmptySlice(t.Players) { - tVO.Players = make([]*vo.PlayerVO, len(t.Players)) - for i, player := range t.Players { - if player == nil { - continue - } - pVO := &vo.PlayerVO{Id: player.Id, Username: player.Username, Avatar: player.Avatar} - tVO.Players[i] = pVO - } - } - if collect.IsNotEmptySlice(t.Robots) { - tVO.Robots = make([]*vo.RobotVO, len(t.Robots)) - for i, _ := range t.Robots { - rVO := &vo.RobotVO{} - tVO.Robots[i] = rVO - } - } - - tables[idx] = tVO - idx++ - } - // 牌桌号降序 - sort.Slice(tables, func(i, j int) bool { - return tables[i].TableNo > tables[j].TableNo - }) - return tables -} diff --git a/internal/service/table.go b/internal/service/table.go index bc17102..8543a8a 100644 --- a/internal/service/table.go +++ b/internal/service/table.go @@ -1,9 +1,9 @@ package service import ( - "github.com/gin-gonic/gin" + "fmt" "github.com/golang/protobuf/proto" - "net/http" + "sort" "texas-poker-bk/api" "texas-poker-bk/internal/game" "texas-poker-bk/internal/service/store" @@ -11,8 +11,8 @@ import ( "texas-poker-bk/tool/collect" ) -// CreateNewTable 创建桌面 TODO 当前在房间则不可创建房间了 -func CreateNewTable(account session.NetAccount, msg *api.ReqCreateTable) (proto.Message, error) { +// HandleReqCreateTable 创建桌面 TODO 当前在房间则不可创建房间了 +func HandleReqCreateTable(account session.NetAccount, msg *api.ReqCreateTable) (proto.Message, error) { // 人数,机器人数 playerNum := msg.Players robotNum := msg.Robots @@ -31,7 +31,12 @@ func CreateNewTable(account session.NetAccount, msg *api.ReqCreateTable) (proto. Id: account.Id, Username: account.UserName, Avatar: account.Avatar, + Status: 1, + Chip: 500, } + // 扣除DB账户余额 TODO 账户金额限制 + account.DecrementBalance(500) + table.Players[0] = owner for i := 0; i < int(robotNum); i++ { table.Robots[i] = &game.Robot{} @@ -43,13 +48,8 @@ func CreateNewTable(account session.NetAccount, msg *api.ReqCreateTable) (proto. return &api.ResCreateTable{TableNo: table.TableNo}, nil } -func GetLobbyView(ctx *gin.Context) { - lobby := store.GetLobbyTablesView() - ctx.JSON(http.StatusOK, gin.H{"data": lobby}) -} - -// GetLobbyView2 返回当前所有桌面和玩家数量 -func GetLobbyView2(account session.NetAccount, msg *api.ReqLobbyView) (proto.Message, error) { +// HandleReqLobbyView 返回当前所有桌面和玩家数量 +func HandleReqLobbyView(account session.NetAccount, msg *api.ReqLobbyView) (proto.Message, error) { res := &api.ResLobbyView{} if store.LobbyTables == nil || len(store.LobbyTables) == 0 { return res, nil @@ -85,10 +85,76 @@ func GetLobbyView2(account session.NetAccount, msg *api.ReqLobbyView) (proto.Mes tables[idx] = table idx++ } + // 牌桌号降序 + sort.Slice(tables, func(i, j int) bool { + return tables[i].TableNo > tables[j].TableNo + }) return res, nil } -// JoinTable 加入牌桌 -func JoinTable(ctx *gin.Context) { +// HandleJoinTable 加入牌桌 +func HandleJoinTable(account session.NetAccount, msg *api.ReqJoinTable) (proto.Message, error) { + account.Lock.Lock() + defer account.Lock.Unlock() + + if account.Player != nil { + return &api.ResFail{Msg: fmt.Sprintf("用户当前已加入#%d牌桌", account.Player.GameTable.TableNo)}, nil + } + // account -> player + // TODO 账户余额限制 + + table := store.LobbyTables[msg.TableNo] + if table == nil { + return &api.ResFail{Msg: "牌桌不存在"}, nil + } + player := &game.Player{ + Id: account.Id, + Username: account.UserName, + Avatar: account.Avatar, + Status: 1, + Chip: 500, + GameTable: table, + } + err := table.JoinPlayer(player) + if err != nil { + return nil, err + } + // 从账户扣除进入牌桌的金额 + account.DecrementBalance(500) + account.Player = player + return &api.ResSuccess{}, nil +} + +// HandleLeaveTable 离开牌桌 +func HandleLeaveTable(account session.NetAccount, msg *api.ReqCreateTable) (proto.Message, error) { + account.Lock.Lock() + defer account.Lock.Unlock() + // 结算, player -> nil + if account.Player == nil { + return &api.ResFail{Msg: "当前未加入牌桌"}, nil + } + // 根据玩家游戏状态判断可否退出 + switch account.Player.Status { + case 1, 2, 7: // 未在游戏中 可退出 + // 结算金额 + account.IncrementBalance(account.Player.Chip) + gameTable := account.Player.GameTable + // table player remove + for i := range gameTable.Players { + if gameTable.Players[i] == account.Player { + gameTable.Players[i] = nil + } + } + account.Player = nil + // TODO notice 牌桌其他玩家 gameTable.notice(ResGameStatus) + return &api.ResSuccess{}, nil + default: + return &api.ResFail{Msg: "游戏进行中,不能退出"}, nil + } +} + +// HandleReqReadyStart 准备开始游戏 +func HandleReqReadyStart(player game.Player, msg *api.ReqReadyStart) (proto.Message, error) { + return nil, nil } diff --git a/internal/session/net_account.go b/internal/session/net_account.go index e76596a..805f2e1 100644 --- a/internal/session/net_account.go +++ b/internal/session/net_account.go @@ -1,13 +1,43 @@ package session +import ( + "sync" + "texas-poker-bk/internal/game" +) + // NetAccount 已认证的长连接用户 type NetAccount struct { - Id int64 - UserName string - Avatar string - Client *NetClient + Id int64 + UserName string + Avatar string + Client *NetClient + Balance int32 // 余额 + Player *game.Player + BalanceLock *sync.RWMutex + Lock *sync.Mutex } func NewNetAccount() { } + +func (account *NetAccount) DecrementBalance(amount int32) int32 { + account.BalanceLock.Lock() + defer account.BalanceLock.Unlock() + account.Balance -= amount + // TODO 同步到 DB + return account.Balance +} + +func (account *NetAccount) IncrementBalance(amount int32) int32 { + account.BalanceLock.Lock() + defer account.BalanceLock.Unlock() + account.Balance += amount + return account.Balance +} + +func (account *NetAccount) GetBalance() int32 { + account.BalanceLock.RLock() + defer account.BalanceLock.RUnlock() + return account.Balance +} diff --git a/internal/session/player.go b/internal/session/player.go index e1bc452..25f5bf6 100644 --- a/internal/session/player.go +++ b/internal/session/player.go @@ -1,6 +1,19 @@ package session +import ( + "sync" + "texas-poker-bk/internal/game" +) + // Player 玩家: table,balance,(hand card) type Player struct { Account *NetAccount + + Id int64 + Username string + Avatar string + Cards [2]*game.Card // 手牌 + Chip int // 玩家筹码 + Status int32 // 状态: 1待准备开始,2已准备开始,3等待其他玩家动作,4待大盲注,5待小盲注,6待跟注,7已弃 + StatusLock *sync.Mutex }