From 8568cf44b073b31617242db4c7c86f48e65e9110 Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Fri, 10 Jun 2022 11:08:51 +0800 Subject: [PATCH] update preserve --- cmd/gameserver/action/protocode.go | 2 +- cmd/gameserver/service/agent.go | 25 ++++++++++++------------- cmd/test/action/protocode.go | 2 +- common/components/conn.go | 8 ++++---- common/components/connector.go | 10 +++++----- common/components/icompontents.go | 10 +++++----- common/components/pbsplitter.go | 2 +- docker/docker-compose-db.yml | 41 +++++++++++++++++++++++++++++++++++++++++ pb/models.pb.go | 4 ++-- protos | 2 +- 10 files changed, 73 insertions(+), 33 deletions(-) create mode 100644 docker/docker-compose-db.yml diff --git a/cmd/gameserver/action/protocode.go b/cmd/gameserver/action/protocode.go index ce4cda2..20c8b65 100644 --- a/cmd/gameserver/action/protocode.go +++ b/cmd/gameserver/action/protocode.go @@ -19,4 +19,4 @@ func GetActionMap() map[interface{}]interface{} { am[uint32(pb.ProtoCode_EquipmentDelRpc)] = EquipmentDelRpc return am -} +} \ No newline at end of file diff --git a/cmd/gameserver/service/agent.go b/cmd/gameserver/service/agent.go index 9585251..cf4046e 100644 --- a/cmd/gameserver/service/agent.go +++ b/cmd/gameserver/service/agent.go @@ -64,7 +64,6 @@ func (c *Agent) OnConnection(conn components.IConnection) { 2 角色不存在 */ func (c *Agent) OnLoginQuery(msg components.IMessage) (int32, proto.Message) { - //logger.Debug("11111111cmd: %v, msg: %s", msg.GetHeader().GetMsgID(), msg.GetData()) req := pb.LoginReq{} if err := proto.Unmarshal(msg.GetData(), &req); err != nil { logger.Error("loginRpc err: %v", err) @@ -77,7 +76,7 @@ func (c *Agent) OnLoginQuery(msg components.IMessage) (int32, proto.Message) { conn := c.Server.GetConnManage().GetConnByUID(uid) if conn != nil { logger.Debug("挤掉。。。。。。。。") - conn.SendSuccess(uint32(pb.ProtoCode_DisConnectNty), nil) + conn.SendSuccess(uint32(pb.ProtoCode_DisConnectNty), nil, msg.GetHeader().GetPreserve()) conn.Stop() } @@ -97,15 +96,15 @@ func (c *Agent) OnLoginQuery(msg components.IMessage) (int32, proto.Message) { return 0, protoMsg } -func (c *Agent) SendMsg(errCode int32, cmd uint32, msg interface{}) error { +func (c *Agent) SendMsg(errCode int32, cmd uint32, msg interface{}, preserve uint32) error { if msg == nil || errCode != 0 { - return c.Send(errCode, cmd, nil) + return c.Send(errCode, cmd, nil, preserve) } rsp, err := proto.Marshal(msg.(proto.Message)) if err != nil { - return c.Send(-100, cmd, nil) + return c.Send(-100, cmd, nil, preserve) } - return c.Send(errCode, cmd, rsp) + return c.Send(errCode, cmd, rsp, preserve) } func (c *Agent) OnMessage(msg components.IMessage) error { @@ -119,24 +118,24 @@ func (c *Agent) OnMessage(msg components.IMessage) error { //login if msg.GetHeader().GetMsgID() == uint32(pb.ProtoCode_LoginRpc) { code, protoMsg := c.OnLoginQuery(msg) - return c.SendMsg(code, msg.GetHeader().GetMsgID(), protoMsg) + return c.SendMsg(code, msg.GetHeader().GetMsgID(), protoMsg, msg.GetHeader().GetPreserve()) } //get handler by msgid - md := c.Server.GetAction(msg.GetHeader().GetMsgID()) - if md == nil { + method := c.Server.GetAction(msg.GetHeader().GetMsgID()) + if method == nil { return fmt.Errorf("cmd: %d, handler is nil", msg.GetHeader().GetMsgID()) } if msg.GetHeader().GetMsgID() != uint32(pb.ProtoCode_CreateRpc) && c.Role == nil { - return c.Send(-101, msg.GetHeader().GetMsgID(), nil) + return c.Send(-101, msg.GetHeader().GetMsgID(), nil, msg.GetHeader().GetPreserve()) } - //调用协议号对应的逻辑函数 - f := md.(func(role *models.RoleModel, msg components.IMessage) (int32, interface{})) + // 调用协议号对应的逻辑函数 + f := method.(func(role *models.RoleModel, msg components.IMessage) (int32, interface{})) errCode, protoMsg := f(c.Role, msg) logger.Debug("rsp errcode: %d, protocode: %d", errCode, msg.GetHeader().GetMsgID()) - return c.SendMsg(errCode, msg.GetHeader().GetMsgID(), protoMsg) + return c.SendMsg(errCode, msg.GetHeader().GetMsgID(), protoMsg, msg.GetHeader().GetPreserve()) } func (c *Agent) OnTimer() { diff --git a/cmd/test/action/protocode.go b/cmd/test/action/protocode.go index 0298945..abe7267 100644 --- a/cmd/test/action/protocode.go +++ b/cmd/test/action/protocode.go @@ -21,4 +21,4 @@ func GetTestActionMap() map[interface{}]interface{} { am[uint32(pb.ProtoCode_EquipmentAddNty)] = EquipmentAddNty return am -} +} \ No newline at end of file diff --git a/common/components/conn.go b/common/components/conn.go index e095ab9..38c8c9e 100644 --- a/common/components/conn.go +++ b/common/components/conn.go @@ -123,8 +123,8 @@ func (c *Connection) Stop() { } } -func (c *Connection) Send(errCode int32, cmd uint32, data []byte) error { - buf, err := c.splitter.Pack(cmd, data, errCode, 0) +func (c *Connection) Send(errCode int32, cmd uint32, data []byte, preserve uint32) error { + buf, err := c.splitter.Pack(cmd, data, errCode, preserve) if err != nil { return err } @@ -140,8 +140,8 @@ func (c *Connection) Send(errCode int32, cmd uint32, data []byte) error { } } -func (c *Connection) SendSuccess(cmd uint32, data []byte) error { - buf, err := c.splitter.Pack(cmd, data, 0, 0) +func (c *Connection) SendSuccess(cmd uint32, data []byte, preserve uint32) error { + buf, err := c.splitter.Pack(cmd, data, 0, preserve) if err != nil { return err } diff --git a/common/components/connector.go b/common/components/connector.go index 196d66f..008bb12 100644 --- a/common/components/connector.go +++ b/common/components/connector.go @@ -66,21 +66,21 @@ func (c *Connector) DisConnect() { c.IConnection.Stop() } -func (c *Connector) Send(cmd uint32, b []byte) error { +func (c *Connector) Send(cmd uint32, b []byte, preserve uint32) error { logger.Debug("connector send cmd: %d, msg: %s", cmd, b) - return c.IConnection.Send(0, cmd, b) + return c.IConnection.Send(0, cmd, b, preserve) } -func (c *Connector) SendPB(cmd pb.ProtoCode, b proto.Message) error { +func (c *Connector) SendPB(cmd pb.ProtoCode, b proto.Message, preserve uint32) error { if b == nil { - return c.Send(uint32(cmd), nil) + return c.Send(uint32(cmd), nil, preserve) } l, err := proto.Marshal(b) if err != nil { return err } - return c.Send(uint32(cmd), l) + return c.Send(uint32(cmd), l, preserve) } func (c *Connector) GetSplitter() ISplitter { diff --git a/common/components/icompontents.go b/common/components/icompontents.go index e7b7aae..beb1936 100644 --- a/common/components/icompontents.go +++ b/common/components/icompontents.go @@ -17,7 +17,7 @@ type ( GetDataLen() uint32 //获取消息数据段长度 GetMsgID() uint32 //获取消息ID GetErrCode() int32 //获取消息错误码 - GetPreserve() uint32 //获取预留数据 + GetPreserve() uint32 //获取预留数据 客户端上传的session。echo回去。 } //网络包 IMessage interface { @@ -52,8 +52,8 @@ type ( GetID() uint32 Start() Stop() - Send(errCode int32, cmd uint32, b []byte) error - SendSuccess(cmd uint32, b []byte) error + Send(errCode int32, cmd uint32, b []byte, preserve uint32) error + SendSuccess(cmd uint32, b []byte, preserve uint32) error CustomChan() chan<- func() SetConnectionCallback(ConnectionCallback) @@ -108,8 +108,8 @@ type ( DisConnect() GetConn() IConnection - Send(cmd uint32, b []byte) error - SendPB(cmd pb.ProtoCode, b proto.Message) error + Send(cmd uint32, b []byte, preserve uint32) error + SendPB(cmd pb.ProtoCode, b proto.Message, preserve uint32) error } //httpserver diff --git a/common/components/pbsplitter.go b/common/components/pbsplitter.go index f64c1eb..2570561 100644 --- a/common/components/pbsplitter.go +++ b/common/components/pbsplitter.go @@ -11,7 +11,7 @@ type PBHead struct { Length uint32 Cmd uint32 ErrCode int32 - PreField uint32 + PreField uint32 // 预留字段 客户端上传的session。echo回去。 } func (h *PBHead) GetDataLen() uint32 { diff --git a/docker/docker-compose-db.yml b/docker/docker-compose-db.yml new file mode 100644 index 0000000..f3e83c6 --- /dev/null +++ b/docker/docker-compose-db.yml @@ -0,0 +1,41 @@ +version: '3.3' +services: + mongo: + image: mongo + container_name: mongodb-pro2d + ports: + - '27017:27017' + restart: always + environment: + MONGO_INITDB_ROOT_USERNAME: root #mongo默认的账号 + MONGO_INITDB_ROOT_PASSWORD: root #mongo默认的密码 + volumes: + - ./.docker/mongo_data:/data/db + - ./.docker/mongo.conf:/data/mongo.conf + # command: --config /data/mongo.conf # 配置文件 + command: [--auth] # 配置文件 + redis: + image: redis:latest + container_name: redis-pro2d + restart: always + ports: + - '6100:6379' + volumes: + - ./.docker/redis_data:/data/db + es: + image: elasticsearch + container_name: elasticsearch-pro2d + restart: always + environment: + discovery.type: single-node + volumes: + - ./.docker/es/data:/usr/share/elasticsearch/data + - ./.docker/es/config:/usr/share/elasticsearch/config + - ./.docker/es/plugins:/usr/share/elasticsearch/plugins + + # etcd: + # image: xieyanze/etcd3 + # container_name: etcd3-pro2d + # restart: always + # ports: + # - '2379:2379' diff --git a/pb/models.pb.go b/pb/models.pb.go index f3cb3d1..cd70b86 100644 --- a/pb/models.pb.go +++ b/pb/models.pb.go @@ -530,8 +530,8 @@ type Role struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" index:"unique" pri:"1"` // @inject_tag: index:"unique" pri:"1" - Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty" index:"unique"` // @inject_tag: index:"unique" + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" index:"unique" pri:"1"` // @inject_tag: index:"unique" pri:"1" + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty" index:"unique"` // @inject_tag: index:"unique" Device string `protobuf:"bytes,3,opt,name=device,proto3" json:"device,omitempty"` Nick string `protobuf:"bytes,4,opt,name=nick,proto3" json:"nick,omitempty"` Level int32 `protobuf:"varint,5,opt,name=level,proto3" json:"level,omitempty"` diff --git a/protos b/protos index b064539..d9a4f5a 160000 --- a/protos +++ b/protos @@ -1 +1 @@ -Subproject commit b06453989759451c4808e52f854a20c12f6b683d +Subproject commit d9a4f5a801c3aabcd3859644f1554e9a3f91fb7d -- libgit2 0.21.2