Browse Source

"big small blind":

master
tangmingyou 4 years ago
parent
commit
4867dab88f
  1. 107
      api/poker.pb.go
  2. 14
      api/poker.proto
  3. 83
      api/proto.js
  4. 3
      cmd/main.go
  5. 3
      etc/config.toml
  6. 3
      internal/conf/conf.go
  7. 11
      internal/game/player.go
  8. 18
      internal/game/table.go
  9. 1
      internal/server/route.go
  10. 22
      internal/server/ws.go
  11. 16
      internal/service/auth.go
  12. 12
      internal/service/table.go
  13. 30
      tool/ip/ip.go

107
api/poker.pb.go

@ -22,6 +22,7 @@ const (
// v1.0.0
// protocol
// doc: https://protobuf.dev/programming-guides/proto3
type ProtoWrap struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -1135,8 +1136,10 @@ type ResGameFullStatus struct {
Chip int32 `protobuf:"varint,4,opt,name=chip,proto3" json:"chip,omitempty"` // 牌桌筹码
RoundTimes int32 `protobuf:"varint,5,opt,name=roundTimes,proto3" json:"roundTimes,omitempty"` // 回合次数
PlayerId int64 `protobuf:"varint,6,opt,name=playerId,proto3" json:"playerId,omitempty"` // 当前玩家id
PublicCard []*Card `protobuf:"bytes,9,rep,name=publicCard,proto3" json:"publicCard,omitempty"` // 公共牌
Players []*TablePlayer `protobuf:"bytes,10,rep,name=players,proto3" json:"players,omitempty"`
BigBlindPos int32 `protobuf:"varint,7,opt,name=bigBlindPos,proto3" json:"bigBlindPos,omitempty"` // 大盲注位
SmallBlindPos int32 `protobuf:"varint,8,opt,name=smallBlindPos,proto3" json:"smallBlindPos,omitempty"` // 小盲注位
PublicCard []*Card `protobuf:"bytes,14,rep,name=publicCard,proto3" json:"publicCard,omitempty"` // 公共牌
Players []*TablePlayer `protobuf:"bytes,15,rep,name=players,proto3" json:"players,omitempty"`
}
func (x *ResGameFullStatus) Reset() {
@ -1213,6 +1216,20 @@ func (x *ResGameFullStatus) GetPlayerId() int64 {
return 0
}
func (x *ResGameFullStatus) GetBigBlindPos() int32 {
if x != nil {
return x.BigBlindPos
}
return 0
}
func (x *ResGameFullStatus) GetSmallBlindPos() int32 {
if x != nil {
return x.SmallBlindPos
}
return 0
}
func (x *ResGameFullStatus) GetPublicCard() []*Card {
if x != nil {
return x.PublicCard
@ -1238,8 +1255,9 @@ type TablePlayer struct {
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"` // 手牌
LastStatus int32 `protobuf:"varint,7,opt,name=lastStatus,proto3" json:"lastStatus,omitempty"`
Master bool `protobuf:"varint,8,opt,name=master,proto3" json:"master,omitempty"` // 是否房主`
HandCard []*Card `protobuf:"bytes,15,rep,name=handCard,proto3" json:"handCard,omitempty"` // 手牌
}
func (x *TablePlayer) Reset() {
@ -1316,6 +1334,13 @@ func (x *TablePlayer) GetStatus() int32 {
return 0
}
func (x *TablePlayer) GetLastStatus() int32 {
if x != nil {
return x.LastStatus
}
return 0
}
func (x *TablePlayer) GetMaster() bool {
if x != nil {
return x.Master
@ -1668,7 +1693,7 @@ var file_poker_proto_rawDesc = []byte{
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, 0x13, 0x0a, 0x11, 0x52,
0x65, 0x71, 0x47, 0x61, 0x6d, 0x65, 0x46, 0x75, 0x6c, 0x6c, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73,
0x22, 0x8a, 0x02, 0x0a, 0x11, 0x52, 0x65, 0x73, 0x47, 0x61, 0x6d, 0x65, 0x46, 0x75, 0x6c, 0x6c,
0x22, 0xd2, 0x02, 0x0a, 0x11, 0x52, 0x65, 0x73, 0x47, 0x61, 0x6d, 0x65, 0x46, 0x75, 0x6c, 0x6c,
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,
@ -1679,39 +1704,45 @@ var file_poker_proto_rawDesc = []byte{
0x75, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a,
0x72, 0x6f, 0x75, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c,
0x61, 0x79, 0x65, 0x72, 0x49, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x6c,
0x61, 0x79, 0x65, 0x72, 0x49, 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, 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, 0xd2, 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, 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, 0x09, 0x52, 0x04, 0x73, 0x75, 0x69, 0x74,
0x22, 0x0e, 0x0a, 0x0c, 0x52, 0x65, 0x71, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74,
0x22, 0x25, 0x0a, 0x0f, 0x52, 0x65, 0x73, 0x42, 0x69, 0x67, 0x42, 0x6c, 0x69, 0x6e, 0x64, 0x43,
0x68, 0x69, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x68, 0x69, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28,
0x05, 0x52, 0x04, 0x63, 0x68, 0x69, 0x70, 0x22, 0x27, 0x0a, 0x11, 0x52, 0x65, 0x73, 0x53, 0x6d,
0x61, 0x6c, 0x6c, 0x42, 0x6c, 0x69, 0x6e, 0x64, 0x43, 0x68, 0x69, 0x70, 0x12, 0x12, 0x0a, 0x04,
0x63, 0x68, 0x69, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x68, 0x69, 0x70,
0x22, 0x15, 0x0a, 0x13, 0x52, 0x65, 0x71, 0x44, 0x69, 0x73, 0x6d, 0x69, 0x73, 0x73, 0x47, 0x61,
0x6d, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x15, 0x0a, 0x13, 0x52, 0x65, 0x73, 0x44, 0x69,
0x73, 0x6d, 0x69, 0x73, 0x73, 0x47, 0x61, 0x6d, 0x65, 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,
0x61, 0x79, 0x65, 0x72, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x62, 0x69, 0x67, 0x42, 0x6c, 0x69,
0x6e, 0x64, 0x50, 0x6f, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x62, 0x69, 0x67,
0x42, 0x6c, 0x69, 0x6e, 0x64, 0x50, 0x6f, 0x73, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x6d, 0x61, 0x6c,
0x6c, 0x42, 0x6c, 0x69, 0x6e, 0x64, 0x50, 0x6f, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52,
0x0d, 0x73, 0x6d, 0x61, 0x6c, 0x6c, 0x42, 0x6c, 0x69, 0x6e, 0x64, 0x50, 0x6f, 0x73, 0x12, 0x29,
0x0a, 0x0a, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x43, 0x61, 0x72, 0x64, 0x18, 0x0e, 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, 0x12, 0x2a, 0x0a, 0x07, 0x70, 0x6c, 0x61,
0x79, 0x65, 0x72, 0x73, 0x18, 0x0f, 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, 0xf2, 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, 0x1e, 0x0a, 0x0a, 0x6c,
0x61, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52,
0x0a, 0x6c, 0x61, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x6d,
0x61, 0x73, 0x74, 0x65, 0x72, 0x18, 0x08, 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,
0x0f, 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, 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, 0x09, 0x52, 0x04, 0x73, 0x75, 0x69, 0x74, 0x22, 0x0e, 0x0a, 0x0c, 0x52, 0x65, 0x71, 0x47,
0x61, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x22, 0x25, 0x0a, 0x0f, 0x52, 0x65, 0x73, 0x42,
0x69, 0x67, 0x42, 0x6c, 0x69, 0x6e, 0x64, 0x43, 0x68, 0x69, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x63,
0x68, 0x69, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x68, 0x69, 0x70, 0x22,
0x27, 0x0a, 0x11, 0x52, 0x65, 0x73, 0x53, 0x6d, 0x61, 0x6c, 0x6c, 0x42, 0x6c, 0x69, 0x6e, 0x64,
0x43, 0x68, 0x69, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x68, 0x69, 0x70, 0x18, 0x01, 0x20, 0x01,
0x28, 0x05, 0x52, 0x04, 0x63, 0x68, 0x69, 0x70, 0x22, 0x15, 0x0a, 0x13, 0x52, 0x65, 0x71, 0x44,
0x69, 0x73, 0x6d, 0x69, 0x73, 0x73, 0x47, 0x61, 0x6d, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x22,
0x15, 0x0a, 0x13, 0x52, 0x65, 0x73, 0x44, 0x69, 0x73, 0x6d, 0x69, 0x73, 0x73, 0x47, 0x61, 0x6d,
0x65, 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 (

14
api/poker.proto

@ -7,6 +7,7 @@ option go_package = "./api;api";
/*
* v1.0.0
* protocol
* doc: https://protobuf.dev/programming-guides/proto3
*/
message ProtoWrap {
int32 ver = 1; // version
@ -129,9 +130,12 @@ message ResGameFullStatus { // 玩家当前游戏状态: 断线,重新登录....
int32 chip = 4; //
int32 roundTimes = 5; //
int64 playerId = 6; // id
int32 bigBlindPos = 7; //
int32 smallBlindPos = 8; //
// int64 masterId = 9;
repeated Card publicCard = 9; //
repeated TablePlayer players = 10;
repeated Card publicCard = 14; //
repeated TablePlayer players = 15;
}
message TablePlayer {
@ -141,9 +145,9 @@ message TablePlayer {
string avatar = 4;
int32 chip = 5; //
int32 status = 6; // : 1,2,(3,4,5,6,7)
bool master = 7; // `
repeated Card handCard = 8; //
int32 lastStatus = 7; // TODO ,
bool master = 8; // `
repeated Card handCard = 15; //
}
message Card {

83
api/proto.js

@ -4772,6 +4772,8 @@ export const api = $root.api = (() => {
* @property {number|null} [chip] ResGameFullStatus chip
* @property {number|null} [roundTimes] ResGameFullStatus roundTimes
* @property {number|Long|null} [playerId] ResGameFullStatus playerId
* @property {number|null} [bigBlindPos] ResGameFullStatus bigBlindPos
* @property {number|null} [smallBlindPos] ResGameFullStatus smallBlindPos
* @property {Array.<api.ICard>|null} [publicCard] ResGameFullStatus publicCard
* @property {Array.<api.ITablePlayer>|null} [players] ResGameFullStatus players
*/
@ -4841,6 +4843,22 @@ export const api = $root.api = (() => {
*/
ResGameFullStatus.prototype.playerId = $util.Long ? $util.Long.fromBits(0,0,false) : 0;
/**
* ResGameFullStatus bigBlindPos.
* @member {number} bigBlindPos
* @memberof api.ResGameFullStatus
* @instance
*/
ResGameFullStatus.prototype.bigBlindPos = 0;
/**
* ResGameFullStatus smallBlindPos.
* @member {number} smallBlindPos
* @memberof api.ResGameFullStatus
* @instance
*/
ResGameFullStatus.prototype.smallBlindPos = 0;
/**
* ResGameFullStatus publicCard.
* @member {Array.<api.ICard>} publicCard
@ -4893,12 +4911,16 @@ export const api = $root.api = (() => {
writer.uint32(/* id 5, wireType 0 =*/40).int32(message.roundTimes);
if (message.playerId != null && Object.hasOwnProperty.call(message, "playerId"))
writer.uint32(/* id 6, wireType 0 =*/48).int64(message.playerId);
if (message.bigBlindPos != null && Object.hasOwnProperty.call(message, "bigBlindPos"))
writer.uint32(/* id 7, wireType 0 =*/56).int32(message.bigBlindPos);
if (message.smallBlindPos != null && Object.hasOwnProperty.call(message, "smallBlindPos"))
writer.uint32(/* id 8, wireType 0 =*/64).int32(message.smallBlindPos);
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();
$root.api.Card.encode(message.publicCard[i], writer.uint32(/* id 14, wireType 2 =*/114).fork()).ldelim();
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();
$root.api.TablePlayer.encode(message.players[i], writer.uint32(/* id 15, wireType 2 =*/122).fork()).ldelim();
return writer;
};
@ -4957,13 +4979,21 @@ export const api = $root.api = (() => {
message.playerId = reader.int64();
break;
}
case 9: {
case 7: {
message.bigBlindPos = reader.int32();
break;
}
case 8: {
message.smallBlindPos = reader.int32();
break;
}
case 14: {
if (!(message.publicCard && message.publicCard.length))
message.publicCard = [];
message.publicCard.push($root.api.Card.decode(reader, reader.uint32()));
break;
}
case 10: {
case 15: {
if (!(message.players && message.players.length))
message.players = [];
message.players.push($root.api.TablePlayer.decode(reader, reader.uint32()));
@ -5022,6 +5052,12 @@ export const api = $root.api = (() => {
if (message.playerId != null && message.hasOwnProperty("playerId"))
if (!$util.isInteger(message.playerId) && !(message.playerId && $util.isInteger(message.playerId.low) && $util.isInteger(message.playerId.high)))
return "playerId: integer|Long expected";
if (message.bigBlindPos != null && message.hasOwnProperty("bigBlindPos"))
if (!$util.isInteger(message.bigBlindPos))
return "bigBlindPos: integer expected";
if (message.smallBlindPos != null && message.hasOwnProperty("smallBlindPos"))
if (!$util.isInteger(message.smallBlindPos))
return "smallBlindPos: integer expected";
if (message.publicCard != null && message.hasOwnProperty("publicCard")) {
if (!Array.isArray(message.publicCard))
return "publicCard: array expected";
@ -5074,6 +5110,10 @@ export const api = $root.api = (() => {
message.playerId = object.playerId;
else if (typeof object.playerId === "object")
message.playerId = new $util.LongBits(object.playerId.low >>> 0, object.playerId.high >>> 0).toNumber();
if (object.bigBlindPos != null)
message.bigBlindPos = object.bigBlindPos | 0;
if (object.smallBlindPos != null)
message.smallBlindPos = object.smallBlindPos | 0;
if (object.publicCard) {
if (!Array.isArray(object.publicCard))
throw TypeError(".api.ResGameFullStatus.publicCard: array expected");
@ -5125,6 +5165,8 @@ export const api = $root.api = (() => {
object.playerId = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
} else
object.playerId = options.longs === String ? "0" : 0;
object.bigBlindPos = 0;
object.smallBlindPos = 0;
}
if (message.inGame != null && message.hasOwnProperty("inGame"))
object.inGame = message.inGame;
@ -5141,6 +5183,10 @@ export const api = $root.api = (() => {
object.playerId = options.longs === String ? String(message.playerId) : message.playerId;
else
object.playerId = options.longs === String ? $util.Long.prototype.toString.call(message.playerId) : options.longs === Number ? new $util.LongBits(message.playerId.low >>> 0, message.playerId.high >>> 0).toNumber() : message.playerId;
if (message.bigBlindPos != null && message.hasOwnProperty("bigBlindPos"))
object.bigBlindPos = message.bigBlindPos;
if (message.smallBlindPos != null && message.hasOwnProperty("smallBlindPos"))
object.smallBlindPos = message.smallBlindPos;
if (message.publicCard && message.publicCard.length) {
object.publicCard = [];
for (let j = 0; j < message.publicCard.length; ++j)
@ -5195,6 +5241,7 @@ export const api = $root.api = (() => {
* @property {string|null} [avatar] TablePlayer avatar
* @property {number|null} [chip] TablePlayer chip
* @property {number|null} [status] TablePlayer status
* @property {number|null} [lastStatus] TablePlayer lastStatus
* @property {boolean|null} [master] TablePlayer master
* @property {Array.<api.ICard>|null} [handCard] TablePlayer handCard
*/
@ -5263,6 +5310,14 @@ export const api = $root.api = (() => {
*/
TablePlayer.prototype.status = 0;
/**
* TablePlayer lastStatus.
* @member {number} lastStatus
* @memberof api.TablePlayer
* @instance
*/
TablePlayer.prototype.lastStatus = 0;
/**
* TablePlayer master.
* @member {boolean} master
@ -5315,11 +5370,13 @@ export const api = $root.api = (() => {
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.lastStatus != null && Object.hasOwnProperty.call(message, "lastStatus"))
writer.uint32(/* id 7, wireType 0 =*/56).int32(message.lastStatus);
if (message.master != null && Object.hasOwnProperty.call(message, "master"))
writer.uint32(/* id 7, wireType 0 =*/56).bool(message.master);
writer.uint32(/* id 8, wireType 0 =*/64).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();
$root.api.Card.encode(message.handCard[i], writer.uint32(/* id 15, wireType 2 =*/122).fork()).ldelim();
return writer;
};
@ -5379,10 +5436,14 @@ export const api = $root.api = (() => {
break;
}
case 7: {
message.master = reader.bool();
message.lastStatus = reader.int32();
break;
}
case 8: {
message.master = reader.bool();
break;
}
case 15: {
if (!(message.handCard && message.handCard.length))
message.handCard = [];
message.handCard.push($root.api.Card.decode(reader, reader.uint32()));
@ -5441,6 +5502,9 @@ export const api = $root.api = (() => {
if (message.status != null && message.hasOwnProperty("status"))
if (!$util.isInteger(message.status))
return "status: integer expected";
if (message.lastStatus != null && message.hasOwnProperty("lastStatus"))
if (!$util.isInteger(message.lastStatus))
return "lastStatus: integer expected";
if (message.master != null && message.hasOwnProperty("master"))
if (typeof message.master !== "boolean")
return "master: boolean expected";
@ -5487,6 +5551,8 @@ export const api = $root.api = (() => {
message.chip = object.chip | 0;
if (object.status != null)
message.status = object.status | 0;
if (object.lastStatus != null)
message.lastStatus = object.lastStatus | 0;
if (object.master != null)
message.master = Boolean(object.master);
if (object.handCard) {
@ -5528,6 +5594,7 @@ export const api = $root.api = (() => {
object.avatar = "";
object.chip = 0;
object.status = 0;
object.lastStatus = 0;
object.master = false;
}
if (message.robot != null && message.hasOwnProperty("robot"))
@ -5545,6 +5612,8 @@ export const api = $root.api = (() => {
object.chip = message.chip;
if (message.status != null && message.hasOwnProperty("status"))
object.status = message.status;
if (message.lastStatus != null && message.hasOwnProperty("lastStatus"))
object.lastStatus = message.lastStatus;
if (message.master != null && message.hasOwnProperty("master"))
object.master = message.master;
if (message.handCard && message.handCard.length) {

3
cmd/main.go

@ -1,6 +1,7 @@
package main
import (
"fmt"
"math/rand"
"texas-poker-bk/internal/conf"
"texas-poker-bk/internal/server"
@ -12,7 +13,7 @@ func startServer() {
rand.Seed(time.Now().UnixNano())
httpServer := server.NewServer()
err := httpServer.Run(conf.Conf.Http.Addr)
err := httpServer.Run(fmt.Sprintf(":%d", conf.Conf.Http.Port))
if err != nil {
panic(err)
}

3
etc/config.toml

@ -1,6 +1,7 @@
[http]
addr = ":9999"
host = ""
port = 9999
[auth]
aesTokenKey = "9Nz3Y6DES3msAFndz4QsJAECUIFkf+KKaRa+jRnNALk="

3
internal/conf/conf.go

@ -43,7 +43,8 @@ type Auth struct {
}
type Http struct {
Addr string
Host string
Port int
}
type Sqlite struct {

11
internal/game/player.go

@ -13,12 +13,23 @@ type Player struct {
Cards [2]*Card // 手牌
Chip int32 // 玩家筹码
Status int32 // 状态: 1待准备开始,2已准备开始,3等待其他玩家动作,4小盲注跟注, [5待大盲注,5待小盲注,] 6待跟注,7已弃牌
LastStatus int32 // 变化前一个状态
GameTable *Table // 当前牌桌
ProtoWriter letter.ProtoWriter
Lock *sync.Mutex
StatusLock *sync.Mutex
}
func (p *Player) Init() {
p.Lock = new(sync.Mutex)
p.StatusLock = new(sync.Mutex)
}
func (p *Player) SetStatus(status int32) {
p.StatusLock.Lock()
defer p.StatusLock.Unlock()
p.LastStatus = p.Status
p.Status = status
}

18
internal/game/table.go

@ -41,7 +41,7 @@ func (t *Table) PlayerCount() int32 {
}
func (t *Table) NextPosPlayer(current int) int {
for i := current; i < len(t.Players); i++ {
for i := current + 1; i < len(t.Players); i++ {
if t.Players[i] == nil {
continue
}
@ -79,12 +79,15 @@ func (t *Table) JoinPlayer(player *Player) error {
// BuildResGameFullStatus 构建牌桌当前游戏状态消息
func (t *Table) BuildResGameFullStatus() *api.ResGameFullStatus {
resGame := &api.ResGameFullStatus{}
resGame.InGame = collect.In(t.Stage, 2, 3, 4, 5, 6, 7)
resGame.TableNo = t.TableNo
resGame.GameStage = t.Stage
resGame.Chip = t.Chip
resGame.RoundTimes = t.RoundTimes
resGame := &api.ResGameFullStatus{
InGame: collect.In(t.Stage, 2, 3, 4, 5, 6, 7),
TableNo: t.TableNo,
GameStage: t.Stage,
Chip: t.Chip,
RoundTimes: t.RoundTimes,
BigBlindPos: int32(t.BigBlindPos),
SmallBlindPos: int32(t.SmallBlindPos),
}
// 公共牌
resGame.PublicCard = make([]*api.Card, len(t.PublicCards))
@ -109,6 +112,7 @@ func (t *Table) BuildResGameFullStatus() *api.ResGameFullStatus {
Avatar: p.Avatar,
Chip: p.Chip,
Status: p.Status,
LastStatus: p.LastStatus,
Master: t.MasterId == p.Id,
HandCard: make([]*api.Card, 2),
}

1
internal/server/route.go

@ -24,6 +24,7 @@ func NewServer() *gin.Engine {
})
// websocket
conn.GET("/ws", Upgrade)
conn.GET("/route_ws", RouteWs)
auth := base.Group("/auth")
auth.GET("/captcha", service.Captcha) // 验证码

22
internal/server/ws.go

@ -8,10 +8,32 @@ import (
"log"
"net/http"
"texas-poker-bk/api"
"texas-poker-bk/internal/conf"
"texas-poker-bk/internal/session"
"texas-poker-bk/tool/ip"
"time"
)
var (
machineHost string
serverAddr string
)
func init() {
machineHost = ip.InternalIP()
if conf.Conf.Http.Host != "" {
machineHost = conf.Conf.Http.Host
}
serverAddr = fmt.Sprintf("%s:%d", machineHost, conf.Conf.Http.Port)
}
// RouteWs 返回 websocket 路由地址
func RouteWs(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{"data": gin.H{
"wsAddr": serverAddr,
}})
}
func Upgrade(ctx *gin.Context) {
//token, exists := ctx.GetQuery("t")
//if !exists {

16
internal/service/auth.go

@ -58,13 +58,25 @@ func Authorize(ctx *gin.Context) {
}
}
sub := &session.Subject{Id: user.Id, Name: user.Username, Time: time.Now().UnixMilli()}
sub := &session.Subject{
Id: user.Id,
Name: user.Username,
Time: time.Now().UnixMilli(),
}
token, err := EncodeSubject(sub)
if err != nil {
ctx.JSON(http.StatusUnauthorized, gin.H{"msg": err.Error()})
return
}
ctx.JSON(http.StatusOK, gin.H{"data": gin.H{"token": token}})
ctx.JSON(http.StatusOK, gin.H{"data": gin.H{
"token": token,
"user": gin.H{
"id": user.Id,
"username": user.Username,
// TODO avatar...
},
}})
}
// 注册用户到DB

12
internal/service/table.go

@ -28,7 +28,7 @@ func HandleReqCreateTable(account *session.NetAccount, msg *api.ReqCreateTable)
Stage: 1,
Dealer: game.NewDealer(),
PublicCards: [5]*game.Card{&game.Card{Dot: 0, Suit: 3}, &game.Card{Dot: 1, Suit: 3}, nil, nil, nil},
PublicCards: [5]*game.Card{nil, nil, nil, nil, nil}, //&game.Card{Dot: 0, Suit: 3}, &game.Card{Dot: 1, Suit: 3}
PlayerNum: playerNum + 1,
RobotNum: robotNum,
@ -46,6 +46,7 @@ func HandleReqCreateTable(account *session.NetAccount, msg *api.ReqCreateTable)
Username: account.UserName,
Avatar: account.Avatar,
Status: 1,
LastStatus: 0,
Chip: 500,
Cards: [2]*game.Card{},
GameTable: table,
@ -136,6 +137,7 @@ func HandleReqJoinTable(account *session.NetAccount, msg *api.ReqJoinTable) (pro
Username: account.UserName,
Avatar: account.Avatar,
Status: 1,
LastStatus: 0,
Chip: 500,
Cards: [2]*game.Card{nil, nil},
GameTable: table,
@ -253,7 +255,7 @@ func HandleReqReadyStart(player *game.Player, msg *api.ReqReadyStart) (proto.Mes
return &api.ResFail{Msg: msg}, nil
}
player.Status = 2
player.SetStatus(2)
player.GameTable.NoticeGameFullStatus()
return &api.ResSuccess{}, nil
@ -268,7 +270,7 @@ func HandleReqCancelReady(player *game.Player, msg *api.ReqCancelReady) (proto.M
if player.Status != 2 {
return &api.ResFail{Msg: "当前未准备"}, nil
}
player.Status = 1
player.SetStatus(1)
player.GameTable.NoticeGameFullStatus()
return &api.ResSuccess{}, nil
}
@ -353,7 +355,7 @@ func HandleReqGameStart(player *game.Player, msg *api.ReqGameStart) (proto.Messa
p.Cards[i] = table.Dealer.Deal()
}
// 玩家状态置为等待
p.Status = 3
p.SetStatus(3)
}
// 发3张公共牌
for i := 0; i < 5; i++ {
@ -365,7 +367,7 @@ func HandleReqGameStart(player *game.Player, msg *api.ReqGameStart) (proto.Messa
table.PublicCards[i] = nil
}
// 待小盲注位玩家下注
table.Players[table.SmallBlindPos].Status = 4
table.Players[table.SmallBlindPos].SetStatus(4)
// 广播牌桌状态
table.NoticeGameFullStatus()

30
tool/ip/ip.go

@ -0,0 +1,30 @@
package ip
import (
"net"
"strings"
)
// InternalIP return internal ip.
func InternalIP() string {
inters, err := net.Interfaces()
if err != nil {
return ""
}
for _, inter := range inters {
if inter.Flags&net.FlagUp != 0 && !strings.HasPrefix(inter.Name, "lo") {
addrs, err := inter.Addrs()
if err != nil {
continue
}
for _, addr := range addrs {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.IP.String()
}
}
}
}
}
return ""
}
Loading…
Cancel
Save