diff --git a/client/client.go b/client/client.go deleted file mode 100644 index 5971c79..0000000 --- a/client/client.go +++ /dev/null @@ -1,48 +0,0 @@ -package client - -import ( - "dcg/game/pb" - "fmt" - "git.noahlan.cn/northlan/ngs/client" - "git.noahlan.cn/northlan/ngs/serialize/protobuf" - "log" -) - -func NewClient(addr string) error { - c := client.NewClient() - - chReady := make(chan struct{}) - c.OnConnected(func() { - chReady <- struct{}{} - }) - - if err := c.Start(addr); err != nil { - return err - } - - serializer := protobuf.NewSerializer() - - c.On("onNewClient", func(data interface{}) { - var newClient pb.Client - serializer.Unmarshal(data.([]byte), &newClient) - log.Printf("服务器通知,由新客户端连接了房间: %+v\n", &newClient) - }) - c.On("onInterval", func(data interface{}) { - var test pb.Test - serializer.Unmarshal(data.([]byte), &test) - log.Printf("服务器->客户端: %+v\n", &test) - }) - - <-chReady - - c.Request("room.join", &pb.JoinRoomReq{LiveRoomId: 123456}, func(data interface{}) { - var resp pb.JoinRoomResp - serializer.Unmarshal(data.([]byte), &resp) - fmt.Printf("服务器->客户端: %+v\n", &resp) - }) - - for { - - } - return nil -} diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..5299bb0 --- /dev/null +++ b/config.yml @@ -0,0 +1,29 @@ +Server: + Debug: false + Listen: 0.0.0.0:8888 +Command: + Regex: "([jJ])|([sS])|([wW])|([cC]\\d)|([mM]\\d)" +Log: + Console: + Level: debug + Format: console + File: + Enabled: false + Level: info + Format: json + Path: ./logs + Filename: dcg.log + FileMaxSize: 10 # 10mb + 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: + MsgToPush: "msgToPush" + MsgToDb: "msgToDb" \ No newline at end of file diff --git a/config/Config.go b/config/Config.go new file mode 100644 index 0000000..6da2677 --- /dev/null +++ b/config/Config.go @@ -0,0 +1,63 @@ +package config + +import ( + "dcg/pkg/logger" + "fmt" + c "github.com/gookit/config/v2" + "github.com/gookit/config/v2/yaml" + "path/filepath" + "runtime" +) + +var ( + _, b, _, _ = runtime.Caller(0) + Root = filepath.Join(filepath.Dir(b), "../") +) + +var Config config + +type ( + Kafka struct { + Addr []string + Topic string + } + + config struct { + // Log 日志配置 + Log struct { + File logger.FileConfig + Console logger.ConsoleConfig + } + Server struct { + Debug bool + Listen string + } + Kafka struct { + Danmaku Kafka + Gift Kafka + } + ConsumerGroupId struct { + MsgToPush string + MsgToDb string + } + Command struct { + Regex string + } + } +) + +func init() { + var err error + c.AddDriver(yaml.Driver) + + err = c.LoadFiles(Root + "/config.yml") + if err != nil { + panic(err) + } + err = c.BindStruct("", &Config) + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", Config) +} diff --git a/game/command/manager.go b/game/command/manager.go new file mode 100644 index 0000000..b77cf34 --- /dev/null +++ b/game/command/manager.go @@ -0,0 +1,36 @@ +package command + +import ( + "dcg/game/pb" + "strings" +) + +type HandlerFunc func(cmd string, user *pb.User) + +type Manager struct { + handlers map[string]HandlerFunc +} + +func NewManager() *Manager { + return &Manager{ + handlers: make(map[string]HandlerFunc), + } +} + +func (m *Manager) Register(cmd string, h HandlerFunc) { + if _, ok := m.handlers[cmd]; ok { + return + } + m.handlers[cmd] = h +} + +func (m *Manager) Handle(cmd string, user *pb.User) { + if len(cmd) < 0 { + return + } + fChar := cmd[0] + c := strings.ToLower(string(fChar)) + if h, ok := m.handlers[c]; ok { + h(cmd, user) + } +} diff --git a/game/init.go b/game/init.go deleted file mode 100644 index 4c1968e..0000000 --- a/game/init.go +++ /dev/null @@ -1,30 +0,0 @@ -package game - -import ( - "dcg/game/room" - "git.noahlan.cn/northlan/ngs" - "git.noahlan.cn/northlan/ngs/component" - "git.noahlan.cn/northlan/ngs/serialize/protobuf" - "strings" -) - -var ( - Services = &component.Components{} - - RoomManager = room.NewRoomManager() -) - -func init() { - Services.Register(RoomManager, - component.WithName("room"), - component.WithNameFunc(func(s string) string { - return strings.ToLower(s) - })) -} - -func Run(listen string) { - ngs.Listen(listen, - ngs.WithComponents(Services), - ngs.WithSerializer(protobuf.NewSerializer()), - ngs.WithDebugMode()) -} diff --git a/game/msg-transfer/danmaku_consumer_handler.go b/game/msg-transfer/danmaku_consumer_handler.go deleted file mode 100644 index 83b0a49..0000000 --- a/game/msg-transfer/danmaku_consumer_handler.go +++ /dev/null @@ -1,51 +0,0 @@ -package msg_transfer - -import ( - "dcg/game/pb" - "dcg/pkg/kafka" - "dcg/pkg/logger" - "github.com/Shopify/sarama" - "github.com/golang/protobuf/proto" -) - -type fcb func(data []byte, msgKey string) - -type DanmakuConsumerHandler struct { - msgHandle map[string]fcb - cg *kafka.ConsumerGroup -} - -func (h *DanmakuConsumerHandler) Init() { - h.msgHandle = make(map[string]fcb) - h.msgHandle["danmaku"] = h.handleDanmaku - h.cg, _ = kafka.NewConsumerGroup(&kafka.ConsumerGroupConfig{ - KafkaVersion: sarama.V3_1_0_0, - OffsetsInitial: sarama.OffsetNewest, - IsReturnErr: false, - }, []string{"danmaku"}, []string{"danmaku"}, "") -} - -func (h *DanmakuConsumerHandler) handleDanmaku(msg []byte, msgKey string) { - logger.SLog.Debug("msg come", string(msg), msgKey) - // danmaku msg proto - var msgFromMq pb.Danmaku - err := proto.Unmarshal(msg, &msgFromMq) - if err != nil { - logger.SLog.Error("unmarshal msg err", err) - return - } - // - -} - -func (DanmakuConsumerHandler) Setup(_ sarama.ConsumerGroupSession) error { return nil } -func (DanmakuConsumerHandler) Cleanup(_ sarama.ConsumerGroupSession) error { return nil } -func (h *DanmakuConsumerHandler) ConsumeClaim(sess sarama.ConsumerGroupSession, - claim sarama.ConsumerGroupClaim) error { - for msg := range claim.Messages() { - logger.SLog.Infow("kafka get info to mysql", "msgTopic", msg.Topic, "msgPartition", msg.Partition, "msg", string(msg.Value)) - h.msgHandle[msg.Topic](msg.Value, string(msg.Key)) - sess.MarkMessage(msg, "") - } - return nil -} diff --git a/game/msg-transfer/init.go b/game/msg-transfer/init.go deleted file mode 100644 index 0b849e4..0000000 --- a/game/msg-transfer/init.go +++ /dev/null @@ -1,9 +0,0 @@ -package msg_transfer - -var ( -//danmakuCH -) - -func Init() { - -} \ No newline at end of file diff --git a/game/msg_transfer/danmaku/msg.go b/game/msg_transfer/danmaku/msg.go new file mode 100644 index 0000000..18b8bf0 --- /dev/null +++ b/game/msg_transfer/danmaku/msg.go @@ -0,0 +1,3 @@ +package danmaku + +type msgHandlerFunc func(data []byte, msgKey string) diff --git a/game/msg_transfer/danmaku/msg_to_db.go b/game/msg_transfer/danmaku/msg_to_db.go new file mode 100644 index 0000000..048ad7c --- /dev/null +++ b/game/msg_transfer/danmaku/msg_to_db.go @@ -0,0 +1,94 @@ +package danmaku + +import ( + "dcg/config" + "dcg/game/command" + "dcg/game/pb" + "dcg/game/svc" + "dcg/pkg/kafka" + "dcg/pkg/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, + }, cfg.Addr, []string{cfg.Topic}, config.Config.ConsumerGroupId.MsgToDb) + + if err != nil { + logger.SLog.Error(err) + } +} + +func (h *MsgToDbHandler) handleAllCmd(_ string, user *pb.User) { + +} + +func (h *MsgToDbHandler) handleDanmaku(data []byte, msgKey string) { + // danmaku msg proto + var msgFromMq pb.Danmaku + 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(cmd, &pb.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 +} diff --git a/game/msg_transfer/danmaku/msg_to_push.go b/game/msg_transfer/danmaku/msg_to_push.go new file mode 100644 index 0000000..621db0c --- /dev/null +++ b/game/msg_transfer/danmaku/msg_to_push.go @@ -0,0 +1,125 @@ +package danmaku + +import ( + "dcg/config" + "dcg/game/command" + "dcg/game/pb" + "dcg/game/svc" + "dcg/pkg/kafka" + "dcg/pkg/logger" + "github.com/Shopify/sarama" + "github.com/golang/protobuf/proto" + "github.com/spf13/cast" + "regexp" +) + +type MsgToPushHandler struct { + ctx *svc.ServiceContext + msgHandle map[string]msgHandlerFunc + regex *regexp.Regexp + commandManager *command.Manager + ConsumerGroup *kafka.ConsumerGroup +} + +func (h *MsgToPushHandler) 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.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) + + 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, + }, cfg.Addr, []string{cfg.Topic}, config.Config.ConsumerGroupId.MsgToPush) + + if err != nil { + logger.SLog.Error(err) + } +} + +func (h *MsgToPushHandler) handleJoinGame(_ string, user *pb.User) { + h.ctx.RoomManager.Broadcast("game.join", &pb.JoinGame{User: user}) +} + +func (h *MsgToPushHandler) handleOutbreak(_ string, user *pb.User) { + h.ctx.RoomManager.Broadcast("game.outbreak", &pb.Outbreak{User: user}) +} + +func (h *MsgToPushHandler) handleCreateUnit(cmd string, user *pb.User) { + if len(cmd) < 2 { + return + } + unit := cmd[1] + h.ctx.RoomManager.Broadcast("game.createUnit", &pb.CreateUnit{ + User: user, + Unit: cast.ToString(unit), + }) +} + +func (h *MsgToPushHandler) handleMove(cmd string, user *pb.User) { + if len(cmd) < 2 { + return + } + line := cmd[1] + h.ctx.RoomManager.Broadcast("game.move", &pb.Move{ + User: user, + Line: cast.ToString(line), + }) +} + +func (h *MsgToPushHandler) handleWai(cmd string, user *pb.User) { + h.ctx.RoomManager.Broadcast("game.wai", &pb.Wai{User: user}) +} + +func (h *MsgToPushHandler) handleDanmaku(data []byte, msgKey string) { + // danmaku msg proto + var msgFromMq pb.Danmaku + 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(cmd, &pb.User{ + UId: msgFromMq.Uid, + Uname: msgFromMq.Uname, + }) + } +} + +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 { + for msg := range claim.Messages() { + //logger.SLog.Infow("kafka get info to mysql", "msgTopic", msg.Topic, "msgPartition", msg.Partition, "msg", string(msg.Value)) + if hFunc, ok := h.msgHandle[msg.Topic]; ok { + hFunc(msg.Value, string(msg.Key)) + } + sess.MarkMessage(msg, "") + } + return nil +} diff --git a/game/msg_transfer/init.go b/game/msg_transfer/init.go new file mode 100644 index 0000000..d56714d --- /dev/null +++ b/game/msg_transfer/init.go @@ -0,0 +1,18 @@ +package msg_transfer + +import ( + "dcg/game/msg_transfer/danmaku" + "dcg/game/svc" +) + +var ( + danmakuMsgToPush danmaku.MsgToPushHandler +) + +func Init(ctx *svc.ServiceContext) { + danmakuMsgToPush.Init(ctx) +} + +func Run() { + go danmakuMsgToPush.ConsumerGroup.RegisterHandlerAndConsumer(&danmakuMsgToPush) +} diff --git a/game/msg_transfer/vars.go b/game/msg_transfer/vars.go new file mode 100644 index 0000000..4d6cfa9 --- /dev/null +++ b/game/msg_transfer/vars.go @@ -0,0 +1 @@ +package msg_transfer diff --git a/game/pb/broadcast.pb.go b/game/pb/broadcast.pb.go new file mode 100644 index 0000000..4f71c5d --- /dev/null +++ b/game/pb/broadcast.pb.go @@ -0,0 +1,569 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.19.4 +// source: broadcast.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) +) + +type User struct { + state protoimpl.MessageState + 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"` //用户名 +} + +func (x *User) Reset() { + *x = User{} + if protoimpl.UnsafeEnabled { + mi := &file_broadcast_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_broadcast_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_broadcast_proto_rawDescGZIP(), []int{0} +} + +func (x *User) GetUId() int64 { + if x != nil { + return x.UId + } + return 0 +} + +func (x *User) GetUname() string { + if x != nil { + return x.Uname + } + return "" +} + +type JoinGame struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` +} + +func (x *JoinGame) Reset() { + *x = JoinGame{} + if protoimpl.UnsafeEnabled { + mi := &file_broadcast_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *JoinGame) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*JoinGame) ProtoMessage() {} + +func (x *JoinGame) ProtoReflect() protoreflect.Message { + mi := &file_broadcast_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 JoinGame.ProtoReflect.Descriptor instead. +func (*JoinGame) Descriptor() ([]byte, []int) { + return file_broadcast_proto_rawDescGZIP(), []int{1} +} + +func (x *JoinGame) GetUser() *User { + if x != nil { + return x.User + } + return nil +} + +type CreateUnit struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` + Unit string `protobuf:"bytes,2,opt,name=unit,proto3" json:"unit,omitempty"` //1-步兵,2-骑兵,3-弓箭手,4-法师 +} + +func (x *CreateUnit) Reset() { + *x = CreateUnit{} + if protoimpl.UnsafeEnabled { + mi := &file_broadcast_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateUnit) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateUnit) ProtoMessage() {} + +func (x *CreateUnit) ProtoReflect() protoreflect.Message { + mi := &file_broadcast_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 CreateUnit.ProtoReflect.Descriptor instead. +func (*CreateUnit) Descriptor() ([]byte, []int) { + return file_broadcast_proto_rawDescGZIP(), []int{2} +} + +func (x *CreateUnit) GetUser() *User { + if x != nil { + return x.User + } + return nil +} + +func (x *CreateUnit) GetUnit() string { + if x != nil { + return x.Unit + } + return "" +} + +type Move struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` + Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line,omitempty"` //1-上,2-中,3-下 +} + +func (x *Move) Reset() { + *x = Move{} + if protoimpl.UnsafeEnabled { + mi := &file_broadcast_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Move) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Move) ProtoMessage() {} + +func (x *Move) ProtoReflect() protoreflect.Message { + mi := &file_broadcast_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 Move.ProtoReflect.Descriptor instead. +func (*Move) Descriptor() ([]byte, []int) { + return file_broadcast_proto_rawDescGZIP(), []int{3} +} + +func (x *Move) GetUser() *User { + if x != nil { + return x.User + } + return nil +} + +func (x *Move) GetLine() string { + if x != nil { + return x.Line + } + return "" +} + +type Outbreak struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` +} + +func (x *Outbreak) Reset() { + *x = Outbreak{} + if protoimpl.UnsafeEnabled { + mi := &file_broadcast_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Outbreak) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Outbreak) ProtoMessage() {} + +func (x *Outbreak) ProtoReflect() protoreflect.Message { + mi := &file_broadcast_proto_msgTypes[4] + 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 Outbreak.ProtoReflect.Descriptor instead. +func (*Outbreak) Descriptor() ([]byte, []int) { + return file_broadcast_proto_rawDescGZIP(), []int{4} +} + +func (x *Outbreak) GetUser() *User { + if x != nil { + return x.User + } + return nil +} + +type Gift struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` + GiftId int32 `protobuf:"varint,2,opt,name=giftId,proto3" json:"giftId,omitempty"` + TotalCoin int64 `protobuf:"varint,3,opt,name=totalCoin,proto3" json:"totalCoin,omitempty"` +} + +func (x *Gift) Reset() { + *x = Gift{} + if protoimpl.UnsafeEnabled { + mi := &file_broadcast_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Gift) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Gift) ProtoMessage() {} + +func (x *Gift) ProtoReflect() protoreflect.Message { + mi := &file_broadcast_proto_msgTypes[5] + 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 Gift.ProtoReflect.Descriptor instead. +func (*Gift) Descriptor() ([]byte, []int) { + return file_broadcast_proto_rawDescGZIP(), []int{5} +} + +func (x *Gift) GetUser() *User { + if x != nil { + return x.User + } + return nil +} + +func (x *Gift) GetGiftId() int32 { + if x != nil { + return x.GiftId + } + return 0 +} + +func (x *Gift) GetTotalCoin() int64 { + if x != nil { + return x.TotalCoin + } + return 0 +} + +type Wai struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` +} + +func (x *Wai) Reset() { + *x = Wai{} + if protoimpl.UnsafeEnabled { + mi := &file_broadcast_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Wai) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Wai) ProtoMessage() {} + +func (x *Wai) ProtoReflect() protoreflect.Message { + mi := &file_broadcast_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 Wai.ProtoReflect.Descriptor instead. +func (*Wai) Descriptor() ([]byte, []int) { + return file_broadcast_proto_rawDescGZIP(), []int{6} +} + +func (x *Wai) GetUser() *User { + if x != nil { + return x.User + } + return nil +} + +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, + 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, + 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, + 0x73, 0x65, 0x72, 0x22, 0x5a, 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, 0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x69, 0x6e, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x69, 0x6e, 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, 0x42, 0x05, 0x5a, 0x03, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_broadcast_proto_rawDescOnce sync.Once + file_broadcast_proto_rawDescData = file_broadcast_proto_rawDesc +) + +func file_broadcast_proto_rawDescGZIP() []byte { + file_broadcast_proto_rawDescOnce.Do(func() { + file_broadcast_proto_rawDescData = protoimpl.X.CompressGZIP(file_broadcast_proto_rawDescData) + }) + return file_broadcast_proto_rawDescData +} + +var file_broadcast_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_broadcast_proto_goTypes = []interface{}{ + (*User)(nil), // 0: pb.User + (*JoinGame)(nil), // 1: pb.JoinGame + (*CreateUnit)(nil), // 2: pb.CreateUnit + (*Move)(nil), // 3: pb.Move + (*Outbreak)(nil), // 4: pb.Outbreak + (*Gift)(nil), // 5: pb.Gift + (*Wai)(nil), // 6: pb.Wai +} +var file_broadcast_proto_depIdxs = []int32{ + 0, // 0: pb.JoinGame.user:type_name -> pb.User + 0, // 1: pb.CreateUnit.user:type_name -> pb.User + 0, // 2: pb.Move.user:type_name -> pb.User + 0, // 3: pb.Outbreak.user:type_name -> pb.User + 0, // 4: pb.Gift.user:type_name -> pb.User + 0, // 5: pb.Wai.user:type_name -> pb.User + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name +} + +func init() { file_broadcast_proto_init() } +func file_broadcast_proto_init() { + if File_broadcast_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_broadcast_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_broadcast_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*JoinGame); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_broadcast_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateUnit); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_broadcast_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Move); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_broadcast_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Outbreak); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_broadcast_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Gift); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_broadcast_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Wai); 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_broadcast_proto_rawDesc, + NumEnums: 0, + NumMessages: 7, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_broadcast_proto_goTypes, + DependencyIndexes: file_broadcast_proto_depIdxs, + MessageInfos: file_broadcast_proto_msgTypes, + }.Build() + File_broadcast_proto = out.File + file_broadcast_proto_rawDesc = nil + file_broadcast_proto_goTypes = nil + file_broadcast_proto_depIdxs = nil +} diff --git a/game/pb/danmaku.pb.go b/game/pb/danmaku.pb.go index 6275b63..d8887c4 100644 --- a/game/pb/danmaku.pb.go +++ b/game/pb/danmaku.pb.go @@ -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: danmaku.proto @@ -25,8 +25,11 @@ type Danmaku struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Uid int64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"` - Uname string `protobuf:"bytes,2,opt,name=uname,proto3" json:"uname,omitempty"` + Platform string `protobuf:"bytes,1,opt,name=platform,proto3" json:"platform,omitempty"` + Uid int64 `protobuf:"varint,2,opt,name=uid,proto3" json:"uid,omitempty"` + Uname string `protobuf:"bytes,3,opt,name=uname,proto3" json:"uname,omitempty"` + Content string `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"` + SendTime int64 `protobuf:"varint,5,opt,name=sendTime,proto3" json:"sendTime,omitempty"` } func (x *Danmaku) Reset() { @@ -61,6 +64,13 @@ func (*Danmaku) Descriptor() ([]byte, []int) { return file_danmaku_proto_rawDescGZIP(), []int{0} } +func (x *Danmaku) GetPlatform() string { + if x != nil { + return x.Platform + } + return "" +} + func (x *Danmaku) GetUid() int64 { if x != nil { return x.Uid @@ -75,15 +85,34 @@ func (x *Danmaku) GetUname() string { return "" } +func (x *Danmaku) GetContent() string { + if x != nil { + return x.Content + } + return "" +} + +func (x *Danmaku) GetSendTime() int64 { + if x != nil { + return x.SendTime + } + return 0 +} + var File_danmaku_proto protoreflect.FileDescriptor var file_danmaku_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x64, 0x61, 0x6e, 0x6d, 0x61, 0x6b, 0x75, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x02, 0x70, 0x62, 0x22, 0x31, 0x0a, 0x07, 0x44, 0x61, 0x6e, 0x6d, 0x61, 0x6b, 0x75, 0x12, 0x10, - 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x69, 0x64, - 0x12, 0x14, 0x0a, 0x05, 0x75, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x75, 0x6e, 0x61, 0x6d, 0x65, 0x42, 0x05, 0x5a, 0x03, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x02, 0x70, 0x62, 0x22, 0x83, 0x01, 0x0a, 0x07, 0x44, 0x61, 0x6e, 0x6d, 0x61, 0x6b, 0x75, 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, 0x10, 0x0a, 0x03, 0x75, + 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x14, 0x0a, + 0x05, 0x75, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x75, 0x6e, + 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 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, 0x42, 0x05, 0x5a, 0x03, 0x2f, 0x70, 0x62, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/game/pb/danmaku.proto b/game/pb/danmaku.proto index 50778b6..0ad4ec5 100644 --- a/game/pb/danmaku.proto +++ b/game/pb/danmaku.proto @@ -5,6 +5,9 @@ package pb; option go_package = "/pb"; message Danmaku { - int64 uid = 1; - string uname = 2; + string platform = 1; + int64 uid = 2; + string uname = 3; + string content = 4; + int64 sendTime = 5; } \ No newline at end of file diff --git a/game/pb/room.pb.go b/game/pb/room.pb.go index b731b2c..3f5e670 100644 --- a/game/pb/room.pb.go +++ b/game/pb/room.pb.go @@ -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: room.proto diff --git a/game/room/manager.go b/game/room/manager.go index 69efccd..e0e70d6 100644 --- a/game/room/manager.go +++ b/game/room/manager.go @@ -22,6 +22,7 @@ type ( Manager struct { component.Base + timer *scheduler.Timer rooms map[int64]*Room } ) @@ -33,11 +34,6 @@ func NewRoomManager() *Manager { } func (m *Manager) Init() { - scheduler.NewTimer(5*time.Second, func() { - for _, room := range m.rooms { - room.group.Broadcast("onInterval", &pb.Test{T: time.Now().UnixNano()}) - } - }) } func (m *Manager) AfterInit() { @@ -48,6 +44,12 @@ func (m *Manager) AfterInit() { room := s.Value(roomIDKey).(*Room) _ = room.group.Leave(s) }) + m.timer = scheduler.NewTimer(30*time.Second, func() { + for roomId, room := range m.rooms { + logger.SLog.Debugf("UserCount: RoomID=%d, Time=%s, Count=%d", + roomId, time.Now().String(), room.group.Count()) + } + }) } func (m *Manager) Shutdown() { @@ -74,9 +76,18 @@ func (m *Manager) Join(s *session.Session, msg *pb.JoinRoomReq) error { s.Set(roomIDKey, room) // members - room.group.Broadcast("onNewClient", &pb.Client{Id: msg.LiveRoomId}) + var resp = &pb.JoinRoomResp{ + Code: 200, + Result: "success", + } - room.group.Add(s) + err = room.group.Add(s) + if err != nil { + resp.Code = 500 + resp.Result = "加入房间失败" + } else { + _ = room.group.Broadcast("onNewClient", &pb.Client{Id: msg.LiveRoomId}) + } return s.Response(&pb.JoinRoomResp{ Code: 200, diff --git a/game/svc/service_context.go b/game/svc/service_context.go new file mode 100644 index 0000000..0d41d3c --- /dev/null +++ b/game/svc/service_context.go @@ -0,0 +1,28 @@ +package svc + +import ( + "dcg/game/room" + "git.noahlan.cn/northlan/ngs/component" + "strings" +) + +type ServiceContext struct { + Services *component.Components + RoomManager *room.Manager +} + +func NewServiceContext() *ServiceContext { + services := &component.Components{} + + roomManager := room.NewRoomManager() + services.Register(roomManager, + component.WithName("room"), + component.WithNameFunc(func(s string) string { + return strings.ToLower(s) + })) + + return &ServiceContext{ + Services: services, + RoomManager: roomManager, + } +} diff --git a/go.mod b/go.mod index ad318d1..28f0466 100644 --- a/go.mod +++ b/go.mod @@ -4,38 +4,47 @@ go 1.18 require ( git.noahlan.cn/northlan/ngs v0.1.2 + 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 google.golang.org/protobuf v1.28.0 ) require ( - github.com/Shopify/sarama v1.32.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect github.com/davecgh/go-spew v1.1.1 // 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/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect + github.com/gookit/config/v2 v2.1.0 // 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/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/klauspost/compress v1.15.1 // indirect - github.com/natefinch/lumberjack v2.0.0+incompatible // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pierrec/lz4 v2.6.1+incompatible // 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 go.uber.org/atomic v1.9.0 // 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-20220418201149-a630d4f3e7a2 // indirect golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // 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 + gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 839a3de..089d175 100644 --- a/go.sum +++ b/go.sum @@ -2,11 +2,20 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= git.noahlan.cn/northlan/ngs v0.1.2 h1:0+cZIAff14VgGBqkCw5Hur9gVD6HzxTmFIvuoWvFphQ= git.noahlan.cn/northlan/ngs v0.1.2/go.mod h1:dWoj94sHXJPFE1BbCvF8hOLtMRUe0V6v7RGpGs4+iAs= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/Shopify/sarama v1.32.0 h1:P+RUjEaRU0GMMbYexGMDyrMkLhbbBVUVISDywi+IlFU= github.com/Shopify/sarama v1.32.0/go.mod h1:+EmJJKZWVT/faR9RcOxJerP+LId4iWdQPBGLy1Y1Njs= +github.com/Shopify/toxiproxy/v2 v2.3.0 h1:62YkpiP4bzdhKMH+6uC5E95y608k3zDwdzuBMsnn3uQ= github.com/Shopify/toxiproxy/v2 v2.3.0/go.mod h1:KvQTtB6RjCJY4zqNJn7C7JDFgsG5uoHYDirfUfpIm0c= +github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= +github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= +github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -36,14 +45,20 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= +github.com/frankban/quicktest v1.14.2 h1:SPb1KFFmM+ybpEjPUhCCkZOM5xlovT5UbrMvWnXyBns= github.com/frankban/quicktest v1.14.2/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= @@ -62,10 +77,17 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= +github.com/gookit/config/v2 v2.1.0 h1:RNiT4tsAkDBP5QPhxGk/vEcQO4ET1xdRBd9BStL4G1E= +github.com/gookit/config/v2 v2.1.0/go.mod h1:2qFkfHkS7Aj4T1LaJh5jxejxhO34NM/eJj4/DY/C9Zs= +github.com/gookit/goutil v0.5.0 h1:SrbfjqZ8iprxJOfKZVT0yGJ4/82afr4Qa0RQwON19I4= +github.com/gookit/goutil v0.5.0/go.mod h1:pq1eTibwb2wN96jrci0xy7xogWzzo9CihOQJEAvz4yQ= +github.com/gookit/ini/v2 v2.1.0/go.mod h1:r06awbwBtIHxjA7ndqWJkRgCAvSG+5FdSGrrbGfigtY= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= @@ -75,60 +97,98 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFb github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/hcl/v2 v2.11.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8= github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo= github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM= github.com/jcmturner/gofork v1.0.0 h1:J7uCkflzTEhUZ64xqKnkDxq3kzc96ajM1Gli5ktUem8= github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o= +github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o= github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg= github.com/jcmturner/gokrb5/v8 v8.4.2 h1:6ZIM6b/JJN0X8UM43ZOM6Z4SJzla+a/u7scXFJzodkA= github.com/jcmturner/gokrb5/v8 v8.4.2/go.mod h1:sb+Xq/fTY5yktf/VxLsE3wlfPqQjp0aWNYyvBVK62bc= github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY= github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/compress v1.14.4/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.15.1 h1:y9FcTHGyrebwfP0ZZqFiaxTaiDnUrGkJkI+f583BL1A= github.com/klauspost/compress v1.15.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= +github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA= +github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= +github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= +github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.0/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= +github.com/yosuke-furukawa/json5 v0.1.1/go.mod h1:sw49aWDqNdRJ6DYUtIQiaA3xyj2IL9tjeNYmX2ixwcU= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= +github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= +github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= @@ -136,9 +196,11 @@ go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95a go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8= go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= @@ -149,13 +211,16 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -172,6 +237,7 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -179,12 +245,15 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -204,6 +273,7 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1N golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= @@ -235,11 +305,18 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= +gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/main.go b/main.go index 9010fb9..ecefd5e 100644 --- a/main.go +++ b/main.go @@ -1,69 +1,29 @@ package main import ( - "dcg/client" - "dcg/game" - "errors" - "github.com/urfave/cli" - "log" - "os" + "dcg/config" + "dcg/game/msg_transfer" + "dcg/game/svc" + "dcg/pkg/logger" + "git.noahlan.cn/northlan/ngs" + "git.noahlan.cn/northlan/ngs/serialize/protobuf" ) func main() { - app := cli.NewApp() - app.Name = "弹幕指挥官 GameServer" - app.Author = "NorthLan" - app.Email = "6995syu@163.com" - app.Description = "弹幕指挥官 TCP服务端" - app.Commands = []cli.Command{ - { - Name: "server", - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "listen,l", - Usage: "-l --listen [ip]:8888", - Value: "127.0.0.1:8888", - }, - }, - Action: runMaster, - }, - { - Name: "client", - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "addr", - Usage: "--addr xxx:xxx", - Value: "127.0.0.1:8888", - }, - }, - Action: runClient, - }, - } - if err := app.Run(os.Args); err != nil { - log.Fatalf("Startup server error %+v", err) - } -} - -func runMaster(args *cli.Context) error { - listen := args.String("listen") - if listen == "" { - return errors.New("master listen address cannot empty") - } - - log.Println("Game server listen address", listen) + _ = logger.InitLogger(&config.Config.Log.File, &config.Config.Log.Console) + defer logger.Sync() - game.Run(listen) + ctx := svc.NewServiceContext() - return nil -} + msg_transfer.Init(ctx) + msg_transfer.Run() -func runClient(args *cli.Context) error { - addr := args.String("addr") - if addr == "" { - return errors.New("address cannot empty") + opts := make([]ngs.Option, 0) + opts = append(opts, ngs.WithComponents(ctx.Services)) + opts = append(opts, ngs.WithSerializer(protobuf.NewSerializer())) + if config.Config.Server.Debug { + ngs.WithDebugMode() } - log.Println("Client start, connect to", addr) - - return client.NewClient(addr) + ngs.Listen(config.Config.Server.Listen, opts...) } diff --git a/pkg/trie/trie_test.go b/pkg/trie/trie_test.go index a31fbd3..e3a6856 100644 --- a/pkg/trie/trie_test.go +++ b/pkg/trie/trie_test.go @@ -2,6 +2,7 @@ package trie import ( "fmt" + "regexp" "testing" ) @@ -23,4 +24,12 @@ func TestTrie(t *testing.T) { } else { fmt.Println("啊 还没能匹配", search) } + + var exp = `([jJ])|([sS])|([cC]\d)|([mM]\d)` + compile, err := regexp.Compile(exp) + if err != nil { + return + } + allString := compile.FindAllString(search, -1) + fmt.Println(allString) }