feat: 修改协议(mq、push),修复问题(礼物乱窜),添加用户rpc

main
NorthLan 3 years ago
parent 491699a20f
commit aa7454bba6

@ -0,0 +1,3 @@
package pb
//go:generate goctl rpc protoc user_center.proto --style=go_zero --go_out=../ --go-grpc_out=../ --zrpc_out=../

@ -0,0 +1,344 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.0
// protoc v3.19.4
// source: user_center.proto
package pb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// model
type User struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
// platform
Platform string `protobuf:"bytes,3,opt,name=platform,proto3" json:"platform,omitempty"`
PUid string `protobuf:"bytes,4,opt,name=pUid,proto3" json:"pUid,omitempty"`
PUname string `protobuf:"bytes,5,opt,name=pUname,proto3" json:"pUname,omitempty"`
PAvatar string `protobuf:"bytes,6,opt,name=pAvatar,proto3" json:"pAvatar,omitempty"`
PInfo string `protobuf:"bytes,7,opt,name=pInfo,proto3" json:"pInfo,omitempty"`
}
func (x *User) Reset() {
*x = User{}
if protoimpl.UnsafeEnabled {
mi := &file_user_center_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *User) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*User) ProtoMessage() {}
func (x *User) ProtoReflect() protoreflect.Message {
mi := &file_user_center_proto_msgTypes[0]
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 User.ProtoReflect.Descriptor instead.
func (*User) Descriptor() ([]byte, []int) {
return file_user_center_proto_rawDescGZIP(), []int{0}
}
func (x *User) GetId() int64 {
if x != nil {
return x.Id
}
return 0
}
func (x *User) GetUsername() string {
if x != nil {
return x.Username
}
return ""
}
func (x *User) GetPlatform() string {
if x != nil {
return x.Platform
}
return ""
}
func (x *User) GetPUid() string {
if x != nil {
return x.PUid
}
return ""
}
func (x *User) GetPUname() string {
if x != nil {
return x.PUname
}
return ""
}
func (x *User) GetPAvatar() string {
if x != nil {
return x.PAvatar
}
return ""
}
func (x *User) GetPInfo() string {
if x != nil {
return x.PInfo
}
return ""
}
// req
type PlatformUserReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Platform string `protobuf:"bytes,1,opt,name=platform,proto3" json:"platform,omitempty"`
PUid string `protobuf:"bytes,2,opt,name=pUid,proto3" json:"pUid,omitempty"`
}
func (x *PlatformUserReq) Reset() {
*x = PlatformUserReq{}
if protoimpl.UnsafeEnabled {
mi := &file_user_center_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PlatformUserReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PlatformUserReq) ProtoMessage() {}
func (x *PlatformUserReq) ProtoReflect() protoreflect.Message {
mi := &file_user_center_proto_msgTypes[1]
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 PlatformUserReq.ProtoReflect.Descriptor instead.
func (*PlatformUserReq) Descriptor() ([]byte, []int) {
return file_user_center_proto_rawDescGZIP(), []int{1}
}
func (x *PlatformUserReq) GetPlatform() string {
if x != nil {
return x.Platform
}
return ""
}
func (x *PlatformUserReq) GetPUid() string {
if x != nil {
return x.PUid
}
return ""
}
type PlatformUserResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"`
}
func (x *PlatformUserResp) Reset() {
*x = PlatformUserResp{}
if protoimpl.UnsafeEnabled {
mi := &file_user_center_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PlatformUserResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PlatformUserResp) ProtoMessage() {}
func (x *PlatformUserResp) ProtoReflect() protoreflect.Message {
mi := &file_user_center_proto_msgTypes[2]
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 PlatformUserResp.ProtoReflect.Descriptor instead.
func (*PlatformUserResp) Descriptor() ([]byte, []int) {
return file_user_center_proto_rawDescGZIP(), []int{2}
}
func (x *PlatformUserResp) GetUser() *User {
if x != nil {
return x.User
}
return nil
}
var File_user_center_proto protoreflect.FileDescriptor
var file_user_center_proto_rawDesc = []byte{
0x0a, 0x11, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x22, 0xaa, 0x01, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72,
0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64,
0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08,
0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x55, 0x69, 0x64,
0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x55, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06,
0x70, 0x55, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x55,
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18,
0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, 0x14,
0x0a, 0x05, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70,
0x49, 0x6e, 0x66, 0x6f, 0x22, 0x41, 0x0a, 0x0f, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d,
0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66,
0x6f, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66,
0x6f, 0x72, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x55, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x70, 0x55, 0x69, 0x64, 0x22, 0x30, 0x0a, 0x10, 0x50, 0x6c, 0x61, 0x74, 0x66,
0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1c, 0x0a, 0x04, 0x75,
0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55,
0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x32, 0x4f, 0x0a, 0x0a, 0x75, 0x73, 0x65,
0x72, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x41, 0x0a, 0x14, 0x72, 0x65, 0x74, 0x72, 0x69,
0x65, 0x76, 0x65, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x12,
0x13, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65,
0x72, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f,
0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f,
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_user_center_proto_rawDescOnce sync.Once
file_user_center_proto_rawDescData = file_user_center_proto_rawDesc
)
func file_user_center_proto_rawDescGZIP() []byte {
file_user_center_proto_rawDescOnce.Do(func() {
file_user_center_proto_rawDescData = protoimpl.X.CompressGZIP(file_user_center_proto_rawDescData)
})
return file_user_center_proto_rawDescData
}
var file_user_center_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_user_center_proto_goTypes = []interface{}{
(*User)(nil), // 0: pb.User
(*PlatformUserReq)(nil), // 1: pb.PlatformUserReq
(*PlatformUserResp)(nil), // 2: pb.PlatformUserResp
}
var file_user_center_proto_depIdxs = []int32{
0, // 0: pb.PlatformUserResp.user:type_name -> pb.User
1, // 1: pb.userCenter.retrievePlatformUser:input_type -> pb.PlatformUserReq
2, // 2: pb.userCenter.retrievePlatformUser:output_type -> pb.PlatformUserResp
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_user_center_proto_init() }
func file_user_center_proto_init() {
if File_user_center_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_user_center_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*User); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_user_center_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PlatformUserReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_user_center_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PlatformUserResp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_user_center_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_user_center_proto_goTypes,
DependencyIndexes: file_user_center_proto_depIdxs,
MessageInfos: file_user_center_proto_msgTypes,
}.Build()
File_user_center_proto = out.File
file_user_center_proto_rawDesc = nil
file_user_center_proto_goTypes = nil
file_user_center_proto_depIdxs = nil
}

@ -0,0 +1,33 @@
syntax = "proto3";
package pb;
option go_package = "./pb";
// model
message User {
int64 id = 1;
string username = 2;
// platform
string platform = 3;
string pUid = 4;
string pUname = 5;
string pAvatar = 6;
string pInfo = 7;
}
// req
message PlatformUserReq {
string platform = 1;
string pUid = 2;
}
message PlatformUserResp {
User user = 1;
}
service userCenter {
// user
rpc retrievePlatformUser(PlatformUserReq) returns (PlatformUserResp);
}

@ -0,0 +1,107 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.19.4
// source: user_center.proto
package pb
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// UserCenterClient is the client API for UserCenter service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type UserCenterClient interface {
// user
RetrievePlatformUser(ctx context.Context, in *PlatformUserReq, opts ...grpc.CallOption) (*PlatformUserResp, error)
}
type userCenterClient struct {
cc grpc.ClientConnInterface
}
func NewUserCenterClient(cc grpc.ClientConnInterface) UserCenterClient {
return &userCenterClient{cc}
}
func (c *userCenterClient) RetrievePlatformUser(ctx context.Context, in *PlatformUserReq, opts ...grpc.CallOption) (*PlatformUserResp, error) {
out := new(PlatformUserResp)
err := c.cc.Invoke(ctx, "/pb.userCenter/retrievePlatformUser", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// UserCenterServer is the server API for UserCenter service.
// All implementations must embed UnimplementedUserCenterServer
// for forward compatibility
type UserCenterServer interface {
// user
RetrievePlatformUser(context.Context, *PlatformUserReq) (*PlatformUserResp, error)
mustEmbedUnimplementedUserCenterServer()
}
// UnimplementedUserCenterServer must be embedded to have forward compatible implementations.
type UnimplementedUserCenterServer struct {
}
func (UnimplementedUserCenterServer) RetrievePlatformUser(context.Context, *PlatformUserReq) (*PlatformUserResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method RetrievePlatformUser not implemented")
}
func (UnimplementedUserCenterServer) mustEmbedUnimplementedUserCenterServer() {}
// UnsafeUserCenterServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to UserCenterServer will
// result in compilation errors.
type UnsafeUserCenterServer interface {
mustEmbedUnimplementedUserCenterServer()
}
func RegisterUserCenterServer(s grpc.ServiceRegistrar, srv UserCenterServer) {
s.RegisterService(&UserCenter_ServiceDesc, srv)
}
func _UserCenter_RetrievePlatformUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(PlatformUserReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserCenterServer).RetrievePlatformUser(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/pb.userCenter/retrievePlatformUser",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserCenterServer).RetrievePlatformUser(ctx, req.(*PlatformUserReq))
}
return interceptor(ctx, in, info, handler)
}
// UserCenter_ServiceDesc is the grpc.ServiceDesc for UserCenter service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var UserCenter_ServiceDesc = grpc.ServiceDesc{
ServiceName: "pb.userCenter",
HandlerType: (*UserCenterServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "retrievePlatformUser",
Handler: _UserCenter_RetrievePlatformUser_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "user_center.proto",
}

@ -0,0 +1,40 @@
// Code generated by goctl. DO NOT EDIT!
// Source: user_center.proto
package usercenter
import (
"context"
"dcg/app/user_center/pb"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
PlatformUserReq = pb.PlatformUserReq
PlatformUserResp = pb.PlatformUserResp
User = pb.User
UserCenter interface {
// user
RetrievePlatformUser(ctx context.Context, in *PlatformUserReq, opts ...grpc.CallOption) (*PlatformUserResp, error)
}
defaultUserCenter struct {
cli zrpc.Client
}
)
func NewUserCenter(cli zrpc.Client) UserCenter {
return &defaultUserCenter{
cli: cli,
}
}
// user
func (m *defaultUserCenter) RetrievePlatformUser(ctx context.Context, in *PlatformUserReq, opts ...grpc.CallOption) (*PlatformUserResp, error) {
client := pb.NewUserCenterClient(m.cli.Conn())
return client.RetrievePlatformUser(ctx, in, opts...)
}

@ -2,7 +2,22 @@ Server:
Debug: false
Listen: 0.0.0.0:8888
Command:
Regex: "([jJ])|([sS])|([wW])|([cC]\\d)|([mM]\\d)|([bB]\\d)"
Keys: [ "j", "加入", "加入游戏", "s", "w", "c1", "c2", "c3", "c4", "r1", "r2", "r3", "m1", "m2", "m3" ]
UserCenterRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
Key: usercenter.rpc
Kafka:
Danmaku:
Addr: [ "127.0.0.1:9093" ]
Topic: "danmaku"
Gift:
Addr: [ "127.0.0.1:9093" ]
Topic: "gift"
ConsumerGroupId:
GiftToPush: "giftToPush"
MsgToPush: "msgToPush"
Log:
Console:
Level: debug
@ -17,14 +32,3 @@ Log:
FileMaxBackups: 30 #
MaxAge: 7 # 保留7天
Compress: true # 压缩日志
Kafka:
Danmaku:
Addr: [ "127.0.0.1:9093" ]
Topic: "danmaku"
Gift:
Addr: [ "127.0.0.1:9093" ]
Topic: "gift"
ConsumerGroupId:
GiftToPush: "giftToPush"
MsgToPush: "msgToPush"
MsgToDb: "msgToDb"

@ -5,6 +5,7 @@ import (
"git.noahlan.cn/northlan/ntools-go/logger"
c "github.com/gookit/config/v2"
"github.com/gookit/config/v2/yaml"
"github.com/zeromicro/go-zero/zrpc"
)
var Config config
@ -35,8 +36,11 @@ type (
MsgToDb string
}
Command struct {
Regex string
Keys []string
}
// RPC
UserCenterRpc zrpc.RpcClientConf
}
)

@ -2,7 +2,6 @@ package command
import (
pushPb "dcg/game/pb/push"
"strings"
)
type HandlerFunc func(roomId int64, cmd string, user *pushPb.User)
@ -17,20 +16,22 @@ func NewManager() *Manager {
}
}
func (m *Manager) Register(cmd string, h HandlerFunc) {
func (m *Manager) Register(h HandlerFunc, cmd string, alias ...string) {
if _, ok := m.handlers[cmd]; ok {
return
}
m.handlers[cmd] = h
// alias
for _, s := range alias {
if _, ok := m.handlers[cmd]; ok {
continue
}
m.handlers[s] = h
}
}
func (m *Manager) Handle(roomId int64, cmd string, user *pushPb.User) {
if len(cmd) < 0 {
return
}
fChar := cmd[0]
c := strings.ToLower(string(fChar))
if h, ok := m.handlers[c]; ok {
if h, ok := m.handlers[cmd]; ok {
h(roomId, cmd, user)
}
}

@ -0,0 +1,70 @@
package danmaku
import (
"git.noahlan.cn/northlan/ntools-go/stringn/ac"
"strings"
)
type (
CMD struct {
IsCMD bool // 是否CMD
Arr []string // 具体CMD []string
}
Parser struct {
trie *ac.Trie
allKeyArr []string
keywordMap map[string]struct{}
}
ParserBuilder struct {
}
)
func NewCMDParser(keys []string) *Parser {
p := &Parser{
keywordMap: make(map[string]struct{}),
allKeyArr: make([]string, len(keys)),
}
for _, keyword := range keys {
p.keywordMap[keyword] = struct{}{}
p.allKeyArr = append(p.allKeyArr, keyword)
}
p.trie = ac.NewTrieBuilder().AddStrings(p.allKeyArr).Build()
return p
}
func (p *Parser) ParseTest(content string) {
p.trie.MatchString(content)
}
func (p *Parser) Parse(content string) *CMD {
// 移除多余空格,小写
tmpContent := strings.ToLower(strings.TrimSpace(content))
matches := p.trie.MatchString(tmpContent)
allKeyLen := 0
matchedKeyMap := make(map[string]struct{})
for _, match := range matches {
tmp := p.allKeyArr[match.Pattern()]
matchedKeyMap[tmp] = struct{}{}
allKeyLen += len(tmp)
}
isCMD := len(tmpContent) <= allKeyLen
// 避免同类型指令重复
arrMap := make(map[rune]struct{})
var matchedCmdArr []string
if isCMD {
matchedCmdArr = make([]string, 0, len(matchedKeyMap))
for s := range matchedKeyMap {
sRune := []rune(s)
if _, ok := arrMap[sRune[0]]; !ok {
arrMap[sRune[0]] = struct{}{}
matchedCmdArr = append(matchedCmdArr, s)
}
}
}
return &CMD{
IsCMD: len(tmpContent) <= allKeyLen,
Arr: matchedCmdArr,
}
}

@ -0,0 +1,46 @@
package danmaku
import (
"fmt"
"testing"
)
func TestParse(t *testing.T) {
contents := []string{
"jc2m2b1s",
"jjjjjjjjjjjj",
"c1c1c1c1c1c1c1c1c1c1",
"c5c6c7c8c9c2c3c4c1c2c3c4c5c6c2c3c4c5c6c1",
"j2jjjjjjjj",
"j",
"加入游戏",
"加入",
"没有什么意义的弹幕",
"92813182798dsjks8923kjhsddfh892h3jkl214",
"昵称为什么可以这么长",
"六十九的覅哦我就法拉盛就发链接我i苏联空军弗拉放假 ",
"一堆乱七八糟的弹幕来袭",
"不服你咬我啊?",
"红方前排速度m2b2",
"c1c2c3c4c1c2c3c4",
}
p := NewCMDParser([]string{"j", "c1", "c2", "c3", "c4", "b1", "b2", "b3", "s", "b2", "b3", "w", "m1", "m2", "m3", "加入", "加入游戏"})
for _, content := range contents {
cmdStruct := p.Parse(content)
fmt.Printf("弹幕: [%s] 是命令否? [%v]\n", content, cmdStruct.IsCMD)
fmt.Printf("清洗后的真实命令为:%s len:%d\n\n", cmdStruct.Arr, len(cmdStruct.Arr))
}
}
func BenchmarkCmd(b *testing.B) {
p := NewCMDParser([]string{"j", "c1", "c2", "c3", "c4", "b1", "b2", "b3", "s", "b2", "b3", "w", "m1", "m2", "m3", "加入", "加入游戏"})
content := "jc2m2b1s"
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
p.ParseTest(content)
}
}

@ -1,97 +0,0 @@
package danmaku
import (
"dcg/config"
"dcg/game/command"
pbMq "dcg/game/pb/mq"
pbPush "dcg/game/pb/push"
"dcg/game/svc"
kfk "dcg/pkg/kafka"
"git.noahlan.cn/northlan/ntools-go/kafka"
"git.noahlan.cn/northlan/ntools-go/logger"
"github.com/Shopify/sarama"
"github.com/golang/protobuf/proto"
"regexp"
)
type MsgToDbHandler struct {
ctx *svc.ServiceContext
msgHandle map[string]msgHandlerFunc
regex *regexp.Regexp
commandManager *command.Manager
ConsumerGroup *kafka.ConsumerGroup
}
func (h *MsgToDbHandler) Init(ctx *svc.ServiceContext) {
h.ctx = ctx
cfg := config.Config.Kafka.Danmaku
h.msgHandle = make(map[string]msgHandlerFunc)
h.msgHandle["danmaku"] = h.handleDanmaku
h.commandManager = command.NewManager()
h.commandManager.Register("j", h.handleAllCmd)
h.commandManager.Register("c", h.handleAllCmd)
h.commandManager.Register("s", h.handleAllCmd)
h.commandManager.Register("m", h.handleAllCmd)
h.commandManager.Register("w", h.handleAllCmd)
var err error
h.regex, err = regexp.Compile(config.Config.Command.Regex)
if err != nil {
logger.SLog.Error(err)
}
h.ConsumerGroup, err = kafka.NewConsumerGroup(&kafka.ConsumerGroupConfig{
KafkaVersion: sarama.V3_1_0_0,
OffsetsInitial: sarama.OffsetNewest,
IsReturnErr: false,
UnMarshaler: kfk.ProtobufMarshaler,
}, cfg.Addr, []string{cfg.Topic}, config.Config.ConsumerGroupId.MsgToDb)
if err != nil {
logger.SLog.Error(err)
}
}
func (h *MsgToDbHandler) handleAllCmd(_ int64, _ string, user *pbPush.User) {
}
func (h *MsgToDbHandler) handleDanmaku(data []byte, msgKey string) {
// danmaku msg proto
var msgFromMq pbMq.MqDanmaku
err := proto.Unmarshal(data, &msgFromMq)
if err != nil {
logger.SLog.Error("unmarshal msg err", err)
return
}
cmdArr := h.parseCommands(msgFromMq.Content)
for _, cmd := range cmdArr {
h.commandManager.Handle(msgFromMq.LiveRoomId, cmd, &pbPush.User{
UId: msgFromMq.Uid,
Uname: msgFromMq.Uname,
})
}
}
func (h *MsgToDbHandler) parseCommands(msg string) []string {
if h.regex == nil {
logger.SLog.Error("regex is null")
return []string{}
}
return h.regex.FindAllString(msg, -1)
}
func (MsgToDbHandler) Setup(_ sarama.ConsumerGroupSession) error { return nil }
func (MsgToDbHandler) Cleanup(_ sarama.ConsumerGroupSession) error { return nil }
func (h *MsgToDbHandler) ConsumeClaim(sess sarama.ConsumerGroupSession,
claim sarama.ConsumerGroupClaim) error {
for msg := range claim.Messages() {
if hFunc, ok := h.msgHandle[msg.Topic]; ok {
hFunc(msg.Value, string(msg.Key))
}
sess.MarkMessage(msg, "")
}
return nil
}

@ -1,6 +1,8 @@
package danmaku
import (
"context"
"dcg/app/user_center/pb"
"dcg/config"
"dcg/game/command"
pbMq "dcg/game/pb/mq"
@ -11,38 +13,37 @@ import (
"git.noahlan.cn/northlan/ntools-go/logger"
"github.com/Shopify/sarama"
"github.com/golang/protobuf/proto"
"regexp"
"strconv"
)
type MsgToPushHandler struct {
ctx *svc.ServiceContext
msgHandle map[string]msgHandlerFunc
regex *regexp.Regexp
svc *svc.ServiceContext
msgHandle map[string]msgHandlerFunc
cmdParser *Parser
commandManager *command.Manager
ConsumerGroup *kafka.ConsumerGroup
ConsumerGroup *kafka.ConsumerGroup
}
func (h *MsgToPushHandler) Init(ctx *svc.ServiceContext) {
h.ctx = ctx
func (h *MsgToPushHandler) Init(svc *svc.ServiceContext) {
h.svc = svc
cfg := config.Config.Kafka.Danmaku
h.msgHandle = make(map[string]msgHandlerFunc)
h.msgHandle["danmaku"] = h.handleDanmaku
h.cmdParser = NewCMDParser(config.Config.Command.Keys)
//
h.commandManager = command.NewManager()
h.commandManager.Register("j", h.handleJoinGame)
h.commandManager.Register("c", h.handleCreateUnit)
h.commandManager.Register("s", h.handleOutbreak)
h.commandManager.Register("m", h.handleMove)
h.commandManager.Register("w", h.handleWai)
h.commandManager.Register("b", h.handleMode)
h.commandManager.Register(h.handleJoinGame, "j", "加入", "加入游戏")
h.commandManager.Register(h.handleOutbreak, "s")
h.commandManager.Register(h.handleWai, "w")
h.commandManager.Register(h.handleCreateUnit, "c1", "c2", "c3", "c4")
h.commandManager.Register(h.handleMove, "m1", "m2", "m3")
h.commandManager.Register(h.handleMode, "r1", "r2", "r3")
var err error
h.regex, err = regexp.Compile(config.Config.Command.Regex)
if err != nil {
logger.SLog.Error(err)
}
h.ConsumerGroup, err = kafka.NewConsumerGroup(&kafka.ConsumerGroupConfig{
KafkaVersion: sarama.V3_1_0_0,
OffsetsInitial: sarama.OffsetNewest,
@ -56,11 +57,11 @@ func (h *MsgToPushHandler) Init(ctx *svc.ServiceContext) {
}
func (h *MsgToPushHandler) handleJoinGame(roomId int64, _ string, user *pushPb.User) {
h.ctx.RoomManager.PushToRoom(roomId, "game.join", &pushPb.JoinGame{User: user})
h.svc.RoomManager.PushToRoom(roomId, "game.join", &pushPb.JoinGame{User: user})
}
func (h *MsgToPushHandler) handleOutbreak(roomId int64, _ string, user *pushPb.User) {
h.ctx.RoomManager.PushToRoom(roomId, "game.outbreak", &pushPb.Outbreak{User: user})
h.svc.RoomManager.PushToRoom(roomId, "game.outbreak", &pushPb.Outbreak{User: user})
}
func (h *MsgToPushHandler) handleCreateUnit(roomId int64, cmd string, user *pushPb.User) {
@ -68,7 +69,7 @@ func (h *MsgToPushHandler) handleCreateUnit(roomId int64, cmd string, user *push
return
}
unit := cmd[1]
h.ctx.RoomManager.PushToRoom(roomId, "game.createUnit", &pushPb.CreateUnit{
h.svc.RoomManager.PushToRoom(roomId, "game.createUnit", &pushPb.CreateUnit{
User: user,
Unit: string(unit),
})
@ -79,14 +80,14 @@ func (h *MsgToPushHandler) handleMove(roomId int64, cmd string, user *pushPb.Use
return
}
line := cmd[1]
h.ctx.RoomManager.PushToRoom(roomId, "game.move", &pushPb.Move{
h.svc.RoomManager.PushToRoom(roomId, "game.move", &pushPb.Move{
User: user,
Line: string(line),
})
}
func (h *MsgToPushHandler) handleWai(roomId int64, _ string, user *pushPb.User) {
h.ctx.RoomManager.PushToRoom(roomId, "game.wai", &pushPb.Wai{User: user})
h.svc.RoomManager.PushToRoom(roomId, "game.wai", &pushPb.Wai{User: user})
}
func (h *MsgToPushHandler) handleMode(roomId int64, cmd string, user *pushPb.User) {
@ -94,7 +95,7 @@ func (h *MsgToPushHandler) handleMode(roomId int64, cmd string, user *pushPb.Use
return
}
line := cmd[1]
h.ctx.RoomManager.PushToRoom(roomId, "game.mode", &pushPb.BuildingMode{
h.svc.RoomManager.PushToRoom(roomId, "game.mode", &pushPb.BuildingMode{
User: user,
Mode: string(line),
})
@ -103,36 +104,40 @@ func (h *MsgToPushHandler) handleMode(roomId int64, cmd string, user *pushPb.Use
func (h *MsgToPushHandler) handleDanmaku(data []byte, msgKey string) {
// danmaku msg proto
var msgFromMq pbMq.MqDanmaku
err := proto.Unmarshal(data, &msgFromMq)
if err != nil {
if err := proto.Unmarshal(data, &msgFromMq); err != nil {
logger.SLog.Error("unmarshal msg err", err)
return
}
// rpc创建或获取用户数据
pbUser := &pushPb.User{
UId: msgFromMq.Uid,
Uname: msgFromMq.Uname,
}
cmdArr := h.parseCommands(msgFromMq.Content)
for _, cmd := range cmdArr {
h.commandManager.Handle(msgFromMq.LiveRoomId, cmd, pbUser)
rpcUser, err := h.svc.UserCenterRpc.RetrievePlatformUser(context.Background(), &pb.PlatformUserReq{
Platform: msgFromMq.Platform,
PUid: strconv.FormatInt(msgFromMq.Uid, 10),
})
if err == nil {
pbUser.Avatar = rpcUser.User.PAvatar
} else {
logger.SLog.Error("rpc获取用户信息失败", err)
}
// 发送正常非命令弹幕消息
if len(cmdArr) <= 0 {
h.ctx.RoomManager.PushToRoom(msgFromMq.LiveRoomId, "live.danmaku", &pushPb.DanmakuMsg{
cmdStruct := h.cmdParser.Parse(msgFromMq.Content)
if cmdStruct.IsCMD {
for _, cmd := range cmdStruct.Arr {
h.commandManager.Handle(msgFromMq.LiveRoomId, cmd, pbUser)
}
} else {
// 发送正常的非命令弹幕消息
h.svc.RoomManager.PushToRoom(msgFromMq.LiveRoomId, "live.danmaku", &pushPb.DanmakuMsg{
User: pbUser,
Content: msgFromMq.Content,
})
}
}
func (h *MsgToPushHandler) parseCommands(msg string) []string {
if h.regex == nil {
logger.SLog.Error("regex is null")
return []string{}
}
return h.regex.FindAllString(msg, -1)
}
func (MsgToPushHandler) Setup(_ sarama.ConsumerGroupSession) error { return nil }
func (MsgToPushHandler) Cleanup(_ sarama.ConsumerGroupSession) error { return nil }
func (h *MsgToPushHandler) ConsumeClaim(sess sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error {

@ -46,7 +46,7 @@ func (h *MsgToPushHandler) handleGift(data []byte, msgKey string) {
logger.SLog.Error("unmarshal msg err", err)
return
}
h.ctx.RoomManager.Broadcast("game.gift", &pushPb.Gift{
h.ctx.RoomManager.PushToRoom(msgFromMq.LiveRoomId, "game.gift", &pushPb.Gift{
User: &pushPb.User{
UId: msgFromMq.Uid,
Uname: msgFromMq.Uname,

@ -11,9 +11,9 @@ var (
giftMsgToPush gift.MsgToPushHandler
)
func Init(ctx *svc.ServiceContext) {
danmakuMsgToPush.Init(ctx)
giftMsgToPush.Init(ctx)
func Init(svc *svc.ServiceContext) {
danmakuMsgToPush.Init(svc)
giftMsgToPush.Init(svc)
}
func Run() {

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc-gen-go v1.28.0
// protoc v3.19.4
// source: broadcast.proto
@ -25,8 +25,9 @@ type User struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
UId int64 `protobuf:"varint,1,opt,name=uId,proto3" json:"uId,omitempty"` //用户id
Uname string `protobuf:"bytes,2,opt,name=uname,proto3" json:"uname,omitempty"` //用户名
UId int64 `protobuf:"varint,1,opt,name=uId,proto3" json:"uId,omitempty"` // 用户id
Uname string `protobuf:"bytes,2,opt,name=uname,proto3" json:"uname,omitempty"` // 用户名
Avatar string `protobuf:"bytes,3,opt,name=avatar,proto3" json:"avatar,omitempty"` // 头像
}
func (x *User) Reset() {
@ -75,6 +76,13 @@ func (x *User) GetUname() string {
return ""
}
func (x *User) GetAvatar() string {
if x != nil {
return x.Avatar
}
return ""
}
type JoinGame struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -519,44 +527,45 @@ var File_broadcast_proto protoreflect.FileDescriptor
var file_broadcast_proto_rawDesc = []byte{
0x0a, 0x0f, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x12, 0x02, 0x70, 0x62, 0x22, 0x2e, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x10, 0x0a,
0x6f, 0x12, 0x02, 0x70, 0x62, 0x22, 0x46, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x10, 0x0a,
0x03, 0x75, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x49, 0x64, 0x12,
0x14, 0x0a, 0x05, 0x75, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
0x75, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x28, 0x0a, 0x08, 0x4a, 0x6f, 0x69, 0x6e, 0x47, 0x61, 0x6d,
0x65, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22,
0x3e, 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x6e, 0x69, 0x74, 0x12, 0x1c, 0x0a,
0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62,
0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x75,
0x6e, 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x6e, 0x69, 0x74, 0x22,
0x38, 0x0a, 0x04, 0x4d, 0x6f, 0x76, 0x65, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18,
0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52,
0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x6c, 0x69, 0x6e, 0x65, 0x22, 0x28, 0x0a, 0x08, 0x4f, 0x75, 0x74,
0x62, 0x72, 0x65, 0x61, 0x6b, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20,
0x75, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18,
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x22, 0x28, 0x0a,
0x08, 0x4a, 0x6f, 0x69, 0x6e, 0x47, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73, 0x65,
0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65,
0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x3e, 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74,
0x65, 0x55, 0x6e, 0x69, 0x74, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75,
0x73, 0x65, 0x72, 0x22, 0x92, 0x01, 0x0a, 0x04, 0x47, 0x69, 0x66, 0x74, 0x12, 0x1c, 0x0a, 0x04,
0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e,
0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x69,
0x66, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x67, 0x69, 0x66, 0x74,
0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x03,
0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1c,
0x0a, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x69, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28,
0x03, 0x52, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x69, 0x6e, 0x12, 0x1a, 0x0a, 0x08,
0x73, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08,
0x73, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x22, 0x23, 0x0a, 0x03, 0x57, 0x61, 0x69, 0x12,
0x73, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x6e, 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x75, 0x6e, 0x69, 0x74, 0x22, 0x38, 0x0a, 0x04, 0x4d, 0x6f, 0x76, 0x65, 0x12,
0x1c, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e,
0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x40, 0x0a,
0x0c, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x69, 0x6e, 0x67, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x1c, 0x0a,
0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62,
0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6d,
0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6d, 0x6f, 0x64, 0x65, 0x22,
0x44, 0x0a, 0x0a, 0x44, 0x61, 0x6e, 0x6d, 0x61, 0x6b, 0x75, 0x4d, 0x73, 0x67, 0x12, 0x1c, 0x0a,
0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x12, 0x0a,
0x04, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6c, 0x69, 0x6e,
0x65, 0x22, 0x28, 0x0a, 0x08, 0x4f, 0x75, 0x74, 0x62, 0x72, 0x65, 0x61, 0x6b, 0x12, 0x1c, 0x0a,
0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62,
0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x63,
0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f,
0x6e, 0x74, 0x65, 0x6e, 0x74, 0x42, 0x09, 0x5a, 0x07, 0x2f, 0x70, 0x62, 0x50, 0x75, 0x73, 0x68,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x92, 0x01, 0x0a, 0x04,
0x47, 0x69, 0x66, 0x74, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73,
0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x69, 0x66, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01,
0x28, 0x05, 0x52, 0x06, 0x67, 0x69, 0x66, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x67, 0x69,
0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x67, 0x69,
0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43,
0x6f, 0x69, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c,
0x43, 0x6f, 0x69, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65,
0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65,
0x22, 0x23, 0x0a, 0x03, 0x57, 0x61, 0x69, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18,
0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52,
0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x40, 0x0a, 0x0c, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x69, 0x6e,
0x67, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75,
0x73, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x6d, 0x6f, 0x64, 0x65, 0x22, 0x44, 0x0a, 0x0a, 0x44, 0x61, 0x6e, 0x6d, 0x61,
0x6b, 0x75, 0x4d, 0x73, 0x67, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75,
0x73, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x42, 0x09, 0x5a,
0x07, 0x2f, 0x70, 0x62, 0x50, 0x75, 0x73, 0x68, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

@ -5,8 +5,9 @@ package pb;
option go_package = "/pbPush";
message User{
int64 uId = 1;//id
string uname = 2;//
int64 uId = 1; // id
string uname = 2; //
string avatar = 3; //
}
message JoinGame{

@ -1,14 +1,19 @@
package svc
import (
"dcg/app/user_center/usercenter"
"dcg/config"
"dcg/game/room"
"git.noahlan.cn/northlan/ngs/component"
"github.com/zeromicro/go-zero/zrpc"
"strings"
)
type ServiceContext struct {
Services *component.Components
RoomManager *room.Manager
UserCenterRpc usercenter.UserCenter
}
func NewServiceContext() *ServiceContext {
@ -24,5 +29,7 @@ func NewServiceContext() *ServiceContext {
return &ServiceContext{
Services: services,
RoomManager: roomManager,
// rpc
UserCenterRpc: usercenter.NewUserCenter(zrpc.MustNewClient(config.Config.UserCenterRpc)),
}
}

@ -4,49 +4,95 @@ go 1.18
require (
git.noahlan.cn/northlan/ngs v0.1.2
git.noahlan.cn/northlan/ntools-go/kafka v1.0.1
git.noahlan.cn/northlan/ntools-go/logger v1.0.1
github.com/Shopify/sarama v1.32.0
github.com/golang/protobuf v1.5.2
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/urfave/cli v1.22.5
go.uber.org/zap v1.21.0
github.com/gookit/config/v2 v2.1.0
google.golang.org/protobuf v1.28.0
)
require (
git.noahlan.cn/northlan/ntools-go/kafka v1.0.1 // indirect
git.noahlan.cn/northlan/ntools-go/logger v1.0.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
git.noahlan.cn/northlan/ntools-go/stringn v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/eapache/go-resiliency v1.2.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gookit/config/v2 v2.1.0 // indirect
github.com/google/gnostic v0.6.8 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/gookit/goutil v0.5.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.0.0 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/openzipkin/zipkin-go v0.4.0 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.34.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/zeromicro/go-zero v1.3.2 // indirect
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/v3 v3.5.4 // indirect
go.opentelemetry.io/otel v1.6.3 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.6.3 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.6.3 // indirect
go.opentelemetry.io/otel/sdk v1.6.3 // indirect
go.opentelemetry.io/otel/trace v1.6.3 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/automaxprocs v1.5.1 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/net v0.0.0-20220421235706-1d1ef9303861 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20220414192740-2d67ff6cf2b4 // indirect
google.golang.org/grpc v1.45.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220422154200-b37d22cd5731 // indirect
google.golang.org/grpc v1.46.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/api v0.23.6 // indirect
k8s.io/apimachinery v0.23.6 // indirect
k8s.io/client-go v0.23.6 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20220413171646-5e7f5fdc6da6 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

744
go.sum

File diff suppressed because it is too large Load Diff

@ -20,13 +20,13 @@ func main() {
_ = logger.InitLogger(&config.Config.Log.File, &config.Config.Log.Console)
defer logger.Sync()
ctx := svc.NewServiceContext()
svc := svc.NewServiceContext()
msg_transfer.Init(ctx)
msg_transfer.Init(svc)
msg_transfer.Run()
opts := make([]ngs.Option, 0)
opts = append(opts, ngs.WithComponents(ctx.Services))
opts = append(opts, ngs.WithComponents(svc.Services))
opts = append(opts, ngs.WithSerializer(protobuf.NewSerializer()))
if config.Config.Server.Debug {
ngs.WithDebugMode()

Loading…
Cancel
Save