Commit 8568cf44b073b31617242db4c7c86f48e65e9110

Authored by zhangqijia
1 parent db0d748f

update preserve

cmd/gameserver/action/protocode.go
... ... @@ -19,4 +19,4 @@ func GetActionMap() map[interface{}]interface{} {
19 19 am[uint32(pb.ProtoCode_EquipmentDelRpc)] = EquipmentDelRpc
20 20  
21 21 return am
22 22 -}
  23 +}
23 24 \ No newline at end of file
... ...
cmd/gameserver/service/agent.go
... ... @@ -64,7 +64,6 @@ func (c *Agent) OnConnection(conn components.IConnection) {
64 64 2 角色不存在
65 65 */
66 66 func (c *Agent) OnLoginQuery(msg components.IMessage) (int32, proto.Message) {
67   - //logger.Debug("11111111cmd: %v, msg: %s", msg.GetHeader().GetMsgID(), msg.GetData())
68 67 req := pb.LoginReq{}
69 68 if err := proto.Unmarshal(msg.GetData(), &req); err != nil {
70 69 logger.Error("loginRpc err: %v", err)
... ... @@ -77,7 +76,7 @@ func (c *Agent) OnLoginQuery(msg components.IMessage) (int32, proto.Message) {
77 76 conn := c.Server.GetConnManage().GetConnByUID(uid)
78 77 if conn != nil {
79 78 logger.Debug("挤掉。。。。。。。。")
80   - conn.SendSuccess(uint32(pb.ProtoCode_DisConnectNty), nil)
  79 + conn.SendSuccess(uint32(pb.ProtoCode_DisConnectNty), nil, msg.GetHeader().GetPreserve())
81 80 conn.Stop()
82 81 }
83 82  
... ... @@ -97,15 +96,15 @@ func (c *Agent) OnLoginQuery(msg components.IMessage) (int32, proto.Message) {
97 96 return 0, protoMsg
98 97 }
99 98  
100   -func (c *Agent) SendMsg(errCode int32, cmd uint32, msg interface{}) error {
  99 +func (c *Agent) SendMsg(errCode int32, cmd uint32, msg interface{}, preserve uint32) error {
101 100 if msg == nil || errCode != 0 {
102   - return c.Send(errCode, cmd, nil)
  101 + return c.Send(errCode, cmd, nil, preserve)
103 102 }
104 103 rsp, err := proto.Marshal(msg.(proto.Message))
105 104 if err != nil {
106   - return c.Send(-100, cmd, nil)
  105 + return c.Send(-100, cmd, nil, preserve)
107 106 }
108   - return c.Send(errCode, cmd, rsp)
  107 + return c.Send(errCode, cmd, rsp, preserve)
109 108 }
110 109  
111 110 func (c *Agent) OnMessage(msg components.IMessage) error {
... ... @@ -119,24 +118,24 @@ func (c *Agent) OnMessage(msg components.IMessage) error {
119 118 //login
120 119 if msg.GetHeader().GetMsgID() == uint32(pb.ProtoCode_LoginRpc) {
121 120 code, protoMsg := c.OnLoginQuery(msg)
122   - return c.SendMsg(code, msg.GetHeader().GetMsgID(), protoMsg)
  121 + return c.SendMsg(code, msg.GetHeader().GetMsgID(), protoMsg, msg.GetHeader().GetPreserve())
123 122 }
124 123  
125 124 //get handler by msgid
126   - md := c.Server.GetAction(msg.GetHeader().GetMsgID())
127   - if md == nil {
  125 + method := c.Server.GetAction(msg.GetHeader().GetMsgID())
  126 + if method == nil {
128 127 return fmt.Errorf("cmd: %d, handler is nil", msg.GetHeader().GetMsgID())
129 128 }
130 129  
131 130 if msg.GetHeader().GetMsgID() != uint32(pb.ProtoCode_CreateRpc) && c.Role == nil {
132   - return c.Send(-101, msg.GetHeader().GetMsgID(), nil)
  131 + return c.Send(-101, msg.GetHeader().GetMsgID(), nil, msg.GetHeader().GetPreserve())
133 132 }
134 133  
135   - //调用协议号对应的逻辑函数
136   - f := md.(func(role *models.RoleModel, msg components.IMessage) (int32, interface{}))
  134 + // 调用协议号对应的逻辑函数
  135 + f := method.(func(role *models.RoleModel, msg components.IMessage) (int32, interface{}))
137 136 errCode, protoMsg := f(c.Role, msg)
138 137 logger.Debug("rsp errcode: %d, protocode: %d", errCode, msg.GetHeader().GetMsgID())
139   - return c.SendMsg(errCode, msg.GetHeader().GetMsgID(), protoMsg)
  138 + return c.SendMsg(errCode, msg.GetHeader().GetMsgID(), protoMsg, msg.GetHeader().GetPreserve())
140 139 }
141 140  
142 141 func (c *Agent) OnTimer() {
... ...
cmd/test/action/protocode.go
... ... @@ -21,4 +21,4 @@ func GetTestActionMap() map[interface{}]interface{} {
21 21 am[uint32(pb.ProtoCode_EquipmentAddNty)] = EquipmentAddNty
22 22  
23 23 return am
24 24 -}
  25 +}
25 26 \ No newline at end of file
... ...
common/components/conn.go
... ... @@ -123,8 +123,8 @@ func (c *Connection) Stop() {
123 123 }
124 124 }
125 125  
126   -func (c *Connection) Send(errCode int32, cmd uint32, data []byte) error {
127   - buf, err := c.splitter.Pack(cmd, data, errCode, 0)
  126 +func (c *Connection) Send(errCode int32, cmd uint32, data []byte, preserve uint32) error {
  127 + buf, err := c.splitter.Pack(cmd, data, errCode, preserve)
128 128 if err != nil {
129 129 return err
130 130 }
... ... @@ -140,8 +140,8 @@ func (c *Connection) Send(errCode int32, cmd uint32, data []byte) error {
140 140 }
141 141 }
142 142  
143   -func (c *Connection) SendSuccess(cmd uint32, data []byte) error {
144   - buf, err := c.splitter.Pack(cmd, data, 0, 0)
  143 +func (c *Connection) SendSuccess(cmd uint32, data []byte, preserve uint32) error {
  144 + buf, err := c.splitter.Pack(cmd, data, 0, preserve)
145 145 if err != nil {
146 146 return err
147 147 }
... ...
common/components/connector.go
... ... @@ -66,21 +66,21 @@ func (c *Connector) DisConnect() {
66 66 c.IConnection.Stop()
67 67 }
68 68  
69   -func (c *Connector) Send(cmd uint32, b []byte) error {
  69 +func (c *Connector) Send(cmd uint32, b []byte, preserve uint32) error {
70 70 logger.Debug("connector send cmd: %d, msg: %s", cmd, b)
71   - return c.IConnection.Send(0, cmd, b)
  71 + return c.IConnection.Send(0, cmd, b, preserve)
72 72 }
73 73  
74   -func (c *Connector) SendPB(cmd pb.ProtoCode, b proto.Message) error {
  74 +func (c *Connector) SendPB(cmd pb.ProtoCode, b proto.Message, preserve uint32) error {
75 75 if b == nil {
76   - return c.Send(uint32(cmd), nil)
  76 + return c.Send(uint32(cmd), nil, preserve)
77 77 }
78 78  
79 79 l, err := proto.Marshal(b)
80 80 if err != nil {
81 81 return err
82 82 }
83   - return c.Send(uint32(cmd), l)
  83 + return c.Send(uint32(cmd), l, preserve)
84 84 }
85 85  
86 86 func (c *Connector) GetSplitter() ISplitter {
... ...
common/components/icompontents.go
... ... @@ -17,7 +17,7 @@ type (
17 17 GetDataLen() uint32 //获取消息数据段长度
18 18 GetMsgID() uint32 //获取消息ID
19 19 GetErrCode() int32 //获取消息错误码
20   - GetPreserve() uint32 //获取预留数据
  20 + GetPreserve() uint32 //获取预留数据 客户端上传的session。echo回去。
21 21 }
22 22 //网络包
23 23 IMessage interface {
... ... @@ -52,8 +52,8 @@ type (
52 52 GetID() uint32
53 53 Start()
54 54 Stop()
55   - Send(errCode int32, cmd uint32, b []byte) error
56   - SendSuccess(cmd uint32, b []byte) error
  55 + Send(errCode int32, cmd uint32, b []byte, preserve uint32) error
  56 + SendSuccess(cmd uint32, b []byte, preserve uint32) error
57 57 CustomChan() chan<- func()
58 58  
59 59 SetConnectionCallback(ConnectionCallback)
... ... @@ -108,8 +108,8 @@ type (
108 108 DisConnect()
109 109  
110 110 GetConn() IConnection
111   - Send(cmd uint32, b []byte) error
112   - SendPB(cmd pb.ProtoCode, b proto.Message) error
  111 + Send(cmd uint32, b []byte, preserve uint32) error
  112 + SendPB(cmd pb.ProtoCode, b proto.Message, preserve uint32) error
113 113 }
114 114  
115 115 //httpserver
... ...
common/components/pbsplitter.go
... ... @@ -11,7 +11,7 @@ type PBHead struct {
11 11 Length uint32
12 12 Cmd uint32
13 13 ErrCode int32
14   - PreField uint32
  14 + PreField uint32 // 预留字段 客户端上传的session。echo回去。
15 15 }
16 16  
17 17 func (h *PBHead) GetDataLen() uint32 {
... ...
docker/docker-compose-db.yml 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +version: '3.3'
  2 +services:
  3 + mongo:
  4 + image: mongo
  5 + container_name: mongodb-pro2d
  6 + ports:
  7 + - '27017:27017'
  8 + restart: always
  9 + environment:
  10 + MONGO_INITDB_ROOT_USERNAME: root #mongo默认的账号
  11 + MONGO_INITDB_ROOT_PASSWORD: root #mongo默认的密码
  12 + volumes:
  13 + - ./.docker/mongo_data:/data/db
  14 + - ./.docker/mongo.conf:/data/mongo.conf
  15 + # command: --config /data/mongo.conf # 配置文件
  16 + command: [--auth] # 配置文件
  17 + redis:
  18 + image: redis:latest
  19 + container_name: redis-pro2d
  20 + restart: always
  21 + ports:
  22 + - '6100:6379'
  23 + volumes:
  24 + - ./.docker/redis_data:/data/db
  25 + es:
  26 + image: elasticsearch
  27 + container_name: elasticsearch-pro2d
  28 + restart: always
  29 + environment:
  30 + discovery.type: single-node
  31 + volumes:
  32 + - ./.docker/es/data:/usr/share/elasticsearch/data
  33 + - ./.docker/es/config:/usr/share/elasticsearch/config
  34 + - ./.docker/es/plugins:/usr/share/elasticsearch/plugins
  35 +
  36 + # etcd:
  37 + # image: xieyanze/etcd3
  38 + # container_name: etcd3-pro2d
  39 + # restart: always
  40 + # ports:
  41 + # - '2379:2379'
... ...
pb/models.pb.go
... ... @@ -530,8 +530,8 @@ type Role struct {
530 530 sizeCache protoimpl.SizeCache
531 531 unknownFields protoimpl.UnknownFields
532 532  
533   - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" index:"unique" pri:"1"` // @inject_tag: index:"unique" pri:"1"
534   - Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty" index:"unique"` // @inject_tag: index:"unique"
  533 + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" index:"unique" pri:"1"` // @inject_tag: index:"unique" pri:"1"
  534 + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty" index:"unique"` // @inject_tag: index:"unique"
535 535 Device string `protobuf:"bytes,3,opt,name=device,proto3" json:"device,omitempty"`
536 536 Nick string `protobuf:"bytes,4,opt,name=nick,proto3" json:"nick,omitempty"`
537 537 Level int32 `protobuf:"varint,5,opt,name=level,proto3" json:"level,omitempty"`
... ...
1   -Subproject commit b06453989759451c4808e52f854a20c12f6b683d
  1 +Subproject commit d9a4f5a801c3aabcd3859644f1554e9a3f91fb7d
... ...