diff --git a/README.md b/README.md index 3abe49d..fd35c6a 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,10 @@ pbjs -t static-module -w api/jsproto -o proto.js api/*.proto # json pbjs -t json api/*.proto > jsproto.json ``` + + +## game process +1. player join (检查筹码...) +2. player ready +3. table begin 发牌 +4. 开始流程,大盲注 小盲注 diff --git a/api/operation.go b/api/operation.go index 355f985..2562df5 100644 --- a/api/operation.go +++ b/api/operation.go @@ -15,14 +15,19 @@ var protoInstances = []proto.Message{ &ProtoWrap{}, &ResSuccess{}, &ResFail{}, + &Ping{}, &Pong{}, + &ReqIdentity{}, &ResIdentity{}, + &ReqLobbyView{}, &ResLobbyView{}, + &ReqCreateTable{}, &ResCreateTable{}, + &ReqJoinTable{}, &ResJoinTable{}, } diff --git a/api/poker.pb.go b/api/poker.pb.go index 83fbbf8..d9a8a14 100644 --- a/api/poker.pb.go +++ b/api/poker.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.1 -// protoc v3.19.0 +// protoc v3.21.12 // source: poker.proto package api @@ -105,6 +105,8 @@ type Ping struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + TimeMs uint64 `protobuf:"varint,1,opt,name=timeMs,proto3" json:"timeMs,omitempty"` // 毫秒时间戳 } func (x *Ping) Reset() { @@ -139,10 +141,19 @@ func (*Ping) Descriptor() ([]byte, []int) { return file_poker_proto_rawDescGZIP(), []int{1} } +func (x *Ping) GetTimeMs() uint64 { + if x != nil { + return x.TimeMs + } + return 0 +} + type Pong struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + TimeMs uint64 `protobuf:"varint,1,opt,name=timeMs,proto3" json:"timeMs,omitempty"` // 毫秒时间戳 } func (x *Pong) Reset() { @@ -177,6 +188,13 @@ func (*Pong) Descriptor() ([]byte, []int) { return file_poker_proto_rawDescGZIP(), []int{2} } +func (x *Pong) GetTimeMs() uint64 { + if x != nil { + return x.TimeMs + } + return 0 +} + // 成功消息 type ResSuccess struct { state protoimpl.MessageState @@ -366,6 +384,7 @@ func (x *ResIdentity) GetMsg() string { return "" } +// 大厅消息 ============= begin type ReqLobbyView struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -408,6 +427,8 @@ type ResLobbyView struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + Tables []*LobbyTable `protobuf:"bytes,3,rep,name=tables,proto3" json:"tables,omitempty"` } func (x *ResLobbyView) Reset() { @@ -442,6 +463,156 @@ func (*ResLobbyView) Descriptor() ([]byte, []int) { return file_poker_proto_rawDescGZIP(), []int{8} } +func (x *ResLobbyView) GetTables() []*LobbyTable { + if x != nil { + return x.Tables + } + return nil +} + +type LobbyTable struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TableNo int32 `protobuf:"varint,1,opt,name=tableNo,proto3" json:"tableNo,omitempty"` // 游戏编号 + PlayerNum int32 `protobuf:"varint,2,opt,name=playerNum,proto3" json:"playerNum,omitempty"` // 限定玩家数量 + RobotNum int32 `protobuf:"varint,3,opt,name=robotNum,proto3" json:"robotNum,omitempty"` // 限定机器人数量 + Players []*LobbyPlayer `protobuf:"bytes,4,rep,name=players,proto3" json:"players,omitempty"` // 当前玩家机器人列表 +} + +func (x *LobbyTable) Reset() { + *x = LobbyTable{} + if protoimpl.UnsafeEnabled { + mi := &file_poker_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LobbyTable) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LobbyTable) ProtoMessage() {} + +func (x *LobbyTable) ProtoReflect() protoreflect.Message { + mi := &file_poker_proto_msgTypes[9] + 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 LobbyTable.ProtoReflect.Descriptor instead. +func (*LobbyTable) Descriptor() ([]byte, []int) { + return file_poker_proto_rawDescGZIP(), []int{9} +} + +func (x *LobbyTable) GetTableNo() int32 { + if x != nil { + return x.TableNo + } + return 0 +} + +func (x *LobbyTable) GetPlayerNum() int32 { + if x != nil { + return x.PlayerNum + } + return 0 +} + +func (x *LobbyTable) GetRobotNum() int32 { + if x != nil { + return x.RobotNum + } + return 0 +} + +func (x *LobbyTable) GetPlayers() []*LobbyPlayer { + if x != nil { + return x.Players + } + return nil +} + +type LobbyPlayer 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"` +} + +func (x *LobbyPlayer) Reset() { + *x = LobbyPlayer{} + if protoimpl.UnsafeEnabled { + mi := &file_poker_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LobbyPlayer) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LobbyPlayer) ProtoMessage() {} + +func (x *LobbyPlayer) ProtoReflect() protoreflect.Message { + mi := &file_poker_proto_msgTypes[10] + 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 LobbyPlayer.ProtoReflect.Descriptor instead. +func (*LobbyPlayer) Descriptor() ([]byte, []int) { + return file_poker_proto_rawDescGZIP(), []int{10} +} + +func (x *LobbyPlayer) GetRobot() bool { + if x != nil { + return x.Robot + } + return false +} + +func (x *LobbyPlayer) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *LobbyPlayer) GetUsername() string { + if x != nil { + return x.Username + } + return "" +} + +func (x *LobbyPlayer) GetAvatar() string { + if x != nil { + return x.Avatar + } + return "" +} + +// 创建桌面 ============= begin type ReqCreateTable struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -454,7 +625,7 @@ type ReqCreateTable struct { func (x *ReqCreateTable) Reset() { *x = ReqCreateTable{} if protoimpl.UnsafeEnabled { - mi := &file_poker_proto_msgTypes[9] + mi := &file_poker_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -467,7 +638,7 @@ func (x *ReqCreateTable) String() string { func (*ReqCreateTable) ProtoMessage() {} func (x *ReqCreateTable) ProtoReflect() protoreflect.Message { - mi := &file_poker_proto_msgTypes[9] + mi := &file_poker_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -480,7 +651,7 @@ func (x *ReqCreateTable) ProtoReflect() protoreflect.Message { // Deprecated: Use ReqCreateTable.ProtoReflect.Descriptor instead. func (*ReqCreateTable) Descriptor() ([]byte, []int) { - return file_poker_proto_rawDescGZIP(), []int{9} + return file_poker_proto_rawDescGZIP(), []int{11} } func (x *ReqCreateTable) GetPlayers() int32 { @@ -508,7 +679,7 @@ type ResCreateTable struct { func (x *ResCreateTable) Reset() { *x = ResCreateTable{} if protoimpl.UnsafeEnabled { - mi := &file_poker_proto_msgTypes[10] + mi := &file_poker_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -521,7 +692,7 @@ func (x *ResCreateTable) String() string { func (*ResCreateTable) ProtoMessage() {} func (x *ResCreateTable) ProtoReflect() protoreflect.Message { - mi := &file_poker_proto_msgTypes[10] + mi := &file_poker_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -534,7 +705,7 @@ func (x *ResCreateTable) ProtoReflect() protoreflect.Message { // Deprecated: Use ResCreateTable.ProtoReflect.Descriptor instead. func (*ResCreateTable) Descriptor() ([]byte, []int) { - return file_poker_proto_rawDescGZIP(), []int{10} + return file_poker_proto_rawDescGZIP(), []int{12} } func (x *ResCreateTable) GetTableNo() int32 { @@ -544,6 +715,7 @@ func (x *ResCreateTable) GetTableNo() int32 { return 0 } +// 加入游戏 ============= begin type ReqJoinTable struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -553,7 +725,7 @@ type ReqJoinTable struct { func (x *ReqJoinTable) Reset() { *x = ReqJoinTable{} if protoimpl.UnsafeEnabled { - mi := &file_poker_proto_msgTypes[11] + mi := &file_poker_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -566,7 +738,7 @@ func (x *ReqJoinTable) String() string { func (*ReqJoinTable) ProtoMessage() {} func (x *ReqJoinTable) ProtoReflect() protoreflect.Message { - mi := &file_poker_proto_msgTypes[11] + mi := &file_poker_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -579,7 +751,7 @@ func (x *ReqJoinTable) ProtoReflect() protoreflect.Message { // Deprecated: Use ReqJoinTable.ProtoReflect.Descriptor instead. func (*ReqJoinTable) Descriptor() ([]byte, []int) { - return file_poker_proto_rawDescGZIP(), []int{11} + return file_poker_proto_rawDescGZIP(), []int{13} } type ResJoinTable struct { @@ -591,7 +763,7 @@ type ResJoinTable struct { func (x *ResJoinTable) Reset() { *x = ResJoinTable{} if protoimpl.UnsafeEnabled { - mi := &file_poker_proto_msgTypes[12] + mi := &file_poker_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -604,7 +776,7 @@ func (x *ResJoinTable) String() string { func (*ResJoinTable) ProtoMessage() {} func (x *ResJoinTable) ProtoReflect() protoreflect.Message { - mi := &file_poker_proto_msgTypes[12] + mi := &file_poker_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -617,7 +789,7 @@ func (x *ResJoinTable) ProtoReflect() protoreflect.Message { // Deprecated: Use ResJoinTable.ProtoReflect.Descriptor instead. func (*ResJoinTable) Descriptor() ([]byte, []int) { - return file_poker_proto_rawDescGZIP(), []int{12} + return file_poker_proto_rawDescGZIP(), []int{14} } var File_poker_proto protoreflect.FileDescriptor @@ -631,8 +803,11 @@ var file_poker_proto_rawDesc = []byte{ 0x73, 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64, - 0x79, 0x22, 0x06, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x22, 0x06, 0x0a, 0x04, 0x50, 0x6f, 0x6e, - 0x67, 0x22, 0x0c, 0x0a, 0x0a, 0x52, 0x65, 0x73, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, + 0x79, 0x22, 0x1e, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x69, 0x6d, + 0x65, 0x4d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x74, 0x69, 0x6d, 0x65, 0x4d, + 0x73, 0x22, 0x1e, 0x0a, 0x04, 0x50, 0x6f, 0x6e, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x69, 0x6d, + 0x65, 0x4d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x74, 0x69, 0x6d, 0x65, 0x4d, + 0x73, 0x22, 0x0c, 0x0a, 0x0a, 0x52, 0x65, 0x73, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, 0x1b, 0x0a, 0x07, 0x52, 0x65, 0x73, 0x46, 0x61, 0x69, 0x6c, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x23, 0x0a, 0x0b, 0x52, 0x65, 0x71, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x74, @@ -641,18 +816,36 @@ var file_poker_proto_rawDesc = []byte{ 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x0e, 0x0a, 0x0c, 0x52, 0x65, - 0x71, 0x4c, 0x6f, 0x62, 0x62, 0x79, 0x56, 0x69, 0x65, 0x77, 0x22, 0x0e, 0x0a, 0x0c, 0x52, 0x65, - 0x73, 0x4c, 0x6f, 0x62, 0x62, 0x79, 0x56, 0x69, 0x65, 0x77, 0x22, 0x42, 0x0a, 0x0e, 0x52, 0x65, - 0x71, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, - 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x70, - 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x6f, 0x62, 0x6f, 0x74, 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, + 0x71, 0x4c, 0x6f, 0x62, 0x62, 0x79, 0x56, 0x69, 0x65, 0x77, 0x22, 0x37, 0x0a, 0x0c, 0x52, 0x65, + 0x73, 0x4c, 0x6f, 0x62, 0x62, 0x79, 0x56, 0x69, 0x65, 0x77, 0x12, 0x27, 0x0a, 0x06, 0x74, 0x61, + 0x62, 0x6c, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x61, 0x70, 0x69, + 0x2e, 0x4c, 0x6f, 0x62, 0x62, 0x79, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x06, 0x74, 0x61, 0x62, + 0x6c, 0x65, 0x73, 0x22, 0x8c, 0x01, 0x0a, 0x0a, 0x4c, 0x6f, 0x62, 0x62, 0x79, 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, 0x12, 0x1c, 0x0a, 0x09, + 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x09, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x6f, + 0x62, 0x6f, 0x74, 0x4e, 0x75, 0x6d, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x6f, + 0x62, 0x6f, 0x74, 0x4e, 0x75, 0x6d, 0x12, 0x2a, 0x0a, 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, + 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4c, 0x6f, + 0x62, 0x62, 0x79, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x52, 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, + 0x72, 0x73, 0x22, 0x67, 0x0a, 0x0b, 0x4c, 0x6f, 0x62, 0x62, 0x79, 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, 0x22, 0x42, 0x0a, 0x0e, 0x52, + 0x65, 0x71, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x18, 0x0a, + 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, + 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x6f, 0x62, 0x6f, 0x74, + 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, } var ( @@ -667,7 +860,7 @@ func file_poker_proto_rawDescGZIP() []byte { return file_poker_proto_rawDescData } -var file_poker_proto_msgTypes = make([]protoimpl.MessageInfo, 13) +var file_poker_proto_msgTypes = make([]protoimpl.MessageInfo, 15) var file_poker_proto_goTypes = []interface{}{ (*ProtoWrap)(nil), // 0: api.ProtoWrap (*Ping)(nil), // 1: api.Ping @@ -678,17 +871,21 @@ var file_poker_proto_goTypes = []interface{}{ (*ResIdentity)(nil), // 6: api.ResIdentity (*ReqLobbyView)(nil), // 7: api.ReqLobbyView (*ResLobbyView)(nil), // 8: api.ResLobbyView - (*ReqCreateTable)(nil), // 9: api.ReqCreateTable - (*ResCreateTable)(nil), // 10: api.ResCreateTable - (*ReqJoinTable)(nil), // 11: api.ReqJoinTable - (*ResJoinTable)(nil), // 12: api.ResJoinTable + (*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 } var file_poker_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 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 } func init() { file_poker_proto_init() } @@ -806,7 +1003,7 @@ func file_poker_proto_init() { } } file_poker_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ReqCreateTable); i { + switch v := v.(*LobbyTable); i { case 0: return &v.state case 1: @@ -818,7 +1015,7 @@ func file_poker_proto_init() { } } file_poker_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ResCreateTable); i { + switch v := v.(*LobbyPlayer); i { case 0: return &v.state case 1: @@ -830,7 +1027,7 @@ func file_poker_proto_init() { } } file_poker_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ReqJoinTable); i { + switch v := v.(*ReqCreateTable); i { case 0: return &v.state case 1: @@ -842,6 +1039,30 @@ func file_poker_proto_init() { } } file_poker_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ResCreateTable); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_poker_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReqJoinTable); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_poker_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ResJoinTable); i { case 0: return &v.state @@ -860,7 +1081,7 @@ func file_poker_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_poker_proto_rawDesc, NumEnums: 0, - NumMessages: 13, + NumMessages: 15, NumExtensions: 0, NumServices: 0, }, diff --git a/api/poker.proto b/api/poker.proto index 3162518..89dbf09 100644 --- a/api/poker.proto +++ b/api/poker.proto @@ -17,11 +17,11 @@ message ProtoWrap { } message Ping { - + uint64 timeMs = 1; // 毫秒时间戳 } message Pong { - + uint64 timeMs = 1; // 毫秒时间戳 } // 成功消息 @@ -43,25 +43,32 @@ message ResIdentity { string msg = 2; } +// 大厅消息 ============= begin message ReqLobbyView { } message ResLobbyView { - + repeated LobbyTable tables = 3; } message LobbyTable { - int32 tableNo = 1; - repeated LobbyPlayer players = 3; + int32 tableNo = 1; // 游戏编号 + int32 playerNum = 2; // 限定玩家数量 + int32 robotNum = 3; // 限定机器人数量 + repeated LobbyPlayer players = 4; // 当前玩家机器人列表 } message LobbyPlayer { - bytes type = 1; - string username = 2; - string avatar = 3; + bool robot = 1; // 是否机器人 + int64 id = 2; + string username = 3; + string avatar = 4; } +// 大厅消息 ============= end + +// 创建桌面 ============= begin message ReqCreateTable { int32 players = 1; int32 robots = 2; @@ -70,11 +77,58 @@ message ReqCreateTable { message ResCreateTable { int32 tableNo = 1; } +// 创建桌面 ============= end + +// 加入游戏 ============= begin message ReqJoinTable { + int32 tableNo = 1; +} +// 玩家准备开始 +message ReqReadyStart { } -message ResJoinTable { +// 房主踢人 +message ReqKickOutTable { + int32 playerId = 1; +} +message ReqAction { + int32 action = 1; // 4下大盲注,5下小盲注,6跟注,7弃牌 + int32 chip = 2; // 押注金额 } + +message ResAction { + +} + +// 查询玩家当前游戏状态 +message ReqGameStatus { +} + +message ResGameStatus { // 玩家当前游戏状态: 断线,重新登录.... + bool inGame = 1; // 是否在游戏中 + int32 tableNo = 2; // 所在桌面编号 + int32 gameStage = 3; // 游戏阶段? + repeated TablePlayer players = 10; +} + +message TablePlayer { + bool robot = 1; // 是否机器人 + int64 id = 2; + string username = 3; + string avatar = 4; + int32 chip = 5; // 筹码 + int32 status = 6; // 玩家状态: 1待准备开始,2已准备开始,已开始(3等待其他玩家动作,4待大盲注,5待小盲注,6待跟注,7已弃) + bool master = 7; // 是否房主 + repeated Card handCard = 8; // 手牌 + repeated Card publicCard = 9; // 公共牌 +} + +message Card { + int32 dot = 1; // 点数 + int32 suit = 2; // 花色 +} + +// 加入游戏 ============= end diff --git a/api/proto.js b/api/proto.js index 8d287f4..e9b96bb 100644 --- a/api/proto.js +++ b/api/proto.js @@ -327,6 +327,7 @@ export const api = $root.api = (() => { * Properties of a Ping. * @memberof api * @interface IPing + * @property {number|Long|null} [timeMs] Ping timeMs */ /** @@ -344,6 +345,14 @@ export const api = $root.api = (() => { this[keys[i]] = properties[keys[i]]; } + /** + * Ping timeMs. + * @member {number|Long} timeMs + * @memberof api.Ping + * @instance + */ + Ping.prototype.timeMs = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + /** * Creates a new Ping instance using the specified properties. * @function create @@ -368,6 +377,8 @@ export const api = $root.api = (() => { Ping.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); + if (message.timeMs != null && Object.hasOwnProperty.call(message, "timeMs")) + writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.timeMs); return writer; }; @@ -402,6 +413,10 @@ export const api = $root.api = (() => { while (reader.pos < end) { let tag = reader.uint32(); switch (tag >>> 3) { + case 1: { + message.timeMs = reader.uint64(); + break; + } default: reader.skipType(tag & 7); break; @@ -437,6 +452,9 @@ export const api = $root.api = (() => { Ping.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; + if (message.timeMs != null && message.hasOwnProperty("timeMs")) + if (!$util.isInteger(message.timeMs) && !(message.timeMs && $util.isInteger(message.timeMs.low) && $util.isInteger(message.timeMs.high))) + return "timeMs: integer|Long expected"; return null; }; @@ -451,7 +469,17 @@ export const api = $root.api = (() => { Ping.fromObject = function fromObject(object) { if (object instanceof $root.api.Ping) return object; - return new $root.api.Ping(); + let message = new $root.api.Ping(); + if (object.timeMs != null) + if ($util.Long) + (message.timeMs = $util.Long.fromValue(object.timeMs)).unsigned = true; + else if (typeof object.timeMs === "string") + message.timeMs = parseInt(object.timeMs, 10); + else if (typeof object.timeMs === "number") + message.timeMs = object.timeMs; + else if (typeof object.timeMs === "object") + message.timeMs = new $util.LongBits(object.timeMs.low >>> 0, object.timeMs.high >>> 0).toNumber(true); + return message; }; /** @@ -463,8 +491,22 @@ export const api = $root.api = (() => { * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ - Ping.toObject = function toObject() { - return {}; + Ping.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.defaults) + if ($util.Long) { + let long = new $util.Long(0, 0, true); + object.timeMs = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.timeMs = options.longs === String ? "0" : 0; + if (message.timeMs != null && message.hasOwnProperty("timeMs")) + if (typeof message.timeMs === "number") + object.timeMs = options.longs === String ? String(message.timeMs) : message.timeMs; + else + object.timeMs = options.longs === String ? $util.Long.prototype.toString.call(message.timeMs) : options.longs === Number ? new $util.LongBits(message.timeMs.low >>> 0, message.timeMs.high >>> 0).toNumber(true) : message.timeMs; + return object; }; /** @@ -502,6 +544,7 @@ export const api = $root.api = (() => { * Properties of a Pong. * @memberof api * @interface IPong + * @property {number|Long|null} [timeMs] Pong timeMs */ /** @@ -519,6 +562,14 @@ export const api = $root.api = (() => { this[keys[i]] = properties[keys[i]]; } + /** + * Pong timeMs. + * @member {number|Long} timeMs + * @memberof api.Pong + * @instance + */ + Pong.prototype.timeMs = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + /** * Creates a new Pong instance using the specified properties. * @function create @@ -543,6 +594,8 @@ export const api = $root.api = (() => { Pong.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); + if (message.timeMs != null && Object.hasOwnProperty.call(message, "timeMs")) + writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.timeMs); return writer; }; @@ -577,6 +630,10 @@ export const api = $root.api = (() => { while (reader.pos < end) { let tag = reader.uint32(); switch (tag >>> 3) { + case 1: { + message.timeMs = reader.uint64(); + break; + } default: reader.skipType(tag & 7); break; @@ -612,6 +669,9 @@ export const api = $root.api = (() => { Pong.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; + if (message.timeMs != null && message.hasOwnProperty("timeMs")) + if (!$util.isInteger(message.timeMs) && !(message.timeMs && $util.isInteger(message.timeMs.low) && $util.isInteger(message.timeMs.high))) + return "timeMs: integer|Long expected"; return null; }; @@ -626,7 +686,17 @@ export const api = $root.api = (() => { Pong.fromObject = function fromObject(object) { if (object instanceof $root.api.Pong) return object; - return new $root.api.Pong(); + let message = new $root.api.Pong(); + if (object.timeMs != null) + if ($util.Long) + (message.timeMs = $util.Long.fromValue(object.timeMs)).unsigned = true; + else if (typeof object.timeMs === "string") + message.timeMs = parseInt(object.timeMs, 10); + else if (typeof object.timeMs === "number") + message.timeMs = object.timeMs; + else if (typeof object.timeMs === "object") + message.timeMs = new $util.LongBits(object.timeMs.low >>> 0, object.timeMs.high >>> 0).toNumber(true); + return message; }; /** @@ -638,8 +708,22 @@ export const api = $root.api = (() => { * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ - Pong.toObject = function toObject() { - return {}; + Pong.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.defaults) + if ($util.Long) { + let long = new $util.Long(0, 0, true); + object.timeMs = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.timeMs = options.longs === String ? "0" : 0; + if (message.timeMs != null && message.hasOwnProperty("timeMs")) + if (typeof message.timeMs === "number") + object.timeMs = options.longs === String ? String(message.timeMs) : message.timeMs; + else + object.timeMs = options.longs === String ? $util.Long.prototype.toString.call(message.timeMs) : options.longs === Number ? new $util.LongBits(message.timeMs.low >>> 0, message.timeMs.high >>> 0).toNumber(true) : message.timeMs; + return object; }; /** @@ -1660,6 +1744,7 @@ export const api = $root.api = (() => { * Properties of a ResLobbyView. * @memberof api * @interface IResLobbyView + * @property {Array.|null} [tables] ResLobbyView tables */ /** @@ -1671,12 +1756,21 @@ export const api = $root.api = (() => { * @param {api.IResLobbyView=} [properties] Properties to set */ function ResLobbyView(properties) { + this.tables = []; 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]]; } + /** + * ResLobbyView tables. + * @member {Array.} tables + * @memberof api.ResLobbyView + * @instance + */ + ResLobbyView.prototype.tables = $util.emptyArray; + /** * Creates a new ResLobbyView instance using the specified properties. * @function create @@ -1701,6 +1795,9 @@ export const api = $root.api = (() => { ResLobbyView.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); + if (message.tables != null && message.tables.length) + for (let i = 0; i < message.tables.length; ++i) + $root.api.LobbyTable.encode(message.tables[i], writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); return writer; }; @@ -1735,6 +1832,12 @@ export const api = $root.api = (() => { while (reader.pos < end) { let tag = reader.uint32(); switch (tag >>> 3) { + case 3: { + if (!(message.tables && message.tables.length)) + message.tables = []; + message.tables.push($root.api.LobbyTable.decode(reader, reader.uint32())); + break; + } default: reader.skipType(tag & 7); break; @@ -1770,6 +1873,15 @@ export const api = $root.api = (() => { ResLobbyView.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; + if (message.tables != null && message.hasOwnProperty("tables")) { + if (!Array.isArray(message.tables)) + return "tables: array expected"; + for (let i = 0; i < message.tables.length; ++i) { + let error = $root.api.LobbyTable.verify(message.tables[i]); + if (error) + return "tables." + error; + } + } return null; }; @@ -1784,7 +1896,18 @@ export const api = $root.api = (() => { ResLobbyView.fromObject = function fromObject(object) { if (object instanceof $root.api.ResLobbyView) return object; - return new $root.api.ResLobbyView(); + let message = new $root.api.ResLobbyView(); + if (object.tables) { + if (!Array.isArray(object.tables)) + throw TypeError(".api.ResLobbyView.tables: array expected"); + message.tables = []; + for (let i = 0; i < object.tables.length; ++i) { + if (typeof object.tables[i] !== "object") + throw TypeError(".api.ResLobbyView.tables: object expected"); + message.tables[i] = $root.api.LobbyTable.fromObject(object.tables[i]); + } + } + return message; }; /** @@ -1796,8 +1919,18 @@ export const api = $root.api = (() => { * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ - ResLobbyView.toObject = function toObject() { - return {}; + ResLobbyView.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.arrays || options.defaults) + object.tables = []; + if (message.tables && message.tables.length) { + object.tables = []; + for (let j = 0; j < message.tables.length; ++j) + object.tables[j] = $root.api.LobbyTable.toObject(message.tables[j], options); + } + return object; }; /** @@ -1829,6 +1962,588 @@ export const api = $root.api = (() => { return ResLobbyView; })(); + api.LobbyTable = (function() { + + /** + * Properties of a LobbyTable. + * @memberof api + * @interface ILobbyTable + * @property {number|null} [tableNo] LobbyTable tableNo + * @property {number|null} [playerNum] LobbyTable playerNum + * @property {number|null} [robotNum] LobbyTable robotNum + * @property {Array.|null} [players] LobbyTable players + */ + + /** + * Constructs a new LobbyTable. + * @memberof api + * @classdesc Represents a LobbyTable. + * @implements ILobbyTable + * @constructor + * @param {api.ILobbyTable=} [properties] Properties to set + */ + function LobbyTable(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]]; + } + + /** + * LobbyTable tableNo. + * @member {number} tableNo + * @memberof api.LobbyTable + * @instance + */ + LobbyTable.prototype.tableNo = 0; + + /** + * LobbyTable playerNum. + * @member {number} playerNum + * @memberof api.LobbyTable + * @instance + */ + LobbyTable.prototype.playerNum = 0; + + /** + * LobbyTable robotNum. + * @member {number} robotNum + * @memberof api.LobbyTable + * @instance + */ + LobbyTable.prototype.robotNum = 0; + + /** + * LobbyTable players. + * @member {Array.} players + * @memberof api.LobbyTable + * @instance + */ + LobbyTable.prototype.players = $util.emptyArray; + + /** + * Creates a new LobbyTable instance using the specified properties. + * @function create + * @memberof api.LobbyTable + * @static + * @param {api.ILobbyTable=} [properties] Properties to set + * @returns {api.LobbyTable} LobbyTable instance + */ + LobbyTable.create = function create(properties) { + return new LobbyTable(properties); + }; + + /** + * Encodes the specified LobbyTable message. Does not implicitly {@link api.LobbyTable.verify|verify} messages. + * @function encode + * @memberof api.LobbyTable + * @static + * @param {api.ILobbyTable} message LobbyTable message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + LobbyTable.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); + if (message.playerNum != null && Object.hasOwnProperty.call(message, "playerNum")) + writer.uint32(/* id 2, wireType 0 =*/16).int32(message.playerNum); + if (message.robotNum != null && Object.hasOwnProperty.call(message, "robotNum")) + writer.uint32(/* id 3, wireType 0 =*/24).int32(message.robotNum); + if (message.players != null && message.players.length) + for (let i = 0; i < message.players.length; ++i) + $root.api.LobbyPlayer.encode(message.players[i], writer.uint32(/* id 4, wireType 2 =*/34).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified LobbyTable message, length delimited. Does not implicitly {@link api.LobbyTable.verify|verify} messages. + * @function encodeDelimited + * @memberof api.LobbyTable + * @static + * @param {api.ILobbyTable} message LobbyTable message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + LobbyTable.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a LobbyTable message from the specified reader or buffer. + * @function decode + * @memberof api.LobbyTable + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {api.LobbyTable} LobbyTable + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + LobbyTable.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.LobbyTable(); + while (reader.pos < end) { + let tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.tableNo = reader.int32(); + break; + } + case 2: { + message.playerNum = reader.int32(); + break; + } + case 3: { + message.robotNum = reader.int32(); + break; + } + case 4: { + if (!(message.players && message.players.length)) + message.players = []; + message.players.push($root.api.LobbyPlayer.decode(reader, reader.uint32())); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a LobbyTable message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof api.LobbyTable + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {api.LobbyTable} LobbyTable + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + LobbyTable.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a LobbyTable message. + * @function verify + * @memberof api.LobbyTable + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + LobbyTable.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"; + if (message.playerNum != null && message.hasOwnProperty("playerNum")) + if (!$util.isInteger(message.playerNum)) + return "playerNum: integer expected"; + if (message.robotNum != null && message.hasOwnProperty("robotNum")) + if (!$util.isInteger(message.robotNum)) + return "robotNum: 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.LobbyPlayer.verify(message.players[i]); + if (error) + return "players." + error; + } + } + return null; + }; + + /** + * Creates a LobbyTable message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof api.LobbyTable + * @static + * @param {Object.} object Plain object + * @returns {api.LobbyTable} LobbyTable + */ + LobbyTable.fromObject = function fromObject(object) { + if (object instanceof $root.api.LobbyTable) + return object; + let message = new $root.api.LobbyTable(); + if (object.tableNo != null) + message.tableNo = object.tableNo | 0; + if (object.playerNum != null) + message.playerNum = object.playerNum | 0; + if (object.robotNum != null) + message.robotNum = object.robotNum | 0; + if (object.players) { + if (!Array.isArray(object.players)) + throw TypeError(".api.LobbyTable.players: array expected"); + message.players = []; + for (let i = 0; i < object.players.length; ++i) { + if (typeof object.players[i] !== "object") + throw TypeError(".api.LobbyTable.players: object expected"); + message.players[i] = $root.api.LobbyPlayer.fromObject(object.players[i]); + } + } + return message; + }; + + /** + * Creates a plain object from a LobbyTable message. Also converts values to other types if specified. + * @function toObject + * @memberof api.LobbyTable + * @static + * @param {api.LobbyTable} message LobbyTable + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + LobbyTable.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.arrays || options.defaults) + object.players = []; + if (options.defaults) { + object.tableNo = 0; + object.playerNum = 0; + object.robotNum = 0; + } + if (message.tableNo != null && message.hasOwnProperty("tableNo")) + object.tableNo = message.tableNo; + if (message.playerNum != null && message.hasOwnProperty("playerNum")) + object.playerNum = message.playerNum; + if (message.robotNum != null && message.hasOwnProperty("robotNum")) + object.robotNum = message.robotNum; + if (message.players && message.players.length) { + object.players = []; + for (let j = 0; j < message.players.length; ++j) + object.players[j] = $root.api.LobbyPlayer.toObject(message.players[j], options); + } + return object; + }; + + /** + * Converts this LobbyTable to JSON. + * @function toJSON + * @memberof api.LobbyTable + * @instance + * @returns {Object.} JSON object + */ + LobbyTable.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for LobbyTable + * @function getTypeUrl + * @memberof api.LobbyTable + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + LobbyTable.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/api.LobbyTable"; + }; + + return LobbyTable; + })(); + + api.LobbyPlayer = (function() { + + /** + * Properties of a LobbyPlayer. + * @memberof api + * @interface ILobbyPlayer + * @property {boolean|null} [robot] LobbyPlayer robot + * @property {number|Long|null} [id] LobbyPlayer id + * @property {string|null} [username] LobbyPlayer username + * @property {string|null} [avatar] LobbyPlayer avatar + */ + + /** + * Constructs a new LobbyPlayer. + * @memberof api + * @classdesc Represents a LobbyPlayer. + * @implements ILobbyPlayer + * @constructor + * @param {api.ILobbyPlayer=} [properties] Properties to set + */ + function LobbyPlayer(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]]; + } + + /** + * LobbyPlayer robot. + * @member {boolean} robot + * @memberof api.LobbyPlayer + * @instance + */ + LobbyPlayer.prototype.robot = false; + + /** + * LobbyPlayer id. + * @member {number|Long} id + * @memberof api.LobbyPlayer + * @instance + */ + LobbyPlayer.prototype.id = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * LobbyPlayer username. + * @member {string} username + * @memberof api.LobbyPlayer + * @instance + */ + LobbyPlayer.prototype.username = ""; + + /** + * LobbyPlayer avatar. + * @member {string} avatar + * @memberof api.LobbyPlayer + * @instance + */ + LobbyPlayer.prototype.avatar = ""; + + /** + * Creates a new LobbyPlayer instance using the specified properties. + * @function create + * @memberof api.LobbyPlayer + * @static + * @param {api.ILobbyPlayer=} [properties] Properties to set + * @returns {api.LobbyPlayer} LobbyPlayer instance + */ + LobbyPlayer.create = function create(properties) { + return new LobbyPlayer(properties); + }; + + /** + * Encodes the specified LobbyPlayer message. Does not implicitly {@link api.LobbyPlayer.verify|verify} messages. + * @function encode + * @memberof api.LobbyPlayer + * @static + * @param {api.ILobbyPlayer} message LobbyPlayer message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + LobbyPlayer.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); + return writer; + }; + + /** + * Encodes the specified LobbyPlayer message, length delimited. Does not implicitly {@link api.LobbyPlayer.verify|verify} messages. + * @function encodeDelimited + * @memberof api.LobbyPlayer + * @static + * @param {api.ILobbyPlayer} message LobbyPlayer message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + LobbyPlayer.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a LobbyPlayer message from the specified reader or buffer. + * @function decode + * @memberof api.LobbyPlayer + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {api.LobbyPlayer} LobbyPlayer + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + LobbyPlayer.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.LobbyPlayer(); + 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; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a LobbyPlayer message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof api.LobbyPlayer + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {api.LobbyPlayer} LobbyPlayer + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + LobbyPlayer.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a LobbyPlayer message. + * @function verify + * @memberof api.LobbyPlayer + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + LobbyPlayer.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"; + return null; + }; + + /** + * Creates a LobbyPlayer message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof api.LobbyPlayer + * @static + * @param {Object.} object Plain object + * @returns {api.LobbyPlayer} LobbyPlayer + */ + LobbyPlayer.fromObject = function fromObject(object) { + if (object instanceof $root.api.LobbyPlayer) + return object; + let message = new $root.api.LobbyPlayer(); + 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); + return message; + }; + + /** + * Creates a plain object from a LobbyPlayer message. Also converts values to other types if specified. + * @function toObject + * @memberof api.LobbyPlayer + * @static + * @param {api.LobbyPlayer} message LobbyPlayer + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + LobbyPlayer.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + 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 = ""; + } + 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; + return object; + }; + + /** + * Converts this LobbyPlayer to JSON. + * @function toJSON + * @memberof api.LobbyPlayer + * @instance + * @returns {Object.} JSON object + */ + LobbyPlayer.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for LobbyPlayer + * @function getTypeUrl + * @memberof api.LobbyPlayer + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + LobbyPlayer.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/api.LobbyPlayer"; + }; + + return LobbyPlayer; + })(); + api.ReqCreateTable = (function() { /** diff --git a/internal/game/player.go b/internal/game/player.go index fd6d2a4..41e5cf4 100644 --- a/internal/game/player.go +++ b/internal/game/player.go @@ -5,9 +5,9 @@ type Player struct { Id int64 Username string Avatar string - cards [2]*Card // 手牌 - chip int // 玩家筹码 - + Cards [2]*Card // 手牌 + Chip int // 玩家筹码 + Status int32 // 状态: 1待准备开始,2已准备开始,3等待其他玩家动作,4待大盲注,5待小盲注,6待跟注,7已弃 } func NewPlayer() *Player { diff --git a/internal/server/route.go b/internal/server/route.go index d505002..a9bb956 100644 --- a/internal/server/route.go +++ b/internal/server/route.go @@ -32,8 +32,7 @@ func NewServer() *gin.Engine { user.GET("/findByName", service.FindUserByName) game := base.Group("/game") - game.GET("/createTable", service.CreateTable) // 新建牌桌 - game.GET("/lobby", service.GetLobbyView) // 游戏大厅 + game.GET("/lobby", service.GetLobbyView) // 游戏大厅 return server } diff --git a/internal/server/wsroute.go b/internal/server/wsroute.go index e389908..4e0ebbb 100644 --- a/internal/server/wsroute.go +++ b/internal/server/wsroute.go @@ -28,8 +28,9 @@ func init() { // client.Write(res) return res, nil }) - // 创建桌面 - HandleNetAccountMsg(&api.ReqCreateTable{}, service.CreateNewTable) + + HandleNetAccountMsg(&api.ReqCreateTable{}, service.CreateNewTable) // 创建桌面 + HandleNetAccountMsg(&api.ReqLobbyView{}, service.GetLobbyView2) // 查询所有游戏桌面 } func checkExistsTypeHandler(op int32, err error) { diff --git a/internal/service/store/store.go b/internal/service/store/store.go index 22b6ae0..dfe95de 100644 --- a/internal/service/store/store.go +++ b/internal/service/store/store.go @@ -45,6 +45,9 @@ func GetLobbyTablesView() []*vo.TableVO { 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 } diff --git a/internal/service/table.go b/internal/service/table.go index 9503f61..bc17102 100644 --- a/internal/service/table.go +++ b/internal/service/table.go @@ -4,11 +4,11 @@ import ( "github.com/gin-gonic/gin" "github.com/golang/protobuf/proto" "net/http" - "strconv" "texas-poker-bk/api" "texas-poker-bk/internal/game" "texas-poker-bk/internal/service/store" "texas-poker-bk/internal/session" + "texas-poker-bk/tool/collect" ) // CreateNewTable 创建桌面 TODO 当前在房间则不可创建房间了 @@ -43,57 +43,51 @@ func CreateNewTable(account session.NetAccount, msg *api.ReqCreateTable) (proto. return &api.ResCreateTable{TableNo: table.TableNo}, nil } -// CreateTable 创建新桌面 -func CreateTable(ctx *gin.Context) { - user := GetSubject(ctx) - - // 人数,机器人数 - players := ctx.PostForm("players") - robots := ctx.PostForm("robots") - playerNum, err := strconv.Atoi(players) - if err != nil { - ctx.JSON(http.StatusBadRequest, gin.H{"msg": "人数格式有误"}) - return - } - robotNum, err := strconv.Atoi(robots) - if err != nil { - ctx.JSON(http.StatusBadRequest, gin.H{"msg": "机器人数格式有误"}) - return - } - if playerNum+robotNum <= 0 { - ctx.JSON(http.StatusBadRequest, gin.H{"msg": "至少添加一个玩家或机器人"}) - return - } - // 初始化一个牌桌 - table := &game.Table{} - table.TableNo = store.TableNo.Add(1) - table.PlayerNum = int32(playerNum) + 1 - table.RobotNum = int32(playerNum) - table.Players = make([]*game.Player, playerNum) - table.Robots = make([]*game.Robot, robotNum) - // 房主 [0] - owner := &game.Player{ - Id: user.Id, - Username: user.Name, - Avatar: user.Avatar, - } - table.Players[0] = owner - for i := 0; i < robotNum; i++ { - table.Robots[i] = &game.Robot{} - } - err = store.SaveNewTable(table) - if err != nil { - ctx.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()}) - return - } - ctx.JSON(http.StatusOK, gin.H{"data": gin.H{"tableNo": table.TableNo}}) -} - 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) { + res := &api.ResLobbyView{} + if store.LobbyTables == nil || len(store.LobbyTables) == 0 { + return res, nil + } + tables := make([]*api.LobbyTable, len(store.LobbyTables)) + res.Tables = tables + + // 遍历 store tables 转换为视图层结构体 + idx := 0 + for _, t := range store.LobbyTables { + table := &api.LobbyTable{TableNo: t.TableNo, PlayerNum: t.PlayerNum, RobotNum: t.RobotNum} + table.Players = make([]*api.LobbyPlayer, t.PlayerNum+t.RobotNum) + + playerIdx := 0 + if collect.IsNotEmptySlice(t.Players) { + for _, p := range t.Players { + if p == nil { + playerIdx++ + continue + } + player := &api.LobbyPlayer{Robot: false, Id: p.Id, Username: p.Username, Avatar: p.Avatar} + table.Players[playerIdx] = player + playerIdx++ + } + } + if collect.IsNotEmptySlice(t.Robots) { + for _, _ = range t.Robots { + table.Players[playerIdx] = &api.LobbyPlayer{Robot: true} + playerIdx++ + } + } + + tables[idx] = table + idx++ + } + return res, nil +} + // JoinTable 加入牌桌 func JoinTable(ctx *gin.Context) {