Browse Source

ws res msg process

master
tangmingyou 4 years ago
parent
commit
6eb14c139e
  1. 2
      api/generate.go
  2. 19
      api/operation.go
  3. 443
      api/poker.pb.go
  4. 32
      api/poker.proto
  5. 1495
      api/proto.js
  6. 1
      cmd/main.go
  7. 2
      internal/server/server.go
  8. 20
      internal/server/ws.go
  9. 4
      internal/server/wsroute.go
  10. 6
      internal/session/net_client.go

2
api/generate.go

@ -1,6 +1,6 @@
package api package api
////go:generate protoc -I. -I$GOPATH/src --go_out=plugins=grpc:. --go_opt=paths=source_relative protocol/protocol.proto ////go:generate protoc -I. -I$GOPATH/src --go_out=plugins=grpc:. --go_opt=paths=source_relative protocol/protocol.proto
//go:generate protoc --go_out=./ --go_opt=paths=source_relative poker.proto //go:generate protoc --go_out=./ --go_opt=paths=source_relative *.proto
//go:generate pbjs -t static-module -w es6 -o proto.js *.proto //go:generate pbjs -t static-module -w es6 -o proto.js *.proto

19
api/operation.go

@ -13,16 +13,23 @@ const OpOffset int32 = 13578
// 注册消息类型 // 注册消息类型
var protoInstances = []proto.Message{ var protoInstances = []proto.Message{
&ProtoWrap{}, &ProtoWrap{},
&ResFail{},
&Ping{}, &Ping{},
&Pong{}, &Pong{},
&ReqIdentity{}, &ReqIdentity{},
&ResIdentity{}, &ResIdentity{},
&ReqLobbyView{},
&ResLobbyView{},
&ReqCreateTable{},
&ReqJoinTable{},
&ResJoinTable{},
} }
var ( var (
prototypeOpMap = make(map[reflect.Type]int32) prototypeOpMap = make(map[reflect.Type]int32)
opPrototypeMap = make(map[int32]reflect.Type) // TODO array opPrototypeMap = make(map[int32]reflect.Type) // TODO array
opProtoNameMap = make(map[int32][2]string) opProtoNameMap = make(map[int32][2]string)
protoNameOpMap = make(map[string]int32)
// opInstanceMap = make(map[int]any) // opInstanceMap = make(map[int]any)
) )
@ -41,6 +48,7 @@ func init() {
} }
name := t.Elem().Name() name := t.Elem().Name()
opProtoNameMap[op+OpOffset] = [2]string{pkg, name} opProtoNameMap[op+OpOffset] = [2]string{pkg, name}
protoNameOpMap[pkg+"."+name] = op + OpOffset
} }
} }
@ -63,6 +71,13 @@ func NewProtoInstance(op int32) (proto.Message, error) {
} }
// GetOpNameMap 获取编号和消息 // GetOpNameMap 获取编号和消息
func GetOpNameMap() map[int32][2]string { func GetOpNameMap() map[string]any {
return opProtoNameMap failOp, _ := GetProtoOp(&ResFail{})
front := make(map[string]any, 4)
front["offset"] = OpOffset
front["failOp"] = failOp
front["opPathMap"] = opProtoNameMap
front["nameOpMap"] = protoNameOpMap
return front
} }

443
api/poker.pb.go

@ -27,10 +27,11 @@ type ProtoWrap struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Ver int32 `protobuf:"varint,1,opt,name=ver,proto3" json:"ver,omitempty"` // version Ver int32 `protobuf:"varint,1,opt,name=ver,proto3" json:"ver,omitempty"` // version
Op int32 `protobuf:"varint,2,opt,name=op,proto3" json:"op,omitempty"` // option/action Op int32 `protobuf:"varint,2,opt,name=op,proto3" json:"op,omitempty"` // option/action
Seq int32 `protobuf:"varint,3,opt,name=seq,proto3" json:"seq,omitempty"` // sequence Seq int32 `protobuf:"varint,3,opt,name=seq,proto3" json:"seq,omitempty"` // sequence
Body []byte `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"` // proto bytes Success bool `protobuf:"varint,4,opt,name=success,proto3" json:"success,omitempty"` // 请求是否成功
Body []byte `protobuf:"bytes,7,opt,name=body,proto3" json:"body,omitempty"` // proto bytes
} }
func (x *ProtoWrap) Reset() { func (x *ProtoWrap) Reset() {
@ -86,6 +87,13 @@ func (x *ProtoWrap) GetSeq() int32 {
return 0 return 0
} }
func (x *ProtoWrap) GetSuccess() bool {
if x != nil {
return x.Success
}
return false
}
func (x *ProtoWrap) GetBody() []byte { func (x *ProtoWrap) GetBody() []byte {
if x != nil { if x != nil {
return x.Body return x.Body
@ -169,6 +177,54 @@ func (*Pong) Descriptor() ([]byte, []int) {
return file_poker_proto_rawDescGZIP(), []int{2} return file_poker_proto_rawDescGZIP(), []int{2}
} }
// 失败响应
type ResFail struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Msg string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"` // 失败消息
}
func (x *ResFail) Reset() {
*x = ResFail{}
if protoimpl.UnsafeEnabled {
mi := &file_poker_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ResFail) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ResFail) ProtoMessage() {}
func (x *ResFail) ProtoReflect() protoreflect.Message {
mi := &file_poker_proto_msgTypes[3]
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 ResFail.ProtoReflect.Descriptor instead.
func (*ResFail) Descriptor() ([]byte, []int) {
return file_poker_proto_rawDescGZIP(), []int{3}
}
func (x *ResFail) GetMsg() string {
if x != nil {
return x.Msg
}
return ""
}
type ReqIdentity struct { type ReqIdentity struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -180,7 +236,7 @@ type ReqIdentity struct {
func (x *ReqIdentity) Reset() { func (x *ReqIdentity) Reset() {
*x = ReqIdentity{} *x = ReqIdentity{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_poker_proto_msgTypes[3] mi := &file_poker_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -193,7 +249,7 @@ func (x *ReqIdentity) String() string {
func (*ReqIdentity) ProtoMessage() {} func (*ReqIdentity) ProtoMessage() {}
func (x *ReqIdentity) ProtoReflect() protoreflect.Message { func (x *ReqIdentity) ProtoReflect() protoreflect.Message {
mi := &file_poker_proto_msgTypes[3] mi := &file_poker_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -206,7 +262,7 @@ func (x *ReqIdentity) ProtoReflect() protoreflect.Message {
// Deprecated: Use ReqIdentity.ProtoReflect.Descriptor instead. // Deprecated: Use ReqIdentity.ProtoReflect.Descriptor instead.
func (*ReqIdentity) Descriptor() ([]byte, []int) { func (*ReqIdentity) Descriptor() ([]byte, []int) {
return file_poker_proto_rawDescGZIP(), []int{3} return file_poker_proto_rawDescGZIP(), []int{4}
} }
func (x *ReqIdentity) GetToken() string { func (x *ReqIdentity) GetToken() string {
@ -228,7 +284,7 @@ type ResIdentity struct {
func (x *ResIdentity) Reset() { func (x *ResIdentity) Reset() {
*x = ResIdentity{} *x = ResIdentity{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_poker_proto_msgTypes[4] mi := &file_poker_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -241,7 +297,7 @@ func (x *ResIdentity) String() string {
func (*ResIdentity) ProtoMessage() {} func (*ResIdentity) ProtoMessage() {}
func (x *ResIdentity) ProtoReflect() protoreflect.Message { func (x *ResIdentity) ProtoReflect() protoreflect.Message {
mi := &file_poker_proto_msgTypes[4] mi := &file_poker_proto_msgTypes[5]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -254,7 +310,7 @@ func (x *ResIdentity) ProtoReflect() protoreflect.Message {
// Deprecated: Use ResIdentity.ProtoReflect.Descriptor instead. // Deprecated: Use ResIdentity.ProtoReflect.Descriptor instead.
func (*ResIdentity) Descriptor() ([]byte, []int) { func (*ResIdentity) Descriptor() ([]byte, []int) {
return file_poker_proto_rawDescGZIP(), []int{4} return file_poker_proto_rawDescGZIP(), []int{5}
} }
func (x *ResIdentity) GetStatus() int32 { func (x *ResIdentity) GetStatus() int32 {
@ -271,24 +327,262 @@ func (x *ResIdentity) GetMsg() string {
return "" return ""
} }
type ReqLobbyView struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *ReqLobbyView) Reset() {
*x = ReqLobbyView{}
if protoimpl.UnsafeEnabled {
mi := &file_poker_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ReqLobbyView) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ReqLobbyView) ProtoMessage() {}
func (x *ReqLobbyView) ProtoReflect() protoreflect.Message {
mi := &file_poker_proto_msgTypes[6]
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 ReqLobbyView.ProtoReflect.Descriptor instead.
func (*ReqLobbyView) Descriptor() ([]byte, []int) {
return file_poker_proto_rawDescGZIP(), []int{6}
}
type ResLobbyView struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *ResLobbyView) Reset() {
*x = ResLobbyView{}
if protoimpl.UnsafeEnabled {
mi := &file_poker_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ResLobbyView) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ResLobbyView) ProtoMessage() {}
func (x *ResLobbyView) ProtoReflect() protoreflect.Message {
mi := &file_poker_proto_msgTypes[7]
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 ResLobbyView.ProtoReflect.Descriptor instead.
func (*ResLobbyView) Descriptor() ([]byte, []int) {
return file_poker_proto_rawDescGZIP(), []int{7}
}
type ReqCreateTable struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *ReqCreateTable) Reset() {
*x = ReqCreateTable{}
if protoimpl.UnsafeEnabled {
mi := &file_poker_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ReqCreateTable) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ReqCreateTable) ProtoMessage() {}
func (x *ReqCreateTable) ProtoReflect() protoreflect.Message {
mi := &file_poker_proto_msgTypes[8]
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 ReqCreateTable.ProtoReflect.Descriptor instead.
func (*ReqCreateTable) Descriptor() ([]byte, []int) {
return file_poker_proto_rawDescGZIP(), []int{8}
}
type ResCreateTable struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *ResCreateTable) Reset() {
*x = ResCreateTable{}
if protoimpl.UnsafeEnabled {
mi := &file_poker_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ResCreateTable) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ResCreateTable) ProtoMessage() {}
func (x *ResCreateTable) 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 ResCreateTable.ProtoReflect.Descriptor instead.
func (*ResCreateTable) Descriptor() ([]byte, []int) {
return file_poker_proto_rawDescGZIP(), []int{9}
}
type ReqJoinTable struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *ReqJoinTable) Reset() {
*x = ReqJoinTable{}
if protoimpl.UnsafeEnabled {
mi := &file_poker_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ReqJoinTable) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ReqJoinTable) ProtoMessage() {}
func (x *ReqJoinTable) 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 ReqJoinTable.ProtoReflect.Descriptor instead.
func (*ReqJoinTable) Descriptor() ([]byte, []int) {
return file_poker_proto_rawDescGZIP(), []int{10}
}
type ResJoinTable struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *ResJoinTable) Reset() {
*x = ResJoinTable{}
if protoimpl.UnsafeEnabled {
mi := &file_poker_proto_msgTypes[11]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ResJoinTable) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ResJoinTable) ProtoMessage() {}
func (x *ResJoinTable) ProtoReflect() protoreflect.Message {
mi := &file_poker_proto_msgTypes[11]
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 ResJoinTable.ProtoReflect.Descriptor instead.
func (*ResJoinTable) Descriptor() ([]byte, []int) {
return file_poker_proto_rawDescGZIP(), []int{11}
}
var File_poker_proto protoreflect.FileDescriptor var File_poker_proto protoreflect.FileDescriptor
var file_poker_proto_rawDesc = []byte{ var file_poker_proto_rawDesc = []byte{
0x0a, 0x0b, 0x70, 0x6f, 0x6b, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x61, 0x0a, 0x0b, 0x70, 0x6f, 0x6b, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x61,
0x70, 0x69, 0x22, 0x53, 0x0a, 0x09, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x57, 0x72, 0x61, 0x70, 0x12, 0x70, 0x69, 0x22, 0x6d, 0x0a, 0x09, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x57, 0x72, 0x61, 0x70, 0x12,
0x10, 0x0a, 0x03, 0x76, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x65, 0x10, 0x0a, 0x03, 0x76, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x65,
0x72, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x6f, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x6f,
0x70, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x65, 0x71, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x65, 0x71, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03,
0x73, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x73, 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x04,
0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x22, 0x06, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x22, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x12, 0x12, 0x0a,
0x06, 0x0a, 0x04, 0x50, 0x6f, 0x6e, 0x67, 0x22, 0x23, 0x0a, 0x0b, 0x52, 0x65, 0x71, 0x49, 0x64, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64,
0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x79, 0x22, 0x06, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x22, 0x06, 0x0a, 0x04, 0x50, 0x6f, 0x6e,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x37, 0x0a, 0x0b, 0x67, 0x22, 0x1b, 0x0a, 0x07, 0x52, 0x65, 0x73, 0x46, 0x61, 0x69, 0x6c, 0x12, 0x10, 0x0a, 0x03,
0x52, 0x65, 0x73, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x6d, 0x73, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x23,
0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x74, 0x61, 0x0a, 0x0b, 0x52, 0x65, 0x71, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x14, 0x0a,
0x74, 0x75, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f,
0x52, 0x03, 0x6d, 0x73, 0x67, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x61, 0x70, 0x69, 0x3b, 0x61, 0x6b, 0x65, 0x6e, 0x22, 0x37, 0x0a, 0x0b, 0x52, 0x65, 0x73, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69,
0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x74, 0x79, 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, 0x10, 0x0a, 0x0e,
0x52, 0x65, 0x71, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x10,
0x0a, 0x0e, 0x52, 0x65, 0x73, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65,
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 ( var (
@ -303,13 +597,20 @@ func file_poker_proto_rawDescGZIP() []byte {
return file_poker_proto_rawDescData return file_poker_proto_rawDescData
} }
var file_poker_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_poker_proto_msgTypes = make([]protoimpl.MessageInfo, 12)
var file_poker_proto_goTypes = []interface{}{ var file_poker_proto_goTypes = []interface{}{
(*ProtoWrap)(nil), // 0: api.ProtoWrap (*ProtoWrap)(nil), // 0: api.ProtoWrap
(*Ping)(nil), // 1: api.Ping (*Ping)(nil), // 1: api.Ping
(*Pong)(nil), // 2: api.Pong (*Pong)(nil), // 2: api.Pong
(*ReqIdentity)(nil), // 3: api.ReqIdentity (*ResFail)(nil), // 3: api.ResFail
(*ResIdentity)(nil), // 4: api.ResIdentity (*ReqIdentity)(nil), // 4: api.ReqIdentity
(*ResIdentity)(nil), // 5: api.ResIdentity
(*ReqLobbyView)(nil), // 6: api.ReqLobbyView
(*ResLobbyView)(nil), // 7: api.ResLobbyView
(*ReqCreateTable)(nil), // 8: api.ReqCreateTable
(*ResCreateTable)(nil), // 9: api.ResCreateTable
(*ReqJoinTable)(nil), // 10: api.ReqJoinTable
(*ResJoinTable)(nil), // 11: api.ResJoinTable
} }
var file_poker_proto_depIdxs = []int32{ 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 output_type
@ -362,7 +663,7 @@ func file_poker_proto_init() {
} }
} }
file_poker_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { file_poker_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ReqIdentity); i { switch v := v.(*ResFail); i {
case 0: case 0:
return &v.state return &v.state
case 1: case 1:
@ -374,6 +675,18 @@ func file_poker_proto_init() {
} }
} }
file_poker_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { file_poker_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ReqIdentity); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_poker_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ResIdentity); i { switch v := v.(*ResIdentity); i {
case 0: case 0:
return &v.state return &v.state
@ -385,6 +698,78 @@ func file_poker_proto_init() {
return nil return nil
} }
} }
file_poker_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ReqLobbyView); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_poker_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ResLobbyView); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_poker_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ReqCreateTable); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_poker_proto_msgTypes[9].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[10].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[11].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ResJoinTable); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
} }
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
@ -392,7 +777,7 @@ func file_poker_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_poker_proto_rawDesc, RawDescriptor: file_poker_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 5, NumMessages: 12,
NumExtensions: 0, NumExtensions: 0,
NumServices: 0, NumServices: 0,
}, },

32
api/poker.proto

@ -12,7 +12,8 @@ message ProtoWrap {
int32 ver = 1; // version int32 ver = 1; // version
int32 op = 2; // option/action int32 op = 2; // option/action
int32 seq = 3; // sequence int32 seq = 3; // sequence
bytes body = 4; // proto bytes bool success = 4; //
bytes body = 7; // proto bytes
} }
message Ping { message Ping {
@ -23,6 +24,11 @@ message Pong {
} }
//
message ResFail {
string msg = 3; //
}
message ReqIdentity { message ReqIdentity {
string token = 1; string token = 1;
} }
@ -31,3 +37,27 @@ message ResIdentity {
int32 status = 1; int32 status = 1;
string msg = 2; string msg = 2;
} }
message ReqLobbyView {
}
message ResLobbyView {
}
message ReqCreateTable {
}
message ResCreateTable {
}
message ReqJoinTable {
}
message ResJoinTable {
}

1495
api/proto.js

File diff suppressed because it is too large Load Diff

1
cmd/main.go

@ -15,5 +15,4 @@ func startServer() {
func main() { func main() {
startServer() startServer()
} }

2
internal/server/server.go

@ -19,7 +19,7 @@ func NewServer() *gin.Engine {
conn := base.Group("/conn") conn := base.Group("/conn")
// 消息映射关系 TODO 生成 json 放在前端 // 消息映射关系 TODO 生成 json 放在前端
conn.GET("/opMap", func(ctx *gin.Context) { conn.GET("/opMap", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{"data": gin.H{"offset": api.OpOffset, "opMap": api.GetOpNameMap()}}) ctx.JSON(http.StatusOK, gin.H{"data": api.GetOpNameMap()})
}) })
// websocket // websocket
conn.GET("/ws", Upgrade) conn.GET("/ws", Upgrade)

20
internal/server/ws.go

@ -106,20 +106,20 @@ func handleNetClient(client *session.NetClient) {
} }
} }
} }
// TODO 处理请求对应消息响应 // 处理请求对应消息响应
fmt.Println(called, res, resErr) // fmt.Println(called, res, resErr)
// 写响应 if resErr != nil {
// 错误消息
client.WriteSeq(false, wrap.Seq, &api.ResFail{Msg: resErr.Error()})
return
}
if res != nil { if res != nil {
client.WriteSeq(wrap.Seq, res) // 响应消息
client.WriteSeq(true, wrap.Seq, res)
return
} }
// log not found handler wrap.Op // log not found handler wrap.Op
fmt.Printf("not found handler for op %d, msg: %v", wrap.Op, msg) fmt.Printf("not found handler for op %d, msg: %v", wrap.Op, msg)
} }
} }
// handleIdentity TODO 通过 token 认证连接的身份
//func handleIdentity(identity *message2.ReqIdentity, client *session.NetClient) {
//
//}

4
internal/server/wsroute.go

@ -16,8 +16,8 @@ func init() {
HandleNetClientMsg(&api.ReqIdentity{}, func(client *session.NetClient, msg *api.ReqIdentity) (proto.Message, error) { HandleNetClientMsg(&api.ReqIdentity{}, func(client *session.NetClient, msg *api.ReqIdentity) (proto.Message, error) {
subject, err := service.DecodeSubject(msg.Token) subject, err := service.DecodeSubject(msg.Token)
if err != nil { if err != nil {
client.Close("authorize failed!") // client.Close("authorize failed!")
return nil, nil return nil, err
} }
account := &session.NetAccount{Id: subject.Id, UserName: subject.Name, Client: client} account := &session.NetAccount{Id: subject.Id, UserName: subject.Name, Client: client}
client.Account = account client.Account = account

6
internal/session/net_client.go

@ -22,16 +22,16 @@ func (c *NetClient) Close(reason string) {
} }
func (c *NetClient) Write(msg proto.Message) { func (c *NetClient) Write(msg proto.Message) {
c.WriteSeq(0, msg) c.WriteSeq(true, 0, msg)
} }
func (c *NetClient) WriteSeq(seq int32, msg proto.Message) { func (c *NetClient) WriteSeq(success bool, seq int32, msg proto.Message) {
op, err := api.GetProtoOp(msg) op, err := api.GetProtoOp(msg)
if err != nil { if err != nil {
return return
} }
bytes, err := proto.Marshal(msg) bytes, err := proto.Marshal(msg)
wrap := &api.ProtoWrap{Ver: 1, Op: op, Seq: seq, Body: bytes} wrap := &api.ProtoWrap{Ver: 1, Op: op, Seq: seq, Success: success, Body: bytes}
wrapBytes, err := proto.Marshal(wrap) wrapBytes, err := proto.Marshal(wrap)
err = c.Conn.WriteMessage(websocket.BinaryMessage, wrapBytes) err = c.Conn.WriteMessage(websocket.BinaryMessage, wrapBytes)
} }

Loading…
Cancel
Save