Commit 927b2652a7545bec77fa83fac6941a11fc9cef6f

Authored by zhangqijia
1 parent b1b91cf6

feat: EmailNewNty, 新邮件通知

cmd/gameserver/gmaction/GmAction.go
... ... @@ -2,7 +2,6 @@
2 2 package gmaction
3 3  
4 4 import (
5   - "pro2d/common"
6 5 "pro2d/common/logger"
7 6 "pro2d/models"
8 7 "pro2d/pb"
... ... @@ -114,24 +113,17 @@ func (gm *GmAction) GMEmail(role *models.RoleModel, params GMParams) {
114 113 if !ok {
115 114 attachments = ""
116 115 }
117   - id, err := common.GetNextEmail()
118   - if err != nil {
119   - logger.Error(err)
120   - return
121   - }
  116 +
122 117 email := &pb.Email{
123   - Id: id,
124 118 RoleId: role.Data.Id,
125 119 Title: title,
126 120 Stitle: stitle,
127 121 Content: content,
128 122 Attachments: attachments,
129   - Status: 0,
130   - CreateTime: common.Timex(),
131 123 }
132   - m := models.NewEmailModelPB(email)
133   - err = m.Create()
  124 + err := role.InsertEmail(email)
134 125 if err != nil {
135   - logger.Error(err)
  126 + logger.Error(err.Error())
  127 + return
136 128 }
137 129 }
... ...
cmd/gameserver/service/agent.go
... ... @@ -100,11 +100,7 @@ func (c *Agent) SendMsg(errCode int32, cmd uint32, msg interface{}, preserve uin
100 100 if msg == nil || errCode != 0 {
101 101 return c.Send(errCode, cmd, nil, preserve)
102 102 }
103   - rsp, err := proto.Marshal(msg.(proto.Message))
104   - if err != nil {
105   - return c.Send(-100, cmd, nil, preserve)
106   - }
107   - return c.Send(errCode, cmd, rsp, preserve)
  103 + return c.SendPB(errCode, cmd, msg.(proto.Message), preserve)
108 104 }
109 105  
110 106 func (c *Agent) OnMessage(msg components.IMessage) error {
... ...
cmd/test/action/protocode.go
... ... @@ -23,6 +23,7 @@ func GetTestActionMap() map[interface{}]interface{} {
23 23 am[uint32(pb.ProtoCode_RoleUpdatePropertyNty)] = RoleUpdatePropertyNty
24 24 am[uint32(pb.ProtoCode_RoleUpdateItemsNty)] = RoleUpdateItemsNty
25 25 am[uint32(pb.ProtoCode_EquipmentAddNty)] = EquipmentAddNty
  26 + am[uint32(pb.ProtoCode_EmailNewNty)] = EmailNewNty
26 27  
27 28 return am
28 29 }
... ...
common/components/conn.go
... ... @@ -3,6 +3,7 @@ package components
3 3 import (
4 4 "bufio"
5 5 "fmt"
  6 + "github.com/golang/protobuf/proto"
6 7 "net"
7 8 "pro2d/common"
8 9 "pro2d/common/logger"
... ... @@ -140,6 +141,27 @@ func (c *Connection) Send(errCode int32, cmd uint32, data []byte, preserve uint3
140 141 }
141 142 }
142 143  
  144 +func (c *Connection) SendPB(errCode int32, cmd uint32, data proto.Message, preserve uint32) error {
  145 + pbData, err := proto.Marshal(data)
  146 + if err != nil {
  147 + return err
  148 + }
  149 + buf, err := c.splitter.Pack(cmd, pbData, errCode, preserve)
  150 + if err != nil {
  151 + return err
  152 + }
  153 +
  154 + sendTimeout := time.NewTimer(5 * time.Millisecond)
  155 + defer sendTimeout.Stop()
  156 + // 发送超时
  157 + select {
  158 + case <-sendTimeout.C:
  159 + return fmt.Errorf("send buff msg timeout")
  160 + case c.WBuffer <- buf:
  161 + return nil
  162 + }
  163 +}
  164 +
143 165 func (c *Connection) SendSuccess(cmd uint32, data []byte, preserve uint32) error {
144 166 buf, err := c.splitter.Pack(cmd, data, 0, preserve)
145 167 if err != nil {
... ...
common/components/icompontents.go
... ... @@ -53,6 +53,7 @@ type (
53 53 Start()
54 54 Stop()
55 55 Send(errCode int32, cmd uint32, b []byte, preserve uint32) error
  56 + SendPB(errCode int32, cmd uint32, b proto.Message, preserve uint32) error
56 57 SendSuccess(cmd uint32, b []byte, preserve uint32) error
57 58 CustomChan() chan<- func()
58 59  
... ...
models/email.go
1 1 package models
2 2  
3 3 import (
4   - "pro2d/common"
5 4 "pro2d/common/components"
6 5 "pro2d/pb"
7 6 )
... ... @@ -30,20 +29,6 @@ func NewEmailModelPB(email *pb.Email) *EmailModel {
30 29 return m
31 30 }
32 31  
33   -func InsertEmail(email *pb.Email) bool {
34   - data := &EmailModel{
35   - ISchema: NewSchema(email.Id, email),
36   - Data: email,
37   - }
38   -
39   - data.SetProperty("createtime", common.Timex())
40   - err := data.Create()
41   - if err != nil {
42   - return false
43   - }
44   - return true
45   -}
46   -
47 32 func (m *EmailModel) Log(role *RoleModel, action int32) {
48 33 //{desc = "onMail", int1 = self:getProperty("id"), int2 = self:getProperty("status"), cint1 = self:getProperty("emailId"),
49 34 // short1 = action, key1=self:getProperty("title"), key2=self:getProperty("attachments")})
... ...
models/role.go
... ... @@ -2,7 +2,6 @@ package models
2 2  
3 3 import (
4 4 "fmt"
5   - "github.com/golang/protobuf/proto"
6 5 "pro2d/common"
7 6 "pro2d/common/components"
8 7 "pro2d/common/db/mongoproxy"
... ... @@ -208,13 +207,8 @@ func (m *RoleModel) UpdateProperties(property map[string]interface{}, notify boo
208 207 Id: ids,
209 208 Role: role,
210 209 }
211   - if rsp, err := proto.Marshal(update); err != nil {
212   - logger.Error("id %s, err:", m.Data.Id, err)
213   - return
214   - } else {
215   - if m.GetConn() != nil && notify {
216   - m.GetConn().Send(0, uint32(pb.ProtoCode_RoleUpdatePropertyNty), rsp, 0)
217   - }
  210 + if m.GetConn() != nil && notify {
  211 + m.GetConn().SendPB(0, uint32(pb.ProtoCode_RoleUpdatePropertyNty), update, 0)
218 212 }
219 213 }
220 214  
... ...
models/rolePlugin.go
... ... @@ -64,15 +64,10 @@ func (m *RoleModel) AddItem(key string, count int32, param *pb.LogConf) bool {
64 64 m.MyLog("in_item", param)
65 65 }
66 66  
67   - rsp, err := proto.Marshal(&pb.RoleUpdateItemsNty{Items: fmt.Sprintf("%s=%d", key, num)})
68   - if err != nil {
69   - logger.Error(err.Error())
70   - return true
71   - }
72   -
73 67 if m.GetConn() != nil {
74   - m.GetConn().Send(0, uint32(pb.ProtoCode_RoleUpdateItemsNty), rsp, 0)
  68 + m.GetConn().SendPB(0, uint32(pb.ProtoCode_RoleUpdateItemsNty), &pb.RoleUpdateItemsNty{Items: fmt.Sprintf("%s=%d", key, num)}, 0)
75 69 }
  70 +
76 71 return true
77 72 }
78 73  
... ... @@ -103,14 +98,8 @@ func (m *RoleModel) AddItems(params common.IMapStringNum, logconf *pb.LogConf) b
103 98  
104 99 m.SetProperty("items", common.MapNumToString(m.Items))
105 100  
106   - rsp, err := proto.Marshal(&pb.RoleUpdateItemsNty{Items: common.MapToString(tmp)})
107   - if err != nil {
108   - logger.Error(err.Error())
109   - return true
110   - }
111   -
112 101 if m.GetConn() != nil {
113   - m.GetConn().Send(0, uint32(pb.ProtoCode_RoleUpdateItemsNty), rsp, 0)
  102 + m.GetConn().SendPB(0, uint32(pb.ProtoCode_RoleUpdateItemsNty), &pb.RoleUpdateItemsNty{Items: common.MapToString(tmp)}, 0)
114 103 }
115 104  
116 105 return true
... ... @@ -375,3 +364,29 @@ func (m *RoleModel) LoadEmails() []*pb.Email {
375 364 }
376 365 return emails
377 366 }
  367 +
  368 +func (m *RoleModel) InsertEmail(email *pb.Email) error {
  369 + id, err := common.GetNextEmail()
  370 + if err != nil {
  371 + return err
  372 + }
  373 +
  374 + email.Id = id
  375 + email.CreateTime = common.Timex()
  376 + email.Status = 0
  377 +
  378 + data := &EmailModel{
  379 + ISchema: NewSchema(email.Id, email),
  380 + Data: email,
  381 + }
  382 + err = data.Create()
  383 + if err != nil {
  384 + return err
  385 + }
  386 +
  387 + nty := &pb.EmailNewNty{Emails: email}
  388 + if m.GetConn() != nil {
  389 + m.GetConn().SendPB(0, uint32(pb.ProtoCode_EmailNewNty), nty, 0)
  390 + }
  391 + return nil
  392 +}
... ...
pb/game.pb.go
... ... @@ -1413,6 +1413,53 @@ func (x *EmailDelRsp) GetIds() []string {
1413 1413 return nil
1414 1414 }
1415 1415  
  1416 +type EmailNewNty struct {
  1417 + state protoimpl.MessageState
  1418 + sizeCache protoimpl.SizeCache
  1419 + unknownFields protoimpl.UnknownFields
  1420 +
  1421 + Emails *Email `protobuf:"bytes,1,opt,name=emails,proto3" json:"emails,omitempty"`
  1422 +}
  1423 +
  1424 +func (x *EmailNewNty) Reset() {
  1425 + *x = EmailNewNty{}
  1426 + if protoimpl.UnsafeEnabled {
  1427 + mi := &file_game_proto_msgTypes[27]
  1428 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
  1429 + ms.StoreMessageInfo(mi)
  1430 + }
  1431 +}
  1432 +
  1433 +func (x *EmailNewNty) String() string {
  1434 + return protoimpl.X.MessageStringOf(x)
  1435 +}
  1436 +
  1437 +func (*EmailNewNty) ProtoMessage() {}
  1438 +
  1439 +func (x *EmailNewNty) ProtoReflect() protoreflect.Message {
  1440 + mi := &file_game_proto_msgTypes[27]
  1441 + if protoimpl.UnsafeEnabled && x != nil {
  1442 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
  1443 + if ms.LoadMessageInfo() == nil {
  1444 + ms.StoreMessageInfo(mi)
  1445 + }
  1446 + return ms
  1447 + }
  1448 + return mi.MessageOf(x)
  1449 +}
  1450 +
  1451 +// Deprecated: Use EmailNewNty.ProtoReflect.Descriptor instead.
  1452 +func (*EmailNewNty) Descriptor() ([]byte, []int) {
  1453 + return file_game_proto_rawDescGZIP(), []int{27}
  1454 +}
  1455 +
  1456 +func (x *EmailNewNty) GetEmails() *Email {
  1457 + if x != nil {
  1458 + return x.Emails
  1459 + }
  1460 + return nil
  1461 +}
  1462 +
1416 1463 var File_game_proto protoreflect.FileDescriptor
1417 1464  
1418 1465 var file_game_proto_rawDesc = []byte{
... ... @@ -1519,8 +1566,12 @@ var file_game_proto_rawDesc = []byte{
1519 1566 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x0d, 0x0a, 0x0b, 0x45, 0x6d, 0x61,
1520 1567 0x69, 0x6c, 0x44, 0x65, 0x6c, 0x52, 0x65, 0x71, 0x22, 0x1f, 0x0a, 0x0b, 0x45, 0x6d, 0x61, 0x69,
1521 1568 0x6c, 0x44, 0x65, 0x6c, 0x52, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x64, 0x73, 0x18, 0x01,
1522   - 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x69, 0x64, 0x73, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f,
1523   - 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
  1569 + 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x69, 0x64, 0x73, 0x22, 0x34, 0x0a, 0x0b, 0x45, 0x6d, 0x61,
  1570 + 0x69, 0x6c, 0x4e, 0x65, 0x77, 0x4e, 0x74, 0x79, 0x12, 0x25, 0x0a, 0x06, 0x65, 0x6d, 0x61, 0x69,
  1571 + 0x6c, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c,
  1572 + 0x73, 0x2e, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x06, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x73, 0x42,
  1573 + 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f,
  1574 + 0x74, 0x6f, 0x33,
1524 1575 }
1525 1576  
1526 1577 var (
... ... @@ -1535,7 +1586,7 @@ func file_game_proto_rawDescGZIP() []byte {
1535 1586 return file_game_proto_rawDescData
1536 1587 }
1537 1588  
1538   -var file_game_proto_msgTypes = make([]protoimpl.MessageInfo, 27)
  1589 +var file_game_proto_msgTypes = make([]protoimpl.MessageInfo, 28)
1539 1590 var file_game_proto_goTypes = []interface{}{
1540 1591 (*HeartReq)(nil), // 0: game.HeartReq
1541 1592 (*HeartRsp)(nil), // 1: game.HeartRsp
... ... @@ -1564,29 +1615,31 @@ var file_game_proto_goTypes = []interface{}{
1564 1615 (*EmailCheckRar)(nil), // 24: game.EmailCheckRar
1565 1616 (*EmailDelReq)(nil), // 25: game.EmailDelReq
1566 1617 (*EmailDelRsp)(nil), // 26: game.EmailDelRsp
1567   - (*Role)(nil), // 27: models.Role
1568   - (*Hero)(nil), // 28: models.Hero
1569   - (*Team)(nil), // 29: models.Team
1570   - (*Equipment)(nil), // 30: models.Equipment
1571   - (*Email)(nil), // 31: models.Email
  1618 + (*EmailNewNty)(nil), // 27: game.EmailNewNty
  1619 + (*Role)(nil), // 28: models.Role
  1620 + (*Hero)(nil), // 29: models.Hero
  1621 + (*Team)(nil), // 30: models.Team
  1622 + (*Equipment)(nil), // 31: models.Equipment
  1623 + (*Email)(nil), // 32: models.Email
1572 1624 }
1573 1625 var file_game_proto_depIdxs = []int32{
1574   - 27, // 0: game.LoginRsp.role:type_name -> models.Role
1575   - 28, // 1: game.LoginRsp.hero:type_name -> models.Hero
1576   - 29, // 2: game.LoginRsp.team:type_name -> models.Team
1577   - 30, // 3: game.LoginRsp.equipments:type_name -> models.Equipment
1578   - 29, // 4: game.ChangeTeamRar.team:type_name -> models.Team
  1626 + 28, // 0: game.LoginRsp.role:type_name -> models.Role
  1627 + 29, // 1: game.LoginRsp.hero:type_name -> models.Hero
  1628 + 30, // 2: game.LoginRsp.team:type_name -> models.Team
  1629 + 31, // 3: game.LoginRsp.equipments:type_name -> models.Equipment
  1630 + 30, // 4: game.ChangeTeamRar.team:type_name -> models.Team
1579 1631 7, // 5: game.HeroEquipReferRar.equipIds:type_name -> game.EquipInfo
1580   - 27, // 6: game.RoleUpdatePropertyNty.role:type_name -> models.Role
1581   - 28, // 7: game.RoleEndBattleRsp.hero:type_name -> models.Hero
1582   - 30, // 8: game.EquipmentAddNty.equip:type_name -> models.Equipment
1583   - 28, // 9: game.HeroUpLevelRsp.hero:type_name -> models.Hero
1584   - 31, // 10: game.EmailListRsp.emails:type_name -> models.Email
1585   - 11, // [11:11] is the sub-list for method output_type
1586   - 11, // [11:11] is the sub-list for method input_type
1587   - 11, // [11:11] is the sub-list for extension type_name
1588   - 11, // [11:11] is the sub-list for extension extendee
1589   - 0, // [0:11] is the sub-list for field type_name
  1632 + 28, // 6: game.RoleUpdatePropertyNty.role:type_name -> models.Role
  1633 + 29, // 7: game.RoleEndBattleRsp.hero:type_name -> models.Hero
  1634 + 31, // 8: game.EquipmentAddNty.equip:type_name -> models.Equipment
  1635 + 29, // 9: game.HeroUpLevelRsp.hero:type_name -> models.Hero
  1636 + 32, // 10: game.EmailListRsp.emails:type_name -> models.Email
  1637 + 32, // 11: game.EmailNewNty.emails:type_name -> models.Email
  1638 + 12, // [12:12] is the sub-list for method output_type
  1639 + 12, // [12:12] is the sub-list for method input_type
  1640 + 12, // [12:12] is the sub-list for extension type_name
  1641 + 12, // [12:12] is the sub-list for extension extendee
  1642 + 0, // [0:12] is the sub-list for field type_name
1590 1643 }
1591 1644  
1592 1645 func init() { file_game_proto_init() }
... ... @@ -1920,6 +1973,18 @@ func file_game_proto_init() {
1920 1973 return nil
1921 1974 }
1922 1975 }
  1976 + file_game_proto_msgTypes[27].Exporter = func(v interface{}, i int) interface{} {
  1977 + switch v := v.(*EmailNewNty); i {
  1978 + case 0:
  1979 + return &v.state
  1980 + case 1:
  1981 + return &v.sizeCache
  1982 + case 2:
  1983 + return &v.unknownFields
  1984 + default:
  1985 + return nil
  1986 + }
  1987 + }
1923 1988 }
1924 1989 type x struct{}
1925 1990 out := protoimpl.TypeBuilder{
... ... @@ -1927,7 +1992,7 @@ func file_game_proto_init() {
1927 1992 GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
1928 1993 RawDescriptor: file_game_proto_rawDesc,
1929 1994 NumEnums: 0,
1930   - NumMessages: 27,
  1995 + NumMessages: 28,
1931 1996 NumExtensions: 0,
1932 1997 NumServices: 0,
1933 1998 },
... ...
pb/protocode.pb.go
... ... @@ -42,6 +42,7 @@ const (
42 42 ProtoCode_RoleUpdatePropertyNty ProtoCode = 1002
43 43 ProtoCode_RoleUpdateItemsNty ProtoCode = 1003
44 44 ProtoCode_EquipmentAddNty ProtoCode = 1004
  45 + ProtoCode_EmailNewNty ProtoCode = 1005
45 46 )
46 47  
47 48 // Enum value maps for ProtoCode.
... ... @@ -66,6 +67,7 @@ var (
66 67 1002: "RoleUpdatePropertyNty",
67 68 1003: "RoleUpdateItemsNty",
68 69 1004: "EquipmentAddNty",
  70 + 1005: "EmailNewNty",
69 71 }
70 72 ProtoCode_value = map[string]int32{
71 73 "UNKNOWN": 0,
... ... @@ -87,6 +89,7 @@ var (
87 89 "RoleUpdatePropertyNty": 1002,
88 90 "RoleUpdateItemsNty": 1003,
89 91 "EquipmentAddNty": 1004,
  92 + "EmailNewNty": 1005,
90 93 }
91 94 )
92 95  
... ... @@ -121,7 +124,7 @@ var File_protocode_proto protoreflect.FileDescriptor
121 124  
122 125 var file_protocode_proto_rawDesc = []byte{
123 126 0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
124   - 0x6f, 0x12, 0x09, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x64, 0x65, 0x2a, 0x90, 0x03, 0x0a,
  127 + 0x6f, 0x12, 0x09, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x64, 0x65, 0x2a, 0xa2, 0x03, 0x0a,
125 128 0x09, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e,
126 129 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x08, 0x48, 0x65, 0x61, 0x72, 0x74,
127 130 0x52, 0x70, 0x63, 0x10, 0xf5, 0x03, 0x12, 0x0d, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52,
... ... @@ -146,9 +149,10 @@ var file_protocode_proto_rawDesc = []byte{
146 149 0x74, 0x65, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x4e, 0x74, 0x79, 0x10, 0xea, 0x07,
147 150 0x12, 0x17, 0x0a, 0x12, 0x52, 0x6f, 0x6c, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, 0x74,
148 151 0x65, 0x6d, 0x73, 0x4e, 0x74, 0x79, 0x10, 0xeb, 0x07, 0x12, 0x14, 0x0a, 0x0f, 0x45, 0x71, 0x75,
149   - 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x64, 0x64, 0x4e, 0x74, 0x79, 0x10, 0xec, 0x07, 0x42,
150   - 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f,
151   - 0x74, 0x6f, 0x33,
  152 + 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x64, 0x64, 0x4e, 0x74, 0x79, 0x10, 0xec, 0x07, 0x12,
  153 + 0x10, 0x0a, 0x0b, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x4e, 0x65, 0x77, 0x4e, 0x74, 0x79, 0x10, 0xed,
  154 + 0x07, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70,
  155 + 0x72, 0x6f, 0x74, 0x6f, 0x33,
152 156 }
153 157  
154 158 var (
... ...